예제 #1
0
        /// <summary>
        /// Creates an instance of EventMap.
        /// </summary>
        /// <param name="applicationInstanceIdentity">An instance of IApplicationInstanceIdentity
        /// uniquely identifying the current application instance.</param>
        /// <param name="relayProvider">The underlying transport for the incoming and
        /// outgoing messages. This could be SignalR, and IoT Hub or some type of notification framework.</param>
        /// <param name="eventTarget">A PubSubEvent instance representing the event to be mapped.</param>
        /// <param name="inboundTransformAction">A TransformArgumentDelegate method used to transform the
        /// event arguments before being routed inbound.</param>
        /// <param name="shouldRouteInbound">A ShouldRouteEventDelegate method that determines if the event
        /// should be routed. Note this method is called prior to the transformation.</param>
        /// <param name="outboundTransformAction">A TransformArgumentDelegate method used to transform the
        /// event arguments before being routed outbound.</param>
        /// <param name="shouldRouteOutbound">A ShouldRouteEventDelegate method that determines if the event
        /// should be routed. Note this method is called prior to the transformation.</param>
        public EventRelayMap(IApplicationInstanceIdentity applicationInstanceIdentity,
                             IRelayProviderSender <T> relayProviderSender,
                             IRelayProviderReceiver <T> relayProviderReceiver,
                             PubSubEvent <T> eventTarget,
                             TransformArgumentDelegate <T> inboundTransformAction, ShouldRouteEventDelegate <T> shouldRouteInbound,
                             TransformArgumentDelegate <T> outboundTransformAction, ShouldRouteEventDelegate <T> shouldRouteOutbound)
        {
            this.ApplicationInstanceIdentity = applicationInstanceIdentity;
            this.Event = eventTarget;
            this.InboundTransformAction  = inboundTransformAction;
            this.ShouldRouteInbound      = shouldRouteInbound;
            this.OutboundTransformAction = outboundTransformAction;
            this.ShouldRouteOutbound     = shouldRouteOutbound;
            this.RelayProviderSender     = relayProviderSender;
            this.RelayProviderReceiver   = relayProviderReceiver;

            // ***
            // *** Links an inbound event from the IRelayProvider
            // *** to the external Publish/Subscribe event system.
            // ***
            string eventName = string.Format("On{0}", this.Event.GetType().Name);

            this.RelayProviderReceiver?.SetCallback(eventName, this.OnProcessInboundMessage);

            // ***
            // *** Setup to receive inbound messages and processes them.
            // ***
            _subscriptionToken = this.Event.Subscribe((e) => { this.OnProcessOutboundMessage(e); });
        }
예제 #2
0
        /// <summary>
        /// CLeans up the internal objects.
        /// </summary>
        public void Dispose()
        {
            // ***
            // *** Unsubscribe from the event.
            // ***
            if (_subscriptionToken != null)
            {
                this.Event.Unsubscribe(this._subscriptionToken);
                _subscriptionToken.Dispose();
                _subscriptionToken = null;
            }

            // ***
            // *** Release the RelayProviderSender object.
            // ***
            if (this.RelayProviderSender != null)
            {
                this.RelayProviderSender.Dispose();
                this.RelayProviderSender = null;
            }

            // ***
            // *** Release the RelayProviderReceiver object.
            // ***
            if (this.RelayProviderReceiver != null)
            {
                this.RelayProviderReceiver.Dispose();
                this.RelayProviderReceiver = null;
            }
        }