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 TestSiteBrail
.Controllers
18 using Castle
.MonoRail
.Framework
;
21 public class AsyncController
: SmartDispatcherController
25 public delegate string Output();
29 private Output output
;
32 public IAsyncResult
BeginWithParams(int id
, string name
)
34 PropertyBag
["id"] = id
;
35 PropertyBag
["name"] = name
;
39 public void EndWithParams()
41 PropertyBag
["value"] = output
.EndInvoke(ControllerContext
.Async
.Result
);
45 public IAsyncResult
BeginIndex()
50 public void EndIndex()
52 string s
= output
.EndInvoke(ControllerContext
.Async
.Result
);
56 public IAsyncResult
BeginWithView()
61 public void EndWithView()
63 PropertyBag
["value"] = output
.EndInvoke(ControllerContext
.Async
.Result
);
66 public IAsyncResult
BeginWithViewAndLayout()
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()
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()
136 [Rescue("UpdateErrorMsg")]
137 public void EndWithRescueEnd()
139 throw new InvalidCastException("error from end");
142 public IAsyncResult
BeginWithActionLayout()
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()
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()
178 return output
.BeginInvoke(
179 ControllerContext
.Async
.Callback
,
180 ControllerContext
.Async
.State
);
183 public string GetString()
185 return "value from async task";