public static List <QaConfigCustomer> GetCustomers(string appName) { List <QaConfigCustomer> customers; if (ConfigServiceUrl != null && ConfigServiceToken != null) { var service = new CachedQPConfigurationService(ConfigServiceUrl, ConfigServiceToken, Options.QpConfigPollingInterval); customers = AsyncHelper.RunSync(() => service.GetCustomers()).ConvertAll(c => new QaConfigCustomer { CustomerName = c.Name, ExcludeFromSchedulers = c.ExcludeFromSchedulers, ConnectionString = c.ConnectionString, DbType = (DatabaseType)(int)c.DbType }); } else { customers = GetQaConfiguration().Customers.ToList(); } foreach (QaConfigCustomer entry in customers) { entry.ConnectionString = TuneConnectionString(entry.ConnectionString, appName, entry.DbType); } return(customers); }
public static async Task <Configuration> GetQpConfiguration() { Configuration result; if (ConfigServiceUrl != null && ConfigServiceToken != null) { var service = new CachedQPConfigurationService(ConfigServiceUrl, ConfigServiceToken); result = new Configuration(); result.Customers = (await service.GetCustomers()).ToArray(); result.Variables = (await service.GetVariables()).ToArray(); } else { var configPath = GetQpConfigPath(); var configSerializer = new XmlSerializer(typeof(Configuration)); try { using (var xmlTextReader = new XmlTextReader(configPath)) { result = (Configuration)configSerializer.Deserialize(xmlTextReader); } } catch (Exception e) { throw new InvalidOperationException("QP8 configuration is incorrect: " + e.Message); } } return(result); }
public static async Task <CustomerConfiguration> GetCustomerConfiguration(string customerCode) { CustomerConfiguration result; if (ConfigServiceUrl != null && ConfigServiceToken != null) { var service = new CachedQPConfigurationService(ConfigServiceUrl, ConfigServiceToken); result = await service.GetCustomer(customerCode); } else { var config = await GetQpConfiguration(); result = config.Customers.SingleOrDefault(n => n.Name == customerCode); } if (result == null) { throw new InvalidOperationException($"Cannot load customer code {customerCode} from QP8 configuration"); } result.ConnectionString = result.ConnectionString.Replace("Provider=SQLOLEDB;", ""); return(result); }
public static List <string> GetCustomerCodes() { if (ConfigServiceUrl != null && ConfigServiceToken != null) { var service = new CachedQPConfigurationService(ConfigServiceUrl, ConfigServiceToken, Options.QpConfigPollingInterval); var customers = AsyncHelper.RunSync(() => service.GetCustomers()); return(customers.ConvertAll(c => c.Name)); } return(GetQaConfiguration().Customers.Select(c => c.CustomerName).ToList()); }
public static QpConnectionInfo GetConnectionInfo(string customerCode, string appName = "QP8Backend") { if (!String.IsNullOrWhiteSpace(customerCode)) { string connectionString; DatabaseType dbType = default(DatabaseType); if (ConfigServiceUrl != null && ConfigServiceToken != null) { var service = new CachedQPConfigurationService(ConfigServiceUrl, ConfigServiceToken, Options.QpConfigPollingInterval); var customer = AsyncHelper.RunSync(() => service.GetCustomer(customerCode)); // TODO: handle 404 if (customer == null) { throw new Exception($"Данный customer code: {customerCode} - отсутствует в конфиге"); } connectionString = customer.ConnectionString; dbType = (DatabaseType)(int)customer.DbType; } else { XElement customerElement = XmlConfig .Descendants("customer") .SingleOrDefault(n => n.Attribute("customer_name")?.Value == customerCode); if (customerElement == null) { throw new Exception($"Данный customer code: {customerCode} - отсутствует в конфиге"); } connectionString = customerElement.Element("db")?.Value; var dbTypeString = customerElement.Attribute("db_type")?.Value; if (!string.IsNullOrEmpty(dbTypeString) && Enum.TryParse(dbTypeString, true, out DatabaseType parsed)) { dbType = parsed; } } if (!String.IsNullOrEmpty(connectionString)) { connectionString = TuneConnectionString(connectionString, appName, dbType); return(new QpConnectionInfo(connectionString, dbType)); } } return(null); }
/// <summary> /// Получение переменной приложения из QP конфига /// </summary> public static string ConfigVariable(string name) { if (ConfigServiceUrl != null && ConfigServiceToken != null) { var service = new CachedQPConfigurationService(ConfigServiceUrl, ConfigServiceToken, Options.QpConfigPollingInterval); var variables = AsyncHelper.RunSync(() => service.GetVariables()); var variable = variables.SingleOrDefault(v => v.Name == name); return(variable?.Value ?? String.Empty); } XElement elem = XmlConfig .Descendants("app_var") .SingleOrDefault(n => n.Attribute("app_var_name")?.Value == name); return(elem?.Value ?? String.Empty); }