Example #1
0
        /// <summary>
        /// Creates a story and starts it.
        /// </summary>
        /// <param name="storyFactory">The story factory.</param>
        /// <param name="name">The name.</param>
        /// <returns>
        /// The new started story.
        /// </returns>
        public static IStory StartNew(this IStoryFactory storyFactory, string name)
        {
            Ensure.ArgumentNotNull(storyFactory, "storyFactory");

            IStory story = storyFactory.CreateStory(name);

            story.Start();

            return(story);
        }
Example #2
0
        /// <summary>
        /// Invokes the task to be observed by this story.
        /// </summary>
        /// <param name="storyFactory">The story factory.</param>
        /// <param name="name">The name.</param>
        /// <param name="func">Function returning a task to observe.</param>
        /// <returns>
        /// The task observed by this story.
        /// </returns>
        public static Task StartNewAsync(this IStoryFactory storyFactory, string name, Func <Task> func)
        {
            Ensure.ArgumentNotNull(storyFactory, "storyFactory");
            Ensure.ArgumentNotNull(func, "func");

            IStory story = storyFactory.CreateStory(name);

            story.Start();

            Task result = func();

            result.ContinueWith(story.Stop, TaskContinuationOptions.ExecuteSynchronously);

            return(result);
        }
Example #3
0
        /// <summary>
        /// Invokes the task to be observed by this story.
        /// </summary>
        /// <param name="storyFactory">The story factory.</param>
        /// <param name="name">The name.</param>
        /// <param name="action">Action to observe.</param>
        public static void StartNew(this IStoryFactory storyFactory, string name, Action action)
        {
            Ensure.ArgumentNotNull(storyFactory, "storyFactory");
            Ensure.ArgumentNotNull(action, "action");

            IStory story = storyFactory.CreateStory(name);

            try
            {
                story.Start();

                action();
            }
            catch (Exception exception)
            {
                story.Data["exception"] = exception;
                throw;
            }
            finally
            {
                story.Stop();
            }
        }
Example #4
0
        /// <summary>
        /// Invokes the task to be observed by this story.
        /// </summary>
        /// <typeparam name="T">The task result type.</typeparam>
        /// <param name="storyFactory">The story factory.</param>
        /// <param name="name">The name.</param>
        /// <param name="func">Function returning a task to observe.</param>
        /// <returns>
        /// The result.
        /// </returns>
        public static T StartNew <T>(this IStoryFactory storyFactory, string name, Func <T> func)
        {
            Ensure.ArgumentNotNull(storyFactory, "storyFactory");
            Ensure.ArgumentNotNull(func, "func");

            IStory story = storyFactory.CreateStory(name);

            try
            {
                story.Start();

                return(func());
            }
            catch (Exception exception)
            {
                story.Data["exception"] = exception;
                throw;
            }
            finally
            {
                story.Stop();
            }
        }