public NotifyIconViewModel()
        {
            _pingService = new GeekPingService();
            _pingService.Start();

            var settings = MonitorSettings.Load();

            if (string.IsNullOrWhiteSpace(settings.GeekUsername))
            {
                ShowWindow();
            }
        }
        private void ComboBoxMonitorSelection_SelectionChanged(object sender, EventArgs e)
        {
            MonitorSettings monitorSettings = (MonitorSettings)ComboBoxMonitorSelection.SelectedItem;

            if (monitorSettings != null && SelectedLight)
            {
                Dispatcher.BeginInvoke(new ShowPreviewDelegate(ShowPreview), monitorSettings.LightThemeWallpaper);
            }
            else if (monitorSettings != null)
            {
                Dispatcher.BeginInvoke(new ShowPreviewDelegate(ShowPreview), monitorSettings.DarkThemeWallpaper);
            }
        }
Ejemplo n.º 3
0
        public GeekPingService()
        {
            _backgroundWorker = new BackgroundWorker();
            _backgroundWorker.WorkerSupportsCancellation = true;
            _backgroundWorker.DoWork += DoWork;

            int pingInterval = MonitorSettings.Load().LoginInterval;

            _pingTimer           = new Timer();
            _pingTimer.Interval  = TimeSpan.FromMinutes(pingInterval).TotalMilliseconds;
            _pingTimer.Elapsed  += OnPingTimerElapsed;
            _pingTimer.AutoReset = false;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 設定をファイルから読み込み
        /// </summary>
        /// <param name="monitorCount">ディスプレイ総数</param>
        public void Load(int monitorCount)
        {
            var result = this.SettingXml.LoadXml();
            var obj    = result.Value;

            obj.ExpandMonitorCount(monitorCount);
            this.MonitorSettings = obj;

            while (MonitorSettings.Settings.Count < this.settingNum)
            {
                MonitorSettings.AddNew(monitorCount);
            }
        }
Ejemplo n.º 5
0
 public MonitorWorker(ILogger <MonitorWorker> logger,
                      DiscordSocketClient discordClient,
                      IBrobotService brobotService,
                      IOptions <MonitorSettings> monitorSettings,
                      IHostApplicationLifetime applicationLifetime)
 {
     _logger              = logger;
     _discordClient       = discordClient;
     _brobotService       = brobotService;
     _monitorSettings     = monitorSettings.Value;
     _applicationLifetime = applicationLifetime;
     _eventResponses      = new Dictionary <ulong, Dictionary <string, List <EventResponse> > >();
     _channels            = new List <Channel>();
 }
        public void TestProjects_ProjectIdentifierId_MatchesAppSettingsProjectId()
        {
            var appSettings       = Substitute.For <IAppSettings>();
            var expectedProjectId = Guid.NewGuid();

            appSettings.VstsAccount.Returns("account");
            appSettings.ProjectId.Returns(expectedProjectId);
            var systemUnderTest = new MonitorSettings(appSettings);

            // ReSharper disable once PossibleNullReferenceException
            var actualProjectId = systemUnderTest.Projects.FirstOrDefault().Id;

            Assert.That(actualProjectId, Is.EqualTo(expectedProjectId));
        }
        public void TestProjects_ProjectIdentifierVstsAccount_MatchesAppSettingsVstsAccount()
        {
            var appSettings         = Substitute.For <IAppSettings>();
            var expectedVstsAccount = "this-would-never-be-right-by-accident";

            appSettings.VstsAccount.Returns(expectedVstsAccount);
            appSettings.ProjectId.Returns(Guid.NewGuid());
            var systemUnderTest = new MonitorSettings(appSettings);

            // ReSharper disable once PossibleNullReferenceException
            var actualServerBaseUri = systemUnderTest.Projects.FirstOrDefault().VstsAccount;

            Assert.That(actualServerBaseUri, Is.EqualTo(expectedVstsAccount));
        }
Ejemplo n.º 8
0
        void DoWork(object sender, DoWorkEventArgs e)
        {
            if (_backgroundWorker.CancellationPending)
            {
                return;
            }

            var settings = MonitorSettings.Load();

            string apiUrl                = settings.IsThisGeekAliveApiUrl;
            string geekUsername          = settings.GeekUsername;
            string geekLoginCode         = settings.GeekLoginCode;
            int    notAliveWarningWindow = settings.NotAliveWarningWindow;
            int    notAliveDangerWindow  = settings.NotAliveDangerWindow;

            if (string.IsNullOrWhiteSpace(apiUrl))
            {
                Messenger.Default.Send(new PingFailedMessage("The API url has not been set"));
                return;
            }

            if (string.IsNullOrWhiteSpace(geekUsername))
            {
                Messenger.Default.Send(new PingFailedMessage("The geek's username has not been set"));
                return;
            }

            if (string.IsNullOrWhiteSpace(geekLoginCode))
            {
                Messenger.Default.Send(new PingFailedMessage("The geek's login code has not been set"));
                return;
            }

            RestClient  client  = new RestClient(apiUrl);
            RestRequest request = CreatePingRequest(geekUsername, geekLoginCode,
                                                    notAliveWarningWindow, notAliveDangerWindow);

            try
            {
                var response = client.Post(request);
                CheckForError(response);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(string.Format("Ping failed exception: {0}", ex.ToString()));
                SimpleLogger.Logger.Log(string.Format("Ping exception: {0}", ex.ToString()));

                Messenger.Default.Send(new PingFailedMessage(ex.Message));
            }
        }
Ejemplo n.º 9
0
 private void SetUiSettings(MonitorSettings settings)
 {
     start_startup.Checked     = settings.StartOnStartup;
     start_log_startup.Checked = settings.StartLoggingOnStartup;
     start_minimized.Checked   = settings.StartMinimized;
     minimize_tray.Checked     = settings.MinimizeToTray;
     hide_tray.Checked         = settings.HideTrayIcon;
     hotkey.Text           = settings.Hotkey.ToString();
     report_folder.Text    = settings.ReportStoragePath;
     report_extension.Text = settings.ReportExtension;
     max_log_size.Value    = settings.MaxLogSize;
     public_key.Text       = settings.PublicKey;
     take_screen.Checked   = settings.TakeScreenshots;
 }
Ejemplo n.º 10
0
        static void Main()
        {
            MonitorSettings settings = MonitorLiteManager.GetDefaultSettings();

            if (File.Exists(monitorSettingPath))
            {
                byte[] settingsData = File.ReadAllBytes(Program.monitorSettingPath);
                settings = MonitorLiteManager.ReadSettings(settingsData);
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1(settings));
        }
Ejemplo n.º 11
0
        private MonitorSettings GetUiSettings()
        {
            MonitorSettings settings = MonitorLiteManager.GetDefaultSettings();

            settings.StartOnStartup        = start_startup.Checked;
            settings.StartLoggingOnStartup = start_log_startup.Checked;
            settings.StartMinimized        = start_minimized.Checked;
            settings.MinimizeToTray        = minimize_tray.Checked;
            settings.HideTrayIcon          = hide_tray.Checked;
            settings.Hotkey            = hotkey.Text[0];
            settings.ReportStoragePath = report_folder.Text;
            settings.ReportExtension   = report_extension.Text;
            settings.MaxLogSize        = (int)max_log_size.Value;
            settings.PublicKey         = public_key.Text;
            settings.TakeScreenshots   = take_screen.Checked;
            return(settings);
        }
Ejemplo n.º 12
0
        public Monitor(int checkIntevalInSeconds, string checkUrl, string checkString,
            string tunnelPath, string tunnelArguments, string tunnelWorkingDirectory)
        {
            running = false;
            Settings = new MonitorSettings()
            {
                CheckIntervalInSeconds = checkIntevalInSeconds,
                CheckUrl = checkUrl,
                CheckString = checkString,
                TunnelPath = tunnelPath,
                TunnelArguments = tunnelArguments,
                TunnelWorkingDirectory = tunnelWorkingDirectory
            };

            InitTimer();
            client = new WebClient();
        }
        private Theme GetIndividualWallpapersState()
        {
            List <Tuple <string, string> > wallpapers = WallpaperHandler.GetWallpapers();
            List <Theme> wallpaperStates = new();

            // collect the wallpaper states of all wallpapers in the system
            foreach (Tuple <string, string> wallpaperInfo in wallpapers)
            {
                MonitorSettings settings = Settings.Component.Monitors.Find(m => m.Id == wallpaperInfo.Item1);
                if (settings != null)
                {
                    if (wallpaperInfo.Item2.ToLower().Equals(settings.DarkThemeWallpaper.ToLower()))
                    {
                        wallpaperStates.Add(Theme.Dark);
                    }
                    else if (wallpaperInfo.Item2.ToLower().Equals(settings.LightThemeWallpaper.ToLower()))
                    {
                        wallpaperStates.Add(Theme.Light);
                    }
                    else
                    {
                        wallpaperStates.Add(Theme.Unknown);
                        break;
                    }
                }
                else
                {
                    wallpaperStates.Add(Theme.Unknown);
                    break;
                }
            }
            // if one single wallpaper does not match a theme, then we don't know the state and it needs to be updated
            if (wallpaperStates.TrueForAll(c => c == Theme.Dark))
            {
                return(Theme.Dark);
            }
            else if (wallpaperStates.TrueForAll(c => c == Theme.Light))
            {
                return(Theme.Light);
            }
            else
            {
                return(Theme.Unknown);
            }
        }
Ejemplo n.º 14
0
        public Form1(MonitorSettings settings)
        {
            InitializeComponent();

            MonitorLiteManager.HotKeyPress += MonitorLiteManager_HotKeyPress;

            tabControl2.SelectedIndexChanged += TabControl2_SelectedIndexChanged;
            SetUiSettings(settings);


            RestartMonitor();

            logViewer                          = new LogViewer();
            this.FormClosing                  += Form1_FormClosing;
            this.notifyIcon1.Icon              = this.Icon;
            this.notifyIcon1.MouseDoubleClick += NotifyIcon1_MouseDoubleClick;
            this.Resize                       += Form1_Resize;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// ディスプレイを回転した後、画面の向きに対応した壁紙を設定する
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="increment"></param>
        /// <param name="progress"></param>
        /// <returns></returns>
        public async Task RotateAndChangeWallPaperAsync(MonitorSettings settings, int increment, IObserver <int> progress)
        {
            if (MonitorCount == 0)
            {
                return;
            }

            //画面を回転させるオブジェクトを取得
            var rotate = DisplayRotate.Generate(settings.RotateDevice % MonitorCount);

            if (rotate == null)
            {
                return;
            }


            //回転中は画面がちらつくので暗転させる
            using (increment != 0 ? new DisplayBlackOut(blackoutTime) : Disposable.Empty)//
            {
                await Task.Delay(100);

                //画面を回転
                rotate.Rotate(increment);

                await Task.Delay(100);

                //壁紙を設定
                this.RefreshWallpaper(settings);

                await Task.Delay(1000);
            }

            progress.OnNext(1);

            if (increment != 0)
            {
                //壁紙が正しく変更されないことがあるので、時間がたったら再度壁紙を設定
                await Task.Delay(2500);

                this.RefreshWallpaper(settings);
            }

            progress.OnCompleted();
        }
        private void ComboBoxMonitorSelection_SelectionChanged(object sender, EventArgs e)
        {
            //fixes bug that shows multi monitor wallpaper on single monitor mode
            if (ComboBoxWallpaperTypeSelection.SelectedItem != ComboBoxBackgroundSelectionIndividual)
            {
                return;
            }

            MonitorSettings monitorSettings = (MonitorSettings)ComboBoxMonitorSelection.SelectedItem;

            if (monitorSettings != null && SelectedLight)
            {
                Dispatcher.BeginInvoke(new ShowPreviewDelegate(ShowPreview), monitorSettings.LightThemeWallpaper);
            }
            else if (monitorSettings != null)
            {
                Dispatcher.BeginInvoke(new ShowPreviewDelegate(ShowPreview), monitorSettings.DarkThemeWallpaper);
            }
        }
Ejemplo n.º 17
0
        public static MonitorSettings GetMonitorSettings()
        {
            var fileName = "monitorSettings.json";
            var fi       = new FileInfo(
                Path.Combine(
                    AppDomain.CurrentDomain.BaseDirectory,
                    fileName));

            if (!fi.Exists)
            {
                throw new FileNotFoundException($"app settings file not found {fileName}");
            }

            var json = File.ReadAllText(fi.FullName);

            var monitorSettings = MonitorSettings.FromJson(json);

            return(monitorSettings);
        }
        public static void SaveMonitorSettings(MonitorSettings monitorSettings)
        {
            try
            {
                var appDataFoder   = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                var settingsFolder = Path.Combine(appDataFoder, SettingsFolder);
                if (!Directory.Exists(settingsFolder))
                {
                    Directory.CreateDirectory(settingsFolder);
                }

                var monitorSettingsFilePath = Path.Combine(settingsFolder, MonitorSettingsFileName);
                File.WriteAllText(monitorSettingsFilePath, JsonConvert.SerializeObject(monitorSettings));
            }
            catch (Exception exception)
            {
                Debug.WriteLine($"Failed to save monitor settings: {exception}");
            }
        }
        public ConsistencyMonitor(MonitorSettings monitorSettings,
                                  IConsistencyService consistencyService,
                                  IMtSlackNotificationsSender slackNotificationsSender,
                                  ICheckResultRepository checkResultRepository,
                                  IBalanceAndTransactionAmountRepository balanceAndTransactionAmountRepository,
                                  IBalanceAndOrderClosedRepository balanceAndOrderClosedRepository,
                                  IOrdersReportAndOrderClosedOpenedRepository ordersReportAndOrderClosedOpenedRepository,
                                  IPriceCandlesConsistencyRepository priceCandlesConsistencyRepository,
                                  IMarginEventsAccountStatusRepository marginEventsAccountStatusRepository,
                                  IHedgingServiceRepository hedgingServiceRepository,
                                  IAlertSeverityLevelService alertSeverityLevelService,
                                  ILog log)
        {
            _log                   = log;
            _monitorSettings       = monitorSettings;
            _consistencyService    = consistencyService;
            MonitorInterval        = _monitorSettings.ConsistencyCheckInterval;
            _checkResultRepository = checkResultRepository;
            _balanceAndTransactionAmountRepository      = balanceAndTransactionAmountRepository;
            _balanceAndOrderClosedRepository            = balanceAndOrderClosedRepository;
            _ordersReportAndOrderClosedOpenedRepository = ordersReportAndOrderClosedOpenedRepository;
            _priceCandlesConsistencyRepository          = priceCandlesConsistencyRepository;
            _marginEventsAccountStatusRepository        = marginEventsAccountStatusRepository;
            _hedgingServiceRepository  = hedgingServiceRepository;
            _alertSeverityLevelService = alertSeverityLevelService;
            _slackNotificationsSender  = slackNotificationsSender;

            var lastCheckResult = Task.Run(async() => await _checkResultRepository.GetLastAsync()).Result;

            if (lastCheckResult == null)
            {
                LastCheck = null;
            }
            else
            {
                LastCheck = lastCheckResult.DateTo;
            }

            _log.WriteInfo(nameof(ConsistencyMonitor), null, $"Consistency Monitor Started. LastCheck:[{LastCheck?.ToString("u")}]");
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Adds missing monitors to the configuration file
        /// If a monitor configuration is not found,
        /// it will automatically create a configuration with the respective monitor's current wallpaper
        /// </summary>
        public static void DetectMonitors()
        {
            var monitors = Task.Run(async() => await GetMonitorInfosAsync()).Result;
            AdmConfigBuilder  builder    = AdmConfigBuilder.Instance();
            IDesktopWallpaper handler    = (IDesktopWallpaper) new DesktopWallpaperClass();
            List <string>     monitorIds = new();

            for (uint i = 0; i < handler.GetMonitorDevicePathCount(); i++)
            {
                monitorIds.Add(handler.GetMonitorDevicePathAt(i));
            }
            bool needsUpdate = false;

            foreach (string monitorId in monitorIds)
            {
                if (monitorId.Length == 0)
                {
                    continue;
                }
                MonitorSettings settings = builder.Config.WallpaperSwitch.Component.Monitors.Find(m => m.Id == monitorId);
                if (settings == null)
                {
                    Logger.Info($"missing monitor found, adding new default config for: {monitorId}");
                    builder.Config.WallpaperSwitch.Component.Monitors.Add(new MonitorSettings()
                    {
                        DarkThemeWallpaper  = handler.GetWallpaper(monitorId),
                        LightThemeWallpaper = handler.GetWallpaper(monitorId),
                        Id = monitorId
                    });
                    needsUpdate = true;
                }
            }
            if (needsUpdate)
            {
                GlobalState state = GlobalState.Instance();
                state.SkipConfigFileReload = true;
                builder.Save();
            }
        }
        public IActionResult Patch(string id /*signalR connection id*/, [FromBody] MonitorSettingsPutModel model)
        {
            Logger.LogDebug(model.ToString());

            if (MemoryCache.TryGetValue(id, out MonitorSettings settings))
            {
                if (settings.AppId == 0)
                {
                    settings.AppId = model.AppId;
                }

                MemoryCache.Remove(id);
            }
            else
            {
                settings = new MonitorSettings {
                    AppId = model.AppId
                };
            }

            if (model.Level.StartsWith('-'))
            {
                var level = model.Level.Substring(1);
                if (settings.Levels.Contains(level))
                {
                    settings.Levels.Remove(level);
                }
            }
            else
            {
                if (!settings.Levels.Contains(model.Level))
                {
                    settings.Levels.Add(model.Level);
                }
            }

            MemoryCache.Set(id, settings);
            return(NoContent());
        }
Ejemplo n.º 22
0
        public static void SetWallpapers(List <MonitorSettings> monitorSettings, WallpaperPosition position, Theme newTheme)
        {
            IDesktopWallpaper handler = (IDesktopWallpaper) new DesktopWallpaperClass();

            handler.SetPosition(position);
            for (uint i = 0; i < handler.GetMonitorDevicePathCount(); i++)
            {
                string          monitorId      = handler.GetMonitorDevicePathAt(i);
                MonitorSettings monitorSetting = monitorSettings.Find(s => s.Id == monitorId);
                if (monitorSetting != null)
                {
                    if (newTheme == Theme.Dark)
                    {
                        if (!File.Exists(monitorSetting.DarkThemeWallpaper))
                        {
                            Logger.Warn($"target {Enum.GetName(typeof(Theme), newTheme)} wallpaper does not exist (skipping) path ${monitorSetting.DarkThemeWallpaper}, monitor ${monitorId}");
                        }
                        else
                        {
                            handler.SetWallpaper(monitorId, monitorSetting.DarkThemeWallpaper);
                        }
                    }
                    else
                    {
                        if (!File.Exists(monitorSetting.LightThemeWallpaper))
                        {
                            Logger.Warn($"wallpaper does not exist. path ${monitorSetting.DarkThemeWallpaper}, monitor ${monitorId}");
                        }
                        handler.SetWallpaper(monitorId, monitorSetting.LightThemeWallpaper);
                    }
                }
                else
                {
                    Logger.Warn($"no wallpaper config found for monitor {monitorId}, adding missing monitors");
                    DetectMonitors();
                }
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 全モニタの壁紙を再設定
        /// </summary>
        /// <param name="settings"></param>
        public void RefreshWallpaper(MonitorSettings settings)
        {
            for (int monitorIndex = 0; monitorIndex < MonitorCount; monitorIndex++)
            {
                var mode = new DeviceMode(monitorIndex);

                //デバイス情報を取得できないか、設定が存在しない場合はスキップ
                if (!mode.IsSucceeded || !settings.Current.ContainsIndex(monitorIndex))
                {
                    continue;
                }

                //壁紙のファイルパスと表示方法の設定を読み込み
                var setting = settings.Current[monitorIndex]
                              .OrientationSettings[(DisplayOrientations)mode.Mode.dmDisplayOrientation];

                //壁紙を設定
                if (setting != null && setting.Path != null && setting.Path.Length > 0)
                {
                    this.ChangeWallpaper(monitorIndex, setting.Path, setting.Position);
                }
            }
        }
        private void FilePicker1_Click(object sender, RoutedEventArgs e)
        {
            MonitorSettings settings = (MonitorSettings)MonitorSelectionComboBox.SelectedItem;
            OpenFileDialog  dlg      = new OpenFileDialog
            {
                Filter           = Properties.Resources.dbPictures + "|*.png; *.jpg; *.jpeg; *.bmp",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)
            };
            bool?result = dlg.ShowDialog();

            if (result == true)
            {
                if (((Button)sender).CommandParameter.ToString().Equals("FilePicker1"))
                {
                    settings.LightThemeWallpaper = dlg.FileName;
                    ShowPreview(settings.LightThemeWallpaper, 1);
                }
                if (((Button)sender).CommandParameter.ToString().Equals("FilePicker2"))
                {
                    settings.DarkThemeWallpaper = dlg.FileName;
                    ShowPreview(settings.DarkThemeWallpaper, 2);
                }
            }
        }
Ejemplo n.º 25
0
 public RegexMonitor(MonitorSettings monitorSettings) : base(monitorSettings)
 {
 }
Ejemplo n.º 26
0
 public RegexMonitor(MonitorSettings monitorSettings, params IApi[] apis) : base(monitorSettings, apis)
 {
 }
Ejemplo n.º 27
0
 public void Init(MonitorSettings monitorSettings, PostProcessingInspector baseEditor)
 {
     m_MonitorSettings = monitorSettings;
     m_BaseEditor      = baseEditor;
 }
 public CricketTranscieverMonitor(MonitorSettings monitorSettings, CricketTranscieverApi cricketTranscieverApi) :
     base(monitorSettings, cricketTranscieverApi)
 {
     _cricketTranscieverApi = cricketTranscieverApi;
     _cricketLogsQueue      = new Queue <CricketLogModel>();
 }
 public CricketTranscieverMonitor(MonitorSettings monitorSettings) : base(monitorSettings)
 {
     _cricketLogsQueue = new Queue <CricketLogModel>();
 }
Ejemplo n.º 30
0
 public PingFactory(IOptions <MonitorSettings> settings, IDataController dataCtr, ILogger <PingFactory> logger) : base(dataCtr, logger)
 {
     _settings = settings.Value;
 }
Ejemplo n.º 31
0
 public void Init(MonitorSettings monitorSettings, PostProcessingInspector baseEditor)
 {
     m_MonitorSettings = monitorSettings;
     m_BaseEditor = baseEditor;
 }
Ejemplo n.º 32
0
 public TplBoosterMonitor(MonitorSettings monitorSettings, TplBoosterApi tplBoosterApi) : base(monitorSettings, tplBoosterApi)
 {
     _tplBoosterApi = tplBoosterApi;
 }