internal void ForceRemoveBuggyClient(IActivityMonitorClient client)
        {
            Debug.Assert(client != null && _clients.Contains(client));
            IActivityMonitorBoundClient bound = client as IActivityMonitorBoundClient;

            if (bound != null)
            {
                try
                {
                    bound.SetMonitor(null, true);
                }
                catch (Exception ex)
                {
                    ActivityMonitor.CriticalErrorCollector.Add(ex, "While removing the buggy client.");
                }
            }
            if (_clients.Length == 1)
            {
                _clients = Util.Array.Empty <IActivityMonitorClient>();
            }
            else
            {
                int idx      = Array.IndexOf(_clients, client);
                var newArray = new IActivityMonitorClient[_clients.Length - 1];
                Array.Copy(_clients, 0, newArray, 0, idx);
                Array.Copy(_clients, idx + 1, newArray, idx, newArray.Length - idx);
                _clients = newArray;
            }
        }
 /// <summary>
 /// Unregisters the given <see cref="IActivityMonitorClient"/> from the <see cref="Clients"/> list.
 /// Silently ignores unregistered client.
 /// </summary>
 /// <param name="client">An <see cref="IActivityMonitorClient"/> implementation.</param>
 /// <returns>The unregistered client or null if it has not been found.</returns>
 public IActivityMonitorClient UnregisterClient(IActivityMonitorClient client)
 {
     if (client == null)
     {
         throw new ArgumentNullException("client");
     }
     using (_monitor.ReentrancyAndConcurrencyLock())
     {
         int idx;
         if ((idx = Array.IndexOf(_clients, client)) >= 0)
         {
             LogFilter filter = LogFilter.Undefined;
             IActivityMonitorBoundClient bound = client as IActivityMonitorBoundClient;
             if (bound != null)
             {
                 filter = bound.MinimalFilter;
                 bound.SetMonitor(null, false);
             }
             var newArray = new IActivityMonitorClient[_clients.Length - 1];
             Array.Copy(_clients, 0, newArray, 0, idx);
             Array.Copy(_clients, idx + 1, newArray, idx, newArray.Length - idx);
             _clients = newArray;
             if (filter != LogFilter.Undefined)
             {
                 _monitor.OnClientMinimalFilterChanged(filter, LogFilter.Undefined);
             }
             return(client);
         }
         return(null);
     }
 }
Esempio n. 3
0
        LogFilter DoGetBoundClientMinimalFilter()
        {
            Debug.Assert(_enteredThreadId == Thread.CurrentThread.ManagedThreadId);

            LogFilter minimal = LogFilter.Undefined;
            List <IActivityMonitorClient> buggyClients = null;

            foreach (var l in _output.Clients)
            {
                IActivityMonitorBoundClient bound = l as IActivityMonitorBoundClient;
                if (bound != null)
                {
                    try
                    {
                        minimal = minimal.Combine(bound.MinimalFilter);
                        if (minimal == LogFilter.Debug)
                        {
                            break;
                        }
                    }
                    catch (Exception exCall)
                    {
                        CriticalErrorCollector.Add(exCall, l.GetType().FullName);
                        if (buggyClients == null)
                        {
                            buggyClients = new List <IActivityMonitorClient>();
                        }
                        buggyClients.Add(l);
                    }
                }
            }
            if (buggyClients != null)
            {
                foreach (var l in buggyClients)
                {
                    _output.ForceRemoveBuggyClient(l);
                }
            }
            return(minimal);
        }
 private IActivityMonitorClient DoRegisterClient(IActivityMonitorClient client, ref bool forceAdded)
 {
     if ((forceAdded |= (Array.IndexOf(_clients, client) < 0)))
     {
         IActivityMonitorBoundClient bound = client as IActivityMonitorBoundClient;
         if (bound != null)
         {
             // Calling SetMonitor before adding it to the client first
             // enables the monitor to initialize itself before being solicited.
             // And if SetMonitor method calls InitializeTopicAndAutoTags, it does not
             // receive a "stupid" OnTopic/AutoTagsChanged.
             bound.SetMonitor(_monitor, false);
         }
         var newArray = new IActivityMonitorClient[_clients.Length + 1];
         Array.Copy(_clients, 0, newArray, 1, _clients.Length);
         newArray[0] = client;
         _clients    = newArray;
         if (bound != null)
         {
             _monitor.OnClientMinimalFilterChanged(LogFilter.Undefined, bound.MinimalFilter);
         }
     }
     return(client);
 }
 /// <summary>
 /// Creates a standardized exception that can be thrown by <see cref="IActivityMonitorBoundClient.SetMonitor"/>.
 /// </summary>
 /// <param name="boundClient">The bound client.</param>
 /// <returns>An exception with an explicit message.</returns>
 static public InvalidOperationException CreateMultipleRegisterOnBoundClientException(IActivityMonitorBoundClient boundClient)
 {
     return(new InvalidOperationException(String.Format(Impl.ActivityMonitorResources.ActivityMonitorBoundClientMultipleRegister, boundClient != null ? boundClient.GetType().FullName : String.Empty)));
 }
 /// <summary>
 /// Creates a standardized exception that can be thrown by <see cref="IActivityMonitorBoundClient.SetMonitor"/>.
 /// </summary>
 /// <param name="boundClient">The bound client.</param>
 /// <returns>An exception with an explicit message.</returns>
 static public InvalidOperationException CreateMultipleRegisterOnBoundClientException( IActivityMonitorBoundClient boundClient )
 {
     return new InvalidOperationException( String.Format( Impl.ActivityMonitorResources.ActivityMonitorBoundClientMultipleRegister, boundClient != null ? boundClient.GetType().FullName : String.Empty ) );
 }