Пример #1
0
        public void EmptyConstructor()
        {
            string filePath = "EmptyConstructor.xml";
            XmlConfigSource source = new XmlConfigSource ();

            IConfig config = source.AddConfig ("Pets");
            config.Set ("cat", "Muffy");
            config.Set ("dog", "Rover");
            config.Set ("bird", "Tweety");
            source.Save (filePath);

            Assert.AreEqual (3, config.GetKeys ().Length);
            Assert.AreEqual ("Muffy", config.Get ("cat"));
            Assert.AreEqual ("Rover", config.Get ("dog"));
            Assert.AreEqual ("Tweety", config.Get ("bird"));

            source = new XmlConfigSource (filePath);
            config = source.Configs["Pets"];

            Assert.AreEqual (3, config.GetKeys ().Length);
            Assert.AreEqual ("Muffy", config.Get ("cat"));
            Assert.AreEqual ("Rover", config.Get ("dog"));
            Assert.AreEqual ("Tweety", config.Get ("bird"));

            File.Delete (filePath);
        }
Пример #2
0
 static AutoUpdateHepler()
 {
     string str = FileUtility.ApplicationRootPath + @"\update";
     if (LoggingService.IsInfoEnabled)
     {
         LoggingService.Info("读取升级配置:" + str);
     }
     XmlConfigSource source = null;
     if (System.IO.File.Exists(str + ".cxml"))
     {
         XmlTextReader decryptXmlReader = new CryptoHelper(CryptoTypes.encTypeDES).GetDecryptXmlReader(str + ".cxml");
         IXPathNavigable document = new XPathDocument(decryptXmlReader);
         source = new XmlConfigSource(document);
         decryptXmlReader.Close();
     }
     else if (System.IO.File.Exists(str + ".xml"))
     {
         source = new XmlConfigSource(str + ".xml");
     }
     if (source != null)
     {
         softName = source.Configs["FtpSetting"].GetString("SoftName", string.Empty);
         version = source.Configs["FtpSetting"].GetString("Version", string.Empty);
         server = source.Configs["FtpSetting"].GetString("Server", string.Empty);
         user = source.Configs["FtpSetting"].GetString("User", string.Empty);
         password = source.Configs["FtpSetting"].GetString("Password", string.Empty);
         path = source.Configs["FtpSetting"].GetString("Path", string.Empty);
         liveup = source.Configs["FtpSetting"].GetString("LiveUp", string.Empty);
         autoupdate = source.Configs["FtpSetting"].GetString("autoupdate", string.Empty);
     }
 }
Пример #3
0
 public static bool HasNewVesion()
 {
     try
     {
         if (!string.IsNullOrEmpty(server))
         {
             WebRequest request = WebRequest.Create(string.Format("ftp://{0}/{1}/update.xml", server, softName));
             request.Credentials = new NetworkCredential(user, password);
             WebResponse response = request.GetResponse();
             XmlDocument document = new XmlDocument();
             document.Load(response.GetResponseStream());
             XmlConfigSource source = new XmlConfigSource(document);
             if (source.Configs["FtpSetting"].GetString("Version").CompareTo(version) > 0)
             {
                 LoggingService.InfoFormatted("系统有新版本:{0}", new object[] { source.Configs["FtpSetting"].GetString("Version") });
                 return true;
             }
         }
     }
     catch (Exception exception)
     {
         LoggingService.Error("查询是否有新版本时出错", exception);
     }
     return false;
 }
Пример #4
0
 private static XmlConfigSource GetConfig(string cfgFileName)
 {
     XmlConfigSource source = null;
     if (configs.ContainsKey(cfgFileName))
     {
         return configs[cfgFileName];
     }
     string filename = cfgFileName;
     int num = filename.LastIndexOf('.');
     if (filename.EndsWith(".config") && File.Exists(filename.Insert(num + 1, "c")))
     {
         filename = filename.Insert(num + 1, "c");
         LoggingService.DebugFormatted("读取的是加密的配置文件:{0}", new object[] { filename });
         CryptoHelper helper = new CryptoHelper(CryptoTypes.encTypeDES);
         using (XmlTextReader reader = helper.GetDecryptXmlReader(filename))
         {
             XPathDocument document = new XPathDocument(reader);
             source = new XmlConfigSource(document);
             goto Label_00B8;
         }
     }
     if (!File.Exists(filename))
     {
         throw new ArgumentOutOfRangeException(cfgFileName + "不存在");
     }
     source = new XmlConfigSource(filename);
     Label_00B8:
     configs.Add(cfgFileName, source);
     return source;
 }
