public void CreateDatabaseSchema(DatabaseType dbType, bool? skipInstaller)
        {
            //Depending on DB Type - Change Provider
            if (dbType == DatabaseType.MySQL)
            {
                SqlSyntaxContext.SqlSyntaxProvider = new MySqlSyntaxProvider();
            }
            else if (dbType == DatabaseType.SQLCE)
            {
                SqlSyntaxContext.SqlSyntaxProvider = new SqlCeSyntaxProvider();

                //Create a path to an Umbraco.sdf file in App_Data
                var path = Path.Combine(umbracoSitePath, "App_Data", "Umbraco.sdf");

                //Modified Connection String for CE creation
                var modConnection = string.Format("Data Source={0};Flush Interval=1;", path);

                //Update connection string
                connectionString = modConnection;
            }
            else
            {
                SqlSyntaxContext.SqlSyntaxProvider = new SqlServerSyntaxProvider();
            }

            //Create a new Umbraco DB object using connection details
            var db = new UmbracoDatabase(connectionString, providerName);

            //Create DB Schema
            //Get the method we want to run
            var methodToRun = typeof (PetaPocoExtensions).GetMethod("CreateDatabaseSchema", BindingFlags.Static | BindingFlags.NonPublic);

            //Invoke the Method - CreateDatabaseSchema(db, false)
            methodToRun.Invoke(null, new object[]{ db, false });

            //Only Add/Update default admin user of admin/admin
            if (skipInstaller == true)
            {
                //Add/update default admin user of admin/admin
                db.Update<UserDto>("set userPassword = @password where id = @id", new { password = "******", id = 0 });
            }
        }
Exemplo n.º 2
0
 private void CreateAndSaveContentXml(XElement xml, int id, UmbracoDatabase db)
 {
     var contentPoco = new ContentXmlDto { NodeId = id, Xml = xml.ToString(SaveOptions.None) };
     var contentExists = db.ExecuteScalar<int>("SELECT COUNT(nodeId) FROM cmsContentXml WHERE nodeId = @Id", new { Id = id }) != 0;
     int contentResult = contentExists ? db.Update(contentPoco) : Convert.ToInt32(db.Insert(contentPoco));
 }
Exemplo n.º 3
0
 private void CreateAndSaveMediaXml(XElement xml, int id, UmbracoDatabase db)
 {
     var poco = new ContentXmlDto { NodeId = id, Xml = xml.ToString(SaveOptions.None) };
     var exists = db.FirstOrDefault<ContentXmlDto>("WHERE nodeId = @Id", new { Id = id }) != null;
     int result = exists ? db.Update(poco) : Convert.ToInt32(db.Insert(poco));
 }
Exemplo n.º 4
0
 private void CreateAndSavePreviewXml(XElement xml, int id, Guid version, UmbracoDatabase db)
 {
     var previewPoco = new PreviewXmlDto
     {
         NodeId = id,
         Timestamp = DateTime.Now,
         VersionId = version,
         Xml = xml.ToString(SaveOptions.None)
     };
     var previewExists =
         db.ExecuteScalar<int>("SELECT COUNT(nodeId) FROM cmsPreviewXml WHERE nodeId = @Id AND versionId = @Version",
                                         new { Id = id, Version = version }) != 0;
     int previewResult = previewExists
                             ? db.Update<PreviewXmlDto>(
                                 "SET xml = @Xml, timestamp = @Timestamp WHERE nodeId = @Id AND versionId = @Version",
                                 new
                                     {
                                         Xml = previewPoco.Xml,
                                         Timestamp = previewPoco.Timestamp,
                                         Id = previewPoco.NodeId,
                                         Version = previewPoco.VersionId
                                     })
                             : Convert.ToInt32(db.Insert(previewPoco));
 }