public ActionResult ResetTask(Guid idTask)
        {
            PreservationService  service = new PreservationService();
            PreservationTask     task    = service.GetPreservationTask(idTask);
            ArchiveConfiguration archiveConfiguration = JsonConvert.DeserializeObject <ArchiveConfiguration>(task.Archive.PreservationConfiguration);

            service.ResetPreservationTask(idTask, true, archiveConfiguration.ForceAutoInc);
            return(RedirectToAction("PreservationTaskDetails", new { id = idTask }));
        }
 public ActionResult ClosePreviousArchiveTasks(Guid idPreservationTask, int selectedTaskYear)
 {
     return(ActionResultHelper.TryCatchWithLogger(() =>
     {
         PreservationService service = new PreservationService();
         PreservationTask preservationTask = service.GetPreservationTask(idPreservationTask);
         service.CreateClosePreviousPreservationTask(preservationTask, selectedTaskYear);
         return RedirectToAction("ArchivePreservationTask", new { id = preservationTask.Archive.IdArchive });
     }, _loggerService));
 }
        public ActionResult DeletePreservationTask(Guid id, [DataSourceRequest] DataSourceRequest request)
        {
            var service = new PreservationService();
            //Guid idPreservationTask = Guid.Parse(id);
            Guid idPreservationTask = id;
            var  preservationTask   = service.GetPreservationTask(idPreservationTask);
            Guid idArchive          = preservationTask.Archive.IdArchive;

            if (preservationTask.ExecutedDate == null && preservationTask.IdPreservation == null)
            {
                service.DeletePreservationTask(preservationTask.IdPreservationTask);
            }
            return(RedirectToAction("ArchivePreservationTask", new { id = idArchive }));
        }
 public ActionResult ClosePreviousArchiveTasks(Guid idPreservationTask)
 {
     return(ActionResultHelper.TryCatchWithLogger(() =>
     {
         PreservationService service = new PreservationService();
         PreservationTask preservationTask = service.GetPreservationTask(idPreservationTask);
         int taskYear = preservationTask.StartDocumentDate.Value.Year;
         IList <int> years = new List <int>()
         {
             (taskYear - 1)
         };
         if (preservationTask.StartDocumentDate.Value != new DateTime(taskYear, 1, 1))
         {
             years.Add(taskYear);
         }
         ViewData["Years"] = years;
         TempData["IdPreservationTask"] = idPreservationTask;
         return PartialView("_ClosePreviousArchiveTasks");
     }, _loggerService));
 }
        public ActionResult ClosePreservationWithoutDocuments(Guid idPreservationTask)
        {
            var service = new PreservationService();
            PreservationTask preservationTask = service.GetPreservationTask(idPreservationTask);

            service.SavePreservationTaskStatus(preservationTask, Library.Common.Objects.Enums.PreservationTaskStatus.Done, false, null);
            if (preservationTask.CorrelatedTasks != null)
            {
                foreach (PreservationTask correlatedtask in preservationTask.CorrelatedTasks)
                {
                    service.SavePreservationTaskStatus(correlatedtask, Library.Common.Objects.Enums.PreservationTaskStatus.Done, false, null);
                }
            }

            if (preservationTask.IdPreservation.HasValue)
            {
                service.ClosePreservation(preservationTask.IdPreservation.Value);
            }
            return(RedirectToAction("Index", "Home"));
        }
