public virtual void Release(IMessagingChannel channel, int token)
        {
            if (channel == null)
            {
                throw new ArgumentNullException("channel");
            }

            Log.Verbose("Trying to release the channel back to the pool for reuse.");

            bool value;

            if (!this.open.TryRemove(channel, out value))
            {
                throw new InvalidOperationException("Cannot release a channel that didn't originate with this connector.");
            }

            if (this.currentToken >= 0 && this.currentToken == token && channel.Active)
            {
                this.available[channel.CurrentConfiguration.GroupName].Add(channel);
            }
            else
            {
                channel.TryDispose();
            }
        }
Exemplo n.º 2
0
        public void BindMessagingChannel(IMessagingChannel <IProtocolGatewayMessage> channel)
        {
            IDeviceProxy deviceProxy = new DeviceProxy(channel, this.deviceListener.Identity, this.messageConverter, this.byteBufferConverter);

            this.deviceListener.BindDeviceProxy(deviceProxy);
            Events.BindMessageChannel(this.deviceListener.Identity);
        }
Exemplo n.º 3
0
 private IEnumerable <IMessageAuditor> GetAuditorsForChannel(IMessagingChannel channel)
 {
     return(new[]
     {
         new ApplicationInsightsMessageAuditor(channel)
     });
 }
