internal override DispatchCommand GetLastExecutedCommand(DispatchCommand last) { if (last.Is<ConfirmTrackStretchCommand>()) { Call.IsDeparted = true; return this; } return last; }
public FriendServerChangedDataModel(string accountName, string serverName) : base(SixIconFont.withSIX_icon_Cloud) { AccountName = accountName; ServerName = serverName; OnClickDispatch = new DispatchCommand <FriendServerChangedCommand>(new FriendServerChangedCommand()); }
public ChatReceivedDataModel(string fromUserName, Uri fromAvatar, string message) : base(SixIconFont.withSIX_icon_Chat_Message) { FromUserName = fromUserName; FromAvatar = fromAvatar; Message = message; OnClickDispatch = new DispatchCommand<ChatMessageRecievedCommand>(new ChatMessageRecievedCommand()); }
internal override DispatchCommand GetLastExecutedCommand(DispatchCommand last) { if (last.Is<DepartureTrackStretchCommand>()) { Call.IsArrived = true; return NullCommand; } return last; }
public void should_invoke_both_sync_and_async_handlers() { _messageDispatcher.LoadMessageHandlerInvokers(); var asyncHandler = new AsyncCommandHandler { WaitForSignal = true }; _containerMock.Setup(x => x.GetInstance(typeof(AsyncCommandHandler))).Returns(asyncHandler); var syncHandler = new SyncCommandHandler(); _containerMock.Setup(x => x.GetInstance(typeof(SyncCommandHandler))).Returns(syncHandler); var command = new DispatchCommand(); DispatchFromDefaultDispatchQueue(command); syncHandler.Called.ShouldBeTrue(); asyncHandler.CalledSignal.Wait(50.Milliseconds()).ShouldBeFalse(); command.Signal.Set(); asyncHandler.CalledSignal.Wait(1000.Milliseconds()).ShouldBeTrue(); }
public ChatReceivedDataModel(string fromUserName, Uri fromAvatar, string message) : base(SixIconFont.withSIX_icon_Chat_Message) { FromUserName = fromUserName; FromAvatar = fromAvatar; Message = message; OnClickDispatch = new DispatchCommand <ChatMessageRecievedCommand>(new ChatMessageRecievedCommand()); }
/// <summary> /// Enqueue a command /// </summary> /// <param name="command">Get the command which was </param> public void Add(DispatchCommand command) { if (command == null) { throw new ArgumentNullException("command"); } _queue.Enqueue(command); }
/// <summary> /// Initializes a new instance of the <see cref="StoredCommand" /> class. /// </summary> /// <param name="msg">The MSG.</param> /// <exception cref="System.ArgumentNullException">msg</exception> public StoredCommand(DispatchCommand msg) { if (msg == null) { throw new ArgumentNullException("msg"); } Command = msg.Command; Id = Command.CommandId; Attempts = msg.Attempts; }
public void Enqueue() { var dispatcher = new AsyncHandler(1); var context = new DownContext(null, null); var state = new DispatchCommand(new FakeCommand()); dispatcher.HandleDownstream(context, state); Assert.True(context.WaitDown(TimeSpan.FromSeconds(1))); Assert.Same(state, context.Message); }
private void EnqueueCommand(DispatchCommand dispatchCmd) { _commands.Enqueue(dispatchCmd); if (_closing) { return; } StartWorker(); }
/// <summary> /// Enqueue a command /// </summary> /// <param name="command">Get the command which was </param> public void Add(DispatchCommand command) { using (var session = _documentStore.OpenSession()) { Diagnostics(command.Command.CommandId, session, "Add"); var cmd = new StoredCommand(command); cmd.ProcessedAt = DateTime.Now; session.Store(cmd); session.SaveChanges(); } }
/// <summary> /// Re add a command which we've tried to invoke but failed. /// </summary> /// <param name="command">Command to add</param> public void Update(DispatchCommand command) { lock (_lock) { var first = _queue.FirstOrDefault(x => x.Command.Command.CommandId == command.Command.CommandId); if (first != null) { first.StartedAt = DateTime.MinValue; } } }
/// <summary> /// Dispatch the command to the handler /// </summary> /// <typeparam name="T">Type of command</typeparam> /// <param name="command">Command to execute</param> /// <remarks>Implementations should throw exceptions unless they are asynchronous or will attempt to retry later.</remarks> public void Dispatch <T>(T command) where T : class, ICommand { if (command == null) { throw new ArgumentNullException("command"); } var msg = new DispatchCommand(command); _pipeline.Send(msg); }
public ProcessManagerDispatcher( DispatchCommand dispatchCommand, IProcessManagerCheckpointRepository <TCheckpoint> checkpointRepository, IProcessManagerFactory processManagerFactory = null, BuildProcessManagerId buildProcessId = null) { _checkpointRepository = checkpointRepository; _dispatchCommand = dispatchCommand; _processManagerFactory = processManagerFactory ?? new DefaultProcessManagerFactory(); _buildProcessId = buildProcessId ?? DefaultBuildProcessManagerId; _byCorrelationId = new Dictionary <Type, Func <object, string> >(); _activeProcesses = new ConcurrentDictionary <string, CheckpointedProcess>(); }
public void DispatchTwo_SingleWorker() { var dispatcher = new AsyncHandler(1); var state1 = new DispatchCommand(new FakeCommand()); var state2 = new DispatchCommand(new FakeCommand()); var context = new DownContext(null, null); dispatcher.HandleDownstream(context, state1); dispatcher.HandleDownstream(context, state2); Assert.True(context.WaitDown(TimeSpan.FromSeconds(1))); Assert.IsType <DispatchCommand>(context.Message); }
/// <summary> /// Add a new command /// </summary> /// <param name="command">Store the command in the DB. You can use the <see cref="ICommand.CommandId"/> as an identity.</param> public void Add(DispatchCommand command) { if (command == null) { throw new ArgumentNullException("command"); } lock (_lock) { _queue.Add(new MyStruct { Command = command }); } }
public static ProcessHandler <TProcess, TCheckpoint> For <TProcess, TCheckpoint>( DispatchCommand dispatchCommand, IProcessManagerCheckpointRepository <TCheckpoint> checkpointRepository, IProcessManagerFactory processManagerFactory = null, ProcessHandler <TProcess, TCheckpoint> .BuildProcessManagerId buildProcessId = null) where TProcess : IProcessManager where TCheckpoint : IComparable <string> { return(new ProcessHandler <TProcess, TCheckpoint>( dispatchCommand, checkpointRepository, processManagerFactory, buildProcessId)); }
public void TwoWorkers_DispatchTwoThreads() { var dispatcher = new AsyncHandler(2); var state1 = new DispatchCommand(new FakeCommand()); var state2 = new DispatchCommand(new FakeCommand()); var evt = new ManualResetEvent(false); var context = new DownContext(null, x => evt.WaitOne()); dispatcher.HandleDownstream(context, state1); Assert.True(context.WaitDown(TimeSpan.FromMilliseconds(100))); context.ResetDown(); dispatcher.HandleDownstream(context, state2); Assert.True(context.WaitDown(TimeSpan.FromMilliseconds(100))); }
public void should_not_clone_message_when_dispatching_locally_to_the_current_queue() { LoadAndStartDispatcher(); var handler = new SyncCommandHandler(); _containerMock.Setup(x => x.GetInstance(typeof(SyncCommandHandler))).Returns(handler); var command = new DispatchCommand(); DispatchFromDefaultDispatchQueue(command); Wait.Until(() => handler.Called, 5.Seconds()); handler.ReceivedMessage.ShouldNotBeNull(); handler.ReceivedMessage.ShouldBeTheSameAs(command); }
public void should_not_clone_message_when_dispatching_a_remote_message() { _messageDispatcher.LoadMessageHandlerInvokers(); var handler = new SyncCommandHandler(); _containerMock.Setup(x => x.GetInstance(typeof(SyncCommandHandler))).Returns(handler); var command = new DispatchCommand(); Dispatch(command); Wait.Until(() => handler.Called, 5.Seconds()); handler.ReceivedMessage.ShouldNotBeNull(); handler.ReceivedMessage.ShouldBeTheSameAs(command); }
public void CommandFailed_SendUpstream() { var root = Substitute.For <IRootContainer>(); var child = Substitute.For <IScopedContainer>(); var handler = new BlockingHandler <FakeCommand>(x => { throw new Exception(); }); root.CreateScope().Returns(child); child.Resolve <IHandleCommand <FakeCommand> >().Returns(handler); var context = Substitute.For <IDownstreamContext>(); var dispatcher = new IocDispatcher(root); var msg = new DispatchCommand(new FakeCommand()); dispatcher.HandleDownstream(context, msg); context.Received().SendUpstream(Arg.Any <CommandFailed>()); Assert.Equal(1, msg.Attempts); }
/// <summary> /// Re add a command which we've tried to invoke but failed. /// </summary> /// <param name="command">Command to add</param> public void Update(DispatchCommand command) { using (var session = _documentStore.OpenSession()) { var cmd = session.Load <StoredCommand>(command.Command.CommandId); if (cmd == null) { throw new InvalidOperationException("Failed to find command with id: " + command.Command.CommandId); } cmd.Command = command.Command; cmd.Attempts = command.Attempts; cmd.ProcessedAt = null; session.Store(command); session.SaveChanges(); } }
public void Dispatch() { var root = Substitute.For <IRootContainer>(); var child = Substitute.For <IScopedContainer>(); var handler = Substitute.For <IHandleCommand <FakeCommand> >(); root.CreateScope().Returns(child); child.Resolve <IHandleCommand <FakeCommand> >().Returns(handler); var context = Substitute.For <IDownstreamContext>(); var dispatcher = new IocDispatcher(root); var msg = new DispatchCommand(new FakeCommand()); dispatcher.HandleDownstream(context, msg); handler.Received().Invoke((FakeCommand)msg.Command); context.DidNotReceive().SendUpstream(Arg.Any <CommandFailed>()); }
public void should_clone_message_when_dispatching_locally_to_a_different_queue() { LoadAndStartDispatcher(); var handler = new SyncCommandHandlerWithQueueName1(); _containerMock.Setup(x => x.GetInstance(typeof(SyncCommandHandlerWithQueueName1))).Returns(handler); var command = new DispatchCommand(); Dispatch(command, true); Wait.Until(() => handler.HandleStopped, 5.Seconds()); handler.ReceivedMessage.ShouldNotBeNull(); handler.ReceivedMessage.ShouldNotBeTheSameAs(command); handler.ReceivedMessage.Guid.ShouldEqual(command.Guid); }
public void ShutDown_NoMoreDispatching() { var dispatcher = new AsyncHandler(2); var command = new FakeCommand(); var state = new DispatchCommand(command); var state2 = new DispatchCommand(new FakeCommand()); var context = new DownContext(null, null); // dispatch first and check that it's passed by properly dispatcher.HandleDownstream(context, state); Assert.True(context.WaitDown(TimeSpan.FromMilliseconds(50))); context.ResetDown(); dispatcher.Close(); dispatcher.HandleDownstream(context, state2); Assert.False(context.WaitDown(TimeSpan.FromMilliseconds(50))); }
public void OnlyOneWorker_TriggerThroughQueue() { var dispatcher = new AsyncHandler(1); var state1 = new DispatchCommand(new FakeCommand()); var state2 = new DispatchCommand(new FakeCommand()); var evt = new ManualResetEvent(false); var context = new DownContext(x => evt.WaitOne(), null); dispatcher.HandleDownstream(context, state1); Assert.True(context.WaitDown(TimeSpan.FromMilliseconds(50))); context.ResetDown(); dispatcher.HandleDownstream(context, state2); Assert.False(context.WaitDown(TimeSpan.FromMilliseconds(50))); evt.Set(); Assert.True(context.WaitDown(TimeSpan.FromMilliseconds(50))); }
public void ExceptionHandler() { var sync = new ManualResetEvent(false); var expected = new Exception("Work not made"); var dispatcher = new AsyncHandler(2); object msg = null; var context = new DownContext(y => { throw expected; }, x => { msg = x; sync.Set(); }); var state1 = new DispatchCommand(new FakeCommand()); dispatcher.HandleDownstream(context, state1); Assert.True(sync.WaitOne(TimeSpan.FromMilliseconds(100))); Assert.NotNull(msg); Assert.IsType <PipelineFailure>(msg); Assert.Same(expected, ((PipelineFailure)msg).Exception); }
public void should_hide_task_scheduler() { _messageDispatcher.LoadMessageHandlerInvokers(); var syncHandler = new CapturingTaskSchedulerSyncCommandHandler(); _containerMock.Setup(x => x.GetInstance(typeof(CapturingTaskSchedulerSyncCommandHandler))).Returns(syncHandler); var asyncHandler = new CapturingTaskSchedulerAsyncCommandHandler(); _containerMock.Setup(x => x.GetInstance(typeof(CapturingTaskSchedulerAsyncCommandHandler))).Returns(asyncHandler); var command = new DispatchCommand(); Dispatch(command, MessageContext.CreateTest("u.name").WithDispatchQueueName("some queue")); // make sure we go through a dispatch queue! syncHandler.Signal.WaitOne(1.Second()).ShouldBeTrue(); asyncHandler.Signal.WaitOne(1.Second()).ShouldBeTrue(); syncHandler.TaskScheduler.ShouldEqual(TaskScheduler.Default); asyncHandler.TaskScheduler.ShouldEqual(TaskScheduler.Default); }
public void should_hide_task_scheduler() { _messageDispatcher.LoadMessageHandlerInvokers(); var syncHandler = new CapturingTaskSchedulerSyncCommandHandler(); _containerMock.Setup(x => x.GetInstance(typeof(CapturingTaskSchedulerSyncCommandHandler))).Returns(syncHandler); var asyncHandler = new CapturingTaskSchedulerAsyncCommandHandler(); _containerMock.Setup(x => x.GetInstance(typeof(CapturingTaskSchedulerAsyncCommandHandler))).Returns(asyncHandler); var command = new DispatchCommand(); Dispatch(command); syncHandler.Signal.WaitOne(1.Second()).ShouldBeTrue(); asyncHandler.Signal.WaitOne(1.Second()).ShouldBeTrue(); syncHandler.TaskScheduler.ShouldEqual(TaskScheduler.Default); asyncHandler.TaskScheduler.ShouldEqual(TaskScheduler.Default); }
public void should_filter_invoker() { _messageDispatcher.LoadMessageHandlerInvokers(); var asyncHandler = new AsyncCommandHandler(); _containerMock.Setup(x => x.GetInstance(typeof(AsyncCommandHandler))).Returns(asyncHandler); var syncHandler = new SyncCommandHandler(); _containerMock.Setup(x => x.GetInstance(typeof(SyncCommandHandler))).Returns(syncHandler); var context = MessageContext.CreateTest("u.name"); var command = new DispatchCommand(); var dispatched = new ManualResetEvent(false); var dispatch = new MessageDispatch(context, command, (x, r) => dispatched.Set()); _messageDispatcher.Dispatch(dispatch, x => x == typeof(AsyncCommandHandler)); dispatched.WaitOne(500.Milliseconds()).ShouldBeTrue(); syncHandler.Called.ShouldBeFalse(); asyncHandler.CalledSignal.IsSet.ShouldBeTrue(); }
/// <summary> /// Re add a command which we've tried to invoke but failed. /// </summary> /// <param name="command">Command to add</param> public void Update(DispatchCommand command) { }
public IEnumerable<DispatchNotification> Execute(DispatchCommand command) { if (command == null) throw new ArgumentNullException(nameof(command)); if (command as TrackStretchCommand == null) return new List<DispatchNotification>(); _lastCommand = command.GetLastExecutedCommand(_lastCommand); return GetNotifications(); }
public FriendServerChangedDataModel(string accountName, string serverName) : base(SixIconFont.withSIX_icon_Cloud) { AccountName = accountName; ServerName = serverName; OnClickDispatch = new DispatchCommand<FriendServerChangedCommand>(new FriendServerChangedCommand()); }
internal override DispatchCommand GetLastExecutedCommand(DispatchCommand last) { if (last.Is<RequestTrackStretchCommand>()) return this; return last; }
internal override DispatchCommand GetLastExecutedCommand(DispatchCommand last) { if (last.Is< RequestTrackStretchCommand>() || last.Is< ConfirmTrackStretchCommand>()) return NullCommand; return last; }
internal override DispatchCommand GetLastExecutedCommand(DispatchCommand last) { return last; }
internal override DispatchCommand GetLastExecutedCommand(DispatchCommand last) { if (last.IsNull) return this; return last; }
/// <summary> /// Start the HTTP server and register us in mDNS / DNS-SD... /// </summary> /// <param name="a_dispatchcommand">our callback</param> /// <param name="a_szInstanceName">the instance name: xxx._twaindirect._sub._privet._tcp.local</param> /// <param name="a_iPort">socket port number (can be 0 to auto select)</param> /// <param name="a_szTy">the friendly name for the device, not forced to be unique</param> /// <param name="a_szUrl">url of cloud server or empty string</param> /// <param name="a_szNote">a helpful note about the device (optional)</param> /// <returns>true on success</returns> public bool ServerStart ( DispatchCommand a_dispatchcommand, string a_szInstanceName, int a_iPort, string a_szTy, string a_szUrl, string a_szNote ) { string szUri; // Make a note of our callback... m_dispatchcommand = a_dispatchcommand; // Create the listener... m_httplistener = new HttpListener(); // HTTPS support for mono, still have to sort out Windows // http://stackoverflow.com/questions/13379963/httplistener-with-https-on-monotouch // Find a port we can use... m_iPort = a_iPort; if (m_iPort == 0) { TcpListener tcplistener = new TcpListener(IPAddress.Any, 0); tcplistener.Start(); m_iPort = ((IPEndPoint)tcplistener.LocalEndpoint).Port; tcplistener.Stop(); } // Add our prefixes, we'll accept input from any address on this port // which is how the advertisement should work. We won't register // until the service is up. Note that our default is to require the // use of HTTPS... if (Config.Get("useHttps", "yes") == "yes") { szUri = @"https://+:" + m_iPort + "/privet/info/"; Log.Info("Monitoring: " + szUri); m_httplistener.Prefixes.Add(szUri); szUri = @"https://+:" + m_iPort + "/privet/infoex/"; Log.Info("Monitoring: " + szUri); m_httplistener.Prefixes.Add(szUri); szUri = @"https://+:" + m_iPort + "/privet/twaindirect/session/"; Log.Info("Monitoring: " + szUri); m_httplistener.Prefixes.Add(szUri); } else { szUri = @"http://+:" + m_iPort + "/privet/info/"; Log.Info("Monitoring: " + szUri); m_httplistener.Prefixes.Add(szUri); szUri = @"http://+:" + m_iPort + "/privet/infoex/"; Log.Info("Monitoring: " + szUri); m_httplistener.Prefixes.Add(szUri); szUri = @"http://+:" + m_iPort + "/privet/twaindirect/session/"; Log.Info("Monitoring: " + szUri); m_httplistener.Prefixes.Add(szUri); } // Start the service... try { m_httplistener.Start(); } catch (Exception exception) { Log.Error("ServerStart: Start failed..." + exception.Message); return(false); } // Handle stuff async... m_iasyncresult = m_httplistener.BeginGetContext(new AsyncCallback(ListenerCallback), m_httplistener); // Register our new device... m_dnssd = new Dnssd(Dnssd.Reason.Register); m_dnssd.RegisterStart(a_szInstanceName, m_iPort, a_szTy, a_szUrl, a_szNote); // All done... return(true); }