I Business Objects di Tustena CRM presentano 8 eventi che permettono di integrare una dll esterna alle logiche di business del CRM.
Attraverso questi eventi, si può interagire direttamente con il
Logic-Tier e accedere ai dati nelle varie
fasi di lavorazione.
Ogni qualvolta un'entità (azienda, contatto, lead, attività, ecc.) viene caricato o salvato, agganciando uno o più di questi eventi, uno sviluppatore può realizzare delle personalizzazioni che agiscono sui dati senza disporre dei sorgenti dell'applicazione.
Elenco eventi:
OnPreLoad - Viene invocato prima del caricamento dell'entità, restituisce l'id dell'oggettoOnLoadComplete - Viene invocato quando l'entità è in memoria, restituisce la classe CrmBusinessObjectsOnPreRuleEngine - Viene invocato prima dell'esecuzione delle Business Rules sull'entità caricata, restituisce la classe CrmBusinessObjects e permette di abortire il salvataggio attraverso il CrmBusinessObjects
portando Abort a false.OnPostRuleEngine - Viene invocato dopo l'esecuzione delle Business Rules sull'entità caricata, restituisce la classe CrmBusinessObjectsOnPreSave - Viene invocato prima di salvare l'oggetto, restituisce la classe CrmBusinessObjects
e permette di abortire il salvataggio attraverso il BusinessObjectEventArgs portando Abort a false.OnSaveComplete - Viene invocato quando l'entità è stata salvata, restituisce la classe CrmBusinessObjectsOnDelete - Viene invocato in caso di cancellazione dell'entità, restituisce un array con gli id degli oggetti cancellatiOnError - Viene invocato quando si verifica un errore, restituisce la classe CrmBusinessObjects
Per attivare questi eventi è necessario quindi creare una dll con NomeDllQualuque.dll ed inserirla all'interno della cartella bin di Tustena.
Successivamente per attivare l'esecuzione di questi eventi bisogna andare nella cartella /EventPlugin/events.xml e modificare la riga xml relativa al BusinessObject al quale si vuole agganciare l'evento.
xml
<?xml version="1.0" encoding="utf-8"?>
<businessObjectsEvents>
<businessObject ID="Company" dllName="EventPlugins.dll" Active="false">
</businessObject>
<businessObject ID="Contact" dllName="EventPlugins.dll" Active="false">
</businessObject>
<businessObject ID="Lead" dllName="EventPlugins.dll" Active="false">
</businessObject>
<businessObject ID="Activity" dllName="NomeDllQualuque.dll" Active="true">
</businessObject>
<businessObject ID="Quote" dllName="EventPlugins.dll" Active="false">
</businessObject>
<businessObject ID="Order" dllName="EventPlugins.dll" Active="false">
</businessObject>
<businessObject ID="DDT" dllName="EventPlugins.dll" Active="false">
</businessObject>
<businessObject ID="Invoice" dllName="EventPlugins.dll" Active="false">
</businessObject>
<businessObject ID="Catalog" dllName="EventPlugins.dll" Active="false">
</businessObject>
<businessObject ID="CatalogMovements" dllName="EventPlugins.dll" Active="false">
</businessObject>
</businessObjectsEvents>
E' anche possibile rinomiare il file events.xml in events.custom.xml, così non verrà sovrascritto con gli aggiornamenti.
qui sotto un esempio di come potrebbe essere scritta la nostra dll di eventi
csharp
using System;
using System.Collections.Generic;
using System.Text;
using Digita.Tustena.Base;
using Digita.Tustena.Core;
using Digita.Tustena.BusinessObjects;
namespace NomeDllQualuque
{
public class NomeDllQualuque: IPlugin
{
#region IPlugin Membri di
public void Init(CrmBusinessObjects bo)
{
bo.OnPreSave += new OnPreSave(bo_OnPreSave);
bo.OnDelete += new OnDelete(bo_OnDelete);
bo.OnLoadComplete += new OnLoadComplete(bo_OnLoadComplete);
}
void bo_OnPreSave(CrmBusinessObjects crmBO, BusinessObjectEventArgs e)
{
switch (crmBO.BusinessObject)
{
case Digita.Tustena.BusinessObjectType.Activity:
throw new NotImplementedException();
break;
}
}
void bo_OnLoadComplete(CrmBusinessObjects crmBO)
{
throw new NotImplementedException();
}
void bo_OnDelete(CrmBusinessObjects crmBO, long[] al, BusinessObjectEventArgs e)
{
throw new NotImplementedException();
}
public ActiveModules RequiredModules
{
get { return ActiveModules.TustenaBase; }
}
#endregion
}
interface IPlugin
{
void Init(CrmBusinessObjects bo);
ActiveModules RequiredModules { get; }
}
}