summaryrefslogtreecommitdiffstats
path: root/src/OAuth/OAuthServiceProvider/Default.aspx.cs
blob: 653046a8a8a66c2050adec9a518e3c5e21ec9e55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
namespace OAuthServiceProvider {
	using System;
	using System.Collections.Generic;
	using System.Configuration;
	using System.IO;
	using System.Linq;
	using System.Web;
	using OAuthServiceProvider.Code;

	public partial class _Default : System.Web.UI.Page {
		protected void createDatabaseButton_Click(object sender, EventArgs e) {
			string databasePath = Path.Combine(Server.MapPath(Request.ApplicationPath), "App_Data");
			if (!Directory.Exists(databasePath)) {
				Directory.CreateDirectory(databasePath);
			}
			string connectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString.Replace("|DataDirectory|", databasePath);
			var dc = new DataClassesDataContext(connectionString);
			if (dc.DatabaseExists()) {
				dc.DeleteDatabase();
			}
			try {
				dc.CreateDatabase();

				// Fill with sample data.
				dc.OAuthConsumers.InsertOnSubmit(new OAuthConsumer {
					ConsumerKey = "sampleconsumer",
					ConsumerSecret = "samplesecret",
				});
				dc.Users.InsertOnSubmit(new User {
					OpenIDFriendlyIdentifier = "=arnott",
					OpenIDClaimedIdentifier = "=!9B72.7DD1.50A9.5CCD",
					Age = 27,
					FullName = "Andrew Arnott",
					FavoriteSites = new System.Data.Linq.EntitySet<FavoriteSite> {
					new FavoriteSite { SiteUrl = "http://www.microsoft.com" },
					new FavoriteSite { SiteUrl = "http://www.google.com" },
				},
				});

				dc.SubmitChanges();
				this.databaseStatus.Visible = true;
			} catch (System.Data.SqlClient.SqlException ex) {
				foreach (System.Data.SqlClient.SqlError error in ex.Errors) {
					Response.Write(error.Message);
				}
			}
		}
	}
}