示例#1
0
        static BaseJob()
        {
            string configPath = Path.Combine(Environment.CurrentDirectory, "SiteInfo.xml");
            if (!File.Exists(configPath))
            {
                JOBTool.LogError("Can't find 'SiteInfo.xml' file.");
                return;
            }

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(configPath);

                XmlNodeList nodeList = doc.SelectNodes("/sites/site");
                // 开始解析
                foreach (XmlNode node in nodeList)
                {
                    SiteInfo info = new SiteInfo();
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        string val = childNode.InnerText.Trim();
                        switch (childNode.Name.ToLower())
                        {
                            case "sitecode":
                                info.SiteCode = val;
                                break;
                            case "baanserver":
                                info.BaaN_Server = val;
                                break;
                            case "connectionconfig":
                                //info.ConnectionConfig = val;
                                info.ConnectionConfig = ConfigurationManager.ConnectionStrings[val].ConnectionString;
                                break;
                            case "reportmail":
                                info.ReportMail = val;
                                break;
                            case "infomail":
                                info.InfoMail = val;
                                break;
                            case "webaddress":
                                info.WebAddress = val;
                                break;
                            case "sqlserverconnectionconfig":
                                info.SqlServerConnectionConfig = ConfigurationManager.ConnectionStrings[val].ConnectionString;
                                break;
                            default:
                                info.AddValue(childNode.Name, val);
                                break;
                        }
                    }
                    _sites.Add(info);
                }
            }
            catch (XmlException ex)
            {
                //XML 中有加载或分析错误。这种情况下,文档保持为空。
                JOBTool.LogError("datetime:" + DateTime.Now.ToString() + " 加载info.xml的时候发生错误!" + ex.Message);
            }
            catch (System.Xml.XPath.XPathException ex)
            {
                //XPath 表达式包含 XmlNamespaceManager 中没有定义的前缀。
                JOBTool.LogError("datetime:" + DateTime.Now.ToString() + " 分析info.xml的时候发生错误!" + ex.Message);
            }
            catch (Exception ex)
            {
                JOBTool.LogError(ex);
            }
        }