private static void PublishToTimeline(TimerResult result, string category, string message)
 {
     GlimpseRuntime.Instance.Configuration.MessageBroker.Publish(new PipelineMessage { Id = Guid.NewGuid() }
         .AsTimedMessage(result)
         .AsTimelineMessage(message, new TimelineCategoryItem(category, "#999", "#bbb"))
     );
 }
        public void ShouldBeAbleToBuildWithFactory(TimerResult timerResult)
        {
            var testMessage = new TestMessage().AsTimedMessage(timerResult);

            Assert.Equal(timerResult.Offset, testMessage.Offset);
            Assert.Equal(timerResult.Duration, testMessage.Duration);
            Assert.Equal(timerResult.StartTime, testMessage.StartTime);
        }
        public void ShouldBeAbleToBuildWithFactory(TimerResult timerResult, string eventName, TimelineCategoryItem eventCategory, string eventSubText)
        {
            var testMessage = new TestMessage().AsTimelineMessage(eventName, eventCategory, eventSubText);

            Assert.Equal(eventName, testMessage.EventName);
            Assert.Equal(eventCategory, testMessage.EventCategory);
            Assert.Equal(eventSubText, testMessage.EventSubText);
        }
        public void BuildDetails(TimerResult timerResult, string controllerName, string actionName, bool isChildAction, Type executedType, MethodInfo method, string eventName, Core.Message.TimelineCategory eventCategory)
        {
            var message = new ActionMessage(timerResult, controllerName, actionName, isChildAction, executedType, method, eventName, eventCategory);

            var dictionary = new Dictionary<string, object>();
            message.BuildDetails(dictionary);

            Assert.Equal(3, dictionary.Count); 
        }
        public void BuildDetails(TimerResult timerResult, FilterCategory filterCategory, Type resultType, bool isChildAction, Type executedType, MethodInfo method, string eventName, Core.Message.TimelineCategory eventCategory)
        {
            var message = new FilterMessage(timerResult, filterCategory, resultType, isChildAction, executedType, method, eventName, eventCategory);

            var dictionary = new Dictionary<string, object>();
            message.BuildDetails(dictionary);

            Assert.Equal(4, dictionary.Count);
            Assert.Equal(resultType, dictionary["ResultType"]);
        }
        public void BuildDetails(TimerResult timerResult, bool isChildAction, Type executedType, MethodInfo method, string eventName, TimelineCategory eventCategory)
        {
            var message = new ActionBaseMessage(timerResult, isChildAction, executedType, method, eventName, eventCategory);

            var dictionary = new Dictionary<string, object>();
            message.BuildDetails(dictionary);

            Assert.Equal(3, dictionary.Count); 
            Assert.Equal(isChildAction, dictionary["IsChildAction"]);
            Assert.Equal(method.Name, dictionary["ExecutionMethod"]); 
            Assert.Equal(executedType, dictionary["ExecutedType"]);
        }
Beispiel #7
0
        /// <summary>
        /// Stops the timer instance.
        /// </summary>
        /// <param name="offset">The offset.</param>
        /// <returns>
        /// Timing info that is collected as a result of the execution.
        /// </returns>
        /// <remarks>
        /// Inconsistent results may be experienced if you do not call Start() before
        /// calling Stop().
        /// </remarks>
        public TimerResult Stop(TimeSpan offset)
        {
            var result = new TimerResult
            {
                StartTime = DateTime.Now - offset,
                Offset    = offset
            };

            result.Duration = Stopwatch.Elapsed - result.Offset;

            return(result);
        }
        public void Construct(TimerResult timerResult, bool isChildAction, Type executedType, MethodInfo method, string eventName, TimelineCategory eventCategory)
        {
            var message = new ActionBaseMessage(timerResult, isChildAction, executedType, method, eventName, eventCategory);

            Assert.Equal(timerResult.Duration, message.Duration);
            Assert.Equal(timerResult.Offset, message.Offset);
            Assert.Equal(timerResult.StartTime, message.StartTime);
            Assert.Equal(eventName, message.EventName);
            Assert.Equal(eventCategory, message.EventCategory);
            Assert.Equal(eventCategory, message.EventCategory);
            Assert.Equal(executedType, message.ExecutedType);
            Assert.Equal(method, message.ExecutedMethod); 
        }
        public void Construct(TimerResult timerResult, string controllerName, string actionName, bool isChildAction, Type executedType, MethodInfo method)
        {
            var message = new ActionMessage(timerResult, controllerName, actionName, isChildAction, executedType, method);

            Assert.Equal(timerResult.Duration, message.Duration);
            Assert.Equal(timerResult.Offset, message.Offset);
            Assert.Equal(timerResult.StartTime, message.StartTime);
            Assert.Equal(executedType, message.ExecutedType);
            Assert.Equal(method, message.ExecutedMethod);
            Assert.Equal(controllerName, message.ControllerName);
            Assert.Equal(actionName, message.ActionName);
            Assert.Equal(string.Format("{0}:{1}", controllerName, actionName), message.EventName);
        }
