예제 #1
0
 public void DependencyOnICommandSenderTest()
 {
     using (var container = new WindsorContainer())
     {
         var messagingEngine = new Mock <IMessagingEngine>().Object;
         var bootstrapper    = container
                               .Register(Component.For <ILogFactory>().Instance(_logFactory))
                               .Register(Component.For <IMessagingEngine>().Instance(messagingEngine))
                               .AddFacility <CqrsFacility>(f => f.RunInMemory().Contexts(
                                                               Register.BoundedContext("bc").ListeningCommands(typeof(string)).On("cmd").WithLoopback(),
                                                               Register.DefaultRouting.PublishingCommands(typeof(string)).To("bc").With("cmd"))
                                                           )
                               .Register(Component.For <CommandSenderDependentComponent>())
                               .Register(Component.For <CommandsHandler>().AsCommandsHandler("bc"))
                               .Resolve <ICqrsEngineBootstrapper>();
         HandlerException exception = null;
         try
         {
             container.Resolve <CommandSenderDependentComponent>();
         }
         catch (HandlerException e)
         {
             exception = e;
         }
         Assert.That(exception, Is.Not.Null, "Component with ICommandSender dependency is resolvable before cqrs engine is bootstrapped");
         Assert.That(exception.Message.Contains("Service 'Lykke.Cqrs.ICommandSender' which was not registered"), Is.True, "Component with ICommandSender dependency is resolvable before cqrs engine is bootstrapped");
         bootstrapper.Start();
         var component = container.Resolve <CommandSenderDependentComponent>();
         component.CommandSender.SendCommand("test", "bc");
         var commandsHandler = container.Resolve <CommandsHandler>();
         Thread.Sleep(200);
         Assert.That(commandsHandler.HandledCommands.Select(o => o.ToString()).ToArray, Is.EqualTo(new[] { "test" }), "Command was not dispatched");
     }
 }
예제 #2
0
        private void NotifyListeners(Event evt, Func <string, IList <Listener> > listenersFn)
        {
            evt.CurrentTarget = _target;
            lock (_getLockObject())
            {
                var listeners = listenersFn(evt.Type);
                // ReSharper disable once ForCanBeConvertedToForeach, to avoid 'collection was modified' exception
                for (var i = 0; i < listeners.Count; i++)
                {
                    var listener = listeners[i];
                    if (listener.Options != null && listener.Options.Passive)
                    {
                        evt.PreventDefaultDeprecated = true;
                    }

                    try
                    {
                        listener.Handler(evt);
                    }
                    catch (Exception e)
                    {
                        HandlerException?.Invoke(e);
                    }
                    finally
                    {
                        evt.PreventDefaultDeprecated = false;
                    }

                    if (listener.Options != null && listener.Options.Once)
                    {
                        RemoveEventListener(evt.Type, listener.Handler, listener.Options);
                    }
                }
            }
        }
예제 #3
0
 // Controller use for error documentattions (such as action 1, 2, 3.........)
 protected void SetAction(int currentActionIndex)
 {
     if (_currentProcessInstance != null)
     {
         string errCode = _currentProcessInstance.ProcessID + _currentProcessErrorNum.ToString("0000") + "-" +
                          _controllerID + currentActionIndex.ToString("000000");
         string proMes = _currentProcessInstance.ProcessErrorList[_currentProcessErrorNum];
         string ctrMes = _controllerErrorList[currentActionIndex];
         string errMes = HandlerException.GetHandlerErrorMessage(
             errCode, proMes, ctrMes);
         string errorCodeDetail = errCode + "-000";
     }
 }
예제 #4
0
	public static int Main(String [] args) {
		String s = "Done";
		int retVal = 100;
		Thread mv_Thread;
		HandlerException [] he = new HandlerException[10];
		for (int i = 0 ; i < 10; i++){
			he[i] = new HandlerException(i);
			mv_Thread = new Thread(new ThreadStart(he[i].runtest));
			try {
				mv_Thread.Start();
			}
			catch (Exception ){
				Console.WriteLine("Exception was caught in main");
				retVal = 0;
			}
		}
		Console.WriteLine(s);
		return retVal;
	}
예제 #5
0
    public static int Main(String [] args)
    {
        String s      = "Done";
        int    retVal = 100;
        Thread mv_Thread;

        HandlerException [] he = new HandlerException[10];
        for (int i = 0; i < 10; i++)
        {
            he[i]     = new HandlerException(i);
            mv_Thread = new Thread(new ThreadStart(he[i].runtest));
            try {
                mv_Thread.Start();
            }
            catch (Exception) {
                Console.WriteLine("Exception was caught in main");
                retVal = 0;
            }
        }
        Console.WriteLine(s);
        return(retVal);
    }
예제 #6
0
 public void OnHandlerException(object sender, HandlerExceptionEventArgs args)
 {
     HandlerException.Invoke(sender, args);
 }