/// <summary> /// </summary> /// <param name="schedaDoc"></param> /// <param name="session"></param> /// <param name="numDest"></param> /// <param name="destinatari"></param> /// <param name="pathFiles"></param> /// <param name="logger"></param> /// <param name="debug"></param> /// <returns></returns> private static bool creaFax(DocsPaVO.documento.SchedaDocumento schedaDoc, ZfLib.UserSession session, string numDest, System.Collections.ArrayList destinatari, string pathFiles) { try { ZfLib.NewMessage mess = session.CreateNewMsg(); // logger.addMessage("Creazione del messaggio al numero "+numDest); logger.Debug("Creazione del messaggio al numero " + numDest); string bodyFax = "Si trasmette come file allegato il documento e gli eventuali allegati."; bodyFax = bodyFax + "Registro: " + schedaDoc.registro.codRegistro + " "; bodyFax = bodyFax + "Numero di protocollo: " + schedaDoc.protocollo.numero + " "; bodyFax = bodyFax + "Data protocollazione: " + schedaDoc.protocollo.dataProtocollazione + " "; bodyFax = bodyFax + "Segnatura: " + schedaDoc.protocollo.segnatura; mess.Text = bodyFax; string[] files = System.IO.Directory.GetFiles(pathFiles); for (int i = 0; i < files.Length; i++) { if (isValidFile(files[i])) { mess.Attachments.Add(files[i]); // logger.addMessage("Attachment "+files[i]+" inserito"); logger.Debug("Attachment " + files[i] + " inserito"); } else { // logger.addMessage("Attachment "+files[i]+" non valido"); logger.Debug("Attachment " + files[i] + " non valido"); } } ; // logger.addMessage("Creazione stringa destinatari"); logger.Debug("Creazione stringa destinatari"); string dest = ""; for (int j = 0; j < destinatari.Count; j++) { dest = dest + ((DocsPaVO.utente.Corrispondente)destinatari[j]).descrizione + " "; } mess.Recipients.AddFaxRecipient(dest, "", numDest); // logger.addMessage("Messaggio creato"); logger.Debug("Messaggio creato"); mess.Send(); // logger.addMessage("Messaggio inviato"); logger.Debug("Messaggio inviato"); return(true); } catch (Exception e) { // logger.addMessage("Creazione ed invio fax non eseguito. Eccezione: "+e.ToString()); logger.Debug("Creazione ed invio fax non eseguito. Eccezione: " + e.ToString()); return(false); } }
/// <summary> /// /// </summary> /// <param name="serverName"></param> /// <param name="infoUtente"></param> /// <param name="ruolo"></param> /// <param name="registro"></param> /// <param name="faxUserLogin"></param> /// <param name="faxUserCodRubrica"></param> /// <returns></returns> public static int processaCasellaFax(string serverName, DocsPaVO.utente.InfoUtente infoUtente, DocsPaVO.utente.Ruolo ruolo, DocsPaVO.utente.Registro registro, string faxUserLogin, string faxUserCodRubrica) { logger.Debug("processaCasellaFax"); int rtn = 0; try { //si ricava il destinatario della trasmissione DocsPaVO.addressbook.QueryCorrispondente qco = new DocsPaVO.addressbook.QueryCorrispondente(); System.Collections.ArrayList reg = new System.Collections.ArrayList(); reg.Add(registro.systemId); qco.codiceRubrica = faxUserCodRubrica; qco.idAmministrazione = registro.idAmministrazione; qco.idRegistri = reg; qco.getChildren = false; System.Collections.ArrayList corr = BusinessLogic.Utenti.addressBookManager.listaCorrispondentiIntMethod(qco); DocsPaVO.utente.Corrispondente destinatario = (DocsPaVO.utente.Corrispondente)corr[0]; //ACCESSO AL FAX ZfLib.ZfAPI api = new ZfLib.ZfAPI(); logger.Debug("Tentativo di login con " + faxUserLogin); ZfLib.UserSession session = api.Logon(faxUserLogin, false); logger.Debug("Login effettuata al server ZFAX con utenza " + faxUserLogin); ZfLib.ServerInfo sinfo = session.Server.GetServerInfo(); bool msgS = session.Inbox.CheckNewMsgStatus(); logger.Debug("Messaggi trovati bool: " + msgS); logger.Debug("Messaggi trovati: " + session.Inbox.GetMsgList().Count); string path = session.UserInDir; rtn = session.Inbox.GetMsgList().Count; for (int i = 0; i < session.Inbox.GetMsgList().Count; i++) { logger.Debug("Esame messaggio " + i); logger.Debug("Esame messaggio " + path); logger.Debug("Esame messaggio " + destinatario.descrizione); ZfLib.Message mess = session.Inbox.GetMsgList()[i]; processaMessaggio(serverName, path, mess, infoUtente, ruolo, registro, destinatario); //cancellazione messaggio logger.Debug("Esame messaggio inizia cancellazione " + i); mess.DeleteMsg(false); logger.Debug("Esame messaggio finita cancellazione " + i); } return(rtn); } catch (Exception e) { logger.Debug("Errore nella gestione dei fax (processaCasellaFax)", e); throw e; } }
/// <summary> /// Tried to find the Zetafax API in the application cache. /// If it cannot find it it logs on to the Zetafax API as the correct user, /// the stores it in the application cache. /// </summary> protected void InitZfComponents() { string strName = Context.User.Identity.Name; ApplicationLog.WriteInfo("InitZfComponents() for user: " + strName); if (ZetafaxConfiguration.EnablePageCache && ZetafaxConfiguration.APICacheExpiresInMins > 0) { InitZfAPIFromCache(strName); } else { // we aren't caching objects - create new Zetafax ones. CreateZfAPIObject(); zfUserSession = zfAPI.Logon(strName, fExclusive_Logon); } }
/// <summary> /// Function called when a user session object is nuked from the cache. /// Logs off the user. /// </summary> /// <param name="key"></param> /// <param name="val"></param> /// <param name="reason"></param> private static void UserSessionExpiryCallback(string key, object val, CacheItemRemovedReason reason) { try { ZfLib.UserSession zfUserSession = (ZfLib.UserSession)val; // we cannot user "FromName" because this function doesn't run as the Zetafax user, // and therefore may not have permission to access the user's files to read information // such as the user's from name string strUser = zfUserSession.UserInDir; int nEnd = strUser.LastIndexOf('\\', strUser.LastIndexOf('\\') - 1); int nStart = 1 + strUser.LastIndexOf('\\', nEnd - 1); strUser = strUser.Substring(nStart, nEnd - nStart); ApplicationLog.WriteTrace("Cache remove: " + strUser.ToLower()); zfUserSession.Logoff(); } catch (Exception ex) { // this error usually occurs if NT authentication is used to protect the Zetafax // directories and the ASPNET process doesn't have authority to release the LOK file. ApplicationLog.WriteTrace(ApplicationLog.FormatException(ex, "Failed to log off user session")); } }
/// <summary> /// Find the API objects in the cache, or create them if they don't exist. /// <remarks> /// We only need one instance of the API object in the cache, /// but each user has their own session object. /// If the main API object expires, the session objects expire as well /// </remarks> /// <param name="strZfName"> /// The Zetafax user name of the session we wish to retrieve from the cache. /// </param> /// </summary> private void InitZfAPIFromCache(string strZfName) { string strFromName = string.Empty; zfAPI = Cache[CACHE_API] as ZfLib.ZfAPI; zfUserSession = Cache[CACHE_SESSION + "_" + strZfName] as ZfLib.UserSession; try { // proper test to see if object is valid strFromName = zfUserSession.FromName; } catch (Exception) { } if (zfAPI != null && zfUserSession != null && strFromName != string.Empty) { // found in cache - nothing more to do! ApplicationLog.WriteTrace("Cache hit: " + strFromName); return; } ApplicationLog.WriteTrace("Cache miss: " + strZfName); TimeSpan ts = TimeSpan.FromMinutes(ZetafaxConfiguration.APICacheExpiresInMins); if (zfAPI == null) { CreateZfAPIObject(); Cache.Insert(CACHE_API, zfAPI, null, Cache.NoAbsoluteExpiration, ts); } zfUserSession = zfAPI.Logon(strZfName, fExclusive_Logon); ApplicationLog.WriteTrace("Logged on: " + strZfName); Cache.Insert(CACHE_SESSION + "_" + strZfName, zfUserSession, new CacheDependency(null, new string[] { CACHE_API }), Cache.NoAbsoluteExpiration, ts, CacheItemPriority.Normal, new CacheItemRemovedCallback(UserSessionExpiryCallback)); }
/// <summary> /// </summary> /// <param name="infoUtente"></param> /// <param name="reg"></param> /// <param name="schedaDoc"></param> /// <param name="debug"></param> public static void FaxInvioMethod(DocsPaVO.utente.InfoUtente infoUtente, DocsPaVO.utente.Registro reg, DocsPaVO.documento.SchedaDocumento schedaDoc) { DataSet dataSet; try { #region Codice Commentato //db.openConnection(); //si estraggono i campi dalla tabella dei registri /* * string queryString="SELECT A.VAR_CODICE, B.VAR_CODICE_AMM FROM DPA_EL_REGISTRI A, DPA_AMMINISTRA B WHERE A.SYSTEM_ID="+reg.systemId+" AND B.SYSTEM_ID=A.ID_AMM"; * db.fillTable(queryString,dataSet,"REGISTRO"); */ #endregion DocsPaDB.Query_DocsPAWS.Fax obj = new DocsPaDB.Query_DocsPAWS.Fax(); obj.getDataReg(out dataSet, reg); if (dataSet.Tables["REGISTRO"].Rows.Count == 0) { return; } DataRow regRow = dataSet.Tables["REGISTRO"].Rows[0]; //si completa l'oggetto registro reg.codAmministrazione = regRow["VAR_CODICE_AMM"].ToString(); string faxUserLogin = obj.getFaxUsrLogin(infoUtente.idCorrGlobali); if (faxUserLogin == null || faxUserLogin.Equals("")) { // logger.addMessage("Utenza faxserver non trovata"); logger.Debug("Utenza faxserver non trovata"); return; } ZfLib.ZfAPI api = new ZfLib.ZfAPI(); // logger.addMessage("Tentativo di login con "+faxUserLogin); logger.Debug("Tentativo di login con " + faxUserLogin); ZfLib.UserSession session = api.Logon(faxUserLogin, false); // inserimento dei file in una cartella temporanei //string basePathFiles=ConfigurationManager.AppSettings["InteropFilePath"]+"\\Invio_files"; //string pathFiles=basePathFiles+"\\"+regRow["VAR_CODICE"].ToString(); string pathFiles = ConfigurationManager.AppSettings["faxTexp"]; DocsPaUtils.Functions.Functions.CheckEsistenzaDirectory(pathFiles); // logger.addMessage("Estrazione dei file da inviare"); logger.Debug("Estrazione dei file da inviare"); estrazioneFiles(infoUtente, schedaDoc, pathFiles); // logger.addMessage("Estrazione dei destinatari"); logger.Debug("Estrazione dei destinatari"); //si uniscono i destinatari e i destinatari per conoscenza System.Collections.ArrayList dest = new System.Collections.ArrayList(); for (int j = 0; j < ((DocsPaVO.documento.ProtocolloUscita)schedaDoc.protocollo).destinatari.Count; j++) { dest.Add(((DocsPaVO.documento.ProtocolloUscita)schedaDoc.protocollo).destinatari[j]); // logger.addMessage("Aggiunto destinatario"); logger.Debug("Aggiunto destinatario"); } for (int j = 0; j < ((DocsPaVO.documento.ProtocolloUscita)schedaDoc.protocollo).destinatariConoscenza.Count; j++) { dest.Add(((DocsPaVO.documento.ProtocolloUscita)schedaDoc.protocollo).destinatariConoscenza[j]); // logger.addMessage("Aggiunto destinatario per conoscenza"); logger.Debug("Aggiunto destinatario per conoscenza"); } // logger.addMessage("Divisione dei destinatari"); logger.Debug("Divisione dei destinatari"); System.Collections.Hashtable destDivisi = dividiDestinatari(dest); System.Collections.IEnumerator keys = destDivisi.Keys.GetEnumerator(); while (keys.MoveNext()) { //creazione ed invio mail // logger.addMessage("Creazione ed invio del fax al numero "+(string) keys.Current); logger.Debug("Creazione ed invio del fax al numero " + (string)keys.Current); creaFax(schedaDoc, session, (string)keys.Current, (System.Collections.ArrayList)destDivisi[keys.Current], pathFiles); } //cancellazione della directory DocsPaUtils.Functions.Functions.CancellaDirectory(pathFiles); //InteroperabilitaUtils.cancellaDirectory(basePathFiles); } catch (Exception e) { logger.Debug("Errore nella gestione dei fax (FaxInvioMethod)", e); throw e; } }