Beispiel #1
0
        public async Task ExecuteAsync(ICommandUpdateDossierData command)
        {
            _logger.WriteInfo(new LogMessage($"{command.CommandName} is arrived"), LogCategories);

            Dossier dossier = command.ContentType.ContentTypeValue;

            try
            {
                if (RetryPolicyEvaluation != null && !string.IsNullOrEmpty(RetryPolicyEvaluation.ReferenceModel))
                {
                    _logger.WriteDebug(new LogMessage("Load reference model from RetryPolicyEvaluation"), LogCategories);
                    dossier = JsonConvert.DeserializeObject <Dossier>(RetryPolicyEvaluation.ReferenceModel, _serializerSettings);
                }
                else
                {
                    _logger.WriteDebug(new LogMessage("Generate new RetryPolicyEvaluation model"), LogCategories);
                    RetryPolicyEvaluation = new EvaluationModel();
                }

                if (!RetryPolicyEvaluation.Steps.Any(f => f.Name == STEP_UPDATE_DOSSIER))
                {
                    Dossier updatedDossier = await UpdateDossierEntity(dossier);

                    _logger.WriteInfo(new LogMessage($"Dossier {updatedDossier.GetTitle()} has been updated"), LogCategories);
                    RetryPolicyEvaluation.Steps.Add(new StepModel()
                    {
                        Name           = STEP_UPDATE_DOSSIER,
                        LocalReference = JsonConvert.SerializeObject(updatedDossier, _serializerSettings)
                    });
                }
                else
                {
                    StepModel messageStatus = RetryPolicyEvaluation.Steps.First(f => f.Name == STEP_UPDATE_DOSSIER);
                    dossier = JsonConvert.DeserializeObject <Dossier>(messageStatus.LocalReference);
                }
            }
            catch (Exception ex)
            {
                RetryPolicyEvaluation.ReferenceModel = JsonConvert.SerializeObject(dossier, _serializerSettings);
                _logger.WriteError(ex, LogCategories);
                throw new ServiceBusEvaluationException(RetryPolicyEvaluation);
            }
        }
