Skip to content

Commit

Permalink
Improved logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert McRackan committed Feb 18, 2020
1 parent 9e0e06e commit 83f538d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 21 deletions.
33 changes: 23 additions & 10 deletions FileLiberator/UNTESTED/DownloadBook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace FileLiberator
/// </summary>
public class DownloadBook : DownloadableBase
{
private const string SERVICE_UNAVAILABLE = "Content Delivery Companion Service is not available.";

public override bool Validate(LibraryBook libraryBook)
=> !AudibleFileStorage.Audio.Exists(libraryBook.Book.AudibleProductId)
&& !AudibleFileStorage.AAX.Exists(libraryBook.Book.AudibleProductId);
Expand Down Expand Up @@ -48,18 +50,29 @@ private async Task<string> downloadBookAsync(LibraryBook libraryBook, string tem
System.Threading.Thread.Sleep(100);
// if bad file download, a 0-33 byte file will be created
// if service unavailable, a 52 byte string will be saved as file
if (new FileInfo(actualFilePath).Length < 100)
{
var contents = File.ReadAllText(actualFilePath);
File.Delete(actualFilePath);
var length = new FileInfo(actualFilePath).Length;

if (length > 100)
return actualFilePath;

var contents = File.ReadAllText(actualFilePath);
File.Delete(actualFilePath);

var unavailable = "Content Delivery Companion Service is not available.";
if (contents.StartsWithInsensitive(unavailable))
throw new Exception(unavailable);
throw new Exception("Error downloading file");
}
var exMsg = contents.StartsWithInsensitive(SERVICE_UNAVAILABLE)
? SERVICE_UNAVAILABLE
: "Error downloading file";

return actualFilePath;
var ex = new Exception(exMsg);
Serilog.Log.Error(ex, "Download error {@DebugInfo}", new
{
libraryBook.Book.Title,
libraryBook.Book.AudibleProductId,
tempAaxFilename,
actualFilePath,
length,
contents
});
throw ex;
}

private void moveBook(LibraryBook libraryBook, string actualFilePath)
Expand Down
2 changes: 1 addition & 1 deletion LibationLauncher/LibationLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<!-- <PublishSingleFile>true</PublishSingleFile> -->
<RuntimeIdentifier>win-x64</RuntimeIdentifier>

<Version>3.1.6.2</Version>
<Version>3.1.7.5</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
25 changes: 21 additions & 4 deletions LibationLauncher/UNTESTED/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,27 @@ private static void checkForUpdate()

private static void logStartupState()
{
Log.Logger.Information("Begin Libation");
Log.Logger.Information($"Version: {BuildVersion}");
Log.Logger.Information($"LibationFiles: {Configuration.Instance.LibationFiles}");
Log.Logger.Information($"Audible locale: {Configuration.Instance.LocaleCountryCode}");
var config = Configuration.Instance;

Log.Logger.Information("Begin Libation. {@DebugInfo}", new
{
Version = BuildVersion.ToString(),

AudibleLocale = config.LocaleCountryCode,
config.LibationFiles,
AudibleFileStorage.BooksDirectory,

config.DownloadsInProgressEnum,
DownloadsInProgressDir = AudibleFileStorage.DownloadsInProgress,
DownloadsInProgressFiles = Directory.EnumerateFiles(AudibleFileStorage.DownloadsInProgress).Count(),

AudibleFileStorage.DownloadsFinal,
DownloadsFinalFiles = Directory.EnumerateFiles(AudibleFileStorage.DownloadsFinal).Count(),

config.DecryptInProgressEnum,
DecryptInProgressDir = AudibleFileStorage.DecryptInProgress,
DecryptInProgressFiles = Directory.EnumerateFiles(AudibleFileStorage.DecryptInProgress).Count(),
});
}

private static Version BuildVersion => System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
Expand Down
18 changes: 12 additions & 6 deletions LibationWinForms/UNTESTED/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,21 @@ static AudioFileState getAudioFileState(string productId)

// update bottom numbers
var pending = noProgress + downloadedOnly;
var text
var statusStripText
= !results.Any() ? "No books. Begin by importing your library"
: pending > 0 ? string.Format(backupsCountsLbl_Format, noProgress, downloadedOnly, fullyBackedUp)
: $"All {"book".PluralizeWithCount(fullyBackedUp)} backed up";
statusStrip1.UIThread(() => backupsCountsLbl.Text = text);

// update menu item
var menuItemText
= pending > 0
? $"{pending} remaining"
: "All books have been liberated";
Serilog.Log.Logger.Information(menuItemText);

Serilog.Log.Logger.Information("Book counts. {@DebugInfo}", new { fullyBackedUp, downloadedOnly, noProgress, pending, statusStripText, menuItemText });

// update UI
statusStrip1.UIThread(() => backupsCountsLbl.Text = statusStripText);
menuStrip1.UIThread(() => beginBookBackupsToolStripMenuItem.Enabled = pending > 0);
menuStrip1.UIThread(() => beginBookBackupsToolStripMenuItem.Text = string.Format(beginBookBackupsToolStripMenuItem_format, menuItemText));
}
Expand All @@ -155,18 +158,21 @@ private void setPdfBackupCounts(IEnumerable<Book> books)
var notDownloaded = boolResults.Count(r => !r);

// update bottom numbers
var text
var statusStripText
= !boolResults.Any() ? ""
: notDownloaded > 0 ? string.Format(pdfsCountsLbl_Format, notDownloaded, downloaded)
: $"| All {downloaded} PDFs downloaded";
statusStrip1.UIThread(() => pdfsCountsLbl.Text = text);

// update menu item
var menuItemText
= notDownloaded > 0
? $"{notDownloaded} remaining"
: "All PDFs have been downloaded";
Serilog.Log.Logger.Information(menuItemText);

Serilog.Log.Logger.Information("PDF counts. {@DebugInfo}", new { downloaded, notDownloaded, statusStripText, menuItemText });

// update UI
statusStrip1.UIThread(() => pdfsCountsLbl.Text = statusStripText);
menuStrip1.UIThread(() => beginPdfBackupsToolStripMenuItem.Enabled = notDownloaded > 0);
menuStrip1.UIThread(() => beginPdfBackupsToolStripMenuItem.Text = string.Format(beginPdfBackupsToolStripMenuItem_format, menuItemText));
}
Expand Down
1 change: 1 addition & 0 deletions REFERENCE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- begin VERSIONING ---------------------------------------------------------------------------------------------------------------------
https://github.com/rmcrackan/Libation/releases

v3.1.7 : Improved logging
v3.1.6 : Bugfix: some series indexes/sequences formats cause library not to import
v3.1.5 : Bugfix: some series indexes/sequences could cause library not to import
v3.1.4 : Bugfix: IsAuthorNarrated was returning no books
Expand Down

0 comments on commit 83f538d

Please sign in to comment.