using System;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
namespace Microsoft.Crm.Sdk.Samples
{
public class SamplePlugin: IPlugin
{
// Basic Constructor with out any parameters
public SamplePlugin(){
// do logic
}
// Basic Constructor with one parameters,the 1st parameter is the unsecure value
public SamplePlugin(string unsecure){
// do logic
}
// Basic Constructor with one parameters,the 1st parameter is the unsecure value and the 2nd is the secure
public SamplePlugin(string unsecure, string secure){
// do logic
}
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the execution context from the service provider.
IPluginExecutionContext context =
(IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
// Get a reference to the organization service.
IOrganizationServiceFactory factory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
// Get a reference to the tracing service.
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
try
{
// Plug-in business logic goes below this line.
// Invoke organization service methods.
}
catch (FaultException<OrganizationServiceFault> ex)
{
// Handle the exception.
}
}
}
}
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
namespace Microsoft.Crm.Sdk.Samples
{
public class SamplePlugin: IPlugin
{
// Basic Constructor with out any parameters
public SamplePlugin(){
// do logic
}
// Basic Constructor with one parameters,the 1st parameter is the unsecure value
public SamplePlugin(string unsecure){
// do logic
}
// Basic Constructor with one parameters,the 1st parameter is the unsecure value and the 2nd is the secure
public SamplePlugin(string unsecure, string secure){
// do logic
}
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the execution context from the service provider.
IPluginExecutionContext context =
(IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
// Get a reference to the organization service.
IOrganizationServiceFactory factory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
// Get a reference to the tracing service.
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
try
{
// Plug-in business logic goes below this line.
// Invoke organization service methods.
}
catch (FaultException<OrganizationServiceFault> ex)
{
// Handle the exception.
}
}
}
}
your blog post has been copied
ReplyDeletehttp://srikanthcrm.wordpress.com/2012/02/14/writing-a-basic-plug-in-in-ms-crm-2011/