Exemplo n.º 1
0
 public static void CreateLegacyTable()
 {
     // Check if the DB table does NOT exist
     if (!_db.TableExist(_dbName))
     {
         //Create DB table - and set overwrite to false
         _db.CreateTable <AcProductDto>(false);
     }
 }
Exemplo n.º 2
0
        public IReadOnlyList <MigrationRecord> GetAll()
        {
            if (!_database.TableExist(MigrationRecord.DefaultTableName))
            {
                return(new MigrationRecord[0]);
            }

            return(_database.Fetch <MigrationRecord>("where 1=1"));
        }
Exemplo n.º 3
0
 static void EnsureTableExists(UmbracoDatabase database)
 {
     if (!database.TableExist(Visitor.TableName))
     {
         database.CreateTable <Visitor>();
     }
 }
Exemplo n.º 4
0
 static void EnsureTableExists(UmbracoDatabase database)
 {
     if (!database.TableExist(VisitorMongoMapping.DatabaseName))
     {
         database.CreateTable <VisitorMongoMapping>();
     }
 }
Exemplo n.º 5
0
 public override void Up()
 {
     if (!_db.TableExist("PublishQueue"))
     {
         _db.CreateTable <QueuedItem>(false);
     }
 }
Exemplo n.º 6
0
 public ContactForm()
 {
     _database = ApplicationContext.Current.DatabaseContext.Database;
     if (!_database.TableExist("ContactForm"))
     {
         _database.CreateTable <ContactFormPoco>();
     }
 }
Exemplo n.º 7
0
 public ExternalLoginStore()
 {
     if (!System.IO.File.Exists(IOHelper.MapPath("~/App_Data/UmbracoIdentity.sdf")))
     {
         using (var en = new SqlCeEngine(ConnString))
         {
             en.CreateDatabase();
         }
     }
     _db = new UmbracoDatabase(ConnString, "System.Data.SqlServerCe.4.0");
     if (!_db.TableExist("ExternalLogins"))
     {
         _db.CreateTable <ExternalLoginDto>();
     }
 }
Exemplo n.º 8
0
        public ExternalLoginStore()
        {
            if (identityStoreConnection == null)
            {
                throw new ConfigurationException("UmbracoIdentityStore is not set in the configuration");
            }

            _db = new UmbracoDatabase(identityStoreConnection.ConnectionString, "System.Data.SqlClient");
            if (!_db.TableExist("ExternalLogins"))
            {
                //unfortunately we'll get issues if we just try this because of differing sql syntax providers. In newer
                // umbraco versions we'd just use the DatabaseSchemaHelper. So in the meantime we have to just
                // do this manually and use reflection :(;
                _db.CreateTable <ExternalLoginDto>();
            }
        }
Exemplo n.º 9
0
        public ExternalLoginStore()
        {
            if (!System.IO.File.Exists(IOHelper.MapPath("~/App_Data/UmbracoIdentity.sdf")))
            {
                using (var en = new SqlCeEngine(ConnString))
                {
                    en.CreateDatabase();
                }
            }

            _db = new UmbracoDatabase(ConnString, "System.Data.SqlServerCe.4.0");
            if (!_db.TableExist("ExternalLogins"))
            {
                //unfortunately we'll get issues if we just try this because of differing sql syntax providers. In newer
                // umbraco versions we'd just use the DatabaseSchemaHelper. So in the meantime we have to just
                // do this manually and use reflection :(;
                //_db.CreateTable<ExternalLoginDto>();

                var sqlceProvider = new SqlCeSyntaxProvider();
                CreateTable(false, typeof(ExternalLoginDto), sqlceProvider);
            }
        }
