コード例 #1
0
 public ConsumeEventCatalogBuilder(Routes routes, MessageContextFactory contextFactory, DepsCatalog deps)
 {
     _catalog        = new Dictionary <string, ICallbackExecutor>();
     _consumeRoutes  = new ConsumeEventRoute(routes);
     _contextFactory = contextFactory;
     _deps           = deps;
 }
コード例 #2
0
 public ConsumeCommandCatalogBuilder(Routes routes, MessageContextFactory contextFactory, DepsCatalog deps)
 {
     _catalog        = new Dictionary <string, ICallbackExecutor>();
     _routes         = routes;
     _contextFactory = contextFactory;
     _deps           = deps;
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: alasai/WesleyCore
        /// <summary>
        /// 创建数据库
        /// </summary>
        private static void BuildDB()
        {
            try
            {
                var dbFactory = new MessageContextFactory();

                var db = dbFactory.CreateDbContext();
                Console.WriteLine("取得数据库实例");
                //更新数据库
                if (db.Database.GetPendingMigrations().Any())
                {
                    db.Database.Migrate();
                    Console.WriteLine("迁移已完成");
                }
                else
                {
                    Console.WriteLine("没有需要迁移的项目");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("迁移失败");
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
コード例 #4
0
ファイル: ConsumeCatalogBuilder.cs プロジェクト: 2garryn/wpay
 public ConsumeCatalogBuilder(Routes routes, MessageContextFactory contextFactory, IConsumerImplFactory consumerFactory, DepsCatalog deps)
 {
     _consumerFactory = consumerFactory;
     _contextFactory  = contextFactory;
     _deps            = deps;
     _commandCatalog  = new ConsumeCommandCatalogBuilder(routes, contextFactory, _deps);
     _eventCatalog    = new ConsumeEventCatalogBuilder(routes, contextFactory, _deps);
 }
コード例 #5
0
        /// <summary>
        /// Starts dispatching the messages and won't yield until
        /// the client has stopped or has disconnected.
        /// </summary>
        /// <returns></returns>
        protected async Task StartDispatchingAsync([NotNull] IManagedNetworkClient <TOutgoingPayloadType, TIncomingPayloadType> client)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            try
            {
                IPeerRequestSendService <TOutgoingPayloadType> requestService = new PayloadInterceptMessageSendService <TOutgoingPayloadType>(client, client);

                if (!client.isConnected && Logger.IsWarnEnabled)
                {
                    Logger.Warn($"The client was not connected before dispatching started.");
                }

                //TODO: Read the next message before awaiting the result of the dispatch message handling.
                while (client.isConnected && !CancelTokenSource.IsCancellationRequested)                 //if we exported we should reading messages
                {
                    NetworkIncomingMessage <TIncomingPayloadType> message = await client.ReadMessageAsync(CancelTokenSource.Token)
                                                                            .ConfigureAwaitFalse();

                    //Supress and continue reading
                    try
                    {
                        //We don't do anything with the result. We should hope someone registered
                        //a default handler to deal with this situation
                        bool result = await Handlers.TryHandleMessage(MessageContextFactory.Create(client, client, requestService), message)
                                      .ConfigureAwaitFalse();
                    }
                    catch (Exception e)
                    {
                        if (Logger.IsInfoEnabled)
                        {
                            Logger.Info($"Error: {e.Message}\n\n Stack Trace: {e.StackTrace}");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (Logger.IsInfoEnabled)
                {
                    Logger.Info($"Error: {e.Message}\n\n Stack Trace: {e.StackTrace}");
                }

                throw;
            }
            finally
            {
                if (Logger.IsInfoEnabled)
                {
                    Logger.Info("Network client stopped reading.");
                }

                OnClientStoppedHandlingMessages();
            }
        }
コード例 #6
0
        /// <summary>
        /// Starts dispatching the messages and won't yield until
        /// the client has stopped or has disconnected.
        /// </summary>
        /// <returns></returns>
        protected async Task StartDispatchingAsync()
        {
            try
            {
                RequestService = new PayloadInterceptMessageSendService <TOutgoingPayloadType>(Client, Client);

                if (!Client.isConnected && Logger.IsWarnEnabled)
                {
                    Logger.Warn($"The client {name} was not connected before dispatching started.");
                }

                while (Client.isConnected && !isClientExported)                //if we exported we should reading messages
                {
                    if (Logger.IsDebugEnabled)
                    {
                        Logger.Debug("Reading message.");
                    }

                    NetworkIncomingMessage <TIncomingPayloadType> message = await Client.ReadMessageAsync(CancelTokenSource.Token)
                                                                            .ConfigureAwait(true);

                    //Supress and continue reading
                    try
                    {
                        //We don't do anything with the result. We should hope someone registered
                        //a default handler to deal with this situation
                        bool result = await Handlers.TryHandleMessage(MessageContextFactory.Create(Client, Client, RequestService), message)
                                      .ConfigureAwait(true);
                    }
                    catch (Exception e)
                    {
                        if (Logger.IsDebugEnabled)
                        {
                            Logger.Debug($"Error: {e.Message}\n\n Stack Trace: {e.StackTrace}");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (Logger.IsDebugEnabled)
                {
                    Logger.Debug($"Error: {e.Message}\n\n Stack Trace: {e.StackTrace}");
                }

                throw;
            }

            if (Logger.IsDebugEnabled)
            {
                Logger.Debug("Network client stopped reading.");
            }
        }
コード例 #7
0
        public void ParseWords()
        {
            var synonymService        = new SynonymService();
            var messageContextFactory = new MessageContextFactory(synonymService);

            MessageContext messageContext = messageContextFactory.Create(new TestInboundMessage("Hello World. Hello World."));

            messageContext.IdentifiedAreaIds.Count.ShouldBeEquivalentTo(0);
            messageContext.IdentifiedComponentIds.Count.ShouldBeEquivalentTo(0);
            messageContext.IdentifiedComponentStates.Count.ShouldBeEquivalentTo(0);

            messageContext.Words.Count.ShouldBeEquivalentTo(3);
        }
コード例 #8
0
        public void IdentifyAreaIds()
        {
            var synonymService = new SynonymService();

            synonymService.AddSynonymsForArea(new AreaId("Office"), "Büro");

            var messageContextFactory = new MessageContextFactory(synonymService);

            MessageContext messageContext = messageContextFactory.Create(new TestInboundMessage("Hello World. Büro."));

            messageContext.IdentifiedAreaIds.Count.ShouldBeEquivalentTo(1);
            messageContext.IdentifiedComponentIds.Count.ShouldBeEquivalentTo(0);
            messageContext.IdentifiedComponentStates.Count.ShouldBeEquivalentTo(0);

            messageContext.Words.Count.ShouldBeEquivalentTo(4);
        }
コード例 #9
0
 public ConsumeExecutorCatalog(ImmutableDictionary <string, ICallbackExecutor> consumers, MessageContextFactory contextFactory, DepsCatalog depsCatalog)
 {
     _consumers      = consumers;
     _contextFactory = contextFactory;
     _deps           = depsCatalog;
 }
コード例 #10
0
 public MessageMiddleware(IComponentContext contex)
 {
     this._messageContextFactory = new MessageContextFactory(contex.Resolve <CommandParser>());
 }
コード例 #11
0
 public IPeerMessageContext <GameClientPacketPayload> CreateMessageContext()
 {
     return(MessageContextFactory.Create(ConnectionService, SendService, this));
 }
コード例 #12
0
 internal CallbackExecutorCommand(CommandConsumerFactory <T> consumerFactory, MessageContextFactory contextFactory, DepsCatalog deps)
 {
     _consumerFactory = consumerFactory;
     _deps            = deps;
     _contextFactory  = contextFactory;
 }
コード例 #13
0
 internal CallbackExecutorEvent(EventConsumerFactory <TServiceDefinition, T> consumerFactory, MessageContextFactory contextFactory, DepsCatalog deps)
 {
     _consumerFactory = consumerFactory;
     _deps            = deps;
     _contextFactory  = contextFactory;
 }