Beispiel #10
0
        /// <summary>
        /// Times the specified action. This will start and stop the timer either side
        /// of the action that is executed.
        /// </summary>
        /// <param name="action">The action that should be executed.</param>
        /// <returns>
        /// Timing info that is collected as a result of the execution.
        /// </returns>
        public TimerResult Time(Action action)
        {
            var result = new TimerResult
            {
                StartTime = DateTime.Now,
                Offset    = Stopwatch.Elapsed
            };

            action();
            result.Duration = Stopwatch.Elapsed - result.Offset;

            return(result);
        }
Beispiel #11
0
        /// <summary>
        /// Times the specified function. This will start and stop the timer either side
        /// of the function that is executed.
        /// </summary>
        /// <typeparam name="T">Type of result that is expected</typeparam>
        /// <param name="function">The function that should be executed.</param>
        /// <returns>
        /// Timing info that is collected as a result of the execution.
        /// </returns>
        public TimerResult <T> Time <T>(Func <T> function)
        {
            var result = new TimerResult <T>
            {
                StartTime = DateTime.Now,
                Offset    = Stopwatch.Elapsed,
                Result    = function()
            };

            result.Duration = Stopwatch.Elapsed - result.Offset;

            return(result);
        }
Beispiel #12
0
        public void Construct(TimerResult timerResult, FilterCategory filterCategory, Type resultType, bool isChildAction, Type executedType, MethodInfo method)
        {
            var message = new FilterMessage(timerResult, filterCategory, resultType, isChildAction, executedType, method);

            Assert.Equal(timerResult.Duration, message.Duration);
            Assert.Equal(timerResult.Offset, message.Offset);
            Assert.Equal(timerResult.StartTime, message.StartTime);  
            Assert.Equal(executedType, message.ExecutedType);
            Assert.Equal(method, message.ExecutedMethod);
            Assert.Equal(filterCategory, message.Category);
            Assert.Equal(resultType, message.ResultType);
            Assert.Equal(string.Format("{0}", filterCategory.ToString()), message.EventName);
        }
        /// <summary>
        /// Calls <c>Proceed</c> on the original implementation, if the current <c>RuntimePolicy</c> is not <c>Off</c>, and provides a corresponding <see cref="TimerResult"/>.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="timerResult">The timer result.</param>
        /// <returns>
        /// Returns <c>true</c> if <c>Proceed</c> was called on the original object, and sets <paramref name="timerResult" />. Returns <c>false</c> and sets <paramref name="timerResult" /> to <c>null</c> if <c>RuntimePolicy</c> is <c>Off</c>.
        /// </returns>
        public static bool TryProceedWithTimer(this IAlternateMethodContext context, out TimerResult timerResult)
        {
            if (context.RuntimePolicyStrategy() == RuntimePolicy.Off)
            {
                context.Proceed();
                timerResult = null;
                return false;
            }

            var timer = context.TimerStrategy();

            timerResult = timer.Time(context.Proceed);
            return true;
        }
        public void Construct(TimerResult timerResult, string controllerName, string actionName, FilterBounds bounds, FilterCategory filterCategory, Type resultType, bool isChildAction, Type executedType, MethodInfo method)
        {
            var message = new BoundedFilterMessage(timerResult, controllerName, actionName, bounds, filterCategory, resultType, isChildAction, executedType, method);

            Assert.Equal(timerResult.Duration, message.Duration);
            Assert.Equal(timerResult.Offset, message.Offset);
            Assert.Equal(timerResult.StartTime, message.StartTime);
            Assert.Equal(executedType, message.ExecutedType);
            Assert.Equal(method, message.ExecutedMethod);
            Assert.Equal(filterCategory, message.Category);
            Assert.Equal(resultType, message.ResultType);
            Assert.Equal(controllerName, message.ControllerName);
            Assert.Equal(actionName, message.ActionName);
            Assert.Equal(bounds, message.Bounds);
            Assert.Equal(string.Format("{0}:{1} - {2}:{3}", filterCategory.ToString(), bounds.ToString(), controllerName, actionName), message.EventName);
        }
Beispiel #15
0
 /// <summary>
 /// Additional code to be executed after the original implementation has been run.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="timerResult">The timer result.</param>
 public abstract void PostImplementation(IAlternateMethodContext context, TimerResult timerResult);
Beispiel #16
0
 /// <summary>
 /// Additional code to be executed after the original implementation has been run.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="timerResult">The timer result.</param>
 public abstract void PostImplementation(IAlternateMethodContext context, TimerResult timerResult);