improved logging: at startup, config changes, library counts

better starting instructions to liberate library
This commit is contained in:
Robert McRackan 2019-12-31 09:49:32 -05:00
parent d9e0f1aedf
commit c7c1b4505b
8 changed files with 69 additions and 37 deletions

View File

@ -64,7 +64,34 @@ namespace FileManager
// set cache // set cache
stringCache[propertyName] = newValue; stringCache[propertyName] = newValue;
// set in file writeFile(propertyName, newValue);
}
public void Set(string propertyName, object newValue)
{
// set cache
objectCache[propertyName] = newValue;
var parsedNewValue = JToken.Parse(JsonConvert.SerializeObject(newValue));
writeFile(propertyName, parsedNewValue);
}
private void writeFile(string propertyName, JToken newValue)
{
try
{
var str = newValue?.ToString();
var formattedValue
= str is null ? "[null]"
: string.IsNullOrEmpty(str) ? "[empty]"
: string.IsNullOrWhiteSpace(str) ? $"[whitespace. Length={str.Length}]"
: str.Length > 100 ? $"[Length={str.Length}] {str[0..50]}...{str[^50..^0]}"
: str;
Serilog.Log.Logger.Information($"Config changed. {propertyName}={formattedValue}");
}
catch { }
// write new setting to file
lock (locker) lock (locker)
{ {
var jObject = readFile(); var jObject = readFile();
@ -73,20 +100,7 @@ namespace FileManager
} }
} }
public void Set(string propertyName, object newValue) // special case: no caching. no logging
{
// set cache
objectCache[propertyName] = newValue;
// set in file
lock (locker)
{
var jObject = readFile();
jObject[propertyName] = JToken.Parse(JsonConvert.SerializeObject(newValue));
File.WriteAllText(Filepath, JsonConvert.SerializeObject(jObject, Formatting.Indented));
}
}
public void SetWithJsonPath(string jsonPath, string propertyName, string newValue) public void SetWithJsonPath(string jsonPath, string propertyName, string newValue)
{ {
lock (locker) lock (locker)
@ -94,6 +108,7 @@ namespace FileManager
var jObject = readFile(); var jObject = readFile();
var token = jObject.SelectToken(jsonPath); var token = jObject.SelectToken(jsonPath);
var debug_oldValue = (string)token[propertyName]; var debug_oldValue = (string)token[propertyName];
token[propertyName] = newValue; token[propertyName] = newValue;
File.WriteAllText(Filepath, JsonConvert.SerializeObject(jObject, Formatting.Indented)); File.WriteAllText(Filepath, JsonConvert.SerializeObject(jObject, Formatting.Indented));
} }

View File

