public override async Task <int> LoadLastCheckpointAsync(string projectorIdentifier)
        {
            TCheckpointInfo checkpointInfo = null;

            try
            {
                checkpointInfo = connection.Get <TCheckpointInfo>(projectorIdentifier);
            }
            catch
            {
                try
                {
                    if (!connection.TableExists("CheckpointInfos"))
                    {
                        connection.CreateTable(typeof(CheckpointInfo));
                        checkpointInfo = connection.Get <TCheckpointInfo>(projectorIdentifier);
                    }
                }
                catch
                {
                }
                // TODO: error handling
            }

            if (checkpointInfo == null)
            {
                return(-1);
            }

            return(checkpointInfo.CheckpointNumber);
        }
Example #2
0
 public void Initialize()
 {
     using (connection.Lock())
     {
         connection.CreateTable <VideoItem>();
         connection.CreateTable <StreamMedia>();
     }
 }
Example #3
0
 public void Initialize()
 {
     using (connection.Lock())
     {
         connection.CreateTable <ArtistItem>();
         connection.CreateTable <AlbumItem>();
         connection.CreateTable <TrackItem>();
         connection.CreateTable <TracklistItem>();
         connection.CreateTable <PlaylistItem>();
     }
 }
Example #4
0
        private void CreateDB(String dbPath)
        {
            //SQLiteConnection db = new SQLiteConnection(dbPath);

            SQLiteConnectionString   connStr = new SQLiteConnectionString(dbPath, true);
            SQLiteConnectionWithLock db      = new SQLiteConnectionWithLock(connStr); //, SQLiteOpenFlags.Create | SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.NoMutex);

            db.CreateTable <Images>();
            db.CreateTable <Map>();
            UserDialogs.Instance.ShowLoading("Downloading map...");
            FindTiles(db);
            UserDialogs.Instance.HideLoading();
        }
 public void Initialize()
 {
     using (connection.Lock())
     {
         connection.CreateTable <BackgroundTrackItem>();
     }
 }
Example #6
0
        /// <summary>
        /// 启动数据库运行
        /// </summary>
        /// <param name="dataBasePath">数据库路径</param>
        public void Start(string dataBasePath = null)
        {
            if (dataBasePath != null)
            {
                this.DataBasePath = dataBasePath;
            }
            _db = new SQLiteConnectionWithLock(new SQLiteConnectionString(
                                                   DataBasePath,
                                                   SQLiteOpenFlags.Create | SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.FullMutex, true))
            {
                // debug log
                Trace         = true,
                TimeExecution = true,
                Tracer        = s => Log?.Verbose(" [pid={0}] {1}", Thread.CurrentThread.ManagedThreadId, s),
                BusyTimeout   = TimeSpan.FromMilliseconds(5000),
                SkipLock      = false
            };

            // 创建表,这个库会自动处理数据结构变更和重复创建
            foreach (var type in _createTableList)
            {
                _db.CreateTable(type);
            }

            updateTableDelegates[DataBaseType.GunDevelop]        = new UpdateTableDelegate(UpdateGunDevelopTotal);
            updateTableDelegates[DataBaseType.GunDevelopHeavy]   = new UpdateTableDelegate(UpdateGunDevelopHeavyTotal);
            updateTableDelegates[DataBaseType.EquipDevelop]      = new UpdateTableDelegate(UpdateEquipDevelopTotal);
            updateTableDelegates[DataBaseType.EquipProduce]      = new UpdateTableDelegate(UpdateEquipProduceTotal);
            updateTableDelegates[DataBaseType.EquipDevelopHeavy] = new UpdateTableDelegate(UpdateEquipDevelopHeavyTotal);
            updateTableDelegates[DataBaseType.MissionBattle]     = new UpdateTableDelegate(UpdateMissionBattleTotal);
            updateTableDelegates[DataBaseType.MissionFinish]     = new UpdateTableDelegate(UpdateMissionFinishTotal);
        }
        public ExampleDataService(IMvxSqliteConnectionFactory sqliteConnectionFactory)
        {
            _sqliteConnectionFactory = sqliteConnectionFactory;
            var databaseName = "myExampleDatabase.sqlite";

            _connection = _sqliteConnectionFactory.GetConnectionWithLock(databaseName);
            _connection.CreateTable <Example>();
        }