Пример #5
0
        public string CheckForUpdates(string clientVersion)
        {
            var response = string.Empty;

            try
            {
                if (!Directory.Exists(_dir + @"\Ester"))
                {
                    throw new Exception("Cannot find Ester folder on server");
                }

                _clientConfigSource = new XmlConfigSource(Path.Combine(HttpRuntime.AppDomainAppPath, @"Resources\Ester\Config.xml")) { AutoSave = true };
                int clientVersionNumber;
                if (int.TryParse(clientVersion, out clientVersionNumber))
                {
                    if (clientVersionNumber < GetLastVersionNumber())
                    {
                        response = _configSource.Configs["Update"].Get("UpdateFileUrl");
                    }
                }
            }
            catch (Exception exception)
            {
                WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.InternalServerError;
                WebOperationContext.Current.OutgoingResponse.StatusDescription = exception.Message;
            }

            return response;
        }
		public void Merge ()
		{
			StringWriter textWriter = new StringWriter ();
			XmlTextWriter xmlWriter = NiniWriter (textWriter);
			WriteSection (xmlWriter, "Pets");
			WriteKey (xmlWriter, "cat", "muffy");
			WriteKey (xmlWriter, "dog", "rover");
			WriteKey (xmlWriter, "bird", "tweety");
			xmlWriter.WriteEndDocument ();
			
			StringReader reader = new StringReader (textWriter.ToString ());
			XmlTextReader xmlReader = new XmlTextReader (reader);
			XmlConfigSource xmlSource = new XmlConfigSource (xmlReader);
			
			StringWriter writer = new StringWriter ();
			writer.WriteLine ("[People]");
			writer.WriteLine (" woman = Jane");
			writer.WriteLine (" man = John");
			IniConfigSource iniSource = 
					new IniConfigSource (new StringReader (writer.ToString ()));
			
			xmlSource.Merge (iniSource);
			
			IConfig config = xmlSource.Configs["Pets"];
			Assert.AreEqual (3, config.GetKeys ().Length);
			Assert.AreEqual ("muffy", config.Get ("cat"));
			Assert.AreEqual ("rover", config.Get ("dog"));
			
			config = xmlSource.Configs["People"];
			Assert.AreEqual (2, config.GetKeys ().Length);
			Assert.AreEqual ("Jane", config.Get ("woman"));
			Assert.AreEqual ("John", config.Get ("man"));
		}
Пример #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PluginSettingsBase"/> class.
        /// </summary>
        /// <param name="pluginName">Name of the plugin.</param>
        public PluginSettingsBase(string pluginName)
        {
            var fileName = string.Format("{0}\\Probel\\nDoctor\\{1}.plugin.config"
                   , Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
                   , pluginName);

            if (!File.Exists(fileName)) { this.BuildDefaultFileStream(fileName); }

            Source = new XmlConfigSource(fileName);
        }
Пример #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GeneralSettings"/> class.
        /// </summary>
        /// <remarks>
        /// Internal to prevent construction of this class by any other
        /// assembly.  This class is intended to be constructed by the
        /// <see cref="Configuration"/> class only.
        /// </remarks>
        /// <param name="configurationSource">Reference to the
        /// configuration source that contains the configuration file.</param>
        internal GeneralSettings(XmlConfigSource configurationSource)
        {
            _config = configurationSource.Configs["General"];

            if (_config == null)
            {
                _config = configurationSource.AddConfig("General");
                SetDefaults();
            }
        }
