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;
        }