Ejemplo n.º 1
0
        public void GetTest()
        {
            const string tableName = nameof(TestObject);

            using var context = new IBoxDBAdapter();
            context.EnsureTable <TestObject>(tableName, "Id");
            context.Open();
            context.Insert(tableName, new TestObject(1L, "Test1"));
            var result = context.Get <TestObject>(tableName, "Name", "Test1");

            Assert.AreEqual(1L, result[0].Id);
        }
        /// <summary>
        /// Initializes the specified configuration database data.
        /// </summary>
        /// <param name="configDBData">The configuration database data.</param>
        public void Initialize(byte[] configDBData)
        {
            if (configDBAdapter != null)
            {
                return;
            }
            var rawData = DecryptDatabaseFile(configDBData);

            configDBAdapter = new IBoxDBAdapter(rawData);
            configDBAdapter.EnsureTable <MetadataEntityDBConfig>(MetadataEntityDBConfig.TableName, MetadataEntityDBConfig.TablePrimaryKey);
            configDBAdapter.Open();
        }
Ejemplo n.º 3
0
        public void GetAllTest()
        {
            const string tableName = nameof(TestObject);

            using var context = new IBoxDBAdapter();
            context.EnsureTable <TestObject>(tableName, "Id");
            context.Open();
            context.Insert(tableName, new TestObject(1L, "Test1"));
            context.Insert(tableName, new TestObject(2L, "Test2"));
            var result = context.GetAll <TestObject>(tableName);

            Assert.AreEqual(2, result.Count);
        }
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing">
        /// <c>true</c> to release both managed and unmanaged resources; <c>false</c> to release
        /// only unmanaged resources.
        /// </param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (configDBAdapter != null)
                {
                    configDBAdapter.Dispose();
                    configDBAdapter = null;
                }
            }

            base.Dispose(disposing);
        }
        private static void InsertEntityData <T>(string dbFolderPath, string tableName, IList <MetadataEntityRawInfo> rowInfos, IList <MetadataEntity> entityDataList, int index) where T : MetadataEntity
        {
            var          dbLocalAddress = index + 2L;
            const string dbName         = nameof(MetadataEntityDBConfig);

            using var configDBAdapter = new IBoxDBAdapter(TempFolderPath, MetadataEntityDBConfig.DatabaseLocalAddress);
            configDBAdapter.EnsureTable <MetadataEntityDBConfig>(dbName, MetadataEntityDBConfig.TablePrimaryKey);
            configDBAdapter.Open();
            var tablePrimaryKey = rowInfos[0].PropertyName;
            var success         = configDBAdapter.Insert(new MetadataEntityDBConfig(tableName, tablePrimaryKey));

            // var success = configDBAdapter.Insert(new MetadataEntityDBConfig(tableName, tablePrimaryKey));

            if (!success)
            {
                return;
            }

            var dataList = new T[entityDataList.Count];

            for (var i = 0; i < entityDataList.Count; i++)
            {
                dataList[i] = (T)entityDataList[i];
            }

            using var dataDBAdapter = new IBoxDBAdapter(TempFolderPath, dbLocalAddress);
            dataDBAdapter.EnsureTable <T>(typeof(T).Name, tablePrimaryKey);
            dataDBAdapter.Open();

            foreach (var data in dataList)
            {
                var result = dataDBAdapter.Insert(tableName, data);

                if (!result)
                {
                    Debug.LogWarning($"Can not write metadata ({data}) into database file: {tableName}!");
                }
            }

            // Copy metadata entity database file.
            CopyDatabaseFile(dbFolderPath, dbLocalAddress, tableName);
        }
        private void CreateDataDBAdapterForEntity <T>(Type entityType, Action <IBoxDBAdapter> handler) where T : MetadataEntity, new()
        {
            if (entityType == null)
            {
                throw new ArgumentNullException(nameof(entityType));
            }

            if (!GetDBRawDataForEntity(entityType, out var dbRawData))
            {
                handler?.Invoke(null);
                return;
            }

            using var dataDBAdapter = new IBoxDBAdapter(dbRawData);
            var tableName      = entityType.Name;
            var primaryKeyName = GetMetadataEntityDBPrimaryKey <T>();

            dataDBAdapter.EnsureTable <T>(tableName, primaryKeyName);
            dataDBAdapter.Open();
            handler?.Invoke(dataDBAdapter);
        }