Пример #1
0
        async Task IAsyncLifetime.DisposeAsync()
        {
            var authenticators = await AuthenticatorRepository.GetAllAsync();

            for (var i = 0; i < authenticators.Count; i++)
            {
                var authenticator = authenticators[i];
                await AuthenticatorRepository.DeleteAsync(authenticator);
            }

            var categories = await CategoryRepository.GetAllAsync();

            for (var i = 0; i < categories.Count; i++)
            {
                var category = categories[i];
                await CategoryRepository.DeleteAsync(category);
            }

            var authenticatorCategories = await AuthenticatorCategoryRepository.GetAllAsync();

            for (var i = 0; i < authenticatorCategories.Count; i++)
            {
                var authenticatorCategory = authenticatorCategories[i];
                await AuthenticatorCategoryRepository.DeleteAsync(authenticatorCategory);
            }

            var customIcons = await CustomIconRepository.GetAllAsync();

            for (var i = 0; i < customIcons.Count; i++)
            {
                var customIcon = customIcons[i];
                await CustomIconRepository.DeleteAsync(customIcon);
            }
        }
Пример #2
0
 public async Task <Backup> CreateBackupAsync()
 {
     return(new Backup(
                await _authenticatorRepository.GetAllAsync(),
                await _categoryRepository.GetAllAsync(),
                await _authenticatorCategoryRepository.GetAllAsync(),
                await _customIconRepository.GetAllAsync()
                ));
 }
Пример #3
0
        private async Task <BackupResult> BackupToDir(Uri destUri)
        {
            var auths = (await _authenticatorRepository.GetAllAsync()).ToImmutableArray();

            if (!auths.Any())
            {
                return(new BackupResult());
            }

            if (!HasPersistablePermissionsAtUri(destUri))
            {
                throw new InvalidOperationException("No permission at URI");
            }

            var password = await GetBackupPassword();

            if (password == null)
            {
                throw new InvalidOperationException("No password defined");
            }

            var backup = new Backup(
                auths,
                await _categoryRepository.GetAllAsync(),
                await _authenticatorCategoryRepository.GetAllAsync(),
                await _customIconRepository.GetAllAsync()
                );

            var dataToWrite = backup.ToBytes(password);

            var directory = DocumentFile.FromTreeUri(_context, destUri);
            var file      = directory.CreateFile(Backup.MimeType,
                                                 FormattableString.Invariant($"backup-{DateTime.Now:yyyy-MM-dd_HHmmss}.{Backup.FileExtension}"));

            if (file == null)
            {
                throw new Exception("File creation failed, got null.");
            }

            await FileUtil.WriteFile(_context, file.Uri, dataToWrite);

            return(new BackupResult(file.Name));
        }
Пример #4
0
        private async Task GetSyncBundle(string nodeId)
        {
            await _authenticatorView.LoadFromPersistenceAsync();

            var auths = new List <WearAuthenticator>();

            var authCategories = await _authenticatorCategoryRepository.GetAllAsync();

            foreach (var auth in _authenticatorView)
            {
                var bindings = authCategories
                               .Where(c => c.AuthenticatorSecret == auth.Secret)
                               .Select(c => new WearAuthenticatorCategory(c.CategoryId, c.Ranking))
                               .ToList();

                var item = new WearAuthenticator(
                    auth.Type, auth.Secret, auth.Icon, auth.Issuer, auth.Username, auth.Period, auth.Digits,
                    auth.Algorithm, auth.Ranking, bindings);

                auths.Add(item);
            }

            var categories = (await _categoryRepository.GetAllAsync()).Select(c => new WearCategory(c.Id, c.Name))
                             .ToList();
            var customIconIds = (await _customIconRepository.GetAllAsync()).Select(i => i.Id).ToList();

            var preferenceWrapper = new PreferenceWrapper(this);
            var preferences       = new WearPreferences(
                preferenceWrapper.DefaultCategory, preferenceWrapper.SortMode, preferenceWrapper.CodeGroupSize);

            var bundle = new WearSyncBundle(auths, categories, customIconIds, preferences);

            var json = JsonConvert.SerializeObject(bundle);
            var data = Encoding.UTF8.GetBytes(json);

            await WearableClass.GetMessageClient(this).SendMessageAsync(nodeId, GetSyncBundleCapability, data);
        }