diff --git a/DtoImporterService/UNTESTED/LibraryImporter.cs b/DtoImporterService/UNTESTED/LibraryImporter.cs index 8b1cd0de..fad44583 100644 --- a/DtoImporterService/UNTESTED/LibraryImporter.cs +++ b/DtoImporterService/UNTESTED/LibraryImporter.cs @@ -33,7 +33,7 @@ namespace DtoImporterService // currently, inserting LibraryBook will throw error if the same book is in multiple accounts for the same region. // // CURRENT SOLUTION: don't re-insert - + var currentLibraryProductIds = DbContext.Library.Select(l => l.Book.AudibleProductId).ToList(); var newItems = items.Where(dto => !currentLibraryProductIds.Contains(dto.ProductId)).ToList(); diff --git a/FileLiberator/UNTESTED/DecryptBook.cs b/FileLiberator/UNTESTED/DecryptBook.cs index f392ff19..e814b72f 100644 --- a/FileLiberator/UNTESTED/DecryptBook.cs +++ b/FileLiberator/UNTESTED/DecryptBook.cs @@ -59,7 +59,7 @@ namespace FileLiberator var proposedOutputFile = Path.Combine(AudibleFileStorage.DecryptInProgress, $"[{libraryBook.Book.AudibleProductId}].m4b"); var account = AudibleApiStorage - .GetAccounts() + .GetAccountsSettings() .GetAccount(libraryBook.Account, libraryBook.Book.Locale); var outputAudioFilename = await aaxToM4bConverterDecrypt(proposedOutputFile, aaxFilename, account); diff --git a/InternalUtilities/Accounts.cs b/InternalUtilities/Accounts.cs index 60898f97..4c4ff232 100644 --- a/InternalUtilities/Accounts.cs +++ b/InternalUtilities/Accounts.cs @@ -10,49 +10,49 @@ using Newtonsoft.Json; namespace InternalUtilities { - public class AccountsPersister : JsonFilePersister + public class AccountsSettingsPersister : JsonFilePersister { /// Alias for Target - public Accounts Accounts => Target; + public AccountsSettings AccountsSettings => Target; /// uses path. create file if doesn't yet exist - public AccountsPersister(Accounts target, string path, string jsonPath = null) + public AccountsSettingsPersister(AccountsSettings target, string path, string jsonPath = null) : base(target, path, jsonPath) { } /// load from existing file - public AccountsPersister(string path, string jsonPath = null) + public AccountsSettingsPersister(string path, string jsonPath = null) : base(path, jsonPath) { } protected override JsonSerializerSettings GetSerializerSettings() => Identity.GetJsonSerializerSettings(); } - // 'Accounts' is intentionally not IEnumerable<> so that properties can be added/extended + // 'AccountsSettings' is intentionally not IEnumerable<> so that properties can be added/extended // from newtonsoft (https://www.newtonsoft.com/json/help/html/SerializationGuide.htm): // .NET : IList, IEnumerable, IList, Array // JSON : Array (properties on the collection will not be serialized) - public class Accounts : IUpdatable + public class AccountsSettings : IUpdatable { public event EventHandler Updated; private void update(object sender = null, EventArgs e = null) { - foreach (var account in AccountsSettings) + foreach (var account in Accounts) validate(account); update_no_validate(); } private void update_no_validate() => Updated?.Invoke(this, new EventArgs()); - public Accounts() { } + public AccountsSettings() { } - // for some reason this will make the json instantiator use _accountsSettings_json.set() + // for some reason this will make the json instantiator use _accounts_json.set() [JsonConstructor] - protected Accounts(List accounts) { } + protected AccountsSettings(List accountsSettings) { } - #region AccountsSettings - private List _accountsSettings_backing = new List(); - [JsonProperty(PropertyName = "AccountsSettings")] - private List _accountsSettings_json + #region Accounts + private List _accounts_backing = new List(); + [JsonProperty(PropertyName = "Accounts")] + private List _accounts_json { - get => _accountsSettings_backing; + get => _accounts_backing; // 'set' is only used by json deser set { @@ -66,11 +66,11 @@ namespace InternalUtilities } } [JsonIgnore] - public IReadOnlyList AccountsSettings => _accountsSettings_json.AsReadOnly(); + public IReadOnlyList Accounts => _accounts_json.AsReadOnly(); #endregion - public static Accounts FromJson(string json) - => JsonConvert.DeserializeObject(json, Identity.GetJsonSerializerSettings()); + public static AccountsSettings FromJson(string json) + => JsonConvert.DeserializeObject(json, Identity.GetJsonSerializerSettings()); public string ToJson(Formatting formatting = Formatting.Indented) => JsonConvert.SerializeObject(this, formatting, Identity.GetJsonSerializerSettings()); @@ -85,19 +85,19 @@ namespace InternalUtilities { validate(account); - _accountsSettings_backing.Add(account); + _accounts_backing.Add(account); account.Updated += update; } // more common naming convention alias for internal collection - public IReadOnlyList GetAll() => AccountsSettings; + public IReadOnlyList GetAll() => Accounts; public Account GetAccount(string accountId, string locale) { if (locale is null) return null; - return AccountsSettings.SingleOrDefault(a => a.AccountId == accountId && a.IdentityTokens.Locale.Name == locale); + return Accounts.SingleOrDefault(a => a.AccountId == accountId && a.IdentityTokens.Locale.Name == locale); } public Account Upsert(string accountId, string locale) @@ -117,11 +117,11 @@ namespace InternalUtilities public bool Delete(Account account) { - if (!_accountsSettings_backing.Contains(account)) + if (!_accounts_backing.Contains(account)) return false; account.Updated -= update; - return _accountsSettings_backing.Remove(account); + return _accounts_backing.Remove(account); } public bool Delete(string accountId, string locale) diff --git a/InternalUtilities/UNTESTED/AudibleApiStorage.cs b/InternalUtilities/UNTESTED/AudibleApiStorage.cs index 2c3f0d71..e878fbd5 100644 --- a/InternalUtilities/UNTESTED/AudibleApiStorage.cs +++ b/InternalUtilities/UNTESTED/AudibleApiStorage.cs @@ -16,7 +16,7 @@ namespace InternalUtilities { // saves. BEWARE: this will overwrite an existing file if (!File.Exists(AccountsSettingsFile)) - _ = new AccountsPersister(new Accounts(), AccountsSettingsFile); + _ = new AccountsSettingsPersister(new AccountsSettings(), AccountsSettingsFile); } // convenience for for tests and demos. don't use in production Libation @@ -24,10 +24,10 @@ namespace InternalUtilities => TEST_GetFirstAccount().GetIdentityTokensJsonPath(); // convenience for for tests and demos. don't use in production Libation public static Account TEST_GetFirstAccount() - => GetAccounts().GetAll().FirstOrDefault(); + => GetAccountsSettings().GetAll().FirstOrDefault(); - public static Accounts GetAccounts() - => new AccountsPersister(AccountsSettingsFile).Accounts; + public static AccountsSettings GetAccountsSettings() + => new AccountsSettingsPersister(AccountsSettingsFile).AccountsSettings; public static string GetIdentityTokensJsonPath(this Account account) => GetIdentityTokensJsonPath(account.AccountId, account.Locale?.Name); @@ -36,7 +36,7 @@ namespace InternalUtilities var usernameSanitized = trimSurroundingQuotes(JsonConvert.ToString(username)); var localeNameSanitized = trimSurroundingQuotes(JsonConvert.ToString(localeName)); - return $"$.AccountsSettings[?(@.AccountId == '{usernameSanitized}' && @.IdentityTokens.LocaleName == '{localeNameSanitized}')].IdentityTokens"; + return $"$.Accounts[?(@.AccountId == '{usernameSanitized}' && @.IdentityTokens.LocaleName == '{localeNameSanitized}')].IdentityTokens"; } // SubString algo is better than .Trim("\"") // orig string " diff --git a/LibationLauncher/LibationLauncher.csproj b/LibationLauncher/LibationLauncher.csproj index 6079cc20..e529f5ba 100644 --- a/LibationLauncher/LibationLauncher.csproj +++ b/LibationLauncher/LibationLauncher.csproj @@ -13,7 +13,7 @@ win-x64 - 3.1.12.249 + 3.1.12.253 diff --git a/LibationLauncher/UNTESTED/Program.cs b/LibationLauncher/UNTESTED/Program.cs index a514a0d9..3ee2fd74 100644 --- a/LibationLauncher/UNTESTED/Program.cs +++ b/LibationLauncher/UNTESTED/Program.cs @@ -162,7 +162,7 @@ namespace LibationLauncher }; // saves to new file - AudibleApiStorage.GetAccounts().Add(account); + AudibleApiStorage.GetAccountsSettings().Add(account); return account; } diff --git a/LibationWinForms/UNTESTED/Dialogs/AccountsDialog.Designer.cs b/LibationWinForms/UNTESTED/Dialogs/AccountsDialog.Designer.cs index f24e821b..f4d90064 100644 --- a/LibationWinForms/UNTESTED/Dialogs/AccountsDialog.Designer.cs +++ b/LibationWinForms/UNTESTED/Dialogs/AccountsDialog.Designer.cs @@ -82,12 +82,8 @@ this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.Size = new System.Drawing.Size(776, 397); this.dataGridView1.TabIndex = 0; - this.dataGridView1.CellBeginEdit += new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.dataGridView1_CellBeginEdit); - this.dataGridView1.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellEndEdit); this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.DataGridView1_CellContentClick); this.dataGridView1.DefaultValuesNeeded += new System.Windows.Forms.DataGridViewRowEventHandler(this.dataGridView1_DefaultValuesNeeded); - this.dataGridView1.RowsAdded += new System.Windows.Forms.DataGridViewRowsAddedEventHandler(this.dataGridView1_RowsAdded); - this.dataGridView1.RowsRemoved += new System.Windows.Forms.DataGridViewRowsRemovedEventHandler(this.dataGridView1_RowsRemoved); // // Original // diff --git a/LibationWinForms/UNTESTED/Dialogs/AccountsDialog.cs b/LibationWinForms/UNTESTED/Dialogs/AccountsDialog.cs index 64b91448..c436f955 100644 --- a/LibationWinForms/UNTESTED/Dialogs/AccountsDialog.cs +++ b/LibationWinForms/UNTESTED/Dialogs/AccountsDialog.cs @@ -2,7 +2,6 @@ using System.Linq; using System.Windows.Forms; using AudibleApi; -using FileManager; using InternalUtilities; namespace LibationWinForms.Dialogs @@ -37,7 +36,12 @@ namespace LibationWinForms.Dialogs private void populateGridValues() { - var accounts = AudibleApiStorage.GetAccounts().AccountsSettings; + // WARNING + // behind the scenes this returns a AccountsSettings + // accounts persister will write ANY EDIT to object immediately to file + // here: copy strings + // only persist in 'save' step + var accounts = AudibleApiStorage.GetAccountsSettings().Accounts; if (!accounts.Any()) return; @@ -92,42 +96,21 @@ namespace LibationWinForms.Dialogs private void cancelBtn_Click(object sender, EventArgs e) => this.Close(); - #region TEMP - private void saveBtn_Click(object sender, EventArgs e) { + var accounts = AudibleApiStorage.GetAccountsSettings() + .Accounts; + + // find added + // validate + + // find deleted + + // find edited + // validate + + // persist } - - private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) - { - - } - - private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) - { - - //if (e.ColumnIndex == dataGridView1.Columns["ItemID"].Index) //if the ItemID-cell is edited - //{ - // dataGridView1.Rows[e.RowIndex].ReadOnly = true; // set all row as read-only - // dataGridView1.Rows[e.RowIndex].Cells["ItemID"].ReadOnly = false; //except ItemID-cell - //} - } - - private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) - { - - //if (dataGridView1.Rows[e.RowIndex].Cells["ItemID"].Value != null) - //{ - // dataGridView1.Rows[e.RowIndex].ReadOnly = true; // set all row as read-only - // dataGridView1.Rows[e.RowIndex].Cells["ItemID"].ReadOnly = false; //except ItemID-cell - //} - } - - private void dataGridView1_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e) - { - - } - #endregion } } diff --git a/LibationWinForms/UNTESTED/Form1.Designer.cs b/LibationWinForms/UNTESTED/Form1.Designer.cs index f0e4a90e..4c23b94d 100644 --- a/LibationWinForms/UNTESTED/Form1.Designer.cs +++ b/LibationWinForms/UNTESTED/Form1.Designer.cs @@ -283,6 +283,7 @@ } #endregion + private System.Windows.Forms.Panel gridPanel; private System.Windows.Forms.MenuStrip menuStrip1; private System.Windows.Forms.ToolStripMenuItem importToolStripMenuItem; @@ -309,4 +310,3 @@ private System.Windows.Forms.ToolStripMenuItem accountsToolStripMenuItem; } } - diff --git a/WinFormsDesigner/Form1.Designer.cs b/WinFormsDesigner/Form1.Designer.cs index abd06293..4adec110 100644 --- a/WinFormsDesigner/Form1.Designer.cs +++ b/WinFormsDesigner/Form1.Designer.cs @@ -1,33 +1,33 @@ namespace WinFormsDesigner { - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } - #region Windows Form Designer generated code + #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.gridPanel = new System.Windows.Forms.Panel(); this.filterHelpBtn = new System.Windows.Forms.Button(); @@ -44,6 +44,7 @@ this.editQuickFiltersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.accountsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.basicSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.advancedSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); @@ -58,9 +59,9 @@ // // gridPanel // - this.gridPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); + this.gridPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.gridPanel.Location = new System.Drawing.Point(12, 56); this.gridPanel.Name = "gridPanel"; this.gridPanel.Size = new System.Drawing.Size(839, 386); @@ -87,8 +88,8 @@ // // filterSearchTb // - this.filterSearchTb.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); + this.filterSearchTb.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.filterSearchTb.Location = new System.Drawing.Point(186, 29); this.filterSearchTb.Name = "filterSearchTb"; this.filterSearchTb.Size = new System.Drawing.Size(584, 20); @@ -97,10 +98,10 @@ // menuStrip1 // this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.importToolStripMenuItem, - this.liberateToolStripMenuItem, - this.quickFiltersToolStripMenuItem, - this.settingsToolStripMenuItem}); + this.importToolStripMenuItem, + this.liberateToolStripMenuItem, + this.quickFiltersToolStripMenuItem, + this.settingsToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(863, 24); @@ -110,7 +111,7 @@ // importToolStripMenuItem // this.importToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.scanLibraryToolStripMenuItem}); + this.scanLibraryToolStripMenuItem}); this.importToolStripMenuItem.Name = "importToolStripMenuItem"; this.importToolStripMenuItem.Size = new System.Drawing.Size(55, 20); this.importToolStripMenuItem.Text = "&Import"; @@ -124,8 +125,8 @@ // liberateToolStripMenuItem // this.liberateToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.beginBookBackupsToolStripMenuItem, - this.beginPdfBackupsToolStripMenuItem}); + this.beginBookBackupsToolStripMenuItem, + this.beginPdfBackupsToolStripMenuItem}); this.liberateToolStripMenuItem.Name = "liberateToolStripMenuItem"; this.liberateToolStripMenuItem.Size = new System.Drawing.Size(61, 20); this.liberateToolStripMenuItem.Text = "&Liberate"; @@ -145,9 +146,9 @@ // quickFiltersToolStripMenuItem // this.quickFiltersToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.firstFilterIsDefaultToolStripMenuItem, - this.editQuickFiltersToolStripMenuItem, - this.toolStripSeparator1}); + this.firstFilterIsDefaultToolStripMenuItem, + this.editQuickFiltersToolStripMenuItem, + this.toolStripSeparator1}); this.quickFiltersToolStripMenuItem.Name = "quickFiltersToolStripMenuItem"; this.quickFiltersToolStripMenuItem.Size = new System.Drawing.Size(84, 20); this.quickFiltersToolStripMenuItem.Text = "Quick &Filters"; @@ -162,7 +163,7 @@ // this.editQuickFiltersToolStripMenuItem.Name = "editQuickFiltersToolStripMenuItem"; this.editQuickFiltersToolStripMenuItem.Size = new System.Drawing.Size(256, 22); - this.editQuickFiltersToolStripMenuItem.Text = "&Edit quick filters"; + this.editQuickFiltersToolStripMenuItem.Text = "&Edit quick filters..."; // // toolStripSeparator1 // @@ -172,31 +173,38 @@ // settingsToolStripMenuItem // this.settingsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.basicSettingsToolStripMenuItem, - this.advancedSettingsToolStripMenuItem}); + this.accountsToolStripMenuItem, + this.basicSettingsToolStripMenuItem, + this.advancedSettingsToolStripMenuItem}); this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem"; this.settingsToolStripMenuItem.Size = new System.Drawing.Size(61, 20); this.settingsToolStripMenuItem.Text = "&Settings"; // + // accountsToolStripMenuItem + // + this.accountsToolStripMenuItem.Name = "accountsToolStripMenuItem"; + this.accountsToolStripMenuItem.Size = new System.Drawing.Size(181, 22); + this.accountsToolStripMenuItem.Text = "&Accounts..."; + // // basicSettingsToolStripMenuItem // this.basicSettingsToolStripMenuItem.Name = "basicSettingsToolStripMenuItem"; - this.basicSettingsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.basicSettingsToolStripMenuItem.Text = "&Basic Settings"; + this.basicSettingsToolStripMenuItem.Size = new System.Drawing.Size(181, 22); + this.basicSettingsToolStripMenuItem.Text = "&Basic Settings..."; // // advancedSettingsToolStripMenuItem // this.advancedSettingsToolStripMenuItem.Name = "advancedSettingsToolStripMenuItem"; - this.advancedSettingsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.advancedSettingsToolStripMenuItem.Text = "&Advanced Settings"; + this.advancedSettingsToolStripMenuItem.Size = new System.Drawing.Size(181, 22); + this.advancedSettingsToolStripMenuItem.Text = "Ad&vanced Settings..."; // // statusStrip1 // this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.visibleCountLbl, - this.springLbl, - this.backupsCountsLbl, - this.pdfsCountsLbl}); + this.visibleCountLbl, + this.springLbl, + this.backupsCountsLbl, + this.pdfsCountsLbl}); this.statusStrip1.Location = new System.Drawing.Point(0, 445); this.statusStrip1.Name = "statusStrip1"; this.statusStrip1.Size = new System.Drawing.Size(863, 22); @@ -212,7 +220,7 @@ // springLbl // this.springLbl.Name = "springLbl"; - this.springLbl.Size = new System.Drawing.Size(232, 17); + this.springLbl.Size = new System.Drawing.Size(233, 17); this.springLbl.Spring = true; // // backupsCountsLbl @@ -224,7 +232,7 @@ // pdfsCountsLbl // this.pdfsCountsLbl.Name = "pdfsCountsLbl"; - this.pdfsCountsLbl.Size = new System.Drawing.Size(219, 17); + this.pdfsCountsLbl.Size = new System.Drawing.Size(218, 17); this.pdfsCountsLbl.Text = "| PDFs: NOT d/l\'ed: {0} Downloaded: {1}"; // // addFilterBtn @@ -259,32 +267,33 @@ this.ResumeLayout(false); this.PerformLayout(); - } + } - #endregion - private System.Windows.Forms.Panel gridPanel; - private System.Windows.Forms.MenuStrip menuStrip1; - private System.Windows.Forms.ToolStripMenuItem importToolStripMenuItem; - private System.Windows.Forms.StatusStrip statusStrip1; - private System.Windows.Forms.ToolStripStatusLabel springLbl; - private System.Windows.Forms.ToolStripStatusLabel visibleCountLbl; - private System.Windows.Forms.ToolStripMenuItem liberateToolStripMenuItem; - private System.Windows.Forms.ToolStripStatusLabel backupsCountsLbl; - private System.Windows.Forms.ToolStripMenuItem beginBookBackupsToolStripMenuItem; - private System.Windows.Forms.ToolStripStatusLabel pdfsCountsLbl; - private System.Windows.Forms.ToolStripMenuItem beginPdfBackupsToolStripMenuItem; - private System.Windows.Forms.TextBox filterSearchTb; - private System.Windows.Forms.Button filterBtn; - private System.Windows.Forms.Button filterHelpBtn; - private System.Windows.Forms.ToolStripMenuItem settingsToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem scanLibraryToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem quickFiltersToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem firstFilterIsDefaultToolStripMenuItem; - private System.Windows.Forms.Button addFilterBtn; - private System.Windows.Forms.ToolStripMenuItem editQuickFiltersToolStripMenuItem; - private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; + #endregion + + private System.Windows.Forms.Panel gridPanel; + private System.Windows.Forms.MenuStrip menuStrip1; + private System.Windows.Forms.ToolStripMenuItem importToolStripMenuItem; + private System.Windows.Forms.StatusStrip statusStrip1; + private System.Windows.Forms.ToolStripStatusLabel springLbl; + private System.Windows.Forms.ToolStripStatusLabel visibleCountLbl; + private System.Windows.Forms.ToolStripMenuItem liberateToolStripMenuItem; + private System.Windows.Forms.ToolStripStatusLabel backupsCountsLbl; + private System.Windows.Forms.ToolStripMenuItem beginBookBackupsToolStripMenuItem; + private System.Windows.Forms.ToolStripStatusLabel pdfsCountsLbl; + private System.Windows.Forms.ToolStripMenuItem beginPdfBackupsToolStripMenuItem; + private System.Windows.Forms.TextBox filterSearchTb; + private System.Windows.Forms.Button filterBtn; + private System.Windows.Forms.Button filterHelpBtn; + private System.Windows.Forms.ToolStripMenuItem settingsToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem scanLibraryToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem quickFiltersToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem firstFilterIsDefaultToolStripMenuItem; + private System.Windows.Forms.Button addFilterBtn; + private System.Windows.Forms.ToolStripMenuItem editQuickFiltersToolStripMenuItem; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.ToolStripMenuItem basicSettingsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem advancedSettingsToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem accountsToolStripMenuItem; } } - diff --git a/_Tests/InternalUtilities.Tests/AccountTests.cs b/_Tests/InternalUtilities.Tests/AccountTests.cs index b981f5b6..e001c4ba 100644 --- a/_Tests/InternalUtilities.Tests/AccountTests.cs +++ b/_Tests/InternalUtilities.Tests/AccountTests.cs @@ -34,11 +34,11 @@ namespace AccountsTests { var json = @" { - ""AccountsSettings"": [] + ""Accounts"": [] } ".Trim(); - var accounts = Accounts.FromJson(json); - accounts.AccountsSettings.Count.Should().Be(0); + var accountsSettings = AccountsSettings.FromJson(json); + accountsSettings.Accounts.Count.Should().Be(0); } [TestMethod] @@ -46,7 +46,7 @@ namespace AccountsTests { var json = @" { - ""AccountsSettings"": [ + ""Accounts"": [ { ""AccountId"": ""cng"", ""AccountName"": ""my main login"", @@ -56,10 +56,10 @@ namespace AccountsTests ] } ".Trim(); - var accounts = Accounts.FromJson(json); - accounts.AccountsSettings.Count.Should().Be(1); - accounts.AccountsSettings[0].AccountId.Should().Be("cng"); - accounts.AccountsSettings[0].IdentityTokens.Should().BeNull(); + var accountsSettings = AccountsSettings.FromJson(json); + accountsSettings.Accounts.Count.Should().Be(1); + accountsSettings.Accounts[0].AccountId.Should().Be("cng"); + accountsSettings.Accounts[0].IdentityTokens.Should().BeNull(); } [TestMethod] @@ -69,7 +69,7 @@ namespace AccountsTests var json = $@" {{ - ""AccountsSettings"": [ + ""Accounts"": [ {{ ""AccountId"": ""cng"", ""AccountName"": ""my main login"", @@ -79,11 +79,11 @@ namespace AccountsTests ] }} ".Trim(); - var accounts = Accounts.FromJson(json); - accounts.AccountsSettings.Count.Should().Be(1); - accounts.AccountsSettings[0].AccountId.Should().Be("cng"); - accounts.AccountsSettings[0].IdentityTokens.Should().NotBeNull(); - accounts.AccountsSettings[0].IdentityTokens.ExistingAccessToken.TokenValue.Should().Be(AccessTokenValue); + var accountsSettings = AccountsSettings.FromJson(json); + accountsSettings.Accounts.Count.Should().Be(1); + accountsSettings.Accounts[0].AccountId.Should().Be("cng"); + accountsSettings.Accounts[0].IdentityTokens.Should().NotBeNull(); + accountsSettings.Accounts[0].IdentityTokens.ExistingAccessToken.TokenValue.Should().Be(AccessTokenValue); } } @@ -96,7 +96,7 @@ namespace AccountsTests var id = JsonConvert.SerializeObject(Identity.Empty, Identity.GetJsonSerializerSettings()); var jsonIn = $@" {{ - ""AccountsSettings"": [ + ""Accounts"": [ {{ ""AccountId"": ""cng"", ""AccountName"": ""my main login"", @@ -106,12 +106,12 @@ namespace AccountsTests ] }} ".Trim(); - var accounts = Accounts.FromJson(jsonIn); + var accountsSettings = AccountsSettings.FromJson(jsonIn); - var jsonOut = accounts.ToJson(); + var jsonOut = accountsSettings.ToJson(); jsonOut.Should().Be(@" { - ""AccountsSettings"": [ + ""Accounts"": [ { ""AccountId"": ""cng"", ""AccountName"": ""my main login"", @@ -162,12 +162,12 @@ namespace AccountsTests public void create_file() { File.Exists(TestFile).Should().BeFalse(); - var accounts = new Accounts(); - _ = new AccountsPersister(accounts, TestFile); + var accountsSettings = new AccountsSettings(); + _ = new AccountsSettingsPersister(accountsSettings, TestFile); File.Exists(TestFile).Should().BeTrue(); File.ReadAllText(TestFile).Should().Be(@" { - ""AccountsSettings"": [] + ""Accounts"": [] } ".Trim()); } @@ -179,12 +179,12 @@ namespace AccountsTests WriteToTestFile("foo"); File.Exists(TestFile).Should().BeTrue(); - var accounts = new Accounts(); - _ = new AccountsPersister(accounts, TestFile); + var accountsSettings = new AccountsSettings(); + _ = new AccountsSettingsPersister(accountsSettings, TestFile); File.Exists(TestFile).Should().BeTrue(); File.ReadAllText(TestFile).Should().Be(@" { - ""AccountsSettings"": [] + ""Accounts"": [] } ".Trim()); } @@ -192,16 +192,16 @@ namespace AccountsTests [TestMethod] public void save_multiple_children() { - var accounts = new Accounts(); - accounts.Add(new Account("a0") { AccountName = "n0" }); - accounts.Add(new Account("a1") { AccountName = "n1" }); + var accountsSettings = new AccountsSettings(); + accountsSettings.Add(new Account("a0") { AccountName = "n0" }); + accountsSettings.Add(new Account("a1") { AccountName = "n1" }); // dispose to cease auto-updates - using (var p = new AccountsPersister(accounts, TestFile)) { } + using (var p = new AccountsSettingsPersister(accountsSettings, TestFile)) { } - var persister = new AccountsPersister(TestFile); - persister.Accounts.AccountsSettings.Count.Should().Be(2); - persister.Accounts.AccountsSettings[1].AccountName.Should().Be("n1"); + var persister = new AccountsSettingsPersister(TestFile); + persister.AccountsSettings.Accounts.Count.Should().Be(2); + persister.AccountsSettings.Accounts[1].AccountName.Should().Be("n1"); } [TestMethod] @@ -210,14 +210,14 @@ namespace AccountsTests var id = new Identity(usLocale); var idJson = JsonConvert.SerializeObject(id, Identity.GetJsonSerializerSettings()); - var accounts = new Accounts(); - accounts.Add(new Account("a0") { AccountName = "n0", IdentityTokens = id }); + var accountsSettings = new AccountsSettings(); + accountsSettings.Add(new Account("a0") { AccountName = "n0", IdentityTokens = id }); // dispose to cease auto-updates - using (var p = new AccountsPersister(accounts, TestFile)) { } + using (var p = new AccountsSettingsPersister(accountsSettings, TestFile)) { } - var persister = new AccountsPersister(TestFile); - var acct = persister.Accounts.AccountsSettings[0]; + var persister = new AccountsSettingsPersister(TestFile); + var acct = persister.AccountsSettings.Accounts[0]; acct.AccountName.Should().Be("n0"); acct.Locale.CountryCode.Should().Be("us"); } @@ -231,22 +231,22 @@ namespace AccountsTests public void save_1_account() { // create initial file - using (var p = new AccountsPersister(new Accounts(), TestFile)) { } + using (var p = new AccountsSettingsPersister(new AccountsSettings(), TestFile)) { } // load file. create account - using (var p = new AccountsPersister(TestFile)) + using (var p = new AccountsSettingsPersister(TestFile)) { var idIn = new Identity(usLocale); var acctIn = new Account("a0") { AccountName = "n0", IdentityTokens = idIn }; - p.Accounts.Add(acctIn); + p.AccountsSettings.Add(acctIn); } // re-load file. ensure account still exists - using (var p = new AccountsPersister(TestFile)) + using (var p = new AccountsSettingsPersister(TestFile)) { - p.Accounts.AccountsSettings.Count.Should().Be(1); - var acct0 = p.Accounts.AccountsSettings[0]; + p.AccountsSettings.Accounts.Count.Should().Be(1); + var acct0 = p.AccountsSettings.Accounts[0]; acct0.AccountName.Should().Be("n0"); acct0.Locale.CountryCode.Should().Be("us"); } @@ -258,46 +258,46 @@ namespace AccountsTests public void save_2_accounts() { // create initial file - using (var p = new AccountsPersister(new Accounts(), TestFile)) { } + using (var p = new AccountsSettingsPersister(new AccountsSettings(), TestFile)) { } // load file. create account 0 - using (var p = new AccountsPersister(TestFile)) + using (var p = new AccountsSettingsPersister(TestFile)) { var idIn = new Identity(usLocale); var acctIn = new Account("a0") { AccountName = "n0", IdentityTokens = idIn }; - p.Accounts.Add(acctIn); + p.AccountsSettings.Add(acctIn); } // re-load file. ensure account still exists - using (var p = new AccountsPersister(TestFile)) + using (var p = new AccountsSettingsPersister(TestFile)) { - p.Accounts.AccountsSettings.Count.Should().Be(1); + p.AccountsSettings.Accounts.Count.Should().Be(1); - var acct0 = p.Accounts.AccountsSettings[0]; + var acct0 = p.AccountsSettings.Accounts[0]; acct0.AccountName.Should().Be("n0"); acct0.Locale.CountryCode.Should().Be("us"); } // load file. create account 1 - using (var p = new AccountsPersister(TestFile)) + using (var p = new AccountsSettingsPersister(TestFile)) { var idIn = new Identity(ukLocale); var acctIn = new Account("a1") { AccountName = "n1", IdentityTokens = idIn }; - p.Accounts.Add(acctIn); + p.AccountsSettings.Add(acctIn); } // re-load file. ensure both accounts still exist - using (var p = new AccountsPersister(TestFile)) + using (var p = new AccountsSettingsPersister(TestFile)) { - p.Accounts.AccountsSettings.Count.Should().Be(2); + p.AccountsSettings.Accounts.Count.Should().Be(2); - var acct0 = p.Accounts.AccountsSettings[0]; + var acct0 = p.AccountsSettings.Accounts[0]; acct0.AccountName.Should().Be("n0"); acct0.Locale.CountryCode.Should().Be("us"); - var acct1 = p.Accounts.AccountsSettings[1]; + var acct1 = p.AccountsSettings.Accounts[1]; acct1.AccountName.Should().Be("n1"); acct1.Locale.CountryCode.Should().Be("uk"); } @@ -307,23 +307,23 @@ namespace AccountsTests public void update_Account_field_just_added() { // create initial file - using (var p = new AccountsPersister(new Accounts(), TestFile)) { } + using (var p = new AccountsSettingsPersister(new AccountsSettings(), TestFile)) { } // load file. create 2 accounts - using (var p = new AccountsPersister(TestFile)) + using (var p = new AccountsSettingsPersister(TestFile)) { var id1 = new Identity(usLocale); var acct1 = new Account("a0") { AccountName = "n0", IdentityTokens = id1 }; - p.Accounts.Add(acct1); + p.AccountsSettings.Add(acct1); // update just-added item. note: this is different than the subscription which happens on initial collection load. ensure this works also acct1.AccountName = "new"; } // verify save property - using (var p = new AccountsPersister(TestFile)) + using (var p = new AccountsSettingsPersister(TestFile)) { - var acct0 = p.Accounts.AccountsSettings[0]; + var acct0 = p.AccountsSettings.Accounts[0]; acct0.AccountName.Should().Be("new"); } } @@ -333,40 +333,40 @@ namespace AccountsTests public void update_Account_field() { // create initial file - using (var p = new AccountsPersister(new Accounts(), TestFile)) { } + using (var p = new AccountsSettingsPersister(new AccountsSettings(), TestFile)) { } // load file. create 2 accounts - using (var p = new AccountsPersister(TestFile)) + using (var p = new AccountsSettingsPersister(TestFile)) { var id1 = new Identity(usLocale); var acct1 = new Account("a0") { AccountName = "n0", IdentityTokens = id1 }; - p.Accounts.Add(acct1); + p.AccountsSettings.Add(acct1); var id2 = new Identity(ukLocale); var acct2 = new Account("a1") { AccountName = "n1", IdentityTokens = id2 }; - p.Accounts.Add(acct2); + p.AccountsSettings.Add(acct2); } // update AccountName on existing file - using (var p = new AccountsPersister(TestFile)) + using (var p = new AccountsSettingsPersister(TestFile)) { - var acct0 = p.Accounts.AccountsSettings[0]; + var acct0 = p.AccountsSettings.Accounts[0]; acct0.AccountName = "new"; } // re-load file. ensure both accounts still exist - using (var p = new AccountsPersister(TestFile)) + using (var p = new AccountsSettingsPersister(TestFile)) { - p.Accounts.AccountsSettings.Count.Should().Be(2); + p.AccountsSettings.Accounts.Count.Should().Be(2); - var acct0 = p.Accounts.AccountsSettings[0]; + var acct0 = p.AccountsSettings.Accounts[0]; // new acct0.AccountName.Should().Be("new"); // still here acct0.Locale.CountryCode.Should().Be("us"); - var acct1 = p.Accounts.AccountsSettings[1]; + var acct1 = p.AccountsSettings.Accounts[1]; acct1.AccountName.Should().Be("n1"); acct1.Locale.CountryCode.Should().Be("uk"); } @@ -377,42 +377,42 @@ namespace AccountsTests public void replace_identity() { // create initial file - using (var p = new AccountsPersister(new Accounts(), TestFile)) { } + using (var p = new AccountsSettingsPersister(new AccountsSettings(), TestFile)) { } // load file. create 2 accounts - using (var p = new AccountsPersister(TestFile)) + using (var p = new AccountsSettingsPersister(TestFile)) { var id1 = new Identity(usLocale); var acct1 = new Account("a0") { AccountName = "n0", IdentityTokens = id1 }; - p.Accounts.Add(acct1); + p.AccountsSettings.Add(acct1); var id2 = new Identity(ukLocale); var acct2 = new Account("a1") { AccountName = "n1", IdentityTokens = id2 }; - p.Accounts.Add(acct2); + p.AccountsSettings.Add(acct2); } // update identity on existing file - using (var p = new AccountsPersister(TestFile)) + using (var p = new AccountsSettingsPersister(TestFile)) { var id = new Identity(ukLocale); - var acct0 = p.Accounts.AccountsSettings[0]; + var acct0 = p.AccountsSettings.Accounts[0]; acct0.IdentityTokens = id; } // re-load file. ensure both accounts still exist - using (var p = new AccountsPersister(TestFile)) + using (var p = new AccountsSettingsPersister(TestFile)) { - p.Accounts.AccountsSettings.Count.Should().Be(2); + p.AccountsSettings.Accounts.Count.Should().Be(2); - var acct0 = p.Accounts.AccountsSettings[0]; + var acct0 = p.AccountsSettings.Accounts[0]; // new acct0.Locale.CountryCode.Should().Be("uk"); // still here acct0.AccountName.Should().Be("n0"); - var acct1 = p.Accounts.AccountsSettings[1]; + var acct1 = p.AccountsSettings.Accounts[1]; acct1.AccountName.Should().Be("n1"); acct1.Locale.CountryCode.Should().Be("uk"); } @@ -424,42 +424,42 @@ namespace AccountsTests public void update_identity_field() { // create initial file - using (var p = new AccountsPersister(new Accounts(), TestFile)) { } + using (var p = new AccountsSettingsPersister(new AccountsSettings(), TestFile)) { } // load file. create 2 accounts - using (var p = new AccountsPersister(TestFile)) + using (var p = new AccountsSettingsPersister(TestFile)) { var id1 = new Identity(usLocale); var acct1 = new Account("a0") { AccountName = "n0", IdentityTokens = id1 }; - p.Accounts.Add(acct1); + p.AccountsSettings.Add(acct1); var id2 = new Identity(ukLocale); var acct2 = new Account("a1") { AccountName = "n1", IdentityTokens = id2 }; - p.Accounts.Add(acct2); + p.AccountsSettings.Add(acct2); } // update identity on existing file - using (var p = new AccountsPersister(TestFile)) + using (var p = new AccountsSettingsPersister(TestFile)) { - p.Accounts.AccountsSettings[0] + p.AccountsSettings.Accounts[0] .IdentityTokens .Update(new AccessToken("Atna|_NEW_", DateTime.Now.AddDays(1))); } // re-load file. ensure both accounts still exist - using (var p = new AccountsPersister(TestFile)) + using (var p = new AccountsSettingsPersister(TestFile)) { - p.Accounts.AccountsSettings.Count.Should().Be(2); + p.AccountsSettings.Accounts.Count.Should().Be(2); - var acct0 = p.Accounts.AccountsSettings[0]; + var acct0 = p.AccountsSettings.Accounts[0]; // new acct0.IdentityTokens.ExistingAccessToken.TokenValue.Should().Be("Atna|_NEW_"); // still here acct0.AccountName.Should().Be("n0"); acct0.Locale.CountryCode.Should().Be("us"); - var acct1 = p.Accounts.AccountsSettings[1]; + var acct1 = p.AccountsSettings.Accounts[1]; acct1.AccountName.Should().Be("n1"); acct1.Locale.CountryCode.Should().Be("uk"); } @@ -478,11 +478,11 @@ namespace AccountsTests var idUk = new Identity(ukLocale); var acct2 = new Account("cng") { IdentityTokens = idUk, AccountName = "bar" }; - var accounts = new Accounts(); - accounts.Add(acct1); - accounts.Add(acct2); + var accountsSettings = new AccountsSettings(); + accountsSettings.Add(acct1); + accountsSettings.Add(acct2); - accounts.GetAccount("cng", "uk").AccountName.Should().Be("bar"); + accountsSettings.GetAccount("cng", "uk").AccountName.Should().Be("bar"); } } @@ -492,23 +492,23 @@ namespace AccountsTests [TestMethod] public void upsert_new() { - var accounts = new Accounts(); - accounts.AccountsSettings.Count.Should().Be(0); + var accountsSettings = new AccountsSettings(); + accountsSettings.Accounts.Count.Should().Be(0); - accounts.Upsert("cng", "us"); + accountsSettings.Upsert("cng", "us"); - accounts.AccountsSettings.Count.Should().Be(1); - accounts.GetAccount("cng", "us").AccountId.Should().Be("cng"); + accountsSettings.Accounts.Count.Should().Be(1); + accountsSettings.GetAccount("cng", "us").AccountId.Should().Be("cng"); } [TestMethod] public void upsert_exists() { - var accounts = new Accounts(); - var orig = accounts.Upsert("cng", "us"); + var accountsSettings = new AccountsSettings(); + var orig = accountsSettings.Upsert("cng", "us"); orig.AccountName = "foo"; - var exists = accounts.Upsert("cng", "us"); + var exists = accountsSettings.Upsert("cng", "us"); exists.AccountName.Should().Be("foo"); orig.Should().IsSameOrEqualTo(exists); @@ -521,28 +521,28 @@ namespace AccountsTests [TestMethod] public void delete_account() { - var accounts = new Accounts(); - var acct = accounts.Upsert("cng", "us"); - accounts.AccountsSettings.Count.Should().Be(1); + var accountsSettings = new AccountsSettings(); + var acct = accountsSettings.Upsert("cng", "us"); + accountsSettings.Accounts.Count.Should().Be(1); - var removed = accounts.Delete(acct); + var removed = accountsSettings.Delete(acct); removed.Should().BeTrue(); - accounts.AccountsSettings.Count.Should().Be(0); + accountsSettings.Accounts.Count.Should().Be(0); } [TestMethod] public void delete_where() { - var accounts = new Accounts(); - var acct = accounts.Upsert("cng", "us"); - accounts.AccountsSettings.Count.Should().Be(1); + var accountsSettings = new AccountsSettings(); + _ = accountsSettings.Upsert("cng", "us"); + accountsSettings.Accounts.Count.Should().Be(1); - accounts.Delete("baz", "baz").Should().BeFalse(); - accounts.AccountsSettings.Count.Should().Be(1); + accountsSettings.Delete("baz", "baz").Should().BeFalse(); + accountsSettings.Accounts.Count.Should().Be(1); - accounts.Delete("cng", "us").Should().BeTrue(); - accounts.AccountsSettings.Count.Should().Be(0); + accountsSettings.Delete("cng", "us").Should().BeTrue(); + accountsSettings.Accounts.Count.Should().Be(0); } [TestMethod] @@ -550,26 +550,26 @@ namespace AccountsTests { Account acct; - using (var p = new AccountsPersister(new Accounts(), TestFile)) + using (var p = new AccountsSettingsPersister(new AccountsSettings(), TestFile)) { - acct = p.Accounts.Upsert("foo", "us"); - p.Accounts.AccountsSettings.Count.Should().Be(1); + acct = p.AccountsSettings.Upsert("foo", "us"); + p.AccountsSettings.Accounts.Count.Should().Be(1); acct.AccountName = "old"; } - using (var p = new AccountsPersister(new Accounts(), TestFile)) + using (var p = new AccountsSettingsPersister(new AccountsSettings(), TestFile)) { - p.Accounts.Delete(acct); - p.Accounts.AccountsSettings.Count.Should().Be(0); + p.AccountsSettings.Delete(acct); + p.AccountsSettings.Accounts.Count.Should().Be(0); } - using (var p = new AccountsPersister(new Accounts(), TestFile)) + using (var p = new AccountsSettingsPersister(new AccountsSettings(), TestFile)) { - File.ReadAllText(TestFile).Should().Be("{\r\n \"AccountsSettings\": []\r\n}".Trim()); + File.ReadAllText(TestFile).Should().Be("{\r\n \"Accounts\": []\r\n}".Trim()); acct.AccountName = "new"; - File.ReadAllText(TestFile).Should().Be("{\r\n \"AccountsSettings\": []\r\n}".Trim()); + File.ReadAllText(TestFile).Should().Be("{\r\n \"Accounts\": []\r\n}".Trim()); } } } @@ -581,31 +581,31 @@ namespace AccountsTests [TestMethod] public void violate_validation() { - var accounts = new Accounts(); + var accountsSettings = new AccountsSettings(); var idIn = new Identity(usLocale); var a1 = new Account("a") { AccountName = "one", IdentityTokens = idIn }; - accounts.Add(a1); + accountsSettings.Add(a1); var a2 = new Account("a") { AccountName = "two", IdentityTokens = idIn }; // violation: validate() - Assert.ThrowsException(() => accounts.Add(a2)); + Assert.ThrowsException(() => accountsSettings.Add(a2)); } [TestMethod] public void identity_violate_validation() { - var accounts = new Accounts(); + var accountsSettings = new AccountsSettings(); var idIn = new Identity(usLocale); var a1 = new Account("a") { AccountName = "one", IdentityTokens = idIn }; - accounts.Add(a1); + accountsSettings.Add(a1); var a2 = new Account("a") { AccountName = "two" }; - accounts.Add(a2); + accountsSettings.Add(a2); // violation: GetAccount.SingleOrDefault Assert.ThrowsException(() => a2.IdentityTokens = idIn);