Пример #1
0
        public IDisposable Subscribe(IEventSink eventSink, object filterInstance, EndpointReference subscriptionManagerReference, IIncomingHeaders headers)
        {
            var selectorSetHeader = headers.GetHeader <SelectorSetHeader>();
            var target            = selectorSetHeader.Selectors.ExtractObjectName();
            var listenerId        = GenerateNextListenerId();

            subscriptionManagerReference.AddProperty(new NotificationListenerListHeader(listenerId.ToString()), false);
            var subscriptionInfo = new SubscriptionInfo(eventSink, listenerId);

            lock (_subscriptions)
            {
                _subscriptions.Add(subscriptionInfo);
            }
            _server.AddNotificationListener(target, subscriptionInfo.OnNotification, subscriptionInfo.FilterNotification, listenerId);

            return(new SubscriptionRemover(
                       () =>
            {
                lock (_subscriptions)
                {
                    var toRemove = _subscriptions.Single(x => x.EventSink == eventSink);
                    _server.RemoveNotificationListener(target, toRemove.OnNotification, toRemove.FilterNotification, toRemove.ListenerId);
                    _subscriptions.Remove(toRemove);
                }
            }));
        }
        private static IEnumerable <Selector> GetSelectors(IIncomingHeaders incomingHeaders)
        {
            var selectorSetHeader = incomingHeaders.GetHeader <SelectorSetHeader>();

            if (selectorSetHeader != null)
            {
                Log.Info("Requesting selectors " + string.Join(", ", selectorSetHeader.Selectors.Select(x => x.ToString())));
                return(selectorSetHeader.Selectors);
            }
            return(Enumerable.Empty <Selector>());
        }
 private static string GetFragmentExpression(IIncomingHeaders incomingHeaders, IOutgoingHeaders outgoingHeaders)
 {
     var fragmentTransferHeader = incomingHeaders.GetHeader<FragmentTransferHeader>();
     string fragmentExpression = null;
     if (fragmentTransferHeader != null)
     {
         Log.InfoFormat("Requesting fragment '{0}'", fragmentTransferHeader.Expression);
         outgoingHeaders.AddHeader(fragmentTransferHeader, true);
         fragmentExpression = fragmentTransferHeader.Expression;
     }
     else
     {
         Log.Debug("Not a fragment request.");
     }
     return fragmentExpression;
 }
        private static string GetFragmentExpression(IIncomingHeaders incomingHeaders, IOutgoingHeaders outgoingHeaders)
        {
            var    fragmentTransferHeader = incomingHeaders.GetHeader <FragmentTransferHeader>();
            string fragmentExpression     = null;

            if (fragmentTransferHeader != null)
            {
                Log.InfoFormat("Requesting fragment '{0}'", fragmentTransferHeader.Expression);
                outgoingHeaders.AddHeader(fragmentTransferHeader, true);
                fragmentExpression = fragmentTransferHeader.Expression;
            }
            else
            {
                Log.Debug("Not a fragment request.");
            }
            return(fragmentExpression);
        }
 private IManagementRequestHandler GetHandler(IIncomingHeaders incomingHeaders)
 {
     var resourceUriHeader = incomingHeaders.GetHeader<ResourceUriHeader>();
     if (resourceUriHeader == null)
     {
         Log.ErrorFormat("Required ResourceURI header not found.");
         throw new DestinationUnreachableFaultException();
     }
     var resourceUri = resourceUriHeader.ResourceUri;
     IManagementRequestHandler handler;
     if (_handlers.TryGetValue(resourceUri, out handler))
     {
         Log.InfoFormat("Using {0} to handle resource '{1}'", handler, resourceUri);
         return handler;
     }
     Log.ErrorFormat("Handler for resource '{0}' not found.", resourceUri);
     throw new DestinationUnreachableFaultException();
 }
        private IManagementRequestHandler GetHandler(IIncomingHeaders incomingHeaders)
        {
            var resourceUriHeader = incomingHeaders.GetHeader <ResourceUriHeader>();

            if (resourceUriHeader == null)
            {
                Log.ErrorFormat("Required ResourceURI header not found.");
                throw new DestinationUnreachableFaultException();
            }
            var resourceUri = resourceUriHeader.ResourceUri;
            IManagementRequestHandler handler;

            if (_handlers.TryGetValue(resourceUri, out handler))
            {
                Log.InfoFormat("Using {0} to handle resource '{1}'", handler, resourceUri);
                return(handler);
            }
            Log.ErrorFormat("Handler for resource '{0}' not found.", resourceUri);
            throw new DestinationUnreachableFaultException();
        }
        private static IEnumerable<Selector> GetSelectors(IIncomingHeaders incomingHeaders)
        {
            var selectorSetHeader = incomingHeaders.GetHeader<SelectorSetHeader>();

            if (selectorSetHeader != null)
            {
                Log.Info("Requesting selectors "+string.Join(", ", selectorSetHeader.Selectors.Select(x => x.ToString())));
                return selectorSetHeader.Selectors;
            }
            return Enumerable.Empty<Selector>();
        }