예제 #1
0
        public async Task <Guid?> Handle(CreateNotificationPipelineCommand request, CancellationToken cancellationToken)
        {
            _logger.LogDebug("Handle started");

            var pipeline = NotificationPipeline.Create(
                NotificationPipelineName.FromString(request.Name),
                String.IsNullOrEmpty(request.Description) == true ? NotificationPipelineDescription.Empty : NotificationPipelineDescription.FromString(request.Description),
                request.TriggerName,
                _conditionFactory.Initilize(new NotificationConditionCreateModel
            {
                Typename            = request.CondtionName,
                PropertiesAndValues = request.ConditionProperties,
            }),
                _actorFactory.Initilize(new NotificationActorCreateModel
            {
                Typename            = request.ActorName,
                PropertiesAndValues = request.ActorProperties,
            }),
                _loggerFactory.CreateLogger <NotificationPipeline>(),
                _conditionFactory, _actorFactory
                );

            Boolean storeResult = await _engine.AddNotificationPipeline(pipeline);

            if (storeResult == false)
            {
                return(null);
            }

            return(pipeline.Id);
        }
예제 #2
0
        // Used by OnNotifyPausedAsync().
        protected async Task OnPausedAsync()
        {
            var notificationParticipants = GetExtensions <INotificationParticipant>();

            // If the notificationParticipants throw during OnPausedAsync, the pipeline will rethrow, and the controller/executor will abort.
            if (notificationParticipants.Any())
            {
                var notificationPipeline = new NotificationPipeline(notificationParticipants);
                await notificationPipeline.OnPausedAsync(this.Parameters.ExtensionsPersistenceTimeout);
            }
        }
예제 #3
0
        public async Task <Boolean> AddNotificationPipeline(NotificationPipeline pipeline)
        {
            Boolean result = await storageEngine.Save(pipeline);

            if (result == true)
            {
                _pipelines.Add(pipeline);
            }

            return(result);
        }
예제 #4
0
        public void Ceate()
        {
            Random random           = new Random();
            String name             = random.GetAlphanumericString();
            String description      = random.GetAlphanumericString();
            String triggerInputName = random.GetAlphanumericString();

            NotificationConditionCreateModel conditionCreateModel = new NotificationConditionCreateModel()
            {
                Typename = random.GetAlphanumericString()
            };

            NotificationActorCreateModel actorCreateModel = new NotificationActorCreateModel()
            {
                Typename = random.GetAlphanumericString()
            };

            DummyNotificationCondition condition = new DummyNotificationCondition {
                ToCreateModelResult = conditionCreateModel
            };
            DummyNotificationActor actor = new DummyNotificationActor {
                ToCreateModelResult = actorCreateModel
            };

            Mock <INotificationConditionFactory> conditionFactoryMock = new Mock <INotificationConditionFactory>(MockBehavior.Strict);

            conditionFactoryMock.Setup(x => x.Initilize(conditionCreateModel)).Returns(condition).Verifiable();

            Mock <INotificationActorFactory> actorFactoryMock = new Mock <INotificationActorFactory>(MockBehavior.Strict);

            actorFactoryMock.Setup(x => x.Initilize(actorCreateModel)).Returns(actor).Verifiable();

            var pipeline = NotificationPipeline.Create(
                NotificationPipelineName.FromString(name), NotificationPipelineDescription.FromString(description),
                triggerInputName, condition, actor, Mock.Of <ILogger <NotificationPipeline> >(),
                conditionFactoryMock.Object, actorFactoryMock.Object);

            Assert.Equal(name, pipeline.Name);
            Assert.Equal(description, pipeline.Description);
            Assert.Equal(triggerInputName, pipeline.TriggerIdentifier);
            Assert.Equal(condition, pipeline.Condition);
            Assert.Equal(actor, pipeline.Actor);

            var @event = GetFirstEvent <NotificationPipelineCreatedEvent>(pipeline);

            Assert.Equal(name, @event.Name);
            Assert.Equal(description, @event.Description);
            Assert.Equal(triggerInputName, @event.TriggerIdentifier);
            Assert.Equal(actorCreateModel, @event.ActorCreateInfo);
            Assert.Equal(conditionCreateModel, @event.ConditionCreateInfo);
        }
