コード例 #1
0
ファイル: QPConfiguration.cs プロジェクト: QuantumArt/QP
        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);
        }
コード例 #2
0
        public static string GetConnectionString(string customerCode, string appName = "QP8Backend")
        {
            if (!string.IsNullOrWhiteSpace(customerCode))
            {
                var customerElement = XmlConfig.Descendants("customer").SingleOrDefault(n => n.Attribute("customer_name")?.Value == customerCode);
                if (customerElement == null)
                {
                    throw new Exception($"Данный customer code: {customerCode} - отсутствует в конфиге");
                }

                var dbConnectionString = customerElement.Element("db");
                if (dbConnectionString != null)
                {
                    return(TuneConnectionString(dbConnectionString.Value, out var _, appName));
                }
            }

            return(null);
        }
コード例 #3
0
ファイル: QPConfiguration.cs プロジェクト: QuantumArt/QP
        /// <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);
        }
コード例 #4
0
        /// <summary>
        /// Получение переменной приложения из QP конфига
        /// </summary>
        public static string ConfigVariable(string name)
        {
            var elem = XmlConfig.Descendants("app_var").SingleOrDefault(n => n.Attribute("app_var_name")?.Value == name);

            return(elem?.Value ?? string.Empty);
        }