- Changed ReflectionBasedDictionaryAdapter to ignore calls to Remove instead of throw...
[castle.git] / MonoRail / TestSiteNVelocity / Controllers / SmartController.cs
blob77f902c013365da2ea3f4af90ad39e262f8bd163
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 TestSiteNVelocity.Controllers
17 using System;
19 using Castle.MonoRail.Framework;
21 using Nullables;
24 public class SmartController : SmartDispatcherController
26 public SmartController()
30 public void StringMethod(string name)
32 RenderText("incoming " + name);
35 public void Complex(string strarg, int intarg, String[] strarray)
37 RenderText(String.Format("incoming {0} {1} {2}", strarg, intarg, String.Join(",", strarray)));
40 public void SimpleBind([DataBind("order")] Order order)
42 RenderText(String.Format("incoming {0}", order.ToString()));
45 public void SimpleBindArray([DataBind("orders")] Order[] orders)
47 if (orders == null)
49 RenderText("Null array shouldn't be returned by databinder");
51 else
53 RenderText(String.Format("incoming {0}", orders.Length));
57 public void ComplexBind([DataBind("order")] Order order, [DataBind("person")] Person person)
59 RenderText(String.Format("incoming {0} {1}", order.ToString(), person.ToString()));
62 public void ComplexBindExcludePrice([DataBind("order", Exclude="order.Price")] Order order, [DataBind("person")] Person person)
64 RenderText(String.Format("incoming {0} {1}", order.ToString(), person.ToString()));
67 public void ComplexBindExcludeName([DataBind("order", Exclude="order.Name")] Order order, [DataBind("person")] Person person)
69 RenderText(String.Format("incoming {0} {1}", order.ToString(), person.ToString()));
72 public void ComplexBindWithPrefix([DataBind("order")] Order order, [DataBind("person")] Person person)
74 RenderText(String.Format("incoming {0} {1}", order.ToString(), person.ToString()));
77 public void FillingBehavior([DataBind("abc")] ClassWithInitializers clazz)
79 System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
81 RenderText(String.Format("incoming {0} {1} {2}", clazz.Name, clazz.Date1.ToShortDateString(), clazz.Date2.ToShortDateString()));
84 public void NullableConversion(Nullables.NullableDouble amount)
86 RenderText(String.Format("incoming {0} {1}", amount.HasValue, amount.ToString()));
89 public void NullableConversion2([DataBind("mov")] Movement movement)
91 RenderText(String.Format("incoming {0} {1}", movement.Name, movement.Amount.ToString()));
94 public void ArrayBinding([DataBind("user")] User2 user)
96 RenderText(user.ToString());
98 foreach(int id in user.Roles)
100 RenderText(" " + id);
102 foreach(int id in user.Permissions)
104 RenderText(" " + id);
108 public void CalculateUtilizationByDay([DataBind("tp1")] TimePoint tp1, [DataBind("tp2")] TimePoint tp2)
110 RenderText(tp1.ToString());
111 RenderText(tp2.ToString());
115 public class ClassWithInitializers
117 private String name;
118 private DateTime date1;
119 private DateTime date2;
121 public ClassWithInitializers()
123 name = "hammett";
124 date1 = DateTime.Now;
125 date2 = DateTime.Now.AddDays(1);
128 public string Name
130 get { return name; }
131 set { name = value; }
134 public DateTime Date1
136 get { return date1; }
137 set { date1 = value; }
140 public DateTime Date2
142 get { return date2; }
143 set { date2 = value; }
147 public class Order
149 private String name;
150 private int itemCount;
151 private float price;
153 public string Name
155 get { return name; }
156 set { name = value; }
159 public int ItemCount
161 get { return itemCount; }
162 set { itemCount = value; }
165 public float Price
167 get { return price; }
168 set { price = value; }
171 public override string ToString()
173 return String.Format("{0} {1} {2}", name, itemCount, price);
177 public class Person
179 String id;
180 Contact contact;
182 public string Id
184 get { return id; }
185 set { id = value; }
188 public Contact Contact
190 get { return contact; }
191 set { contact = value; }
194 public override string ToString()
196 return String.Format("{0} {1}", id, contact);
200 public class Contact
202 String email, phone;
204 public Contact()
208 public Contact(string email, string phone)
210 this.email = email;
211 this.phone = phone;
214 public string Email
216 get { return email; }
217 set { email = value; }
220 public string Phone
222 get { return phone; }
223 set { phone = value; }
226 public override string ToString()
228 return String.Format("{0} {1}", email, phone);
232 public class Movement
234 String name; Nullables.NullableDouble amount;
236 public string Name
238 get { return name; }
239 set { name = value; }
242 public NullableDouble Amount
244 get { return amount; }
245 set { amount = value; }
249 public class User2
251 String name; int[] roles; int[] permissions;
253 public string Name
255 get { return name; }
256 set { name = value; }
259 public int[] Roles
261 get { return roles; }
262 set { roles = value; }
265 public int[] Permissions
267 get { return permissions; }
268 set { permissions = value; }
271 public override string ToString()
273 return String.Format("User {0} {1} {2}", name, roles.Length, permissions.Length);
277 public class TimePoint : IComparable
279 private int _hour;
280 private int _minute;
281 private int _second;
283 public TimePoint()
288 public TimePoint(int hour, int minute, int second)
290 _hour = hour;
291 _minute = minute;
292 _second = second;
295 public int Hour
297 get { return _hour; }
298 set { _hour = value; }
301 public int Minute
303 get { return _minute; }
304 set { _minute = value; }
307 public int Second
309 get { return _second; }
310 set { _second = value; }
313 public override string ToString()
315 return String.Format(" {0}:{1}:{2} ", _hour, _minute, _second);
318 public int CompareTo(object obj)
320 throw new NotImplementedException();