/// <summary> /// (Thread Safe) Save state to persistant store /// </summary> public void Save() { lock (this.saveLock) { SmokeSignalConfig.SaveToStore(this); } }
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; }
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); }
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); }
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; }
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(); }
private static void SaveToStore(SmokeSignalConfig ss) { SmokeSignalConfig.SaveToStore(ss, BackingStoreDir); }