1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
18 using System
.Collections
;
21 /// Utility class for wizard related queries and operations
23 public static class WizardUtils
26 /// Constructs the wizard namespace.
28 /// <param name="controllerContext">The controller context.</param>
29 /// <returns></returns>
30 public static String
ConstructWizardNamespace(IControllerContext controllerContext
)
32 return String
.Format("wizard.{0}", controllerContext
.Name
);
36 /// Determines whether the current wizard has a previous step.
38 /// <param name="engineContext">The engine context.</param>
39 /// <param name="controller">The controller.</param>
40 /// <param name="controllerContext">The controller context.</param>
42 /// <c>true</c> if has previous step; otherwise, <c>false</c>.
44 public static bool HasPreviousStep(IEngineContext engineContext
, IController controller
, IControllerContext controllerContext
)
46 String wizardName
= WizardUtils
.ConstructWizardNamespace(controllerContext
);
48 int currentIndex
= (int) engineContext
.Session
[wizardName
+ "currentstepindex"];
50 return currentIndex
> 0;
54 /// Determines whether the current wizard has a next step.
56 /// <param name="engineContext">The engine context.</param>
57 /// <param name="controller">The controller.</param>
58 /// <param name="controllerContext">The controller context.</param>
60 /// <c>true</c> if has next step; otherwise, <c>false</c>.
62 public static bool HasNextStep(IEngineContext engineContext
, IController controller
, IControllerContext controllerContext
)
64 String wizardName
= WizardUtils
.ConstructWizardNamespace(controllerContext
);
66 IList stepList
= (IList
) engineContext
.Items
["wizard.step.list"];
68 int currentIndex
= (int) engineContext
.Session
[wizardName
+ "currentstepindex"];
70 return (currentIndex
+ 1) < stepList
.Count
;
74 /// Gets the index of the current step.
76 /// <param name="engineContext">The engine context.</param>
77 /// <param name="controller">The controller.</param>
78 /// <param name="controllerContext">The controller context.</param>
79 /// <returns></returns>
80 public static int GetCurrentStepIndex(IEngineContext engineContext
, IController controller
, IControllerContext controllerContext
)
82 String wizardName
= WizardUtils
.ConstructWizardNamespace(controllerContext
);
84 int curIndex
= (int) engineContext
.Session
[wizardName
+ "currentstepindex"];
90 /// Gets the name of the current step.
92 /// <param name="engineContext">The engine context.</param>
93 /// <param name="controller">The controller.</param>
94 /// <param name="controllerContext">The controller context.</param>
95 /// <returns></returns>
96 public static String
GetCurrentStepName(IEngineContext engineContext
, IController controller
, IControllerContext controllerContext
)
98 String wizardName
= WizardUtils
.ConstructWizardNamespace(controllerContext
);
100 int curIndex
= (int) engineContext
.Session
[wizardName
+ "currentstepindex"];
102 IList stepList
= (IList
) engineContext
.Items
["wizard.step.list"];
104 return (String
) stepList
[curIndex
];
108 /// Gets the name of the previous step.
110 /// <param name="engineContext">The engine context.</param>
111 /// <param name="controller">The controller.</param>
112 /// <param name="controllerContext">The controller context.</param>
113 /// <returns></returns>
114 public static String
GetPreviousStepName(IEngineContext engineContext
, IController controller
, IControllerContext controllerContext
)
116 String wizardName
= WizardUtils
.ConstructWizardNamespace(controllerContext
);
118 int curIndex
= (int) engineContext
.Session
[wizardName
+ "currentstepindex"];
120 IList stepList
= (IList
) engineContext
.Items
["wizard.step.list"];
122 if ((curIndex
- 1) >= 0)
124 return (String
) stepList
[curIndex
- 1];
131 /// Gets the name of the next step.
133 /// <param name="index">The step index.</param>
134 /// <param name="engineContext">The engine context.</param>
135 /// <param name="controller">The controller.</param>
136 /// <param name="controllerContext">The controller context.</param>
137 /// <returns></returns>
138 public static string GetStepName(int index
, IEngineContext engineContext
, IController controller
, IControllerContext controllerContext
)
140 IList stepList
= (IList
) engineContext
.Items
["wizard.step.list"];
142 if ((index
) < stepList
.Count
)
144 return (String
) stepList
[index
];
151 /// Gets the name of the next step.
153 /// <param name="engineContext">The engine context.</param>
154 /// <param name="controller">The controller.</param>
155 /// <param name="controllerContext">The controller context.</param>
156 /// <returns></returns>
157 public static String
GetNextStepName(IEngineContext engineContext
, IController controller
, IControllerContext controllerContext
)
159 String wizardName
= WizardUtils
.ConstructWizardNamespace(controllerContext
);
161 int curIndex
= (int) engineContext
.Session
[wizardName
+ "currentstepindex"];
163 IList stepList
= (IList
) engineContext
.Items
["wizard.step.list"];
165 if ((curIndex
+ 1) < stepList
.Count
)
167 return (String
) stepList
[curIndex
+ 1];
174 /// Registers the current step info/state.
176 /// <param name="engineContext">The engine context.</param>
177 /// <param name="controller">The controller.</param>
178 /// <param name="controllerContext">The controller context.</param>
179 /// <param name="actionName">Name of the action.</param>
180 public static void RegisterCurrentStepInfo(IEngineContext engineContext
, IController controller
,
181 IControllerContext controllerContext
, String actionName
)
183 IList stepList
= (IList
) engineContext
.Items
["wizard.step.list"];
185 for(int i
= 0; i
< stepList
.Count
; i
++)
187 String stepName
= (String
) stepList
[i
];
189 if (actionName
== stepName
)
191 RegisterCurrentStepInfo(engineContext
, controller
, controllerContext
, i
, stepName
);
198 /// Registers the current step info/state.
200 /// <param name="engineContext">The engine context.</param>
201 /// <param name="controller">The controller.</param>
202 /// <param name="controllerContext">The controller context.</param>
203 /// <param name="stepIndex">Index of the step.</param>
204 /// <param name="stepName">Name of the step.</param>
205 public static void RegisterCurrentStepInfo(IEngineContext engineContext
, IController controller
,
206 IControllerContext controllerContext
, int stepIndex
, String stepName
)
208 String wizardName
= WizardUtils
.ConstructWizardNamespace(controllerContext
);
210 engineContext
.Session
[wizardName
+ "currentstepindex"] = stepIndex
;
211 engineContext
.Session
[wizardName
+ "currentstep"] = stepName
;