Example #1
0
 public TestFileTransaction(IOConnectionInfo ioc, bool useFileTransaction, bool offline)
 {
     _offline = offline;
     _transaction = new FileTransactionEx(ioc, useFileTransaction);
 }
Example #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;
        }
Example #3
0
 public BuiltInFileTransaction(IOConnectionInfo ioc, bool useFileTransaction, BuiltInFileStorage fileStorage)
 {
     _ioc = ioc;
     _fileStorage = fileStorage;
     _transaction = new FileTransactionEx(ioc, useFileTransaction);
 }