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

private OnSavePost ( ) : void
Результат void
Пример #1
0
        private static bool SaveConfigFileEx(AppConfigEx tConfig,
                                             string strFilePath, bool bRemoveConfigPref)
        {
            tConfig.OnSavePre();

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

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

            bool bResult = true;

            try
            {
                Debug.Assert(!string.IsNullOrEmpty(strFilePath));
                IOConnectionInfo iocPath = IOConnectionInfo.FromPath(strFilePath);

                using (FileTransactionEx ft = new FileTransactionEx(iocPath,
                                                                    Program.Config.Application.UseTransactedConfigWrites))
                {
                    using (Stream s = ft.OpenWrite())
                    {
                        using (XmlWriter xw = XmlUtilEx.CreateXmlWriter(s))
                        {
                            XmlSerializerEx xs = new XmlSerializerEx(typeof(AppConfigEx));
                            xs.Serialize(xw, tConfig);
                        }
                    }

                    ft.CommitWrite();
                }
            }
            catch (Exception) { Debug.Assert(false); bResult = false; }

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

            AssertConfigPref(tConfig);

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

            XmlSerializerEx xmlSerial = new XmlSerializerEx(typeof(AppConfigEx));
            bool bResult = true;

            // FileStream fs = null;
            IOConnectionInfo iocPath = IOConnectionInfo.FromPath(strFilePath);
            FileTransactionEx fts = new FileTransactionEx(iocPath, true);
            Stream fs = null;

            // 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 = StrUtil.Utf8;
            xws.Indent = true;
            xws.IndentChars = "\t";

            try
            {
                // fs = new FileStream(strFilePath, FileMode.Create,
                //	FileAccess.Write, FileShare.None);
                fs = fts.OpenWrite();
                if(fs == null) throw new InvalidOperationException();

                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(bResult)
            {
                try { fts.CommitWrite(); }
                catch(Exception) { Debug.Assert(false); }
            }

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

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

            XmlSerializerEx xmlSerial = new XmlSerializerEx(typeof(AppConfigEx));
            bool            bResult   = true;

            // FileStream fs = null;
            IOConnectionInfo  iocPath = IOConnectionInfo.FromPath(strFilePath);
            FileTransactionEx fts     = new FileTransactionEx(iocPath, true);
            Stream            fs      = null;

            // 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    = StrUtil.Utf8;
            xws.Indent      = true;
            xws.IndentChars = "\t";

            try
            {
                // fs = new FileStream(strFilePath, FileMode.Create,
                //	FileAccess.Write, FileShare.None);
                fs = fts.OpenWrite();
                if (fs == null)
                {
                    throw new InvalidOperationException();
                }

                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 (bResult)
            {
                try { fts.CommitWrite(); }
                catch (Exception) { Debug.Assert(false); }
            }

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

            tConfig.OnSavePost();
            return(bResult);
        }