Exemplo n.º 4
0
        public void BindMessagingChannel(IMessagingChannel <IProtocolGatewayMessage> channel)
        {
            var sessionStateQuery = this.sessionStatePersistenceProvider.GetAsync(new AuthenticatedIdentity(this.deviceListener.Identity.Id));

            IDeviceProxy deviceProxy = new DeviceProxy(channel, this.deviceListener.Identity, this.messageConverter, this.byteBufferConverter);

            this.deviceListener.BindDeviceProxy(
                deviceProxy,
                async() =>
            {
                var sessionState = await sessionStateQuery;

                if (sessionState is SessionState registrationSessionState)
                {
                    var subscriptions = SessionStateParser.GetDeviceSubscriptions(registrationSessionState.SubscriptionRegistrations, this.deviceListener.Identity.Id);

                    foreach ((DeviceSubscription deviceSubscription, bool addSubscription) in subscriptions)
                    {
                        if (deviceSubscription == DeviceSubscription.Unknown)
                        {
                            continue;
                        }

                        if (addSubscription)
                        {
                            await this.deviceListener.AddSubscription(deviceSubscription);
                        }
                        else
                        {
                            await this.deviceListener.RemoveSubscription(deviceSubscription);
                        }
                    }
                }
            });
 public PipelineDispatcherHook(
     IMessagingHost messagingHost)
 {
     _messagingHost  = messagingHost;
     _channelGroup   = _messagingHost.Initialize();
     _messageChannel = _channelGroup.OpenChannel();
 }
Exemplo n.º 6
0
		protected virtual ICollection<IMessageAuditor> ResolveAuditors(IMessagingChannel channel)
		{
			if (this.emptyFactory)
				return new IMessageAuditor[0];

			return this.auditorFactory(channel).Where(x => x != null).ToArray();
		}
Exemplo n.º 7
0
        public virtual IDispatchContext PrepareDispatch(object message = null, IMessagingChannel actual = null)
        {
            this.EnsureTransaction();

            var context = new DefaultDispatchContext(actual ?? this);

            return(message == null ? context : context.WithMessage(message));
        }
        public void BindMessagingChannel(IMessagingChannel <IMessage> channel)
        {
            Contract.Requires(channel != null);

            Contract.Assert(this.messagingChannel == null);

            this.messagingChannel = channel;
            this.Receive();
        }
Exemplo n.º 9
0
        protected virtual ICollection <IMessageAuditor> ResolveAuditors(IMessagingChannel channel)
        {
            if (this.emptyFactory)
            {
                return(new IMessageAuditor[0]);
            }

            return(this.auditorFactory(channel).Where(x => x != null).ToArray());
        }
Exemplo n.º 10
0
 public DeviceProxy(IMessagingChannel <IProtocolGatewayMessage> channel, IIdentity identity,
                    IMessageConverter <IProtocolGatewayMessage> messageConverter, IByteBufferConverter byteBufferConverter)
 {
     this.isActive            = new AtomicBoolean(true);
     this.channel             = Preconditions.CheckNotNull(channel, nameof(channel));
     this.messageConverter    = Preconditions.CheckNotNull(messageConverter, nameof(messageConverter));
     this.Identity            = Preconditions.CheckNotNull(identity, nameof(this.Identity));
     this.byteBufferConverter = Preconditions.CheckNotNull(byteBufferConverter, nameof(byteBufferConverter));
 }
Exemplo n.º 11
0
        public DefaultDispatchContext(IMessagingChannel channel)
        {
            this.Channel       = this.channel = channel;
            this.dispatchTable = this.channel.CurrentConfiguration.DispatchTable;

            var config = channel.CurrentConfiguration;

            this.builder       = config.MessageBuilder;
            this.returnAddress = config.ReturnAddress;
        }
Exemplo n.º 12
0
        public void BindMessagingChannel(IMessagingChannel channel)
        {
            Contract.Requires(channel != null);

            Contract.Assert(this.messagingChannel == null);

            this.messagingChannel     = channel;
            this.lifetimeCancellation = new CancellationTokenSource();
            this.Receive();
        }
		public DependencyResolverChannel(IMessagingChannel channel, IDependencyResolver resolver)
		{
			if (channel == null)
				throw new ArgumentNullException("channel");

			if (resolver == null)
				throw new ArgumentNullException("resolver");

			this.channel = channel;
			this.resolver = resolver;
		}
		public DefaultChannelMessageDispatchContext(IMessagingChannel channel, ChannelMessage channelMessage)
		{
			if (channel == null)
				throw new ArgumentNullException("channel");

			if (channelMessage == null)
				throw new ArgumentNullException("channelMessage");

			this.channel = channel;
			this.channelMessage = channelMessage;
		}
		public virtual void Teardown(IMessagingChannel channel, int token)
		{
			if (channel == null)
				throw new ArgumentNullException("channel");

			if (!this.open.ContainsKey(channel))
				throw new InvalidOperationException("Cannot tear down a channel that didn't originate with this connector.");

			if (this.FirstOneThrough(token, token + 1))
				this.ClearAvailableChannels();

			Log.Verbose("Tearing down channel.");
			channel.TryDispose();
		}
Exemplo n.º 16
0
        public DependencyResolverChannel(IMessagingChannel channel, IDependencyResolver resolver)
        {
            if (channel == null)
            {
                throw new ArgumentNullException("channel");
            }

            if (resolver == null)
            {
                throw new ArgumentNullException("resolver");
            }

            this.channel  = channel;
            this.resolver = resolver;
        }
Exemplo n.º 17
0
        public DefaultChannelMessageDispatchContext(IMessagingChannel channel, ChannelMessage channelMessage)
        {
            if (channel == null)
            {
                throw new ArgumentNullException("channel");
            }

            if (channelMessage == null)
            {
                throw new ArgumentNullException("channelMessage");
            }

            this.channel        = channel;
            this.channelMessage = channelMessage;
        }
		public PooledDispatchChannel(PooledDispatchConnector connector, IMessagingChannel channel, int token)
		{
			if (connector == null)
				throw new ArgumentNullException("connector");

			if (channel == null)
				throw new ArgumentNullException("channel");

			if (token < 0)
				throw new ArgumentException("The token greater than or equal to zero.", "token");

			this.connector = connector;
			this.channel = channel;
			this.token = token;
		}
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_messageChannel != null)
         {
             _messageChannel.Dispose();
             _messageChannel = null;
         }
         if (_channelGroup != null)
         {
             _channelGroup.Dispose();
             _channelGroup = null;
         }
     }
 }
		public virtual void Release(IMessagingChannel channel, int token)
		{
			if (channel == null)
				throw new ArgumentNullException("channel");

			Log.Verbose("Trying to release the channel back to the pool for reuse.");

			bool value;
			if (!this.open.TryRemove(channel, out value))
				throw new InvalidOperationException("Cannot release a channel that didn't originate with this connector.");

			if (this.currentToken >= 0 && this.currentToken == token && channel.Active)
				this.available[channel.CurrentConfiguration.GroupName].Add(channel);
			else
				channel.TryDispose();
		}
        public void BindMessagingChannel(IMessagingChannel channel)
        {
            Contract.Requires(channel != null);
            Contract.Assert(this.messagingChannel == null);

            this.messagingChannel = channel;
            var closedCause = Volatile.Read(ref this.closedCause);

            if (closedCause != null)
            {
                channel.Close(closedCause);
            }
            foreach (var source in this.sources)
            {
                source.BindMessagingChannel(channel);
            }
        }