Example #8
0
        private int GetCurrentVersion()
        {
            _connection.CreateTable <VersionRow>();
            var version = _connection.Table <VersionRow>()
                          .OrderByDescending(x => x.Version)
                          .FirstOrDefault();

            return(version?.Version ?? 0);
        }
Example #9
0
        private void CreateDB(String dbPath)
        {
            //SQLiteConnection db = new SQLiteConnection(dbPath);

            SQLiteConnectionString   connStr = new SQLiteConnectionString(dbPath, true);
            SQLiteConnectionWithLock db      = new SQLiteConnectionWithLock(connStr);

            db.CreateTable <House>();

            //UserDialogs.Instance.ShowLoading("Downloading houses...");
            LoadHouses(db);
            //UserDialogs.Instance.HideLoading();
        }
Example #10
0
        private void EnsureTableExists <TEntityData>() where TEntityData : class, IEntityData
        {
            var tableName   = GetTableName <TEntityData>();
            var columnInfos = baseConnection.GetTableInfo(tableName);

            if (!columnInfos.Any())
            {
                baseConnection.CreateTable <TEntityData>();
            }
            else
            {
                baseConnection.MigrateTable <TEntityData>();
            }
        }
Example #11
0
 public Task <CreateTablesResult> CreateTablesAsync(params Type[] types)
 {
     if (types == null)
     {
         throw new ArgumentNullException("types");
     }
     return(Task.Factory.StartNew(() =>
     {
         var result = new CreateTablesResult();
         SQLiteConnectionWithLock conn = GetConnection();
         using (conn.Lock())
         {
             foreach (Type type in types)
             {
                 int aResult = conn.CreateTable(type);
                 result.Results[type] = aResult;
             }
         }
         return result;
     }, CancellationToken.None, _taskCreationOptions, _taskScheduler ?? TaskScheduler.Default));
 }
Example #12
0
 public Task <CreateTablesResult> CreateTablesAsync(params Type[] types)
 {
     if (types == null)
     {
         throw new ArgumentNullException("types");
     }
     return(_taskFactory.StartNew(() =>
     {
         var result = new CreateTablesResult();
         SQLiteConnectionWithLock conn = GetConnection();
         using (conn.Lock())
         {
             foreach (Type type in types)
             {
                 int aResult = conn.CreateTable(type);
                 result.Results[type] = aResult;
             }
         }
         return result;
     }));
 }
        private void AddRecords()
        {
            SqLiteUtilitiesAlt utilities;
            int maxValue = 999;

            utilities = new SqLiteUtilitiesAlt(this);

            TimeSpan original, alternative;

            try
            {
                utilities.OpenConnection();

                var stopWatch = Stopwatch.StartNew();
                for (int i = 0; i <= maxValue; i++)
                {
                    utilities.AddRecord("test", "person", i, "12345678901234567890123456789012345678901234567890");
                }
                stopWatch.Stop();

                original = stopWatch.Elapsed;

                utilities.CloseConnection();

                var newConnection = new SQLiteConnectionWithLock(new SQLitePlatformAndroid(),
                                                                 new SQLiteConnectionString(Path.Combine(Environment.ExternalStorageDirectory.AbsolutePath, "async.db"), true));

                newConnection.DropTable <Record>();
                newConnection.CreateTable <Record>();

                stopWatch.Restart();

                newConnection.BeginTransaction();

                for (int i = 0; i <= maxValue; i++)
                {
                    newConnection.Insert(new Record()
                    {
                        FirstName = "test",
                        LastName  = "person",
                        Index     = i,
                        Misc      = "12345678901234567890123456789012345678901234567890"
                    });
                }

                newConnection.Commit();

                stopWatch.Stop();
                alternative = stopWatch.Elapsed;
            }
            catch (Exception ex)
            {
                AlertDialog.Builder dlgException = new AlertDialog.Builder(this);
                dlgException.SetMessage("An error has occurred adding records: " + ex.Message);
                dlgException.SetTitle("Error");
                dlgException.SetPositiveButton("OK", (sender, args) => { });
                dlgException.SetCancelable(true);
                dlgException.Create().Show();
                return;
            }

            AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
            dlgAlert.SetMessage(string.Format("All records written to database. Original time: {0}, alternative time: {1}", original, alternative));
            dlgAlert.SetTitle("Success");
            dlgAlert.SetPositiveButton("OK", (sender, args) => { });
            dlgAlert.SetCancelable(true);
            dlgAlert.Create().Show();
            return;
        }