Ejemplo n.º 1
0
 /// <summary>
 /// Constructor.
 /// Only classes inside of ChaskisCore can create instances of this class directly.
 /// All plugins must use <see cref="ChaskisEventFactory"/>
 /// </summary>
 /// <param name="sourcePlugin">The plugin that generated this event.</param>
 /// <param name="destinationPlugin">
 /// The plugin this event wishes to talk to.
 ///
 /// Null for a "broadcast" (all plugins may listen).
 /// </param>
 internal ChaskisEvent(
     ChaskisEventSource sourceType,
     string sourcePlugin,
     string destinationPlugin,
     IDictionary <string, string> args,
     IDictionary <string, string> passThroughArgs = null
     )
 {
     this.SourceType   = sourceType;
     this.SourcePlugin = sourcePlugin.ToUpper();
     if (destinationPlugin == null)
     {
         this.DestinationPlugin = BroadcastEventStr;
     }
     else
     {
         this.DestinationPlugin = destinationPlugin.ToUpper();
     }
     this.Args            = args;
     this.PassThroughArgs = passThroughArgs;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructor.  Use this to capture a PLUGIN event.
        /// </summary>
        /// <param name="argPattern">
        /// Chaskis events have arguments after the source and plugin.
        /// You can filter events based on its arguments with this parameter
        /// and only capture events whose arguments match this pattern.
        /// </param>
        /// <param name="expectedSource">
        /// The expected source.
        /// </param>
        /// <param name="expectedSourcePlugin">
        /// The expected plugin.
        /// Must be the ToString value of <see cref="ChaskisEventProtocol"/>
        /// if expectedSource is set to <see cref="ChaskisEventSource.CORE"/>.
        /// </param>
        /// <param name="creatorPluginName">The plugin that created this event.</param>
        internal ChaskisEventHandler(
            ChaskisEventSource expectedSource,
            string expectedSourcePlugin,
            string creatorPluginName,
            Action <ChaskisEventHandlerLineActionArgs> lineAction
            )
        {
            if (expectedSource == ChaskisEventSource.CORE)
            {
                if (Enum.TryParse(expectedSourcePlugin, out ChaskisEventProtocol protocol) == false)
                {
                    throw new ArgumentException(
                              "Invalid protocol passed into constructor.  Ensure you want a CORE event. Got: " + expectedSourcePlugin
                              );
                }
            }

            ArgumentChecker.IsNotNull(lineAction, nameof(lineAction));

            this.expectedSource = expectedSource;

            if (expectedSourcePlugin != null)
            {
                this.expectedPlugin = expectedSourcePlugin.ToUpper();
            }
            else
            {
                // Handle events from ALL plugins.
                this.expectedPlugin = null;
            }

            this.creatorPlugin = creatorPluginName.ToUpper();

            this.lineAction   = lineAction;
            this.KeepHandling = true;
        }