Example #1
0
        public void ProcessRequest(WebContext <T> webContext, ISharpboxController <T> controller)
        {
            try
            {
                this.HandleRequest(webContext, controller);
                this.PopulateLifeCycleTrail(webContext);
            }
            catch (Exception ex)
            {
                if (webContext.WebResponse == null)
                {
                    webContext.WebResponse = new WebResponse <T>()
                    {
                        ModelErrors = new Dictionary <string, Stack <ModelError> >()
                    };
                }

                this.AddModelStateError(webContext, controller, "ExecutionError", new ModelError(ex, ex.Message));
            }

            if (this._successor != null && controller.IsModelStateValid())
            {
                this._successor.ProcessRequest(webContext, controller);
            }
        }
Example #2
0
        public override void HandleRequest(WebContext <T> webContext, ISharpboxController <T> controller)
        {
            try
            {
                this.ActionCommandMap             = controller.LoadCommandActionMap();
                webContext.WebRequest.CommandName = this.ActionCommandMap.GetCommandByAction(webContext, webContext.WebRequest.UiAction);

                webContext.WebResponse.AddLifeCycleTrailItem(this.Name, LifeCycleHandlerState.Success, string.Empty);
            }
            catch (ArgumentNullException aex)
            {
                AddModelStateError(webContext, controller, aex.ParamName, new ModelError(aex.Message));
            }
            catch (InvalidOperationException iex)
            {
                AddModelStateError(webContext, controller, iex.Source, new ModelError(iex.Message));
            }
            catch (KeyNotFoundException knfe)
            {
                AddModelStateError(webContext, controller, knfe.Source, new ModelError(knfe.Message));
            }
            catch (Exception ex)
            {
                AddModelStateError(webContext, controller, ex.Source, new ModelError(ex.Message));
            }
        }
Example #3
0
        public void ProcessRequest(WebRequest <T> webRequest, ISharpboxController <T> controller)
        {
            this.WebRequest  = webRequest;
            this.WebResponse = new WebResponse <T>()
            {
                ModelErrors = new Dictionary <string, Stack <ModelError> >()
            };

            this._handler.ProcessRequest(this, controller);
        }
Example #4
0
        public override void HandleRequest(WebContext <T> webContext, ISharpboxController <T> controller)
        {
            // Grab the instance
            var parameters = new List <object> {
                webContext.WebRequest.Instance
            };

            // If we are calling this handler or the entire chain out of band we might be declaring additional arguments. So we add them to the list.
            if (webContext.WebRequest.Args != null)
            {
                parameters.AddRange(webContext.WebRequest.Args);
            }

            // If this is a request with a file then add it to the parameters for execution
            if (webContext.WebRequest.FileDetail != null)
            {
                parameters.Add(webContext.WebRequest.FileDetail);
            }

            webContext.DispatchResponse = webContext.Dispatch.Process <T>(webContext.WebRequest.CommandName, parameters.ToArray());

            webContext.WebResponse.Instance     = (T)webContext.DispatchResponse.Entity;
            webContext.WebResponse.ResponseType = webContext.DispatchResponse.ResponseType.ToString();

            webContext.WebContextState = WebContextState.ResponseSet;

            var messageMap   = controller.LoadCommandMessageMap();
            var commandName  = webContext.WebRequest.CommandName;
            var responseType = webContext.DispatchResponse.ResponseType;

            if (webContext.DispatchResponse.ResponseType == ResponseTypes.Error)
            {
                this.AddModelStateError(webContext, controller, "ProcessingError", new ModelError(webContext.DispatchResponse.Message));
            }

            // Check to see if the controller has a message for this command + response type. Else use the default dispatcher message.

            if (messageMap.ContainsKey(commandName) && messageMap[commandName].ContainsKey(responseType))
            {
                webContext.WebResponse.Message = messageMap[commandName][responseType];
            }
            else
            {
                webContext.WebResponse.Message = webContext.DispatchResponse.Message;
            }

            // Then we'll give the controller once last chance to modify or override the message. This is helpful for formatted messages.
            controller.FormatMessage(webContext.DispatchResponse, webContext.WebResponse.Message);
        }
Example #5
0
        public override void HandleRequest(WebContext <T> webContext, ISharpboxController <T> controller)
        {
            if (!controller.IsModelStateValid())
            {
                controller.MigrateModelErrorsToWebContext();
                return;
            }

            this.Validator = controller.LoadValidatorByUiAction(webContext.WebRequest.UiAction);

            if (!this.Validate(webContext.WebRequest))
            {
                webContext.WebResponse.Instance = webContext.WebRequest.Instance;

                foreach (var e in this.ValidationResult.Errors)
                {
                    AddModelStateError(webContext, controller, e.PropertyName, new ModelError(e.ErrorMessage));
                }
            }
        }
Example #6
0
 public override void HandleRequest(WebContext <T> webContext, ISharpboxController <T> controller)
 {
 }
Example #7
0
        /// <summary>
        /// This will: (1) Call the controller facade pattern to add this error to the Controller which in turn sets !IsModelValid. (2) Add the error to the WebResponse using the overload method and (3) set the WebContext as faulted.
        /// </summary>
        /// <param name="webContext"></param>
        /// <param name="controller"></param>
        /// <param name="key"></param>
        /// <param name="modelError"></param>
        public void AddModelStateError(WebContext <T> webContext, ISharpboxController <T> controller, string key, ModelError modelError)
        {
            controller.AddErrorToModelState(key, modelError.ErrorMessage);

            this.AddModelStateError(webContext, key, modelError);
        }
Example #8
0
 public abstract void HandleRequest(WebContext <T> webContext, ISharpboxController <T> controller);