コード例 #1
0
 private async Task EvaluateWorkflowActionsAsync(TCommand command, IBaseCommonExecutor baseCommonExecutor, IEvent evt)
 {
     if (typeof(ICQRS).IsAssignableFrom(evt.GetType()) && command.WorkflowActions != null)
     {
         ICQRS cqrsEvt = evt as ICQRS;
         _logger.WriteDebug(new LogMessage($"Evaluate {command.WorkflowActions.Count} workflow actions"), LogCategories);
         foreach (IWorkflowAction workflowAction in command.WorkflowActions)
         {
             cqrsEvt.WorkflowActions.Add(workflowAction);
         }
         await baseCommonExecutor.CreateWorkflowActionsAsync(command, command.WorkflowActions);
     }
 }
コード例 #2
0
 protected override void AfterSave(Message entity)
 {
     try
     {
         _logger.WriteDebug(new LogMessage($"VecompSoftware.DocSuite.Private.WebAPI.Controllers.Entity.Messages.AfterSave with entity UniqueId {entity.UniqueId}"), LogCategories);
         Message message = _unitOfWork.Repository <Message>().Find(entity.EntityId);
         if (message != null)
         {
             IIdentityContext identity = new IdentityContext(_currentIdentity.FullUserName);
             ICQRS            command  = null;
             if (entity.Status == MessageStatus.Active)
             {
                 command = new CommandCreateMessage(_parameterEnvService.CurrentTenantName, _parameterEnvService.CurrentTenantId, Guid.Empty, identity, message);
             }
             if (command != null)
             {
                 foreach (IWorkflowAction workflowAction in WorkflowActions)
                 {
                     workflowAction.IdWorkflowActivity = IdWorkflowActivity;
                     command.WorkflowActions.Add(workflowAction);
                 }
                 ServiceBusMessage serviceBusMessage = _cqrsMapper.Map(command, new ServiceBusMessage());
                 if (serviceBusMessage == null || string.IsNullOrEmpty(serviceBusMessage.ChannelName))
                 {
                     throw new DSWException($"Queue name to command [{command}] is not mapped", null, DSWExceptionCode.SC_Mapper);
                 }
                 Task.Run(async() =>
                 {
                     await _queueService.SubscribeQueue(serviceBusMessage.ChannelName).SendToQueueAsync(serviceBusMessage);
                 }).Wait();
             }
         }
     }
     catch (DSWException ex)
     {
         _logger.WriteError(ex, LogCategories);
     }
     base.AfterSave(entity);
 }
コード例 #3
0
 public TestController(ICQRS cQRS)
 {
     this._cqrs = cQRS;
 }
コード例 #4
0
        protected override void AfterSave(Protocol entity)
        {
            try
            {
                _logger.WriteDebug(new LogMessage($"VecompSoftware.DocSuite.Private.WebAPI.Controllers.Entity.Protocols.AfterSave with entity UniqueId {entity.UniqueId}"), LogCategories);
                Protocol protocol = _unitOfWork.Repository <Protocol>().GetByUniqueIdWithRole(entity.UniqueId).FirstOrDefault();
                if (protocol != null)
                {
                    IList <CategoryFascicle> categoryFascicles = protocol.Category.CategoryFascicles.Where(f => f.DSWEnvironment == (int)DSWEnvironmentType.Protocol || f.DSWEnvironment == 0).ToList();
                    CategoryFascicle         categoryFascicle  = categoryFascicles.FirstOrDefault();
                    if (categoryFascicles != null && categoryFascicles.Count > 1)
                    {
                        categoryFascicle = categoryFascicles.FirstOrDefault(f => f.FascicleType == FascicleType.Period);
                    }
                    IIdentityContext identity = new IdentityContext(_currentIdentity.FullUserName);
                    ICQRS            command  = null;

                    if (CurrentUpdateActionType.HasValue && CurrentUpdateActionType == UpdateActionType.ActivateProtocol)
                    {
                        command = new CommandCreateProtocol(_parameterEnvService.CurrentTenantName, _parameterEnvService.CurrentTenantId, protocol.TenantAOO.UniqueId, null, null, null, identity, protocol, categoryFascicle, null);
                    }

                    if (CurrentDeleteActionType.HasValue && CurrentDeleteActionType == DeleteActionType.DeleteProtocol)
                    {
                        command = new CommandUpdateProtocol(_parameterEnvService.CurrentTenantName, _parameterEnvService.CurrentTenantId, protocol.TenantAOO.UniqueId, null, null, null, identity, protocol, categoryFascicle, null);
                    }

                    if (HttpContext.Current.Request.HttpMethod == HttpMethod.Put.Method &&
                        CurrentUpdateActionType.HasValue && CurrentUpdateActionType != UpdateActionType.ActivateProtocol)
                    {
                        command = new CommandUpdateProtocol(_parameterEnvService.CurrentTenantName, _parameterEnvService.CurrentTenantId, protocol.TenantAOO.UniqueId, null, null, null, identity, protocol, categoryFascicle, null);
                    }

                    if (command != null)
                    {
                        WorkflowActionDocumentUnitLinkModel workflowActionDocumentUnitLinkModel;
                        DocumentUnitModel documentUnitModel;
                        foreach (IWorkflowAction workflowAction in WorkflowActions)
                        {
                            workflowAction.IdWorkflowActivity = IdWorkflowActivity;
                            if (workflowAction is IWorkflowActionDocumentUnitLink)
                            {
                                workflowActionDocumentUnitLinkModel = (WorkflowActionDocumentUnitLinkModel)workflowAction;
                                documentUnitModel = workflowActionDocumentUnitLinkModel.GetReferenced();
                                if (documentUnitModel.UniqueId != protocol.UniqueId)
                                {
                                    documentUnitModel = workflowActionDocumentUnitLinkModel.GetDestinationLink();
                                }
                                documentUnitModel.Year   = protocol.Year;
                                documentUnitModel.Number = protocol.Number.ToString();
                            }
                            command.WorkflowActions.Add(workflowAction);
                        }
                        ServiceBusMessage message = _cqrsMapper.Map(command, new ServiceBusMessage());
                        if (message == null || string.IsNullOrEmpty(message.ChannelName))
                        {
                            throw new DSWException($"Queue name to command [{command}] is not mapped", null, DSWExceptionCode.SC_Mapper);
                        }
                        Task.Run(async() =>
                        {
                            await _queueService.SubscribeQueue(message.ChannelName).SendToQueueAsync(message);
                        }).Wait();
                    }
                }
            }
            catch (DSWException ex)
            {
                _logger.WriteError(ex, LogCategories);
            }
            base.AfterSave(entity);
        }