Пример #1
0
        /// <summary>
        /// Aggiornamento stato di sessione
        /// </summary>
        protected virtual void RefreshState()
        {
            try
            {
                // NB:
                // Importante mantenere l'impostazione a null di questo flag,
                // utilizzato poi dalla pagina "docSalva.aspx".
                // Se lo si toglie, la firma multipla non funziona.
                // Grazie, utilizzo sessione selvaggio!
                UIManager.UserManager.setBoolDocSalva(this, null);

                FirmaDigitaleMng         mng             = new FirmaDigitaleMng();
                DocsPaWR.SchedaDocumento schedaDocumento = mng.GetSchedaDocumento(this.IdDocumento);

                if (schedaDocumento != null)
                {
                    bool consolidated = false;

                    if (((Convert.ToInt32(schedaDocumento.accessRights) > 0) && (Convert.ToInt32(schedaDocumento.accessRights) < 45)))
                    {
                        // Non si posseggono i diritti per firmare il documento (attesa accettazione, stato finale, prot. annullati)
                        throw new ApplicationException("Non si posseggono i diritti per firmare il documento");
                    }

                    if (schedaDocumento.checkOutStatus != null)
                    {
                        // Documento bloccato
                        throw new ApplicationException("Il documento risulta bloccato");
                    }


                    if ((schedaDocumento.protocollo != null) && (schedaDocumento.protocollo.protocolloAnnullato != null))
                    {
                        // Prot. annullato
                        throw new ApplicationException("Il documento risulta annullato");
                    }

                    if (schedaDocumento.ConsolidationState != null &&
                        schedaDocumento.ConsolidationState.State > DocsPaWR.DocumentConsolidationStateEnum.None)
                    {
                        // Il documento risulta consolidato, non può essere firmato digitalmente
                        consolidated = true;
                    }

                    if (consolidated)
                    {
                        throw new ApplicationException("Il documento risulta in stato consolidato");
                    }
                }
                else
                {
                    throw new ApplicationException("Errore nel reperimento dei metadati del documento");
                }

                DocsPaWR.FileRequest fileRequest = null;

                if (schedaDocumento.documenti != null && schedaDocumento.documenti.Length > 0)
                {
                    if (Request.QueryString["fromDoc"] != null && Request.QueryString["fromDoc"].Equals("1"))
                    {
                        //Emanuela 16-04-2014: modifica per consetire la firma anche degli allegati
                        //fileRequest = UIManager.FileManager.getSelectedFile();
                        fileRequest = schedaDocumento.documenti[0];
                        if (UIManager.DocumentManager.getSelectedAttachId() != null)
                        {
                            FileRequest fileReqTemp = FileManager.GetFileRequest(UIManager.DocumentManager.getSelectedAttachId());

                            Allegato a = new Allegato();
                            a.applicazione          = fileRequest.applicazione;
                            a.daAggiornareFirmatari = fileRequest.daAggiornareFirmatari;
                            a.dataInserimento       = fileRequest.dataInserimento;
                            a.descrizione           = fileRequest.descrizione;
                            a.docNumber             = fileRequest.docNumber;
                            a.docServerLoc          = fileRequest.docServerLoc;
                            a.fileName          = fileRequest.fileName;
                            a.fileSize          = fileRequest.fileSize;
                            a.firmatari         = fileRequest.firmatari;
                            a.firmato           = fileRequest.firmato;
                            a.idPeople          = fileRequest.idPeople;
                            a.path              = fileRequest.path;
                            a.subVersion        = fileRequest.version;
                            a.version           = fileRequest.version;
                            a.versionId         = fileRequest.versionId;
                            a.versionLabel      = fileRequest.versionLabel;
                            a.cartaceo          = fileRequest.cartaceo;
                            a.repositoryContext = fileRequest.repositoryContext;
                            a.TypeAttachment    = 1;
                            a.numeroPagine      = (fileReqTemp as Allegato).numeroPagine;

                            if ((fileRequest.fNversionId != null) && (fileRequest.fNversionId != ""))
                            {
                                a.fNversionId = fileRequest.fNversionId;
                            }

                            fileRequest = a;
                        }
                    }
                    else
                    {
                        schedaDocumento = DocumentManager.getDocumentListVersions(this.Page, this.IdDocumento, this.IdDocumento);
                        fileRequest     = schedaDocumento.documenti[0];
                        // fileRequest = schedaDocumento.documenti[0];
                    }

                    int fileSize;
                    Int32.TryParse(fileRequest.fileSize, out fileSize);

                    if (fileSize == 0)
                    {
                        throw new ApplicationException("Nessun file acquisito per il documento");
                    }

                    #region VERIFICA DIMENSIONE MASSIMA FILE
                    int maxDimFileSign = 0;
                    if (!string.IsNullOrEmpty(Utils.InitConfigurationKeys.GetValue(UserManager.GetUserInSession().idAmministrazione, Utils.DBKeys.FE_DO_BIG_FILE_MIN.ToString())) &&
                        !Utils.InitConfigurationKeys.GetValue(UserManager.GetUserInSession().idAmministrazione, Utils.DBKeys.FE_DO_BIG_FILE_MIN.ToString()).Equals("0"))
                    {
                        maxDimFileSign = Convert.ToInt32(Utils.InitConfigurationKeys.GetValue(UserManager.GetUserInSession().idAmministrazione, Utils.DBKeys.FE_DO_BIG_FILE_MIN.ToString()));
                    }
                    if (maxDimFileSign > 0 && Convert.ToInt32(fileSize) > maxDimFileSign)
                    {
                        string maxSize = Convert.ToString(Math.Round((double)maxDimFileSign / 1048576, 3));
                        string msg     = "La dimensione del file supera il limite massimo consentito per la firma. Il limite massimo consentito e' " + maxSize + " Mb";
                        throw new ApplicationException(msg);
                    }
                    #endregion

                    if (string.IsNullOrEmpty(Utils.InitConfigurationKeys.GetValue(UIManager.UserManager.GetInfoUser().idAmministrazione, DBKeys.FE_REQ_CONV_PDF.ToString())) || !Utils.InitConfigurationKeys.GetValue(UIManager.UserManager.GetInfoUser().idAmministrazione, DBKeys.FE_REQ_CONV_PDF.ToString()).Equals("1"))
                    {
                        if (!this.IsFormatSupportedForSign(fileRequest))
                        {
                            throw new ApplicationException("Formato file non ammesso per la firma");
                        }
                    }
                }

                if (fileRequest != null)
                {
                    // Impostazione scheda documento in sessione
                    // NB: Ultima operazione nei controlli

                    //Emanuela 17-04-2014: commentato perchè dal tab allegati alla chiusura della popup, dopo la firma, tornando nel tab profilo, caricava il
                    //profilo dell'allegato
                    //UIManager.DocumentManager.setSelectedRecord(schedaDocumento);

                    // Impostazione metadati file selezionato
                    UIManager.FileManager.setSelectedFile(fileRequest);

                    //ABBATANGELI MASSSIGNATURE HASH

                    bool   cosign    = false;
                    string tipoFirma = this.Request.QueryString["tipoFirma"];
                    if (!string.IsNullOrEmpty(tipoFirma))
                    {
                        if (tipoFirma.ToLower().Equals("cosign"))
                        {
                            cosign = true;
                        }
                    }

                    bool   pades     = false;
                    string tipoPades = this.Request.QueryString["pades"];
                    if (!string.IsNullOrEmpty(tipoPades))
                    {
                        if (tipoPades.ToLower().Equals("true"))
                        {
                            pades = true;
                        }
                    }

                    string extFile     = Path.GetExtension(fileRequest.fileName);
                    bool   isPadesSign = fileRequest.tipoFirma == TipoFirma.PADES || fileRequest.tipoFirma == TipoFirma.PADES_ELETTORNICA;
                    bool   firmato     = (!string.IsNullOrEmpty(fileRequest.firmato) && fileRequest.firmato.Trim() == "1");

                    if (!firmato && cosign)
                    {
                        throw new ApplicationException("Impossibile apporre la firma parallela perche' il file non risulta essere firmato");
                    }

                    if (firmato && extFile.ToUpper() == ".P7M" && pades)
                    {
                        throw new ApplicationException("Impossibile firmare PADES un file firmato CADES");
                    }

                    if (firmato && isPadesSign && !pades && cosign)
                    {
                        throw new ApplicationException("Impossibile cofirmare CADES un file firmato PADES");
                    }

                    NttDataWA.UIManager.FileManager.setMassSignature(fileRequest, cosign, pades, IdDocumento);
                }
                else
                {
                    throw new ApplicationException("Errore nel reperimento dell'ultima versione del documento");
                }
            }
            catch (Exception ex)
            {
                string exMessage = !String.IsNullOrEmpty(ex.Message) && ex.Message.Length < 200 ? ex.Message : "Errore generico";
                //FirmaDigitaleResultManager.SetData(
                //            new FirmaDigitaleResultStatus
                //            {
                //                Status = false,
                //                StatusDescription = exMessage,
                //                IdDocument = this.IdDocumento
                //            }
                //    );
                if (this.Response != null)
                {
                    this.Response.StatusCode = 500;
                    this.Response.Write(exMessage);
                    this.Response.End();
                    this.Response.Flush();
                    //throw new ApplicationException(exMessage);
                }
                //this.Response.StatusCode = -1;
                //this.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                //this.Response.Status = "999";
                //this.Response.StatusDescription = ex.Message;
                //this.Response.End();
                //throw new ApplicationException(ex.Message);

                //DocsPAWA.Logger.log("statusCode = " + this.Response.StatusCode);
                //DocsPAWA.Logger.log("StatusDescription = " + this.Response.StatusDescription);

                //DocsPAWA.Logger.logException(ex);
            }
        }
