コード例 #1
0
        public static async Task Main(string[] args)
        {
            //
            //	get configuration information
            //
            MessageQueueAppConfig messageQueueAppConfig = new MessageQueueAppConfig();
            ConnectionStrings     connectionStrings     = new ConnectionStrings();

            string environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
            string jsonFile    = $"appsettings.{environment}.json";

            var configBuilder = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile(jsonFile, optional: true, reloadOnChange: true);

            IConfigurationRoot configuration = configBuilder.Build();

            configuration.GetSection("MessageQueueAppConfig").Bind(messageQueueAppConfig);
            configuration.GetSection("ConnectionStrings").Bind(connectionStrings);
            //
            //	set up sending queue
            //
            IMessageQueueConnection sendingQueueConnection = new MessageQueueConnection(messageQueueAppConfig);

            sendingQueueConnection.CreateConnection();

            List <IMessageQueueConfiguration> messageQueueConfigurations = new List <IMessageQueueConfiguration>();
            //
            //	Inventory Received Transactions
            //
            IMessageQueueConfiguration inventoryReceivedConfiguration = new MessageQueueConfiguration(MessageQueueExchanges.InventoryReceived, messageQueueAppConfig, sendingQueueConnection);

            inventoryReceivedConfiguration.AddQueue(MessageQueueEndpoints.SalesOrderQueue);
            inventoryReceivedConfiguration.AddQueue(MessageQueueEndpoints.PurchaseOrderQueue);
            inventoryReceivedConfiguration.AddQueue(MessageQueueEndpoints.LoggingQueue);

            inventoryReceivedConfiguration.InitializeOutboundMessageQueueing();
            messageQueueConfigurations.Add(inventoryReceivedConfiguration);
            //
            //	Product Creation and Updates
            //
            IMessageQueueConfiguration productUpdatedConfiguration = new MessageQueueConfiguration(MessageQueueExchanges.ProductUpdated, messageQueueAppConfig, sendingQueueConnection);

            productUpdatedConfiguration.AddQueue(MessageQueueEndpoints.SalesOrderQueue);
            productUpdatedConfiguration.AddQueue(MessageQueueEndpoints.PurchaseOrderQueue);
            productUpdatedConfiguration.AddQueue(MessageQueueEndpoints.LoggingQueue);

            productUpdatedConfiguration.InitializeOutboundMessageQueueing();
            messageQueueConfigurations.Add(productUpdatedConfiguration);
            //
            //	Inventory Shipped Transactions
            //
            IMessageQueueConfiguration inventoryShippedConfiguration = new MessageQueueConfiguration(MessageQueueExchanges.InventoryShipped, messageQueueAppConfig, sendingQueueConnection);

            inventoryShippedConfiguration.AddQueue(MessageQueueEndpoints.SalesOrderQueue);
            inventoryShippedConfiguration.AddQueue(MessageQueueEndpoints.LoggingQueue);

            inventoryShippedConfiguration.InitializeOutboundMessageQueueing();
            messageQueueConfigurations.Add(inventoryShippedConfiguration);

            //
            //	initialize Sending Messages
            //
            IInventoryManagementDataService inventoryManagementDataService = new InventoryManagementDataService();
            IMessageQueueProcessing         messageProcessing = new MessageProcessing(inventoryManagementDataService);

            IHostedService sendInventoryManagementMessages = new SendMessages(sendingQueueConnection, messageProcessing,
                                                                              messageQueueAppConfig, connectionStrings, messageQueueConfigurations, MessageQueueEndpoints.InventoryQueue);
            //
            //	set up receiving queue
            //
            IMessageQueueConnection receivingConnection = new MessageQueueConnection(messageQueueAppConfig);

            receivingConnection.CreateConnection();

            List <IMessageQueueConfiguration> inboundMessageQueueConfigurations = new List <IMessageQueueConfiguration>();
            IMessageQueueConfiguration        inboundConfiguration = new MessageQueueConfiguration(messageQueueAppConfig, receivingConnection);

            inboundMessageQueueConfigurations.Add(inboundConfiguration);

            inboundConfiguration.InitializeInboundMessageQueueing(MessageQueueEndpoints.InventoryQueue);
            inboundConfiguration.InitializeLoggingExchange(MessageQueueExchanges.Logging, MessageQueueEndpoints.LoggingQueue);
            IInventoryManagementDataService inboundInventoryManagementDataService = new InventoryManagementDataService();
            IMessageQueueProcessing         inboundMessageProcessing = new MessageProcessing(inboundInventoryManagementDataService);

            IHostedService receiveInventoryManagementMessages = new ReceiveMessages(receivingConnection, inboundMessageProcessing, messageQueueAppConfig, connectionStrings, inboundMessageQueueConfigurations);
            //
            //	Set Up Message Processing
            //
            IInventoryManagementDataService inventoryManagementProcessingDataService = new InventoryManagementDataService();
            IMessageQueueProcessing         messageProcessor = new MessageProcessing(inventoryManagementProcessingDataService);
            ProcessMessages processMessages = new ProcessMessages(messageProcessor, messageQueueAppConfig, connectionStrings);

            var builder = new HostBuilder().ConfigureAppConfiguration((hostingContext, config) => {})
                          .ConfigureServices((hostContext, services) =>
            {
                services.AddTransient <IHostedService>(provider => processMessages);
            })
                          .ConfigureServices((hostContext, services) =>
            {
                services.AddTransient <IHostedService>(provider => sendInventoryManagementMessages);
            })
                          .ConfigureServices((hostContext, services) =>
            {
                services.AddTransient <IHostedService>(provider => receiveInventoryManagementMessages);
            })
                          .ConfigureLogging((hostingContext, logging) =>
            {
                logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                logging.AddConsole();
            });

            await builder.RunConsoleAsync();
        }
