Exemple #1
0
        private static void LoadConfig(string fileName)
        {
            if (!File.Exists(fileName))
            {
                Log <RCServerService> .Logger.Warn("Cannot find configuration file!");
            }
            else
            {
                XmlTextReader xmlTextReader = null;
                try
                {
                    try
                    {
                        xmlTextReader = new XmlTextReader(fileName)
                        {
                            WhitespaceHandling = WhitespaceHandling.None
                        };
                        xmlTextReader.MoveToContent();
                        bool flag = true;
                        while (true)
                        {
                            if (!flag)
                            {
                                flag = true;
                            }
                            else if (!xmlTextReader.Read())
                            {
                                if (Base.WorkGroupString == null)
                                {
                                    Base.WorkGroupString = "<WorkGroups/>";
                                }
                                if (Base.ServerGroupString == null)
                                {
                                    Base.ServerGroupString = "<ServerGroups/>";
                                }
                                return;
                            }
                            if (xmlTextReader.NodeType == XmlNodeType.Element)
                            {
                                string name = xmlTextReader.Name;
                                string str  = name;
                                if (name != null)
                                {
                                    if (str == "Server")
                                    {
                                        Base.ReadServerInfo(xmlTextReader);
                                    }
                                    else if (str == "ProcessTemplates")
                                    {
                                        if (!xmlTextReader.IsEmptyElement)
                                        {
                                            Base.ReadProcessTemplateInfo(xmlTextReader);
                                        }
                                    }
                                    else if (str == "WorkGroups")
                                    {
                                        if (Base.WorkGroupString != null)
                                        {
                                            throw new FormatException("<WorkGroups> tag cannot be appeared before");
                                        }
                                        Base.WorkGroupString = xmlTextReader.ReadOuterXml();
                                        flag = false;
                                        WorkGroupStructureNode.GetWorkGroup(Base.WorkGroupString);
                                    }
                                    else if (str == "ServerGroups")
                                    {
                                        if (Base.ServerGroupString != null)
                                        {
                                            break;
                                        }
                                        Base.ServerGroupString = xmlTextReader.ReadOuterXml();
                                        flag = false;
                                        ServerGroupStructureNode.GetServerGroup(Base.ServerGroupString);
                                    }
                                    else if (str == "Authority")
                                    {
                                        Base.Security.LoadSecurity(xmlTextReader);
                                        flag = false;
                                    }
                                    else if (str == "EmergencyCall")
                                    {
                                        Base.Emergency.LoadEmergencyInfo(xmlTextReader);
                                        flag = false;
                                    }
                                }
                            }
                        }
                        throw new FormatException("<ServerGroups> tag cannot be appeared before");
                    }
                    catch (Exception exception)
                    {
                        Log <RCServerService> .Logger.Error("Exception occured while loading configuration", exception);

                        throw new ApplicationException("Cannot start service because configuration is invalid!");
                    }
                }
                finally
                {
                    if (xmlTextReader != null)
                    {
                        xmlTextReader.Close();
                    }
                }
            }
        }
Exemple #2
0
 public static void SaveConfig()
 {
     Base.SaveConfig(BaseConfiguration.WorkingDirectory + "\\" + BaseConfiguration.ServerConfigFile);
 }