Exemplo n.º 10
0
        private void CreateTable(bool overwrite, Type modelType, SqlCeSyntaxProvider syntaxProvider)
        {
            var defFactoryType  = Type.GetType("Umbraco.Core.Persistence.DatabaseModelDefinitions.DefinitionFactory,Umbraco.Core", true);
            var tableDefinition = (TableDefinition)defFactoryType.CallStaticMethod("GetTableDefinition", modelType);

            var tableName = tableDefinition.Name;

            string createSql           = syntaxProvider.Format(tableDefinition);
            string createPrimaryKeySql = syntaxProvider.FormatPrimaryKey(tableDefinition);
            var    foreignSql          = syntaxProvider.Format(tableDefinition.ForeignKeys);
            var    indexSql            = syntaxProvider.Format(tableDefinition.Indexes);

            var tableExist = _db.TableExist(tableName);

            if (overwrite && tableExist)
            {
                _db.DropTable(tableName);
                tableExist = false;
            }

            if (tableExist == false)
            {
                using (var transaction = _db.GetTransaction())
                {
                    //Execute the Create Table sql
                    int created = _db.Execute(new Sql(createSql));
                    LogHelper.Info <ExternalLoginStore>(string.Format("Create Table sql {0}:\n {1}", created, createSql));

                    //If any statements exists for the primary key execute them here
                    if (!string.IsNullOrEmpty(createPrimaryKeySql))
                    {
                        int createdPk = _db.Execute(new Sql(createPrimaryKeySql));
                        LogHelper.Info <ExternalLoginStore>(string.Format("Primary Key sql {0}:\n {1}", createdPk, createPrimaryKeySql));
                    }

                    //Turn on identity insert if db provider is not mysql
                    if (syntaxProvider.SupportsIdentityInsert() && tableDefinition.Columns.Any(x => x.IsIdentity))
                    {
                        _db.Execute(new Sql(string.Format("SET IDENTITY_INSERT {0} ON ", syntaxProvider.GetQuotedTableName(tableName))));
                    }

                    //Turn off identity insert if db provider is not mysql
                    if (syntaxProvider.SupportsIdentityInsert() && tableDefinition.Columns.Any(x => x.IsIdentity))
                    {
                        _db.Execute(new Sql(string.Format("SET IDENTITY_INSERT {0} OFF;", syntaxProvider.GetQuotedTableName(tableName))));
                    }

                    //Loop through foreignkey statements and execute sql
                    foreach (var sql in foreignSql)
                    {
                        int createdFk = _db.Execute(new Sql(sql));
                        LogHelper.Info <ExternalLoginStore>(string.Format("Create Foreign Key sql {0}:\n {1}", createdFk, sql));
                    }

                    //Loop through index statements and execute sql
                    foreach (var sql in indexSql)
                    {
                        int createdIndex = _db.Execute(new Sql(sql));
                        LogHelper.Info <ExternalLoginStore>(string.Format("Create Index sql {0}:\n {1}", createdIndex, sql));
                    }

                    transaction.Complete();
                }
            }

            LogHelper.Info <ExternalLoginStore>(string.Format("New table '{0}' was created", tableName));
        }
