ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Summary of CRM 2011 plug-in

2019-07-27 23:37:49  阅读:327  来源: 互联网

标签:plug service IPluginExecutionContext ins context execution 2011 CRM


原文链接:http://www.cnblogs.com/Republic/archive/2012/03/27/SummaryOfPlug_In.html

Topic 1: IserviceProvider

Defines:

IServiceProvider Interface: Defines a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.

ServiceProvider Contains:

A container for service objects. Contains references to the plug-in execution context (IPluginExecutionContext), tracing service (ITracingService), organization service (IOrganizationServiceFactory), and notification service (IServiceEndpointNotificationService).

Remarks:

Called by the event execution pipeline during processing of a message request for which the plug-in was registered. For more information, see the IServiceProvider Interface. The notification service is only provided for asynchronous registered plug-ins.

How to use:

//Extract the tracing service for use in debugging sandboxed plug-ins.

ITracingService tracingService =

(ITracingService)serviceProvider.GetService(typeof(ITracingService));





// Obtain the execution context from the service provider.

IPluginExecutionContext context =

(IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));



//IOrganizationServiceFactory

IOrganizationServiceFactory serviceFactory =

(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));



//IServiceEndpointNotificationService

IServiceEndpointNotificationService endPointService =

(IServiceEndpointNotificationService)serviceProvider.GetService(typeof(IServiceEndpointNotificationService));



 

 

Topic 2: ItracingService

 

Function:

Provides a method of logging run-time trace information for plug-ins.

Remarks:

A reference to a tracing service implementation can be obtained from the service provider passed to plug-in’s Execute method.

The ITracingService interface provides a way to log plug-in run-time information. This method of logging information is especially useful for sandboxed plug-ins registered with Microsoft Dynamics CRM Online that cannot otherwise be debugged using a debugger.

The tracing information is displayed in a dialog of the Microsoft Dynamics CRM Web application only if an exception is passed from a plug-in back to the platform

How to use:

//Extract the tracing service for use in debugging sandboxed plug-ins.

ITracingService tracingService =

(ITracingService)serviceProvider.GetService(typeof(ITracingService));

tracingService.Trace("FollowupPlugin begin:");

tracingService.Trace("FollowupPlugin: {0}","Test Tracing Service");

 

How to enable tracing server:

Articles refrences from here: http://support.microsoft.com/kb/907490

How to enable tracing in Microsoft Dynamics CRM

Topic 3: IOrganizationServiceFactory Interface

 

Defines & Functions:

Represents a factory for creating IOrganizationService instances.

Members:

 

Name

Description

                                                                     

CreateOrganizationService

Returns an IOrganizationService   instance for the organization that the specified user is a member of.

 

How to use:

// Obtain the execution context from the service provider.

IPluginExecutionContext context =

(IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));



//IOrganizationServiceFactory

IOrganizationServiceFactory serviceFactory =

(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));



//IServiceEndpointNotificationService

IServiceEndpointNotificationService endPointService =

(IServiceEndpointNotificationService)serviceProvider.GetService(typeof(IServiceEndpointNotificationService));



IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

 

 

Topic 4: IpluginExecutionContext

Function:

Defines the contextual information passed to a plug-in at run-time. Contains information that describes the run-time environment that the plug-in is executing in, information related to the execution pipeline, and entity business information.

Remarks:

The execution context is passed to a plug-in at run time in the System.IServiceProvider parameter of the Execute method. You can obtain the context from the service provider as shown in the following plug-in code.

 

IPluginExecutionContext Members:

 

Name

Description

    

ParentContext

Gets the execution   context from the parent pipeline operation.

    

Stage

Gets the stage in the   execution pipeline that a synchronous plug-in is registered for.

 

How to use:

It contains so many properties,  you can study them by yourself.

 

Topic 5: IServiceEndpointNotificationService Interface

Function:

Posts the plug-in execution context to the Windows Azure platform AppFabric Service Bus.

 

 

Topic 6: How to register a plug-in

 

Plug-in Storage:

Plug-ins not-registered in the sandbox can be stored in the Microsoft Dynamics CRM server's database or the on-disk file system. We strongly recommend that you store your production-ready plug-ins in the Microsoft Dynamics CRM database, instead of on-disk. Plug-ins stored in the database are automatically distributed across multiple Microsoft Dynamics CRM servers in a data center cluster. On-disk storage of plug-ins is useful for debugging plug-ins using Microsoft Visual Studio but is mostly provided for backward compatibility with callouts. You can debug a plug-in that is stored in the database.

Plug-ins registered in the sandbox must be stored in the database regardless of the Microsoft Dynamics CRM deployment (on-premises, IFD/SPLA, or Online).

IExecutionContext.PostEntityImages Property:

Gets the properties of the primary entity after the core platform operation has been completed.

IExecutionContext.PreEntityImages Property:

Gets the properties of the primary entity before the core platform operation has begins.

How to update a plug-in:

  1. End process of w3wp.exe
  2. Disable the services of  sandbox service, asyn service and ..
  3. Use a user as administrator or has the privileges

Topic 7: Sandbox

TOPic 8: Pass data & SharedVariables

Introduce:

The message pipeline model defines a parameter collection of custom data values in the execution context that is passed through the pipeline and shared among registered plug-ins, even from different 3rd party developers. This collection of data can be used by different plug-ins to communicate information between plug-ins and enable chain processing where data processed by one plug-in can be processed by the next plug-in in the sequence and so on. This feature is especially useful in pricing engine scenarios where multiple pricing plug-ins pass data between one another to calculate the total price for a sales order or invoice. Another potential use for this feature is to communicate information between a plug-in registered for a pre-event and a plug-in registered for a post-event.

The name of the parameter that is used for passing information between plug-ins is SharedVariables. This is a collection of key\value pairs. At run time, plug-ins can add, read, or modify properties in the SharedVariables collection. This provides a method of information communication among plug-ins.

How to use & sample code:

/// <summary>
/// A plug-in that sends data to another plug-in through the SharedVariables
/// property of IPluginExecutionContext.
/// </summary>
/// <remarks>Register the PreEventPlugin for a pre-event and the
/// PostEventPlugin plug-in on a post-event.
/// </remarks>
public class PreEventPlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the execution context from the service provider.
Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));

// Create or retrieve some data that will be needed by the post event
// plug-in. You could run a query, create an entity, or perform a calculation.
//In this sample, the data to be passed to the post plug-in is
// represented by a GUID.
Guid contact = new Guid("{74882D5C-381A-4863-A5B9-B8604615C2D0}");

// Pass the data to the post event plug-in in an execution context shared
// variable named PrimaryContact.
context.SharedVariables.Add("PrimaryContact", (Object)contact.ToString());
}
}

public class PostEventPlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the execution context from the service provider.
Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));

// Obtain the contact from the execution context shared variables.
if (context.SharedVariables.Contains("PrimaryContact"))
{
Guid contact =
new Guid((string)context.SharedVariables["PrimaryContact"]);

// Do something with the contact.
}
}
}

 

转载于:https://www.cnblogs.com/Republic/archive/2012/03/27/SummaryOfPlug_In.html

标签:plug,service,IPluginExecutionContext,ins,context,execution,2011,CRM
来源: https://blog.csdn.net/weixin_30667649/article/details/97570610

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有