Exemplo n.º 1
0
        internal static async Task <IPAddress> ResolveIPAddressAsync(string addressOrHost, AddressFamily family)
        {
            var loopback = family == AddressFamily.InterNetwork ? IPAddress.Loopback : IPAddress.IPv6Loopback;

            if (addressOrHost.Equals("loopback", StringComparison.OrdinalIgnoreCase))
            {
                return(loopback);
            }

            if (IPAddress.TryParse(addressOrHost, out var address))
            {
                return(address);
            }

            var candidates = await Dns.GetHostAddressesAsync(addressOrHost);

            var chosen = candidates.OrderBy(x => x, IPAddressComparer.Instance).FirstOrDefault();

            if (chosen == null)
            {
                var error = new ConfigurationError($"Hostname {addressOrHost} with family {family} is not a valid IP address or DNS name");

                throw new ConfigurationException(error);
            }

            return(chosen);
        }
Exemplo n.º 2
0
        public ConfigurationError FactoryConfigureICSCommModule(string strEDLFileName, string strGatewayAddress,
                                                                ushort usERTUtilityID)
        {
            ConfigurationError ConfigurationResult = ConfigurationError.SUCCESS;
            IPAddress          GatewayAddress      = null;

            try
            {
                IPAddress.TryParse(strGatewayAddress, out GatewayAddress);
            }
            catch
            {
                ConfigurationResult = ConfigurationError.INVALID_ICS_GATEWAY_ADDRESS;
            }

            if (ConfigurationError.SUCCESS == ConfigurationResult)
            {
                m_ConfigureDevice.IsFactoryConfig   = true;
                m_ConfigureDevice.FactoryConfigType = AMIConfigureDevice.ConfigurationOptions.ICSCommModuleOnly;
                m_ConfigureDevice.GatewayAddress    = GatewayAddress;

                if (0 != usERTUtilityID)
                {
                    m_ConfigureDevice.ERTUtilityID = usERTUtilityID;
                }

                ConfigurationResult = m_ConfigureDevice.Configure(strEDLFileName);
            }

            return(ConfigurationResult);
        }
Exemplo n.º 3
0
        public async Task ConnectAsync()
        {
            var addressParts = projectionHost.Split(':');

            if (addressParts.Length < 2 || !int.TryParse(addressParts[1], out var port))
            {
                port = 2113;
            }

            var endpoints = await Dns.GetHostAddressesAsync(addressParts[0]);

            var endpoint = new IPEndPoint(endpoints.First(x => x.AddressFamily == AddressFamily.InterNetwork), port);

            projectionsManager =
                new ProjectionsManager(
                    connection.Settings.Log, endpoint,
                    connection.Settings.OperationTimeout);
            try
            {
                await projectionsManager.ListAllAsync(connection.Settings.DefaultUserCredentials);
            }
            catch (Exception ex)
            {
                var error = new ConfigurationError($"GetEventStore cannot connect to event store projections: {projectionHost}.");

                throw new ConfigurationException(error, ex);
            }
        }
 public void AddTest()
 {
     ConfigurationError error = new ConfigurationError(new MyNode(), "Argument Exception");
     errors.Add(error);
     Assert.AreEqual(1, errors.Count);
     Assert.AreSame(error, errors[0]);
 }