Пример #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DatabaseSettings"/> class.
        /// </summary>
        /// <remarks>
        /// Internal to prevent construction of this class by any other
        /// assembly.  This class is intended to be constructed by the
        /// <see cref="Configuration"/> class only.
        /// </remarks>
        /// <param name="configurationSource">Reference to the
        /// configuration source that contains the configuration file.</param>
        internal DatabaseSettings(XmlConfigSource configurationSource)
        {
            _config = configurationSource.Configs["Database"];

            if (_config == null)
            {
                _config = configurationSource.AddConfig("Database");
                SetDefaults();
            }
        }
Пример #10
0
        public void GetConfig()
        {
            StringWriter textWriter = new StringWriter ();
            XmlTextWriter writer = NiniWriter (textWriter);
            WriteSection (writer, "Pets");
            WriteKey (writer, "cat", "muffy");
            WriteKey (writer, "dog", "rover");
            WriteKey (writer, "bird", "tweety");
            writer.WriteEndDocument ();

            StringReader reader = new StringReader (textWriter.ToString ());
            XmlTextReader xmlReader = new XmlTextReader (reader);
            XmlConfigSource source = new XmlConfigSource (xmlReader);

            IConfig config = source.Configs["Pets"];
            Assert.AreEqual ("Pets", config.Name);
            Assert.AreEqual (3, config.GetKeys ().Length);
            Assert.AreEqual (source, config.ConfigSource);
        }
Пример #11
0
 static SupportClass()
 {
     string path = Path.Combine(DAOConfigsPath, "DAO.config");
     LoggingService.DebugFormatted("查找DAO配置文件:{0}", new object[] { path });
     if (File.Exists(path))
     {
         config = new XmlConfigSource(path);
     }
     else
     {
         path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path);
         LoggingService.DebugFormatted("查找DAO配置文件:{0}", new object[] { path });
         if (File.Exists(path))
         {
             config = new XmlConfigSource(path);
         }
     }
     if (config == null)
     {
         LoggingService.Warn("没有找到DAO配置文件...");
     }
 }
		public void GetString ()
		{
			StringWriter textWriter = new StringWriter ();
			XmlTextWriter writer = NiniWriter (textWriter);
			WriteSection (writer, "Pets");
			WriteKey (writer, "cat", "muffy");
			WriteKey (writer, "dog", "rover");
			WriteKey (writer, "bird", "tweety");
			writer.WriteEndDocument ();
			
			StringReader reader = new StringReader (textWriter.ToString ());
			XmlTextReader xmlReader = new XmlTextReader (reader);
			XmlConfigSource source = new XmlConfigSource (xmlReader);

			IConfig config = source.Configs["Pets"];
			
			Assert.AreEqual ("muffy", config.Get ("cat"));
			Assert.AreEqual ("rover", config.Get ("dog"));
			Assert.AreEqual ("muffy", config.GetString ("cat"));
			Assert.AreEqual ("rover", config.GetString ("dog"));
			Assert.AreEqual ("my default", config.Get ("Not Here", "my default"));
			Assert.IsNull (config.Get ("Not Here 2"));
		}
Пример #13
0
 static SupportClass()
 {
     string path = Path.Combine(DataFormsConfigPath, source);
     if (File.Exists(path))
     {
         config = new XmlConfigSource(path);
     }
     else
     {
         path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, source);
         if (File.Exists(path))
         {
             config = new XmlConfigSource(path);
         }
     }
     if (config == null)
     {
         throw new NullReferenceException("找不到表单配置文件:" + path);
     }
     string[] keys = config.Configs["DataBindProperty"].GetKeys();
     DBPKeys = new StringCollection();
     DBPKeys.AddRange(keys);
 }
Пример #14
0
        /// <summary>
        /// Provide same ini loader functionality for standard ini and master ini - file system or XML over http
        /// </summary>
        /// <param name="iniPath">Full path to the ini</param>
        /// <returns></returns>
        private bool ReadConfig(string iniPath)
        {
            bool success = false;

            if (!IsUri(iniPath))
            {
                m_log.InfoFormat("[CONFIG] Reading configuration file {0}",
                        Path.GetFullPath(iniPath));

                m_config.Merge(new IniConfigSource(iniPath));
                success = true;
            }
            else
            {
                m_log.InfoFormat("[CONFIG] {0} is a http:// URI, fetching ...",
                        iniPath);

                // The ini file path is a http URI
                // Try to read it
                //
                try
                {
                    XmlReader r = XmlReader.Create(iniPath);
                    XmlConfigSource cs = new XmlConfigSource(r);
                    m_config.Merge(cs);

                    success = true;
                }
                catch (Exception e)
                {
                    m_log.FatalFormat("[CONFIG] Exception reading config from URI {0}\n" + e.ToString(), iniPath);
                    Environment.Exit(1);
                }
            }
            return success;
        }
