예제 #1
0
        public static Cities Get()
        {
            Cities c = new Cities();
            try
            {
                var container = RoamingSettingsHelper.GetContainer("Cities");
                var subContainer = container.GetContainer("Locate");
                var enumContainer = container.GetContainer("Routes");
                c.CurrentIndex = (int)container.Values["CurrentIndex"];
                c.EnableLocate = (bool)container.Values["EnableLocate"];
                CitySettingsModel loc;

                if (subContainer.ReadGroupSettings(out loc))
                {
                    if (loc.City != null && loc.Id != null)
                    {
                        c.LocatedCity = loc;
                        if (c.CurrentIndex == -1)
                        {
                            if (c.EnableLocate == true)
                                c.LocatedCity.IsCurrent = true;
                            else
                            {
                                c.CurrentIndex = 0;
                            }
                        }
                    }
                }

                int i = (int)container.Values["Count"];
                List<CitySettingsModel> cs = new List<CitySettingsModel>();
                for (int j = 0; j < i; j++)
                {
                    CitySettingsModel m;
                    var sub = RoamingSettingsHelper.GetContainer(j.ToString());
                    if (sub.ReadGroupSettings(out m))
                    {
                        cs.Add(m);
                    }
                }
                c.SavedCities = cs.ToArray();
                if (c.CurrentIndex != -1 && !c.SavedCities.IsNullorEmpty())
                {
                    c.SavedCities[c.CurrentIndex].IsCurrent = true;
                }
                int l = (int)enumContainer.Values["Count"];
                List<LocateRoute> li = new List<LocateRoute>();
                for (int m = 0; m < l; m++)
                {
                    var toure = (LocateRoute)Enum.Parse(typeof(LocateRoute), (string)enumContainer.ReadSettingsValue(m.ToString()));
                    li.Add(toure);
                }
                c.Routes = li.ToArray();
                return c;
            }
            catch (Exception)
            {
                if (c.SavedCities == null)
                {
                    c.SavedCities = new CitySettingsModel[] { };
                }
                return c;
            }
        }
예제 #2
0
        public static Cities Get()
        {
            Cities c = new Cities();

            try
            {
                var container     = RoamingSettingsHelper.GetContainer("Cities");
                var subContainer  = container.GetContainer("Locate");
                var enumContainer = container.GetContainer("Routes");
                c.CurrentIndex = (int)container.Values["CurrentIndex"];
                c.EnableLocate = (bool)container.Values["EnableLocate"];
                CitySettingsModel loc;

                if (subContainer.ReadGroupSettings(out loc))
                {
                    if (loc.City != null && loc.Id != null)
                    {
                        c.LocatedCity = loc;
                        if (c.CurrentIndex == -1)
                        {
                            if (c.EnableLocate == true)
                            {
                                c.LocatedCity.IsCurrent = true;
                            }
                            else
                            {
                                c.CurrentIndex = 0;
                            }
                        }
                    }
                }

                int i = (int)container.Values["Count"];
                List <CitySettingsModel> cs = new List <CitySettingsModel>();
                for (int j = 0; j < i; j++)
                {
                    CitySettingsModel m;
                    var sub = RoamingSettingsHelper.GetContainer(j.ToString());
                    if (sub.ReadGroupSettings(out m))
                    {
                        cs.Add(m);
                    }
                }
                c.SavedCities = cs.ToArray();
                if (c.CurrentIndex != -1 && !c.SavedCities.IsNullorEmpty())
                {
                    c.SavedCities[c.CurrentIndex].IsCurrent = true;
                }
                int l = (int)enumContainer.Values["Count"];
                List <LocateRoute> li = new List <LocateRoute>();
                for (int m = 0; m < l; m++)
                {
                    var toure = (LocateRoute)Enum.Parse(typeof(LocateRoute), (string)enumContainer.ReadSettingsValue(m.ToString()));
                    li.Add(toure);
                }
                c.Routes = li.ToArray();
                return(c);
            }
            catch (Exception)
            {
                if (c.SavedCities == null)
                {
                    c.SavedCities = new CitySettingsModel[] { };
                }
                return(c);
            }
        }