private static void LoadEnterpriseAdapter() { var configuration = ConfigurationManager.AppSettings["EnterpriseAdapter"]; if (configuration == null) { var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var section = config.GetSection("localAdmin"); if (section != null) { var localAdminUser = ((AppSettingsSection)section).Settings["LocalAdminUser"]; var localAdminPassword = ((AppSettingsSection)section).Settings["localAdminPassword"]; if (localAdminUser != null && !string.IsNullOrEmpty(localAdminUser.Value) && localAdminPassword != null && !string.IsNullOrEmpty(localAdminPassword.Value)) { _enterpriseAdapter = new LocalAdmin(); } } } else { var assemblyDetails = configuration.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (assemblyDetails.Length != 2) { throw new FormatException("EnterpriseAdapter configuration is invalid!"); } var assembly = Assembly.Load(assemblyDetails[1].Trim()); _enterpriseAdapter = (IEnterpriseAdapter)assembly.CreateInstance(assemblyDetails[0]); if (_enterpriseAdapter == null) { throw new InvalidOperationException(string.Format("Unable to create instance of {0}", assemblyDetails[0])); } _enterpriseAdminGroup = ConfigurationManager.AppSettings["EnterpriseAdminGroup"]; if (_enterpriseAdminGroup == null) { throw new Exception("EnterpriseAdminGroup has not been configured!"); } _enterpriseDomain = ConfigurationManager.AppSettings["EnterpriseDomain"]; if (_enterpriseDomain == null) { throw new Exception("EnterpriseDomain has not been configured!"); } _enterpriseNetbiosDomain = ConfigurationManager.AppSettings["EnterpriseNetbiosDomain"]; } if (_enterpriseAdapter != null) { _enterpriseAdapter.Initialize(); } }
private static void LoadEnterpriseAdapter() { var configuration = ConfigurationManager.AppSettings["EnterpriseAdapter"]; if (configuration == null) { return; } var assemblyDetails = configuration.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (assemblyDetails.Length != 2) { throw new FormatException("EnterpriseAdapter configuration is invalid!"); } var assembly = Assembly.Load(assemblyDetails[1].Trim()); _enterpriseAdapter = (IEnterpriseAdapter)assembly.CreateInstance(assemblyDetails[0]); if (_enterpriseAdapter == null) { throw new InvalidOperationException(string.Format("Unable to create instance of {0}", assemblyDetails[0])); } _adminGroup = ConfigurationManager.AppSettings["EnterpriseAdminGroup"]; if (_adminGroup == null) { throw new Exception("EnterpriseAdminGroup has not been configured!"); } _enterpriseDomain = ConfigurationManager.AppSettings["EnterpriseDomain"]; if (_enterpriseDomain == null) { throw new Exception("EnterpriseDomain has not been configured!"); } _enterpriseAdapter.Initialize(); }