示例#1
0
 public async Task <Backup> CreateBackupAsync()
 {
     return(new Backup(
                await _authenticatorRepository.GetAllAsync(),
                await _categoryRepository.GetAllAsync(),
                await _authenticatorCategoryRepository.GetAllAsync(),
                await _customIconRepository.GetAllAsync()
                ));
 }
示例#2
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);
            }
        }
        public async Task CullUnused()
        {
            var authenticators = await _authenticatorRepository.GetAllAsync();

            var icons = await _customIconRepository.GetAllAsync();

            var iconsInUse = authenticators
                             .Where(a => a.Icon != null && a.Icon.StartsWith(CustomIcon.Prefix))
                             .Select(a => a.Icon[1..])
        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));
        }
示例#5
0
        public async Task <IEnumerable <AuthenticatorDto> > GetAllAsync()
        {
            var authenticators = await _authenRepository.GetAllAsync();

            return(_mapper.Map <IEnumerable <Authenticator>, IEnumerable <AuthenticatorDto> >(authenticators));
        }