Beispiel #1
0
        public void Backup()
        {
            TCSavedData dataToSave = new TCSavedData();

            dataToSave.Counters = new SerializableDictionary <string, int>();

            try
            {
                string prefix = "on-";
                foreach (KeyValuePair <string, Counter> item in this.timers)
                {
                    string left4 = item.Key.Substring(0, 4);
                    if (left4 != "PART")
                    {
                        dataToSave.Counters.Add(item.Key, (item.Value as Counter).GetIntValue());

                        if ((item.Value as Counter).Enabled)
                        {
                            dataToSave.Counters.Add(prefix + item.Key, 1);
                        }
                    }
                }

                Serialization sAgent = new Serialization("serialization_tc" + this.id + ".dat");
                sAgent.Backup(dataToSave);
            }
            catch (Exception ex)
            {
                Console.WriteLine(DateTime.Now + " " + ex.TargetSite.ToString(), ex.Source, ex.ToString());
            }
        }
Beispiel #2
0
        public void Restore()
        {
            Serialization sAgent       = new Serialization("serialization_tc" + this.id + ".dat");
            TCSavedData   restoredData = new TCSavedData();

            try
            {
                restoredData = sAgent.Restore(restoredData);

                if (restoredData.Counters != null)
                {
                    foreach (KeyValuePair <string, int> restoredItem in restoredData.Counters)
                    {
                        if (this.timers.ContainsKey(restoredItem.Key))
                        {
                            this.timers[restoredItem.Key].SetValue(restoredItem.Value);
                        }

                        string prefix = "on-";
                        string onKey;
                        if (restoredItem.Key.Length > prefix.Length)
                        {
                            onKey = restoredItem.Key.Substring(prefix.Length);
                            if (this.timers.ContainsKey(onKey))
                            {
                                this.timers[onKey].Start();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(DateTime.Now + " " + ex.TargetSite.ToString(), ex.Source, ex.ToString());
            }
        }