コード例 #2
0
 private void Process(string msg)
 {
     ProcessMessages?.Invoke(String.Format("{0}: {1}", DateTime.Now.ToString(), msg));
 }
コード例 #3
0
        public static WebSocketConnectionInfo Create(WebSocketHttpRequest request, string clientIp, int clientPort, string negotiatedSubprotocol, ProcessMessages PM)
        {
            var info = new WebSocketConnectionInfo
            {
                Origin                = request["Origin"] ?? request["Sec-WebSocket-Origin"],
                Host                  = request["Host"],
                SubProtocol           = request["Sec-WebSocket-Protocol"],
                Path                  = request.Path,
                ClientIpAddress       = clientIp,
                ClientPort            = clientPort,
                NegotiatedSubProtocol = negotiatedSubprotocol,
                Headers               = new Dictionary <string, string>(request.Headers, System.StringComparer.InvariantCultureIgnoreCase),
                PM = PM
            };
            var cookieHeader = request["Cookie"];

            if (cookieHeader != null)
            {
                var match  = CookieRegex.Match(cookieHeader);
                var fields = match.Groups["cookie_name"].Captures;
                var values = match.Groups["cookie_value"].Captures;
                for (var i = 0; i < fields.Count; i++)
                {
                    var name  = fields[i].ToString();
                    var value = values[i].ToString();
                    info.Cookies[name] = value;
                }
            }

            return(info);
        }
コード例 #4
0
 public TryOutController(ILogger <TryOutController> log, ProcessMessages processMessages)
 {
     _log             = log;
     _processMessages = processMessages;
 }
コード例 #5
0
ファイル: Client.cs プロジェクト: Fox0074/TelegramBot
    private void Listener()
    {
        while (true)
        {
            try
            {
                if (ListenerToken.IsCancellationRequested)
                {
                    return;
                }

                if (!IsConnected)
                {
                    _Connect();
                }

                if (!_IsAuthorized)
                {
                    Authorized();
                }

                while (true)
                {
                    if (ListenerToken.IsCancellationRequested)
                    {
                        return;
                    }
                    {
                        Unit msg;
                        try
                        {
                            msg = ReceiveData <Unit>();
                        }
                        catch (Exception ex)
                        {
                            Unit exUnit = new Unit("Exception", null);
                            exUnit.Exception = ex.InnerException ?? ex;
                            SendData(exUnit);
                            continue;
                        }

                        if (!msg.IsAnswer)
                        {
                            ProcessMessages.ProcessMessage(msg, this);
                        }
                    }
                }
            }
            catch (TaskCanceledException)
            {
                return;
            }
            catch (Exception ex)
            {
                if (Events.OnError != null)
                {
                    Events.OnError.BeginInvoke(ex, null, null);
                }
            }
            finally
            {
                _Dicsonnect();
            }

            Thread.Sleep(2000);
        }
    }
コード例 #6
0
 public IntendsHandlerController(ILogger <IntendsHandlerController> log, ProcessMessages processMessages)
 {
     _log             = log;
     _processMessages = processMessages;
 }