コード例 #1
0
        /// <summary>
        /// Adds a tag over the given span.
        /// </summary>
        /// <param name="span">The <see cref="ITrackingSpan"/> that tracks the tag across text versions.</param>
        /// <param name="tag">The tag to associate with the given span.</param>
        /// <returns>The <see cref="TrackingTagSpan&lt;T&gt;"/> that was added, which can be used to remove the tag later on.</returns>
        /// <remarks>This method is safe to use from any thread.</remarks>
        /// <exception cref="ArgumentNullException"><paramref name="span"/> or <paramref name="tag"/> is null.</exception>
        public TrackingTagSpan <T> CreateTagSpan(ITrackingSpan span, T tag)
        {
            if (span == null)
            {
                throw new ArgumentNullException("span");
            }
            if (tag == null)
            {
                throw new ArgumentNullException("tag");
            }

            var tagSpan = new TrackingTagSpan <T>(span, tag);

            StartBatch();
            try
            {
                lock (mutex)
                {
                    _trackingTagSpans.Add(tagSpan);
                    UpdateBatchSpan(tagSpan.Span);
                }
            }
            finally
            {
                EndBatch();
            }

            return(tagSpan);
        }
コード例 #2
0
        /// <summary>
        /// Removes a tag span that was created by calling <see cref="CreateTagSpan"/>.
        /// </summary>
        /// <param name="tagSpan">The <see cref="TrackingTagSpan&lt;T&gt;"/> returned from a previous call to <see cref="CreateTagSpan"/>.</param>
        /// <returns><c>true</c> if removed successfully, otherwise <c>false</c>.</returns>
        /// <remarks>This method is safe to use from any thread.</remarks>
        public bool RemoveTagSpan(TrackingTagSpan <T> tagSpan)
        {
            if (tagSpan == null)
            {
                throw new ArgumentNullException("tagSpan");
            }

            bool removed = false;

            StartBatch();
            try
            {
                lock (mutex)
                {
                    // Find the tracking tag span to be removed
                    removed = (_trackingTagSpans.Remove(tagSpan));
                    if (removed)
                    {
                        UpdateBatchSpan(tagSpan.Span);
                    }
                }
            }
            finally
            {
                EndBatch();
            }

            return(removed);
        }