Exemplo n.º 5
0
        protected ConfigurationResult ConfigureExtendedSelfRead(AMIConfigureDevice ConfigureDevice)
        {
            ConfigurationResult Result      = ConfigurationResult.SUCCESS;
            ConfigurationError  ConfigError = ConfigurationError.GENERAL_ERROR;

            if (Table00.IsTableUsed(2265) &&
                (Table00.DeviceClass.ToUpper().Equals(ITRD_DEVICE_CLASS) ||
                 Table00.DeviceClass.ToUpper().Equals(ITRE_DEVICE_CLASS) ||
                 Table00.DeviceClass.ToUpper().Equals(ITRF_DEVICE_CLASS) ||
                 Table00.DeviceClass.ToUpper().Equals(ITRJ_DEVICE_CLASS) ||
                 Table00.DeviceClass.ToUpper().Equals(ITRK_DEVICE_CLASS)))
            {
                ConfigError = ConfigureDevice.WriteTableByElementRange(
                    CentronTblEnum.MfgTbl217SelfReadTwoLogicalIdentifier,
                    new int[1] {
                    0
                },
                    CentronTblEnum.MfgTbl217SelfReadTwoLogicalIdentifierQualifier,
                    new int[1] {
                    ConfigureDevice.GetFieldArrayLastIndex(CentronTblEnum.MfgTbl217SelfReadTwoLogicalIdentifierQualifier)
                });
            }
            else
            {
                ConfigError = ConfigurationError.OPERATION_NOT_POSSIBLE;
            }

            // Translate to the ItronDevice ConfigurationResult error code since
            // the factory is using ConfigurationError and we do not want to always
            // rely on having the version in AMIConfiguration.dll
            Result = TranslateConfigError(ConfigError);

            return(Result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Configures the meter instrumentation profile config block
        /// with the specified program
        /// </summary>
        /// <param name="ConfigureDevice">AMIConfigureDevice object with the correct table set already loaded</param>
        /// <returns></returns>
        /// Revision History
        /// MM/DD/YY who Version Issue# Description
        /// -------- --- ------- ------ ---------------------------------------
        /// 03/06/12 JKW				Created - Lithium
        ///
        protected ConfigurationResult ConfigureInstrumentationProfile(AMIConfigureDevice ConfigureDevice)
        {
            ConfigurationResult Result      = ConfigurationResult.SUCCESS;
            ConfigurationError  ConfigError = ConfigurationError.GENERAL_ERROR;

            if (Table00.IsTableUsed(2265))
            {
                ConfigError = ConfigureDevice.WriteTableByElementRange(
                    CentronTblEnum.MfgTbl217InstrumentationProfileIntervalLength,
                    null,
                    CentronTblEnum.MfgTbl217InstrumentationProfilePulseWeightSetTwo,
                    new int[1] {
                    ConfigureDevice.GetFieldArrayLastIndex(CentronTblEnum.MfgTbl217InstrumentationProfilePulseWeightSetTwo)
                });
            }
            else
            {
                ConfigError = ConfigurationError.OPERATION_NOT_POSSIBLE;
            }

            // Translate to the ItronDevice ConfigurationResult error code since
            // the factory is using ConfigurationError and we do not want to always
            // rely on having the version in AMIConfiguration.dll
            Result = TranslateConfigError(ConfigError);

            return(Result);
        }
Exemplo n.º 7
0
        public ConfigurationResult Configure(string sProgramName)
#endif
        {
            AMIConfigureCentronII ConfigureDevice = new AMIConfigureCentronII(m_PSEM);
            ConfigurationError    ConfigError     = ConfigurationError.GENERAL_ERROR;

            // Set up the progress bar event handlers
            ConfigureDevice.ShowProgressEvent += this.ShowProgressEvent;
            ConfigureDevice.StepProgressEvent += this.StepProgressEvent;
            ConfigureDevice.HideProgressEvent += this.HideProgressEvent;

            ConfigureDevice.IsCanadian = IsCanadian;

            // We always need to set the Prompt for data so we should just use what is
            // currently in the meter.

            ConfigureDevice.UnitID = UnitID;
            ConfigureDevice.CustomerSerialNumber = SerialNumber;
            ConfigureDevice.InitialDateTime      = null;

            ConfigError = ConfigureDevice.Configure(sProgramName);

            // Translate to the ItronDevice ConfigurationResult error code since
            // the factory is using ConfigurationError and we do not want to always
            // rely on having the version in AMIConfiguration.dll

            return(TranslateConfigError(ConfigError));
        }
Exemplo n.º 8
0
        public void ConfigureServices(IServiceCollection services, IConfiguration config)
        {
            var fullTextType = config.GetValue <string>("fullText:type");

            if (string.Equals(fullTextType, "elastic", StringComparison.OrdinalIgnoreCase))
            {
                var elasticConfiguration = config.GetValue <string>("fullText:elastic:configuration");

                if (string.IsNullOrWhiteSpace(elasticConfiguration))
                {
                    var error = new ConfigurationError("Value is required.", "fullText:elastic:configuration");

                    throw new ConfigurationException(error);
                }

                var indexName = config.GetValue <string>("fullText:elastic:indexName");

                if (string.IsNullOrWhiteSpace(indexName))
                {
                    indexName = "squidex-index";
                }

                services.AddSingleton(
                    c => new ElasticSearchTextIndex(elasticConfiguration, indexName));

                services.AddSingleton <ITextIndex>(
                    c => c.GetRequiredService <ElasticSearchTextIndex>());

                services.AddSingleton <IInitializable>(
                    c => c.GetRequiredService <ElasticSearchTextIndex>());
            }
        }
Exemplo n.º 9
0
        public ConfigurationResult Configure(string sProgramName, PromptForData PFData)
#endif
        {
            AMIConfigureCentronII ConfigureDevice = new AMIConfigureCentronII(m_PSEM);
            ConfigurationError    ConfigError     = ConfigurationError.GENERAL_ERROR;

            // Set up the progress bar event handlers
            ConfigureDevice.ShowProgressEvent += this.ShowProgressEvent;
            ConfigureDevice.StepProgressEvent += this.StepProgressEvent;
            ConfigureDevice.HideProgressEvent += this.HideProgressEvent;

            ConfigureDevice.IsCanadian = IsCanadian;

            ConfigureDevice.UnitID = PFData.UnitID;
            ConfigureDevice.CustomerSerialNumber = PFData.SerialNumber;
            ConfigureDevice.InitialDateTime      = PFData.InitialDateTime;

            ConfigError = ConfigureDevice.Configure(sProgramName);

            // Translate to the ItronDevice ConfigurationResult error code since
            // the factory is using ConfigurationError and we do not want to always
            // rely on having the version in AMIConfiguration.dll

            return(TranslateConfigError(ConfigError));
        }
        public void AddTest()
        {
            ConfigurationError error = new ConfigurationError(new MyNode(), "Argument Exception");

            errors.Add(error);
            Assert.AreEqual(1, errors.Count);
            Assert.AreSame(error, errors[0]);
        }
        public void AddCreateTest()
        {
            errors.Add(new MyNode(), "Argument Exception");
            Assert.AreEqual(1, errors.Count);
            ConfigurationError error = errors[0];

            Assert.AreEqual("Argument Exception", error.Message);
        }
Exemplo n.º 12
0
        private ConfigurationError[] Convert(IList <Exception> errors)
        {
            var result = new ConfigurationError[errors.Count];

            for (int i = 0; i < result.Length; i++)
            {
                result[i] = new ConfigurationError(errors[i]);
            }
            return(result);
        }
Exemplo n.º 13
0
        public static void AddSquidexEventPublisher(this IServiceCollection services, IConfiguration config)
        {
            var eventPublishers = config.GetSection("eventPublishers");

            foreach (var child in eventPublishers.GetChildren())
            {
                var eventPublisherType = child.GetValue <string>("type");

                if (string.IsNullOrWhiteSpace(eventPublisherType))
                {
                    var error = new ConfigurationError("Value is required.", "eventPublishers:{child.Key}:type");

                    throw new ConfigurationException(error);
                }

                var eventsFilter = child.GetValue <string>("eventsFilter");

                var enabled = child.GetValue <bool>("enabled");

                if (string.Equals(eventPublisherType, "RabbitMq", StringComparison.OrdinalIgnoreCase))
                {
                    var publisherConfig = child.GetValue <string>("configuration");

                    if (string.IsNullOrWhiteSpace(publisherConfig))
                    {
                        var error = new ConfigurationError("Value is required.", "eventPublishers:{child.Key}:configuration");

                        throw new ConfigurationException(error);
                    }

                    var exchange = child.GetValue <string>("exchange");

                    if (string.IsNullOrWhiteSpace(exchange))
                    {
                        var error = new ConfigurationError("Value is required.", "eventPublishers:{child.Key}:exchange");

                        throw new ConfigurationException(error);
                    }

                    var name = $"EventPublishers_{child.Key}";

                    if (enabled)
                    {
                        services.AddSingletonAs(c => new RabbitMqEventConsumer(c.GetRequiredService <IJsonSerializer>(), name, publisherConfig, exchange, eventsFilter))
                        .As <IEventConsumer>();
                    }
                }
                else
                {
                    var error = new ConfigurationError($"Unsupported value '{child.Key}", "eventPublishers:{child.Key}:type.");

                    throw new ConfigurationException(error);
                }
            }
        }
Exemplo n.º 14
0
        public string BuildUrl(string path, bool trailingSlash = true)
        {
            if (string.IsNullOrWhiteSpace(BaseUrl))
            {
                var error = new ConfigurationError("urls:baseurl", "Value is required.");

                throw new ConfigurationException(error);
            }

            return(BaseUrl.BuildFullUrl(path, trailingSlash));
        }
Exemplo n.º 15
0
        public HostString BuildHost()
        {
            if (!TryBuildHost(baseUrl, out var host))
            {
                var error = new ConfigurationError("urls:baseurl", "Value is required.");

                throw new ConfigurationException(error);
            }

            return(host);
        }
        public static string GetRequiredValue(this IConfiguration config, string path)
        {
            var value = config.GetValue <string>(path);

            if (string.IsNullOrWhiteSpace(value))
            {
                var error = new ConfigurationError("Value is required.", path);

                throw new ConfigurationException(error);
            }

            return(value);
        }
Exemplo n.º 17
0
        public async Task InitializeAsync(
            CancellationToken ct)
        {
            try
            {
                await client.SoftDeleteAsync(Guid.NewGuid().ToString(), StreamState.Any, cancellationToken : ct);
            }
            catch (Exception ex)
            {
                var error = new ConfigurationError("GetEventStore cannot connect to event store.");

                throw new ConfigurationException(error, ex);
            }
        }
Exemplo n.º 18
0
        public async Task InitializeAsync(CancellationToken ct = default)
        {
            try
            {
                await connection.ConnectAsync();
            }
            catch (Exception ex)
            {
                var error = new ConfigurationError("GetEventStore cannot connect to event store.");

                throw new ConfigurationException(error, ex);
            }

            await projectionClient.ConnectAsync();
        }
Exemplo n.º 19
0
        public async Task InitializeAsync(CancellationToken ct = default)
        {
            try
            {
                CreateCollection();

                await SetupCollectionAsync(Collection, ct);
            }
            catch (Exception ex)
            {
                var error = new ConfigurationError($"MongoDb connection failed to connect to database {Database.DatabaseNamespace.DatabaseName}.");

                throw new ConfigurationException(error, ex);
            }
        }
Exemplo n.º 20
0
 public ConfigurationErrorListViewItem(ConfigurationError error) : base()
 {
     this.error = error;
     if (error.ConfigurationNode != null)
     {
         Text = error.ConfigurationNode.Name;
     }
     StateImageIndex = 0;
     SubItems.Add(String.Empty);
     SubItems.Add(error.Message);
     if (error.ConfigurationNode != null)
     {
         SubItems.Add(error.ConfigurationNode.Path);
     }
 }
        public void ConfigurationError()
        {
            var payload = new ConfigurationErrorPayload
            {
                ConfigurationName = "config",
                Message           = "some message",
                UsedConfiguration = "some value"
            };

            foreach (ConfigurationErrorType value in Enum.GetValues(typeof(ConfigurationErrorType)))
            {
                payload.ErrorType = value;
                var obj = new ConfigurationError(new ConfigurationErrorPayload[] { payload });
                obj.ValidateSchema();
            }
        }
Exemplo n.º 22
0
        public async Task ConnectAsync()
        {
            var addressParts = projectionHost.Split(':');

            if (addressParts.Length < 2 || !int.TryParse(addressParts[1], out var port))
            {
                port = 2113;
            }

            var endpoints = await Dns.GetHostAddressesAsync(addressParts[0]);

            var endpoint = new IPEndPoint(endpoints.First(x => x.AddressFamily == AddressFamily.InterNetwork), port);

            async Task ConnectToSchemaAsync(string schema)
            {
                projectionsManager =
                    new ProjectionsManager(
                        connection.Settings.Log, endpoint,
                        connection.Settings.OperationTimeout,
                        null,
                        schema);

                await projectionsManager.ListAllAsync(connection.Settings.DefaultUserCredentials);
            }

            try
            {
                try
                {
                    await ConnectToSchemaAsync("https");
                }
                catch (HttpRequestException)
                {
                    await ConnectToSchemaAsync("http");
                }
                catch (AggregateException ex) when(ex.Flatten().InnerException is HttpRequestException)
                {
                    await ConnectToSchemaAsync("http");
                }
            }
            catch (Exception ex)
            {
                var error = new ConfigurationError($"GetEventStore cannot connect to event store projections: {projectionHost}.");

                throw new ConfigurationException(error, ex);
            }
        }
        public static string ConfigureByOption(this IConfiguration config, string path, Alternatives options)
        {
            var value = config.GetRequiredValue(path);

            if (options.TryGetValue(value, out var action))
            {
                action();
            }
            else
            {
                var error = new ConfigurationError($"Unsupported value '{value}', supported: {string.Join(" ", options.Keys)}.", path);

                throw new ConfigurationException(error);
            }

            return(value);
        }
        /// <summary>
        /// Event handler for OnFailedToParseConfiguration
        /// </summary>
        /// <param name="mismatchedTypeConfigurations">failed to parse configurations</param>
        private void CreateTypeMismatchEvent(IList <string> mismatchedTypeConfigurations)
        {
            //Remove previous events, they are no longer relevant
            RemoveEvents();

            var ev = new ConfigurationError(new[]
            {
                new ConfigurationErrorPayload
                {
                    ErrorType         = ConfigurationErrorType.TypeMismatch,
                    ConfigurationName = nameof(RemoteConfiguration),
                    UsedConfiguration = AgentConfiguration.RemoteConfiguration.ToString(),
                    Message           = $"Couldn't parse the following configurations: {string.Join(", ", mismatchedTypeConfigurations)}"
                }
            }
                                            );

            _events.Add(ev);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Loads the Factory prompt for values into the program tables
        /// </summary>
        /// <returns>ConfigurationError Code</returns>
        // Revison History:
        // MM/DD/YY who Version Issue# Description
        // -------- --- ------- ------ ---------------------------------------
        // 07/08/10 AF  2.42.02        Created
        // 07/08/10 AF  2.42.03        Updated to use C1219Tables.LandisGyr.Gateway dll
        //
        protected override ConfigurationError LoadFactoryPromptForItems()
        {
            ConfigurationError ConfigError = ConfigurationError.SUCCESS;

            try
            {
                // Load the Unit ID
                m_GatewayTables.SetValue(StdTableEnum.STDTBL6_DEVICE_ID, null, m_strUnitID);

                // Load the Customer Serial Number
                m_GatewayTables.SetValue(StdTableEnum.STDTBL6_UTIL_SER_NO, null, m_strCustomerSerialNumber);
            }
            catch (Exception)
            {
                ConfigError = ConfigurationError.ITEM_NOT_FOUND;
            }

            return(ConfigError);
        }
Exemplo n.º 26
0
        public virtual ConfigurationError GetValue(uint uiID, out object objValue)
        {
            ConfigurationError ConfigError = ConfigurationError.GENERAL_ERROR;
            object             objOutput   = null;

            switch (uiID)
            {
            case (uint)AMIConfigurationItem.UNIT_ID:
            {
                objOutput   = (object)m_ConfigureDevice.UnitID;
                ConfigError = ConfigurationError.SUCCESS;

                break;
            }

            case (uint)AMIConfigurationItem.CUSTOMER_SERIAL_NUMBER:
            {
                objOutput   = (object)m_ConfigureDevice.CustomerSerialNumber;
                ConfigError = ConfigurationError.SUCCESS;

                break;
            }

            case (uint)AMIConfigurationItem.CANADIAN_METER:
            {
                objOutput   = (object)m_ConfigureDevice.IsCanadian;
                ConfigError = ConfigurationError.SUCCESS;

                break;
            }

            default:
            {
                objOutput   = null;
                ConfigError = ConfigurationError.ITEM_NOT_FOUND;
                break;
            }
            }

            objValue = objOutput;
            return(ConfigError);
        }
Exemplo n.º 27
0
        protected ConfigurationResult ConfigureNonBillingEnergyandLoadProfile(AMIConfigureDevice ConfigureDevice)
        {
            ConfigurationResult Result      = ConfigurationResult.SUCCESS;
            ConfigurationError  ConfigError = ConfigurationError.GENERAL_ERROR;

            if (Table00.IsTableUsed(2265) &&
                (Table00.DeviceClass.ToUpper().Equals(ITRE_DEVICE_CLASS) || Table00.DeviceClass.ToUpper().Equals(ITRF_DEVICE_CLASS)) ||
                (Table00.DeviceClass.ToUpper().Equals(ITRK_DEVICE_CLASS)))
            {
                ConfigError = ConfigureDevice.WriteTableByElementRange(
                    CentronTblEnum.MfgTbl217NonBillableEnergyId,
                    new int[1] {
                    0
                },
                    CentronTblEnum.MfgTbl217NonBillableEnergyId,
                    new int[1] {
                    ConfigureDevice.GetFieldArrayLastIndex(CentronTblEnum.MfgTbl217NonBillableEnergyId)
                });

                if (ConfigError == ConfigurationError.SUCCESS)
                {
                    ConfigError = ConfigureDevice.WriteTableByElementRange(
                        CentronTblEnum.MfgTbl217NonBillingLoadProfileIntervalLength,
                        null,
                        CentronTblEnum.MfgTbl217NonBillingLoadProfilePulseWeightSetTwo,
                        new int[1] {
                        ConfigureDevice.GetFieldArrayLastIndex(CentronTblEnum.MfgTbl217NonBillingLoadProfilePulseWeightSetTwo)
                    });
                }
            }
            else
            {
                ConfigError = ConfigurationError.OPERATION_NOT_POSSIBLE;
            }

            // Translate to the ItronDevice ConfigurationResult error code since
            // the factory is using ConfigurationError and we do not want to always
            // rely on having the version in AMIConfiguration.dll
            Result = TranslateConfigError(ConfigError);

            return(Result);
        }
Exemplo n.º 28
0
        public void ConfigureServices(IServiceCollection services, IConfiguration config)
        {
            var fullTextType = config.GetValue <string>("fullText:type");

            if (string.Equals(fullTextType, "Azure", StringComparison.OrdinalIgnoreCase))
            {
                var serviceEndpoint = config.GetValue <string>("fullText:azure:serviceEndpoint");

                if (string.IsNullOrWhiteSpace(serviceEndpoint))
                {
                    var error = new ConfigurationError("Value is required.", "fullText:azure:serviceEndpoint");

                    throw new ConfigurationException(error);
                }

                var serviceApiKey = config.GetValue <string>("fullText:azure:apiKey");

                if (string.IsNullOrWhiteSpace(serviceApiKey))
                {
                    var error = new ConfigurationError("Value is required.", "fullText:azure:apiKey");

                    throw new ConfigurationException(error);
                }

                var indexName = config.GetValue <string>("fullText:azure:indexName");

                if (string.IsNullOrWhiteSpace(indexName))
                {
                    indexName = "squidex-index";
                }

                services.AddSingleton(
                    c => new AzureTextIndex(serviceEndpoint, serviceApiKey, indexName));

                services.AddSingleton <ITextIndex>(
                    c => c.GetRequiredService <AzureTextIndex>());

                services.AddSingleton <IInitializable>(
                    c => c.GetRequiredService <AzureTextIndex>());
            }
        }
Exemplo n.º 29
0
        private static (int, int) GetPorts(IConfiguration config)
        {
            var orleansPortSilo    = config.GetOptionalValue("orleans:siloPort", 11111);
            var orleansPortGateway = config.GetOptionalValue("orleans:gatewayPort", 40000);

            var privatePorts = config.GetOptionalValue("WEBSITE_PRIVATE_PORTS", string.Empty);

            if (!string.IsNullOrWhiteSpace(privatePorts) && config.GetValue <bool>("orleans:useAzureNetwork"))
            {
                var ports = privatePorts.Split(',');

                if (ports.Length < 1 || !int.TryParse(ports[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out orleansPortSilo))
                {
                    var error = new ConfigurationError("Insufficient private ports configured.", "WEBSITE_PRIVATE_PORTS");

                    throw new ConfigurationException(error);
                }
            }

            return(orleansPortSilo, orleansPortGateway);
        }
Exemplo n.º 30
0
        /// <summary>
        /// 根据上游请求找到下游请求对象
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public DownstreamRoute Get(DownstreamContext context)
        {
            var configuration = context.Configuration;

            var httpContextRequest = context.HttpContext.Request;

            var upstreamUrlPath = httpContextRequest.Path.ToString();

            var upstreamQueryString = httpContextRequest.QueryString.ToString();

            var upstreamHost = httpContextRequest.Headers["Host"];


            var configRoutes = configuration.Routes;

            if (configRoutes == null || configRoutes.Count == 0)
            {
                var error = new ConfigurationError(upstreamUrlPath);
                _errors.Add(error);

                return(null);
            }

            var upstreamUri = $"{upstreamHost}{upstreamUrlPath}";

            //从配置文件里面查找进行
            var configRoute = configRoutes.FirstOrDefault(x => x.UpstreamHost + x.UpstreamPathTemplate == upstreamUri);

            if (configRoute == null)
            {
                var error = new ConfigurationError(upstreamUrlPath);
                _errors.Add(error);

                return(null);
            }

            DownstreamRoute route = GetDownstreamRoute(configRoute, upstreamQueryString);

            return(route);
        }
Exemplo n.º 31
0
        public Task InitializeAsync(CancellationToken ct = default)
        {
            try
            {
                var currentConnection = connection.Value;

                if (!currentConnection.IsOpen)
                {
                    var error = new ConfigurationError($"RabbitMq event bus failed to connect to {connectionFactory.Endpoint}.");

                    throw new ConfigurationException(error);
                }

                return(Task.CompletedTask);
            }
            catch (Exception ex)
            {
                var error = new ConfigurationError($"RabbitMq event bus failed to connect to {connectionFactory.Endpoint}.");

                throw new ConfigurationException(error, ex);
            }
        }
Exemplo n.º 32
0
 public void FixtureSetUp()
 {
     node = new ApplicationConfigurationNode(ApplicationData.FromCurrentAppDomain());
     message = "Test";
     error = new ConfigurationError(node, message);
 }
 public void TestInitialize()
 {
     node = new ConfigurationApplicationNode(ConfigurationApplicationFile.FromCurrentAppDomain());
     message = "Test";
     error = new ConfigurationError(node, message);
 }
Exemplo n.º 34
0
		private void DisplayConfigurationError(ConfigurationError error)
		{
			Console.WriteLine("DisplayConfigurationError:" + error.Message);
		}