Пример #1
0
 public void ResetFetch()
 {
     if (Commander != null)
     {
         KeyName(out string latestdatekeyname, out string oldestdatekeyname);
         SQLiteConnectionUser.DeleteKey(latestdatekeyname);
         SQLiteConnectionUser.DeleteKey(oldestdatekeyname);
     }
 }
Пример #2
0
        public bool UpdateProfiles(List <Profile> newset, int poweronindex)        // true reload - Current is invalid if true, must reload to new profile
        {
            List <Profile> toberemoved = new List <Profile>();

            foreach (Profile p in ProfileList)
            {
                Profile c = newset.Find(x => x.Id == p.Id);

                if (c == null)         // if newset does not have this profile ID
                {
                    toberemoved.Add(p);
                }
                else
                {                             // existing in both, update
                    System.Diagnostics.Debug.WriteLine("Update ID " + p.Id);
                    p.Name          = c.Name; // update name and condition
                    p.TripCondition = c.TripCondition;
                    p.BackCondition = c.BackCondition;
                }
            }

            bool removedcurrent = false;

            foreach (Profile p in toberemoved)
            {
                if (Object.ReferenceEquals(Current, p))
                {
                    removedcurrent = true;
                }

                System.Diagnostics.Debug.WriteLine("Delete ID " + p.Id);
                SQLiteConnectionUser.DeleteKey(ProfilePrefix(p.Id) + "%");       // all profiles string
                ProfileList.Remove(p);
            }

            foreach (Profile p in newset.Where((p) => p.Id == -1))
            {
                int[] curids = (from x in ProfileList select x.Id).ToArray();

                int id = DefaultId + 1;
                for (; id < 10000; id++)
                {
                    if (Array.IndexOf(curids, id) == -1)
                    {
                        break;
                    }
                }

                System.Diagnostics.Debug.WriteLine("Make ID " + id);
                p.Id = id;
                ProfileList.Add(p);
            }

            poweronindex = poweronindex >= 0 ? poweronindex : 0;
            SQLiteConnectionUser.PutSettingInt("ProfilePowerOnID", ProfileList[poweronindex].Id);
            PowerOn = ProfileList[poweronindex];

            SaveProfiles();
            History.Clear();        // because an ID may have gone awol

            return(removedcurrent);
        }