Ejemplo n.º 1
0
        /// <summary>
        /// Unregisters the first <see cref="IActivityMonitorClient"/> from the <see cref="IActivityMonitorOutput.Clients"/> list
        /// that satisfies the predicate.
        /// </summary>
        /// <param name="this">This <see cref="IActivityMonitorOutput"/>.</param>
        /// <param name="predicate">A predicate that will be used to determine the first client to unregister.</param>
        /// <returns>The unregistered client, or null if no client has been found.</returns>
        public static T UnregisterClient <T>(this IActivityMonitorOutput @this, Func <T, bool> predicate) where T : IActivityMonitorClient
        {
            if (predicate == null)
            {
                throw new ArgumentNullException("predicate");
            }
            T c = @this.Clients.OfType <T>().Where(predicate).FirstOrDefault();

            if (c != null)
            {
                @this.UnregisterClient(c);
            }
            return(c);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a strong bridge to another monitor's <see cref="ActivityMonitorBridgeTarget"/>.
        /// Only one bridge to the same monitor can exist at a time: if <see cref="FindBridgeTo"/> is not null,
        /// this throws a <see cref="InvalidOperationException"/>.
        /// A strong bridge synchronizes <see cref="IActivityMonitor.AutoTags"/> and <see cref="IActivityMonitor.Topic"/> between the two monitors. When created, the 2 properties
        /// of the local monitor are set to the ones of the target monitor.
        /// </summary>
        /// <param name="this">This <see cref="IActivityMonitorOutput"/>.</param>
        /// <param name="targetBridge">The target bridge that will receive our logs.</param>
        /// <returns>A <see cref="IDisposable"/> object that can be disposed to automatically call <see cref="UnbridgeTo"/>.</returns>
        public static IDisposable CreateStrongBridgeTo(this IActivityMonitorOutput @this, ActivityMonitorBridgeTarget targetBridge)
        {
            if (targetBridge == null)
            {
                throw new ArgumentNullException("targetBridge");
            }
            if (@this.Clients.OfType <ActivityMonitorBridge>().Any(b => b.BridgeTarget == targetBridge))
            {
                throw new InvalidOperationException();
            }
            var created = @this.RegisterClient(new ActivityMonitorBridge(targetBridge, true, true));

            return(Util.CreateDisposableAction(() => @this.UnregisterClient(created)));
        }