public BindingList <Document> GetAllDocumentsWithThumbnail(string archiveName, bool visible, int skip, int take, out int docunentsInArchiveCount) { docunentsInArchiveCount = -1; try { logger.DebugFormat("GetAllDocuments archiveName:{0}, skip:{1}, take:{2}, visible:{3}", archiveName, skip, take, visible); var archive = ArchiveService.GetArchiveByName(archiveName); if (archive == null) { throw new BiblosDS.Library.Common.Exceptions.Archive_Exception("Archive: " + archiveName + " not found."); } var result = DocumentService.GetAllDocuments(archive, visible, skip, take, out docunentsInArchiveCount); using (var clientChannel = WCFUtility.GetClientConfigChannel <IServiceDocumentStorage>(ServerService.WCF_DocumentStorage_HostName)) { foreach (var item in result) { if (!string.IsNullOrEmpty(item.IdThumbnail)) { item.ThumbnailContent = (clientChannel as IServiceDocumentStorage).GetDocumentConformAttach(item, item.IdThumbnail).Content; } } } return(result); } catch (Exception ex) { logger.Error(ex); throw; } finally { logger.DebugFormat("GetAllDocuments archiveName:{0}, RETUNT: {1}", archiveName, docunentsInArchiveCount); } }
public void AddStorage(DocumentStorage Storage) { StorageService.AddStorage(Storage); using (var clientChannel = WCFUtility.GetClientConfigChannel <IServiceDocumentStorage>(ServerService.WCF_DocumentStorage_HostName)) { (clientChannel as IServiceDocumentStorage).InitializeStorage(Storage); } }
public static DocumentServer AddDocumentToMaster(Document document) { var server = ServerService.GetCurrentServer(); if (server == null) { throw new Exceptions.ServerNotDefined_Exception(); } string pathTransito = ServerService.GetPathTransito(document.Archive, server.IdServer); DocumentStatus status = DocumentStatus.Undefined; if (document.Archive.TransitoEnabled) { if ((document.Content != null && document.Content.Blob != null && document.Content.Blob.Length > 0)) { FileService.SaveFileToTransitoLocalPath(document, pathTransito, document.Content.Blob); status = DocumentStatus.InTransito; } else { if (ConfigurationManager.AppSettings["AllowZeroByteDocument"].ToStringExt() != "true") { throw new Exception("Impossibile inserire un documento di zero byte."); } else { status = DocumentStatus.ProfileOnly; } } } else { if ((document.Content != null && document.Content.Blob != null && document.Content.Blob.Length > 0)) { using (var clientChannel = WCFUtility.GetClientConfigChannel <IServiceDocumentStorage>(ServerService.WCF_DocumentStorage_HostName, server.ServerName)) { (clientChannel as IServiceDocumentStorage).AddDocument(document); } status = DocumentStatus.InStorage; } else { if (ConfigurationManager.AppSettings["AllowZeroByteDocument"].ToStringExt() != "true") { throw new Exception("Impossibile inserire un documento di zero byte."); } else { status = DocumentStatus.ProfileOnly; } } } document.Storage = null; document.StorageArea = null; return(DbProvider.SaveDocumentToMaster(document, server, status, pathTransito)); }
public bool StoreTransitArchiveDocumentAttaches(string archiveName) { bool bReturn = true; try { DocumentArchive archive = ArchiveService.GetArchiveByName(archiveName); if (archive == null) { throw new BiblosDS.Library.Common.Exceptions.Archive_Exception("Archive not found"); } BindingList <DocumentAttach> documents = DocumentService.GetDocumentAttachesInTransito(archive.IdArchive, 0); // esegue la query nel db DocumentAttach document; foreach (var item in documents) { try { document = DocumentService.GetDocumentAttach(item.IdDocumentAttach); using (var clientChannel = WCFUtility.GetClientConfigChannel <IServiceDocumentStorage>(ServerService.WCF_DocumentStorage_HostName)) { (clientChannel as IServiceDocumentStorage).AddAttachToDocument(document); } } catch (Exception e) { bReturn = false; Logging.WriteLogEvent(LoggingSource.BiblosDS_WS, "Document.ProcessCheckInTransitoDocumentAttach", e.ToString(), LoggingOperationType.BiblosDS_CheckInTransitoDocument, LoggingLevel.BiblosDS_Warning); } } // end foreach return(bReturn); } catch (Exception ex) { Logging.WriteLogEvent(LoggingSource.BiblosDS_WS, "Document.ProcessCheckInTransitoDocument", ex.ToString(), LoggingOperationType.BiblosDS_CheckInTransitoDocument, LoggingLevel.BiblosDS_Warning); return(false); } }
public bool StoreTransitDocuments() { logger.Debug("StoreTransitDocuments -> Init"); bool bReturn = true; try { BindingList <Document> documents = DocumentService.GetDocumentInTransito(0); // esegue la query nel db Document document; foreach (Document item in documents) { try { document = DocumentService.GetDocument(item.IdDocument); using (var clientChannel = WCFUtility.GetClientConfigChannel <IServiceDocumentStorage>(ServerService.WCF_DocumentStorage_HostName)) { (clientChannel as IServiceDocumentStorage).AddDocument(document); } } catch (Exception e) { bReturn = false; Logging.WriteLogEvent(LoggingSource.BiblosDS_WS, "Document.ProcessCheckInTransitoDocument", e.ToString(), LoggingOperationType.BiblosDS_CheckInTransitoDocument, LoggingLevel.BiblosDS_Warning); } } // end foreach logger.InfoFormat("StoreTransitDocuments -> End processed {0} documents that are in 'Transito'", documents.Count); return(bReturn); } catch (Exception ex) { Logging.WriteLogEvent(LoggingSource.BiblosDS_WS, "Document.ProcessCheckInTransitoDocument", ex.ToString(), LoggingOperationType.BiblosDS_CheckInTransitoDocument, LoggingLevel.BiblosDS_Warning); return(false); } }
public bool StoreTransitDocument(Guid idDocument) { bool bReturn = true; try { Document document; try { document = DocumentService.GetDocument(idDocument); using (var clientChannel = WCFUtility.GetClientConfigChannel <IServiceDocumentStorage>(ServerService.WCF_DocumentStorage_HostName)) { (clientChannel as IServiceDocumentStorage).AddDocument(document); } } catch (Exception e) { bReturn = false; Logging.WriteLogEvent(LoggingSource.BiblosDS_WS, "Document.ProcessCheckInTransitoDocument", e.ToString(), LoggingOperationType.BiblosDS_CheckInTransitoDocument, LoggingLevel.BiblosDS_Warning); } logger.InfoFormat("Document.ProcessCheckInTransitoDocument processed document: {0}", idDocument); return(bReturn); } catch (Exception ex) { Logging.WriteLogEvent(LoggingSource.BiblosDS_WS, "Document.ProcessCheckInTransitoDocument", ex.ToString(), LoggingOperationType.BiblosDS_CheckInTransitoDocument, LoggingLevel.BiblosDS_Warning); return(false); } }
public override async Task Execute(CommandModel commandModel) { try { if (!(commandModel is CommandInsertPreservationPDV)) { _logger.Error($"Command is not of type {nameof(CommandInsertPreservationPDV)}"); return; } CommandInsertPreservationPDV @command = commandModel as CommandInsertPreservationPDV; await SendNotification(command.ReferenceId, $"Inizio salvataggio PDV per il lotto di versamento con id {command.IdAwardBatch}", NotifyLevel.Info); DocumentArchive pdvArchive = ArchiveService.GetArchiveByName(command.PDVArchive); if (pdvArchive == null) { _logger.Error($"Archive with name {command.PDVArchive} not found"); throw new Exception($"Non è stato trovato un archivio con nome {command.PDVArchive}"); } ICollection <DocumentAttribute> attributes = AttributeService.GetAttributesFromArchive(pdvArchive.IdArchive); AwardBatch awardBatch = _preservationService.GetAwardBatch(command.IdAwardBatch); if (awardBatch == null) { _logger.Error($"Award batch with id {command.IdAwardBatch} not found"); throw new Exception($"Non è stato trovato un lotto di versamento con id {command.IdAwardBatch}"); } Document document = new Document { Content = new DocumentContent() { Blob = Convert.FromBase64String(command.Content) }, Name = string.Concat(UtilityService.GetSafeFileName(awardBatch.Name), ".xml"), Archive = pdvArchive, AttributeValues = new BindingList <DocumentAttributeValue>() }; document.AttributeValues.Add(new DocumentAttributeValue() { Value = document.Name, Attribute = attributes.Single(f => f.Name.Equals("Filename", StringComparison.InvariantCultureIgnoreCase)) }); document.AttributeValues.Add(new DocumentAttributeValue() { Value = awardBatch.Name, Attribute = attributes.Single(f => f.Name.Equals("Signature", StringComparison.InvariantCultureIgnoreCase)) }); using (var clientChannel = WCFUtility.GetClientConfigChannel <IDocuments>(ServerService.WCF_Document_HostName)) { document = (clientChannel as IDocuments).AddDocumentToChain(document, null, DocumentContentFormat.Binary); } awardBatch.IdPDVDocument = document.IdDocument; _preservationService.UpdateAwardBatch(awardBatch); _logger.Info($"Saved PDV with id {awardBatch.IdPDVDocument} for awardbatch {awardBatch.IdAwardBatch}"); await SendNotification(command.ReferenceId, $"PDV salvato con id {awardBatch.IdPDVDocument} per il lotto di versamento con id {awardBatch.IdAwardBatch}", NotifyLevel.Info); } catch (Exception ex) { _logger.Error("Error on insert PDV", ex); await SendNotification(commandModel.ReferenceId, $"Errore nella fase di inserimento PDV", NotifyLevel.Error); } }