Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="infoUtente"></param>
        /// <param name="allegato"></param>
        /// <param name="documento"></param>
        /// <returns></returns>
        public static bool scambiaAllegatoDocumento(DocsPaVO.utente.InfoUtente infoUtente,
                                                    DocsPaVO.documento.Allegato allegato, DocsPaVO.documento.Documento documento)
        {
            // Controllo su stato congelato
            DocumentConsolidation.CanExecuteAction(infoUtente, documento.docNumber, DocumentConsolidation.ConsolidationActionsDeniedEnum.ModifyVersions, true);

            bool retValue = false;

            using (DocsPaDB.TransactionContext transactionContext = new DocsPaDB.TransactionContext())
            {
                DocsPaDocumentale.Documentale.DocumentManager documentManager = new DocsPaDocumentale.Documentale.DocumentManager(infoUtente);

                retValue = documentManager.ScambiaAllegatoDocumento(allegato, documento);

                if (retValue)
                {
                    transactionContext.Complete();
                }
            }

            return(retValue);
        }
Exemple #2
0
        /// <summary>
        /// Rimozione di un allegato
        /// </summary>
        /// <param name="allegato"></param>
        /// <param name="infoUtente"></param>
        public static bool rimuoviAllegato(DocsPaVO.documento.Allegato allegato, DocsPaVO.utente.InfoUtente infoUtente)
        {
            bool retValue = false;

            if (allegato.repositoryContext != null)
            {
                // Rimozione dell'allegato nell'ambito del  repository context
                SessionRepositoryFileManager fm = BusinessLogic.Documenti.SessionRepositoryFileManager.GetFileManager(allegato.repositoryContext);

                // Verifica esistenza file acquisito nel repository context
                if (fm.ExistFile(allegato))
                {
                    fm.RemoveFile(allegato);
                }

                retValue = true;
            }
            else
            {
                // Controllo su stato congelato
                DocumentConsolidation.CanExecuteAction(infoUtente,
                                                       allegato.docNumber,
                                                       DocumentConsolidation.ConsolidationActionsDeniedEnum.RemoveAttatchments, true);

                using (DocsPaDB.TransactionContext transactionContext = new DocsPaDB.TransactionContext())
                {
                    DocsPaDocumentale.Documentale.DocumentManager documentManager = new DocsPaDocumentale.Documentale.DocumentManager(infoUtente);

                    retValue = documentManager.RemoveAttatchment(allegato);

                    if (retValue)
                    {
                        transactionContext.Complete();
                    }
                }
            }

            return(retValue);
        }
