public async Task Handle(EntityCreated <ScenarioEntity> notification, CancellationToken cancellationToken)
 {
     if (notification.Entity.UpdateScores)
     {
         await _scoringService.UpdateScenarioScores(notification.Entity.Id, cancellationToken);
     }
 }
Exemple #2
0
        public virtual async Task HandleMessage(EntityCreated <T> message)
        {
            _repository.Add(message.Value);
            await _repository.UnitOfWork.SaveChangesAsync().ConfigureAwait(false);

            _logger.LogDebug($"IntegrationEvent: Entity {typeof(T).Name} Created");
        }
Exemple #3
0
 public async Task Handle(EntityCreated <ScenarioTemplateEntity> notification, CancellationToken cancellationToken)
 {
     var scenarioTemplate = _mapper.Map <ViewModels.ScenarioTemplate>(notification.Entity);
     await _engineHub.Clients
     .Groups(
         EngineGroups.GetSystemGroup(notification.Entity.Id),
         EngineGroups.SystemGroup)
     .SendAsync(EngineMethods.ScenarioTemplateCreated, scenarioTemplate);
 }
Exemple #4
0
        public async Task <EntityCreated> Handle(CreateEntity command)
        {
            await HandleCommandFor(command.EntityId);

            Verify.EntityNameIsUnique(command.Name);
            var events = new EntityCreated(command.EntityId, command.Name);

            return(events);
        }
Exemple #5
0
        public async Task Handle(EntityCreated <ViewEntity> notification, CancellationToken ct)
        {
            IWebhookEventPayload payload = new ViewModels.Webhooks.ViewCreated()
            {
                ViewId   = notification.Entity.Id,
                ParentId = notification.Entity.ParentViewId
            };

            await _backgroundService.AddEvent(new WebhookEvent(EventType.ViewCreated, payload));
        }
Exemple #6
0
            public Task HandleMessage(EntityCreated <Invoice> message)
            {
                Console.WriteLine("Invoice Created");

                lock (Events)
                {
                    Events.Add(message);
                }

                return(Task.CompletedTask);
            }
Exemple #7
0
        public async Task Handle(EntityCreated <Domain.Models.VmTeam> notification, CancellationToken cancellationToken)
        {
            var tasks = new List <Task>();

            if (notification.Entity.Vm == null)
            {
                if (_db.Entry(notification.Entity).State == EntityState.Detached)
                {
                    _db.Attach(notification.Entity);
                }

                notification.Entity.Vm = await _db.Vms
                                         .Where(x => x.Id == notification.Entity.VmId)
                                         .Include(x => x.VmTeams)
                                         .FirstOrDefaultAsync();
            }

            if (notification.Entity.Vm == null)
            {
                return;
            }

            var vm     = _mapper.Map <Vm>(notification.Entity.Vm);
            var viewId = await _viewService.GetViewIdForTeam(notification.Entity.TeamId, cancellationToken);

            if (viewId.HasValue)
            {
                foreach (var teamId in notification.Entity.Vm.VmTeams.Select(x => x.TeamId))
                {
                    if (teamId != notification.Entity.TeamId)
                    {
                        var vId = await _viewService.GetViewIdForTeam(teamId, cancellationToken);

                        // if this vm was already on a team in the same view, don't notify that view again
                        if (vId.HasValue && vId.Value == viewId.Value)
                        {
                            viewId = null;
                            break;
                        }
                    }
                }

                if (viewId.HasValue)
                {
                    tasks.Add(_vmHub.Clients.Group(viewId.ToString()).SendAsync(VmHubMethods.VmCreated, vm, cancellationToken));
                }
            }

            tasks.Add(_vmHub.Clients.Group(notification.Entity.TeamId.ToString()).SendAsync(VmHubMethods.VmCreated, vm, cancellationToken));
            await Task.WhenAll(tasks);
        }
