示例#1
0
        public async void SaveFileAsync(ServerSettings settingsToSave, string filename)
        {
            await semaphore.WaitAsync();

            try
            {
                ServerSettingsFile file = new ServerSettingsFile(errorLogger);
                file.Initialise(settingsToSave);
                string contents = file.ToXML();
                if (contents != null)
                {
                    if (!filename.EndsWith(".xml"))
                    {
                        filename += ".xml";
                    }
                    File.WriteAllText(Path.Combine(saveDirectory, filename), contents);
                }
            }
            catch (Exception ex)
            {
                errorLogger.LogException(ex, ErrorSeverity.Error);
            }

            semaphore.Release();
        }
示例#2
0
        /// <summary>
        /// Loads command XML files present in the saveDirectory into <see cref="CommandFile"/>s
        /// </summary>
        /// <returns></returns>
        public List <ServerSettingsFile> LoadFiles()
        {
            List <ServerSettingsFile> result = new List <ServerSettingsFile>();

            foreach (var path in Directory.EnumerateFiles(saveDirectory))
            {
                string             contents = File.ReadAllText(path);
                ServerSettingsFile file     = new ServerSettingsFile(errorLogger);
                bool loaded = file.FromXML(contents);
                if (loaded)
                {
                    result.Add(file);
                }
            }

            return(result);
        }