示例#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();
            }
        }
示例#3
0
        async Task <MdContainer> LoadDbContainer()
        {
            var appContainerInfo = await Session.AccessContainer.GetMDataInfoAsync(AppContainerPath);

            var mdKeyCipherBytes = await Session.MDataInfoActions.EncryptEntryKeyAsync(appContainerInfo, nameof(MdContainer).ToUtfBytes());

            var cipherTxtEntryVal = await Session.MData.GetValueAsync(appContainerInfo, mdKeyCipherBytes);

            var plainTxtEntryVal = await Session.MDataInfoActions.DecryptAsync(appContainerInfo, cipherTxtEntryVal.Item1);

            var mdContainerJson = plainTxtEntryVal.ToUtfString();
            var mdContainer     = mdContainerJson.Parse <MdContainer>();

            _mdContainer = mdContainer;
            return(mdContainer);
        }
        async Task <MdContainer> LoadDbContainer()
        {
            var appContainerInfo = await _dataOps.Session.AccessContainer.GetMDataInfoAsync(APP_CONTAINER_PATH);

            var mdKeyCipherBytes = await _dataOps.Session.MDataInfoActions.EncryptEntryKeyAsync(appContainerInfo, MD_CONTAINER_KEY_BYTES);

            var cipherTxtEntryVal = await _dataOps.Session.MData.GetValueAsync(appContainerInfo, mdKeyCipherBytes);

            _mdContainerVersion = cipherTxtEntryVal.Item2;

            var plainTxtEntryVal = await _dataOps.Session.MDataInfoActions.DecryptAsync(appContainerInfo, cipherTxtEntryVal.Item1);

            var mdContainerJson = plainTxtEntryVal.ToUtfString();

            _mdContainer = mdContainerJson.Parse <MdContainer>();
            return(_mdContainer);
        }
示例#5
0
        public async Task InitializeManager()
        {
            if (!await ExistsManagerAsync())
            {
                // Create new md head container
                _mdContainer = new MdContainer();

                var mdContainerRoot = await GetNewMdNodeAsync();

                var f = new Factories.DataTreeFactory(_nodeFactory);
                _mdContainerSource = await f.CreateAsync((s) => throw new ArgumentOutOfRangeException("Can only add 999k items to this collection.")); // no expansion func, means we can only create 999 databases with this account.

                var serializedDbContainer = _mdContainerSource.MdLocator.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 ------------------------
                }

                // Set Permissions
                var version = await _dataOps.Session.MData.GetVersionAsync(appContainer);

                foreach (var pair in _permissions.AppContainerPermissions)
                {
                    var userSignKeyH = await _dataOps.Session.Crypto.SignPubKeyNewAsync(pair.Key);

                    await _dataOps.Session.MData.SetUserPermissionsAsync(appContainer, userSignKeyH, pair.Value, ++version);
                }
            }
            else
            {
                _mdContainer = await LoadDbContainer();
            }
        }