Example #6
0
        public async Task ExecutePreservation(string idTask)
        {
            PreservationService preservationService = new PreservationService();
            PreservationTask    task = null;

            try
            {
                SendProgressMessage($"Inizio attività di conservazione per il task {idTask}, a breve verranno visualizzate le attività realtive allo stato di conservazione", ProgressMessageLevel.Info, Context.ConnectionId);
                SendProgressMessage($"L'attività potrebbe richiedere alcuni minuti, attendere prego...", ProgressMessageLevel.Info, Context.ConnectionId);
                if (!Guid.TryParse(idTask, out Guid taskId))
                {
                    throw new ArgumentException($"Il parametro passato non è nel formato corretto.", nameof(idTask));
                }

                task = preservationService.GetPreservationTask(taskId);
                if (string.IsNullOrEmpty(task.Archive.PreservationConfiguration))
                {
                    throw new Exception($"L'archivio {task.Archive.Name} non è stato configurato");
                }

                ArchiveConfiguration archiveConfiguration = JsonConvert.DeserializeObject <ArchiveConfiguration>(task.Archive.PreservationConfiguration);
                if (task.LockDate.HasValue)
                {
                    throw new Exception($"Il Task {taskId} è bloccato e non può essere processato");
                }


                if (task.IdPreservation.HasValue)
                {
                    throw new Exception($"Il Task {taskId} ha già una conservazione associata");
                }

                if (!preservationService.LockTask(task))
                {
                    throw new Exception($"Task is LOCK {task.IdPreservationTask}");
                }

                string correlationId = Context.ConnectionId;
                await StartHubConnection(correlationId);

                using (HttpClient client = new HttpClient())
                {
                    CommandExecutePreservation command = new CommandExecutePreservation();
                    command.ReferenceId          = correlationId;
                    command.IdTask               = taskId;
                    command.AutoGenerateNextTask = archiveConfiguration.AutoGeneratedNextTask;
                    command.PDVArchive           = ConfigurationHelper.PDVArchiveName;
                    command.RDVArchive           = ConfigurationHelper.RDVArchiveName;

                    await client.SendAsync(new HttpRequestMessage(HttpMethod.Post, $"{ConfigurationHelper.WCFHostWebAPIUrl}/api/CQRS")
                    {
                        Content = new ObjectContent <CommandExecutePreservation>(command, new JsonMediaTypeFormatter()
                        {
                            SerializerSettings = _serializerSettings
                        })
                    });
                }
            }
            catch (TaskCanceledException tex)
            {
                _logger.Warn("Il task ha impiegato molto tempo per l'esecuzione ed è stato annullato. L' attività di conservazione continuerà in background.", tex);
                SendProgressMessage("L'attività di conservazione stà impiegando più tempo del previsto. Si prega di attendere il completamento del processo.", ProgressMessageLevel.Warning, Context.ConnectionId);
            }
            catch (Exception ex)
            {
                _logger.Error("Error on create preservation", ex);
                if (task != null)
                {
                    preservationService.UnlockTask(task);
                }
                SendProgressMessage($"Errore nell'esecuzione dell'attività di conservazione: {ex.Message}", ProgressMessageLevel.Error, Context.ConnectionId);
            }
        }
Example #7
0
        public override async Task Execute(CommandModel commandModel)
        {
            PreservationTask preservationTask = null;

            try
            {
                _commandModel = commandModel;
                if (!(commandModel is CommandExecutePreservation))
                {
                    _logger.Error($"Command is not of type {nameof(CommandExecutePreservation)}");
                    await SendNotification(commandModel.ReferenceId, "E' avvenuto un errore durante la gestione del comando di esecuzione conservazione", NotifyLevel.Error, true);

                    return;
                }

                CommandExecutePreservation @command = commandModel as CommandExecutePreservation;
                if (command.IdTask == Guid.Empty)
                {
                    _logger.Error($"Command with idTask not defined");
                    await SendNotification(command.ReferenceId, "Non è stato definito un ID Task per l'esecuzione della conservazione", NotifyLevel.Error, true);

                    return;
                }

                preservationTask = _preservationService.GetPreservationTask(command.IdTask);
                if (preservationTask == null)
                {
                    _logger.Error($"Task {command.IdTask} not found");
                    await SendNotification(command.ReferenceId, $"Non è stato trovato un Task con id {command.IdTask}", NotifyLevel.Error, true);

                    return;
                }
                PreservationInfoResponse response = _preservationService.CreatePreservation(preservationTask);
                if (response.HasErros)
                {
                    await SendNotification(command.ReferenceId, $"Errore nell'attività di conservazione del task con id {command.IdTask}: {response.Error.Message}", NotifyLevel.Error, true);

                    return;
                }

                if (preservationTask.TaskType.Type == PreservationTaskTypes.Preservation && command.AutoGenerateNextTask)
                {
                    try
                    {
                        _preservationService.AutoGenerateNextTask(preservationTask);
                    }
                    catch (Exception ex)
                    {
                        _logger.Warn($"E' avvenuto un errore durante la generazione del task di conservazione successivo al task {command.IdTask}", ex);
                        await SendNotification(command.ReferenceId, $"Non è stato possibile generare il task di conservazione successivo al task {command.IdTask}", NotifyLevel.Warning);
                    }
                }

                if (response.AwardBatchesXml != null && response.AwardBatchesXml.Count > 0)
                {
                    foreach (KeyValuePair <Guid, string> awardBatchXml in response.AwardBatchesXml)
                    {
                        string serializedContent = Convert.ToBase64String(Encoding.UTF8.GetBytes(awardBatchXml.Value));
                        if (!string.IsNullOrEmpty(command.PDVArchive))
                        {
                            CommandInsertPreservationPDV pdvCommand = new CommandInsertPreservationPDV()
                            {
                                PDVArchive   = command.PDVArchive,
                                ReferenceId  = command.ReferenceId,
                                IdAwardBatch = awardBatchXml.Key,
                                Content      = serializedContent
                            };
                            await Mediator.Send(pdvCommand);
                        }

                        if (!string.IsNullOrEmpty(command.RDVArchive))
                        {
                            CommandInsertPreservationRDV rdvCommand = new CommandInsertPreservationRDV()
                            {
                                RDVArchive   = command.RDVArchive,
                                ReferenceId  = command.ReferenceId,
                                IdAwardBatch = awardBatchXml.Key,
                                Content      = serializedContent
                            };
                            await Mediator.Send(rdvCommand);
                        }
                    }
                }
                await SendNotification(command.ReferenceId, $"Processo di conservazione terminato", NotifyLevel.Info, true);
            }
            catch (Exception ex)
            {
                _logger.Error($"Error on execute preservation task", ex);
                await SendNotification(commandModel.ReferenceId, $"E' avvenuto un errore durante l'attività richiesta", NotifyLevel.Error, true);
            }
            finally
            {
                if (preservationTask != null)
                {
                    _preservationService.UnlockTask(preservationTask);
                }
            }
        }
