Exemplo n.º 1
0
		/// <summary>
		/// Sets the context.
		/// </summary>
		/// <param name="context">The context.</param>
		public override void SetContext(IEngineContext context)
		{
			base.SetContext(context);

			urlBuilder = (IUrlBuilder) context.GetService(typeof(IUrlBuilder));
			currentUrl = context.UrlInfo;
		}
 protected override IMockResponse BuildResponse(UrlInfo info)
 {
     StubResponse response = new StubResponse(info,
                                     new DefaultUrlBuilder(),
                                     new StubServerUtility(),
                                     new RouteMatch(),
                                     Referrer);
     return response;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Invoked by <see cref="WizardActionProvider"/>.
        /// </summary>
        /// <remarks>
        /// This can be overriden but it's important to invoke the base
        /// implementation.
        /// </remarks>
        /// <param name="wizardController"></param>
        protected internal virtual void Initialize(Controller wizardController)
        {
            _wizardcontroller = wizardController;

            _context = wizardController.Context;

            UrlInfo urlInfo = _context.UrlInfo;

            InitializeFieldsFromServiceProvider(wizardController.ServiceProvider);
            InitializeControllerState(urlInfo.Area, urlInfo.Controller, urlInfo.Action);
        }
Exemplo n.º 4
0
 public void Action()
 {
     var mocks = new MockRepository();
     var urlBuilder = mocks.CreateMock<IUrlBuilder>();
     var url = new UrlInfo("area", "control", "action");
     With.Mocks(mocks).Expecting(delegate {
         Expect.Call(urlBuilder.BuildUrl(url, "tarea", "ControllerWArea", "taction"))
             .Repeat.Once()
             .Return(null);
     }).Verify(delegate {
         urlBuilder.BuildUrl<ControllerWArea>(url, c => c.taction());
     });
 }
Exemplo n.º 5
0
        private void InternalRedirectToStep(int stepIndex, String step)
        {
            WizardUtils.RegisterCurrentStepInfo(_wizardcontroller, stepIndex, step);

            // We need to preserve any attribute from the QueryString
            // for example in case the url has an Id
            if (Context.Request.QueryString.HasKeys())
            {
                String url = UrlInfo.CreateAbsoluteRailsUrl(Context.ApplicationPath,
                                                            _wizardcontroller.Name, step, Context.UrlInfo.Extension) + Context.Request.Uri.Query;

                Context.Response.Redirect(url);
            }
            else
            {
                Context.Response.Redirect(_wizardcontroller.Name, step);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
 /// </summary>
 /// <param name="url">The URL.</param>
 /// <param name="innerException">The inner exception.</param>
 public ControllerNotFoundException(UrlInfo url, Exception innerException)
     : this(url.Area, url.Controller, innerException)
 {
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
 /// </summary>
 /// <param name="url">The URL.</param>
 public ControllerNotFoundException(UrlInfo url) : this(url.Area, url.Controller)
 {
 }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ResourceFileHandler"/> class.
 /// </summary>
 /// <param name="urlInfo">The URL info.</param>
 /// <param name="staticResourceRegistry">The static resource registry.</param>
 public ResourceFileHandler(UrlInfo urlInfo, IStaticResourceRegistry staticResourceRegistry)
 {
     this.urlInfo = urlInfo;
     this.staticResourceRegistry = staticResourceRegistry;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Checks whether the target url is a resource file url.
 /// </summary>
 /// <param name="urlInfo">The url info.</param>
 /// <returns></returns>
 protected virtual bool IsResourceFileUrl(UrlInfo urlInfo)
 {
     return(urlInfo.Area == "MonoRail" && urlInfo.Controller == "Files");
 }
Exemplo n.º 10
0
        public void IncludeActions(Controller controller)
        {
            IRailsEngineContext context = controller.Context;

            IWizardController wizardController = controller as IWizardController;

            if (wizardController == null)
            {
                throw new RailsException("The controller {0} must implement the interface " +
                                         "IWizardController to be used as a wizard", controller.Name);
            }

            steps = wizardController.GetSteps(controller.Context);

            if (steps == null || steps.Length == 0)
            {
                throw new RailsException("The controller {0} returned no WizardStepPage",
                                         controller.Name);
            }

            IList stepList = new ArrayList();

            controller.DynamicActions["start"] = this;

            urlInfo = controller.Context.UrlInfo;

            rawAction = urlInfo.Action;

            requestedAction = ObtainRequestedAction(rawAction, out innerAction);

            foreach (WizardStepPage step in steps)
            {
                String actionName = step.ActionName;

                if (String.Compare(requestedAction, actionName, true) == 0)
                {
                    currentStepInstance = step;

                    if (innerAction != null)
                    {
                        // If there's an inner action, we invoke it as a step too
                        controller.DynamicActions[rawAction] =
                            new DelegateDynamicAction(new ActionDelegate(OnStepActionRequested));
                    }
                }

                controller.DynamicActions[actionName] =
                    new DelegateDynamicAction(new ActionDelegate(OnStepActionRequested));

                stepList.Add(actionName);

                step.Initialize(controller);
            }

            context.UnderlyingContext.Items["wizard.step.list"] = stepList;

            if (currentStepInstance != null && !HasRequiredSessionData(controller))
            {
                StartWizard(controller, false);
            }

            SetUpWizardHelper(controller);
            SetUpWizardHelper(currentStepInstance);
        }
Exemplo n.º 11
0
        protected void InitUrlInfo(string areaName, string controllerName, string actionName)
        {
            var urlInfo = new UrlInfo(areaName, controllerName, actionName, "/", "castle");

            engineContext = new StubEngineContext();
            engineContext.AddService(typeof(IUrlBuilder), serviceProvider.UrlBuilder);
            engineContext.CurrentController = controller;
            engineContext.CurrentControllerContext = controllerContext;
            engineContext.Services.ViewEngineManager = serviceProvider.ViewEngineManager;
            output = (StringWriter) engineContext.Response.Output;

            var routeMatch = new RouteMatch();
            controllerContext.RouteMatch = routeMatch;
        }
        /// <summary>
        /// Implementation of IDynamicActionProvider.
        /// <para>
        /// Grab all steps related to the wizard
        /// and register them as dynamic actions.
        /// </para>
        /// </summary>
        /// <param name="engineContext">The engine context.</param>
        /// <param name="controller">Wizard controller (must implement <see cref="IWizardController"/></param>
        /// <param name="controllerContext">The controller context.</param>
        public void IncludeActions(IEngineContext engineContext, IController controller, IControllerContext controllerContext)
        {
            // Primordial assert

            var wizardController = controller as IWizardController;

            if (wizardController == null)
            {
                throw new MonoRailException("The controller {0} must implement the interface " +
                                            "IWizardController to be used as a wizard", controllerContext.Name);
            }

            // Grab all Wizard Steps

            steps = wizardController.GetSteps(engineContext);

            if (steps == null || steps.Length == 0)
            {
                throw new MonoRailException("The controller {0} returned no WizardStepPage", controllerContext.Name);
            }

            var stepList = new List <string>();

            // Include the "start" dynamic action, which resets the wizard state

            controllerContext.DynamicActions["start"] = this;

            // Find out the action request (and possible inner action)
            //   Each action will be a step name, or maybe the step name + action (ie Page1-Save)

            urlInfo = engineContext.UrlInfo;

            rawAction = urlInfo.Action;

            requestedAction = ObtainRequestedAction(rawAction, out innerAction);

            // If no inner action was found, fallback to 'RenderWizardView'

            if (string.IsNullOrEmpty(innerAction))
            {
                innerAction = "RenderWizardView";
            }

            engineContext.Items["wizard.step.list"] = stepList;

            SetUpWizardHelper(engineContext, wizardController, controller, controllerContext);

            // Initialize all steps and while we are at it,
            // discover the current step

            foreach (var step in steps)
            {
                var actionName = step.ActionName;

                step.WizardController        = wizardController;
                step.WizardControllerContext = controllerContext;

                if (string.Compare(requestedAction, actionName, true) == 0)
                {
                    currentStepInstance = step;

                    if (innerAction != null)
                    {
                        // If there's an inner action, we invoke it as a step too
                        controllerContext.DynamicActions[rawAction] = new DelegateDynamicAction(OnStepActionRequested);
                    }

                    engineContext.CurrentController = step;
                }
                else
                {
                    controllerContext.DynamicActions[actionName] = new DelegateDynamicAction(OnStepActionRequested);
                }

                stepList.Add(actionName);
            }

            SetUpWizardHelper(engineContext, wizardController, controller, controllerContext);
        }