Пример #1
0
        /// <summary>
        /// Executes the method action by wrapping it with
        /// 1. Logging of start / end time.
        /// 2. Status updates.
        /// </summary>
        /// <param name="methodName">The name of the method being executed.</param>
        /// <param name="taskName">Option name to use for the TaskName for StatusUpdates.</param>
        /// <param name="wrapTryCatch">Whether or not to wrap the call inside a try catch.</param>
        /// <param name="action">Action to execute.</param>
        public void Execute <T>(string methodName, string taskName, bool wrapTryCatch, Func <T> action)
        {
            T result = default(T);

            Execute(methodName, taskName, () =>
            {
                if (!wrapTryCatch)
                {
                    result = action();
                }
                else
                {
                    result = Try.CatchLogGet <T>("", action);
                }
            });
        }
Пример #2
0
        /// <summary>
        /// Executes the application.execute method via a lamda and logs the success/failure.
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        protected BoolMessageItem ExecuteInternal(Func <BoolMessageItem> action)
        {
            string methodName = _instance.GetType().FullName + ".Execute";

            _helper.Execute("Execute(context)", "", () =>
            {
                _result = Try.CatchLogGet <BoolMessageItem>("Error in " + methodName, action);
            });

            // Handle possiblity of applicationTemplate returning null for result.
            if (_result == null)
            {
                _result          = new BoolMessageItem(null, false, _instance.GetType().Name + " returned null result, converting this to a failure result.");
                _instance.Result = _result;
            }

            string message = _result.Success ? "Successful" : "Failed : " + _result.Message;

            Logger.Info(methodName + " : " + message);
            return(_result);
        }