Beispiel #1
0
        /// <summary>
        ///     Load a config file
        /// </summary>
        /// <param name="location"></param>
        public static void LoadFile(string location = "")
        {
            if (string.IsNullOrEmpty(location))
            {
                location = DefaultFileLocation.Location(RequestFile.Config) + CteFileName;
            }

            _filepath = location;


            Logger.Log(LogLevel.Info, "Config", "Loading file", _filepath);

            if (!File.Exists(_filepath))
            {
                Logger.Log(LogLevel.Info, "Config", "Creating config file");
                DirectoryInfo dirInfo = new FileInfo(_filepath).Directory;
                if (dirInfo != null)
                {
                    string parent = dirInfo.ToString();
                    Util.FsUtil.CreateDirectoryIfNotExists(parent);
                }

                FileStream   fs = File.Create(_filepath);
                StreamWriter sw = new StreamWriter(fs);
                sw.WriteLine("<xml></xml>");
                sw.Close();
                fs.Close();
            }

            _xmldoc = new XmlDocument();
            _xmldoc.Load(_filepath);

            LoadCache(); //everything's cached, we're ready to go
        }
Beispiel #2
0
        /// <summary>
        ///     Initialize everything, create cache
        /// </summary>
        public static void Initialize()
        {
            string location = Config.ReadString("Locale", "File", DefaultFileLocation.Location(RequestFile.Config) + "/default.xml");

            _filepath = location;

            if (!File.Exists(_filepath))
            {
                DirectoryInfo dirInfo = new FileInfo(_filepath).Directory;
                if (dirInfo != null)
                {
                    string parent = dirInfo.ToString();
                    Util.FsUtil.CreateDirectoryIfNotExists(parent);
                }

                FileStream   fs = File.Create(_filepath);
                StreamWriter sw = new StreamWriter(fs);
                sw.WriteLine(XmlHead + XmlTail);
                sw.Close();
                fs.Close();
            }

            _xmldoc = new XmlDocument();
            _xmldoc.Load(_filepath);

            LoadCache();             //everything's cached, we're ready to go
            IsInitialized = true;
        }
Beispiel #3
0
        /// <summary>
        ///     Save a config file
        /// </summary>
        /// <param name="location"></param>
        public static void SaveFile(string location = "")
        {
            if (string.IsNullOrEmpty(location))
            {
                location = DefaultFileLocation.Location(RequestFile.Config) + CteFileName;
            }

            if (_cache.Count == 0)
            {
                Logger.Log(LogLevel.Debug, "Config", "Didn't save file: nothing to save");
                return;
            }

            _filepath = location;

            Logger.Log(LogLevel.Info, "Config", "Saving file", _filepath);

            SaveCache();
        }