PrepareSave() приватный Метод

Prepare for saving the configuration to disk. None of the modifications in this method need to be rolled back (for rollback, use OnSavePre / OnSavePost).
private PrepareSave ( ) : void
Результат void
Пример #1
0
        private static bool SaveConfigFileEx(AppConfigEx tConfig,
                                             string strFilePath, bool bRemoveConfigPref)
        {
            tConfig.PrepareSave();

            XmlSerializer xmlSerial = new XmlSerializer(typeof(AppConfigEx));
            FileStream    fs        = null;
            bool          bResult   = true;

            // Temporarily remove user file preference (restore after saving)
            bool bConfigPref = tConfig.Meta.PreferUserConfiguration;

            if (bRemoveConfigPref)
            {
                tConfig.Meta.PreferUserConfiguration = false;
            }

            XmlWriterSettings xws = new XmlWriterSettings();

            xws.Encoding    = Encoding.UTF8;
            xws.Indent      = true;
            xws.IndentChars = "\t";

            try
            {
                fs = new FileStream(strFilePath, FileMode.Create,
                                    FileAccess.Write, FileShare.None);

                XmlWriter xw = XmlWriter.Create(fs, xws);

                xmlSerial.Serialize(xw, tConfig);

                xw.Close();
            }
            catch (Exception) { bResult = false; }            // Do not assert

            if (fs != null)
            {
                fs.Close(); fs = null;
            }

            if (bRemoveConfigPref)
            {
                tConfig.Meta.PreferUserConfiguration = bConfigPref;
            }

            return(bResult);
        }
Пример #2
0
        private static bool SaveConfigFileEx(AppConfigEx tConfig,
            string strFilePath, bool bRemoveConfigPref)
        {
            tConfig.PrepareSave();

            XmlSerializer xmlSerial = new XmlSerializer(typeof(AppConfigEx));
            FileStream fs = null;
            bool bResult = true;

            // Temporarily remove user file preference (restore after saving)
            bool bConfigPref = tConfig.Meta.PreferUserConfiguration;
            if(bRemoveConfigPref) tConfig.Meta.PreferUserConfiguration = false;

            XmlWriterSettings xws = new XmlWriterSettings();
            xws.Encoding = Encoding.UTF8;
            xws.Indent = true;
            xws.IndentChars = "\t";

            try
            {
                fs = new FileStream(strFilePath, FileMode.Create,
                    FileAccess.Write, FileShare.None);

                XmlWriter xw = XmlWriter.Create(fs, xws);

                xmlSerial.Serialize(xw, tConfig);

                xw.Close();
            }
            catch(Exception) { bResult = false; } // Do not assert

            if(fs != null) { fs.Close(); fs = null; }

            if(bRemoveConfigPref) tConfig.Meta.PreferUserConfiguration = bConfigPref;

            return bResult;
        }