/// <summary> /// Mapping dell'oggetto /// </summary> /// <param name="logInfo"> /// Dati del log nel sistema documentale /// </param> /// <param name="ev"> /// Dati dell'evento generato /// </param> /// <returns> /// Oggetto dal pubblicare /// </returns> public virtual Subscriber.Proxy.PublishedObject Map(VtDocs.LogInfo logInfo, EventInfo ev) { string section = string.Empty; try { Subscriber.Proxy.PublishedObject retValue = null; this._infoUtente = Security.ImpersonateUser(logInfo); section = "Impersonate"; // Reperimento dati del fascicolo DocsPaVO.fascicolazione.Fascicolo project = this.GetProject(logInfo); section = "GetProject"; if (project != null) { // Mapping dei dati del fascicolo List <Subscriber.Proxy.Property> list = new List <Subscriber.Proxy.Property>(); if (project.apertura != null) { section = "AperturaFascicolo"; list.Add( new Subscriber.Proxy.Property { Name = "AperturaFascicolo", Type = Subscriber.Proxy.PropertyTypesEnum.String, Value = project.apertura, Hidden = true } ); } if (project.chiusura != null) { section = "ChiusuraFascicolo"; list.Add( new Subscriber.Proxy.Property { Name = "ChiusuraFascicolo", Type = Subscriber.Proxy.PropertyTypesEnum.String, Value = project.chiusura, Hidden = true } ); } if (project.noteFascicolo != null) { section = "NoteFascicolo"; if (project.noteFascicolo.Count() > 0) { if (!String.IsNullOrEmpty(project.noteFascicolo.FirstOrDefault().Testo)) { list.Add( new Subscriber.Proxy.Property { Name = "NoteFascicolo", Type = Subscriber.Proxy.PropertyTypesEnum.String, Value = project.noteFascicolo.FirstOrDefault().Testo, Hidden = true } ); } } } section = "CodiceFascicolo"; list.Add( new Subscriber.Proxy.Property { Name = "CodiceFascicolo", Type = Subscriber.Proxy.PropertyTypesEnum.String, Value = project.codice, Hidden = true } ); section = "DataCreazione"; list.Add( new Subscriber.Proxy.Property { Name = "DataCreazione", Type = Subscriber.Proxy.PropertyTypesEnum.String, Value = project.dataCreazione } ); if (project.template != null) { section = "Template"; foreach (DocsPaVO.ProfilazioneDinamica.OggettoCustom field in project.template.ELENCO_OGGETTI) { this.AddProperty(field, list); } } // Reperimento dello stato del fascicolo DocsPaVO.DiagrammaStato.Stato objectState = BusinessLogic.DiagrammiStato.DiagrammiStato.getStatoFasc(project.systemID); if (objectState != null) { section = "IDStato"; list.Add( new Subscriber.Proxy.Property { Name = "IDStato", Type = Subscriber.Proxy.PropertyTypesEnum.Numeric, Value = objectState.SYSTEM_ID, Hidden = true } ); section = "Stato"; list.Add( new Subscriber.Proxy.Property { Name = "Stato", Type = Subscriber.Proxy.PropertyTypesEnum.String, Value = objectState.DESCRIZIONE, Hidden = true } ); } retValue = new Subscriber.Proxy.PublishedObject { IdObject = project.systemID, Description = string.Format("{0} - {1}", project.codice, project.descrizione), ObjectType = "Fascicolo", TemplateName = project.template.DESCRIZIONE, Properties = list.ToArray() }; } section = "Finito"; return(retValue); } catch (Exception ex) { throw new PublisherException(ErrorCodes.UNHANDLED_ERROR, ex.Message + " Section: " + section); } }
/// <summary> /// Notifica evento al SubScriber /// </summary> /// <param name="channelRef"></param> /// <param name="logInfo"></param> /// <param name="obj"></param> /// <returns></returns> protected virtual Subscriber.Proxy.ListenerResponse NotifyEvent(ChannelRefInfo channelRef, VtDocs.LogInfo logInfo, Subscriber.Proxy.PublishedObject obj) { logger.Debug("Start. " + channelRef.ChannelName); Subscriber.Proxy.EventInfo eventInfo = new Subscriber.Proxy.EventInfo { EventName = logInfo.EventCode, EventDate = DateTime.Now, Author = new Subscriber.Proxy.EventAuthorInfo { Name = logInfo.UserName, RoleName = logInfo.RoleDescription }, PublishedObject = obj }; logger.DebugFormat("Eventname: {0}, Eventdate: {1}, Author user: {2}, Role {3}", eventInfo.EventName, eventInfo.EventDate.ToString(), eventInfo.Author.Name, eventInfo.Author.RoleName); Subscriber.Proxy.ListenerResponse response = null; Subscriber.Proxy.ChannelInfo channelInfo = null; using (Subscriber.Proxy.SubscriberWebService subscriber = new Subscriber.Proxy.SubscriberWebService()) { subscriber.Url = channelRef.SubscriberServiceUrl; logger.DebugFormat("Sub Url: {0}. Prelievo canali", subscriber.Url); Subscriber.Proxy.ChannelInfo[] channels = subscriber.GetChannelList(); if (channels != null) { logger.Debug("Channel trovati. N " + channels.Length + ""); for (int i = 0; i < channels.Length; i++) { logger.Debug(channels[i].Name); } channelInfo = channels.Where(e => e.Name == channelRef.ChannelName).First(); if (channelInfo == null) { // Istanza di pubblicazione non trovata nel subscriber collegato logger.Debug("Istanza di pubblicazione non trovata nel subscriber collegato"); throw new PublisherException(ErrorCodes.PUBLISH_CHANNEL_NOT_FOUND, ErrorDescriptions.PUBLISH_CHANNEL_NOT_FOUND); } } logger.Debug("Chiamo il notify Event"); response = subscriber.NotifyEvent( new Subscriber.Proxy.ListenerRequest { ChannelInfo = channelInfo, EventInfo = eventInfo } ); } return(response); }
/// <summary> /// Processo di pubblicazione dei contenuti del canale di pubbliciazione /// </summary> /// <param name="instance"></param> public void Publish(ChannelRefInfo instance) { DateTime actualData = DateTime.Now; logger.Debug("START"); logger.Debug("IDADM: " + instance.Admin.Id); logger.Debug("NOMECANALE: " + instance.ChannelName); //logger.Debug("end ex date: " + instance.EndExecutionDate.ToString()); //logger.Debug("conto esecuzioni: " + instance.ExecutionCount.ToString()); logger.Debug("Id istanza: " + instance.Id.ToString()); //logger.Debug("Ultima esecuzione: "+instance.LastExecutionDate.ToString()); logger.Debug("LastLogId: " + instance.LastLogId.ToString()); logger.Debug("MAchine Name: " + instance.MachineName); logger.Debug("Publisher Url: " + instance.PublisherServiceUrl); int lastLogId = instance.LastLogId; try { if (instance.Events != null && instance.Events.Length > 0) { // Analisi dei singoli eventi foreach (EventInfo ev in instance.Events) { //logger.Debug("presenti degli eventi legati all'istanza"); VtDocs.LogCriteria criteria = new VtDocs.LogCriteria { Admin = instance.Admin, EventName = ev.EventName, FromLogId = instance.LastLogId, ObjectType = ev.ObjectType, ObjectTemplateName = ev.ObjectTemplateName }; logger.DebugFormat("Dati evento: Admin {0}, EventName={1}, fromLogId= {2}, objectType={3}, objTemplName= {4}", instance.Admin, ev.EventName, instance.LastLogId, ev.ObjectType, ev.ObjectTemplateName); IDataMapper mapper = null; // Ricerca delle attività effettuate per l'evento foreach (VtDocs.LogInfo logInfo in VtDocs.LogDataAdapter.GetLogs(criteria)) { //logger.Debug("Trovato un logInfo dalla store procedure"); logger.DebugFormat("{0}, Id: {1}, OD: {2}", logInfo.EventDescription, logInfo.Id, logInfo.ObjectDescription); if (mapper == null) { mapper = new VtDocs.DataMapper(); } //logger.Debug("Prima del mappamento"); // Mapping dell'oggetto documentale nel formato per la pubblicazione Subscriber.Proxy.PublishedObject obj = mapper.Map(logInfo, ev); logger.Debug("Post mappamento. Obj è null? " + (obj == null).ToString()); if (obj != null) { //logger.Debug("obj non è null"); int countComputed = 0; if (!string.IsNullOrEmpty(instance.ChannelName) && instance.ChannelName.ToUpper() == "ALBO_TELEMATICO") { logger.Debug("Gestione albo telematico"); logger.Debug(logInfo.ObjectDescription.ToUpper()); if ((logInfo.ObjectDescription.ToUpper().Contains("DA PUBBLICARE") || logInfo.ObjectDescription.ToUpper().Contains("DA ANNULLARE") || logInfo.ObjectDescription.ToUpper().Contains("DA REVOCARE")) && !logInfo.ObjectDescription.ToUpper().Contains("ERRORE")) { logger.Debug("E' in uno stato che genera notifica ad albo telematico. Chiamo il notifyEvent."); Subscriber.Proxy.ListenerResponse response = this.NotifyEvent(instance, logInfo, obj); countComputed = response.RuleResponseList.Count(e => e.Rule.Computed); } } else { // Notifica evento al SubScriber logger.Debug("Entro nel notify event"); Subscriber.Proxy.ListenerResponse response = this.NotifyEvent(instance, logInfo, obj); countComputed = response.RuleResponseList.Count(e => e.Rule.Computed); } // Reperimento del numero delle regole di pubblicazione processate con esito positivo //int countComputed = response.RuleResponseList.Count(e => e.Rule.Computed); if (countComputed > 0) { logger.Debug("Pubblicazione effettuata"); // Incremento del numero di oggetti pubblicati instance.PublishedObjects++; instance.TotalPublishedObjects++; } else { logger.Debug("Pubblicazione non effettuata"); } } // Viene memorizzato l'id e la data dell'ultimo log analizzato //instance.LastLogId = logInfo.Id; if (logInfo.Id > lastLogId) { lastLogId = logInfo.Id; } instance.StartLogDate = logInfo.Data; } } } } catch (PublisherException pubEx) { logger.Debug(pubEx.Message); SaveError(instance, pubEx); throw pubEx; } catch (Exception ex) { logger.Debug(ex.Message); PublisherException pubEx = new PublisherException(ErrorCodes.UNHANDLED_ERROR, ex.Message); SaveError(instance, pubEx); throw pubEx; } finally { // Viene incrementato il numero delle esecuzioni delle pubblicazioni instance.ExecutionCount++; instance.TotalExecutionCount++; // Impostazione della data dell'ultima esecuzione della regola instance.LastExecutionDate = actualData; // Aggiornamento del last log id avviene alla fine, non durante l'analisi degli eventi. instance.LastLogId = lastLogId; // Aggiornamento dati istanza di pubblicazione instance = DataAccess.PublisherDataAdapter.UpdateExecutionState(instance); } }
/// <summary> /// Mapping dell'oggetto /// </summary> /// <param name="logInfo"> /// Dati del log nel sistema documentale /// </param> /// <param name="ev"> /// Dati dell'evento generato /// </param> /// <returns> /// Oggetto dal pubblicare /// </returns> public virtual Subscriber.Proxy.PublishedObject Map(VtDocs.LogInfo logInfo, EventInfo ev) { try { Subscriber.Proxy.PublishedObject retValue = null; // Reperimento dati del documento DocsPaVO.documento.SchedaDocumento document = this.GetDocument(logInfo); if (document != null) { // Mapping dei dati del fascicolo List <Subscriber.Proxy.Property> list = new List <Subscriber.Proxy.Property>(); if (document.template != null) { foreach (DocsPaVO.ProfilazioneDinamica.OggettoCustom field in document.template.ELENCO_OGGETTI) { Subscriber.Proxy.Property p = this.MapProperty(field); if (p != null) { list.Add(p); } } } // Reperimento dello stato del fascicolo DocsPaVO.DiagrammaStato.Stato objectState = BusinessLogic.DiagrammiStato.DiagrammiStato.getStatoDoc(document.systemId); if (objectState != null) { list.Add( new Subscriber.Proxy.Property { Name = "IDStato", Type = Subscriber.Proxy.PropertyTypesEnum.Numeric, Value = objectState.SYSTEM_ID, Hidden = true } ); list.Add( new Subscriber.Proxy.Property { Name = "Stato", Type = Subscriber.Proxy.PropertyTypesEnum.String, Value = objectState.DESCRIZIONE, Hidden = true } ); } if (ev.LoadFileIfDocumentType) { // Caricamento ultima versione del documento DocsPaVO.documento.FileRequest fr = (DocsPaVO.documento.FileRequest)document.documenti[0]; if (fr.subVersion != "!") { DocsPaVO.documento.FileDocumento file = BusinessLogic.Documenti.FileManager.getFile(fr, Security.ImpersonateUser(logInfo)); if (file != null) { list.Add(new Subscriber.Proxy.Property { Name = "FileName", Type = Subscriber.Proxy.PropertyTypesEnum.String, Value = file.name, Hidden = true }); list.Add(new Subscriber.Proxy.Property { Name = "File", Type = Subscriber.Proxy.PropertyTypesEnum.BinaryContent, BinaryValue = file.content, Hidden = true }); list.Add(new Subscriber.Proxy.Property { Name = "FilePrintThumb", Type = Subscriber.Proxy.PropertyTypesEnum.String, Value = DocsPaUtils.Security.CryptographyManager.CalcolaImpronta(file.content), Hidden = true }); } } //Gestione Allegati if (document.allegati != null) { int attNumber = 0; foreach (DocsPaVO.documento.Allegato allegato in document.allegati) { if (allegato.subVersion != "!") { DocsPaVO.documento.FileDocumento file = BusinessLogic.Documenti.FileManager.getFile((DocsPaVO.documento.FileRequest)allegato, Security.ImpersonateUser(logInfo)); list.Add(new Subscriber.Proxy.Property { Name = String.Format("AttachmentName_{0}", attNumber), Type = Subscriber.Proxy.PropertyTypesEnum.String, Value = file.name, Hidden = true }); list.Add(new Subscriber.Proxy.Property { Name = String.Format("Attachment_{0}", attNumber), Type = Subscriber.Proxy.PropertyTypesEnum.BinaryContent, BinaryValue = file.content, Hidden = true }); list.Add(new Subscriber.Proxy.Property { Name = String.Format("AttachmentPrintThumb_{0}", attNumber), Type = Subscriber.Proxy.PropertyTypesEnum.String, Value = DocsPaUtils.Security.CryptographyManager.CalcolaImpronta(file.content), Hidden = true }); attNumber++; } } } } /* user information that generated the event */ list.Add(new Subscriber.Proxy.Property { Name = "UserName", //UserName utente che ha generato la pubblicazione Type = Subscriber.Proxy.PropertyTypesEnum.String, Value = logInfo.UserName, Hidden = true }); list.Add(new Subscriber.Proxy.Property { Name = "CodeAdm", // codice amministrazione Type = Subscriber.Proxy.PropertyTypesEnum.String, Value = BusinessLogic.Amministrazione.AmministraManager.AmmGetInfoAmmCorrente(logInfo.IdAdmin.ToString()).Codice, Hidden = true }); list.Add(new Subscriber.Proxy.Property { Name = "RoleCode", //codice ruolo Type = Subscriber.Proxy.PropertyTypesEnum.String, Value = logInfo.RoleCode, Hidden = true }); /* end user information*/ string docName = string.Empty; if (document.tipoProto == "G") { docName = string.Format("ID: {0}", document.docNumber); } else if (document.protocollo != null) { docName = string.Format("Segnatura: {0}", document.protocollo.segnatura); } //document.protocollo.segnatura retValue = new Subscriber.Proxy.PublishedObject { IdObject = document.systemId, Description = docName, ObjectType = "Documento", TemplateName = document.template.DESCRIZIONE, Properties = list.ToArray() }; } return(retValue); } catch (Exception ex) { throw new PublisherException(ErrorCodes.UNHANDLED_ERROR, ex.Message); } }