public bool saveArchiveConfiguration(ArchiveConfiguration config) { if (config == null) { return(true); } try { JavaScriptSerializer serializer = new JavaScriptSerializer(); var request = new RestRequest(ResourcePath + "/archive/configuration/save", Method.POST); request.RequestFormat = DataFormat.Json; serializer.MaxJsonLength = int.MaxValue; string json = serializer.Serialize(config); request.AddParameter("application/json", json, ParameterType.RequestBody); var response = RestClient.ExecuteTaskAsync(request); RestResponse queryResult = (RestResponse)response.Result; bool valid = ValidateResponse(queryResult); JavaScriptSerializer Serializer = new JavaScriptSerializer(); Serializer.MaxJsonLength = int.MaxValue; return(Serializer.Deserialize <bool>(response.Result.Content)); } catch (Exception e) { logger.Error("Unable to save ArchiveConfiguration.", e); throw new BcephalException("Unable to save ArchiveConfiguration.", e); } }
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 static bool Create(this ArchiveConfiguration This, string Source_Folder, string Dest_File) { var args = new CreateArchiveParameters() { Source_Folder = Source_Folder, Dest_File = Dest_File }; return(This.Create(args)); }
public static ArchiveConfiguration ArchiveConfiguration() { var ret = new ArchiveConfiguration() { CreateUsing = new ExternalToolConfiguration() { Path = Utilities.SevenZip.CommandLine.FolderPath, Application = Utilities.SevenZip.CommandLine.ExecutableName, ArgumentTemplate = Utilities.SevenZip.CommandLine.SelfExtractingArchive.CreateParameterTemplate, }, }; return(ret); }
/// <summary> /// /// </summary> /// <returns>ArchiveConfiguration</returns> public ArchiveConfiguration getArchiveConfiguration() { try { var request = new RestRequest(ResourcePath + "/archive/configuration", Method.GET); var queryResult = RestClient.ExecuteTaskAsync(request); checkError(queryResult.Result); ArchiveConfiguration config = RestSharp.SimpleJson.DeserializeObject <ArchiveConfiguration>(queryResult.Result.Content); return(config); } catch (BcephalException e) { logger.Error("Unable to retrieve archive configuration", e); throw new BcephalException(e.Message); } catch (Exception e) { logger.Error("Unable to retrieve archive configuration", e); throw new BcephalException("Unable to retrieve archive configuration.", e); } }
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); } }
private string UnZipPreservationFile(string zipPath) { StringBuilder sb = new StringBuilder(); try { if (System.IO.File.Exists(zipPath)) { using (Stream stream = System.IO.File.OpenRead(zipPath)) using (IReader reader = ReaderFactory.Open(stream)) { while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { string fileName = Path.GetFileName(reader.Entry.Key); _logger.InfoFormat("UnzipPreservationFile -> Lettura file {0}", fileName); string preservationIdStr = fileName.Split('_').FirstOrDefault(); if (Guid.TryParse(preservationIdStr, out Guid idPreservation)) { Preservation preservation = _preservationService.GetPreservation(idPreservation, false); if (preservation == null) { _logger.WarnFormat("Nessuna conservazione trovata con Id {0}", idPreservation); continue; } if (preservation.CloseDate.HasValue) { _logger.InfoFormat("UnzipPreservationFile -> Conservazione <b>{0}</b> del {1} <b>CHIUSA</b> il {2}.<br/>", preservation.IdPreservation, preservation.StartDate, preservation.CloseDate); sb.AppendFormat("Conservazione <b>{0}</b> del {1} <b>CHIUSA</b> il {2}.<br/>", preservation.IdPreservation, preservation.StartDate, preservation.CloseDate); continue; } string toSaveFile = Path.Combine(preservation.Path, fileName.Substring(fileName.IndexOf('_') + 1)); if (System.IO.File.Exists(toSaveFile)) { _logger.InfoFormat("UnzipPreservationFile -> File già presente!<br/>Il file verrà ignorato: {0}<br/>", Path.Combine(preservation.Path, preservation.Label, fileName.Substring(fileName.IndexOf('_') + 1))); sb.AppendFormat("File già presente!<br/>Il file verrà ignorato: {0}<br/>", Path.Combine(preservation.Path, preservation.Label, fileName.Substring(fileName.IndexOf('_') + 1))); } else { reader.WriteEntryToFile(toSaveFile, _extractionOptions); _logger.DebugFormat("UnzipPreservationFile -> file {0} saved correctly", toSaveFile); } string ipdaSignedFile = IpdaUtil.GetIpdaTsdFile(preservation.Path); if (string.IsNullOrEmpty(ipdaSignedFile)) { _logger.WarnFormat("UnzipPreservationFile -> Nessun file IPDA firmato trovato nel percorso {0}", preservation.Path); continue; } ArchiveConfiguration archiveConfiguration = JsonConvert.DeserializeObject <ArchiveConfiguration>(preservation.Archive.PreservationConfiguration); if (!archiveConfiguration.CloseWithoutVerify) { _logger.InfoFormat("UnzipPreservationFile -> Chiusura Conservazione {0} con verify", preservation.IdPreservation); if (_preservationService.VerifyExistingPreservation(preservation.IdPreservation)) { _logger.InfoFormat("UnzipPreservationFile -> Verifica conservazione {0} conclusa con esito positivo", preservation.IdPreservation); } else { _logger.InfoFormat("UnzipPreservationFile -> Verifica conservazione {0} conclusa con esito negativo", preservation.IdPreservation); sb.Append(string.Join("<br/>", _preservationService.ErrorMessages)); continue; } } _preservationService.ClosePreservation(preservation.IdPreservation); string pattern = "Conservazione <b>{0}</b> del {1} <b>CHIUSA</b> in questa esecuzione.<br/>"; sb.AppendFormat(pattern, preservation.IdPreservation, preservation.StartDate); //aggiunge informazioni sull'ipda sb.Append(GetIpdaInfo(_preservationService.verifiedIpda)); } } } } } } catch (Exception ex) { _logger.Error(ex); _logger.ErrorFormat("UnzipPreservationFile -> errore nello spacchettamento dello zip per la chiusura: {0}. La procedura non verrà interrotta", ex.Message); sb.Append(ex.Message); } return(sb.ToString()); }
public static bool Create(this ArchiveConfiguration This, CreateArchiveParameters Args) { return(This.CreateUsing.Run(Args)); }