public bool SaveTabPageCollection(TabPageDataCollection tabPageDataCollection, string password, bool saveToSharedFolder = false) { bool success = false; try { var settings = new StorageManagerSettings(true, Environment.ProcessorCount, true, password); var storageManager = new StorageManager(settings); if (saveToSharedFolder) { string encodedConfigFilePath = GetFullPathToSharedDatabaseFile(); if (File.Exists(encodedConfigFilePath)) { File.Delete(encodedConfigFilePath); } settings.Password = ConfSaltVal + settings.Password + ConfSaltVal2; File.Copy(GetFullPathToDatabaseFile(), encodedConfigFilePath); success = storageManager.SerializeObjectToFile(_appSettingsService.Settings, GetFullPathToSharedEncryptedConfigFile(), null); } else { success = storageManager.SerializeObjectToFile(tabPageDataCollection, GetFullPathToDatabaseFile(), null); } } catch (Exception ex) { Log.Error(ex, "Error saving database"); } return(success); }
public FormTabEdit(TabPageDataCollection tabPageDataCollection) { _tabPageDataCollection = tabPageDataCollection; VerifyAndCorrectIndexing(_tabPageDataCollection); _listViewDataSource = tabPageDataCollection.TabPageDictionary.Select(x => x.Value).Select(x => new DragableListItem { Index = x.PageIndex, Label = x.TabPageLabel, PageData = x }).ToList(); InitializeComponent(); }
/// <summary> /// Initializes a new instance of the <see cref="MainFormLogicManager" /> class. /// </summary> /// <param name="memoStorageService">The memo storage service.</param> /// <param name="fileStorageService">The file storage service.</param> /// <param name="passwordStorage">The password storage.</param> /// <param name="scope">The scope.</param> /// <param name="appSettingsService">The application settings service.</param> public MainFormLogicManager(MemoStorageService memoStorageService, FileStorageService fileStorageService, PasswordStorage passwordStorage, ILifetimeScope scope, AppSettingsService appSettingsService) { _memoStorageService = memoStorageService; _fileStorageService = fileStorageService; _scope = scope; _appSettingsService = appSettingsService; _passwordStorage = passwordStorage; _tabPageDataCollection = TabPageDataCollection.CreateNewPageDataCollection(_appSettingsService.Settings.DefaultEmptyTabPages); }
private void openDatabaseToolStripMenuItem_Click(object sender, EventArgs e) { var formGetPassword = new FormGetPassword { PasswordSalt = _appSettingsService.Settings.ApplicationSaltValue, PasswordDerivedString = _appSettingsService.Settings.PasswordDerivedString }; if (formGetPassword.ShowDialog(this) != DialogResult.OK) { return; } string password = formGetPassword.PasswordString; _passwordStorage.Set(PwdKey, password); TabPageDataCollection tabPageCollection; try { tabPageCollection = _memoStorageService.LoadTabPageCollection(password); // Make sure that every tabPageData has a unique Id bool uniqueIdCreated = tabPageCollection.TabPageDictionary.Values.Aggregate(false, (current, tabPageData) => current | tabPageData.GenerateUniqueIdIfNoneExists()); if (uniqueIdCreated) { _applicationState.UniqueIdMissingFromExistingTabPage = true; } if (tabPageCollection.TabPageDictionary.Count == 0) { tabPageCollection = TabPageDataCollection.CreateNewPageDataCollection(_appSettingsService.Settings.DefaultEmptyTabPages); } } catch (Exception ex) { Log.Error(ex, "Open database Error."); MessageBox.Show(this, "Unable to load database, please verify that you entered the correct password. " + ex.Message, "Failed to load database", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _tabPageDataCollection = tabPageCollection; InitializeTabControls(); _applicationState.DatabaseLoaded = true; _applicationState.TabIndexChanged = false; _applicationState.TabPageAddOrRemove = false; _applicationState.TabTextDataChanged = false; UpdateApplicationState(); }
public TabPageDataCollection LoadTabPageCollection(string password) { TabPageDataCollection tabPageDataCollection = null; try { var settings = new StorageManagerSettings(true, Environment.ProcessorCount, true, password); var storageManager = new StorageManager(settings); tabPageDataCollection = storageManager.DeserializeObjectFromFile <TabPageDataCollection>(GetFullPathToDatabaseFile(), null); } catch (Exception ex) { Log.Error(ex, "Error loading database"); } return(tabPageDataCollection); }
private void VerifyAndCorrectIndexing(TabPageDataCollection tabPageDataCollection) { var pageIndexList = tabPageDataCollection.TabPageDictionary.Values.Select(x => x.PageIndex).ToList(); bool incorrectPageIndexFound = pageIndexList.Any(pageIndex => pageIndexList.Count(k => k == pageIndex) > 1); if (!incorrectPageIndexFound) { return; } foreach (int key in tabPageDataCollection.TabPageDictionary.Keys) { tabPageDataCollection.TabPageDictionary[key].PageIndex = key; } TabDataChanged = true; }
public FormMain(AppSettingsService appSettingsService, MemoStorageService memoStorageService, PasswordStorage passwordStorage, ILifetimeScope scope) { if (DesignMode) { return; } _appSettingsService = appSettingsService; _memoStorageService = memoStorageService; _passwordStorage = passwordStorage; _scope = scope; _applicationState = new ApplicationState(); _tabPageDataCollection = TabPageDataCollection.CreateNewPageDataCollection(_appSettingsService.Settings.DefaultEmptyTabPages); _licenseService = LicenceService.Instance; InitializeComponent(); }
public bool SaveTabPageCollection(TabPageDataCollection tabPageDataCollection, string password) { bool success = false; try { var settings = new StorageManagerSettings(true, Environment.ProcessorCount, true, password); var storageManager = new StorageManager(settings); success = storageManager.SerializeObjectToFile(tabPageDataCollection, GetFullPathToDatabaseFile(), null); } catch (Exception ex) { Log.Error(ex, "Error saving database"); } FoundDatabaseErrors = false; return(success); }
private void createNewDatabaseToolStripMenuItem_Click(object sender, EventArgs e) { if ( MessageBox.Show(this, "Do you want to create a new Memo database? Doing so will overwrite any existing stored database under this account.", "Create new database?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK) { return; } var frmsetPassword = new FormSetPassword { Text = "Choose password" }; if (frmsetPassword.ShowDialog(this) != DialogResult.OK) { return; } string password = frmsetPassword.VerifiedPassword; if (string.IsNullOrEmpty(password)) { MessageBox.Show(this, "Password can not be empty!", Resources.FormMain__ErrorText, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _passwordStorage.Set(PwdKey, password); _tabPageDataCollection = TabPageDataCollection.CreateNewPageDataCollection(_appSettingsService.Settings.DefaultEmptyTabPages); _memoStorageService.SaveTabPageCollection(_tabPageDataCollection, password); _appSettingsService.Settings.PasswordDerivedString = GeneralConverters.GeneratePasswordDerivedString(_appSettingsService.Settings.ApplicationSaltValue + password + _appSettingsService.Settings.ApplicationSaltValue); _appSettingsService.SaveSettings(); InitializeTabControls(); _applicationState.DatabaseLoaded = true; _applicationState.DatabaseExists = true; UpdateApplicationState(); }
private void RestoreDatabaseFromSyncPathMenuItem_Click(object sender, EventArgs e) { if (_applicationState.DatabaseExists && MessageBox.Show("Are you sure that you want to replace the existing database?\nIt is recommended that you perform a backup before replacing the existing database!", "Replace database from sync folder", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } var formGetPassword = new FormGetPassword { UsePasswordValidation = false }; if (formGetPassword.ShowDialog(this) != DialogResult.OK) { return; } string password = formGetPassword.PasswordString; _tabPageDataCollection = null; _applicationState.DatabaseLoaded = false; _appSettingsService.LoadSettings(); InitFormSettings(); RestoreSyncDataResult result = _memoStorageService.RestoreBackupFromSyncFolder(password); if (result.Successful) { MessageBox.Show("Database and app settings restored from sync folder.", "Restore complete", MessageBoxButtons.OK, MessageBoxIcon.Information); _applicationState.DatabaseExists = true; UpdateApplicationState(); } else { MessageBox.Show("Could not restore sync folder content: " + result.ErrorText, "Error restoring data", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public TabSearchEngine(TabPageDataCollection tabPageDataCollection, int textStartIndex = 0) { _searchState = new TextSearchState(); _tabPageDataCollection = tabPageDataCollection; ResetSearchState(_tabPageDataCollection.ActiveTabIndex, textStartIndex, 0); }
public PageDataCollectionManager(TabPageDataCollection dataCollection) { _dataCollection = dataCollection; }