Exemplo n.º 1
0
        private void InternalRedirectToStep(IEngineContext engineContext, int stepIndex, String step,
                                            IDictionary queryStringParameters)
        {
            WizardUtils.RegisterCurrentStepInfo(engineContext, wizardParentController, wizardcontrollerContext, stepIndex, step);

            // Does this support areas?

            var urlBuilder = engineContext.Services.GetService <IUrlBuilder>();

            if (queryStringParameters != null && queryStringParameters.Count != 0)
            {
                if (WizardController.UseCurrentRouteForRedirects)
                {
                    var dictionary = new Dictionary <string, string>(wizardcontrollerContext.RouteMatch.Parameters);
                    dictionary["action"] = step;

                    var parameters = UrlBuilderParameters.From(queryStringParameters, dictionary);

                    RedirectToUrl(urlBuilder.BuildUrl(engineContext.UrlInfo, parameters));
                }
                else
                {
                    Redirect(WizardControllerContext.AreaName, wizardcontrollerContext.Name, step, queryStringParameters);
                }
            }
            else if (Context.Request.QueryString.HasKeys())
            {
                // We need to preserve any attribute from the QueryString
                // for example in case the url has an Id
                if (WizardController.UseCurrentRouteForRedirects)
                {
                    var queryParameters = new Dictionary <string, string>();
                    foreach (var key in Query.AllKeys)
                    {
                        queryParameters.Add(key, Query[key]);
                    }
                    var parameters = UrlBuilderParameters.From(queryParameters,
                                                               wizardcontrollerContext.RouteMatch.Parameters);
                    RedirectToUrl(urlBuilder.BuildUrl(engineContext.UrlInfo, parameters));
                }
                else
                {
                    Redirect(WizardControllerContext.AreaName, wizardcontrollerContext.Name, step, Query);
                }
            }
            else
            {
                if (WizardController.UseCurrentRouteForRedirects)
                {
                    RedirectUsingRoute(step, true);
                }
                else
                {
                    Redirect(WizardControllerContext.AreaName, wizardcontrollerContext.Name, step);
                }
            }
        }
        /// <summary>
        /// Invoked when a step is accessed on the url,
        /// i.e. http://host/mywizard/firststep.rails and
        /// when an inner action is invoked like http://host/mywizard/firststep-save.rails
        /// </summary>
        /// <param name="engineContext">The engine context.</param>
        /// <param name="controller">The controller.</param>
        /// <param name="controllerContext">The controller context.</param>
        private object OnStepActionRequested(IEngineContext engineContext, IController controller, IControllerContext controllerContext)
        {
            if (currentStepInstance != null && !HasRequiredSessionData(engineContext, controller, controllerContext))
            {
                StartWizard(engineContext, controller, controllerContext, false);
            }

            controllerContext.SelectedViewName = null;

            var wizController = (IWizardController)controller;

            var wizardName  = WizardUtils.ConstructWizardNamespace(controllerContext);
            var currentStep = (String)engineContext.Session[wizardName + "currentstep"];

            // If OnBeforeStep returns false we stop
            if (!wizController.OnBeforeStep(wizardName, currentStep, currentStepInstance))
            {
                return(null);
            }

            var stepMetaDescriptor =
                engineContext.Services.ControllerDescriptorProvider.BuildDescriptor(currentStepInstance);

            // Record the step we're working with
            WizardUtils.RegisterCurrentStepInfo(engineContext, controller, controllerContext, currentStepInstance.ActionName);

            try
            {
                var stepContext =
                    engineContext.Services.ControllerContextFactory.Create(
                        controllerContext.AreaName, controllerContext.Name, innerAction,
                        stepMetaDescriptor, controllerContext.RouteMatch);
                stepContext.PropertyBag = controllerContext.PropertyBag;

                SetUpWizardHelper(engineContext, wizController, currentStepInstance, stepContext);

                // IsPreConditionSatisfied might need the controller's context
                if (currentStepInstance is Controller)
                {
                    ((Controller)currentStepInstance).Contextualize(engineContext, stepContext);
                }

                // The step cannot be accessed in the current state of matters
                if (!currentStepInstance.IsPreConditionSatisfied(engineContext))
                {
                    return(null);
                }

                currentStepInstance.Process(engineContext, stepContext);

                return(null);
            }
            finally
            {
                wizController.OnAfterStep(wizardName, currentStep, currentStepInstance);
            }
        }
Exemplo n.º 3
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.º 4
0
        /// <summary>
        /// Invoked when a step is accessed on the url,
        /// i.e. http://host/mywizard/firststep.rails and
        /// when an inner action is invoked like http://host/mywizard/firststep-save.rails
        /// </summary>
        /// <param name="controller"></param>
        private void OnStepActionRequested(Controller controller)
        {
            controller.CancelView();

            IRailsEngineContext context = controller.Context;

            IWizardController wizController = (IWizardController)controller;

            String wizardName = WizardUtils.ConstructWizardNamespace(controller);

            String currentStep = (String)context.Session[wizardName + "currentstep"];

            // The step will inherit the controller property bag,
            // this way filters can pass values to the step property without having to know it
            currentStepInstance.PropertyBag = controller.PropertyBag;

            if (!wizController.OnBeforeStep(wizardName, currentStep, currentStepInstance))
            {
                return;
            }

            WizardUtils.RegisterCurrentStepInfo(controller, currentStepInstance.ActionName);

            if (innerAction == null || innerAction == String.Empty)
            {
                currentStepInstance.Process(
                    controller.Context, controller.ServiceProvider,
                    urlInfo.Area, urlInfo.Controller, "RenderWizardView");
            }
            else
            {
                currentStepInstance.Process(
                    controller.Context, controller.ServiceProvider,
                    urlInfo.Area, urlInfo.Controller, innerAction);
            }

            wizController.OnAfterStep(wizardName, currentStep, currentStepInstance);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sends a redirect to the next wizard step (if it exists)
        /// </summary>
        /// <exception cref="MonoRailException">if no further step exists</exception>
        protected virtual void RedirectToNextStep(IDictionary queryStringParameters)
        {
            var wizardName = WizardUtils.ConstructWizardNamespace(ControllerContext);

            var currentIndex = (int)Context.Session[wizardName + "currentstepindex"];

            var stepList = (IList)Context.Items["wizard.step.list"];

            if ((currentIndex + 1) < stepList.Count)
            {
                var nextStepIndex = currentIndex + 1;

                var nextStep = (String)stepList[nextStepIndex];

                WizardUtils.RegisterCurrentStepInfo(Context, wizardParentController, ControllerContext, nextStepIndex, nextStep);

                InternalRedirectToStep(Context, nextStepIndex, nextStep, queryStringParameters);
            }
            else
            {
                throw new MonoRailException("There is no next step available");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Sends a redirect to the next wizard step (if it exists)
        /// </summary>
        /// <exception cref="RailsException">if no further step exists</exception>
        protected void RedirectToNextStep()
        {
            String wizardName = WizardUtils.ConstructWizardNamespace(_wizardcontroller);

            int currentIndex = (int)Context.Session[wizardName + "currentstepindex"];

            IList stepList = (IList)Context.UnderlyingContext.Items["wizard.step.list"];

            if ((currentIndex + 1) < stepList.Count)
            {
                int nextStepIndex = currentIndex + 1;

                String nextStep = (String)stepList[nextStepIndex];

                WizardUtils.RegisterCurrentStepInfo(_wizardcontroller, nextStepIndex, nextStep);

                InternalRedirectToStep(nextStepIndex, nextStep);
            }
            else
            {
                throw new RailsException("No next step available");
            }
        }