Example #1
0
        public async Task Unsubscribe(string service, string eventName)
        {
            if (!Ws.IsConnected)
            {
                throw new Exception("ws is not connected");
            }

            var unsubRequest = new HubRequest
            {
                service   = service,
                eventName = eventName,
                method    = "unsubscribe"
            };

            if (!_subscriptions.Contains(unsubRequest))
            {
                throw new Exception("subscription not found");
            }

            await _restProtocol.RequestAsync(unsubRequest);

            _subscriptions.Remove(unsubRequest);
            if (EventSubscribed != null)
            {
                EventSubscribed(this, new EventArgs <HubRequest>(unsubRequest));
            }
        }
Example #2
0
        public async Task Subscribe(string service, string eventName, object credentials = null)
        {
            if (!Ws.IsConnected)
            {
                throw new Exception("ws is not connected");
            }

            var subRequest = new HubRequest
            {
                service     = service,
                eventName   = eventName,
                credentials = credentials,
                method      = "subscribe"
            };

            if (_subscriptions.Contains(subRequest))
            {
                _subscriptions.Remove(subRequest);
            }

            await _restProtocol.RequestAsync(subRequest);

            _subscriptions.Add(subRequest);
            if (EventSubscribed != null)
            {
                EventSubscribed(this, new EventArgs <HubRequest>(subRequest));
            }
        }
Example #3
0
        public void Update(HubRequest req)
        {
            if (!Contains(req))
            {
                throw new Exception("[HubSubscriptionCollection] not found");
            }

            this[req].credentials = req.credentials;
        }
Example #4
0
        public void Add(HubRequest req)
        {
            if (Contains(req))
            {
                throw new Exception("[HubSubscriptionCollection] Already exists");
            }

            _subscriptions.Add(req);
        }
Example #5
0
        public void Update(HubRequest req)
        {
            if (!Contains(req))
            {
                throw new Exception("[HubSubscriptionCollection] not found");
            }

            this[req].validator = req.validator;
        }
Example #6
0
        public void Remove(HubRequest req)
        {
            if (!Contains(req))
            {
                throw new Exception("[HubSubscriptionCollection] not found");
            }

            var item = this[req];

            _subscriptions.Remove(item);
        }
Example #7
0
        private HubRequest this[HubRequest req]
        {
            get
            {
                if (!Contains(req))
                {
                    throw new Exception("[HubSubscriptionCollection] not found");
                }

                return(_subscriptions.Find(x => x.service == req.service && x.eventName == req.eventName));
            }
        }
Example #8
0
        public bool Contains(HubRequest req)
        {
            var subscription = _subscriptions.Find(x => x.service == req.service && x.eventName == req.eventName);

            return(subscription != null);
        }
 public HubSubscriptionError(HubRequest request, Exception ex)
 {
     Request   = request;
     Exception = ex;
 }