Changed to use Authenticate asp.net event instead of Authorize
[castle.git] / Samples / ActiveRecord / BlogSample / App.cs
blobd421cdc26e4394a6dc658520397ec2cfd6f76336
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 BlogSample
17 using System.Windows.Forms;
19 using BlogSample.UI;
21 using Castle.ActiveRecord;
22 using Castle.ActiveRecord.Framework.Config;
24 public class App
26 public static void Main()
28 // 1. Step Configure and Initialize ActiveRecord:
30 // If you want to use the InPlaceConfigurationSource:
31 // Hashtable properties = new Hashtable();
32 // properties.Add("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver");
33 // properties.Add("hibernate.dialect", "NHibernate.Dialect.MsSql2000Dialect");
34 // properties.Add("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider");
35 // properties.Add("hibernate.connection.connection_string", "Data Source=.;Initial Catalog=test;Integrated Security=SSPI");
36 // InPlaceConfigurationSource source = new InPlaceConfigurationSource();
37 // source.Add(typeof(ActiveRecordBase), properties);
39 // We are using XmlConfigurationSource:
40 XmlConfigurationSource source = new XmlConfigurationSource("../appconfig.xml");
42 ActiveRecordStarter.Initialize( source, typeof(Blog), typeof(Post), typeof(User) );
44 // 2. Create the schema
46 // If you want to let AR to create the schema
47 if (MessageBox.Show("Do you want to let ActiveRecord create the database tables?", "Schema", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
49 ActiveRecordStarter.CreateSchema();
52 // 3. Create the first user (so you can log in)
54 if (User.GetUsersCount() == 0)
56 User user = new User("admin", "123");
58 user.Create();
61 // 4. Bring the Login Form
63 using(LoginForm login = new LoginForm())
65 if (login.ShowDialog() != DialogResult.OK)
67 return;
71 // 5. Show the main form
73 using(BlogManagement mainForm = new BlogManagement())
75 Application.Run(mainForm);