Пример #15
0
        /// <summary>
        /// Provide same ini loader functionality for standard ini and master ini - file system or XML over http
        /// </summary>
        /// <param name="iniPath">Full path to the ini</param>
        /// <returns></returns>
        private bool ReadConfig(string iniPath, int i)
        {
            bool success = false;

            if (!IsUri(iniPath))
            {
                if(showIniLoading)
                    m_log.InfoFormat("[CONFIG]: Reading configuration file {0}", Path.GetFullPath(iniPath));

                m_config.Merge(new IniConfigSource(iniPath, Nini.Ini.IniFileType.AuroraStyle));
                if (inidbg)
                {
                    WriteConfigFile(i, m_config);
                }
                success = true;
            }
            else
            {
                m_log.InfoFormat("[CONFIG]: {0} is a http:// URI, fetching ...", iniPath);

                // The ini file path is a http URI
                // Try to read it
                try
                {
                    XmlReader r = XmlReader.Create(iniPath);
                    XmlConfigSource cs = new XmlConfigSource(r);
                    m_config.Merge(cs);

                    success = true;
                }
                catch (Exception e)
                {
                    m_log.FatalFormat("[CONFIG]: Exception reading config from URI {0}\n" + e.ToString(), iniPath);
                    Environment.Exit(1);
                }
            }
            return success;
        }
Пример #16
0
        /// <summary>
        /// Creates a new config file.
        /// </summary>
        private void CreateNewFile()
        {
            string type = null;;

            if (IsArg ("set-type")) {
                type = GetArg ("set-type").ToLower ();
            } else {
                ThrowError ("You must supply a type (--set-type)");
            }

            switch (type)
            {
            case "ini":
                IniConfigSource iniSource = new IniConfigSource ();
                iniSource.Save (configPath);
                break;
            case "xml":
                XmlConfigSource xmlSource = new XmlConfigSource ();
                xmlSource.Save (configPath);
                break;
            case "config":
                DotNetConfigSource dotnetSource = new DotNetConfigSource ();
                dotnetSource.Save (configPath);
                break;
            default:
                ThrowError ("Unknown type");
                break;
            }
        }
Пример #17
0
        /// <summary>
        /// Loads a sourc from file.
        /// </summary>
        private IConfigSource LoadSource(string path)
        {
            IConfigSource result = null;
            string extension = null;

            if (IsArg ("set-type")) {
                extension = "." + GetArg ("set-type").ToLower ();
            } else {
                FileInfo info = new FileInfo (path);
                extension = info.Extension;
            }

            switch (extension)
            {
                case ".ini":
                    result = new IniConfigSource (path);
                    break;
                case ".config":
                    result = new DotNetConfigSource (path);
                    break;
                case ".xml":
                    result = new XmlConfigSource (path);
                    break;
                default:
                    ThrowError ("Unknown config file type");
                    break;
            }
            if (verbose) {
                PrintLine ("Loaded config: " + result.GetType ().Name);
            }

            return result;
        }
