예제 #1
0
        public static bool CheckIn(DocsPaVO.CheckInOut.CheckOutStatus checkOutStatus, byte[] content, string checkInComments, InfoUtente infoUtente)
        {
            bool retValue = false;

            try
            {
                DocsPaUtils.Query queryDef = DocsPaUtils.InitQuery.getInstance().getQuery("CHECKINOUT_CHECKIN_DOCUMENT");
                queryDef.setParam("id", checkOutStatus.ID.ToString());

                string commandText = queryDef.getSQL();
                logger.Debug(commandText);

                using (DocsPaDB.DBProvider dbProvider = new DocsPaDB.DBProvider())
                    retValue = dbProvider.ExecuteNonQuery(commandText);

                if (retValue)
                {
                    // Creazione della versione del documento
                    retValue = CreateDocumentVersion(checkOutStatus, content, checkInComments, infoUtente);
                }
            }
            catch (Exception ex)
            {
                logger.Debug(ex.Message, ex);

                throw new ApplicationException("Errore nel CheckIn del documento. IDDocumento: " + checkOutStatus.IDDocument, ex);
            }

            return(retValue);
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="infoUtente"></param>
        /// <param name="status"></param>
        private static void UndoCheckOut(DocsPaVO.utente.InfoUtente infoUtente, DocsPaVO.CheckInOut.CheckOutStatus status)
        {
            DocsPaVO.Validations.ValidationResultInfo result = BusinessLogic.CheckInOut.CheckInOutServices.UndoCheckOut(status, infoUtente);

            if (!result.Value)
            {
                // Errore nell'undocheckout del documento, viene effettuato un nuovo tentativo
                result = BusinessLogic.CheckInOut.CheckInOutServices.UndoCheckOut(status, infoUtente);
            }

            // Rimozione documento da tabella di conversione
            logger.Debug("Eliminazione documento da DocRichiestaConversionePdf");
            BusinessLogic.Documenti.DocManager.delDocRichiestaConversionePdf(status.IDDocument);
        }
예제 #3
0
        public static bool CreateDocumentVersion(DocsPaVO.CheckInOut.CheckOutStatus checkOutStatus, byte[] checkedOutFileContent, string checkInComments, DocsPaVO.utente.InfoUtente checkOutOwner)
        {
            bool retValue = false;

            DocsPaDB.Query_DocsPAWS.CheckInOut checkInOutDb = new DocsPaDB.Query_DocsPAWS.CheckInOut();

            // Reperimento dell'ultima versione del documento
            FileRequest fileRequest = checkInOutDb.GetFileRequest(checkOutStatus.IDDocument);

            FileDocumento fileDocument = CreateFileDocument(checkOutStatus.DocumentLocation, checkedOutFileContent);

            if (checkInOutDb.IsAcquired(fileRequest))
            {
                // Se per l'ultima versione del documento è stato acquisito un file,
                // viene creata nuova versione per il documento
                fileRequest           = new FileRequest();
                fileRequest.fileName  = checkOutStatus.DocumentLocation;
                fileRequest.docNumber = checkOutStatus.DocumentNumber;

                // Impostazione degli eventuali commenti da aggiungere alla versione
                fileRequest.descrizione = checkInComments;


                retValue = AddVersion(fileRequest, false, checkOutOwner);
            }
            else
            {
                // Se per l'ultima versione del documento non è stato acquisito un file,
                // il file viene acquisito per l'ultima versione
                fileRequest.fileName = fileDocument.fullName;

                // Impostazione degli eventuali commenti da aggiungere alla versione
                fileRequest.descrizione = checkInComments;

                retValue = true;
            }

            if (retValue && fileDocument != null &&
                fileDocument.content != null &&
                fileDocument.content.Length > 0)
            {
                string errore = string.Empty;
                retValue = Documenti.CacheFileManager.PutFile(checkOutOwner, fileRequest, fileDocument, fileDocument.estensioneFile, out errore);
            }

            return(retValue);
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="infoUtente"></param>
        /// <param name="status"></param>
        /// <param name="content"></param>
        /// <param name="checkInComment"></param>
        private static bool CheckIn(DocsPaVO.utente.InfoUtente infoUtente, DocsPaVO.CheckInOut.CheckOutStatus status, byte[] content, string checkInComment)
        {
            DocsPaVO.Validations.ValidationResultInfo result = BusinessLogic.CheckInOut.CheckInOutServices.CheckIn(status, infoUtente, content, checkInComment);

            // Rimozione documento da tabella di conversione
            logger.Debug("Eliminazione documento da DocRichiestaConversionePdf");
            BusinessLogic.Documenti.DocManager.delDocRichiestaConversionePdf(status.IDDocument);

            DocsPaDB.Query_DocsPAWS.CheckInOut checkInOutDb = new DocsPaDB.Query_DocsPAWS.CheckInOut();

            // Reperimento dell'ultima versione del documento
            FileRequest fileRequest = checkInOutDb.GetFileRequest(status.IDDocument);

            BusinessLogic.Documenti.FileManager.processFileInformation(fileRequest, infoUtente);

            return(result.Value);
        }
예제 #5
0
        /// <summary>
        /// Elimina il documento della coda di conversione pdf lato server
        /// </summary>
        /// <returns></returns>
        public static void DequeueServerPdfConversion(string nameDocConvertito, string nameFileXml, byte[] docConvertito, byte[] xml, ref DocsPaVO.utente.InfoUtente infoUser, ref string noteLog, ref DocsPaVO.documento.SchedaDocumento sDoc)
        {
            logger.Debug(
                string.Format("INIZIO: EnqueueServerPdfConversion, nameDocConvertito: '{0}', nameFileXml: '{1}', docConvertiro: '{2}', xml: '{3}'",
                              nameDocConvertito,
                              nameFileXml,
                              (docConvertito != null ? docConvertito.Length.ToString() : "NULL"),
                              (xml != null ? xml.Length.ToString() : "NULL")));

            DocsPaVO.utente.InfoUtente         infoUtente          = null;
            DocsPaVO.documento.SchedaDocumento schedaDocPrincipale = null;

            //string noteGeneraliTrasmissione = string.Empty;
            using (DocsPaDB.TransactionContext transactionContext = new DocsPaDB.TransactionContext())
            {
                try
                {
                    logger.Debug("INIZIO - Lettura file xml di metadati");

                    // 1. Lettura file xml di metadati
                    MemoryStream ms   = new MemoryStream(xml);
                    XmlDocument  xDoc = new XmlDocument();
                    xDoc.Load(ms);
                    XmlNode node = xDoc.DocumentElement;

                    logger.Debug("Creazione infoUtente");
                    //Creazione infoUtente
                    infoUtente     = new DocsPaVO.utente.InfoUtente();
                    infoUtente.dst = node.SelectSingleNode("DST").InnerText.ToString();
                    infoUtente.idAmministrazione = node.SelectSingleNode("ID_AMM").InnerText.ToString();
                    infoUtente.idCorrGlobali     = node.SelectSingleNode("ID_CORR_GLOBALI").InnerText.ToString();
                    infoUtente.idGruppo          = node.SelectSingleNode("ID_GRUPPO").InnerText.ToString();
                    infoUtente.idPeople          = node.SelectSingleNode("ID_PEOPLE").InnerText.ToString();
                    infoUtente.sede   = node.SelectSingleNode("SEDE").InnerText.ToString();
                    infoUtente.urlWA  = node.SelectSingleNode("URLWA").InnerText.ToString();
                    infoUtente.userId = node.SelectSingleNode("USERID").InnerText.ToString();

                    if (node.SelectSingleNode("ID_PEOPLE_DELEGATO") != null && !string.IsNullOrEmpty(node.SelectSingleNode("ID_PEOPLE_DELEGATO").ToString()))
                    {
                        infoUtente.delegato = new DocsPaVO.utente.InfoUtente()
                        {
                            idPeople = node.SelectSingleNode("ID_PEOPLE_DELEGATO").InnerText.ToString()
                        };
                    }
                    infoUser = infoUtente;
                    logger.Debug("Creazione fileRequest");
                    //Creazione FileRequest
                    DocsPaVO.documento.FileRequest fileRequest = new DocsPaVO.documento.FileRequest();
                    fileRequest.autore          = node.SelectSingleNode("AUTORE").InnerText.ToString();
                    fileRequest.dataInserimento = node.SelectSingleNode("DATA_INSERIMENTO").InnerText.ToString();
                    fileRequest.descrizione     = node.SelectSingleNode("DESCRIZIONE").InnerText.ToString();
                    fileRequest.docNumber       = node.SelectSingleNode("DOCNUMBER").InnerText.ToString();

                    string OriginalfileName = null;
                    try
                    {
                        //potrebbe non esistere
                        OriginalfileName = node.SelectSingleNode("ORIGINAL_FILE_NAME").InnerText.ToString();
                    }
                    catch
                    {
                        logger.Debug("ORIGINAL_FILE_NAME non presente");
                    }

                    //Faillace : provo nel caso sia codificato in base 64 (modifica del 4-6-2014)
                    try
                    {
                        if (OriginalfileName != null)
                        {
                            byte[] ofnBytes = Convert.FromBase64String(OriginalfileName);
                            if (ofnBytes != null)
                            {
                                OriginalfileName = System.Text.UTF8Encoding.UTF8.GetString(ofnBytes);
                            }
                        }
                    }
                    catch
                    {
                        // se entro nella catch il filename non è codificato base64, non defo fare nulla perchè il nome file sarà
                        // in chiaro, ma avrà le accentate errate in quanto convertito ascii
                        // se prensente un punto interrogativo (non ammesso nel filename ma introdotto dal convertitore) lo converto in underscore.
                        if (OriginalfileName != null)
                        {
                            OriginalfileName = OriginalfileName.Replace('?', '_');
                        }
                    }

                    logger.Debug("Informazioni documento");
                    //Recupero informazioni del documento
                    string idProfile = node.SelectSingleNode("ID_PROFILE").InnerText.ToString();
                    string docNumber = node.SelectSingleNode("DOCNUMBER").InnerText.ToString();
                    logger.Debug("FINE - Lettura file xml di metadati");

                    // 2. Verifica se il documento è in stato di conversione PDF
                    if (BusinessLogic.Documenti.DocManager.isDocInConversionePdf(idProfile))
                    {
                        // 3. Controllo che il documento in stato di conversione sia in checkout dallo stesso utente
                        logger.Debug("INIZIO - Reperimento dello stato di CheckOut del documento '{0}'");
                        DocsPaVO.CheckInOut.CheckOutStatus statusCheckOut = null;

                        try
                        {
                            statusCheckOut = BusinessLogic.CheckInOut.CheckInOutServices.GetCheckOutStatus(idProfile, docNumber, infoUtente);
                        }
                        catch (Exception ex)
                        {
                            // 3a. Si è verificato un errore nel reperimento delle informazioni di stato del documento nel sistema documentale
                            // In tali frangenti, non è possibile effettuare l'undo checkout nel sistema documentale e la conseguente rimozione del lock di conversione.
                            // Pertanto sarà notificata una trasmissione di fallimento all'utente segnalando, tra le note individuali, che c'è stato un problema
                            // nel sistema documentale e che il documento dovrà essere sbloccato a mano.
                            //noteGeneraliTrasmissione = string.Format("Problemi durante la conversione in PDF per il documento '{0}'. " +
                            //                                         "Sarà necessario sbloccare manualmente il documento e ripetere l'operazione.", idProfile);
                            noteLog = string.Format("Problemi durante la conversione in PDF per il documento '{0}'. " +
                                                    "Sarà necessario sbloccare manualmente il documento e ripetere l'operazione.", idProfile);

                            //throw new ApplicationException(noteGeneraliTrasmissione, ex);
                            throw new ApplicationException(noteLog, ex);
                        }

                        logger.Debug("FINE - Reperimento dello stato di CheckOut del documento '{0}'");

                        if (statusCheckOut != null &&
                            statusCheckOut.DocumentNumber == fileRequest.docNumber &&
                            statusCheckOut.UserName.ToUpper() == infoUtente.userId.ToUpper())
                        {
                            logger.Debug("DocNumber CheckOut : " + statusCheckOut.DocumentNumber);
                            logger.Debug("DocNumber FileRequest : " + fileRequest.docNumber);
                            logger.Debug("IdRole CheckOut : " + statusCheckOut.IDRole);
                            logger.Debug("IdCorrGlobali infoUtente : " + infoUtente.idCorrGlobali);
                            logger.Debug("UserName CheckOut : " + statusCheckOut.UserName);
                            logger.Debug("UserName infoUtente : " + infoUtente.userId);

                            statusCheckOut.DocumentLocation = nameDocConvertito;

                            bool undoCheckOut = false;

                            // Se il parametro "docConvertito" è null allora ci sono stati problemi nella conversione
                            if (docConvertito != null)
                            {
                                // 4. CheckIn del documento
                                if (!CheckIn(infoUtente, statusCheckOut, docConvertito, "Documento convertito in pdf lato server"))
                                {
                                    // 4a. Errore in CheckIn, viene effettuato l'UndoCheckOut
                                    UndoCheckOut(infoUtente, statusCheckOut);
                                    undoCheckOut = true;
                                }
                                else
                                {
                                    if (!String.IsNullOrEmpty(OriginalfileName))
                                    {
                                        //documento convertito, gli rimetto il nome originale
                                        OriginalfileName = System.IO.Path.GetFileNameWithoutExtension(OriginalfileName) + ".pdf";
                                        DocsPaVO.documento.FileRequest fr = (DocsPaVO.documento.FileRequest)BusinessLogic.Documenti.DocManager.getDettaglioNoSecurity(infoUtente, docNumber).documenti[0];
                                        BusinessLogic.Documenti.FileManager.setOriginalFileName(infoUtente, fr, OriginalfileName, true);
                                    }
                                }
                            }
                            else
                            {
                                // 4a. File non convertito, UndoCheckOut del documento
                                UndoCheckOut(infoUtente, statusCheckOut);
                                undoCheckOut = true;
                            }

                            logger.Debug("Recupero scheda documento");

                            DocsPaVO.documento.SchedaDocumento schDoc = null;

                            try
                            {
                                // 5. Reperimento scheda del documento convertito
                                schDoc = BusinessLogic.Documenti.DocManager.getDettaglioNoSecurity(infoUtente, docNumber);
                            }
                            catch (Exception ex)
                            {
                                // Errore nel reperimento del dettaglio del documento
                                logger.Debug(ex);

                                // NB. Nonostante l'errore, il documento è stato correttamente convertito (o meno)
                                // e il checkin (o undocheckout) è stato effettauto correttamente.
                                // Pertanto il reperimento della scheda è ininfluente e come nota generale
                                // viene impostato l'id del documento, senza distinguere se principale o allegato
                                //noteGeneraliTrasmissione = string.Format("Il documento '{0}' è stato convertito in PDF.", docNumber);
                                noteLog = string.Format("Il documento '{0}' è stato convertito in PDF.", docNumber);
                            }

                            if (schDoc != null)
                            {
                                // Verifico se il doc convertito è un allegato
                                bool isAllegato = (schDoc.documentoPrincipale != null);

                                if (isAllegato)
                                {
                                    try
                                    {
                                        // 5a. Reperimento scheda doc principale per l'allegato
                                        schedaDocPrincipale = BusinessLogic.Documenti.DocManager.getDettaglioNoSecurity(
                                            infoUtente,
                                            schDoc.documentoPrincipale.docNumber);
                                    }
                                    catch (Exception ex)
                                    {
                                        // Errore nel reperimento del dettaglio del documento allegato
                                        logger.Debug(ex);
                                    }

                                    if (undoCheckOut)
                                    {
                                        //noteGeneraliTrasmissione = string.Format("Problemi durante la conversione in PDF per l'allegato '{0}'. Ripetere l'operazione.", schDoc.docNumber);
                                        noteLog = string.Format("Problemi durante la conversione in PDF per l'allegato '{0}'. Ripetere l'operazione.", schDoc.docNumber);
                                    }
                                    else
                                    {
                                        // Impostazione note generali di trasmissione
                                        //noteGeneraliTrasmissione = string.Format("Allegato '{0}' convertito in PDF.", schDoc.docNumber);
                                        noteLog = string.Format("Allegato '{0}' convertito in PDF.", schDoc.docNumber);
                                    }
                                }

                                else
                                {
                                    schedaDocPrincipale = schDoc;

                                    // Impostazione note generali di trasmissione
                                    string docName = string.Empty;

                                    if (schedaDocPrincipale.protocollo != null)
                                    {
                                        docName = schedaDocPrincipale.protocollo.segnatura;
                                    }
                                    else
                                    {
                                        docName = schedaDocPrincipale.docNumber;
                                    }

                                    if (undoCheckOut)
                                    {
                                        //noteGeneraliTrasmissione = string.Format("Problemi durante la conversione in PDF per il documento '{0}'. Ripetere l'operazione.", docName);
                                        noteLog = string.Format("Problemi durante la conversione in PDF per il documento '{0}'. Ripetere l'operazione.", docName);
                                    }
                                    else
                                    {
                                        //noteGeneraliTrasmissione = string.Format("Il documento '{0}' è stato convertito in PDF.", docName);
                                        noteLog = string.Format("Il documento '{0}' è stato convertito in PDF.", docName);
                                    }
                                }
                            }
                        }
                        else
                        {
                            logger.Debug(string.Format("Il documento '{0}' non è più bloccato nel sistema documentale per la conversione PDF", idProfile));
                        }
                    }
                    else
                    {
                        logger.Debug(string.Format("Il documento '{0}' non è più in coda di conversione PDF", idProfile));
                    }
                }
                catch (Exception ex)
                {
                    logger.Debug("Errore in BusinessLogic.Documenti.LifeCyclePdfConverter.cs - metodo: DequeueServerPdfConversion", ex);
                }
                finally
                {
                    sDoc = schedaDocPrincipale;
                    //ExecuteTrasmissione(infoUtente, schedaDocPrincipale, noteGeneraliTrasmissione);

                    // 6. Completamento della transazione in ogni caso
                    transactionContext.Complete();

                    logger.Debug(string.Format("FINE: EnqueueServerPdfConversion, nameDocConvertito: '{0}', nameFileXml: '{1}', docConvertiro: '{2}', xml: '{3}'",
                                               nameDocConvertito,
                                               nameFileXml,
                                               (docConvertito != null ? docConvertito.Length.ToString() : "NULL"),
                                               (xml != null ? xml.Length.ToString() : "NULL")));
                    logger.Debug("Tramissione di notifica conversione");
                }
            }
        }
예제 #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="checkOutAdminStatus"></param>
 /// <returns></returns>
 public bool ForceUndoCheckOut(DocsPaVO.CheckInOut.CheckOutStatus checkOutAdminStatus)
 {
     return(this.Instance.ForceUndoCheckOut(checkOutAdminStatus));
 }