Beispiel #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);
     }
 }
Beispiel #2
0
        private async Task <Tuple <DocumentUnit, DocumentUnit> > EvaluateMappingDocumentUnitAsync(TCommand command, IBaseCommonExecutor baseCommonExecutor, IContentBase entity, bool isCommandUpdate)
        {
            DocumentUnit documentUnit      = null;
            DocumentUnit existDocumentUnit = null;

            if (typeof(IDocumentUnitEntity).IsAssignableFrom(baseCommonExecutor.GetType()))
            {
                documentUnit = await baseCommonExecutor.Mapping(entity, command.Identity, isCommandUpdate);

                documentUnit.TenantAOO = new TenantAOO()
                {
                    UniqueId = command.TenantAOOId
                };
                existDocumentUnit = await _webApiClient.GetDocumentUnitAsync(documentUnit);

                bool skipSendDocument = existDocumentUnit != null &&
                                        existDocumentUnit.UniqueId == documentUnit.UniqueId && existDocumentUnit.Year == documentUnit.Year && existDocumentUnit.Number == documentUnit.Number &&
                                        existDocumentUnit.Subject == existDocumentUnit.Subject && existDocumentUnit.Environment == documentUnit.Environment;
                if ((!isCommandUpdate && !skipSendDocument) || isCommandUpdate)
                {
                    await baseCommonExecutor.SendDocumentAsync(documentUnit, isCommandUpdate);

                    _logger.WriteDebug(new LogMessage($"DocumentUnit - {entity.GetType()} - {entity.UniqueId} has been successfully created."), LogCategories);
                }
                else
                {
                    _logger.WriteWarning(new LogMessage($"DocumentUnit - {entity.GetType()} - {entity.UniqueId} already exists and CQRS structures has been skipped."), LogCategories);
                }
            }

            return(new Tuple <DocumentUnit, DocumentUnit>(documentUnit, existDocumentUnit));
        }
Beispiel #3
0
        private async Task EvaluateAuthorizationEventsAsync(IBaseCommonExecutor executor, TCommand command, IContentBase entity,
                                                            Tuple <DocumentUnit, DocumentUnit> evaluatedMapping)
        {
            DocumentUnit documentUnitBeforeSave = evaluatedMapping.Item2;
            DocumentUnit documentUnit           = evaluatedMapping.Item1;

            if (documentUnit == null)
            {
                return;
            }

            List <DocumentUnitRole>       rolesAdded   = new List <DocumentUnitRole>();
            List <DocumentUnitRole>       rolesDeleted = new List <DocumentUnitRole>();
            List <DocumentUnitUser>       usersAdded   = new List <DocumentUnitUser>();
            List <DocumentUnitUser>       usersRemoved = new List <DocumentUnitUser>();
            IEventCreateRoleAuthorization createRoleUserAuthorization;
            IEventCreateUserAuthorization createUserAuthorization;
            IEventDeleteRoleAuthorization deleteRoleUserAuthorization;
            IEventDeleteUserAuthorization deleteUserAuthorization;

            if (documentUnitBeforeSave == null)
            {
                rolesAdded.AddRange(documentUnit.DocumentUnitRoles);
                usersAdded.AddRange(documentUnit.DocumentUnitUsers);
            }
            else
            {
                rolesAdded.AddRange(documentUnit.DocumentUnitRoles.Where(p => !documentUnitBeforeSave.DocumentUnitRoles.Any(l => p.UniqueId == l.UniqueId)));
                rolesDeleted.AddRange(documentUnitBeforeSave.DocumentUnitRoles.Where(p => !documentUnit.DocumentUnitRoles.Any(l => p.UniqueId == l.UniqueId)));
                usersAdded.AddRange(documentUnit.DocumentUnitUsers.Where(d => !documentUnitBeforeSave.DocumentUnitUsers.Any(l => d.UniqueId == l.UniqueId)));
                usersRemoved.AddRange(documentUnitBeforeSave.DocumentUnitUsers.Where(d => !documentUnit.DocumentUnitUsers.Any(l => d.UniqueId == l.UniqueId)));
            }

            _logger.WriteDebug(new LogMessage($"Evaluate {rolesAdded.Count} roles added"), LogCategories);
            foreach (DocumentUnitRole role in rolesAdded)
            {
                createRoleUserAuthorization = new EventCreateRoleAuthorization(Guid.NewGuid(), entity.UniqueId, command.TenantName, command.TenantId, command.TenantAOOId, command.Identity, documentUnit, role.UniqueIdRole, null);
                if (!await executor.PushEventAsync(createRoleUserAuthorization))
                {
                    _logger.WriteError(new LogMessage("PushEventAsync Error in sending event to WebAPI"), LogCategories);
                }
            }

            _logger.WriteDebug(new LogMessage($"Evaluate {rolesDeleted.Count} roles deleted"), LogCategories);
            foreach (DocumentUnitRole role in rolesDeleted)
            {
                deleteRoleUserAuthorization = new EventDeleteRoleAuthorization(Guid.NewGuid(), entity.UniqueId, command.TenantName, command.TenantId, command.TenantAOOId, command.Identity, documentUnitBeforeSave, role.UniqueIdRole, null);
                if (!await executor.PushEventAsync(deleteRoleUserAuthorization))
                {
                    _logger.WriteError(new LogMessage("PushEventAsync Error in sending event to WebAPI"), LogCategories);
                }
            }

            _logger.WriteDebug(new LogMessage($"Evaluate {usersAdded.Count} user added"), LogCategories);
            foreach (DocumentUnitUser user in usersAdded)
            {
                createUserAuthorization = new EventCreateUserAuthorization(Guid.NewGuid(), entity.UniqueId, command.TenantName, command.TenantId, command.TenantAOOId, command.Identity, documentUnit, user.Account, null);
                if (!await executor.PushEventAsync(createUserAuthorization))
                {
                    _logger.WriteError(new LogMessage("PushEventAsync Error in sending event to WebAPI"), LogCategories);
                }
            }

            _logger.WriteDebug(new LogMessage($"Evaluate {usersRemoved.Count} user deleted"), LogCategories);
            foreach (DocumentUnitUser user in usersRemoved)
            {
                deleteUserAuthorization = new EventDeleteUserAuthorization(Guid.NewGuid(), entity.UniqueId, command.TenantName, command.TenantId, command.TenantAOOId, command.Identity, documentUnitBeforeSave, user.Account, null);
                if (!await executor.PushEventAsync(deleteUserAuthorization))
                {
                    _logger.WriteError(new LogMessage("PushEventAsync Error in sending event to WebAPI"), LogCategories);
                }
            }
        }