Пример #18
0
        /// <summary>
        /// Load the given configuration at a path and perform an action on each Config contained within it
        /// </summary>
        /// <param name="path"></param>
        /// <param name="fileDescription"></param>
        /// <param name="action"></param>
        private static void LoadFromFile(string path, string fileDescription, ConfigAction action)
        {
            if (File.Exists(path))
            {
                try
                {
                    XmlConfigSource source = new XmlConfigSource(path);

                    for (int i = 0; i < source.Configs.Count; i++)
                    {
                        action(source.Configs[i], path);
                    }
                }
                catch (XmlException e)
                {
                    m_log.ErrorFormat("[LIBRARY INVENTORY]: Error loading {0} : {1}", path, e);
                }
            }
            else
            {
                m_log.ErrorFormat("[LIBRARY INVENTORY]: {0} file {1} does not exist!", fileDescription, path);
            }
        }
        protected void ForEachDefaultXmlAsset(string assetSetFilename, Action<AssetBase> action)
        {
            List<AssetBase> assets = new List<AssetBase>();
            if (File.Exists(assetSetFilename))
            {
                string assetSetPath = "ERROR";
                string assetRootPath = "";
                try
                {
                    DateTime start = DateTime.Now;
                    XmlConfigSource source = new XmlConfigSource(assetSetFilename);
                    assetRootPath = Path.GetFullPath(source.SavePath);
                    assetRootPath = Path.GetDirectoryName(assetRootPath);

                    for (int i = 0; i < source.Configs.Count; i++)
                    {
                        assetSetPath = source.Configs[i].GetString("file", String.Empty);

                        LoadXmlAssetSet(Path.Combine(assetRootPath, assetSetPath), assets);
                    }
                    MainConsole.Instance.Warn((DateTime.Now - start).Milliseconds);
                }
                catch (XmlException e)
                {
                    MainConsole.Instance.ErrorFormat("[ASSETS]: Error loading {0} : {1}", assetSetPath, e);
                }
            }
            else
            {
                MainConsole.Instance.ErrorFormat("[ASSETS]: Asset set control file {0} does not exist!  No assets loaded.", assetSetFilename);
            }

            DateTime start2 = DateTime.Now;
            assets.ForEach(action);
            MainConsole.Instance.Warn((DateTime.Now - start2).Milliseconds);
        }
        /// <summary>
        /// Load the given configuration at a path and perform an action on each Config contained within it
        /// </summary>
        /// <param name="path"></param>
        /// <param name="fileDescription"></param>
        /// <param name="action"></param>
        void LoadFromFile(string path, string fileDescription, ConfigAction action)
        {
            if (File.Exists(path))
            {
                try
                {
                    var source = new XmlConfigSource(path);

                    for (int i = 0; i < source.Configs.Count; i++)
                        action(source.Configs[i], path);
                }
                catch (XmlException e)
                {
                    MainConsole.Instance.ErrorFormat("[InventoryXMLLoader]: Error loading {0} : {1}", path, e);
                }
            } else
                MainConsole.Instance.ErrorFormat("[InventoryXMLLoader]: {0} file {1} does not exist!", fileDescription, path);
        }
Пример #21
0
        public RegionInfo(string description, string filename, bool skipConsoleConfig, IConfigSource configSource, string configName)
        {
            // m_configSource = configSource;

            if (filename.ToLower().EndsWith(".ini"))
            {
                if (!File.Exists(filename)) // New region config request
                {
                    IniConfigSource newFile = new IniConfigSource();
                    ReadNiniConfig(newFile, configName);

                    newFile.Save(filename);

                    RegionFile = filename;

                    return;
                }

                IniConfigSource source = new IniConfigSource(filename);

                bool saveFile = false;
                if (source.Configs[configName] == null)
                    saveFile = true;

                ReadNiniConfig(source, configName);

                if (configName != String.Empty && saveFile)
                    source.Save(filename);

                RegionFile = filename;

                return;
            }

            try
            {
                // This will throw if it's not legal Nini XML format
                // and thereby toss it to the legacy loader
                //
                IConfigSource xmlsource = new XmlConfigSource(filename);

                ReadNiniConfig(xmlsource, configName);

                RegionFile = filename;

                return;
            }
            catch (Exception)
            {
            }

            configMember =
                new ConfigurationMember(filename, description, loadConfigurationOptions, handleIncomingConfiguration, !skipConsoleConfig);
            configMember.performConfigurationRetrieve();
            RegionFile = filename;
        }
