コード例 #1
0
        /// <summary>
        /// Metodo per l'aggiunta degli allegati ad un documento
        /// </summary>
        /// <param name="docNumber">Numero del documento cui aggiungere gli allegati</param>
        /// <param name="attachments">Informazioni sugli allegati da creare</param>
        /// <param name="userInfo">Informazioni sull'utente utilizzato per la creazione del predisposto in ingresso</param>
        /// <param name="senderAdministrationId">Id dell'amministrazione mittente della richiesta di interoperabilità</param>
        /// <param name="senderFileManagerUrl">Url del file manager per il download dell'eventuale file associato ad un allegato</param>
        private static void AddAttachments(String docNumber, List <DocumentInfo> attachments, InfoUtente userInfo, String senderAdministrationId, String senderFileManagerUrl)
        {
            int i = 0;

            foreach (DocumentInfo attachment in attachments)
            {
                // Creazione dell'oggetto allegato
                Allegato a = new Allegato();

                // Impostazione delle proprietà dell'allegato
                if (String.IsNullOrEmpty(attachment.Name))
                {
                    a.descrizione = String.Format("Allegato {0}", i);
                }
                else
                {
                    a.descrizione = attachment.Name;
                }

                a.docNumber    = docNumber;
                a.fileName     = InteroperabilitaSegnatura.getFileName(attachment.FileName);
                a.version      = "0";
                a.numeroPagine = attachment.NumberOfPages;

                // Aggiunta dell'allegato al documento principale
                try
                {
                    a = AllegatiManager.aggiungiAllegato(userInfo, a);
                }
                catch (Exception ex)
                {
                    SimplifiedInteroperabilityLogAndRegistryManager.InsertItemInLog(
                        docNumber,
                        true,
                        String.Format("Errore durante l'aggiunta dell'allegato '{0}'. Messaggio eccezione: {1}",
                                      a.descrizione,
                                      ex.Message));

                    throw new CreatingDocumentException(
                              String.Format("Errore durante l'aggiunta dell'allegato '{0}'", attachment.Name));
                }
                string errPutFile = "";
                try
                {
                    // Associazione dell'immagine all'allegato
                    FileRequest request = a as FileRequest;
                    if (!String.IsNullOrEmpty(attachment.FileName))
                    {
                        SimplifiedInteroperabilityFileManager.DownloadFile(
                            attachment,
                            senderAdministrationId,
                            request,
                            userInfo,
                            senderFileManagerUrl,
                            out errPutFile);
                    }

                    if (!string.IsNullOrEmpty(errPutFile))
                    {
                        throw new Exception("Errore durante l'associazione dell'immagine al documento principale");
                    }
                }
                catch (Exception e)
                {
                    SimplifiedInteroperabilityLogAndRegistryManager.InsertItemInLog(
                        a.docNumber,
                        true,
                        String.Format("Errore durante l'associazione dell'immagine per l'allegato '{0}'. Messaggio eccezione: {1}",
                                      a.descrizione,
                                      e.Message));
                    if (!string.IsNullOrEmpty(errPutFile) && errPutFile.Contains("formato file"))
                    {
                        throw new DownloadDocumentException(
                                  String.Format("Errore durante l'associazione dell'immagine all'allegato '{0}'. {1} destinataria.", attachment.Name, errPutFile));
                    }
                    else
                    {
                        throw new DownloadDocumentException(
                                  String.Format("Errore durante l'associazione dell'immagine all'allegato '{0}'", attachment.Name));
                    }
                }
                i++;
            }
        }
