Implement FarmEvents Interface
- Last UpdatedJun 06, 2024
- 2 minute read
Overview
The IFarmEvent Interface exposes four events to capture the Farm Configuration file’s Add/Edit event. This event is triggered when the CentralConfig.xml file is created or edited, before installing the service, and after the services are installed.
The steps mentioned in this section are not mandatory steps. If the user wants to implement IFarmEvents then the user can use the steps mentioned .
CentralConfig.xml file contains database user details and the Farm database connection string details.
Following is the description of event triggers, when a particular method is called:
-
OnCentralConfigFileCreation: When CentralConfig.xml file is created.
-
OnCentralConfigFileEdit: When CentralConfig.xml file is edited.
-
OnServiceInstallationStart: When Service Installation is about to start.
-
OnServiceInstallationComplete: When service installation is completed.
To create a Custom IFarmEvent
-
Create a Custom class library implementing the IFarmEvent.
DLL Reference
Skelta.FarmConfiguration
Workflow.NET.NET2
Sample Code: A sample implementation code is shown below. This code notifies in the logger file after all the events have occurred.
using System;
using System.Collections.Generic;
using System.Text;
using Skelta.Core;
namespace FarmEvents
{
class MyFarmEvents: Skelta.FarmConfiguration.IFarmEvent
{
#region IFarmEventMembers
// Product key should be passed as Empty.
string productKey = "";
public void OnCentralConfigFileCreation(string productKey, Skelta.FarmConfiguration.HandleSkeltaFarm.DatabaseUserCredentials databaseUser, string databaseType, string connectionString)
{
Workflow.NET.Log log = new Workflow.NET.Log();
log.LogInformation("************** In OnCentralConfigFileCreation ***********");
log.Close();
}
public void OnCentralConfigFileEdit(string productKey, Skelta.FarmConfiguration.HandleSkeltaFarm.DatabaseUserCredentials databaseUser, string connectionString, string databaseType, Skelta.FarmConfiguration.HandleSkeltaFarm.EditedConfiguration editedConfiguration)
{
Workflow.NET.Log log = new Workflow.NET.Log();
log.LogInformation("************** In OnCentralConfigFileEdit ***********");
log.Close();
}
public bool OnServiceInstallationComplete(Skelta.FarmManager.ServiceMappingCollection serviceMappings)
{
Workflow.NET.Log log = new Workflow.NET.Log();
log.LogInformation("************** In OnServiceInstallationComplete ***********");
log.Close();
return true;
}
public bool OnServiceInstallationStart(Skelta.FarmManager.ServiceCollection services)
{
Workflow.NET.Log log = new Workflow.NET.Log();
log.LogInformation("************** In OnServiceInstallationStart ***********");
log.Close();
return true;
}
#endregion
#region ISkeltaAddInProvider Members
string _Settings;
Guid _Id;
void ISkeltaAddInProvider.InitializeProvider(string settings, Guid id)
{
this._Settings = settings;
this._Id = id;
}
string ISkeltaAddInProvider.Settings
{
get { return _Settings; }
}
Guid ISkeltaAddInProvider.Id
{
get
{
return _Id;
}
}
#endregion
}
}
-
Compile the class and add the dll in the [AVEVA Work Tasks Installed Path]\AVEVA\Work Tasks\bin folder. After this make an entry in the SKAddInProviders table mentioning the type as IFarmEvent. The name can be anything. The class name and the assembly path should be provided accordingly. The class name should be the name of the Custom Class (Namespace.ClassName).
INSERT INTO SKAddInProviders (Type,[Name],ClassName,[Assembly],Settings,IsGacAssembly) VALUES ('IFarmEvent','EventName','NameSpace.ClassName','bin\<DLLName>.dll','',false)