Exemplo n.º 11
0
        private static void CreateDataBase(UmbracoDatabase db)
        {
            if (!db.TableExist("ContactMessage"))
            {
                db.CreateTable <ContactPoco>(false);
            }

            if (!db.TableExist("ContactSettings"))
            {
                db.CreateTable <ContactSettings>(false);
                var settingsTwo = new List <ContactSettings>()
                {
                    new ContactSettings()
                    {
                        ConfigName   = "PageSize",
                        ConfigValue  = "10",
                        ConfigText   = "Page Size",
                        ConfigHelper = "",
                        ConfigSort   = 9
                    },
                    new ContactSettings()
                    {
                        ConfigName   = "AutoReplyMessage",
                        ConfigValue  = "Thanks for contacting us",
                        ConfigText   = "Auto Reply Message",
                        ConfigHelper = "",
                        ConfigSort   = 3
                    },
                    new ContactSettings()
                    {
                        ConfigName   = "TemplateNode",
                        ConfigValue  = "",
                        ConfigText   = "Auto Reply Template",
                        ConfigHelper = "",
                        ConfigSort   = 4
                    },
                    new ContactSettings()
                    {
                        ConfigName   = "SendNotificationTo",
                        ConfigValue  = "",
                        ConfigText   = "Send Notification To",
                        ConfigHelper = "*Use commas to include multiple email",
                        ConfigSort   = 7
                    },
                    new ContactSettings()
                    {
                        ConfigName   = "NotificationMessage",
                        ConfigValue  = "You have new message from %name%",
                        ConfigText   = "Notification Message",
                        ConfigHelper = "",
                        ConfigSort   = 6
                    },
                    new ContactSettings()
                    {
                        ConfigName   = "AutoReplySubject",
                        ConfigValue  = "Thanks for contacting us %name%",
                        ConfigText   = "Auto Reply Subject",
                        ConfigHelper = "",
                        ConfigSort   = 2
                    },
                    new ContactSettings()
                    {
                        ConfigName   = "NotificationSubject",
                        ConfigValue  = "New message from %name%",
                        ConfigText   = "Notification Subject",
                        ConfigHelper = "",
                        ConfigSort   = 5
                    },
                    new ContactSettings()
                    {
                        ConfigName   = "NotificationTemplateNode",
                        ConfigValue  = "",
                        ConfigText   = "Notification Template",
                        ConfigHelper = "",
                        ConfigSort   = 8
                    },
                    new ContactSettings()
                    {
                        ConfigName   = "SenderEmail",
                        ConfigValue  = "*****@*****.**",
                        ConfigText   = "Sender Email",
                        ConfigHelper = "",
                        ConfigSort   = 0
                    },
                    new ContactSettings()
                    {
                        ConfigName   = "DisplayNameSender",
                        ConfigValue  = "Noreply You Website",
                        ConfigText   = "Display Name Sender",
                        ConfigHelper = "",
                        ConfigSort   = 1
                    }
                };

                db.BulkInsertRecords(settingsTwo);

                db.Execute(
                    "CREATE TABLE uContactorVersion (DbVersion INT)");

                db.Execute(
                    "INSERT INTO uContactorVersion values(1)");
            }
        }
Exemplo n.º 12
0
        public override async Task <DeliverableResponse> Run(string command, string[] args)
        {
            var dbNotReady = false;

            try
            {
                if (!database.TableExist(TableName))
                {
                    if (!await SetupDatabase())
                    {
                        return(DeliverableResponse.FinishedWithError);
                    }
                }
            }
            catch (DbException)
            {
                Out.WriteLine("There was an error checking for the database Chauffeur Delivery tracking table, most likely your connection string is invalid or your database doesn't exist.");
                Out.WriteLine("Chauffeur will attempt to run the first delivery, expecting it to call `install`.");
                dbNotReady = true;
            }

            string directory;

            if (!settings.TryGetChauffeurDirectory(out directory))
            {
                await Out.WriteLineAsync("Error accessing the Chauffeur directory. Check your file system permissions");

                return(DeliverableResponse.Continue);
            }

            var allDeliveries = fileSystem.Directory
                                .GetFiles(directory, "*.delivery", SearchOption.TopDirectoryOnly)
                                .ToArray();

            if (!allDeliveries.Any())
            {
                await Out.WriteLineAsync("No deliveries found.");

                return(DeliverableResponse.Continue);
            }

            if (dbNotReady)
            {
                try
                {
                    var delivery = allDeliveries.First();
                    var file     = fileSystem.FileInfo.FromFileName(delivery);

                    var tracking = await Deliver(file);

                    if (!tracking.SignedFor)
                    {
                        return(DeliverableResponse.FinishedWithError);
                    }

                    if (!await SetupDatabase())
                    {
                        return(DeliverableResponse.FinishedWithError);
                    }

                    database.Save(tracking);

                    allDeliveries = allDeliveries.Skip(1).ToArray();
                }
                catch (DbException)
                {
                    Out.WriteLine("Ok, I tried. Chauffeur had a database error, either a missing connection string or the DB couldn't be setup.");
                    return(DeliverableResponse.FinishedWithError);
                }
            }

            await ProcessDeliveries(allDeliveries);

            return(DeliverableResponse.Continue);
        }