Exemplo n.º 22
0
        public AuditChannel(IMessagingChannel channel, ICollection <IMessageAuditor> auditors)
        {
            if (channel == null)
            {
                throw new ArgumentNullException("channel");
            }

            if (auditors == null)
            {
                throw new ArgumentNullException("auditors");
            }

            if (auditors.Count == 0)
            {
                throw new ArgumentException("At least one auditor must be provided.", "auditors");
            }

            this.channel  = channel;
            this.auditors = new List <IMessageAuditor>(auditors);
        }
        public virtual void Teardown(IMessagingChannel channel, int token)
        {
            if (channel == null)
            {
                throw new ArgumentNullException("channel");
            }

            if (!this.open.ContainsKey(channel))
            {
                throw new InvalidOperationException("Cannot tear down a channel that didn't originate with this connector.");
            }

            if (this.FirstOneThrough(token, token + 1))
            {
                this.ClearAvailableChannels();
            }

            Log.Verbose("Tearing down channel.");
            channel.TryDispose();
        }
Exemplo n.º 24
0
        public PooledDispatchChannel(PooledDispatchConnector connector, IMessagingChannel channel, int token)
        {
            if (connector == null)
            {
                throw new ArgumentNullException("connector");
            }

            if (channel == null)
            {
                throw new ArgumentNullException("channel");
            }

            if (token < 0)
            {
                throw new ArgumentException("The token greater than or equal to zero.", "token");
            }

            this.connector = connector;
            this.channel   = channel;
            this.token     = token;
        }
Exemplo n.º 25
0
  public SubscriptionService(
      IOrchardServices orchardServices,
      IContentManager contentManager,
      IRepository<ThreadSubscriptionRecord> threadSubscriptionRepository,
      IRepository<UserPartRecord> userRepository,
      IUserPreferredCultureService userPreferredCultureService,
      ISubscriptionEmailTemplateService subscriptionEmailTemplateService,
      IMessagingChannel emailMessagingChannel,
      ISiteService siteService,
      IPostService postService
 )
  {
      _orchardServices = orchardServices;
      _contentManager = contentManager;
      _threadSubscriptionRepository = threadSubscriptionRepository;
      _userRepository = userRepository;
      _userPreferredCultureService = userPreferredCultureService;
      _subscriptionEmailTemplateService = subscriptionEmailTemplateService;
      _emailMessageingChannel = emailMessagingChannel;
      _siteService = siteService;
      _postService = postService;
  }
Exemplo n.º 26
0
        public async void BindMessagingChannel(IMessagingChannel channel)
        {
            try
            {
                Contract.Requires(channel != null);

                Contract.Assert(this.messagingChannel == null);

                this.messagingChannel = channel;
                await this.bridge.DeviceClient.SetMethodHandlerAsync(
                    this.methodName,
                    (req, self) =>
                {
                    var handler = (MethodHandler)self;
                    return(handler.dispatchCallback(req, handler));
                },
                    this);
            }
            catch (Exception ex)
            {
                this.messagingChannel.Close(ex);
            }
        }
 public ApplicationInsightsMessageAuditor(IMessagingChannel channel)
 {
     _channel         = channel;
     _telemetryClient = new TelemetryClient();
 }
		protected static void Build(IMessagingChannel channel, ChannelMessage channelMessage)
		{
			dispatchContext = new DefaultChannelMessageDispatchContext(channel, channelMessage);
		}
