Changed the way the paths from AssemblySourceInfo will be returned, will use \ instea...
[castle.git] / MonoRail / Castle.MonoRail.Framework / Internal / WizardUtils.cs
blobae01574b76453f03150242b08525a7048e41a56f
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.Framework.Internal
17 using System;
18 using System.Collections;
20 /// <summary>
21 /// Utility class for wizard related queries and operations
22 /// </summary>
23 public static class WizardUtils
25 /// <summary>
26 /// Constructs the wizard namespace.
27 /// </summary>
28 /// <param name="controller">The controller.</param>
29 /// <returns></returns>
30 public static String ConstructWizardNamespace(Controller controller)
32 if (controller is WizardStepPage)
34 return ConstructWizardNamespace( (controller as WizardStepPage).WizardController );
37 return String.Format("wizard.{0}", controller.Name);
40 /// <summary>
41 /// Determines whether the current wizard has a previous step.
42 /// </summary>
43 /// <param name="controller">The controller.</param>
44 /// <returns>
45 /// <c>true</c> if has previous step; otherwise, <c>false</c>.
46 /// </returns>
47 public static bool HasPreviousStep(Controller controller)
49 IRailsEngineContext context = controller.Context;
51 String wizardName = WizardUtils.ConstructWizardNamespace(controller);
53 int currentIndex = (int) context.Session[wizardName + "currentstepindex"];
55 return currentIndex > 0;
58 /// <summary>
59 /// Determines whether the current wizard has a next step.
60 /// </summary>
61 /// <param name="controller">The controller.</param>
62 /// <returns>
63 /// <c>true</c> if has next step; otherwise, <c>false</c>.
64 /// </returns>
65 public static bool HasNextStep(Controller controller)
67 IRailsEngineContext context = controller.Context;
69 String wizardName = WizardUtils.ConstructWizardNamespace(controller);
71 IList stepList = (IList) context.Items["wizard.step.list"];
73 int currentIndex = (int) context.Session[wizardName + "currentstepindex"];
75 return (currentIndex + 1) < stepList.Count;
78 /// <summary>
79 /// Gets the name of the previous step.
80 /// </summary>
81 /// <param name="controller">The controller.</param>
82 /// <returns></returns>
83 public static String GetPreviousStepName(Controller controller)
85 IRailsEngineContext context = controller.Context;
87 String wizardName = WizardUtils.ConstructWizardNamespace(controller);
89 int curIndex = (int) context.Session[wizardName + "currentstepindex"];
91 IList stepList = (IList) context.Items["wizard.step.list"];
93 if ((curIndex - 1) >= 0)
95 return (String) stepList[curIndex - 1];
98 return null;
101 /// <summary>
102 /// Gets the name of the next step.
103 /// </summary>
104 /// <param name="controller">The controller.</param>
105 /// <returns></returns>
106 public static String GetNextStepName(Controller controller)
108 IRailsEngineContext context = controller.Context;
110 String wizardName = WizardUtils.ConstructWizardNamespace(controller);
112 int curIndex = (int) context.Session[wizardName + "currentstepindex"];
114 IList stepList = (IList) context.Items["wizard.step.list"];
116 if ((curIndex + 1) < stepList.Count)
118 return (String) stepList[curIndex + 1];
121 return null;
124 /// <summary>
125 /// Registers the current step info/state.
126 /// </summary>
127 /// <param name="controller">The controller.</param>
128 /// <param name="actionName">Name of the action.</param>
129 public static void RegisterCurrentStepInfo(Controller controller, String actionName)
131 IRailsEngineContext context = controller.Context;
133 IList stepList = (IList) context.Items["wizard.step.list"];
135 for(int i=0; i < stepList.Count; i++)
137 String stepName = (String) stepList[i];
139 if (actionName == stepName)
141 RegisterCurrentStepInfo(controller, i, stepName);
143 break;
148 /// <summary>
149 /// Registers the current step info/state.
150 /// </summary>
151 /// <param name="controller">The controller.</param>
152 /// <param name="stepIndex">Index of the step.</param>
153 /// <param name="stepName">Name of the step.</param>
154 public static void RegisterCurrentStepInfo(Controller controller, int stepIndex, String stepName)
156 IRailsEngineContext context = controller.Context;
157 String wizardName = WizardUtils.ConstructWizardNamespace(controller);
159 context.Session[wizardName + "currentstepindex"] = stepIndex;
160 context.Session[wizardName + "currentstep"] = stepName;