Exemplo n.º 1
0
        protected void CreateStore(Boolean UpdateStore)
        {
            if (StoreExists)
            {
                if (!UpdateStore)
                {
                    throw new StoreAlreadyExistsException();
                }
            }
            else
            {
#if (!WINDOWS_PHONE)
                SQLiteConnection.CreateFile(FileName);
#endif
            }

            var connection = GetConnection(true);
            try
            {
                foreach (var entity in this.Entities)
                {
                    CreateTable(connection, entity);
                }
            }
            finally
            {
                DoneWithConnection(connection, true);
            }
        }
Exemplo n.º 2
0
        public EntityStore(string databaseFullPath, DestructorType destructorType = DestructorType.None)
        {
            _databaseFullPath = databaseFullPath;
            _destructorType   = destructorType;
            _connectionString = String.Format("Data Source={0}; Version=3; Read Only=False; Pooling=True; Max Pool Size=10", _databaseFullPath);

            if (!File.Exists(_databaseFullPath))
            {
                SQLiteConnection.CreateFile(_databaseFullPath);
                Log.Info("Successfully created the EntityStore database file at {0}", databaseFullPath);
            }
            else
            {
                Log.Info("Successfully confirmed that the EntityStore database exists at {0}", databaseFullPath);
            }

            using (var connection = new SQLiteConnection(_connectionString))
            {
                connection.Open();
                using (var cmd = connection.CreateCommand())
                {
                    Log.Debug("About to create or check for the Entities table in the EntityStore database.");
                    cmd.CommandText = "CREATE TABLE IF NOT EXISTS Entities (entityType TEXT, entityKey TEXT, entityBlob TEXT, entityTag TEXT, lastModified DATETIME, PRIMARY KEY (entityType, entityKey))";
                    cmd.CommandType = CommandType.Text;
                    cmd.ExecuteNonQuery();
                    Log.Info("Successfully created or checked that the Entities table exists in the EntityStore database.");
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates the database.
        /// </summary>
        public void Create()
        {
            var filePath = new FileInfo(dataSourcePath);

            if (!filePath.Exists)
            {
                SQLiteConnection.CreateFile(dataSourcePath);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates the database.
        /// </summary>
        public void Create()
        {
#if !NETCORE
            var filePath = new FileInfo(dataSourcePath);
            if (!filePath.Exists)
            {
                SQLiteConnection.CreateFile(dataSourcePath);
            }
#endif
        }
Exemplo n.º 5
0
        private void CreateDbIfNotExists()
        {
            string path = Path.Combine(this.DBDirectory, this.DBName);

            if (!File.Exists(path))
            {
                Directory.CreateDirectory(this.DBDirectory);
                SQLiteConnectionAlias.CreateFile(Path.Combine(this.DBDirectory, this.DBName));
            }
        }
Exemplo n.º 6
0
        public static void Setup(bool useLocalFiles)
        {
            DataDirectory = new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Gablarski"));
            if (!DataDirectory.Exists)
            {
                DataDirectory.Create();
            }

            if (useLocalFiles)
            {
                KeyFile = new FileInfo("gablarski.key");
                DbFile  = new FileInfo("gablarski.db");
            }
            else
            {
                KeyFile = new FileInfo(Path.Combine(DataDirectory.FullName, "gablarski.key"));
                DbFile  = new FileInfo(Path.Combine(DataDirectory.FullName, "gablarski.db"));
            }

                        #if !XAMARIN
            var builder = new SQLiteConnectionStringBuilder();
            builder.DataSource = DbFile.FullName;

            db = new SQLiteConnection(builder.ToString());
                        #else
            KeyFile = new FileInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), KeyFile.Name));
            DbFile  = new FileInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), DbFile.Name));
            if (!DbFile.Exists)
            {
                SQLiteConnection.CreateFile(DbFile.FullName);
            }

            db = new SQLiteConnection("Data Source=" + DbFile.FullName);
                        #endif
            db.Open();

            CreateDbs();
        }
Exemplo n.º 7
0
        public override void CreateStore()
        {
            if (StoreExists)
            {
                throw new StoreAlreadyExistsException();
            }

#if (!WINDOWS_PHONE)
            SQLiteConnection.CreateFile(FileName);
#endif
            var connection = GetConnection(true);
            try
            {
                foreach (var entity in this.Entities)
                {
                    CreateTable(connection, entity);
                }
            }
            finally
            {
                DoneWithConnection(connection, true);
            }
        }