예제 #5
0
        public static NotificationPipeline CreatePipleline(Random random, string triggerIdentifier, NotificationCondition condition = null, NotificationActor actor = null)
        {
            NotificationActorCreateModel actorCreateModel = new NotificationActorCreateModel
            {
                Typename            = random.GetAlphanumericString(),
                PropertiesAndValues = new Dictionary <String, String>(),
            };

            NotificationConditionCreateModel conditionCreateModel = new NotificationConditionCreateModel
            {
                Typename            = random.GetAlphanumericString(),
                PropertiesAndValues = new Dictionary <String, String>(),
            };

            Mock <INotificationConditionFactory> conditionFactoryMock = new Mock <INotificationConditionFactory>(MockBehavior.Strict);

            conditionFactoryMock.Setup(x => x.Initilize(conditionCreateModel)).Returns(condition ?? DummyNotificationCondition.AllErrors).Verifiable();

            Mock <INotificationActorFactory> actorFactoryMock = new Mock <INotificationActorFactory>(MockBehavior.Strict);

            actorFactoryMock.Setup(x => x.Initilize(actorCreateModel)).Returns(actor ?? DummyNotificationActor.AllErrors).Verifiable();

            Guid id = random.NextGuid();

            var pipeline = new NotificationPipeline(id, conditionFactoryMock.Object,
                                                    actorFactoryMock.Object, Mock.Of <ILogger <NotificationPipeline> >());

            pipeline.Load(new[] { new NotificationPipelineCreatedEvent
                                  {
                                      Id                  = id,
                                      Description         = random.GetAlphanumericString(),
                                      Name                = random.GetAlphanumericString(),
                                      TriggerIdentifier   = triggerIdentifier,
                                      ActorCreateInfo     = actorCreateModel,
                                      ConditionCreateInfo = conditionCreateModel,
                                  } });

            return(pipeline);
        }
예제 #6
0
        public void Run()
        {
            var pump = new MockPump();
            var sut  = new NotificationPipeline(pump, loadContext, processNotification);

            var result = sut.Handle(new MyNotification {
                Prefix = ":"
            });

            Assert.IsType <NoResponse>(result.Msg);
            Assert.Empty(result.Notifications);

            Assert.Equal(2, pump.Commands.Count);
            Assert.Equal(":foo", (pump.Commands[0] as MyCommand).Parameter);
            Assert.Equal(":foo", (pump.Commands[1] as YourCommand).Parameter);


            (IMessageContextModel Ctx, string Version) loadContext(IMessage msg)
            {
                return(new MyNotificationCtx()
                {
                    Value = "foo"
                }, "");
            }

            Command[] processNotification(IMessage msg, IMessageContextModel ctx)
            {
                var prefix = (msg as MyNotification).Prefix;
                var value  = (ctx as MyNotificationCtx).Value;

                return(new[] { new MyCommand {
                                   Parameter = prefix + value
                               }, (Command) new YourCommand {
                                   Parameter = prefix + value
                               } });
            }
        }
 public NotificationPipelineTests()
 {
     channel1 = Substitute.For <IBufferedNotificationChannel>();
     channel2 = Substitute.For <IBufferedNotificationChannel>();
     sut      = new NotificationPipeline(pipelineId, new[] { channel1, channel2 });
 }
예제 #8
0
 public void Register <TMessage>(LoadContextModel load, ProcessNotification processNotification, UpdateContextModel update)
 {
     _broadcast.Subscribe(update);
     _pipelines[typeof(TMessage)] = new NotificationPipeline(this, load, processNotification);
 }
예제 #9
0
 /// <summary>
 /// Reset notification pipeline
 /// </summary>
 public void ReInstallNotificationPipeline()
 {
     NotificationPipeline = new NotificationPipeline();
 }