public async Task BaseDispatcher_PublishCommandAsync_Should_Not_Throw_Exception_If_NoConfiguration_IsDefined_And_LogWarning()
        {
            var loggerMock        = new Mock <ILogger>();
            var loggerFactoryMock = new Mock <ILoggerFactory>();

            loggerFactoryMock.Setup(m => m.CreateLogger(It.IsAny <string>()))
            .Returns(loggerMock.Object);
            var fakeScopeFactory = new TestScopeFactory(new TestScope(new Dictionary <Type, object>
            {
                { typeof(ILoggerFactory), loggerFactoryMock.Object }
            }));

            bool coreDispatcherCalledWithoutSecurityCritical = false;
            var  d = new BaseDispatcher(new CQELight.Dispatcher.Configuration.DispatcherConfiguration(false), fakeScopeFactory);

            var command = new TestCommand();

            CoreDispatcher.OnCommandDispatched += (c) =>
            {
                coreDispatcherCalledWithoutSecurityCritical = object.ReferenceEquals(c, command);
                return(Task.FromResult(Result.Ok()));
            };

            //Shouldn't throw exception
            await d.DispatchCommandAsync(command).ConfigureAwait(false);

            coreDispatcherCalledWithoutSecurityCritical.Should().BeTrue();
        }
Пример #2
0
 public NetLibHost(IFactory <NetManager, MutableSessionCollection> sessionsFactory,
                   IFactory <SessionCollection, IHostOperationExecutor> executorFactory,
                   BaseDispatcher <TMessage, TResponse> dispatcher,
                   SessionRequestHandler handler, ILoggerFactory loggerFactory) : base(sessionsFactory, executorFactory, dispatcher, handler, loggerFactory)
 {
     Manager = new NetManager(this);
 }
Пример #3
0
        public async Task BaseDispatcher_DispatchEventAsync_Should_Not_Throw_Exception_If_NoConfiguration_IsDefined_And_LogWarning()
        {
            var loggerMock        = new Mock <ILogger>();
            var loggerFactoryMock = new Mock <ILoggerFactory>();

            loggerFactoryMock.Setup(m => m.CreateLogger(It.IsAny <string>()))
            .Returns(loggerMock.Object);
            var fakeScopeFactory = new TestScopeFactory(new TestScope(new Dictionary <Type, object>
            {
                { typeof(ILoggerFactory), loggerFactoryMock.Object }
            }));

            bool coreDispatcherCalledWithoutSecurityCritical = false;

            var d = new BaseDispatcher(new DispatcherConfiguration(false), fakeScopeFactory);

            var evt = new TestEvent();

            CoreDispatcher.OnEventDispatched += (e) =>
            {
                coreDispatcherCalledWithoutSecurityCritical = object.ReferenceEquals(e, evt);
                return(Task.CompletedTask);
            };

            //Shouldn't throw exception
            await d.PublishEventAsync(evt).ConfigureAwait(false);

            coreDispatcherCalledWithoutSecurityCritical.Should().BeTrue();
        }
Пример #4
0
 public static void Close()
 {
     BaseDispatcher.Invoke(ReleaseMutex);
     TeraSniffer.Instance.Enabled = false;
     SettingsWriter.Save();
     WindowManager.Dispose();
     ProxyInterface.Instance.Disconnect(); //ProxyOld.CloseConnection();
     UpdateManager.StopTimer();
     Environment.Exit(0);
 }
Пример #5
0
 protected AbstractClient(IFactory <TConnection, Session> sessionFactory, IFactory <Session, IClientOperationExecutor> executorFactory, BaseDispatcher <TRequest, TResponse> dispatcher, BaseSerializer serializer, ILoggerFactory loggerFactory)
 {
     Serializer                = serializer;
     _sessionFactory           = sessionFactory;
     _executorFactory          = executorFactory;
     _dispatcher               = dispatcher;
     _dispatcher.ExecutionSide = Side.Client;
     Logger  = loggerFactory.CreateLogger(GetType().FullName);
     Session = NotConnectedSession.Default;
 }
Пример #6
0
 protected AbstractHost(IFactory <TConnectionCollection, MutableSessionCollection> sessionsFactory,
                        IFactory <SessionCollection, IHostOperationExecutor> executorFactory,
                        BaseDispatcher <TRequest, TResponse> dispatcher, SessionRequestHandler handler, ILoggerFactory loggerFactory)
 {
     Logger                   = loggerFactory.CreateLogger(GetType().FullName);
     _sessionsFactory         = sessionsFactory;
     _executorFactory         = executorFactory;
     _handler                 = handler;
     Dispatcher               = dispatcher;
     Dispatcher.ExecutionSide = Side.Server;
 }
Пример #7
0
 public static void FUBH()
 {
     BaseDispatcher.BeginInvoke(new Action(() =>
     {
         if (fubh == null)
         {
             fubh = new FUBH();
         }
         fubh.Show();
     }));
 }
 public MessageProcessor(
     TelegramProxies.PogoTelegramProxy proxy,
     RaidDispatcher dispatcher,
     Queries.StatePeakQuery lastStateQuery,
     DataAccess.Commands.Raid.IModifyChatTitleCommand modifyChatTitleCommand
     )
     : base(proxy, dispatcher, lastStateQuery, modifyChatTitleCommand)
 {
     this.proxy          = proxy;
     this.dispatcher     = dispatcher;
     this.lastStateQuery = lastStateQuery;
 }
 public BaseMessageProcessor(
     TelegramBotClient proxy,
     BaseDispatcher dispatcher,
     Queries.StatePeakQuery lastStateQuery,
     DataAccess.Commands.Raid.IModifyChatTitleCommand modifyChatTitleCommand
     )
 {
     this.proxy                  = proxy;
     this.dispatcher             = dispatcher;
     this.lastStateQuery         = lastStateQuery;
     this.modifyChatTitleCommand = modifyChatTitleCommand;
 }
