public void TableChanged(UspTableVersionChangeTrackingReturnModel table) { // get all the subscribers try { var subscriberKeys = (from c in Subscribers select c.Key).ToList(); for (int i = subscriberKeys.Count - 1; i >= 0; i--) { var KeyValue = subscriberKeys.ElementAt(i); IEventNotificationCallback callback = Subscribers[KeyValue]; if (((ICommunicationObject)callback).State == CommunicationState.Opened) { //call back only those subscribers who are interested in this fileType if (string.Equals(KeyValue.TableInterested, table.Name, StringComparison.OrdinalIgnoreCase)) { callback.PublishTableChange(table.Name); } } else { //These subscribers are no longer active. Delete them from subscriber list subscriberKeys.Remove(KeyValue); Subscribers.Remove(KeyValue); } } } catch (Exception ex) { Logger.Error(ex, ex.Message); throw; } }
public void Subscribe(string id, string tableName) { try { IEventNotificationCallback callback = OperationContext.Current.GetCallbackChannel <IEventNotificationCallback>(); lock (locker) { Subscriber subscriber = new Subscriber(); subscriber.Id = id; subscriber.TableInterested = tableName; Subscribers.Add(subscriber, callback); } } catch (Exception ex) { Logger.Error(ex, ex.Message); throw; } }