@ -13,7 +13,7 @@
<!-- <PublishSingleFile>true</PublishSingleFile> --> <!-- <PublishSingleFile>true</PublishSingleFile> -->
<RuntimeIdentifier>win-x64</RuntimeIdentifier> <RuntimeIdentifier>win-x64</RuntimeIdentifier>
<Version>3.1.0.50</Version> <Version>3.1.0.52</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,7 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using FileManager; using FileManager;
using LibationWinForms; using LibationWinForms;
@ -191,7 +190,6 @@ namespace LibationLauncher
//Log.Logger.Here().Debug("Begin Libation. Debug with line numbers"); //Log.Logger.Here().Debug("Begin Libation. Debug with line numbers");
} }
private static event Action cheating;
private static void checkForUpdate() private static void checkForUpdate()
{ {
try try
@ -247,8 +245,9 @@ namespace LibationLauncher
private static void logStartupState() private static void logStartupState()
{ {
Log.Logger.Information("Begin Libation"); Log.Logger.Information("Begin Libation");
Log.Logger.Information($"Version: {BuildVersion}"); Log.Logger.Information($"Version: {BuildVersion}");
Log.Logger.Information($"LibationFiles: {Configuration.Instance.LibationFiles}");
Log.Logger.Information($"Audible locale: {Configuration.Instance.LocaleCountryCode}");
} }
private static Version BuildVersion => System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; private static Version BuildVersion => System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

View File

@ -40,13 +40,15 @@
this.welcomeLbl.AutoSize = true; this.welcomeLbl.AutoSize = true;
this.welcomeLbl.Location = new System.Drawing.Point(12, 9); this.welcomeLbl.Location = new System.Drawing.Point(12, 9);
this.welcomeLbl.Name = "welcomeLbl"; this.welcomeLbl.Name = "welcomeLbl";
this.welcomeLbl.Size = new System.Drawing.Size(399, 78); this.welcomeLbl.Size = new System.Drawing.Size(399, 117);
this.welcomeLbl.TabIndex = 0; this.welcomeLbl.TabIndex = 0;
this.welcomeLbl.Text = resources.GetString("welcomeLbl.Text"); this.welcomeLbl.Text = resources.GetString("welcomeLbl.Text");
// //
// noQuestionsBtn // noQuestionsBtn
// //
this.noQuestionsBtn.Location = new System.Drawing.Point(15, 90); this.noQuestionsBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.noQuestionsBtn.Location = new System.Drawing.Point(15, 129);
this.noQuestionsBtn.Name = "noQuestionsBtn"; this.noQuestionsBtn.Name = "noQuestionsBtn";
this.noQuestionsBtn.Size = new System.Drawing.Size(396, 57); this.noQuestionsBtn.Size = new System.Drawing.Size(396, 57);
this.noQuestionsBtn.TabIndex = 1; this.noQuestionsBtn.TabIndex = 1;
@ -55,7 +57,9 @@
// //
// basicBtn // basicBtn
// //
this.basicBtn.Location = new System.Drawing.Point(15, 153); this.basicBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.basicBtn.Location = new System.Drawing.Point(15, 192);
this.basicBtn.Name = "basicBtn"; this.basicBtn.Name = "basicBtn";
this.basicBtn.Size = new System.Drawing.Size(396, 57); this.basicBtn.Size = new System.Drawing.Size(396, 57);
this.basicBtn.TabIndex = 2; this.basicBtn.TabIndex = 2;
@ -64,7 +68,9 @@
// //
// advancedBtn // advancedBtn
// //
this.advancedBtn.Location = new System.Drawing.Point(15, 216); this.advancedBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.advancedBtn.Location = new System.Drawing.Point(15, 255);
this.advancedBtn.Name = "advancedBtn"; this.advancedBtn.Name = "advancedBtn";
this.advancedBtn.Size = new System.Drawing.Size(396, 57); this.advancedBtn.Size = new System.Drawing.Size(396, 57);
this.advancedBtn.TabIndex = 3; this.advancedBtn.TabIndex = 3;
@ -75,7 +81,7 @@
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(423, 285); this.ClientSize = new System.Drawing.Size(423, 324);
this.Controls.Add(this.advancedBtn); this.Controls.Add(this.advancedBtn);
this.Controls.Add(this.basicBtn); this.Controls.Add(this.basicBtn);
this.Controls.Add(this.noQuestionsBtn); this.Controls.Add(this.noQuestionsBtn);

View File

@ -123,6 +123,9 @@
Please fill in a few settings. You can also change these settings later. Please fill in a few settings. You can also change these settings later.
After you make your selections, get started by importing your library. After you make your selections, get started by importing your library.
Go to Import &gt; Scan Library</value> Go to Import &gt; Scan Library
Download your entire library from the "Liberate" tab or
liberate your books one at a time by clicking the stoplight</value>
</data> </data>
</root> </root>

View File

@ -49,13 +49,11 @@ namespace LibationWinForms
// also applies filter. ONLY call AFTER loading grid // also applies filter. ONLY call AFTER loading grid
loadInitialQuickFilterState(); loadInitialQuickFilterState();
{ // init bottom counts // init bottom counts
backupsCountsLbl.Text = "[Calculating backed up book quantities]"; backupsCountsLbl.Text = "[Calculating backed up book quantities]";
pdfsCountsLbl.Text = "[Calculating backed up PDFs]"; pdfsCountsLbl.Text = "[Calculating backed up PDFs]";
setBackupCounts(null, null); setBackupCounts(null, null);
} }
}
#region reload grid #region reload grid
bool isProcessingGridSelect = false; bool isProcessingGridSelect = false;
@ -142,6 +140,7 @@ namespace LibationWinForms
= pending > 0 = pending > 0
? $"{pending} remaining" ? $"{pending} remaining"
: "All books have been liberated"; : "All books have been liberated";
Serilog.Log.Logger.Information(menuItemText);
menuStrip1.UIThread(() => beginBookBackupsToolStripMenuItem.Enabled = pending > 0); menuStrip1.UIThread(() => beginBookBackupsToolStripMenuItem.Enabled = pending > 0);
menuStrip1.UIThread(() => beginBookBackupsToolStripMenuItem.Text = string.Format(beginBookBackupsToolStripMenuItem_format, menuItemText)); menuStrip1.UIThread(() => beginBookBackupsToolStripMenuItem.Text = string.Format(beginBookBackupsToolStripMenuItem_format, menuItemText));
} }
@ -167,6 +166,7 @@ namespace LibationWinForms
= notDownloaded > 0 = notDownloaded > 0
? $"{notDownloaded} remaining" ? $"{notDownloaded} remaining"
: "All PDFs have been downloaded"; : "All PDFs have been downloaded";
Serilog.Log.Logger.Information(menuItemText);
menuStrip1.UIThread(() => beginPdfBackupsToolStripMenuItem.Enabled = notDownloaded > 0); menuStrip1.UIThread(() => beginPdfBackupsToolStripMenuItem.Enabled = notDownloaded > 0);
menuStrip1.UIThread(() => beginPdfBackupsToolStripMenuItem.Text = string.Format(beginPdfBackupsToolStripMenuItem_format, menuItemText)); menuStrip1.UIThread(() => beginPdfBackupsToolStripMenuItem.Text = string.Format(beginPdfBackupsToolStripMenuItem_format, menuItemText));
} }

