namespace <%= client %>.<%= package %>.BusinessLogic
{
using System;
using <%= client %>.<%= package %>.BusinessLogic.Logging;
using Microsoft.Xrm.Sdk;
///
/// Dynamics 365 plugin.
///
public abstract class Plugin : IPlugin
{
///
/// Initializes a new instance of the class.
///
public Plugin()
: base()
{
}
///
/// Initializes a new instance of the class.
///
/// The unsecure configuration.
/// The secure configuration.
public Plugin(string unsecureConfig, string secureConfig)
: this()
{
this.UnsecureConfig = unsecureConfig;
this.SecureConfig = secureConfig;
}
///
/// Gets the plugin step's unsecure configuration.
///
protected string UnsecureConfig { get; private set; }
///
/// Gets the plugin step's secure configuration.
///
protected string SecureConfig { get; private set; }
///
public void Execute(IServiceProvider serviceProvider)
{
var tracingSvc = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var orgSvc = serviceFactory.CreateOrganizationService(Guid.Empty);
var repositoryFactory = new RepositoryFactory(orgSvc);
var logWriter = new TracingServiceLogWriter(tracingSvc, true);
this.Execute(context, orgSvc, logWriter, repositoryFactory);
}
///
/// Execute the plugin.
///
/// The plugin execution context.
/// The organization service.
/// The log writer.
/// The repository factory.
protected abstract void Execute(IPluginExecutionContext context, IOrganizationService orgSvc, TracingServiceLogWriter logWriter, RepositoryFactory repositoryFactory);
}
}