示例#1
0
        /// <summary>
        /// Creates the TagConfig object
        /// </summary>
        /// <param name="parent">The parent node of the configuration file</param>
        /// <param name="configContext">The context of the node</param>
        /// <param name="section">The root node of the config file section being parsed</param>
        /// <returns>An TagConfig object encapsulating all settings defined in the specified configuration file section</returns>
        public object Create(object parent, object configContext, XmlNode section)
        {
            XmlElement root = (XmlElement)section;

            TagConfig Config = TagConfig.ParseXml(root);

            return(Config);
        }
示例#2
0
        /// <summary>
        /// Reads the config file and initializes tracing and logging
        /// </summary>
        public static void LoadConfiguration()
        {
            if (_config == null)
            {
                // Try to read the configuration
                try
                {
                    _config = (TagConfig)ConfigurationSettings.GetConfig("TagConfig");

                    if (_config == null)
                    {
                        throw new ConfigurationException("Error parsing TagConfig section of config file");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error loading Config file: {0}", e.Message);
                    Console.WriteLine("Exiting...");
                    return;
                }

                // Make the configuration available to the CallsignHelper for ServerAdmin tags
                CallsignHelper.SetServerAdmins(_config.ServerAdmins);

                // Initialize tracing
                TagTrace.Initialize(_config.TraceLevel, _config.TracePath, _config.TraceArchiveDir, _config.TraceConsole, null);

                TagTrace.WriteLine(TraceLevel.Info, "TAG Build {0} is starting...", Build.ToString());

                // Initialize reconnect timer
                ReconnectTimer.Initialize(_config.ReconnectInterval, _config.MaxRetries);
                ReconnectTimer.ShutdownTagEvent += new AsyncCallback(ReconnectShutdown);

                // Configure ASGS as necessary
                if (_config.AsgsUrl != null)
                {
                    AsgsConnector.Initialize(_config.AsgsUrl, _config.PostTimeout);
                }

                if (_config.CssUrl != null)
                {
                    CssConnector.Initialize(_config.CssUrl, _config.PostTimeout, _config.UseCss);
                }

                TagTrace.WriteLine(TraceLevel.Verbose, "Initializing logging...");
                GameLogger.Initialize(_config.XmlPath);

                TagTrace.WriteLine(TraceLevel.Info, "Configuration Loaded.");
            }
        }
示例#3
0
        /// <summary>
        /// Parses Xml configuration data into an instance of TagConfig
        /// </summary>
        /// <param name="root">The root Xml node of the configuration section</param>
        public static TagConfig ParseXml(XmlNode root)
        {
            TagConfig Result = new TagConfig();

            try
            {
                foreach (XmlNode Node in root.ChildNodes)
                {
                    if (!(Node is XmlElement))
                    {
                        continue;
                    }

                    XmlElement Element = (XmlElement)Node;

                    switch (Element.Name)
                    {
                    case "TAG":
                        if (Element.HasAttribute("UpdateTime"))
                        {
                            string   Time     = Element.GetAttribute("UpdateTime");
                            DateTime TempTime = DateTime.Parse(Time);

                            // Add a day if the update time has already passed
                            if (DateTime.Now > TempTime)
                            {
                                TempTime = TempTime.AddDays(1);
                            }

                            Result._updateTime = TempTime;
                        }

                        if (Element.HasAttribute("skipUpdates"))
                        {
                            Result._skipUpdates = Boolean.Parse(Element.GetAttribute("skipUpdates"));
                        }

                        if (Element.HasAttribute("ASGSUrl"))
                        {
                            Result._asgsUrl = Element.GetAttribute("ASGSUrl");
                        }

                        if (Element.HasAttribute("CSSUrl"))
                        {
                            Result._cssUrl = Element.GetAttribute("CSSUrl");
                        }

                        if (Element.HasAttribute("useCss"))
                        {
                            Result._useCss = Boolean.Parse(Element.GetAttribute("useCss"));
                        }

                        if (Element.HasAttribute("PostTimeout"))
                        {
                            Result._postTimeout = int.Parse(Element.GetAttribute("PostTimeout"));
                        }

                        break;

                    case "ReconnectTimer":
                        if (Element.HasAttribute("Interval"))
                        {
                            string SecondsString = Element.GetAttribute("Interval");
                            Result._reconnectIntervalSeconds = int.Parse(SecondsString);
                        }
                        if (Element.HasAttribute("MaxRetries"))
                        {
                            Result._maxRetries = int.Parse(Element.GetAttribute("MaxRetries"));
                        }

                        break;

                    case "Log":
                        foreach (XmlNode SubNode in Node.ChildNodes)
                        {
                            if (!(SubNode is XmlElement))
                            {
                                continue;
                            }

                            XmlElement SubElement = (XmlElement)SubNode;

                            switch (SubElement.Name)
                            {
                            case "XmlFile":
                                if (SubElement.HasAttribute("Path"))
                                {
                                    string TempPath = SubElement.GetAttribute("Path");
                                    Result._xmlPath = (Path.IsPathRooted(TempPath)) ? TempPath : Application.StartupPath + "\\" + TempPath;
                                }
                                break;
                            }
                        }
                        break;

                    case "Trace":
                        if (Element.HasAttribute("Level"))
                        {
                            Result._traceLevel = (TraceLevel)Enum.Parse(typeof(TraceLevel), Element.GetAttribute("Level"));
                        }
                        if (Element.HasAttribute("Path"))
                        {
                            string TempPath = Element.GetAttribute("Path");
                            Result._tracePath = (Path.IsPathRooted(TempPath)) ? TempPath : Application.StartupPath + "\\" + TempPath;
                        }
                        if (Element.HasAttribute("ArchiveDir"))
                        {
                            string TempPath = Element.GetAttribute("ArchiveDir");
                            Result._traceArchiveDir = (Path.IsPathRooted(TempPath)) ? TempPath : Application.StartupPath + "\\" + TempPath;
                        }
                        if (Element.HasAttribute("Console"))
                        {
                            Result._traceConsole = bool.Parse(Element.GetAttribute("Console"));
                        }

                        break;

                    case "ServerAdmins":
                        foreach (XmlNode SubNode in Node.ChildNodes)
                        {
                            if (!(SubNode is XmlElement))
                            {
                                continue;
                            }

                            XmlElement SubElement = (XmlElement)SubNode;

                            switch (SubElement.Name)
                            {
                            case "ServerAdmin":
                                Result._serverAdmins.Add(SubElement.InnerText.ToLower());
                                break;
                            }
                        }
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                TagTrace.WriteLine(TraceLevel.Error, "Error parsing Xml Config File: {0}", e.Message);
            }

            return(Result);
        }