Esempio n. 1
0
        private async Task BuildCQRSInsertCommand(ICommandInsertUDSData command, UDSEntityModel udsModel)
        {
            IEventInsertUDSData evt = new EventInsertUDSData(command.CorrelationId, command.TenantName, command.TenantId, command.TenantAOOId, command.Identity,
                                                             command.ContentType.ContentTypeValue);

            if (udsModel.Relations != null && udsModel.Relations.PECMails != null && udsModel.Relations.PECMails.Any())
            {
            }
            evt.CorrelatedMessages.Add(command);
        }
Esempio n. 2
0
        public override async Task ExecuteAsync(ICommandInsertUDSData command)
        {
            _logger.WriteInfo(new LogMessage(string.Concat(command.CommandName, " is arrived")), LogCategories);

            Guid?  collaborationUniqueId;
            string collaborationTemplateName;
            int?   collaborationId;

            try
            {
                _logger.WriteInfo(new LogMessage(string.Concat(command.ContentType.Id, " model evaluating ... ")), LogCategories);
                UDSEntityModel udsEntityModel = await InsertDataAsync(command.ContentType.ContentTypeValue, command.Identity.User, command.CreationTime);

                command.ContentType.ContentTypeValue.UniqueId = udsEntityModel.IdUDS;
                ResetModelXML(command.ContentType.ContentTypeValue);

                collaborationId           = udsEntityModel.Relations.Collaborations.FirstOrDefault()?.IdCollaboration;
                collaborationUniqueId     = udsEntityModel.Relations.Collaborations.FirstOrDefault()?.CollaborationUniqueId;
                collaborationTemplateName = udsEntityModel.Relations.Collaborations.FirstOrDefault()?.CollaborationTemplateName;

                IEventInsertUDSData evt = new EventInsertUDSData(command.CorrelationId, command.TenantName, command.TenantId, command.TenantAOOId, command.Identity,
                                                                 command.ContentType.ContentTypeValue);
                evt.CorrelatedMessages.Add(command);
                if (!await PushEventAsync(evt))
                {
                    throw new Exception("EventInsertUDSData not sent");
                }

                UDSBuildModel    udsBuildModel    = MapUDSModel(command.ContentType.ContentTypeValue, udsEntityModel);
                CategoryFascicle categoryFascicle = await GetPeriodicCategoryFascicleByEnvironment(udsEntityModel.IdCategory.Value, command.ContentType.ContentTypeValue.UDSRepository.DSWEnvironment);

                if (categoryFascicle == null)
                {
                    categoryFascicle = await GetDefaultCategoryFascicle(udsEntityModel.IdCategory.Value);
                }
                ICommandCQRSCreateUDSData commandCQRS = new CommandCQRSCreateUDSData(command.TenantName, command.TenantId, command.TenantAOOId, command.Identity, udsBuildModel, categoryFascicle, null,
                                                                                     collaborationUniqueId, collaborationId, collaborationTemplateName);
                if (command.CorrelationId.HasValue)
                {
                    commandCQRS = new CommandCQRSCreateUDSData(command.CorrelationId.Value, command.TenantName, command.TenantId, command.TenantAOOId, command.Identity, udsBuildModel, categoryFascicle, null,
                                                               collaborationUniqueId, collaborationId, collaborationTemplateName);
                }
                if (udsBuildModel.WorkflowActions != null)
                {
                    foreach (IWorkflowAction workflowAction in udsBuildModel.WorkflowActions)
                    {
                        commandCQRS.WorkflowActions.Add(workflowAction);
                    }
                }
                if (!await PushCommandAsync(commandCQRS))
                {
                    throw new Exception("CommandCQRSCreateUDSData not sent");
                }
                #region [ EventCompleteUDSBuild ]
                IEventCompleteUDSBuild eventCompleteUDSBuild = new EventCompleteUDSBuild(Guid.NewGuid(), command.CorrelationId, command.TenantName, command.TenantId, command.TenantAOOId,
                                                                                         command.Identity, udsBuildModel, null);
                if (!await PushEventAsync(eventCompleteUDSBuild))
                {
                    _logger.WriteError(new LogMessage($"EventCompleteUDSBuild {udsBuildModel.UniqueId} has not been sended"), LogCategories);
                    throw new Exception("IEventCompleteUDSBuild not sended");
                }
                _logger.WriteInfo(new LogMessage($"EventCompleteUDSBuild {udsBuildModel.UniqueId} has been sended"), LogCategories);
                #endregion
            }
            catch (Exception ex)
            {
                ResetModelXML(command.ContentType.ContentTypeValue);
                IEventError evt = new EventError(command.CorrelationId, command.TenantName, command.TenantId, command.TenantAOOId, command.Identity,
                                                 new ContentTypeString($"Errore in fase di inserimento nell'archivio [{ex.Message}]"), null);
                evt.CorrelatedMessages.Add(command);
                if (!await PushEventAsync(evt))
                {
                    throw new Exception("EventError not sent");
                }
                throw ex;
            }

            _logger.WriteInfo(new LogMessage("message completed."), LogCategories);
        }