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); }
// 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); } }
public async Task <Boolean> AddNotificationPipeline(NotificationPipeline pipeline) { Boolean result = await storageEngine.Save(pipeline); if (result == true) { _pipelines.Add(pipeline); } return(result); }
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); }
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); }
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 }); }
public void Register <TMessage>(LoadContextModel load, ProcessNotification processNotification, UpdateContextModel update) { _broadcast.Subscribe(update); _pipelines[typeof(TMessage)] = new NotificationPipeline(this, load, processNotification); }
/// <summary> /// Reset notification pipeline /// </summary> public void ReInstallNotificationPipeline() { NotificationPipeline = new NotificationPipeline(); }