コード例 #1
0
        /// <summary>Save the given object into a file</summary>
        /// <param name="ConfigObject">The object to save</param>
        /// <param name="Filename">The filename the objects should get</param>
        /// <exception cref="ArgumentException" />
        /// <exception cref="ArgumentNullException" />
        /// <exception cref="ArgumentOutOfRangeException" />
        /// <exception cref="DirectoryNotFoundException" />
        /// <exception cref="FileNotFoundException" />
        /// <exception cref="IOException" />
        /// <exception cref="InvalidOperationException" />
        /// <exception cref="NotSupportedException" />
        /// <exception cref="PathTooLongException" />
        /// <exception cref="UnauthorizedAccessException" />
        /// <exception cref="System.Security.SecurityException" />
        public static void SaveConfig(Object ConfigObject, String Filename)
        {
            //Get file info on the file to save to
            String          Filepath = ConfigOptions.ConfigFolder + Filename + ConfigOptions.ConfigExtension;
            var             FI       = new FileInfo(Filepath);
            EventWaitHandle Lock     = ConfigLoader.GetLock(Filepath);

            //Check parent directory
            DirectoryInfo DI = FI.Directory;

            //Create if missing
            if (!DI.Exists)
            {
                DI.Create();
            }

            //Setup
            IConfigSerializer <Object> serializer = null;
            FileStream writer = null;

            Lock.WaitOne();
#if !DEBUG
            try {
#endif
            //Assign serializer and stream
            serializer = ConfigLoader._SerializerFactory.GetSerializer(ConfigObject.GetType());
            writer     = new FileStream(FI.FullName, FileMode.Create);

            //Serialize object
            serializer.Serialize(ConfigObject, writer);

            //Flush and close
            writer.Flush();
            writer.Close();
#if !DEBUG
        }
#pragma warning disable 168
        catch (Exception ex) {
#pragma warning restore 168
            //Close stream if open
            if (writer != null)
            {
                writer.Close();
            }

            ErrorSaving(Filepath, ex);
        }
#endif

            Lock.Set();
        }
コード例 #2
0
        /// <summary>
        /// Save application settings to the file
        /// </summary>
        /// <param name="settings"></param>
        public void Save(T settings)
        {
            var data = _serializer.Serialize(settings);

            SaveFileToTheDisk(data);
        }
コード例 #3
0
 public void SaveConfig(IConfig config, string pathToConfigFile)
 {
     fileSystem.File.WriteAllText(pathToConfigFile, configSerializer.Serialize(config));
 }
コード例 #4
0
ファイル: Config.cs プロジェクト: xuejwei/lol-clientless-bot
 public void Save(string fileName, IConfigSerializer serializer)
 {
     using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
         serializer.Serialize(fs, this);
 }