コード例 #1
0
        private MenuItemViewModel AddDatabaseEntry(IFile dbFile)
        {
            var id = dbFile.IdFromPath();

            var exists = Databases.FirstOrDefault(m => m.Id == dbFile.IdFromPath());

            if (exists != null)
            {
                return(exists);
            }

            var entry = new MenuItemViewModel
            {
                DisplayName = dbFile.Name,
                Id          = dbFile.IdFromPath(),
                Command     = new DelegateCommand(async() =>
                {
                    try
                    {
                        var db = await _cache.UnlockAsync(id, _credentialProvider);

                        if (db != null)
                        {
                            _navigator.GoToDatabaseView(db, db.Root);
                        }
                    }
                    catch (InvalidCredentialsException)
                    {
                        await _messageDialogs.InvalidCredentialsAsync();
                    }
                    catch (DatabaseUnlockException e)
                    {
                        await _messageDialogs.UnlockErrorAsync(e.Message);
                    }
                })
            };

            entry.RemoveCommand = new DelegateCommand(async() =>
            {
                await _cache.RemoveDatabaseAsync(dbFile);
            });

            SynchContext.Post(_ => Databases.Add(entry), null);

            return(entry);
        }
コード例 #2
0
ファイル: MenuViewModel.cs プロジェクト: Mittemi/KeePassWin
        private void AddDatabaseEntry(IFile dbFile)
        {
            var id = dbFile.IdFromPath();

            var entry = new MenuItemViewModel
            {
                DisplayName = dbFile.Name,
                Command     = new DelegateCommand(async() =>
                {
                    try
                    {
                        var db = await _cache.UnlockAsync(id, _credentialProvider);

                        if (db != null)
                        {
                            _navigator.GoToDatabaseView(db, db.Root);
                        }
                    }
                    catch (InvalidCredentialsException)
                    {
                        await _messageDialogs.InvalidCredentialsAsync();
                    }
                    catch (DatabaseUnlockException e)
                    {
                        await _messageDialogs.UnlockErrorAsync(e.Message);
                    }
                })
            };

            entry.RemoveCommand = new DelegateCommand(async() =>
            {
                await _cache.RemoveDatabaseAsync(dbFile)
                .ContinueWith((t, o) => Databases.Remove(entry), SynchContext);
            });

            SynchContext.Post(_ => Databases.Add(entry), null);
        }