Beispiel #2
0
        public async Task ExecuteAsync(ICommandBuildDossier command)
        {
            Dossier           dossier           = new Dossier();
            DossierBuildModel dossierBuildModel = command.ContentType.ContentTypeValue;
            DossierModel      dossierModel      = dossierBuildModel.Dossier;

            IdWorkflowActivity = dossierBuildModel.IdWorkflowActivity;

            try
            {
                if (RetryPolicyEvaluation != null && !string.IsNullOrEmpty(RetryPolicyEvaluation.ReferenceModel))
                {
                    dossierModel = JsonConvert.DeserializeObject <DossierModel>(RetryPolicyEvaluation.ReferenceModel, _serializerSettings);
                }
                else
                {
                    RetryPolicyEvaluation = new EvaluationModel();
                }

                #region [ STEP PREPARE ENTITY ]
                if (!RetryPolicyEvaluation.Steps.Any(d => d.Name == STEP_PREPARE_ENTITY))
                {
                    ProcessPrepareEntityStepEvaluation(dossier, dossierModel);

                    RetryPolicyEvaluation.Steps.Add(new StepModel()
                    {
                        Name           = STEP_PREPARE_ENTITY,
                        LocalReference = JsonConvert.SerializeObject(dossier, _serializerSettings)
                    });
                }
                else
                {
                    StepModel messageStatus = RetryPolicyEvaluation.Steps.First(f => f.Name == STEP_PREPARE_ENTITY);
                    dossier = JsonConvert.DeserializeObject <Dossier>(messageStatus.LocalReference);
                }
                #endregion

                #region [ STEP CREATE ENTITY ]
                if (!RetryPolicyEvaluation.Steps.Any(f => f.Name == STEP_CREATE_ENTITY))
                {
                    dossier.WorkflowName         = dossierBuildModel.WorkflowName;
                    dossier.IdWorkflowActivity   = dossierBuildModel.IdWorkflowActivity;
                    dossier.WorkflowAutoComplete = dossierBuildModel.WorkflowAutoComplete;
                    dossier.WorkflowActions      = dossierBuildModel.WorkflowActions;

                    _logger.WriteDebug(new LogMessage(JsonConvert.SerializeObject(dossier, _serializerSettings)), LogCategories);
                    dossier = await _webApiClient.PostEntityAsync(dossier);

                    _logger.WriteInfo(new LogMessage($"Dossier {dossier.Year}/{dossier.Number:0000000} ({dossier.UniqueId}) has been created"), LogCategories);

                    RetryPolicyEvaluation.Steps.Add(new StepModel()
                    {
                        Name           = STEP_CREATE_ENTITY,
                        LocalReference = JsonConvert.SerializeObject(dossier, _serializerSettings)
                    });
                }
                else
                {
                    StepModel messageStatus = RetryPolicyEvaluation.Steps.First(f => f.Name == STEP_CREATE_ENTITY);
                    dossier = JsonConvert.DeserializeObject <Dossier>(messageStatus.LocalReference);
                }
                #endregion

                #region [ STEP ADD DOSSIER DOCUMENTS ]
                if (!RetryPolicyEvaluation.Steps.Any(f => f.Name == STEP_ADD_DOCUMENTS))
                {
                    if (dossierModel.Documents != null && dossierModel.Documents.Any())
                    {
                        dossier.DossierDocuments = dossierModel.Documents.Select(docModel => new DossierDocument
                        {
                            IdArchiveChain = docModel.IdArchiveChain
                        }).ToList();
                    }
                }
                else
                {
                    StepModel messageStatus = RetryPolicyEvaluation.Steps.First(f => f.Name == STEP_ADD_DOCUMENTS);
                    dossier = JsonConvert.DeserializeObject <Dossier>(messageStatus.LocalReference);
                }
                #endregion

                #region [ STEP UPDATE DOSSIER ]
                if (!RetryPolicyEvaluation.Steps.Any(f => f.Name == STEP_UPDATE_DOSSIER))
                {
                    dossier = await _webApiClient.PutEntityAsync(dossier);

                    RetryPolicyEvaluation.Steps.Add(new StepModel()
                    {
                        Name           = STEP_UPDATE_DOSSIER,
                        LocalReference = JsonConvert.SerializeObject(dossier, _serializerSettings)
                    });
                }
                else
                {
                    StepModel messageStatus = RetryPolicyEvaluation.Steps.First(f => f.Name == STEP_UPDATE_DOSSIER);
                    dossier = JsonConvert.DeserializeObject <Dossier>(messageStatus.LocalReference);
                }
                #endregion

                #region [ STEP COMPLETE DOSSIER BUILD]
                dossierModel.Year             = dossier.Year;
                dossierModel.Number           = dossier.Number;
                dossierModel.Title            = $"Dossier {dossier.Year}/{dossier.Number:0000000}";
                dossierModel.RegistrationDate = dossier.RegistrationDate;
                dossierModel.RegistrationUser = dossier.RegistrationUser;
                dossierModel.LastChangedDate  = dossier.LastChangedDate;
                dossierModel.LastChangedUser  = dossier.LastChangedUser;
                dossierModel.StartDate        = dossier.StartDate;
                dossierModel.Subject          = dossier.Subject;
                dossierModel.DossierType      = (DossierTypeModel)dossier.DossierType;

                dossierBuildModel.Dossier = dossierModel;
                IEventCompleteDossierBuild eventCompleteDossierBuild = new EventCompleteDossierBuild(Guid.NewGuid(), command.CorrelationId ?? dossierBuildModel.UniqueId,
                                                                                                     command.TenantName, command.TenantId, command.TenantAOOId, command.Identity, dossierBuildModel, null);

                if (!await _webApiClient.PushEventAsync(eventCompleteDossierBuild))
                {
                    _logger.WriteError(new LogMessage($"EventCompleteDossierBuild {dossier.GetTitle()} has not been sent"), LogCategories);
                    throw new Exception("IEventCompleteDossierBuild not sent");
                }
                _logger.WriteInfo(new LogMessage($"EventCompleteDossierBuild {eventCompleteDossierBuild.Id} has been sent"), LogCategories);
                #endregion
            }
            catch (Exception ex)
            {
                RetryPolicyEvaluation.ReferenceModel = JsonConvert.SerializeObject(dossierModel, _serializerSettings);

                _logger.WriteError(ex, LogCategories);
                throw new ServiceBusEvaluationException(RetryPolicyEvaluation);
            }
        }