다음을 통해 공유


플러그 인 간 데이터 전달

 

게시 날짜: 2016년 11월

적용 대상: Dynamics CRM 2015

Microsoft Dynamics 365의 메시지 파이프라인 모델은 파이프라인을 통해 전달되고 다른 타사 개발자들까지 등록된 플러그 인 사이에서 공유되는 실행 컨텍스트에서 사용자 지정 데이터 값의 매개 변수 컬렉션을 정의합니다. 이 데이터 컬렉션은 플러그 인 사이의 정보를 교환하고 한 플러그 인에서 처리되는 데이터를 다음 플러그 인에서 처리하는 식으로 계속 처리할 수 있는 체인 처리를 활성화하기 위해 다른 플러그 인에서 사용할 수 있습니다. 이 기능은 여러 개의 가격 산정 플러그 인 간에 서로 데이터를 전달하여 판매 주문 또는 송장에 대한 총 가격을 계산하는 가격 산정 엔진 시나리오에서 특히 유용합니다. 이 기능은 사전 이벤트에 등록된 플러그 인과 사후 이벤트에 등록된 플러그 인 간에 정보를 교환하는 데도 사용됩니다.

플러그 인 간 정보를 전달하는 데 사용되는 매개 변수 이름은 SharedVariables입니다. 이 매개 변수는 key\value 쌍으로 이루어집니다. 런타임에 플러그 인은 SharedVariables 컬렉션에서 속성을 추가하거나 읽거나 수정할 수 있습니다. 이 플러그 인은 플러그 인 사이의 정보 통신 방법을 제공합니다.

이 샘플에서는 SharedVariables을 사용하여 사전 이벤트 등록 플러그 인에서 사후 이벤트 등록 플러그 인에 데이터를 전달하는 방법을 보여 줍니다.


using System;

// Microsoft Dynamics CRM namespace(s)
using Microsoft.Xrm.Sdk;

namespace Microsoft.Crm.Sdk.Samples
{
    /// <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-operation stage and the 
    /// PostEventPlugin plug-in on a post-operation stage.
    /// </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.
            }
        }
    }
}


' Microsoft Dynamics CRM namespace(s)
Imports Microsoft.Xrm.Sdk

Namespace Microsoft.Crm.Sdk.Samples

    ''' <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-operation stage and the 
    ''' PostEventPlugin plug-in on a post-operation stage.
    ''' </remarks>
    Public Class PreEventPlugin
        Implements IPlugin

        Public Sub Execute(ByVal serviceProvider As IServiceProvider) _
            Implements IPlugin.Execute

            ' Obtain the execution context from the service provider.
            Dim context As Microsoft.Xrm.Sdk.IPluginExecutionContext =
                CType(serviceProvider.GetService(
                        GetType(Microsoft.Xrm.Sdk.IPluginExecutionContext)), 
                    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.
            Dim contact As 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", CType(contact.ToString(),
                                        Object))

        End Sub
    End Class

    Public Class PostEventPlugin
        Implements IPlugin

        Public Sub Execute(ByVal serviceProvider As IServiceProvider) _
            Implements IPlugin.Execute

            ' Obtain the execution context from the service provider.
            Dim context As Microsoft.Xrm.Sdk.IPluginExecutionContext =
                CType(serviceProvider.GetService(
                        GetType(Microsoft.Xrm.Sdk.IPluginExecutionContext)), 
                    Microsoft.Xrm.Sdk.IPluginExecutionContext)

            ' Obtain the contact from the execution context shared variables.
            If context.SharedVariables.Contains("PrimaryContact") Then

                Dim contact As New Guid(CStr(context.SharedVariables("PrimaryContact")))

                ' Do something with the contact.

            End If

        End Sub
    End Class

End Namespace

공유 변수 컬렉션에 추가된 모든 데이터 유형은 직렬화할 수 있습니다. 그렇지 않으면 서버에서 데이터를 직렬화하는 방법을 몰라 플러그 인이 실행되지 못합니다.

스테이지 20 또는 40에 등록된 플러그 인의 경우 만들기, 업데이트, 삭제 또는 RetrieveExchangeRateRequest에 의해 스테이지 10에 등록된 플러그 인에서 공유 변수에 액세스하려면 ParentContext.SharedVariables 컬렉션에 액세스해야 합니다. 다른 모든 경우 IPluginExecutionContext.SharedVariables에는 컬렉션이 있습니다.

참고 항목

IPluginExecutionContext
플러그 인 개발
플러그 인의 가장
이벤트 실행 파이프라인

© 2017 Microsoft. All rights reserved. 저작권 정보