コード例 #1
0
        /// <summary>
        /// Executes a macro of a given type.
        /// </summary>
        private Attempt <MacroContent> ExecuteProfileMacroWithErrorWrapper(MacroModel macro, string msgIn, Func <MacroContent> getMacroContent, Func <string> msgErr)
        {
            try
            {
                return(Attempt.Succeed(getMacroContent()));
            }
            catch (Exception e)
            {
                Exceptions.Add(e);

                _plogger.Warn <MacroRenderer>(e, "Failed {MsgIn}", msgIn);

                var macroErrorEventArgs = new MacroErrorEventArgs
                {
                    Name        = macro.Name,
                    Alias       = macro.Alias,
                    MacroSource = macro.MacroSource,
                    Exception   = e,
                    Behaviour   = Current.Configs.Settings().Content.MacroErrorBehaviour
                };

                OnError(macroErrorEventArgs);

                switch (macroErrorEventArgs.Behaviour)
                {
                case MacroErrorBehaviour.Inline:
                    // do not throw, eat the exception, display the trace error message
                    return(Attempt.Fail(new MacroContent {
                        Text = msgErr()
                    }, e));

                case MacroErrorBehaviour.Silent:
                    // do not throw, eat the exception, do not display anything
                    return(Attempt.Fail(new MacroContent {
                        Text = string.Empty
                    }, e));

                case MacroErrorBehaviour.Content:
                    // do not throw, eat the exception, display the custom content
                    return(Attempt.Fail(new MacroContent {
                        Text = macroErrorEventArgs.Html ?? string.Empty
                    }, e));

                //case MacroErrorBehaviour.Throw:
                default:
                    // see http://issues.umbraco.org/issue/U4-497 at the end
                    // throw the original exception
                    throw;
                }
            }
        }
コード例 #2
0
 protected void OnError(MacroErrorEventArgs e)
 {
     Error?.Invoke(this, e);
 }