Amazon.CognitoSync.SyncManager.Internal.SQLiteLocalStorage.CreateDataset C# (CSharp) Метод

CreateDataset() публичный Метод

Create a dataset
public CreateDataset ( string identityId, string datasetName ) : void
identityId string Identity Id
datasetName string Dataset name.
Результат void
        public void CreateDataset(string identityId, string datasetName)
        {
            lock (sqlite_lock)
            {
                DatasetMetadata metadata = GetMetadataHelper(identityId, datasetName);

                if (metadata == null)
                {
                    string query = DatasetColumns.BuildInsert(
                        new string[]
                        {
                            DatasetColumns.IDENTITY_ID,
                            DatasetColumns.DATASET_NAME,
                            DatasetColumns.CREATION_TIMESTAMP,
                            DatasetColumns.LAST_MODIFIED_TIMESTAMP
                        });

                    CreateDatasetHelper(query, identityId, datasetName, DateTime.Now, DateTime.Now);

                }
            }
        }

Usage Example

        public void SQliteDatasetsTests()
        {
            string dbPath = Path.Combine(PCLStorage.FileSystem.Current.LocalStorage.Path, DB_FILE_NAME);

            string randomId = "old";
            string randomDataset = Guid.NewGuid().ToString();
            using (SQLiteLocalStorage storage = new SQLiteLocalStorage())
            {
                storage.WipeData();
                storage.CreateDataset(randomId, randomDataset);
                storage.PutValue(randomId, randomDataset, "Voldemort", "He who must not be named");

                using (SQLiteConnection connection = new SQLiteConnection(dbPath))
                {
                    string query = "select count(*) from datasets where dataset_name = @dataset_name and identity_id = @identity_id ";
                    using (var sqliteStatement = connection.Prepare(query))
                    {
                        BindData(sqliteStatement, randomDataset, randomId);
                        if(sqliteStatement.Step()==SQLiteResult.ROW)
                        {
                            var count = sqliteStatement.GetInteger(0);
                            Assert.IsTrue(count == 1);
                        }
                        else
                        {
                            Assert.Fail();
                        }

                    }

                    query = "select count(*) from records where dataset_name = @dataset_name and identity_id = @identity_id ";

                    using( var sqliteStatement = connection.Prepare(query))
                    {
                        BindData(sqliteStatement, randomDataset, randomId);
                        if (sqliteStatement.Step() == SQLiteResult.ROW)
                        {
                            var count = sqliteStatement.GetInteger(0);
                            Assert.IsTrue(count == 1);
                        }
                        else
                        {
                            Assert.Fail();
                        }
                    }
                }

                var datasets = storage.GetDatasetMetadata(randomId);
                Assert.IsTrue(datasets.Count == 1);

                var Id = "new";
                storage.ChangeIdentityId(randomId, Id);
                randomId = Id;

                using (SQLiteConnection connection = new SQLiteConnection(dbPath))
                {
                    var query = "select count(*) from datasets where dataset_name = @dataset_name and identity_id = @identity_id ";
                    using (var sqliteStatement = connection.Prepare(query))
                    {
                        BindData(sqliteStatement, randomDataset, randomId);
                        if (sqliteStatement.Step() == SQLiteResult.ROW)
                        {
                            var count = sqliteStatement.GetInteger(0);
                            Assert.IsTrue(count == 1);
                        }
                        else
                        {
                            Assert.Fail();
                        }
                    }


                    query = "select count(*) from records where dataset_name = @dataset_name and identity_id = @identity_id ";
                    using (var sqliteStatement = connection.Prepare(query))
                    {
                        BindData(sqliteStatement, randomDataset, randomId);
                        if (sqliteStatement.Step() == SQLiteResult.ROW)
                        {
                            var count = sqliteStatement.GetInteger(0);
                            Assert.IsTrue(count == 1);
                        }
                        else
                        {
                            Assert.Fail();
                        }
                    }
                }

                storage.DeleteDataset(randomId, randomDataset);

                using (SQLiteConnection connection = new SQLiteConnection(dbPath))
                {
                    var query = "select last_sync_count from datasets where dataset_name = @dataset_name and identity_id = @identity_id";

                    using (var sqliteStatement = connection.Prepare(query))
                    {
                        BindData(sqliteStatement, randomDataset, randomId);
                        if (sqliteStatement.Step() == SQLiteResult.ROW)
                        {
                            var count = sqliteStatement.GetInteger(0);
                            Assert.IsTrue(count == -1);
                        }
                        else
                        {
                            Assert.Fail();
                        }
                    }

                }

                Assert.IsNotNull(storage.GetDatasetMetadata(randomId)[0]);

            }
        }
All Usage Examples Of Amazon.CognitoSync.SyncManager.Internal.SQLiteLocalStorage::CreateDataset