Exemplo n.º 1
0
        private async Task OnOtpAuthMigrationScan(string uri)
        {
            OtpAuthMigration migration;

            try
            {
                migration = OtpAuthMigration.FromOtpAuthMigrationUri(uri);
            }
            catch (Exception)
            {
                ShowSnackbar(Resource.String.qrCodeFormatError, Snackbar.LengthShort);
                return;
            }

            var inserted = 0;

            try
            {
                foreach (var item in migration.Authenticators)
                {
                    Authenticator auth;

                    try
                    {
                        auth = Authenticator.FromOtpAuthMigrationAuthenticator(item);
                    }
                    catch (InvalidAuthenticatorException)
                    {
                        continue;
                    }

                    if (_authSource.IsDuplicate(auth))
                    {
                        continue;
                    }

                    await _connection.InsertAsync(auth);

                    inserted++;
                }
            }
            catch (SQLiteException)
            {
                ShowSnackbar(Resource.String.genericError, Snackbar.LengthShort);
                return;
            }

            await _authSource.Update();

            await SwitchCategory(null);

            RunOnUiThread(_authListAdapter.NotifyDataSetChanged);

            var message = String.Format(GetString(Resource.String.restoredFromMigration), inserted);

            ShowSnackbar(message, Snackbar.LengthLong);
        }
Exemplo n.º 2
0
        public Task <int> ParseOtpMigrationUri(string uri)
        {
            var migration      = OtpAuthMigration.FromOtpAuthMigrationUri(uri);
            var authenticators = new List <Authenticator>();

            foreach (var item in migration.Authenticators)
            {
                Authenticator auth;

                try
                {
                    auth = Authenticator.FromOtpAuthMigrationAuthenticator(item, _iconResolver);
                }
                catch (ArgumentException)
                {
                    continue;
                }

                authenticators.Add(auth);
            }

            return(_authenticatorService.AddManyAsync(authenticators));
        }