Пример #10
0
        public async Task BaseDispatcher_PublishCommandAsync_Should_Keep_Result_Info()
        {
            var cfgBuilder = new DispatcherConfigurationBuilder();

            cfgBuilder
            .ForCommand <TestResultCommand>()
            .UseBuses(typeof(FakeResultDataBus));

            var dispatcher = new BaseDispatcher(cfgBuilder.Build());

            var result = await dispatcher.DispatchCommandAsync(new TestResultCommand());

            result.Should().BeOfType <Result <string> >();
        }
Пример #11
0
 public static void Close(bool releaseMutex = true, int code = 0)
 {
     _running = false;
     PacketAnalyzer.Sniffer.Enabled = false;
     Settings?.Save();
     WindowManager.Dispose();
     StubInterface.Instance.Disconnect();
     Firebase.Dispose();
     UpdateManager.StopTimer();
     if (releaseMutex)
     {
         BaseDispatcher.Invoke(ReleaseMutex);
     }
     Environment.Exit(code);
 }
Пример #12
0
 public static void ReleaseMutex()
 {
     _running = false;
     BaseDispatcher.Invoke(() =>
     {
         try
         {
             _mutex?.ReleaseMutex();
         }
         catch (Exception e)
         {
             Log.F($"Failed to release mutex: {e}");
         }
     });
 }
Пример #13
0
        public async Task BaseDispatcher_PublishCommandAsync_WithResult_Should_Enter_InGoodPath_DependingOfResult()
        {
            var cfgBuilder = new DispatcherConfigurationBuilder();

            cfgBuilder
            .ForCommand <TestCommand>()
            .UseBuses(typeof(FakeFailResultBus), typeof(FakeOkResultBus));

            var dispatcher = new BaseDispatcher(cfgBuilder.Build());

            bool successCalled = false;
            bool failureCalled = false;

            (await dispatcher.DispatchCommandAsync(new TestCommand()))
            .OnSuccess(() => successCalled = true)
            .OnFailure(() => failureCalled = true);

            successCalled.Should().BeFalse();
            failureCalled.Should().BeTrue();
        }
Пример #14
0
 private static void LoadModules()
 {
     BaseDispatcher.Invoke(() =>
     {
         try
         {
             ModuleLoader.LoadModules(BasePath);
         }
         catch (FileLoadException fle)
         {
             TccMessageBox.Show("TCC module loader", SR.ErrorWhileLoadingModule(fle.FileName), MessageBoxButton.OK, MessageBoxImage.Error);
             Close();
         }
         catch (FileNotFoundException fnfe)
         {
             TccMessageBox.Show("TCC module loader", SR.ErrorWhileLoadingModule(Path.GetFileName(fnfe.FileName)), MessageBoxButton.OK, MessageBoxImage.Error);
             Close();
         }
     });
 }
Пример #15
0
        public async Task PublishEventRange_NoSequence_Should_Respect_Order_SameAggregateId()
        {
            var aggId  = Guid.NewGuid();
            var data   = new DataHolder();
            var events = new Queue <IDomainEvent>();

            events.Enqueue(new EventOne(data, aggId));
            events.Enqueue(new EventTwo(data, aggId));
            events.Enqueue(new EventThree(data, aggId));

            var builder = new DispatcherConfigurationBuilder();

            builder
            .ForAllEvents()
            .UseBus <InMemoryEventBus>();
            var dispatcher = new BaseDispatcher(builder.Build());

            await dispatcher.PublishEventsRangeAsync(events);

            data.Data[aggId].Should().Be("123");
        }
Пример #16
0
 public Client(IFactory <NetPeer, Session> sessionFactory, IFactory <Session, IClientOperationExecutor> executorFactory, BaseDispatcher <TRequest, TResponse> dispatcher, BaseSerializer serializer, ILoggerFactory loggerFactory) : base(sessionFactory, executorFactory, dispatcher, serializer, loggerFactory)
 {
     Manager = new NetManager(this);
 }
 public TcpNetOperationHost(IFactory <Socket, MutableSessionCollection> sessionsFactory, IFactory <SessionCollection, IHostOperationExecutor> executorFactory, BaseDispatcher <TRequest, TResponse> dispatcher, SessionRequestHandler handler, ILoggerFactory loggerFactory) : base(sessionsFactory, executorFactory, dispatcher, handler, loggerFactory)
 {
 }
 public TcpNetOperationClient(IFactory <Socket, Session> sessionFactory, IFactory <Session, IClientOperationExecutor> executorFactory, BaseDispatcher <TRequest, TResponse> dispatcher, ILoggerFactory logger, BaseSerializer serializer) : base(sessionFactory, executorFactory, dispatcher, serializer, logger)
 {
     Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     Client.LingerState.Enabled = false;
     Client.Blocking            = false;
 }