Esempio n. 1
0
        /// <summary>
        /// 初始化配置
        /// </summary>
        /// <param name="config">配置对象</param>
        /// <param name="element">XML流</param>
        public static void ConfigureFromXML(ConfigSection config, XmlElement element)
        {
            XmlNodeList list1 = element.GetElementsByTagName("DomainDataProvider");

            if (list1.Count == 0)
            {
                //throw new Exception("ConfigSection: XML configuration does not contain a <DomainDataProvider> element. Configuration Aborted.");
                ExceptionManager.Raise(typeof(ConfigSection), "$Error_XML_Configuration_DataProvider", null, null);
            }
            if (list1.Count > 1)
            {
                //throw new Exception("ConfigSection: XML configuration contains [" + list1.Count + "] <DomainDataProvider> elements. Only one is allowed. Configuration Aborted.");
                ExceptionManager.Raise(typeof(ConfigSection), "$Error_XML_Configuration_Contain_DataProvider", string.Format("[$ListCount={0}]", list1.Count), null);
            }

            if (list1[0].Attributes["Type"] == null)
            {
                //throw new Exception("ConfigSection: element <DomainDataProvider> does not contain an attribute <Type> . Configuration Aborted.");
                ExceptionManager.Raise(typeof(ConfigSection), "$Error_DomainDataProvider_Type", null, null);
            }
            config.DomainSetting.DataProviderType = list1[0].Attributes["Type"].Value;

            XmlNodeList listPersistBrokers = element.GetElementsByTagName("PersistBroker");

            if (listPersistBrokers.Count == 0)
            {
                //throw new Exception("ConfigSection: XML configuration does not contain a <PersistBroker> element. Configuration Aborted.");
                ExceptionManager.Raise(typeof(ConfigSection), "$Error_DomainDataProvider_PersistBroker", null, null);
            }
            else
            {
                foreach (XmlNode item in listPersistBrokers)
                {
                    PersistBrokerSetting setting = new PersistBrokerSetting();
                    setting.Text              = item.Attributes["Text"].Value;
                    setting.Name              = item.Attributes["Name"].Value;
                    setting.Default           = bool.Parse(item.Attributes["Default"].Value);
                    setting.PersistBrokerType = item.Attributes["Type"].Value;
                    setting.NLS           = item.Attributes["NLS"].Value;
                    setting.ConnectString = EncryptionHelper.DESDecryption(item.Attributes["ConnectString"].Value);

                    if (setting.PersistBrokerType == "ODPPersistBroker" && setting.ConnectString.ToUpper().IndexOf("PROVIDER") >= 0)
                    {
                        int i1 = setting.ConnectString.ToUpper().IndexOf("PROVIDER");
                        int i2 = setting.ConnectString.ToUpper().IndexOf(";", i1);
                        if (i2 < 0)
                        {
                            i2 = setting.ConnectString.Length - 1;
                        }
                        setting.ConnectString = setting.ConnectString.Remove(i1, i2 - i1 + 1);
                    }

                    config.DomainSetting.AddSetting(setting);

                    //if (setting.Default)
                    //{
                    //    config.DomainSetting.PersistBrokerType = setting.PersistBrokerType;
                    //    config.DomainSetting.ConnectString = setting.ConnectString;
                    //}
                }
            }

            #region old flow

            /* //marked by carey.cheng on 2010-05-19 for muti db support
             *          XmlNodeList list2 = element.GetElementsByTagName("PersistBroker");
             *          if (list2.Count == 0)
             *          {
             *                  //throw new Exception("ConfigSection: XML configuration does not contain a <PersistBroker> element. Configuration Aborted.");
             *                  ExceptionManager.Raise(typeof(ConfigSection),"$Error_DomainDataProvider_PersistBroker",null,null);
             *
             *          }
             *          if (list2.Count > 1)
             *          {
             *                  //throw new Exception("ConfigSection: XML configuration contains [" + list2.Count + "] <PersistBroker> elements. Only one is allowed. Configuration Aborted.");
             *                  ExceptionManager.Raise(typeof(ConfigSection),"$Error_DomainDataProvider_PersistBroker_Contain_More_Than_One",string.Format("[$listCount={0}]", list2.Count),null);
             *          }
             *
             *          if (list2[0].Attributes["Type"] == null)
             *          {
             *                  //throw new Exception("ConfigSection: element <PersistBroker> does not contain an attribute <Type> . Configuration Aborted.");
             *                  ExceptionManager.Raise(typeof(ConfigSection),"$Error_DomainDataProvider_PersistBroker_Type",null,null);
             *          }
             *
             *          if (list2[0].Attributes["ConnectString"] == null)
             *          {
             *                  //throw new Exception("ConfigSection: element <PersistBroker> does not contain an attribute <ConnectString> . Configuration Aborted.");
             *                  ExceptionManager.Raise(typeof(ConfigSection),"$Error_DomainDataProvider_PersistBroker_ConnectString",null,null);
             *          }
             *
             *          if (list2[0].Attributes["IsPool"] == null)
             *          {
             *                  config.DomainSetting.IsPool  = 0;
             *          }
             *          else
             *          {
             *                  config.DomainSetting.IsPool = config.DomainSetting.PoolSize = System.Int32.Parse (list2[0].Attributes["IsPool"].Value);
             *          }
             *
             *          if (list2[0].Attributes["PoolSize"] == null)
             *          {
             *                  config.DomainSetting.PoolSize = 1;
             *                  //				//throw new Exception("ConfigSection: element <PersistBroker> does not contain an attribute <ConnectString> . Configuration Aborted.");
             *                  //				ExceptionManager.Raise(typeof(ConfigSection),"$Error_DomainDataProvider_PersistBroker_PoolSize",null,null);
             *          }
             *          else
             *          {
             *                  config.DomainSetting.PoolSize = System.Int32.Parse (list2[0].Attributes["PoolSize"].Value);
             *          }
             *
             *          XmlNodeList list3 = element.GetElementsByTagName("RealTimeReportAutoRefresh");
             *          if (list3.Count == 0)
             *          {
             *                  //throw new Exception("ConfigSection: XML configuration does not contain a <DomainDataProvider> element. Configuration Aborted.");
             *                  //ExceptionManager.Raise(typeof(ConfigSection),"$Error_XML_Configuration_RealTimeReportAutoRefresh",null,null);
             *                  config.DomainSetting.Interval  = 300000;
             *          }
             *          else
             *          {
             *                  if(list3[0].Attributes["Seconds"] != null)
             *                  {
             *                          config.DomainSetting.Interval = System.Int32.Parse(list3[0].Attributes["Seconds"].Value);
             *                  }
             *                  else
             *                  {
             *                          config.DomainSetting.Interval  = 300000;
             *                   }
             *          }
             *
             *          XmlNodeList list4 = element.GetElementsByTagName("DateRange");
             *          if (list4.Count == 0)
             *          {
             *                  //throw new Exception("ConfigSection: XML configuration does not contain a <DomainDataProvider> element. Configuration Aborted.");
             *                  //ExceptionManager.Raise(typeof(ConfigSection),"$Error_XML_Configuration_RealTimeReportAutoRefresh",null,null);
             *                  config.DomainSetting.MaxDateRange  = 30;
             *          }
             *          else
             *          {
             *                  if(list4[0].Attributes["Max"] != null)
             *                  {
             *                          config.DomainSetting.MaxDateRange = System.Int32.Parse(list4[0].Attributes["Max"].Value);
             *                  }
             *                  else
             *                  {
             *                          config.DomainSetting.MaxDateRange  = 30;
             *                  }
             *          }
             *
             *
             *          config.DomainSetting.PersistBrokerType = list2[0].Attributes["Type"].Value;
             *          //sammer kong encryption
             *          config.DomainSetting.ConnectString = EncryptionHelper.DESDecryption(list2[0].Attributes["ConnectString"].Value);
             *          // Added by Icyer 2006/11/03
             *          if (config.DomainSetting.PersistBrokerType == "ODPPersistBroker")
             *          {
             *                  if (config.DomainSetting.ConnectString.ToUpper().IndexOf("PROVIDER") >= 0)
             *                  {
             *                          int i1 = config.DomainSetting.ConnectString.ToUpper().IndexOf("PROVIDER");
             *                          int i2 = config.DomainSetting.ConnectString.ToUpper().IndexOf(";", i1);
             *                          if (i2 < 0)
             *                                  i2 = config.DomainSetting.ConnectString.Length - 1;
             *                          config.DomainSetting.ConnectString = config.DomainSetting.ConnectString.Remove(i1, i2 - i1 + 1);
             *                  }
             *          }
             *          // Added end
             *
             *          //SPC connection string
             *          XmlNodeList list5 = element.GetElementsByTagName("SPCPersistBroker");
             *          if(list5.Count > 0)
             *          {
             *                  config.DomainSetting.SPCConnectString = EncryptionHelper.DESDecryption(list5[0].Attributes["ConnectString"].Value);
             *                  config.DomainSetting.SPCPersistBrokerType = list5[0].Attributes["Type"].Value;
             *                  // Added by Icyer 2006/11/03
             *                  if (config.DomainSetting.SPCPersistBrokerType == "ODPPersistBroker")
             *                  {
             *                          if (config.DomainSetting.SPCConnectString.ToUpper().IndexOf("PROVIDER") >= 0)
             *                          {
             *                                  int i1 = config.DomainSetting.SPCConnectString.ToUpper().IndexOf("PROVIDER");
             *                                  int i2 = config.DomainSetting.SPCConnectString.ToUpper().IndexOf(";", i1);
             *                                  if (i2 < 0)
             *                                          i2 = config.DomainSetting.SPCConnectString.Length - 1;
             *                                  config.DomainSetting.SPCConnectString = config.DomainSetting.SPCConnectString.Remove(i1, i2 - i1 + 1);
             *                          }
             *                  }
             *                  // Added end
             *          }
             *
             *          //SAP DB connection string
             *          XmlNodeList listSAP = element.GetElementsByTagName("SAPDBPersistBroker");
             *          if(listSAP.Count > 0)
             *          {
             *                  config.DomainSetting.SAPDBConnectString = EncryptionHelper.DESDecryption(listSAP[0].Attributes["ConnectString"].Value);
             *                  config.DomainSetting.SAPDBPersistBrokerType = listSAP[0].Attributes["Type"].Value;
             *                  // Added by Icyer 2006/11/03
             *                  if (config.DomainSetting.SAPDBPersistBrokerType == "ODPPersistBroker")
             *                  {
             *                          if (config.DomainSetting.SAPDBConnectString.ToUpper().IndexOf("PROVIDER") >= 0)
             *                          {
             *                                  int i1 = config.DomainSetting.SAPDBConnectString.ToUpper().IndexOf("PROVIDER");
             *                                  int i2 = config.DomainSetting.SAPDBConnectString.ToUpper().IndexOf(";", i1);
             *                                  if (i2 < 0)
             *                                          i2 = config.DomainSetting.SAPDBConnectString.Length - 1;
             *                                  config.DomainSetting.SAPDBConnectString = config.DomainSetting.SAPDBConnectString.Remove(i1, i2 - i1 + 1);
             *                          }
             *                  }
             *                  // Added end
             *          }
             *
             *
             *
             *          //ERP DB connection string
             *          XmlNodeList listERP = element.GetElementsByTagName("ODBCPersistBroker");
             *          if(listERP.Count > 0)
             *          {
             *                  config.DomainSetting.ERPConnectString = EncryptionHelper.DESDecryption(listERP[0].Attributes["ConnectString"].Value);
             *                  config.DomainSetting.ERPPersistBrokerType = listERP[0].Attributes["Type"].Value;
             *                  // Added by Icyer 2006/11/03
             *                  if (config.DomainSetting.ERPPersistBrokerType == "ODPPersistBroker")
             *                  {
             *                          if (config.DomainSetting.ERPConnectString.ToUpper().IndexOf("PROVIDER") >= 0)
             *                          {
             *                                  int i1 = config.DomainSetting.ERPConnectString.ToUpper().IndexOf("PROVIDER");
             *                                  int i2 = config.DomainSetting.ERPConnectString.ToUpper().IndexOf(";", i1);
             *                                  if (i2 < 0)
             *                                          i2 = config.DomainSetting.ERPConnectString.Length - 1;
             *                                  config.DomainSetting.ERPConnectString = config.DomainSetting.ERPConnectString.Remove(i1, i2 - i1 + 1);
             *                          }
             *                  }
             *                  // Added end
             *          }
             *
             *          //His DB connection string
             *          XmlNodeList listHIS = element.GetElementsByTagName("HisPersistBroker");
             *          if(listHIS.Count > 0)
             *          {
             *                  config.DomainSetting.HisConnectString = EncryptionHelper.DESDecryption(listHIS[0].Attributes["ConnectString"].Value);
             *                  config.DomainSetting.HisPersistBrokerType = listHIS[0].Attributes["Type"].Value;
             *                  // Added by Icyer 2006/11/03
             *                  if (config.DomainSetting.HisPersistBrokerType == "ODPPersistBroker")
             *                  {
             *                          if (config.DomainSetting.HisConnectString.ToUpper().IndexOf("PROVIDER") >= 0)
             *                          {
             *                                  int i1 = config.DomainSetting.HisConnectString.ToUpper().IndexOf("PROVIDER");
             *                                  int i2 = config.DomainSetting.HisConnectString.ToUpper().IndexOf(";", i1);
             *                                  if (i2 < 0)
             *                                          i2 = config.DomainSetting.HisConnectString.Length - 1;
             *                                  config.DomainSetting.HisConnectString = config.DomainSetting.HisConnectString.Remove(i1, i2 - i1 + 1);
             *                          }
             *                  }
             *                  // Added end
             *          }
             */
            #endregion

            //JobClassName 导入日志类型
            XmlNodeList listJobClass = element.GetElementsByTagName("MESJobClassName");
            if (listJobClass.Count > 0)
            {
                config.DomainSetting.MESJobClassName = listJobClass[0].Attributes["Type"].Value;
            }

            // Added By Hi1/venus.feng on 20080813 for Hisense Version : Add change NLS_LANG register
            XmlNodeList listNLS = element.GetElementsByTagName("NLSRegister");
            if (listNLS.Count > 0)
            {
                if (listNLS[0].Attributes["NLSDIR"] != null)
                {
                    config.DomainSetting.NLSDIR = listNLS[0].Attributes["NLSDIR"].Value;
                }
                else
                {
                    config.DomainSetting.NLSDIR = string.Empty;
                }
                //marked by carey.cheng on 2010-05-19 for muti db support
                //if (listNLS[0].Attributes["NLS"] != null)
                //{
                //    config.DomainSetting.NLS = listNLS[0].Attributes["NLS"].Value;
                //}
                //else
                //{
                //    config.DomainSetting.NLS = string.Empty;
                //}
                //end marked by carey.cheng on 2010-05-19 for muti db support
            }

            XmlNodeList list3 = element.GetElementsByTagName("RealTimeReportAutoRefresh");
            if (list3.Count == 0)
            {
                //throw new Exception("ConfigSection: XML configuration does not contain a <DomainDataProvider> element. Configuration Aborted.");
                //ExceptionManager.Raise(typeof(ConfigSection),"$Error_XML_Configuration_RealTimeReportAutoRefresh",null,null);
                config.DomainSetting.Interval = 300000;
            }
            else
            {
                if (list3[0].Attributes["Seconds"] != null)
                {
                    config.DomainSetting.Interval = System.Int32.Parse(list3[0].Attributes["Seconds"].Value);
                }
                else
                {
                    config.DomainSetting.Interval = 300000;
                }
            }
            // End Added
        }