protected static void InfoAllegatiDocumento(Guid idDocumento, InfoAllegatiResponse response) { response.Eseguito = false; response.CodiceEsito = CodiceErrore.NessunErrore; if (idDocumento == Guid.Empty) { response.CodiceEsito = CodiceErrore.IdDocumentoNonValido; } else { try { using (var client = new DocumentServiceReference.DocumentsClient()) { var allegati = client.GetDocumentAttachs(idDocumento); response.Allegati = allegati.Select(x => new AllegatoItem { IdAllegato = x.IdDocumentAttach, Nome = x.Name }).ToList(); response.Eseguito = true; } } catch (FaultException <BiblosDsException> faultEx) { logger.Error(faultEx); ParseBiblosDSFaultException(response, faultEx); } catch (Exception ex) { throw; } } }
/// <summary> /// Contenuto (array di bytes) dell'allegato. /// </summary> /// <param name="request">Informazioni inerenti all'allegato.</param> /// <returns>Esito operazione e contenuto dell'allegato.</returns> protected static void AggiungiAllegato(Guid idDocumento, FileItem allegato, AggiungiAllegatoResponse response) { response.Eseguito = false; response.CodiceEsito = CodiceErrore.NessunErrore; if (allegato == null) //L'allegato è nullo? { response.CodiceEsito = CodiceErrore.AllegatoNonPresente; response.Eseguito = false; } else { if (allegato.Blob == null || allegato.Blob.Length < 1 || string.IsNullOrWhiteSpace(allegato.Nome)) //L'allegato non è valido: il file è lungo 0 bytes oppure il nome è nullo. { response.CodiceEsito = CodiceErrore.AllegatoNonValido; } if (response.CodiceEsito == CodiceErrore.NessunErrore && idDocumento == Guid.Empty) { response.CodiceEsito = CodiceErrore.IdDocumentoNonValido; } //TODO: eventuali altre validazioni qui. } //Procede solo se non ci sono stati errori prima di arrivare qui. if (response.CodiceEsito == CodiceErrore.NessunErrore) { try { using (var client = new DocumentServiceReference.DocumentsClient()) { var result = client.AddDocumentAttach(idDocumento, new DocumentAttach { Content = new DocumentContent(allegato.Blob, allegato.Gruppo), Name = allegato.Nome, IdDocument = idDocumento }); if (result != null) { client.ConfirmDocumentAttach(result.IdDocumentAttach); response.Eseguito = true; } } } catch (FaultException <BiblosDsException> faultEx) { logger.Error(faultEx); ParseBiblosDSFaultException(response, faultEx); } catch (Exception ex) { throw; } } }