|
2 | 2 | using SharpPasswordManager.BL.Interfaces; |
3 | 3 | using SharpPasswordManager.DL.Models; |
4 | 4 | using SharpPasswordManager.Handlers; |
| 5 | +using System.ComponentModel; |
5 | 6 | using System.IO; |
6 | 7 | using System.Reflection; |
7 | 8 | using System.Windows; |
|
10 | 11 |
|
11 | 12 | namespace SharpPasswordManager.ViewModels |
12 | 13 | { |
13 | | - public class MainViewModel |
| 14 | + public class MainViewModel : INotifyPropertyChanged |
14 | 15 | { |
15 | 16 | public UserControl CategoriesControl { get; set; } |
16 | 17 | public UserControl DataControl { get; set; } |
17 | 18 |
|
| 19 | + public Visibility SecurePanelVisibility { get; set; } = Visibility.Hidden; |
| 20 | + IStorageHandler<CategoryModel, DataModel> storageHandler; |
| 21 | + |
18 | 22 | public MainViewModel() |
19 | 23 | { |
20 | 24 | IStorageController<CategoryModel> categoryController = new StorageController<CategoryModel>(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), SecureManager.CategoriesFileName)); |
21 | 25 | IStorageController<DataModel> dataController = new StorageController<DataModel>(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), SecureManager.DataFileName), new Cryptographer(SecureManager.Key)); |
22 | 26 |
|
23 | | - IStorageHandler<CategoryModel, DataModel> storageHandler = new StorageHandler(categoryController, dataController); |
| 27 | + storageHandler = new StorageHandler(categoryController, dataController); |
24 | 28 |
|
25 | 29 | CategoriesControl = new Views.CategoryView(); |
26 | 30 | CategoryViewModel categoryVM = new CategoryViewModel(storageHandler); |
@@ -63,5 +67,37 @@ private void Close() |
63 | 67 | { |
64 | 68 | Application.Current.Shutdown(); |
65 | 69 | } |
| 70 | + |
| 71 | + private ICommand secureCmd; |
| 72 | + public ICommand SecureCmd |
| 73 | + { |
| 74 | + get |
| 75 | + { |
| 76 | + return secureCmd ?? (secureCmd = new CommandHandler(Secure, () => true)); |
| 77 | + } |
| 78 | + } |
| 79 | + private async void Secure() |
| 80 | + { |
| 81 | + SecurePanelVisibility = Visibility.Visible; |
| 82 | + OnPropertyChanged(nameof(SecurePanelVisibility)); |
| 83 | + Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait; |
| 84 | + await storageHandler.SecureStorageAsync(); |
| 85 | + Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow; |
| 86 | + SecurePanelVisibility = Visibility.Hidden; |
| 87 | + OnPropertyChanged(nameof(SecurePanelVisibility)); |
| 88 | + } |
| 89 | + |
| 90 | + #region Property changing |
| 91 | + public event PropertyChangedEventHandler PropertyChanged; |
| 92 | + |
| 93 | + private void OnPropertyChanged(string propertyName) |
| 94 | + { |
| 95 | + if (PropertyChanged != null) |
| 96 | + { |
| 97 | + var args = new PropertyChangedEventArgs(propertyName); |
| 98 | + PropertyChanged(this, args); |
| 99 | + } |
| 100 | + } |
| 101 | + #endregion |
66 | 102 | } |
67 | 103 | } |
0 commit comments