Example #1
0
        private void LoadUserConfiguration(UserConfigJson userCityConfigs)
        {
            if (InvokeRequired)
            {
                InvokeAsync(() => LoadUserConfiguration(userCityConfigs));
                return;
            }

            _userCityConfigs = userCityConfigs;

            Dictionary <string, CityEntry> citiesDictionary = Cities.ListOfCities.ToDictionary(cityEntry => cityEntry.City);

            _areaConfigs = userCityConfigs.CityConfigs.Where(userCityConfig => citiesDictionary.ContainsKey(userCityConfig.City))
                           .GroupBy(userCityConfig => citiesDictionary[userCityConfig.City].Id)
                           .Select(group => new AreaConfiguration(group.Key,
                                                                  group.Any(userCityConfig => userCityConfig.DisplayAlerts),
                                                                  group.Any(userCityConfig => userCityConfig.SoundAlerts)))
                           .ToDictionary(areaConfig => areaConfig.Area);

            _cityConfigs = userCityConfigs.CityConfigs.ToDictionary(cityConfig => cityConfig.City);

            if (userCityConfigs.Version == "1.0")
            {
                MessageBox.Show("רשימת היישובים עודכנה, אנא וודה נכונות ההגדרות.", "צבע אדום 1.7 by DxCK", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading);
                UserSettings.ShowUserSettings();
            }
        }
Example #2
0
        public static void RaiseConfigurationChangedEvent(UserConfigJson userConfig)
        {
            EventHandler <ConfigurationChangedEventArgs> configurationChanged = ConfigurationChanged;

            if (configurationChanged != null)
            {
                configurationChanged.Invoke(null, new ConfigurationChangedEventArgs(userConfig));
            }
        }
Example #3
0
        private void AreaSelector_Load(object sender, EventArgs e)
        {
            UserConfigJson userConfig = UserConfiguration.GetConfiguration();

            try
            {
                _checkedChangesFromCode = true;
                checkBox2.Checked       = (bool)userConfig.ShowConnectionNotifications;
                checkBox3.Checked       = (bool)userConfig.ShowAlertsFromUnknownAreas;
                checkBox1.Checked       = IsStartsOnStartup();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }
            finally
            {
                _checkedChangesFromCode = false;
            }

            Dictionary <string, UserCityConfig> userConfigDictionary = userConfig.CityConfigs.ToDictionary(x => x.City);

            List <UserCityConfig> finalUserConfig    = new List <UserCityConfig>();
            List <ListViewItem>   finalListViewItems = new List <ListViewItem>();

            for (int i = 0; i < Cities.ListOfCities.Count; i++)
            {
                string city = Cities.ListOfCities[i].City;

                UserCityConfig userCityConfig;

                if (!userConfigDictionary.TryGetValue(city, out userCityConfig))
                {
                    userCityConfig      = new UserCityConfig();
                    userCityConfig.City = city;
                }

                ListViewItem item = new ListViewItem(new string[] { userCityConfig.City, ToDisplay(userCityConfig.DisplayAlerts), ToDisplay(userCityConfig.SoundAlerts) });
                item.Tag = userCityConfig;

                finalUserConfig.Add(userCityConfig);
                finalListViewItems.Add(item);
            }

            _userConfig    = finalUserConfig.ToArray();
            _listViewItems = finalListViewItems.ToArray();

            RefillListView();
        }
Example #4
0
        public static void SaveConfiguration(UserConfigJson userCityConfigs)
        {
            try
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();

                string serializedJson = serializer.Serialize(userCityConfigs);

                File.WriteAllText(_configFilePath, serializedJson, Encoding.UTF8);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }

            RaiseConfigurationChangedEvent(userCityConfigs);
        }
Example #5
0
 public ConfigurationChangedEventArgs(UserConfigJson userConfig)
 {
     UserConfig = userConfig;
 }
Example #6
0
        public static UserConfigJson GetConfiguration()
        {
            try
            {
                string jsonConfig = File.ReadAllText(_configFilePath);

                if (!string.IsNullOrWhiteSpace(jsonConfig))
                {
                    JavaScriptSerializer serializer = new JavaScriptSerializer();

                    try
                    {
                        UserConfigJson userConfigJson = serializer.Deserialize <UserConfigJson>(jsonConfig);

                        if (!userConfigJson.ShowConnectionNotifications.HasValue)
                        {
                            userConfigJson.ShowConnectionNotifications = true;
                        }

                        if (!userConfigJson.ShowAlertsFromUnknownAreas.HasValue)
                        {
                            userConfigJson.ShowAlertsFromUnknownAreas = true;
                        }

                        string[] newCities = Cities.ListOfCities.Select(city => city.City).Except(userConfigJson.CityConfigs.Select(cityConfig => cityConfig.City)).ToArray();

                        if (newCities.Length > 0)
                        {
                            bool allDisplayAlerts = userConfigJson.CityConfigs.All(userCityConfig => userCityConfig.DisplayAlerts);
                            bool allSoundAlerts   = userConfigJson.CityConfigs.All(userCityConfig => userCityConfig.SoundAlerts);

                            IEnumerable <UserCityConfig> newCitiesConfigs = newCities.Select(city => new UserCityConfig(city, allDisplayAlerts, allSoundAlerts));

                            userConfigJson.CityConfigs = userConfigJson.CityConfigs.Concat(newCitiesConfigs).ToArray();
                        }


                        return(userConfigJson);
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex.ToString());
                    }

                    //version 1.0 config region
                    {
                        UserCityConfig[] version1Config = serializer.Deserialize <UserCityConfig[]>(jsonConfig);
                        Dictionary <string, UserCityConfig> version1ConfigDictionary = version1Config.ToDictionary(userCityConfig => userCityConfig.City);

                        bool allDisplayAlerts;
                        bool allSoundAlerts;

                        if (version1Config.Length == 1883)
                        {
                            allDisplayAlerts = version1Config.All(userCityConfig => userCityConfig.DisplayAlerts);
                            allSoundAlerts   = version1Config.All(userCityConfig => userCityConfig.SoundAlerts);
                        }
                        else
                        {
                            allDisplayAlerts = false;
                            allSoundAlerts   = false;
                        }

                        UserConfigJson convertedConfigJson = new UserConfigJson()
                        {
                            Version = "1.5",
                            ShowConnectionNotifications = true,
                            ShowAlertsFromUnknownAreas  = true,
                            CityConfigs = Cities.ListOfCities
                                          .Select(cityEntry =>
                            {
                                if (version1ConfigDictionary.ContainsKey(cityEntry.City))
                                {
                                    return(version1ConfigDictionary[cityEntry.City]);
                                }
                                else
                                {
                                    return(new UserCityConfig(cityEntry.City, allDisplayAlerts, allSoundAlerts));
                                }
                            })
                                          .ToArray()
                        };

                        try
                        {
                            SaveConfiguration(convertedConfigJson);
                        }
                        catch (Exception ex)
                        {
                            Trace.WriteLine(ex.ToString());
                        }

                        convertedConfigJson.Version = "1.0";
                        return(convertedConfigJson);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }

            //return default configuration
            return(new UserConfigJson()
            {
                Version = "1.5",
                ShowConnectionNotifications = true,
                ShowAlertsFromUnknownAreas = true,
                CityConfigs = Cities.ListOfCities.Select(cityEntry => new UserCityConfig(cityEntry.City, true, false)).ToArray()
            });
        }