Exemplo n.º 1
0
        public ActionResult CreateIpda(Guid id)
        {
            return(ActionResultHelper.TryCatchWithLogger(() =>
            {
                try
                {
                    Preservation preservation = _preservationService.GetPreservation(id, false);
                    if (preservation == null)
                    {
                        _loggerService.Error(string.Format("Nessuna conservazione trovata con id {0}", id));
                        return Content("Errore: Conservazione non valida");
                    }

                    string closeFile = IpdaUtil.GetCloseFile(preservation.Path);
                    if (string.IsNullOrEmpty(closeFile))
                    {
                        return Content("Errore: Conservazione non valida");
                    }

                    IpdaConverter converter = new IpdaConverter();
                    Ipda ipda = converter.ConvertCloseFile(closeFile, "NomeFileInArchivio");
                    ipda.SaveAs(IpdaUtil.Close2IpdaFilename(closeFile));

                    return Content("Il file IPDA è stato generato con successo");
                }
                catch (Exception ex)
                {
                    _loggerService.Error(ex.Message, ex);
                    return Content(string.Concat("Errore durante la conversione del file di chiusura.<br/>", ex.Message));
                }
            }, _loggerService));
        }
Exemplo n.º 2
0
        public ActionResult Index(Guid id)
        {
            return(ActionResultHelper.TryCatchWithLogger(() =>
            {
                Preservation preservation = _preservationService.GetPreservation(id, false);
                if (preservation == null)
                {
                    _loggerService.Warn(string.Format("Nessuna conservazione trovata con id {0}", id));
                    return HttpNotFound();
                }

                IpdaIndexViewModel model = new IpdaIndexViewModel()
                {
                    Preservation = preservation
                };
                string preservationPath = preservation.Path;
                string closeFile = IpdaUtil.GetCloseFile(preservationPath);
                string ipdaXmlFile = IpdaUtil.GetIpdaXmlFile(preservationPath);
                string ipdaTsdFile = IpdaUtil.GetIpdaTsdFile(preservationPath);
                model.ToCreate = (!string.IsNullOrEmpty(closeFile) && string.IsNullOrEmpty(ipdaXmlFile) && string.IsNullOrEmpty(ipdaTsdFile));
                model.ToSign = !model.ToCreate && (!string.IsNullOrEmpty(ipdaXmlFile) && string.IsNullOrEmpty(ipdaTsdFile));
                model.ToClose = !model.ToCreate && !model.ToSign && (!string.IsNullOrEmpty(ipdaXmlFile) && !string.IsNullOrEmpty(ipdaTsdFile) && !preservation.CloseDate.HasValue);
                return View(model);
            }, _loggerService));
        }
Exemplo n.º 3
0
 public ActionResult DownloadXml(Guid id)
 {
     return(ActionResultHelper.TryCatchWithLogger(() =>
     {
         Preservation preservation = _preservationService.GetPreservation(id, false);
         string xmlFile = IpdaUtil.GetIpdaXmlFile(preservation.Path);
         return File(xmlFile, System.Net.Mime.MediaTypeNames.Application.Zip, string.Concat(id, "_", Path.GetFileName(xmlFile)));
     }, _loggerService));
 }
Exemplo n.º 4
0
        public ActionResult GridPreservations(Guid id, [DataSourceRequest] DataSourceRequest request)
        {
            return(ActionResultHelper.TryCatchWithLogger(() =>
            {
                var result = new DataSourceResult();
                ICollection <Preservation> preservations = _preservationService.GetPreservations(id, request.PageSize, (request.Page - 1) * request.PageSize, true, false, out int counter);

                List <PreservationItem> gridItems = new List <PreservationItem>();
                foreach (var p in preservations)
                {
                    PreservationItem pi = new PreservationItem
                    {
                        IdPreservation = p.IdPreservation,
                        Label = p.Label,
                        StartDate = p.StartDate,
                        EndDate = p.EndDate,
                        CloseDate = p.CloseDate,
                        Username = p.User.Name,
                        DisplayCreate = "none",
                        DisplaySign = "none",
                        DisplayClose = "none",
                        DisplayPurge = "none"
                    };

                    if (IpdaUtil.GetCloseFile(p.Path) != "" && IpdaUtil.GetIpdaXmlFile(p.Path) == "" && IpdaUtil.GetIpdaTsdFile(p.Path) == "")
                    {
                        pi.DisplayCreate = "inline";
                    }

                    if (IpdaUtil.GetIpdaXmlFile(p.Path) != "" && IpdaUtil.GetIpdaTsdFile(p.Path) == "" && !p.CloseDate.HasValue)
                    {
                        pi.DisplaySign = "inline";
                    }

                    if (IpdaUtil.GetIpdaXmlFile(p.Path) != "" && IpdaUtil.GetIpdaTsdFile(p.Path) != "" && !p.CloseDate.HasValue)
                    {
                        pi.DisplayClose = "inline";
                    }

                    if (p.CloseDate.HasValue && _preservationService.CountPreservationDocumentsToPurge(p.IdPreservation) > 0)
                    {
                        pi.DisplayPurge = "inline";
                    }

                    gridItems.Add(pi);
                }

                result.Total = counter;
                result.Data = gridItems;
                return Json(result, JsonRequestBehavior.AllowGet);
            }, _loggerService));
        }
Exemplo n.º 5
0
        private string CreatePreservationZipToDownload(List <Preservation> preservations)
        {
            string destination = Path.Combine(ConfigurationHelper.GetAppDataPath(), string.Format("Preservation_{0:yyyyMMddHHmmss}.zip", DateTime.Now));

            using (IWritableArchive archive = ArchiveFactory.Create(ArchiveType.Zip))
            {
                foreach (Preservation preservation in preservations)
                {
                    string file = IpdaUtil.GetIpdaXmlFile(preservation.Path);
                    archive.AddEntry(string.Concat(preservation.IdPreservation, "_", Path.GetFileName(file)), file);
                }
                archive.SaveTo(destination, CompressionType.Deflate);
            }
            return(destination);
        }
Exemplo n.º 6
0
        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());
        }