Пример #2
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            bool   retValue      = false;
            bool   isContent     = false;
            bool   issocket      = false;
            string idDocument    = string.Empty;
            string base64content = string.Empty;

            // Put user code to initialize the page here
            try
            {
                this.startUp();
                this.ErrorPage = "";
                if (Request.QueryString["tipofirma"] != null)
                {
                    if (!Request.QueryString["tipofirma"].Equals(""))
                    {
                        tipofirma = Request.QueryString["tipofirma"];
                    }
                }
                if (tipofirma.Equals("cosign"))
                {
                    firmabool = true;
                }
                else
                {
                    firmabool = false;
                }


                if (Request.QueryString["iscontent"] != null)
                {
                    bool.TryParse(Request.QueryString["iscontent"], out isContent);
                }

                if (Request.QueryString["issocket"] != null)
                {
                    bool.TryParse(Request.QueryString["issocket"], out issocket);
                }

                if (Request.QueryString["idDocumento"] != null)
                {
                    idDocument = Request.QueryString["idDocumento"].ToString();
                }

                byte[] ba = null;

                if (!issocket)
                {
                    ba = Request.BinaryRead(Request.ContentLength);
                }
                else
                {
                    string contentFile = Request["contentFile"];
                    //Stream stream=Request.InputStream;
                    if (!String.IsNullOrEmpty(contentFile))
                    {
                        contentFile = contentFile.Replace(' ', '+');
                        contentFile = contentFile.Trim();
                        NttDataWA.Utils.FileJSON file = JsonConvert.DeserializeObject <NttDataWA.Utils.FileJSON>(contentFile);
                        ba = Convert.FromBase64String(file.content);
                    }
                }
                DocsPaWR.DocsPaWebService DocsPaWS = ProxyManager.GetWS();
                DocsPaWR.FileDocumento    fd       = new NttDataWA.DocsPaWR.FileDocumento();
                //fd.content=ba;

                ASCIIEncoding ae = new ASCIIEncoding();
                if (!isContent)
                {
                    base64content = ae.GetString(ba);
                }

                if (UIManager.UserManager.getBoolDocSalva(this) == null)
                {
                    if (!IsPostBack)
                    {
                        //	string prova=base64content.Replace(base64content.Substring(4,2),"Ds");
                        FileRequest fr = null;
                        DocsPaWR.SchedaDocumento schedaDocumento = null;

                        if (string.IsNullOrEmpty(idDocument))
                        {
                            fr = UIManager.FileManager.getSelectedFile();
                        }
                        else
                        {
                            fr = UIManager.FileManager.getSelectedMassSignature(idDocument).fileRequest;
                            FirmaDigitaleMng mmg = new FirmaDigitaleMng();
                            schedaDocumento = mmg.GetSchedaDocumento(idDocument);
                        }

                        if (!string.IsNullOrEmpty(Request.QueryString["signedAsPdf"]))
                        {
                            // Se il file è in formato pdf, viene modificato il nome del file
                            bool signedAsPdf;
                            bool.TryParse(Request.QueryString["signedAsPdf"], out signedAsPdf);
                            if (signedAsPdf)
                            {
                                fr.fileName += ".PdF_convertito"; //SERVE PER IL BACKEND NON MODIFICARLO!!!
                            }
                        }

                        fr.dataInserimento = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");

                        if (fr.GetType().Equals(typeof(DocsPaWR.Allegato)))
                        {
                            // Creazione di un nuovo allegato per il file firmato
                            DocsPaWR.Allegato currentAllegato = (DocsPaWR.Allegato)fr;

                            DocsPaWR.Allegato newAllegato = new DocsPaWR.Allegato();
                            newAllegato.descrizione       = currentAllegato.descrizione;
                            newAllegato.numeroPagine      = currentAllegato.numeroPagine;
                            newAllegato.fileName          = fr.fileName;
                            newAllegato.firmatari         = currentAllegato.firmatari;
                            newAllegato.docNumber         = currentAllegato.docNumber;
                            newAllegato.version           = "0";
                            newAllegato.cartaceo          = false;
                            newAllegato.repositoryContext = UIManager.DocumentManager.GetSelectedAttachment().repositoryContext;

                            fr = newAllegato;
                        }

                        if (isContent)
                        {
                            retValue = DocsPaWS.AppendContentFirmato(ba, firmabool, ref fr, UIManager.UserManager.GetInfoUser());
                        }
                        else
                        {
                            retValue = DocsPaWS.AppendDocumentoFirmato(base64content, firmabool, ref fr, UIManager.UserManager.GetInfoUser());
                        }

                        if (!retValue)
                        {
                            throw new Exception();
                        }

                        UIManager.FileManager.setSelectedFile(fr);
                        if (schedaDocumento == null)
                        {
                            schedaDocumento = UIManager.DocumentManager.getSelectedRecord();
                        }

                        List <DocsPaWR.Allegato> attachments = new List <DocsPaWR.Allegato>(schedaDocumento.allegati);

                        if (UIManager.DocumentManager.getSelectedAttachId() != null)
                        {
                            //attachments.Add((Allegato)fr);
                            //schedaDocumento.allegati = attachments.ToArray();
                            int      index = schedaDocumento.allegati.Select((item, i) => new { obj = item, index = i }).First(item => item.obj.versionId.Equals(UIManager.DocumentManager.GetSelectedAttachment().versionId)).index;
                            Allegato a     = new Allegato();
                            a.applicazione          = fr.applicazione;
                            a.daAggiornareFirmatari = fr.daAggiornareFirmatari;
                            a.dataInserimento       = fr.dataInserimento;
                            a.descrizione           = fr.descrizione;
                            a.docNumber             = fr.docNumber;
                            a.docServerLoc          = fr.docServerLoc;
                            a.fileName          = fr.fileName;
                            a.fileSize          = fr.fileSize;
                            a.firmatari         = fr.firmatari;
                            a.firmato           = fr.firmato;
                            a.idPeople          = fr.idPeople;
                            a.path              = fr.path;
                            a.subVersion        = fr.version;
                            a.version           = fr.version;
                            a.versionId         = fr.versionId;
                            a.versionLabel      = schedaDocumento.allegati[index].versionLabel;
                            a.cartaceo          = fr.cartaceo;
                            a.repositoryContext = fr.repositoryContext;
                            a.TypeAttachment    = 1;
                            //a.numeroPagine = (fr as Allegato).numeroPagine;
                            // modifica necessaria per FILENET (A.B.)
                            if ((fr.fNversionId != null) && (fr.fNversionId != ""))
                            {
                                a.fNversionId = fr.fNversionId;
                            }
                            schedaDocumento.allegati[index] = a;

                            UIManager.DocumentManager.setSelectedAttachId(fr.versionId);
                            UIManager.DocumentManager.setSelectedNumberVersion(a.version);
                            //schedaDocumento.allegati = UIManager.DocumentManager.AddAttachment((Allegato)fr);
                        }
                        else
                        {
                            //fr = UIManager.DocumentManager.AddVersion(fr, false);
                            schedaDocumento.documenti = UIManager.DocumentManager.addVersion(schedaDocumento.documenti, (Documento)fr);
                            UIManager.DocumentManager.setSelectedNumberVersion(fr.version);
                        }

                        UIManager.DocumentManager.setSelectedRecord(schedaDocumento);
                        UIManager.UserManager.setBoolDocSalva(this, "salvato");
                    }
                }
            }
            catch (Exception es)
            {
                ErrorManager.setError(this, es);
            }
        }