Exemple #8
0
        public async Task Handle(EntityCreated <ScenarioEntity> notification, CancellationToken cancellationToken)
        {
            var scenarioSummary = _mapper.Map <ViewModels.Scenario>(
                _mapper.Map <ViewModels.ScenarioSummary>(notification.Entity));
            await _engineHub.Clients.Group(notification.Entity.Id.ToString())
            .SendAsync(EngineMethods.ScenarioCreated, scenarioSummary);

            var scenario = _mapper.Map <ViewModels.Scenario>(notification.Entity);
            await _engineHub.Clients
            .Groups(
                EngineGroups.GetSystemGroup(notification.Entity.Id),
                EngineGroups.SystemGroup)
            .SendAsync(EngineMethods.ScenarioCreated, scenario);
        }
        public Entity CreateEntity(string name)
        {
            var entity = new Entity(this, _nextEntityId, name);

            _entities.Add(entity);

            if (name != null)
            {
                _entitiesByName.Add(name, entity);
            }

            EntityCreated?.Invoke(this, entity);
            _nextEntityId++;
            return(entity);
        }
Exemple #10
0
        public virtual async Task HandleMessage(EntityUpdated <T> message)
        {
            _repository.Update(message.NewValue);
            try
            {
                await _repository.UnitOfWork.SaveChangesAsync().ConfigureAwait(false);

                _logger.LogDebug($"IntegrationEvent: Entity {typeof(T).Name} Updated");
            }
            catch (EntityNotFoundException)
            {
                _repository.Remove(message.NewValue);

                EntityCreated <T> created = new EntityCreated <T>(message.NewValue);
                await HandleMessage(created);
            }
        }
Exemple #11
0
        public async Task Handle(EntityCreated <TaskEntity> notification, CancellationToken cancellationToken)
        {
            var task = _mapper.Map <ViewModels.Task>(notification.Entity);

            if (notification.Entity.ScenarioTemplateId.HasValue)
            {
                await _engineHub.Clients.Group(EngineGroups.SystemGroup).SendAsync(EngineMethods.TaskCreated, task);
            }
            else if (notification.Entity.ScenarioId.HasValue)
            {
                var taskSummary = _mapper.Map <ViewModels.Task>(
                    _mapper.Map <ViewModels.TaskSummary>(notification.Entity));

                await _engineHub.Clients
                .Groups(
                    EngineGroups.GetSystemGroup(notification.Entity.ScenarioId.Value),
                    EngineGroups.SystemGroup)
                .SendAsync(EngineMethods.TaskCreated, task);

                await _engineHub.Clients
                .Group(notification.Entity.Id.ToString())
                .SendAsync(EngineMethods.TaskCreated, taskSummary);
            }
        }
Exemple #12
0
 public void Apply(EntityCreated e)
 {
 }
Exemple #13
0
 public void Apply(EntityCreated @event)
 {
     Projection.Entities.Add(@event.Id, new Entity(@event.Id, @event.Name));
 }
Exemple #14
0
 private void OnEntityCreated(Entity entity)
 {
     entity.Manager = this;
     EntityCreated?.Invoke(entity);
 }
 public async Task Handle(EntityCreated <Domain.Models.Vm> notification, CancellationToken cancellationToken)
 {
     await base.HandleCreateOrUpdate(notification.Entity, VmHubMethods.VmCreated, null, cancellationToken);
 }
Exemple #16
0
 public void EntityAdd(Entity e)
 {
     EntityCreated?.Invoke(e);
 }
Exemple #17
0
 internal void OnEntityCreated(object sender, T entity)
 {
     EntityCreated?.Invoke(sender, new EntityChangedEventArgs <T>(entity));
 }
 protected void OnCreate()
 {
     EntityCreated?.Invoke(this);
     AllEntities.Add(this);
 }
Exemple #19
0
 public void When(EntityCreated e)
 {
     EntityId   = e.EntityId;
     EntityName = e.EntityName;
 }
Exemple #20
0
 public Task HandleMessage(EntityCreated <Order> message)
 {
     _options.OnCreated?.Invoke(this, message);
     return(Task.CompletedTask);
 }
 public async Task Handle(EntityCreated <EventEntity> notification, CancellationToken ct)
 {
     await base.HandleCreateOrUpdate(notification.Entity, EventHubMethods.EventCreated, null, ct);
 }