private void Save() { progBusy.IsBusy = true; string groupId; if (!NavigationContext.QueryString .TryGetValue("group", out groupId)) { groupId = null; } ThreadPool.QueueUserWorkItem(_ => { var info = Cache.DbInfo; var database = Cache.Database; var writer = new DatabaseWriter(); info.OpenDatabaseFile(x => writer .LoadExisting(x, info.Data.MasterKey)); if (_entry.ID != null) { _binding.Save(); writer.Details(_entry); } else { database.AddNew( _entry, groupId); writer.New(_entry); } info.SetDatabase(x => writer.Save( x, database.RecycleBin)); Dispatcher.BeginInvoke(() => { UpdateNotes(); progBusy.IsBusy = false; _binding.HasChanges = false; if (!info.NotifyIfNotSyncable()) { new ToastPrompt { Title = Properties.Resources.SavedTitle, Message = Properties.Resources.SavedCaption, TextOrientation = System.Windows.Controls .Orientation.Vertical, }.Show(); } }); ThreadPool.QueueUserWorkItem( __ => Cache.AddRecent(_entry.ID)); }); }
private void Save() { progBusy.IsBusy = true; string errorMessage = string.Empty; string groupId; if (!NavigationContext.QueryString .TryGetValue("group", out groupId)) { groupId = null; } if (IsReservedName()) { errorMessage = Strings.EntryDetails_NameReserved; } var duplicate = GetAnyDuplicateField(); if (duplicate != null) { errorMessage = string.Format(Strings.EntryDetails_NameDuplicate, duplicate.Name); } if (!string.IsNullOrEmpty(errorMessage)) { MessageBox.Show(errorMessage, "Warning", MessageBoxButton.OK); progBusy.IsBusy = false; return; } ThreadPool.QueueUserWorkItem(_ => { var info = Cache.DbInfo; var database = Cache.Database; var writer = new DatabaseWriter(); info.OpenDatabaseFile(x => writer .LoadExisting(x, info.Data.MasterKey)); foreach (var fild in _fields) { _entry.Add(new Field() { Name = fild.Name, Value = fild.Value, Protected = fild.Protected }); } if (_entry.ID != null) { _binding.Save(); writer.Details(_entry); } else { database.AddNew( _entry, groupId); writer.New(_entry); } info.SetDatabase(x => writer.CreateRecycleBin( x, database.RecycleBin)); Dispatcher.BeginInvoke(() => { UpdateNotes(); progBusy.IsBusy = false; _binding.HasChanges = false; if (!info.NotifyIfNotSyncable()) { new ToastPrompt { Title = Properties.Resources.SavedTitle, Message = Properties.Resources.SavedCaption, TextOrientation = System.Windows.Controls .Orientation.Vertical, }.Show(); } }); ThreadPool.QueueUserWorkItem( __ => Cache.AddRecent(_entry.ID)); }); }
protected override void OnNavigatedTo( bool cancelled, NavigationEventArgs e) { if (cancelled) { return; } if (_binding != null) { _binding.Save(); UpdateNotes(); if (!String.IsNullOrEmpty(_binding.Password)) { txtPassword.Text = _binding.Password; } return; } DateTime convertedDate; if ((Cache.DbInfo != null) && (Cache.DbInfo.Details.Modified != null)) { convertedDate = DateTime.Parse(Cache.DbInfo.Details.Modified); ApplicationTitle.Text = "WinPass - " + Cache.DbInfo.Details.Name + " (" + convertedDate + ")"; } var database = Cache.Database; if (database == null) { this.BackToDBs(); return; } string id; var queries = NavigationContext.QueryString; _fields = new ObservableCollection <FieldBinding>(); Entry entry; if (queries.TryGetValue("id", out id)) { entry = database.GetEntry(id); ThreadPool.QueueUserWorkItem( _ => Cache.AddRecent(id)); // Notes if (!String.IsNullOrEmpty(entry.Notes)) { txtNotes.Text = entry.Notes; } // Fields _fields = new ObservableCollection <FieldBinding>(entry.CustomFields .Select(x => new FieldBinding(x))); } else { var config = database.Configuration; entry = new Entry { Password = Generator .CharacterSets.NewEntry(), UserName = config.DefaultUserName, Protections = { Title = config.ProtectTitle, UserName = config.ProtectUserName, Password = config.ProtectPassword, } }; txtTitle.Loaded += (sender, e1) => txtTitle.Focus(); } lstFields.ItemsSource = _fields; DisplayEntry(entry); }
protected override void OnNavigatedTo( bool cancelled, NavigationEventArgs e) { if (cancelled) { return; } if (_binding != null) { _binding.Save(); UpdateNotes(); UpdateFieldsCount(_entry); txtPassword.Text = _binding.Password; return; } var database = Cache.Database; if (database == null) { this.BackToDBs(); return; } string id; var queries = NavigationContext.QueryString; Entry entry; if (queries.TryGetValue("id", out id)) { entry = database.GetEntry(id); ThreadPool.QueueUserWorkItem( _ => Cache.AddRecent(id)); } else { var config = database.Configuration; entry = new Entry { Password = Generator .CharacterSets.NewEntry(), UserName = config.DefaultUserName, Protections = { Title = config.ProtectTitle, UserName = config.ProtectUserName, Password = config.ProtectPassword, } }; txtTitle.Loaded += (sender, e1) => txtTitle.Focus(); } DisplayEntry(entry); UpdateFieldsCount(entry); }