Exemplo n.º 1
0
 /// <summary>
 /// (Thread Safe) Save state to persistant store
 /// </summary>
 public void Save()
 {
     lock (this.saveLock)
     {
         SmokeSignalConfig.SaveToStore(this);
     }
 }
Exemplo n.º 2
0
        public static bool Initialize(string storePath)
        {
            bool success = true;
            if (Instance == null)
            {
                Instance = Restore(storePath);

                if (Instance == null)
                {
                    // Data in the xml file was corrupt/unreadable
                    success = false;
                    Instance = new SmokeSignalConfig();
                }
            }
            return success;
        }
Exemplo n.º 3
0
        private static SmokeSignalConfig Restore(string dirPath)
        {
            BackingStoreDir = dirPath;
            string fullPath = BackingStoreFile;

            SmokeSignalConfig smokeSignalInfo = null;
            bool error = false;

            if (!System.IO.File.Exists(fullPath))
            {
                // create & save a new file
                smokeSignalInfo = new SmokeSignalConfig();
                smokeSignalInfo.Save();
                return(smokeSignalInfo);
            }

            Exception caughtException = null;

            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(fullPath);

                XmlSerializer ser = new XmlSerializer(typeof(SmokeSignalConfig));
                using (StringReader reader = new StringReader(xmlDoc.OuterXml))
                {
                    smokeSignalInfo = (SmokeSignalConfig)ser.Deserialize(reader);
                    reader.Close();
                }
            }
            catch (XmlException ex) { caughtException = ex; }
            catch (IOException ex) { caughtException = ex; }
            catch (UnauthorizedAccessException ex) { caughtException = ex; }
            catch (System.Security.SecurityException ex) { caughtException = ex; }
            catch (InvalidOperationException ex) { caughtException = ex; }
            catch (ApplicationException ex) { caughtException = ex; }

            if (caughtException != null)
            {
                // xml file was corrupt. Make a backup and delete original
                Utils.TraceException(TraceLevel.Warning, caughtException, string.Format("SmokeSignalConfig.xml was corrupt. Making a backup and starting with a new file."));
                error = Utils.SafeBackupAndDelete(fullPath);
            }

            return(smokeSignalInfo);
        }
Exemplo n.º 4
0
        public static bool Initialize(string storePath)
        {
            bool success = true;

            if (Instance == null)
            {
                Instance = Restore(storePath);

                if (Instance == null)
                {
                    // Data in the xml file was corrupt/unreadable
                    success  = false;
                    Instance = new SmokeSignalConfig();
                }
            }
            return(success);
        }
Exemplo n.º 5
0
        private static SmokeSignalConfig Restore(string dirPath)
        {
            BackingStoreDir = dirPath;
            string fullPath = BackingStoreFile;

            SmokeSignalConfig smokeSignalInfo = null;
            bool error = false;

            if (!System.IO.File.Exists(fullPath))
            {
                // create & save a new file
                smokeSignalInfo = new SmokeSignalConfig();
                smokeSignalInfo.Save();
                return smokeSignalInfo;
            }

            Exception caughtException = null;
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(fullPath);

                XmlSerializer ser = new XmlSerializer(typeof(SmokeSignalConfig));
                using (StringReader reader = new StringReader(xmlDoc.OuterXml))
                {
                    smokeSignalInfo = (SmokeSignalConfig)ser.Deserialize(reader);
                    reader.Close();
                }
            }
            catch (XmlException ex) { caughtException = ex; }
            catch (IOException ex) { caughtException = ex; }
            catch (UnauthorizedAccessException ex) { caughtException = ex; }
            catch (System.Security.SecurityException ex) { caughtException = ex; }
            catch (InvalidOperationException ex) { caughtException = ex; }
            catch (ApplicationException ex) { caughtException = ex; }

            if (caughtException != null)
            {
                // xml file was corrupt. Make a backup and delete original
                Utils.TraceException(TraceLevel.Warning, caughtException, string.Format("SmokeSignalConfig.xml was corrupt. Making a backup and starting with a new file."));
                error = Utils.SafeBackupAndDelete(fullPath);
            }

            return smokeSignalInfo;
        }
Exemplo n.º 6
0
        public static void SaveToStore(SmokeSignalConfig ss, string dirPath)
        {
            string fullPath = Path.Combine(dirPath, "SmokeSignalConfig.xml");

            if (!System.IO.File.Exists(fullPath))
            {
                if (!System.IO.Directory.Exists(dirPath))
                {
                    System.IO.Directory.CreateDirectory(dirPath);
                }
            }

            XmlSerializer ser = new XmlSerializer(typeof(SmokeSignalConfig));

            System.IO.StreamWriter file = new System.IO.StreamWriter(fullPath);

            ser.Serialize(file, ss);
            file.Close();
        }
Exemplo n.º 7
0
 private static void SaveToStore(SmokeSignalConfig ss)
 {
     SmokeSignalConfig.SaveToStore(ss, BackingStoreDir);
 }
Exemplo n.º 8
0
 private static void SaveToStore(SmokeSignalConfig ss)
 {
     SmokeSignalConfig.SaveToStore(ss, BackingStoreDir);
 }
Exemplo n.º 9
0
        public static void SaveToStore(SmokeSignalConfig ss, string dirPath)
        {
            string fullPath = Path.Combine(dirPath, "SmokeSignalConfig.xml");

            if (!System.IO.File.Exists(fullPath))
            {
                if (!System.IO.Directory.Exists(dirPath))
                {
                    System.IO.Directory.CreateDirectory(dirPath);
                }
            }

            XmlSerializer ser = new XmlSerializer(typeof(SmokeSignalConfig));

            System.IO.StreamWriter file = new System.IO.StreamWriter(fullPath);

            ser.Serialize(file, ss);
            file.Close();
        }