public SecureDocumentModel Create(SecureDocumentModel documentModel)
        {
            try
            {
                _logger.WriteDebug(new LogMessage(string.Concat("Create -> create secure document for document ", documentModel.DocumentName)), LogCategories);
                if (documentModel.DocumentContent == null)
                {
                    _logger.WriteWarning(new LogMessage("Create -> document not found"), LogCategories);
                    throw new ArgumentNullException(nameof(SecureDocumentModel.DocumentContent), "Nessun documento passato per la securizzazione");
                }

                DOUService.DOUResponse response = _client.create(documentModel.DocumentContent, _idService, null);
                ValidateResponse(response);
                _logger.WriteInfo(new LogMessage(string.Concat("Create -> document generated correctly with id ", response.idPdf)), LogCategories);
                return(new SecureDocumentModel()
                {
                    IdDocument = response.idPdf,
                    DocumentContent = response.pdf
                });
            }
            catch (Exception ex)
            {
                _logger.WriteError(new LogMessage("Create -> Error on create secure document call."), ex, LogCategories);
                throw;
            }
        }
        public void Upload(SecureDocumentModel documentModel)
        {
            try
            {
                if (documentModel.DocumentContent == null)
                {
                    _logger.WriteWarning(new LogMessage("Upload -> document not found"), LogCategories);
                    throw new ArgumentNullException(nameof(SecureDocumentModel.DocumentContent), "Nessun documento passato per la securizzazione");
                }

                if (string.IsNullOrEmpty(documentModel.IdDocument))
                {
                    _logger.WriteWarning(new LogMessage("Upload -> idDocument is null"), LogCategories);
                    throw new ArgumentNullException(nameof(SecureDocumentModel.IdDocument), "Nessun iddocument passato per la securizzazione");
                }
                DOUService.DOUResponse response = _client.upload(documentModel.DocumentContent, documentModel.IdDocument, _idService, Encoding.UTF8.GetBytes(DEFAULT_METADATA));
                ValidateResponse(response);
                _logger.WriteInfo(new LogMessage(string.Concat("Upload -> document with id ", documentModel.IdDocument, " uploaded correctly")), LogCategories);
            }
            catch (Exception ex)
            {
                _logger.WriteError(new LogMessage("Upload -> Error on upload secure document call."), ex, LogCategories);
                throw;
            }
        }
        public SecureDocumentModel Update(SecureDocumentModel documentModel)
        {
            try
            {
                _logger.WriteDebug(new LogMessage(string.Concat("Update -> update secure document for iddocument ", documentModel.IdDocument)), LogCategories);
                if (documentModel.DocumentContent == null)
                {
                    _logger.WriteWarning(new LogMessage("Update -> document not found"), LogCategories);
                    throw new ArgumentNullException(nameof(SecureDocumentModel.DocumentContent), "Nessun documento passato per la securizzazione");
                }

                if (string.IsNullOrEmpty(documentModel.IdDocument))
                {
                    _logger.WriteWarning(new LogMessage("Update -> idDocument is null"), LogCategories);
                    throw new ArgumentNullException(nameof(SecureDocumentModel.IdDocument), "Nessun iddocument passato per la securizzazione");
                }

                DOUService.DOUResponse response = _client.update(documentModel.DocumentContent, documentModel.IdDocument, _idService);
                ValidateResponse(response);
                _logger.WriteInfo(new LogMessage(string.Concat("Update -> document with id ", response.idPdf, " updated correctly")), LogCategories);
                return(new SecureDocumentModel()
                {
                    IdDocument = response.idPdf,
                    DocumentContent = response.pdf
                });
            }
            catch (Exception ex)
            {
                _logger.WriteError(new LogMessage("Update -> Error on update secure document call."), ex, LogCategories);
                throw;
            }
        }
        public void UploadSecureDocument(stDoc document)
        {
            try
            {
                logger.InfoFormat("UploadSecureDocument - INIT - {0}", HttpContext.Current.Request.UserHostAddress);
                if (_secureDocumentService == null)
                {
                    logger.Warn("UploadSecureDocument - SecureDocumentService not initialize. Please check application configuration settings.");
                    throw new Exception("Servizio di securizzazione non abilitato. Verificare le impostazioni del sistema.");
                }

                SecureDocumentModel request = new SecureDocumentModel()
                {
                    DocumentContent = Convert.FromBase64String(document.Blob),
                    IdDocument      = document.ReferenceId
                };
                logger.DebugFormat("UploadSecureDocument - Call upload secure document for iddocument {0}", document.ReferenceId);
                _secureDocumentService.Upload(request);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                throw ex;
            }
            finally
            {
                logger.InfoFormat("UploadSecureDocument - END - {0}", HttpContext.Current.Request.UserHostAddress);
            }
        }
 public void Delete(SecureDocumentModel documentModel)
 {
     try
     {
         if (string.IsNullOrEmpty(documentModel.IdDocument))
         {
             _logger.WriteWarning(new LogMessage("Delete -> idDocument is null"), LogCategories);
             throw new ArgumentNullException(nameof(SecureDocumentModel.IdDocument), "Nessun iddocument passato per la securizzazione");
         }
         DOUService.DOUResponse response = _client.delete(documentModel.IdDocument, _idService);
         ValidateResponse(response);
         _logger.WriteInfo(new LogMessage(string.Concat("Delete -> document with id ", documentModel.IdDocument, " deleted correctly")), LogCategories);
     }
     catch (Exception ex)
     {
         _logger.WriteError(new LogMessage("Delete -> Error on delete secure document call."), ex, LogCategories);
         throw;
     }
 }
        public stDoc CreateSecureDocument(stDoc document, string filename, string label)
        {
            try
            {
                logger.InfoFormat("CreateSecureDocument - INIT - {0}", HttpContext.Current.Request.UserHostAddress);
                if (_secureDocumentService == null)
                {
                    logger.Warn("CreateSecureDocument - SecureDocumentService not initialize. Please check application configuration settings.");
                    throw new Exception("Servizio di securizzazione non abilitato. Verificare le impostazioni del sistema.");
                }

                filename = Path.GetFileName(filename);
                logger.DebugFormat("CreateSecureDocument - Convert document {0} to PDF", filename);
                stDoc pdfDocument           = ToRasterFormatEx(document, Path.GetExtension(filename), label);
                SecureDocumentModel request = new SecureDocumentModel()
                {
                    DocumentContent = Convert.FromBase64String(pdfDocument.Blob),
                    DocumentName    = string.Concat(Path.GetFileName(filename), ".pdf")
                };
                logger.DebugFormat("CreateSecureDocument - Call create secure document for document {0}", filename);
                SecureDocumentModel response = _secureDocumentService.Create(request);
                return(new stDoc()
                {
                    Blob = Convert.ToBase64String(response.DocumentContent),
                    ReferenceId = response.IdDocument
                });
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                throw ex;
            }
            finally
            {
                logger.InfoFormat("CreateSecureDocument - END - {0}", HttpContext.Current.Request.UserHostAddress);
            }
        }