View File

@ -40,13 +40,15 @@
this.welcomeLbl.AutoSize = true; this.welcomeLbl.AutoSize = true;
this.welcomeLbl.Location = new System.Drawing.Point(12, 9); this.welcomeLbl.Location = new System.Drawing.Point(12, 9);
this.welcomeLbl.Name = "welcomeLbl"; this.welcomeLbl.Name = "welcomeLbl";
this.welcomeLbl.Size = new System.Drawing.Size(399, 78); this.welcomeLbl.Size = new System.Drawing.Size(399, 117);
this.welcomeLbl.TabIndex = 0; this.welcomeLbl.TabIndex = 0;
this.welcomeLbl.Text = resources.GetString("welcomeLbl.Text"); this.welcomeLbl.Text = resources.GetString("welcomeLbl.Text");
// //
// noQuestionsBtn // noQuestionsBtn
// //
this.noQuestionsBtn.Location = new System.Drawing.Point(15, 90); this.noQuestionsBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.noQuestionsBtn.Location = new System.Drawing.Point(15, 129);
this.noQuestionsBtn.Name = "noQuestionsBtn"; this.noQuestionsBtn.Name = "noQuestionsBtn";
this.noQuestionsBtn.Size = new System.Drawing.Size(396, 57); this.noQuestionsBtn.Size = new System.Drawing.Size(396, 57);
this.noQuestionsBtn.TabIndex = 1; this.noQuestionsBtn.TabIndex = 1;
@ -55,7 +57,9 @@
// //
// basicBtn // basicBtn
// //
this.basicBtn.Location = new System.Drawing.Point(15, 153); this.basicBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.basicBtn.Location = new System.Drawing.Point(15, 192);
this.basicBtn.Name = "basicBtn"; this.basicBtn.Name = "basicBtn";
this.basicBtn.Size = new System.Drawing.Size(396, 57); this.basicBtn.Size = new System.Drawing.Size(396, 57);
this.basicBtn.TabIndex = 2; this.basicBtn.TabIndex = 2;
@ -64,7 +68,9 @@
// //
// advancedBtn // advancedBtn
// //
this.advancedBtn.Location = new System.Drawing.Point(15, 216); this.advancedBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.advancedBtn.Location = new System.Drawing.Point(15, 255);
this.advancedBtn.Name = "advancedBtn"; this.advancedBtn.Name = "advancedBtn";
this.advancedBtn.Size = new System.Drawing.Size(396, 57); this.advancedBtn.Size = new System.Drawing.Size(396, 57);
this.advancedBtn.TabIndex = 3; this.advancedBtn.TabIndex = 3;
@ -75,7 +81,7 @@
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(423, 285); this.ClientSize = new System.Drawing.Size(423, 324);
this.Controls.Add(this.advancedBtn); this.Controls.Add(this.advancedBtn);
this.Controls.Add(this.basicBtn); this.Controls.Add(this.basicBtn);
this.Controls.Add(this.noQuestionsBtn); this.Controls.Add(this.noQuestionsBtn);

View File

@ -123,6 +123,9 @@
Please fill in a few settings. You can also change these settings later. Please fill in a few settings. You can also change these settings later.
After you make your selections, get started by importing your library. After you make your selections, get started by importing your library.
Go to Import &gt; Scan Library</value> Go to Import &gt; Scan Library
Download your entire library from the "Liberate" tab or
liberate your books one at a time by clicking the stoplight</value>
</data> </data>
</root> </root>