コード例 #2
0
        /// <summary>
        /// Creazione del documento nel sistema
        /// </summary>
        /// <param name="settings">Impostazioni relative al registro su cui creare il documento</param>
        /// <param name="senderInfo">Informazioni sul mittente della richiesta</param>
        /// <param name="interoperabilityMessage">Messaggio con le informazioni sulla richiesta di interoperabilità</param>
        /// <param name="userRole">Ruolo dell'utente da utilizzare per la creazione del documento</param>
        /// <param name="user">Utente da utilizzare per la creazione del documento</param>
        /// <returns>Scheda del documento creato</returns>
        private static SchedaDocumento CreateDocument(InteroperabilitySettings settings, Corrispondente senderInfo, InteroperabilityMessage interoperabilityMessage, Ruolo userRole, Utente user, String messageId)
        {
            // Recupero delle informazioni sull'utente da utilizzare come creatore del documento
            InfoUtente userInfo = UserManager.GetInfoUtente(user, userRole);

            // Creazione della scheda documento da restituire
            SchedaDocumento document = DocManager.NewSchedaDocumento(userInfo);

            // Recupero del registro su cui creare il predisposto
            Registro registry = RegistriManager.getRegistro(settings.RegistryId);

            // Recupero del mezzo di spedizione
            MezzoSpedizione channel = InfoDocManager.GetMezzoSpedizioneDaCodice("SIMPLIFIEDINTEROPERABILITY");

            // Impostazione delle proprietà del documento
            try
            {
                if (!String.IsNullOrEmpty(interoperabilityMessage.MainDocument.FileName))
                {
                    document.appId = InteroperabilitaSegnatura.getApp(interoperabilityMessage.MainDocument.FileName).application;
                }
            }
            catch (Exception e) {}

            document.idPeople = user.idPeople;
            document.userId   = user.userId;
            document.oggetto  = new Oggetto()
            {
                descrizione = interoperabilityMessage.Record.Subject
            };
            document.predisponiProtocollazione = true;
            document.registro            = registry;
            document.tipoProto           = "A";
            document.typeId              = "SIMPLIFIEDINTEROPERABILITY";
            document.mezzoSpedizione     = channel.IDSystem;
            document.descMezzoSpedizione = channel.Descrizione;
            document.interop             = "S";
            document.protocollatore      = new Protocollatore(userInfo, userRole);
            document.privato             = interoperabilityMessage.IsPrivate ? "1" : "0";

            // Se la gestione dell'interoperabilità è manuale con mantenimento
            // del documento pendente, il documento viene creato privato e subito dopo
            // la creazione viene rimarcato come non privato
            if (settings.ManagementMode == ManagementType.M && settings.KeepPrivate)
            {
                document.privato = "1";
            }

            // Preparazione dell'oggetto protocollo entrata
            ProtocolloEntrata proto = new ProtocolloEntrata();

            proto.mittente = senderInfo;
            proto.dataProtocolloMittente        = interoperabilityMessage.Record.RecordDate.ToString("dd/MM/yyyy HH:mm:ss");
            proto.descrizioneProtocolloMittente = String.Format("{0}{1}{2}",
                                                                interoperabilityMessage.Record.AOOCode,
                                                                DocsPaDB.Utils.Personalization.getInstance(registry.idAmministrazione).getSepSegnatura(),
                                                                interoperabilityMessage.Record.RecordNumber);
            document.protocollo = proto;

            // Se per l'amministrazione è configurata l'aggiunta di una nota visibile a tutti,
            // ne viene aggiunta una
            String value = DocsPaUtils.Configuration.InitConfigurationKeys.GetValue("0", "BE_NOTE_IN_SEGNATURA");

            if (!String.IsNullOrEmpty(value) && value == "1" && !String.IsNullOrEmpty(interoperabilityMessage.Note))
            {
                document.noteDocumento = new List <DocsPaVO.Note.InfoNota>()
                {
                    new DocsPaVO.Note.InfoNota(interoperabilityMessage.Note, userInfo.idPeople, userInfo.idGruppo, DocsPaVO.Note.TipiVisibilitaNotaEnum.Tutti, String.Empty)
                    {
                        DaInserire = true
                    }
                }
            }
            ;

            // Salvataggio del documento
            try
            {
                document = DocSave.addDocGrigia(document, userInfo, userRole);

                // Associazione del canale di spedizione al documento
                ProtoManager.collegaMezzoSpedizioneDocumento(userInfo, channel.IDSystem, document.systemId);
            }
            catch (Exception e)
            {
                SimplifiedInteroperabilityLogAndRegistryManager.InsertItemInLog(String.Empty, true, e.Message + " Id messaggio: " + messageId);
                throw new CreatingDocumentException("Errore durante la creazione del documento");
            }
            // Se tutto è andato bene, la scheda documento ha ora il campo system id popolato, quindi viene aggiunta
            // una voce al log e viene aggiornato l'id profile per la voce nel registro dei messaggi ricevuti
            SimplifiedInteroperabilityLogAndRegistryManager.InsertItemInLog(document.systemId, false,
                                                                            String.Format("Documento relativo alla richiesta con id {0}, creato correttamente.", messageId));
            SimplifiedInteroperabilityLogAndRegistryManager.SetIdProfileForMessage(messageId, document.systemId);

            // Impostazione delle informazioni aggiuntive e salvataggio del documento
            ((Documento)document.documenti[0]).dataArrivo = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
            bool toUpdate;

            document = DocSave.save(userInfo, document, false, out toUpdate, userRole);
            string errPutFile = "";

            try
            {
                // Associazione dell'immagine al documento
                String      err     = String.Empty;
                FileRequest request = document.documenti[0] as FileRequest;
                logger.DebugFormat("IS - Associa documento. Versionid {0}, Versionlabel {1}, version {2}",
                                   request.versionId, request.versionLabel, request.version);

                if (!String.IsNullOrEmpty(interoperabilityMessage.MainDocument.FileName))
                {
                    SimplifiedInteroperabilityFileManager.DownloadFile(
                        interoperabilityMessage.MainDocument,
                        interoperabilityMessage.Sender.AdministrationId,
                        request,
                        userInfo,
                        interoperabilityMessage.Sender.FileManagerUrl,
                        out errPutFile);
                }
                if (!string.IsNullOrEmpty(errPutFile))
                {
                    throw new Exception("Errore durante l'associazione dell'immagine al documento principale");
                }
            }
            catch (Exception e)
            {
                SimplifiedInteroperabilityLogAndRegistryManager.InsertItemInLog(
                    document.systemId,
                    true,
                    String.Format("Errore durante l'associazione dell'immagine per il documento principale. Messaggio eccezione: {0}",
                                  e.Message));
                if (!string.IsNullOrEmpty(errPutFile) && errPutFile.Contains("formato file"))
                {
                    throw new DownloadDocumentException("Errore durante l'associazione dell'immagine al documento principale." + errPutFile + " destinataria.");
                }
                else
                {
                    throw new DownloadDocumentException("Errore durante l'associazione dell'immagine al documento principale");
                }
            }
            AddAttachments(document.docNumber, interoperabilityMessage.Attachments, userInfo, interoperabilityMessage.Sender.AdministrationId, interoperabilityMessage.Sender.FileManagerUrl);
            // Restituzione del documento salvato
            return(document);
        }