Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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;
        }