/// <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; } } }
/// <summary> /// Aggiunta di un allegato ad un documento. /// </summary> /// <param name="request">Modello di richiesta per l'aggiunta allegato.</param> /// <returns>Esito aggiunta <see cref="AggiungiAllegatoResponse"/>.</returns> public static AggiungiAllegatoResponse AggiungiAllegato(AggiungiAllegatoRequest request) { var response = new AggiungiAllegatoResponse { Eseguito = false, CodiceEsito = CodiceErrore.NessunErrore }; try { logger.DebugFormat("AggiungiAllegati request:{0}", request.ToString()); //Validazione token usato per la login. response.TokenInfo = Helpers.ValidaToken(request); //Viene controllato se il token è scaduto o non trovato. if (response.TokenInfo == null) { response.CodiceEsito = CodiceErrore.TokenNonValidoOScaduto; } else { //Verifico che la request sia corretta var checkRequestResult = request.CheckRequest(response); if (checkRequestResult != CodiceErrore.NessunErrore) { response.CodiceEsito = checkRequestResult; } else { AggiungiAllegato(request.IdDocumento, request.Allegato, response); } } } catch (Exception ex) { logger.Error(ex); response.CodiceEsito = CodiceErrore.ErroreGenerico; response.MessaggioErrore = ex.ToString(); } //Controlla se è tutto ok. response.CheckResponse(); //Torna al chiamante. logger.DebugFormat("AggiungiAllegati response:{0}", response.ToString()); return(response); }