示例#1
0
        public async Task InitializeManager()
        {
            if (!await ExistsManagerAsync())
            {
                // Create new md head container
                _mdContainer = new MdContainer();
                var serializedDbContainer = _mdContainer.Json();

                // Update App Container (store md head info to it)
                var appContainer = await Session.AccessContainer.GetMDataInfoAsync(AppContainerPath);

                var dbIdCipherBytes = await Session.MDataInfoActions.EncryptEntryKeyAsync(appContainer, nameof(MdContainer).ToUtfBytes());

                var dbCipherBytes = await Session.MDataInfoActions.EncryptEntryValueAsync(appContainer, serializedDbContainer.ToUtfBytes());

                using (var appContEntryActionsH = await Session.MDataEntryActions.NewAsync())
                {
                    await Session.MDataEntryActions.InsertAsync(appContEntryActionsH, dbIdCipherBytes, dbCipherBytes);

                    await Session.MData.MutateEntriesAsync(appContainer, appContEntryActionsH); // <----------------------------------------------    Commit ------------------------
                }
            }
            else
            {
                await LoadDbContainer();
            }
        }
        public async Task InitializeManager()
        {
            if (!await ExistsManagerAsync())
            {
                // Create new md head container
                _mdContainer = new MdContainer();
                var serializedDbContainer = _mdContainer.Json();

                // Insert a serialized mdContainer into App Container
                var appContainer = await _dataOps.Session.AccessContainer.GetMDataInfoAsync(APP_CONTAINER_PATH);

                var dbIdCipherBytes = await _dataOps.Session.MDataInfoActions.EncryptEntryKeyAsync(appContainer, MD_CONTAINER_KEY_BYTES);

                var dbCipherBytes = await _dataOps.Session.MDataInfoActions.EncryptEntryValueAsync(appContainer, serializedDbContainer.ToUtfBytes());

                using (var appContEntryActionsH = await _dataOps.Session.MDataEntryActions.NewAsync())
                {
                    await _dataOps.Session.MDataEntryActions.InsertAsync(appContEntryActionsH, dbIdCipherBytes, dbCipherBytes);

                    await _dataOps.Session.MData.MutateEntriesAsync(appContainer, appContEntryActionsH); // <----------------------------------------------    Commit ------------------------
                }
            }
            else
            {
                await LoadDbContainer();
            }
        }