Пример #22
0
 /// <summary>
 /// Saves the peer configuration.
 /// </summary>
 /// <param name="fileName">The name of the file where to save it.</param>
 private void SaveTo(String fileName)
 {
     // Save the configuration as input for future reconfiguration
     try
     {
         using (FileStream oStream = new FileStream(fileName, FileMode.Create))
         {
             XmlConfigSource source2 = new XmlConfigSource();
             source2.Merge(source);
             source2.Save(oStream);
         }
     }
     catch (Exception e)
     {
         if (log.IsWarnEnabled)
         {
             log.Warn(e);
             log.Warn("Could not save to " + fileName);
         }
     }
 }
        // File based loading
        //
        public RegionInfo LoadRegionFromFile(string description, string filename, bool skipConsoleConfig, IConfigSource configSource, string configName)
        {
            // m_configSource = configSource;
            RegionInfo region = new RegionInfo();
            if (filename.ToLower().EndsWith(".ini"))
            {
                if (!File.Exists(filename)) // New region config request
                {
                    IniConfigSource newFile = new IniConfigSource();

                    region.RegionFile = filename;

                    ReadNiniConfig(region, newFile, configName);
                    newFile.Save(filename);

                    return region;
                }

                IniConfigSource m_source = new IniConfigSource(filename, Nini.Ini.IniFileType.AuroraStyle);

                bool saveFile = false;
                if (m_source.Configs[configName] == null)
                    saveFile = true;

                region.RegionFile = filename;

                bool update = ReadNiniConfig(region, m_source, configName);

                if (configName != String.Empty && (saveFile || update))
                    m_source.Save(filename);

                return region;
            }

            try
            {
                // This will throw if it's not legal Nini XML format
                // and thereby toss it to the legacy loader
                //
                IConfigSource xmlsource = new XmlConfigSource(filename);

                ReadNiniConfig(region, xmlsource, configName);

                region.RegionFile = filename;

                return region;
            }
            catch (Exception)
            {
            }
            return null;
        }
Пример #24
0
        // Handle all the automagical stuff
        //
        public ServicesServerBase(string prompt, string[] args) : base()
        {
            // Save raw arguments
            //
            m_Arguments = args;

            // Read command line
            //
            ArgvConfigSource argvConfig = new ArgvConfigSource(args);

            argvConfig.AddSwitch("Startup", "console", "c");
            argvConfig.AddSwitch("Startup", "logfile", "l");
            argvConfig.AddSwitch("Startup", "inifile", "i");
            argvConfig.AddSwitch("Startup", "prompt",  "p");
            argvConfig.AddSwitch("Startup", "logconfig", "g");

            // Automagically create the ini file name
            //
            string fileName = Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location);
            string iniFile = fileName + ".ini";
            string logConfig = null;

            IConfig startupConfig = argvConfig.Configs["Startup"];
            if (startupConfig != null)
            {
                // Check if a file name was given on the command line
                //
                iniFile = startupConfig.GetString("inifile", iniFile);
                //
                // Check if a prompt was given on the command line
                prompt = startupConfig.GetString("prompt", prompt);
                //
                // Check for a Log4Net config file on the command line
                logConfig =startupConfig.GetString("logconfig",logConfig);
            }

            // Find out of the file name is a URI and remote load it
            // if it's possible. Load it as a local file otherwise.
            //
            Uri configUri;

            try
            {
                if (Uri.TryCreate(iniFile, UriKind.Absolute, out configUri) &&
                    configUri.Scheme == Uri.UriSchemeHttp)
                {
                    XmlReader r = XmlReader.Create(iniFile);
                    Config = new XmlConfigSource(r);
                }
                else
                {
                    Config = new IniConfigSource(iniFile);
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Error reading from config source.  {0}", e.Message);
                Environment.Exit(1);
            }

            // Merge the configuration from the command line into the
            // loaded file
            //
            Config.Merge(argvConfig);

            // Refresh the startupConfig post merge
            //
            if (Config.Configs["Startup"] != null)
            {
                startupConfig = Config.Configs["Startup"];
            }

            ConfigDirectory = startupConfig.GetString("ConfigDirectory", ".");

            prompt = startupConfig.GetString("Prompt", prompt);

            // Allow derived classes to load config before the console is
            // opened.
            //
            ReadConfig();

            // Create main console
            //
            string consoleType = "local";
            if (startupConfig != null)
                consoleType = startupConfig.GetString("console", consoleType);

            if (consoleType == "basic")
            {
                MainConsole.Instance = new CommandConsole(prompt);
            }
            else if (consoleType == "rest")
            {
                MainConsole.Instance = new RemoteConsole(prompt);
                ((RemoteConsole)MainConsole.Instance).ReadConfig(Config);
            }
            else
            {
                MainConsole.Instance = new LocalConsole(prompt);
            }

            m_console = MainConsole.Instance;

            if (logConfig != null)
            {
                FileInfo cfg = new FileInfo(logConfig);
                XmlConfigurator.Configure(cfg);
            }
            else
            {
                XmlConfigurator.Configure();
            }

            LogEnvironmentInformation();
            RegisterCommonAppenders(startupConfig);

            if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty)
            {
                CreatePIDFile(startupConfig.GetString("PIDFile"));
            }

            RegisterCommonCommands();

            // Register the quit command
            //
            MainConsole.Instance.Commands.AddCommand("General", false, "quit",
                    "quit",
                    "Quit the application", HandleQuit);

            MainConsole.Instance.Commands.AddCommand("General", false, "shutdown",
                    "shutdown",
                    "Quit the application", HandleQuit);

            // Allow derived classes to perform initialization that
            // needs to be done after the console has opened
            //
            Initialise();
        }
