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)); } }
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)); } }
public void Update(HubRequest req) { if (!Contains(req)) { throw new Exception("[HubSubscriptionCollection] not found"); } this[req].credentials = req.credentials; }
public void Add(HubRequest req) { if (Contains(req)) { throw new Exception("[HubSubscriptionCollection] Already exists"); } _subscriptions.Add(req); }
public void Update(HubRequest req) { if (!Contains(req)) { throw new Exception("[HubSubscriptionCollection] not found"); } this[req].validator = req.validator; }
public void Remove(HubRequest req) { if (!Contains(req)) { throw new Exception("[HubSubscriptionCollection] not found"); } var item = this[req]; _subscriptions.Remove(item); }
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)); } }
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; }