/// <summary>
 /// Initializes the plugin properties.
 /// </summary>
 /// <param name="plugin">The plugin.</param>
 private void InitializePluginProperties(IRegisteredEventsPlugin plugin)
 {
     Event = PluginExecutionContext.GetEvent(plugin.RegisteredEvents);
     if (Event == null)
     {
         var message = $"No RegisteredEvent found for the current context of Stage: {this.GetPipelineStage()}, Message: {MessageName}, Entity: {PrimaryEntityName}.  Either Unregister the plugin for this event, or include this as a RegisteredEvent in the Plugin's RegisteredEvents.";
         try
         {
             TracingService.Trace(message);
             TracingService.Trace(this.GetContextInfo());
         }
         finally
         {
             throw new InvalidPluginExecutionException(message);
         }
     }
     if (Event.Message == RegisteredEvent.Any)
     {
         Event = new RegisteredEvent(Event.Stage, PluginExecutionContext.GetMessageType(), Event.Execute);
     }
     PluginTypeName = plugin.GetType().FullName;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Helper object that stores the services available in this plug-in
        /// </summary>
        /// <param name="serviceProvider">IServiceProvider</param>
        /// <param name="plugin">Plugin handler</param>
        public LocalPluginContext(IServiceProvider serviceProvider, IPluginHandler plugin)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            // Obtain the execution context service from the service provider.
            PluginExecutionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

            // Obtain the tracing service from the service provider.
            TracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            // Get the notification service from the service provider.
            NotificationService = (IServiceEndpointNotificationService)serviceProvider.GetService(typeof(IServiceEndpointNotificationService));

            // Obtain the organization factory service from the service provider.
            _factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

            // Set Event
            Event = PluginExecutionContext.GetEvent(plugin.RegisteredEvents);

            PluginTypeName = plugin.GetType().FullName;
        }