Exemplo n.º 29
0
 protected static void Build(IMessagingChannel wrapped, IDependencyResolver resolver)
 {
     channel = new DependencyResolverChannel(wrapped, resolver);
 }
Exemplo n.º 30
0
 public virtual IDispatchContext PrepareDispatch(object message = null, IMessagingChannel actual = null)
 {
     Log.Debug("Preparing a dispatch");
     return(this.CurrentContext.PrepareDispatch(message, actual ?? this));
 }
		public virtual IDispatchContext PrepareDispatch(object message = null, IMessagingChannel channel = null)
		{
			this.ThrowWhenDisposed();
			return this.delivery.PrepareDispatch(message, channel);
		}
		public virtual IDispatchContext PrepareDispatch(object message = null, IMessagingChannel actual = null)
		{
			this.EnsureTransaction();

			var context = new DefaultDispatchContext(actual ?? this);
			return message == null ? context : context.WithMessage(message);
		}
 public void BindMessagingChannel(IMessagingChannel <MessageWithFeedback> channel)
 {
     this.messagingChannel = channel;
     this.messagingChannel.CapabilitiesChanged += this.OnChannelCapabilitiesChanged;
     this.messagingClient.BindMessagingChannel(this);
 }
 protected static void Build(IMessagingChannel channel, ChannelMessage channelMessage)
 {
     dispatchContext = new DefaultChannelMessageDispatchContext(channel, channelMessage);
 }
		public DefaultDispatchContext(IMessagingChannel channel)
		{
			this.Channel = this.channel = channel;
			this.dispatchTable = this.channel.CurrentConfiguration.DispatchTable;

			var config = channel.CurrentConfiguration;
			this.builder = config.MessageBuilder;
			this.returnAddress = config.ReturnAddress;
		}
		public SynchronousMessenger(IMessagingChannel channel)
		{
			this.channel = channel;
		}
		protected static void Build(IMessagingChannel wrapped, IDependencyResolver resolver)
		{
			channel = new DependencyResolverChannel(wrapped, resolver);
		}
Exemplo n.º 38
0
 public virtual IDispatchContext PrepareDispatch(object message = null, IMessagingChannel channel = null)
 {
     this.ThrowWhenDisposed();
     return(this.delivery.PrepareDispatch(message, channel));
 }
Exemplo n.º 39
0
        public IDispatchContext PrepareDispatch(object message = null, IMessagingChannel channel = null)
        {
            var context = new DefaultDispatchContext(channel ?? this);

            return(message == null ? context : context.WithMessage(message));
        }
        public void BindMessagingChannel(IMessagingChannel<IMessage> channel)
        {
            Contract.Requires(channel != null);

            Contract.Assert(this.messagingChannel == null);

            this.messagingChannel = channel;
            this.Receive();
        }
		public AuditChannel(IMessagingChannel channel, ICollection<IMessageAuditor> auditors)
		{
			if (channel == null)
				throw new ArgumentNullException("channel");

			if (auditors == null)
				throw new ArgumentNullException("auditors");

			if (auditors.Count == 0)
				throw new ArgumentException("At least one auditor must be provided.", "auditors");

			this.channel = channel;
			this.auditors = auditors;
		}
		public virtual IDispatchContext PrepareDispatch(object message = null, IMessagingChannel actual = null)
		{
			Log.Debug("Preparing a dispatch");
			return this.CurrentContext.PrepareDispatch(message, actual ?? this);
		}
Exemplo n.º 43
0
 public SynchronousMessenger(IMessagingChannel channel)
 {
     this.channel = channel;
 }
		protected static void Build(IMessagingChannel channel, IDispatchTable dispatchTable)
		{
			dispatchContext = new DefaultDispatchContext(channel, dispatchTable);
		}
 public void BindMessagingChannel(IMessagingChannel <MessageWithFeedback> channel)
 {
     this.messagingChannel = channel;
     this.messagingClient.BindMessagingChannel(this);
 }