Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
                }
            }
        }
Exemplo n.º 4
0
        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);
                }
            }
        }
Exemplo n.º 5
0
        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);
        }