Пример #25
0
        /// <summary>
        /// Use the asset set information at path to load assets
        /// </summary>
        /// <param name="assetSetPath"></param>
        /// <param name="assets"></param>
        protected static void LoadXmlAssetSet(string assetSetPath, List<AssetBase> assets)
        {
            //m_log.InfoFormat("[ASSETS]: Loading asset set {0}", assetSetPath);

            if (File.Exists(assetSetPath))
            {
                try
                {
                    XmlConfigSource source = new XmlConfigSource(assetSetPath);
                    String dir = Path.GetDirectoryName(assetSetPath);

                    for (int i = 0; i < source.Configs.Count; i++)
                    {
                        string assetIdStr = source.Configs[i].GetString("assetID", UUID.Random().ToString());
                        string name = source.Configs[i].GetString("name", String.Empty);
                        sbyte type = (sbyte) source.Configs[i].GetInt("assetType", 0);
                        string assetPath = Path.Combine(dir, source.Configs[i].GetString("fileName", String.Empty));

                        AssetBase newAsset = CreateAsset(assetIdStr, name, assetPath, false);

                        newAsset.Type = type;
                        assets.Add(newAsset);
                    }
                }
                catch (XmlException e)
                {
                    m_log.ErrorFormat("[ASSETS]: Error loading {0} : {1}", assetSetPath, e);
                }
            }
            else
            {
                m_log.ErrorFormat("[ASSETS]: Asset set file {0} does not exist!", assetSetPath);
            }
        }
Пример #26
0
 public void Initialize()
 {
     ConfigSource = new XmlConfigSource("Config.xml") { AutoSave = true };
 }
Пример #27
0
        public void ForEachDefaultXmlAsset(string assetSetFilename, Action<AssetBase> action)
        {
            List<AssetBase> assets = new List<AssetBase>();
            if (File.Exists(assetSetFilename))
            {
                string assetSetPath = "ERROR";
                string assetRootPath = String.Empty;
                try
                {
                    XmlConfigSource source = new XmlConfigSource(assetSetFilename);
                    assetRootPath = Path.GetFullPath(source.SavePath);
                    assetRootPath = Path.GetDirectoryName(assetRootPath);

                    for (int i = 0; i < source.Configs.Count; i++)
                    {
                        assetSetPath = source.Configs[i].GetString("file", String.Empty);

                        LoadXmlAssetSet(Path.Combine(assetRootPath, assetSetPath), assets);
                    }
                }
                catch (XmlException e)
                {
                    m_log.ErrorFormat("[ASSETS]: Error loading {0} : {1}", assetSetPath, e);
                }
            }
            else
            {
                m_log.ErrorFormat("[ASSETS]: Asset set control file {0} does not exist!  No assets loaded.", assetSetFilename);
            }

            assets.ForEach(action);
        }