private void InviaInConservazione(string idProfile, string idAmm) { try { Conservazione.ConservazioneManager cons = new Conservazione.ConservazioneManager(); cons.ExecuteVersamentoSingolo(idProfile, idAmm, true); } catch (Exception ex) { logger.Debug("Errore non gestito nel processo di invio in conservazione della stampa: {0}", ex); } }
private static string InviaASdi(DocsPaVO.utente.InfoUtente infoUtente, string docnumber, string diagramId, string codEsecutore) { logger.Debug("BEGIN"); string retVal = "-1"; string identificativo_Invio = string.Empty; string dbKey = (DocsPaUtils.Configuration.InitConfigurationKeys.GetValue("0", "BE_SDI_VIA_PEC")); string autoSign = (DocsPaUtils.Configuration.InitConfigurationKeys.GetValue("0", "BE_FIRMA_AUTOMATICA_HSM")); bool PEC_ENABLED = (string.IsNullOrEmpty(dbKey) || dbKey == "0"?false:true); bool automaticHsmSignature = (!string.IsNullOrEmpty(autoSign) && autoSign == "1"); if (PEC_ENABLED) { logger.Debug("INVIO PEC: ATTIVO"); } else { logger.Debug("INVIO PEC: NON ATTIVO"); } if (automaticHsmSignature) { logger.Debug("FIRMA HSM AUTOMATICA: ATTIVA"); } else { logger.Debug("FIRMA HSM AUTOMATICA: NON ATTIVA"); } try { string fileNameSdi = getNomeSDI(codEsecutore, docnumber); DocsPaVO.documento.SchedaDocumento schedaDoc = Documenti.DocManager.getDettaglioNoSecurity(infoUtente, docnumber); DocsPaVO.documento.FileRequest docPrincipale = (DocsPaVO.documento.FileRequest)schedaDoc.documenti[0]; //DocsPaVO.documento.FileDocumento fileDoc = Documenti.FileManager.getFile(docPrincipale, infoUtente); DocsPaVO.documento.FileDocumento fileDoc = Documenti.FileManager.getFileFirmato(docPrincipale, infoUtente, false); string nomeOld = fileDoc.name; string extOriginalName = System.IO.Path.GetExtension(fileDoc.nomeOriginale).ToLower(); fileDoc.nomeOriginale = fileNameSdi + ".xml"; if (!extOriginalName.ToUpper().Equals("XML") && !extOriginalName.ToUpper().Equals(".XML")) { fileDoc.nomeOriginale += extOriginalName; } fileDoc.name = fileDoc.nomeOriginale; logger.Debug("FILENAME: " + fileDoc.name); bool prosegui = true; if (automaticHsmSignature) { #region OLD CODE //prosegui = docPrincipale.firmato.Equals("1"); #endregion // Gabriele Melini 28-02-2017 // Prima dell'invio a SDI se il file non è firmato devo firmarlo utilizzando il servizio // di firma HSM automatica if (!docPrincipale.firmato.Equals("1")) { Documenti.FileManager.setOriginalFileName(infoUtente, docPrincipale, fileDoc.nomeOriginale, true); logger.Debug("FILE DA FIRMARE"); string rootPath = DocsPaUtils.Configuration.InitConfigurationKeys.GetValue("0", "BE_TEMP_PATH"); string inputPath = System.IO.Path.Combine(rootPath, string.Format(@"SignXML\Input\{0}\{1}", docPrincipale.versionId, fileDoc.nomeOriginale)); string outputPath = System.IO.Path.Combine(rootPath, string.Format(@"SignXML\Output\{0}\{1}.P7M", docPrincipale.versionId, fileDoc.nomeOriginale)); if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(inputPath))) { System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(inputPath)); } if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(outputPath))) { System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath)); } // Al momento il firmatario coincide con l'utente responsabile della conservazione // in futuro andrebbe gestito un po' meglio Conservazione.ConservazioneManager cman = new Conservazione.ConservazioneManager(); string idUtente = cman.GetIdUtenteRespConservazione(infoUtente.idAmministrazione); string idRuolo = cman.GetIdRuoloRespConservazione(infoUtente.idAmministrazione); if (string.IsNullOrEmpty(idUtente) || string.IsNullOrEmpty(idRuolo)) { prosegui = false; } else { DocsPaVO.utente.InfoUtente signer = new DocsPaVO.utente.InfoUtente(); DocsPaVO.utente.Utente u = BusinessLogic.Utenti.UserManager.getUtenteById(idUtente); DocsPaVO.utente.Ruolo r = BusinessLogic.Utenti.UserManager.getRuoloByIdGruppo(idRuolo); signer = BusinessLogic.Utenti.UserManager.GetInfoUtente(u, r); if (signer.dst == null) { signer.dst = BusinessLogic.Utenti.UserManager.getSuperUserAuthenticationToken(); } // Scrivo su file system il file da firmare System.IO.File.WriteAllBytes(inputPath, fileDoc.content); // Chiamo il servizio di firma automatica byte[] signedContent = Documenti.FileManager.HSM_AutomaticSignature(signer, inputPath, outputPath, false); if (signedContent != null) { logger.Debug("signed content length: " + signedContent.Length); // Rimuovo il file dal path temporaneo try { if (System.IO.File.Exists(inputPath)) { System.IO.File.Delete(inputPath); } } catch (Exception exc) { logger.ErrorFormat("Rimozione file temporanei non riuscita: {0}", exc.Message); } // Aggiungo la versione prosegui = Documenti.SignedFileManager.AppendDocumentoFirmato(signedContent, false, ref docPrincipale, infoUtente); if (prosegui) { // Ricarico il file firmato schedaDoc = Documenti.DocManager.getDettaglioNoSecurity(infoUtente, docnumber); fileDoc = BusinessLogic.Documenti.FileManager.getFileFirmato((DocsPaVO.documento.FileRequest)schedaDoc.documenti[0], infoUtente, false); fileDoc.name = fileDoc.nomeOriginale; logger.Debug("FILENAME: " + fileDoc.name); } } else { logger.Debug("Firma automatica non riuscita!"); prosegui = false; } } } } if (docPrincipale != null && prosegui) { logger.Debug("INVIO A SDI"); identificativo_Invio = SdiConnector.Connector.SendFileToSdi(fileDoc); logger.Debug("RESULT: " + identificativo_Invio); if (PEC_ENABLED) { //if (!string.IsNullOrEmpty(identificativo_Invio)) //if (string.IsNullOrEmpty(identificativo_Invio)) //{ logger.Debug("INVIO VIA PEC"); string retvalPec = SdiConnector.Connector.SendFileToSdiViaPec(fileDoc, docnumber); logger.Debug("RESULT: " + retvalPec); string[] pecResp = retvalPec.Split(':'); if (pecResp[0].ToLower() == "false") { // se va in errore annullo l'identificativo invio identificativo_Invio = string.Empty; } //} } fileDoc.name = nomeOld; if (!string.IsNullOrEmpty(identificativo_Invio)) { addNota(infoUtente, schedaDoc, fileNameSdi); Documenti.FileManager.setOriginalFileName(infoUtente, docPrincipale, fileDoc.nomeOriginale, true); if (Fatturazione.FatturazioneManager.PutProfileFattura(docnumber, identificativo_Invio, diagramId)) { retVal = "1"; } else { retVal = "0"; } } else { retVal = "-2"; } } else { retVal = "-3"; } } catch (Exception ex) { retVal = "-1"; } return(retVal); }
/// <summary> /// /// </summary> /// <param name="counterId"></param> /// <param name="registryId"></param> /// <param name="rfId"></param> /// <param name="userInfo"></param> /// <param name="role"></param> /// <param name="year"></param> /// <param name="lastPrintedNumber"></param> /// <param name="lastNumberToPrint"></param> public void GeneratePrint(String counterId, String registryId, String rfId, InfoUtente userInfo, Ruolo role, String year, String lastPrintedNumber, String lastNumberToPrint) { RegistriRepertorioPrintManager manager = new RegistriRepertorioPrintManager(); // Generazione filtri per la stampa List <FiltroRicerca> filters = new List <FiltroRicerca>() { new FiltroRicerca() { argomento = "idCounter", valore = counterId }, new FiltroRicerca() { argomento = "idRegistry", valore = registryId }, new FiltroRicerca() { argomento = "idRf", valore = rfId }, new FiltroRicerca() { argomento = "year", valore = year }, new FiltroRicerca() { argomento = "lastPrintedNumber", valore = lastPrintedNumber }, new FiltroRicerca() { argomento = "lastNumberToPrint", valore = lastNumberToPrint } }; // Creazione della stampa FileDocumento fileDocument = BusinessLogic.Reporting.ReportGeneratorCommand.GetReport( new DocsPaVO.Report.PrintReportRequest() { UserInfo = userInfo, SearchFilters = filters, ReportType = DocsPaVO.Report.ReportTypeEnum.PDF, ReportKey = "StampaRegistriRepertori", ContextName = "StampaRegistriRepertori", AdditionalInformation = String.Format("Stampa del repertorio per l'anno {0} dal n. {1} al n. {2}", year, Convert.ToInt32(lastPrintedNumber), lastNumberToPrint) }).Document; // Apertura di un contesto transazionale using (DocsPaDB.TransactionContext transactionContext = new DocsPaDB.TransactionContext()) { if (userInfo != null && string.IsNullOrEmpty(userInfo.dst)) { userInfo.dst = BusinessLogic.Utenti.UserManager.getSuperUserAuthenticationToken(); } // Reperimento del nome della tipologia string tipologia = manager.GetNomeTipologia(counterId); // Creazione della scheda documento SchedaDocumento document = InitializeDocument(userInfo, registryId, rfId, year, lastPrintedNumber, lastNumberToPrint, tipologia); Ruolo[] roles = new Ruolo[] { }; // Salvataggio del documento String docNumber = this.SaveDocument(userInfo, role, document, fileDocument, out roles); if (String.IsNullOrEmpty(docNumber)) { throw new Exception("Errore durante la creazione della stampa"); } // Aggiornamento del registro delle stampe e del prossimo numero da stampare if (!manager.UpdatePrinterManager(counterId, lastPrintedNumber, lastNumberToPrint, docNumber, registryId, rfId, year)) { throw new Exception("Errore durante l'aggiornamento dell'anagrafica delle stampe effettuate"); } int rights = 0; // Assegnazione della visibilità della stampa al responsabile di repertorio (se impostato) if (!BusinessLogic.utenti.RegistriRepertorioPrintManager.AssignDocumentVisibilityToResponsable(userInfo, docNumber, counterId, rfId, registryId, out rights)) { throw new Exception("Errore assegnazione visiblità a ruolo responsabile"); } // Se ci sono ruoli superiori, viene assegnata la visibilità foreach (Ruolo r in roles) { if (!BusinessLogic.utenti.RegistriRepertorioPrintManager.AssignDocumentVisibilityToRole(userInfo, docNumber, counterId, rfId, registryId, r.idGruppo, rights)) { throw new Exception(String.Format("Errore assegnazione visiblità al ruolo {0}", r.codice)); } } //assegnazione visibilità nel caso di repertori di tipologia/RF if ((string.IsNullOrEmpty(rfId) && string.IsNullOrEmpty(registryId)) || (!string.IsNullOrEmpty(rfId))) { DocsPaDB.Utils.Gerarchia gerarchia = new DocsPaDB.Utils.Gerarchia(); object[] supRolePrinter = gerarchia.getGerarchiaSup(role, ((DocsPaVO.utente.Registro)role.registri[0]).systemId, null, DocsPaVO.trasmissione.TipoOggetto.DOCUMENTO).ToArray(); foreach (Ruolo r in supRolePrinter) { if (!BusinessLogic.utenti.RegistriRepertorioPrintManager.AssignDocumentVisibilityToRole(userInfo, docNumber, counterId, rfId, registryId, r.idGruppo, rights)) { throw new Exception(String.Format("Errore assegnazione visiblità al ruolo {0}", r.codice)); } } } // Invio in conservazione Conservazione.ConservazioneManager cons = new Conservazione.ConservazioneManager(); if (cons.GetStatoAttivazione(userInfo.idAmministrazione) && this.IsStampaRepDaConservare(counterId)) { this.InviaInConservazione(docNumber, userInfo.idAmministrazione); } // Completamento transazione transactionContext.Complete(); } }