Exemple #1
0
 /// <summary>
 /// Asserts that the plugin has only a single registered event, and sets it as the registered event for the context.
 /// </summary>
 /// <param name="plugin"></param>
 /// <returns></returns>
 public PluginExecutionContextBuilder WithRegisteredEvent(IRegisteredEventsPlugin plugin)
 {
     if (!plugin.RegisteredEvents.Any())
     {
         throw new Exception("Plugin " + plugin.GetType().FullName + " does not contain any registered events!  Unable to set the registered event of the context.");
     }
     if (plugin.RegisteredEvents.Skip(1).Any())
     {
         throw new Exception("Plugin " + plugin.GetType().FullName + " contains more than one registered event!  Unable to determine what registered event to use for the context.");
     }
     return(WithRegisteredEvent(plugin.RegisteredEvents.Single()));
 }
Exemple #2
0
 // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
 private void AssertEventFound(IRegisteredEventsPlugin plugin, RegisteredEvent @event, string message)
 {
     if (@event == null)
     {
         throw new Exception($"Plugin {plugin.GetType().FullName} {message}  Unable to set the registered event of the context.");
     }
 }
Exemple #3
0
        /// <summary>
        /// Sets the registered event for the context to the first registered event of the plugin. Throws an exception if more than one event is found.
        /// </summary>
        /// <param name="plugin">The plugin.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">Plugin  + plugin.GetType().FullName +  does not contain any registered events!  Unable to set the registered event of the context.</exception>
        public TDerived WithFirstRegisteredEvent(IRegisteredEventsPlugin plugin)
        {
            if (!plugin.RegisteredEvents.Any())
            {
                throw new Exception("Plugin " + plugin.GetType().FullName + " does not contain any registered events!  Unable to set the registered event of the context.");
            }

            return(WithRegisteredEvent(plugin.RegisteredEvents.Single()));
        }
        public PluginExecutionContextBuilder WithFirstRegisteredEvent(IRegisteredEventsPlugin plugin)
        {
            var first = plugin.RegisteredEvents.FirstOrDefault();

            if (first == null)
            {
                throw new Exception("Plugin " + plugin.GetType().FullName + " does not contain any registered events!  Unable to set the registered event of the context.");
            }

            return(WithRegisteredEvent(first));
        }
Exemple #5
0
        /// <summary>
        /// Sets the registered event for the context to the first registered event of the plugin. Throws an exception if more than one event is found.
        /// </summary>
        /// <param name="plugin">The plugin.</param>
        /// <param name="predicate">Optional predicate based on the RegisteredEvents of the plugin.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">Plugin  + plugin.GetType().FullName +  does not contain any registered events!  Unable to set the registered event of the context.</exception>
        public TDerived WithFirstRegisteredEvent(IRegisteredEventsPlugin plugin, Func <RegisteredEvent, bool> predicate = null)
        {
            var first = predicate == null
                ? plugin.RegisteredEvents.FirstOrDefault()
                : plugin.RegisteredEvents.FirstOrDefault(predicate);

            if (first == null)
            {
                throw new Exception("Plugin " + plugin.GetType().FullName + " does not contain any registered events!  Unable to set the registered event of the context.");
            }

            return(WithRegisteredEvent(first));
        }
 /// <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;
 }