示例#1
0
        private static async Task RequestSunTimes()
        {
            var client   = new SunsetSunriseClient();
            var sunTimes = await client.GetSunsetSunriseAsync(UserSettings.Settings.Latitude.Value, UserSettings.Settings.Longitude.Value);

            UserSettings.Settings.UpdateSunriseSunset(sunTimes.SunriseHour, sunTimes.SunriseMinute, sunTimes.SunsetHour, sunTimes.SunsetMinute);
        }
示例#2
0
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            #region LatLong

            double latitude  = 0;
            double longitude = 0;
            try
            {
                if (!string.IsNullOrWhiteSpace(OptionsViewModel.Latitude))
                {
                    latitude = Convert.ToDouble(OptionsViewModel.Latitude, CultureInfo.InvariantCulture);
                }
            }
            catch
            {
                PopupCreator.Error(Options.Resources.InvalidLatitude);
                return;
            }

            try
            {
                if (!string.IsNullOrWhiteSpace(OptionsViewModel.Longitude))
                {
                    longitude = Convert.ToDouble(OptionsViewModel.Longitude, CultureInfo.InvariantCulture);
                }
            }
            catch
            {
                PopupCreator.Error(Options.Resources.InvalidLongitude);
                return;
            }

            if ((latitude != UserSettings.Settings.Latitude || longitude != UserSettings.Settings.Longitude) && (latitude != 0 && longitude != 0))
            {
                var client = new SunsetSunriseClient();

                try
                {
                    var sunTimes = client.GetSunsetSunriseAsync(latitude, longitude).GetAwaiter().GetResult();

                    UserSettings.Settings.UpdateSunriseSunset(sunTimes.SunriseHour, sunTimes.SunriseMinute, sunTimes.SunsetHour, sunTimes.SunsetMinute);
                }
                catch
                {
                    PopupCreator.Error(Options.Resources.SunsetSunriseError);
                    return;
                }

                UserSettings.Settings.Latitude  = latitude;
                UserSettings.Settings.Longitude = longitude;
            }
            #endregion

            #region StartAtWindowsStartup
            if (UserSettings.Settings.StartAtWindowsStartup != OptionsViewModel.StartAtWindowsStartUp)
            {
                if (OptionsViewModel.StartAtWindowsStartUp)
                {
                    _startupKey.SetValue(UserSettings.APPLICATIONNAME, $"{System.Reflection.Assembly.GetExecutingAssembly().Location} -s");
                }
                else
                {
                    _startupKey.DeleteValue(UserSettings.APPLICATIONNAME, false);
                }

                _startupKey.Close();

                UserSettings.Settings.StartAtWindowsStartup = OptionsViewModel.StartAtWindowsStartUp;
            }
            #endregion

            #region ScreenMirror
            var monitorNames = WindowsDisplayAPI.DisplayConfig.PathDisplayTarget.GetDisplayTargets().Select(m => m.FriendlyName).ToArray();

            foreach (var device in UserSettings.Settings.Devices)
            {
                device.ScreenMirrorAlgorithm            = OptionsViewModel.AlgorithmPerDevice[device.Name];
                device.ScreenMirrorRefreshRatePerSecond = OptionsViewModel.ScreenMirrorRefreshRatePerDevice[device.Name];
                device.ScreenMirrorControlBrightness    = OptionsViewModel.ScreenMirrorControlBrightnessPerDevice[device.Name];
                device.ScreenMirrorMonitorIndex         = Array.IndexOf(monitorNames, OptionsViewModel.MonitorPerDevice[device.Name]);
            }
            #endregion

            #region Language

            if (OptionsViewModel.SelectedLanguage != null)
            {
                UserSettings.Settings.UserLocale = _languageDictionary[OptionsViewModel.SelectedLanguage];
            }

            #endregion

            #region MinimizeToSystemTray
            UserSettings.Settings.MinimizeToSystemTray = OptionsViewModel.MinimizeToSystemTray;
            #endregion

            #region Colors

            UserSettings.Settings.CustomEffects = OptionsViewModel.CustomColorEffects;

            #endregion Colors
            UserSettings.Settings.SaveSettings();

            // Reload the orchestrator so custom effects are reloaded.
            OrchestratorCollection.ResetOrchestratorForActiveDevice();

            _mainWindow.ReloadEffects();

            Close();
        }
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            #region LatLong

            double latitude  = 0;
            double longitude = 0;
            try
            {
                if (!string.IsNullOrWhiteSpace(OptionsViewModel.Latitude))
                {
                    latitude = Convert.ToDouble(OptionsViewModel.Latitude, CultureInfo.InvariantCulture);
                }
            }
            catch
            {
                PopupCreator.Error(Options.Resources.InvalidLatitude);
                return;
            }

            try
            {
                if (!string.IsNullOrWhiteSpace(OptionsViewModel.Longitude))
                {
                    longitude = Convert.ToDouble(OptionsViewModel.Longitude, CultureInfo.InvariantCulture);
                }
            }
            catch
            {
                PopupCreator.Error(Options.Resources.InvalidLongitude);
                return;
            }

            if ((latitude != UserSettings.Settings.Latitude || longitude != UserSettings.Settings.Longitude) && (latitude != 0 && longitude != 0))
            {
                var client = new SunsetSunriseClient();

                try
                {
                    var sunTimes = client.GetSunsetSunriseAsync(latitude, longitude).GetAwaiter().GetResult();

                    UserSettings.Settings.UpdateSunriseSunset(sunTimes.SunriseHour, sunTimes.SunriseMinute, sunTimes.SunsetHour, sunTimes.SunsetMinute);
                }
                catch
                {
                    PopupCreator.Error(Options.Resources.SunsetSunriseError);
                    return;
                }

                UserSettings.Settings.Latitude  = latitude;
                UserSettings.Settings.Longitude = longitude;
            }
            #endregion

            #region StartAtWindowsStartup
            if (UserSettings.Settings.StartAtWindowsStartup != OptionsViewModel.StartAtWindowsStartUp)
            {
                if (OptionsViewModel.StartAtWindowsStartUp)
                {
                    //Replace .dll with .exe since in .net core 3 the current executing assembly is the dll
                    _startupKey.SetValue(UserSettings.APPLICATIONNAME, $"{System.Reflection.Assembly.GetExecutingAssembly().Location.Replace(".dll", ".exe")} -s");
                }
                else
                {
                    _startupKey.DeleteValue(UserSettings.APPLICATIONNAME, false);
                }

                _startupKey.Close();

                UserSettings.Settings.StartAtWindowsStartup = OptionsViewModel.StartAtWindowsStartUp;
            }
            #endregion

            #region ScreenMirror
            foreach (var device in UserSettings.Settings.Devices)
            {
                device.ScreenMirrorAlgorithm = OptionsViewModel.AlgorithmPerDevice[device.Name];
            }

            UserSettings.Settings.ScreenMirrorMonitorIndex         = Array.IndexOf(_monitorNames.ToArray(), OptionsViewModel.SelectedMonitor);
            UserSettings.Settings.ScreenMirrorRefreshRatePerSecond = OptionsViewModel.ScreenMirrorRefreshRatePerSecond;

            #endregion

            #region Language

            if (OptionsViewModel.SelectedLanguage != null)
            {
                UserSettings.Settings.UserLocale = _languageDictionary[OptionsViewModel.SelectedLanguage];
            }

            #endregion

            #region MinimizeToSystemTray
            UserSettings.Settings.MinimizeToSystemTray = OptionsViewModel.MinimizeToSystemTray;
            #endregion

            #region Colors

            var deletedColors = UserSettings.Settings.CustomEffects?.Except(OptionsViewModel.CustomColorEffects).ToList();

            UserSettings.Settings.CustomEffects = OptionsViewModel.CustomColorEffects;

            //Remove invalid triggers from the schedules
            if (deletedColors?.Any() == true)
            {
                UserSettings.Settings.DeleteTriggers(deletedColors.Select(color =>
                                                                          UserCustomColorEffect.DisplayName(color.EffectName)));
            }

            #endregion Colors


            UserSettings.Settings.SaveSettings();

            //Reload the orchestrator so custom effects are reloaded.
            OrchestratorCollection.ResetOrchestrators();

            //Reload effects such that custom effects are updated in the view
            _mainWindow.ReloadEffectsInView();

            Close();
        }
示例#4
0
 public SunriseSunsetAPITests()
 {
     client = new SunsetSunriseClient(uri, lng, lat, date);
 }