Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / TestSiteBrail / Controllers / AsyncController.cs
blob82beafab8e2414d1e95b6a39354f7647c24a11ea
1 // Copyright 2004-2008 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 TestSiteBrail.Controllers
17 using System;
18 using Castle.MonoRail.Framework;
20 [Layout("master")]
21 public class AsyncController : SmartDispatcherController
23 #region Delegates
25 public delegate string Output();
27 #endregion
29 private Output output;
32 public IAsyncResult BeginWithParams(int id, string name)
34 PropertyBag["id"] = id;
35 PropertyBag["name"] = name;
36 return CallAsync();
39 public void EndWithParams()
41 PropertyBag["value"] = output.EndInvoke(ControllerContext.Async.Result);
45 public IAsyncResult BeginIndex()
47 return CallAsync();
50 public void EndIndex()
52 string s = output.EndInvoke(ControllerContext.Async.Result);
53 RenderText(s);
56 public IAsyncResult BeginWithView()
58 return CallAsync();
61 public void EndWithView()
63 PropertyBag["value"] = output.EndInvoke(ControllerContext.Async.Result);
66 public IAsyncResult BeginWithViewAndLayout()
68 return CallAsync();
71 public void EndWithViewAndLayout()
73 PropertyBag["value"] = output.EndInvoke(ControllerContext.Async.Result);
76 public IAsyncResult BeginErrorBegin()
78 throw new InvalidCastException("test error on begin");
81 public void EndErrorBegin()
83 PropertyBag["value"] = output.EndInvoke(ControllerContext.Async.Result);
87 public IAsyncResult BeginErrorAsync()
89 return CallThrowingAsync();
92 public void EndErrorAsync()
94 PropertyBag["value"] = output.EndInvoke(ControllerContext.Async.Result);
98 public IAsyncResult BeginErrorEnd()
100 return CallAsync();
103 public void EndErrorEnd()
105 throw new InvalidOperationException("test error from end");
108 public IAsyncResult BeginWithRescueAsync()
110 return CallThrowingAsync();
114 [Rescue("UpdateErrorMsg")]
115 public void EndWithRescueAsync()
117 PropertyBag["value"] = output.EndInvoke(ControllerContext.Async.Result);
120 [Rescue("UpdateErrorMsg")]
121 public IAsyncResult BeginWithRescueBegin()
123 throw new InvalidCastException("test error on rescue");
126 public void EndWithRescueBegin()
128 PropertyBag["value"] = output.EndInvoke(ControllerContext.Async.Result);
131 public IAsyncResult BeginWithRescueEnd()
133 return CallAsync();
136 [Rescue("UpdateErrorMsg")]
137 public void EndWithRescueEnd()
139 throw new InvalidCastException("error from end");
142 public IAsyncResult BeginWithActionLayout()
144 return CallAsync();
147 [Layout("defaultlayout")]
148 public void EndWithActionLayout()
150 PropertyBag["value"] = output.EndInvoke(ControllerContext.Async.Result);
153 [Rescue("UpdateErrorMsg")]
154 [Layout("defaultlayout")]
155 public IAsyncResult BeginRescueOnBeginActionLayout()
157 throw new InvalidOperationException("blah");
160 public void EndRescueOnBeginActionLayout()
164 private IAsyncResult CallThrowingAsync()
166 output = Throw;
167 return output.BeginInvoke(ControllerContext.Async.Callback, ControllerContext.Async.State);
170 private string Throw()
172 throw new InvalidOperationException("error from async");
175 private IAsyncResult CallAsync()
177 output = GetString;
178 return output.BeginInvoke(
179 ControllerContext.Async.Callback,
180 ControllerContext.Async.State);
183 public string GetString()
185 return "value from async task";