Example #8
0
    public PreservationInfoResponse ExecutePreservationTask(Guid idTask)
    {
        try
        {
            logger.InfoFormat("ExecutePreservationTask - id task {0}", idTask);
            var svc = new PreservationService();
            //Check if idTask exists
            var taskToExecute = svc.GetPreservationTask(idTask);
            PreservationTask taskPreservation = null;
            if (taskToExecute == null)
            {
                throw new Exception("Nessun task trovato con l'id passato");
            }

            if (taskToExecute.TaskType.Type != PreservationTaskTypes.Verify) //Anche il tipo Unknown viene trattato come se fosse il task di conservazione.
            {
                taskPreservation = taskToExecute;
                if (taskToExecute.CorrelatedTasks != null)
                {
                    taskToExecute = taskToExecute
                                    .CorrelatedTasks
                                    .FirstOrDefault(x => x.TaskType != null && x.TaskType.Type == PreservationTaskTypes.Verify);

                    if (taskToExecute == null)
                    {
                        taskToExecute = taskPreservation;
                    }
                }
            }

            try
            {
                if (!taskToExecute.Enabled)
                {
                    throw new Exception("Il task di {0} non risulta abilitato.");
                }
                if (taskToExecute.HasError)
                {
                    throw new Exception("Il task di {0} è stato eseguito con errori.");
                }
                if (taskToExecute.Executed)
                {
                    throw new Exception("Il task di {0} non è stato ancora eseguito.");
                }

                if (taskPreservation != null)
                {
                    taskToExecute = taskPreservation;

                    if (!taskToExecute.Enabled)
                    {
                        throw new Exception("Il task di {0} non risulta abilitato.");
                    }
                    if (taskToExecute.HasError)
                    {
                        throw new Exception("Il task di {0} è stato eseguito con errori.");
                    }
                    if (!taskToExecute.Executed)
                    {
                        throw new Exception("Il task di {0} non è stato ancora eseguito.");
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format(ex.Message, taskToExecute.TaskType.Type == PreservationTaskTypes.Verify ? "verifica" : "conservazione"));
            }

            return(new BiblosDS.WCF.WCFServices.PreservationServiceInstances().ExecutePreservation(taskPreservation));
        }
        catch (Exception ex)
        {
            logger.Error(ex);
            if (ex is FaultException)
            {
                throw ex;
            }
            else
            {
                throw new FaultException <BiblosDsException>(new BiblosDsException(ex), new FaultReason(ex.Message));
            }
        }
        finally
        {
            logger.InfoFormat("ExecutePreservationTask END {0}", idTask);
        }
    }