Esempio n. 1
0
 public void Create()
 {
     using (var context = new DataClassesDataContext())
     {
         context.CreateDatabase();
     }
 }
 public void CreateDatabase()
 {
     db = new DataClassesDataContext(Server.MapPath("App_Data/solstice.mdf"));
     if (db.DatabaseExists())
     {
         Console.WriteLine("Deleting old database...");
         db.DeleteDatabase();
     }
     db.CreateDatabase();
 }
Esempio n. 3
0
        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 = "Bob",
                    OpenIDClaimedIdentifier  = "http://localhost:4864/user/bob",
                    Age           = 27,
                    FullName      = "Bob Smith",
                    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);
                }
            }
        }
Esempio n. 4
0
        public ActionResult CreateDatabase()
        {
            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();

                // Add the necessary row for the sample client.
                dc.Clients.InsertOnSubmit(new Client {
                    ClientIdentifier = "sampleconsumer",
                    ClientSecret     = "samplesecret",
                    Name             = "Some sample client",
                });
                dc.Clients.InsertOnSubmit(new Client {
                    ClientIdentifier = "sampleImplicitConsumer",
                    Name             = "Some sample client used for implicit grants (no secret)",
                    Callback         = "http://localhost:59722/",
                });

                dc.SubmitChanges();

                // Force the user to log out because a new database warrants a new row in the users table, which we create
                // when the user logs in.
                FormsAuthentication.SignOut();
                ViewData["Success"] = true;
            } catch (SqlException ex) {
                ViewData["Error"] = string.Join("<br>", ex.Errors.OfType <SqlError>().Select(er => er.Message).ToArray());
            }

            return(this.View());
        }
Esempio n. 5
0
        public ActionResult CreateDatabase()
        {
            var dc = new DataClassesDataContext(ConnectionString);

            if (dc.DatabaseExists())
            {
                dc.DeleteDatabase();
            }
            try {
                dc.CreateDatabase();

                // Add the necessary row for the sample client.
                dc.Clients.InsertOnSubmit(new Client {
                    ClientIdentifier = "samplewebapiconsumer",
                    ClientSecret     = "samplesecret",
                    Name             = "Some sample client",
                });
                dc.Clients.InsertOnSubmit(new Client {
                    ClientIdentifier = "sampleImplicitConsumer",
                    Name             = "Some sample client used for implicit grants (no secret)",
                    Callback         = "http://localhost:59722/",
                });

                dc.SubmitChanges();

                // Force the user to log out because a new database warrants a new row in the users table, which we create
                // when the user logs in.
                FormsAuthentication.SignOut();
                ViewData["Success"] = true;
            }
            catch (SqlException ex) {
                ViewData["Error"] = string.Join("<br>", ex.Errors.OfType <SqlError>().Select(er => er.Message).ToArray());
            }

            return(this.View("Database"));
        }