Exemple #3
0
        /// <summary>
        /// Modifica dei dati di un allegato
        /// </summary>
        /// <param name="allegato"></param>
        /// <param name="debug"></param>
        public static void modificaAllegato(DocsPaVO.utente.InfoUtente infoUtente, DocsPaVO.documento.Allegato allegato)
        {
            if (allegato.repositoryContext != null)
            {
                // Modifica allegato gestito mediante il repository context
            }
            else
            {
                // Controllo su stato congelato
                DocumentConsolidation.CanExecuteAction(infoUtente,
                                                       allegato.docNumber,
                                                       DocumentConsolidation.ConsolidationActionsDeniedEnum.ModifyAttatchments, true);

                using (DocsPaDB.TransactionContext transactionContext = new DocsPaDB.TransactionContext())
                {
                    DocsPaDocumentale.Documentale.DocumentManager documentManager = new DocsPaDocumentale.Documentale.DocumentManager(infoUtente);

                    documentManager.ModifyAttatchment(allegato);

                    transactionContext.Complete();
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Rimozione di una versione del documento
        /// </summary>
        /// <param name="fileRequest"></param>
        /// <param name="infoUtente"></param>
        /// <returns></returns>
        public static bool removeVersion(DocsPaVO.documento.FileRequest fileRequest, DocsPaVO.utente.InfoUtente infoUtente)
        {
            if (fileRequest.repositoryContext == null)
            {
                // Verifica stato di consolidamento del documento
                DocumentConsolidation.CanExecuteAction(infoUtente, fileRequest.docNumber, DocumentConsolidation.ConsolidationActionsDeniedEnum.RemoveVersions, true);
            }

            logger.Debug("removeVersion");
            bool result = false;


            using (DocsPaDB.TransactionContext transactionContext = new DocsPaDB.TransactionContext())
            {
                DocsPaDocumentale.Documentale.DocumentManager documentManager = new DocsPaDocumentale.Documentale.DocumentManager(infoUtente);
                result = documentManager.RemoveVersion(fileRequest);
                if (result)
                {
                    transactionContext.Complete();
                }
            }
            return(result);
        }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="infoUtente"></param>
        /// <param name="fileReq"></param>
        public static void modificaVersione(DocsPaVO.utente.InfoUtente infoUtente, DocsPaVO.documento.FileRequest fileReq)
        {
            try
            {
                if (fileReq.repositoryContext == null)
                {
                    // Verifica stato di consolidamento del documento
                    DocumentConsolidation.CanExecuteAction(infoUtente, fileReq.docNumber, DocumentConsolidation.ConsolidationActionsDeniedEnum.RemoveVersions, true);
                }

                using (DocsPaDB.TransactionContext transactionContext = new DocsPaDB.TransactionContext())
                {
                    DocsPaDocumentale.Documentale.DocumentManager documentManager = new DocsPaDocumentale.Documentale.DocumentManager(infoUtente);
                    documentManager.ModifyVersion(fileReq);

                    transactionContext.Complete();
                }
            }
            catch (Exception ex)
            {
                logger.Debug(ex.Message);
            }
        }
Exemple #6
0
        /// <summary>
        /// </summary>
        /// <param name="fileRequest"></param>
        /// <param name="infoUtente"></param>
        /// <param name="daInviare"></param>
        /// <returns></returns>
        public static DocsPaVO.documento.FileRequest addVersion(DocsPaVO.documento.FileRequest fileRequest, DocsPaVO.utente.InfoUtente infoUtente, bool daInviare)
        {
            logger.Info("BEGIN");
            logger.Debug("addVersion");

            if (fileRequest.repositoryContext != null)
            {
                if (!daInviare)
                {
                    // Inserimento della versione nel repositorycontext (il documento ancora non è stato salvato)
                    int newVersion, newVersionLabel;
                    Int32.TryParse(fileRequest.version, out newVersion);
                    Int32.TryParse(fileRequest.versionLabel, out newVersionLabel);

                    fileRequest.subVersion   = "!";
                    fileRequest.version      = (newVersion + 1).ToString();
                    fileRequest.versionLabel = (newVersionLabel + 1).ToString();
                }
            }
            else
            {
                // Verifica stato di consolidamento del documento
                DocumentConsolidation.CanExecuteAction(infoUtente, fileRequest.docNumber, DocumentConsolidation.ConsolidationActionsDeniedEnum.AddVersions, true);
                if (!LibroFirma.LibroFirmaManager.CanExecuteAction(fileRequest, infoUtente))
                {
                    throw new Exception("Non è possibile creare la versione poichè il documento principale è in libro firma");
                }

                DocsPaDocumentale.Documentale.DocumentManager documentManager = new DocsPaDocumentale.Documentale.DocumentManager(infoUtente);
                if (!documentManager.AddVersion(fileRequest, daInviare))
                {
                    fileRequest = null;
                }
            }
            logger.Info("END");
            return(fileRequest);
        }
Exemple #7
0
        // public static DocsPaVO.documento.SchedaDocumento predisponiAllaProtocollazione(DocsPaVO.utente.InfoUtente infoUtente,  //string idAmministrazione, string idPeople, string idCorrGlobali, DocsPaVO.documento.SchedaDocumento schedaDoc, string sede)
        /// <summary>
        /// </summary>
        /// <param name="schedaDoc"></param>
        /// <param name="objSicurezza"></param>
        /// <param name="debug"></param>
        /// <returns></returns>
        public static DocsPaVO.documento.SchedaDocumento predisponiAllaProtocollazione(DocsPaVO.utente.InfoUtente infoUtente, DocsPaVO.documento.SchedaDocumento schedaDoc)
        {
            // Verifica stato di consolidamento del documento
            DocumentConsolidation.CanExecuteAction(infoUtente, schedaDoc.systemId, DocumentConsolidation.ConsolidationActionsDeniedEnum.PrepareProtocol, true);

            logger.Debug("predisponiAllaProtocollazione");

            string incestino = string.Empty;

            //controllo se doc in cestino
            incestino = BusinessLogic.Documenti.DocManager.checkdocInCestino(schedaDoc.docNumber);

            if (incestino != "" &&
                incestino == "1")
            {
                throw new Exception("Il documento è stato rimosso, non è più possibile modificarlo");
            }


            DocsPaDocumentale.Documentale.DocumentManager documentManager = new DocsPaDocumentale.Documentale.DocumentManager(infoUtente);
            if (!documentManager.PredisponiProtocollazione(schedaDoc))
            {
                string message = "Non è stato possibile predisporre il documento alla protocollazione";
                logger.Debug(message);
                throw new ApplicationException(message);
            }

            if (schedaDoc.documenti != null &&
                !string.IsNullOrEmpty(((DocsPaVO.documento.Documento)schedaDoc.documenti[0]).dataArrivo))
            {
                string firstParam = "DTA_ARRIVO =" + DocsPaDbManagement.Functions.Functions.ToDate(((DocsPaVO.documento.Documento)schedaDoc.documenti[0]).dataArrivo);
                new DocsPaDB.Query_DocsPAWS.Documenti().UpdateVersions(firstParam, schedaDoc.docNumber);
            }

            return(schedaDoc);
        }
Exemple #8
0
        /// <summary>
        /// Inserimento di un nuovo allegato per un documento
        /// </summary>
        /// <param name="infoUtente"></param>
        /// <param name="allegato"></param>
        /// <param name="debug"></param>
        /// <returns></returns>
        private static DocsPaVO.documento.Allegato aggiungiAllegato(DocsPaVO.utente.InfoUtente infoUtente, DocsPaVO.documento.Allegato allegato, bool statoCongelato)
        {
            using (DocsPaDB.TransactionContext transactionContext = new DocsPaDB.TransactionContext())
            {
                if (allegato.repositoryContext != null)
                {
                    // Inserimento di un allegato nel repositorycontext
                    allegato.version      = "1";                                                                       // Prima versione dell'allegato
                    allegato.versionId    = allegato.position.ToString();                                              // Viene assegnato un nuovo id temporaneo (la sequenza di inserimento)
                    allegato.versionLabel = DocsPaDB.Query_DocsPAWS.Documenti.FormatCodiceAllegato(allegato.position); // Viene creato, in base alla sequenza di inserimento, il codice progressivo

                    // L'allegato viene impostato come non acquisito
                    allegato.subVersion = "!";
                    allegato.fileName   = string.Empty;
                    allegato.fileSize   = "0";
                }
                else
                {
                    if (statoCongelato && allegato.TypeAttachment != 2 && allegato.TypeAttachment != 3)
                    {
                        // Controllo su stato congelato, solo se non si sta creando l'allegato nel repository context
                        DocumentConsolidation.CanExecuteAction(infoUtente,
                                                               allegato.docNumber,
                                                               DocumentConsolidation.ConsolidationActionsDeniedEnum.AddAttatchments, true);
                    }
                    DocsPaDB.Query_DocsPAWS.Documenti doc = new DocsPaDB.Query_DocsPAWS.Documenti();

                    string oldApp  = null;
                    string putfile = "";

                    try
                    {
                        if (allegato.applicazione != null)
                        {
                            if (allegato.applicazione.systemId == null)
                            {
                                allegato.applicazione = BusinessLogic.Documenti.FileManager.getApplicazione(allegato.applicazione.estensione);
                            }

                            logger.Debug("Update della tabella profile");

                            string param = "DOCNUMBER=" + allegato.docNumber;
                            doc.GetApplication(out oldApp, allegato.docNumber, allegato.applicazione.systemId, param);
                        }

                        if (!string.IsNullOrEmpty(allegato.versionLabel))
                        {
                            // L'allegato è già stato creato (ha già la versionLabel),
                            // si sta usando il metodo per fare un'acquisizione sull'allegato
                            putfile = "Y";
                        }

                        DocsPaDocumentale.Documentale.DocumentManager documentManager = new DocsPaDocumentale.Documentale.DocumentManager(infoUtente);
                        //Se l'allegato non è una ricevuta controllo se il doc principale è in libro firma; se il doc principale è in libro firma non è possibile allegare
                        if (allegato.TypeAttachment != 2 && allegato.TypeAttachment != 3 && LibroFirmaManager.IsModificaBloccataPerDocumentoPrincipaleInLF(allegato.docNumber, infoUtente.idAmministrazione))
                        {
                            throw new Exception("Non è possibile creare l'allegato poichè il documento principale è in libro firma");
                        }

                        if (!documentManager.AddAttachment(allegato, putfile))
                        {
                            throw new Exception("Errore nell'inserimento dell'allegato nel documentale");
                        }
                        else
                        {
                            transactionContext.Complete();
                        }
                    }
                    catch (Exception e)
                    {
                        string message = string.Format("Errore nell'inserimento dell'allegato: {0}", e.Message);
                        logger.Debug(message);
                        throw new Exception(message);
                    }
                }
            }

            return(allegato);
        }
Exemple #9
0
        /// <summary>
        /// Aggiunta di un file firmato ad un documento esistente
        /// </summary>
        /// <param name="base64content"></param>
        /// <param name="cofirma"></param>
        /// <param name="fileRequest"></param>
        /// <param name="infoUtente"></param>
        /// <returns></returns>
        private static bool AppendDocumentoFirmato(
            byte[] signedContent,
            bool cofirma,
            ref DocsPaVO.documento.FileRequest fileRequest,
            DocsPaVO.utente.InfoUtente infoUtente, bool isPades, bool isConvertedToPdf = false)
        {
            bool retValue = true;

            DocsPaVO.documento.FileRequest fileRequest_old = (DocsPaVO.documento.FileRequest)fileRequest.Clone();

            try
            {
                if (fileRequest.repositoryContext == null)
                {
                    // Verifica stato di consolidamento del documento, solamente se non si sta firmando nel repository context
                    DocumentConsolidation.CanExecuteAction(infoUtente,
                                                           fileRequest.docNumber,
                                                           DocumentConsolidation.ConsolidationActionsDeniedEnum.SignDocument,
                                                           true);
                }
                //luca
                if (fileRequest != null && !String.IsNullOrEmpty(fileRequest.fileName) && (fileRequest.fileName.ToLower().EndsWith("pdf_convertito") || isConvertedToPdf))
                {
                    fileRequest.fileName = System.IO.Path.GetFileNameWithoutExtension(fileRequest.fileName) + ".pdf";
                    isConvertedToPdf     = true;
                }
                //end luca
                // Verifica se il formato del file è accettato per la firma
                if (!IsFormatSupportedForSign(infoUtente, fileRequest))
                {
                    throw new ApplicationException("Formato file non supportato per la firma");
                }

                DocsPaVO.documento.Applicazione  app     = new DocsPaVO.documento.Applicazione();
                DocsPaVO.documento.FileDocumento fileDoc = new DocsPaVO.documento.FileDocumento();

                fileDoc.content = signedContent;
                fileDoc.length  = fileDoc.content.Length;
                string nomeOriginale = BusinessLogic.Documenti.FileManager.getOriginalFileName(infoUtente, fileRequest);

                if (isPades)
                {
                    // INC000001085991 PITRE - conversione in pdf su firma pades non aggiorna l'estensione
                    // fileDoc.nomeOriginale = nomeOriginale ;
                    if (!string.IsNullOrEmpty(nomeOriginale))
                    {
                        //se il filename finisce PDF probabilmente è stato convertito.
                        //controllo inoltre se il nomeoriginale non finisce con PDF, in tal caso lo popolo.
                        if ((System.IO.Path.GetExtension(fileRequest.fileName).ToUpper() == ".PDF") &&
                            (System.IO.Path.GetExtension(nomeOriginale).ToUpper() != ".PDF") && isConvertedToPdf)
                        {
                            nomeOriginale += ".PDF";
                        }

                        fileDoc.nomeOriginale = nomeOriginale;
                    }

                    fileDoc.estensioneFile = GetAppSuffix(fileRequest.fileName);
                    fileDoc.name           = fileRequest.fileName;
                    app.estensione         = GetAppSuffix(fileRequest.fileName);
                }
                else
                {
                    if (cofirma && System.IO.Path.GetExtension(nomeOriginale).ToUpper().Equals(".P7M"))
                    {
                        app.estensione = GetAppSuffix(fileRequest.fileName);
                        fileDoc.name   = fileRequest.fileName;



                        if (!string.IsNullOrEmpty(nomeOriginale))
                        {
                            //se il filename finisce PDF probabilmente è stato convertito.
                            //controllo inoltre se il nomeoriginale non finisce con PDF, in tal caso lo popolo.
                            if ((System.IO.Path.GetExtension(fileRequest.fileName).ToUpper() == ".PDF") &&
                                (System.IO.Path.GetExtension(nomeOriginale).ToUpper() != ".PDF"))
                            {
                                nomeOriginale += ".PDF";
                            }

                            fileDoc.nomeOriginale = nomeOriginale;
                        }
                        fileDoc.estensioneFile = GetAppSuffix(fileRequest.fileName);
                    }
                    else
                    {
                        app.estensione = GetAppSuffix(fileRequest.fileName + ".P7M");
                        fileDoc.name   = fileRequest.fileName + ".P7M";

                        //luca
                        if (isConvertedToPdf)
                        {
                            //ATTENZIONE, Se un giorno attiveremo la firma pades lato client questo codice non andrà più bene
                            if (!string.IsNullOrEmpty(nomeOriginale))
                            {
                                nomeOriginale = nomeOriginale + ".PDF";
                            }
                        }
                        // end luca
                        if (!string.IsNullOrEmpty(nomeOriginale))
                        {
                            //se il filename finisce PDF probabilmente è stato convertito.
                            //controllo inoltre se il nomeoriginale non finisce con PDF, in tal caso lo popolo.
                            if ((System.IO.Path.GetExtension(fileRequest.fileName).ToUpper() == ".PDF") &&
                                (System.IO.Path.GetExtension(nomeOriginale).ToUpper() != ".PDF"))
                            {
                                nomeOriginale += ".PDF";
                            }

                            fileDoc.nomeOriginale = nomeOriginale + ".P7M";
                        }
                        fileDoc.estensioneFile = GetAppSuffix(fileRequest.fileName + ".p7m");
                    }
                }
                fileDoc.fullName = fileDoc.name;

                bool addNewAttatchment = false;
                bool isAllegato        = (fileRequest.GetType().Equals(typeof(DocsPaVO.documento.Allegato)));

                if (isAllegato && fileRequest.repositoryContext == null)
                {
                    // La firma digitale per l'allegato viene fatta solamente se il documento già esiste su database

                    // Se è attiva la gestione di profilazione degli allegati,
                    // deve essere aggiunta una nuova versione del documento.
                    // Altrimenti, deve essere creato un nuovo allegato.
                    addNewAttatchment = (!BusinessLogic.Documenti.AllegatiManager.isEnabledProfilazioneAllegati());
                }

                if (addNewAttatchment)
                {
                    fileRequest.docNumber   = BusinessLogic.Documenti.AllegatiManager.getIdDocumentoPrincipale((DocsPaVO.documento.Allegato)fileRequest);
                    fileRequest.descrizione = "Versione firmata";
                    fileRequest.cartaceo    = false;
                    fileRequest             = BusinessLogic.Documenti.AllegatiManager.aggiungiAllegato(infoUtente, (DocsPaVO.documento.Allegato)fileRequest);

                    if (fileRequest == null)
                    {
                        throw new ApplicationException("Errore nella creazione dell'allegato firmato per il documento");
                    }
                }
                else
                {
                    fileRequest.applicazione = app;
                    fileRequest.versionId    = "";
                    fileRequest.descrizione  = "Versione firmata";
                    fileRequest.cartaceo     = false;
                    fileRequest = BusinessLogic.Documenti.VersioniManager.addVersion(fileRequest, infoUtente, false);

                    if (fileRequest == null)
                    {
                        throw new ApplicationException("Errore nella creazione della versione firmata per il documento");
                    }

                    bool setDataFirma = BusinessLogic.Documenti.DocManager.SetDataFirmaDocumento(fileRequest.docNumber, fileRequest.versionId);

                    if (!isAllegato)
                    {
                        ((DocsPaVO.documento.Documento)fileRequest).daInviare = "1";
                    }
                }

                //PDZ devo sapere prima di fare la put se è firmato elettronicamente per la gestione tipo firma mista
                List <DocsPaVO.LibroFirma.FirmaElettronica> firmaE = LibroFirma.LibroFirmaManager.GetFirmaElettronicaDaFileRequest(fileRequest_old);
                bool isFirmatoElettonicamente = firmaE != null && firmaE.Count > 0;
                fileRequest.tipoFirma = isFirmatoElettonicamente ? DocsPaVO.documento.TipoFirma.ELETTORNICA : fileRequest.tipoFirma;

                BusinessLogic.Documenti.FileManager.putFile(fileRequest, fileDoc, infoUtente, false);

                //ABBATANGELI GIANLUIGI - FIRMA ELETTRONICA

                if (isFirmatoElettonicamente)
                {
                    string impronta = string.Empty;
                    DocsPaDB.Query_DocsPAWS.Documenti docInfoDB = new DocsPaDB.Query_DocsPAWS.Documenti();
                    docInfoDB.GetImpronta(out impronta, fileRequest.versionId, fileRequest.docNumber);

                    foreach (DocsPaVO.LibroFirma.FirmaElettronica firma in firmaE)
                    {
                        firma.UpdateXml(impronta, fileRequest.versionId, fileRequest.version);
                        LibroFirma.LibroFirmaManager.InserisciFirmaElettronica(firma);
                    }
                }
                //FINE
            }
            catch (Exception e)
            {
                logger.Debug(e.ToString());
                logger.Debug("Errore nella gestione della verifica firma (verificaFirmaMethod)", e);

                retValue = false;
            }

            return(retValue);
        }
Exemple #10
0
        /// <summary>
        /// </summary>
        /// <param name="schedaDoc"></param>
        /// <param name="objSicurezza"></param>
        /// <param name="debug"></param>
        /// <returns></returns>
        public static DocsPaVO.documento.SchedaDocumento save(DocsPaVO.utente.InfoUtente infoUtente, DocsPaVO.documento.SchedaDocumento schedaDoc, bool enableUffRef, out bool daAggiornareUffRef, DocsPaVO.utente.Ruolo ruolo)
        {
            logger.Info("BEGIN");

            //SOSTITUISCO IL CARATTERE SPECIALE
            if (schedaDoc.oggetto.descrizione.Contains("–"))
            {
                schedaDoc.oggetto.descrizione = schedaDoc.oggetto.descrizione.Replace("–", "-");
            }

            // Controllo su stato congelato del documento
            DocumentConsolidation.CanChangeMetadata(infoUtente, schedaDoc, true);

            DocsPaVO.documento.SchedaDocumento savedDocument = null;

            daAggiornareUffRef = false;
            string incestino = string.Empty;

            //controllo se doc in cestino
            incestino = BusinessLogic.Documenti.DocManager.checkdocInCestino(schedaDoc.docNumber);

            if (incestino != "" &&
                incestino == "1")
            {
                throw new Exception("Il documento è stato rimosso, non è più possibile modificarlo");
            }

            //Verifico se il documento è in libro firma e se è prevista la repertoriazione del documento
            #region CHECK_LIBRO_FIRMA
            if (LibroFirma.LibroFirmaManager.IsDocInLibroFirma(schedaDoc.docNumber))
            {
                bool daRepertoriare = false;
                if (schedaDoc.template != null && !string.IsNullOrEmpty(schedaDoc.template.ID_TIPO_ATTO) && schedaDoc.template.ELENCO_OGGETTI != null && schedaDoc.template.ELENCO_OGGETTI.Count > 0)
                {
                    DocsPaVO.ProfilazioneDinamica.OggettoCustom ogg = (from o in schedaDoc.template.ELENCO_OGGETTI.Cast <DocsPaVO.ProfilazioneDinamica.OggettoCustom>()
                                                                       where o.TIPO.DESCRIZIONE_TIPO.Equals("Contatore") && o.REPERTORIO.Equals("1") &&
                                                                       o.CONTATORE_DA_FAR_SCATTARE && string.IsNullOrEmpty(o.VALORE_DATABASE)
                                                                       select o).FirstOrDefault();
                    if (ogg != null && !LibroFirma.LibroFirmaManager.IsTitolarePassoInAttesa(schedaDoc.docNumber, infoUtente, DocsPaVO.LibroFirma.Azione.DOCUMENTO_REPERTORIATO))
                    {
                        throw new Exception("Non è possibile procedere con la repertoriazione poichè il documento è in Libro Firma");
                    }
                }
            }
            #endregion

            // Contesto transazionale
            using (DocsPaDB.TransactionContext transactionContext = new DocsPaDB.TransactionContext())
            {
                if (schedaDoc.repositoryContext != null)
                {
                    // Cerazione del documento grigio se è stata fornita una scheda documento in repository context
                    schedaDoc = addDocGrigia(schedaDoc, infoUtente, ruolo);
                }

                if (schedaDoc.systemId != null && !schedaDoc.systemId.Equals(""))
                {
                    if (schedaDoc.predisponiProtocollazione || (schedaDoc.protocollo != null && (schedaDoc.protocollo.segnatura == null || (schedaDoc.protocollo.segnatura != null && schedaDoc.protocollo.segnatura == "")) && schedaDoc.protocollo.ModUffRef == true && enableUffRef))
                    {
                        savedDocument = predisponiAllaProtocollazione(infoUtente, schedaDoc);
                    }
                    else
                    {
                        savedDocument = salvaModifiche(infoUtente, schedaDoc, enableUffRef, out daAggiornareUffRef);
                    }
                }
                else
                {
                    savedDocument = schedaDoc;
                }

                //Richiamo il metodo per il calcolo della atipicità del documento
                DocsPaDB.Query_DocsPAWS.Documentale documentale = new DocsPaDB.Query_DocsPAWS.Documentale();
                schedaDoc.InfoAtipicita = documentale.CalcolaAtipicita(infoUtente, schedaDoc.docNumber, DocsPaVO.Security.InfoAtipicita.TipoOggettoAtipico.DOCUMENTO);

                if (savedDocument != null)
                {
                    // La transazione viene completata, se le modifiche sono state effettuate correttamente
                    transactionContext.Complete();
                }
            }
            logger.Info("END");
            return(savedDocument);
        }