locked
Regarding Plugin RRS feed

  • Question

  • Hi All

    Please can anybody explain this sample Plugin line by line, Thanks in Advance

    IPluginExecutionContext context = (IPluginExecutionContext)
    serviceProvider.GetService(typeof(IPluginExecutionContext));
    
    Entity entity;
    
    if (context.InputParameters.Contains("Target") &&
    context.InputParameters["Target"] is Entity)
    {
    entity = (Entity)context.InputParameters["Target"];
    


    -- Regards shivakumar

    Wednesday, February 15, 2012 7:19 AM

Answers

  • // Obtain the execution context from the service provider.

    1.    IPluginExecutionContext context = (IPluginExecutionContext) serviceProvider.GetService(typeof(IPluginExecutionContext));

    IPluginExecutionContext 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. The context is contained in the System.IServiceProvider parameter that is passed at run-time to a plug-in through its Execute method.

    When a system event is fired for which a plug-in is registered, the system creates and populates the context and passes it to a plug-in through the above mentioned classes and methods. The execution context is passed to each registered plug-in in the pipeline when they are executed. Each plug-in in the execution pipeline is able to modify writable properties in the context. For example, given a plug-in registered for a pre-event and another plug-in registered for a post-event, the post-event plug-in can receive a context that has been modified by the pre-event plug-in. The same situation applies to plug-ins that are registered within the same stage.

    All the properties in IPluginExecutionContext are read-only. However, your plug-in can modify the contents of those properties that are collections. For information on infinite loop prevention, refer to Depth.

    2. Entity entity

    Just defines a entity object

    // The InputParameters collection contains all the data passed in the message request.

    3.     if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { // Obtain the target entity from the input parmameters. Entity entity = (Entity)context.InputParameters["Target"];

    The InputParameters property contains the data that is in the request message currently being processed by the event execution pipeline. Your plug-in code can access this data. The property is of type ParameterCollection where the keys to access the request data are the names of the actual public properties in the request. As an example, take a look at CreateRequest. One property of CreateRequest is named Target which is of type Entity. This is the entity currently being operated upon by the platform. To access the data of the entity you would use the name “Target” as the key in the input parameter collection. You also need to cast the returned instance.

    Similarly, the OutputParameters property contains the data that is in the response message, for example CreateResponse, currently being passed through the event execution pipeline. However, only synchronous post-event and asynchronous registered plug-ins have OutputParameters populated as the response is the result of the core platform operation. The property is of type ParameterCollection where the keys to access the response data are the names of the actual public properties in the response.

    With Regards Mubasher If you find this answer as help ful please vote as helpful and if you find this answer Please Mark It as Answer :)


    Mubasher

    • Proposed as answer by MubasherSharif Wednesday, February 15, 2012 12:50 PM
    • Marked as answer by Shivakumar B Saturday, March 10, 2012 4:24 AM
    Wednesday, February 15, 2012 12:03 PM

All replies

  • hi shiva,

    this will help full Sample plugin


    Anwar noori

    Wednesday, February 15, 2012 9:49 AM
  • Dear Shiva 

        Please find the links below 

        Plugin Development 

        Register your plug-in 

       Understand the Data Context Passed to a Plug-In 

       Pass Data between Plug-Ins 

       Plugin Development in 2011 

       Pre-Image & Post Image in CRM plugin 

      Check out these links... for any help u can ping me  :)


    With Regards Athul MT If you find this answer as help ful please vote as helpful and if you find this answer Please Mark It as Answer :)

    • Proposed as answer by Athul MT Wednesday, February 15, 2012 1:05 PM
    Wednesday, February 15, 2012 10:06 AM
  • // Obtain the execution context from the service provider.

    1.    IPluginExecutionContext context = (IPluginExecutionContext) serviceProvider.GetService(typeof(IPluginExecutionContext));

    IPluginExecutionContext 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. The context is contained in the System.IServiceProvider parameter that is passed at run-time to a plug-in through its Execute method.

    When a system event is fired for which a plug-in is registered, the system creates and populates the context and passes it to a plug-in through the above mentioned classes and methods. The execution context is passed to each registered plug-in in the pipeline when they are executed. Each plug-in in the execution pipeline is able to modify writable properties in the context. For example, given a plug-in registered for a pre-event and another plug-in registered for a post-event, the post-event plug-in can receive a context that has been modified by the pre-event plug-in. The same situation applies to plug-ins that are registered within the same stage.

    All the properties in IPluginExecutionContext are read-only. However, your plug-in can modify the contents of those properties that are collections. For information on infinite loop prevention, refer to Depth.

    2. Entity entity

    Just defines a entity object

    // The InputParameters collection contains all the data passed in the message request.

    3.     if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { // Obtain the target entity from the input parmameters. Entity entity = (Entity)context.InputParameters["Target"];

    The InputParameters property contains the data that is in the request message currently being processed by the event execution pipeline. Your plug-in code can access this data. The property is of type ParameterCollection where the keys to access the request data are the names of the actual public properties in the request. As an example, take a look at CreateRequest. One property of CreateRequest is named Target which is of type Entity. This is the entity currently being operated upon by the platform. To access the data of the entity you would use the name “Target” as the key in the input parameter collection. You also need to cast the returned instance.

    Similarly, the OutputParameters property contains the data that is in the response message, for example CreateResponse, currently being passed through the event execution pipeline. However, only synchronous post-event and asynchronous registered plug-ins have OutputParameters populated as the response is the result of the core platform operation. The property is of type ParameterCollection where the keys to access the response data are the names of the actual public properties in the response.

    With Regards Mubasher If you find this answer as help ful please vote as helpful and if you find this answer Please Mark It as Answer :)


    Mubasher

    • Proposed as answer by MubasherSharif Wednesday, February 15, 2012 12:50 PM
    • Marked as answer by Shivakumar B Saturday, March 10, 2012 4:24 AM
    Wednesday, February 15, 2012 12:03 PM