public void Unsubscribe(string categoryName, string counterName) { #if DEBUG Console.WriteLine("Unsubscribe({0}, {1})", categoryName, counterName); #endif IPerfmonCallback callback = OperationContext.Current.GetCallbackChannel <IPerfmonCallback>(); RemoveCallback(categoryName, counterName, callback); }
public void Leave() { #if DEBUG MessageProperties properties = OperationContext.Current.IncomingMessageProperties; var endpoint = (RemoteEndpointMessageProperty)properties[RemoteEndpointMessageProperty.Name]; Console.WriteLine("{0}:{1} has left", endpoint.Address, endpoint.Port); #endif IPerfmonCallback callback = OperationContext.Current.GetCallbackChannel <IPerfmonCallback>(); RemoveCallbacks(callback); }
public void RemoveCallbacks(IPerfmonCallback callback) { foreach (var kvp in subscribers.ToList()) { Tuple <string, string> tuple = kvp.Key; List <IPerfmonCallback> list = kvp.Value; list.Remove(callback); if (!list.Any()) { subscribers.Remove(tuple); } } }
public void RemoveCallback(string categoryName, string counterName, IPerfmonCallback callback) { Tuple <string, string> tuple = Tuple.Create(categoryName, counterName); List <IPerfmonCallback> list; if (subscribers.TryGetValue(tuple, out list)) { list.Remove(callback); if (!list.Any()) { subscribers.Remove(tuple); } } }
public bool Subscribe(string categoryName, string counterName) { #if DEBUG Console.WriteLine("Subscribe({0}, {1})", categoryName, counterName); #endif if (!allowedCategories.Contains(categoryName)) { return(false); } try { if (!PerformanceCounterCategory.CounterExists(counterName, categoryName)) { return(false); } } catch (InvalidOperationException) { // Category does not exist return(false); } IPerfmonCallback callback = OperationContext.Current.GetCallbackChannel <IPerfmonCallback>(); Tuple <string, string> tuple = Tuple.Create(categoryName, counterName); List <IPerfmonCallback> list; if (subscribers.TryGetValue(tuple, out list)) { if (!list.Contains(callback)) { list.Add(callback); } } else { list = new List <IPerfmonCallback>() { callback }; subscribers.Add(tuple, list); } return(true); }