Пример #1
0
        /// <summary>
        /// 从配置信息获取配置信息
        /// </summary>
        /// <param name="configuration">配置</param>
        public static void GetConfig()
        {
            // 客户信息配置
            SystemInfo.CustomerCompanyName = ConfigurationManager.AppSettings["CustomerCompanyName"];
            SystemInfo.ConfigurationFrom   = BaseConfiguration.GetConfiguration(ConfigurationManager.AppSettings["ConfigurationFrom"]);
            SystemInfo.SoftName            = ConfigurationManager.AppSettings["SoftName"];
            SystemInfo.SoftFullName        = ConfigurationManager.AppSettings["SoftFullName"];
            SystemInfo.Version             = ConfigurationManager.AppSettings["Version"];
            SystemInfo.RootMenuCode        = ConfigurationManager.AppSettings["RootMenuCode"];
            SystemInfo.ServiceUserName     = ConfigurationManager.AppSettings["ServiceUserName"];
            SystemInfo.ServicePassword     = ConfigurationManager.AppSettings["ServicePassword"];
            SystemInfo.ServicePassword     = SecretHelper.AESDecrypt(SystemInfo.ServicePassword);
            SystemInfo.RootMenuCode        = ConfigurationManager.AppSettings["RootMenuCode"];

            //SystemInfo.CurrentLanguage = ConfigurationManager.AppSettings["CurrentLanguage"];
            // SystemInfo.Service = ConfigurationManager.AppSettings["Service"];
            // SystemInfo.EnableRecordLog = (ConfigurationManager.AppSettings["EnableRecordLog"].ToUpper(), true.ToString().ToUpper(), true);

            if (ConfigurationManager.AppSettings["EnableEncryptServerPassword"] != null)
            {
                SystemInfo.EnableEncryptServerPassword = ConfigurationManager.AppSettings["EnableEncryptServerPassword"].ToUpper().Equals(true.ToString().ToUpper());
            }
            if (ConfigurationManager.AppSettings["EncryptClientPassword"] != null)
            {
                SystemInfo.EncryptClientPassword = ConfigurationManager.AppSettings["EncryptClientPassword"].ToUpper().Equals(true.ToString().ToUpper());
            }

            if (ConfigurationManager.AppSettings["EnableCheckIPAddress"] != null)
            {
                SystemInfo.EnableCheckIPAddress = ConfigurationManager.AppSettings["EnableCheckIPAddress"].ToUpper().Equals(true.ToString().ToUpper());
            }

            // SystemInfo.AutoLogOn = (ConfigurationManager.AppSettings["AutoLogOn"].ToUpper(), true.ToString().ToUpper(), true);
            // SystemInfo.LogOnAssembly = ConfigurationManager.AppSettings["LogOnAssembly"];
            // SystemInfo.LogOnForm = ConfigurationManager.AppSettings["LogOnAssembly"];
            // SystemInfo.MainForm = ConfigurationManager.AppSettings["MainForm"];

            if (ConfigurationManager.AppSettings["CheckOnLine"] != null)
            {
                SystemInfo.CheckOnLine = ConfigurationManager.AppSettings["CheckOnLine"].ToUpper().Equals(true.ToString().ToUpper());
            }
            // SystemInfo.LoadAllUser = (ConfigurationManager.AppSettings["LoadAllUser"].ToUpper(), true.ToString().ToUpper(), true);
            // SystemInfo.AllowUserToRegister = (ConfigurationManager.AppSettings["AllowUserToRegister"].ToUpper(), true.ToString().ToUpper(), true);
            // SystemInfo.EnableUserAuthorizationScope = (ConfigurationManager.AppSettings["EnableUserAuthorizationScope"].ToUpper(), true.ToString().ToUpper(), true);
            // SystemInfo.EnableTableFieldPermission = (ConfigurationManager.AppSettings["EnableTableFieldPermission"].ToUpper(), true.ToString().ToUpper(), true);
            // SystemInfo.EnableTableConstraintPermission = (ConfigurationManager.AppSettings["EnableTableConstraintPermission"].ToUpper(), true.ToString().ToUpper(), true);

            if (ConfigurationManager.AppSettings["EnableUserAuthorization"] != null)
            {
                SystemInfo.EnableUserAuthorization = ConfigurationManager.AppSettings["EnableUserAuthorization"].ToUpper().Equals(true.ToString().ToUpper());
            }

            if (ConfigurationManager.AppSettings["EnableUserAuthorizationScope"] != null)
            {
                SystemInfo.EnableUserAuthorizationScope = ConfigurationManager.AppSettings["EnableUserAuthorizationScope"].ToUpper().Equals(true.ToString().ToUpper());
            }

            if (ConfigurationManager.AppSettings["EnableModulePermission"] != null)
            {
                SystemInfo.EnableModulePermission = ConfigurationManager.AppSettings["EnableModulePermission"].ToUpper().Equals(true.ToString().ToUpper());
            }

            if (ConfigurationManager.AppSettings["EnablePermissionItem"] != null)
            {
                SystemInfo.EnablePermissionItem = ConfigurationManager.AppSettings["EnablePermissionItem"].ToUpper().Equals(true.ToString().ToUpper());
            }

            if (ConfigurationManager.AppSettings["EnableOrganizePermission"] != null)
            {
                SystemInfo.EnableOrganizePermission = ConfigurationManager.AppSettings["EnableOrganizePermission"].ToUpper().Equals(true.ToString().ToUpper());
            }

            if (ConfigurationManager.AppSettings["EnableTableFieldPermission"] != null)
            {
                SystemInfo.EnableTableFieldPermission = ConfigurationManager.AppSettings["EnableTableFieldPermission"].ToUpper().Equals(true.ToString().ToUpper());
            }

            if (ConfigurationManager.AppSettings["EnableTableConstraintPermission"] != null)
            {
                SystemInfo.EnableTableConstraintPermission = ConfigurationManager.AppSettings["EnableTableConstraintPermission"].ToUpper().Equals(true.ToString().ToUpper());
            }

            // 数据库连接
            if (ConfigurationManager.AppSettings["RDIFrameworkDbType"] != null)
            {
                SystemInfo.RDIFrameworkDbType = BaseConfiguration.GetDbType(ConfigurationManager.AppSettings["RDIFrameworkDbType"]);
            }
            if (ConfigurationManager.AppSettings["BusinessDbType"] != null)
            {
                SystemInfo.BusinessDbType = BaseConfiguration.GetDbType(ConfigurationManager.AppSettings["BusinessDbType"]);
            }
            if (ConfigurationManager.AppSettings["WorkFlowDbType"] != null)
            {
                SystemInfo.WorkFlowDbType = BaseConfiguration.GetDbType(ConfigurationManager.AppSettings["WorkFlowDbType"]);
            }
            if (ConfigurationManager.AppSettings["EncryptDbConnection"] != null)
            {
                SystemInfo.EncryptDbConnection = ConfigurationManager.AppSettings["EncryptDbConnection"].ToUpper().Equals(true.ToString().ToUpper());
            }

            SystemInfo.BusinessDbConnectionString    = ConfigurationManager.AppSettings["BusinessDbConnection"];
            SystemInfo.RDIFrameworkDbConectionString = ConfigurationManager.AppSettings["RDIFrameworkDbConection"];
            SystemInfo.WorkFlowDbConnectionString    = ConfigurationManager.AppSettings["WorkFlowDbConnection"];
            // 对加密的数据库连接进行解密操作
            if (SystemInfo.EncryptDbConnection)
            {
                SystemInfo.BusinessDbConnection    = SecretHelper.AESDecrypt(SystemInfo.BusinessDbConnectionString);
                SystemInfo.RDIFrameworkDbConection = SecretHelper.AESDecrypt(SystemInfo.RDIFrameworkDbConectionString);
                SystemInfo.WorkFlowDbConnection    = SecretHelper.AESDecrypt(SystemInfo.WorkFlowDbConnectionString);
            }
            else
            {
                SystemInfo.BusinessDbConnection    = ConfigurationManager.AppSettings["BusinessDbConnection"];
                SystemInfo.RDIFrameworkDbConection = ConfigurationManager.AppSettings["RDIFrameworkDbConection"];
                SystemInfo.WorkFlowDbConnection    = ConfigurationManager.AppSettings["WorkFlowDbConnection"];
            }

            SystemInfo.RegisterKey = ConfigurationManager.AppSettings["RegisterKey"];
        }
        /// <summary>
        /// 从指定的文件读取配置项
        /// </summary>
        /// <param name="fileName">配置文件</param>
        public static void GetConfig(string fileName)
        {
            var xmlDocument = new XmlDocument();

            xmlDocument.Load(fileName);

            SystemInfo.ConfigFile = Exists("ConfigFile") ? GetValue(xmlDocument, "ConfigFile") : SystemInfo.ConfigFile;
            SystemInfo.Host       = Exists("Host") ? GetValue(xmlDocument, "Host") : SystemInfo.Host;

            if (Exists("Port"))
            {
                int.TryParse(GetValue(xmlDocument, "Port"), out SystemInfo.Port);
            }

            // 客户信息配置
            SystemInfo.CurrentUserName = Exists("CurrentUserName") ? GetValue(xmlDocument, "CurrentUserName") : SystemInfo.CurrentUserName;
            SystemInfo.CurrentPassword = Exists("CurrentPassword") ? GetValue(xmlDocument, "CurrentPassword") : SystemInfo.CurrentPassword;

            if (Exists("MultiLanguage"))
            {
                SystemInfo.MultiLanguage = (String.Compare(GetValue(xmlDocument, "MultiLanguage"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            }

            SystemInfo.CurrentLanguage = Exists("CurrentLanguage") ? GetValue(xmlDocument, "CurrentLanguage") : SystemInfo.CurrentLanguage;

            if (Exists("RememberPassword"))
            {
                SystemInfo.RememberPassword = (String.Compare(GetValue(xmlDocument, "RememberPassword"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            }

            if (Exists("AutoLogOn"))
            {
                SystemInfo.AutoLogOn = (String.Compare(GetValue(xmlDocument, "AutoLogOn"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            }

            if (Exists("EnableCheckPasswordStrength"))
            {
                SystemInfo.EnableCheckPasswordStrength = (String.Compare(GetValue(xmlDocument, "EnableCheckPasswordStrength"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            }

            if (Exists("EncryptClientPassword"))
            {
                SystemInfo.EncryptClientPassword = (String.Compare(GetValue(xmlDocument, "EncryptClientPassword"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            }
            if (Exists("EnableEncryptServerPassword"))
            {
                SystemInfo.EnableEncryptServerPassword = (String.Compare(GetValue(xmlDocument, "EnableEncryptServerPassword"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            }

            SystemInfo.CurrentStyle      = Exists("CurrentStyle") ? GetValue(xmlDocument, "CurrentStyle") : SystemInfo.CurrentStyle;
            SystemInfo.CurrentThemeColor = Exists("CurrentThemeColor") ? GetValue(xmlDocument, "CurrentThemeColor") : SystemInfo.CurrentThemeColor;

            if (Exists("OnLineTime0ut"))
            {
                var valueOnLineTimeOut = GetValue(xmlDocument, "OnLineTime0ut");
                if (!string.IsNullOrEmpty(valueOnLineTimeOut) && MathHelper.IsInteger(valueOnLineTimeOut))
                {
                    SystemInfo.OnLineTime0ut = Convert.ToInt16(valueOnLineTimeOut);
                }
            }

            if (Exists("EnableCheckIPAddress"))
            {
                SystemInfo.EnableCheckIPAddress = (String.Compare(GetValue(xmlDocument, "EnableCheckIPAddress"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            }
            if (Exists("CheckOnLine"))
            {
                SystemInfo.CheckOnLine = (String.Compare(GetValue(xmlDocument, "CheckOnLine"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            }
            if (Exists("UseMessage"))
            {
                SystemInfo.UseMessage = (String.Compare(GetValue(xmlDocument, "UseMessage"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            }
            if (Exists("AllowUserToRegister"))
            {
                SystemInfo.AllowUserToRegister = (String.Compare(GetValue(xmlDocument, "AllowUserToRegister"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            }
            if (Exists("EnableRecordLog"))
            {
                SystemInfo.EnableRecordLog = (String.Compare(GetValue(xmlDocument, "EnableRecordLog"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            }

            SystemInfo.CustomerCompanyName = GetValue(xmlDocument, "CustomerCompanyName");
            SystemInfo.ConfigurationFrom   = BaseConfiguration.GetConfiguration(GetValue(xmlDocument, "ConfigurationFrom"));
            SystemInfo.SoftName            = GetValue(xmlDocument, "SoftName");
            SystemInfo.SoftFullName        = GetValue(xmlDocument, "SoftFullName");
            SystemInfo.RootMenuCode        = GetValue(xmlDocument, "RootMenuCode");
            SystemInfo.Version             = GetValue(xmlDocument, "Version");

            if (Exists("EnableUserAuthorization"))
            {
                SystemInfo.EnableUserAuthorization = (String.Compare(GetValue(xmlDocument, "EnableUserAuthorization"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            }
            if (Exists("EnableModulePermission"))
            {
                SystemInfo.EnableModulePermission = (String.Compare(GetValue(xmlDocument, "EnableModulePermission"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            }
            if (Exists("EnablePermissionItem"))
            {
                SystemInfo.EnablePermissionItem = (String.Compare(GetValue(xmlDocument, "EnablePermissionItem"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            }
            if (Exists("EnableTableFieldPermission"))
            {
                SystemInfo.EnableTableFieldPermission = (String.Compare(GetValue(xmlDocument, "EnableTableFieldPermission"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            }
            if (Exists("EnableTableConstraintPermission"))
            {
                SystemInfo.EnableTableConstraintPermission = (String.Compare(GetValue(xmlDocument, "EnableTableConstraintPermission"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            }
            if (Exists("EnableUserAuthorizationScope"))
            {
                SystemInfo.EnableUserAuthorizationScope = (String.Compare(GetValue(xmlDocument, "EnableUserAuthorizationScope"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            }
            if (Exists("EnableHandWrittenSignature"))
            {
                SystemInfo.EnableHandWrittenSignature = (String.Compare(GetValue(xmlDocument, "EnableHandWrittenSignature"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            }
            if (Exists("EnableOrganizePermission"))
            {
                SystemInfo.EnableOrganizePermission = (String.Compare(GetValue(xmlDocument, "EnableOrganizePermission"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            }

            if (Exists("DefaultPassword"))
            {
                SystemInfo.DefaultPassword = GetValue(xmlDocument, "DefaultPassword");
                SystemInfo.DefaultPassword = SecretHelper.AESDecrypt(SystemInfo.DefaultPassword);
            }

            if (Exists("LoadAllUser"))
            {
                SystemInfo.LoadAllUser = (String.Compare(GetValue(xmlDocument, "LoadAllUser"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            }

            SystemInfo.Service       = GetValue(xmlDocument, "Service");
            SystemInfo.LogOnAssembly = Exists("LogOnAssembly") ? GetValue(xmlDocument, "LogOnAssembly") : SystemInfo.LogOnAssembly;
            SystemInfo.LogOnForm     = Exists("LogOnForm") ? GetValue(xmlDocument, "LogOnForm") : SystemInfo.LogOnForm;
            SystemInfo.MainForm      = Exists("MainForm") ? GetValue(xmlDocument, "MainForm") : SystemInfo.MainForm;
            int.TryParse(GetValue(xmlDocument, "OnLineLimit"), out SystemInfo.OnLineLimit);

            // 打开数据库连接
            SystemInfo.RDIFrameworkDbType            = Exists("RDIFrameworkDbType") ? BaseConfiguration.GetDbType(GetValue(xmlDocument, "RDIFrameworkDbType")) : SystemInfo.RDIFrameworkDbType;
            SystemInfo.BusinessDbType                = Exists("BusinessDbType") ? BaseConfiguration.GetDbType(GetValue(xmlDocument, "BusinessDbType")) : SystemInfo.BusinessDbType;
            SystemInfo.WorkFlowDbType                = Exists("WorkFlowDbType") ? BaseConfiguration.GetDbType(GetValue(xmlDocument, "WorkFlowDbType")) : SystemInfo.WorkFlowDbType;
            SystemInfo.EncryptDbConnection           = (String.Compare(GetValue(xmlDocument, "EncryptDbConnection"), "TRUE", true, CultureInfo.CurrentCulture) == 0);
            SystemInfo.BusinessDbConnectionString    = GetValue(xmlDocument, "BusinessDbConnection");
            SystemInfo.WorkFlowDbConnectionString    = GetValue(xmlDocument, "WorkFlowDbConnection");
            SystemInfo.RDIFrameworkDbConectionString = GetValue(xmlDocument, "RDIFrameworkDbConection");

            if (SystemInfo.EncryptDbConnection)
            {
                SystemInfo.WorkFlowDbConnection    = SecretHelper.AESDecrypt(SystemInfo.WorkFlowDbConnectionString);
                SystemInfo.BusinessDbConnection    = SecretHelper.AESDecrypt(SystemInfo.BusinessDbConnectionString);
                SystemInfo.RDIFrameworkDbConection = SecretHelper.AESDecrypt(SystemInfo.RDIFrameworkDbConectionString);
            }
            else
            {
                SystemInfo.WorkFlowDbConnection    = SystemInfo.WorkFlowDbConnectionString;
                SystemInfo.BusinessDbConnection    = SystemInfo.BusinessDbConnectionString;
                SystemInfo.RDIFrameworkDbConection = SystemInfo.RDIFrameworkDbConectionString;
            }

            SystemInfo.ServiceUserName = GetValue(xmlDocument, "ServiceUserName");
            SystemInfo.ServicePassword = GetValue(xmlDocument, "ServicePassword");
            SystemInfo.ServicePassword = SecretHelper.AESDecrypt(SystemInfo.ServicePassword);

            SystemInfo.RegisterKey = GetValue(xmlDocument, "RegisterKey");
            SystemInfo.NodeTimeout = GetValue(xmlDocument, "NodeTimeout");

            // 错误报告相关
            SystemInfo.ErrorReportFrom         = GetValue(xmlDocument, "ErrorReportFrom");
            SystemInfo.ErrorReportMailUserName = GetValue(xmlDocument, "ErrorReportMailUserName");
            SystemInfo.ErrorReportMailPassword = GetValue(xmlDocument, "ErrorReportMailPassword");
            //SMTP服务器,如:smtp.126.com
            SystemInfo.ErrorReportMailServer   = GetValue(xmlDocument, "ErrorReportMailServer");
            SystemInfo.ErrorReportMailPassword = SecretHelper.AESDecrypt(SystemInfo.ErrorReportMailPassword);
            var blog = GetValue(xmlDocument, "RDIFrameworkBlog");

            if (!string.IsNullOrEmpty(blog))
            {
                SystemInfo.RDIFrameworkBlog = blog;
            }
            var weibo = GetValue(xmlDocument, "RDIFrameworkWeibo");

            if (!string.IsNullOrEmpty(weibo))
            {
                SystemInfo.RDIFrameworkWeibo = weibo;
            }
        }