Compare commits

...

2 Commits

Author SHA1 Message Date
Robert McRackan
b9314ac678 Added validation and error handling
BETA READY
2019-11-15 22:43:04 -05:00
Robert McRackan
e319326c30 Switch to SQLite 2019-11-15 16:34:16 -05:00
10 changed files with 90 additions and 35 deletions

View File

@@ -6,6 +6,9 @@ namespace DataLayer
public class LibationContextFactory : DesignTimeDbContextFactoryBase<LibationContext>
{
protected override LibationContext CreateNewInstance(DbContextOptions<LibationContext> options) => new LibationContext(options);
protected override void UseDatabaseEngine(DbContextOptionsBuilder optionsBuilder, string connectionString) => optionsBuilder.UseSqlServer(connectionString);
protected override void UseDatabaseEngine(DbContextOptionsBuilder optionsBuilder, string connectionString) => optionsBuilder
//.UseSqlServer
.UseSqlite
(connectionString);
}
}

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace DataLayer.Utilities
{
public static class LocalDatabaseInfo
{
public static List<string> GetLocalDBInstances()
{
// Start the child process.
using var p = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
UseShellExecute = false,
RedirectStandardOutput = true,
FileName = "cmd.exe",
Arguments = "/C sqllocaldb info",
CreateNoWindow = true,
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
}
};
p.Start();
var output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
// if LocalDb is not installed then it will return that 'sqllocaldb' is not recognized as an internal or external command operable program or batch file
return string.IsNullOrWhiteSpace(output) || output.Contains("not recognized")
? new List<string>()
: output
.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)
.Select(i => i.Trim())
.Where(i => !string.IsNullOrEmpty(i))
.ToList();
}
}
}

View File

@@ -1,6 +1,7 @@
{
"ConnectionStrings": {
"LibationContext": "Server=(LocalDb)\\MSSQLLocalDB;Database=DataLayer.LibationContext;Integrated Security=true;",
"LibationContext_sqlserver": "Server=(LocalDb)\\MSSQLLocalDB;Database=DataLayer.LibationContext;Integrated Security=true;",
"LibationContext": "Data Source=LibationContext.db;Foreign Keys=False;",
"// on windows sqlite paths accept windows and/or unix slashes": "",
"MyTestContext": "Data Source=%DESKTOP%/sample.db"

View File

@@ -43,19 +43,19 @@ namespace FileLiberator
try
{
{
var statusHandler = await processAsync(libraryBook, AudibleFileStorage.AAX, DownloadBook);
var statusHandler = await DownloadBook.TryProcessAsync(libraryBook);
if (statusHandler.HasErrors)
return statusHandler;
}
{
var statusHandler = await processAsync(libraryBook, AudibleFileStorage.Audio, DecryptBook);
var statusHandler = await DecryptBook.TryProcessAsync(libraryBook);
if (statusHandler.HasErrors)
return statusHandler;
}
{
var statusHandler = await processAsync(libraryBook, AudibleFileStorage.PDF, DownloadPdf);
var statusHandler = await DownloadPdf.TryProcessAsync(libraryBook);
if (statusHandler.HasErrors)
return statusHandler;
}
@@ -67,10 +67,5 @@ namespace FileLiberator
Completed?.Invoke(this, displayMessage);
}
}
private static async Task<StatusHandler> processAsync(LibraryBook libraryBook, AudibleFileStorage afs, IProcessable processable)
=> !await afs.ExistsAsync(libraryBook.Book.AudibleProductId)
? await processable.ProcessAsync(libraryBook)
: new StatusHandler();
}
}

View File

@@ -13,12 +13,8 @@ namespace FileLiberator
public class DownloadPdf : DownloadableBase
{
public override async Task<bool> ValidateAsync(LibraryBook libraryBook)
{
if (string.IsNullOrWhiteSpace(getdownloadUrl(libraryBook)))
return false;
return !await AudibleFileStorage.PDF.ExistsAsync(libraryBook.Book.AudibleProductId);
}
=> !string.IsNullOrWhiteSpace(getdownloadUrl(libraryBook))
&& !await AudibleFileStorage.PDF.ExistsAsync(libraryBook.Book.AudibleProductId);
private static string getdownloadUrl(LibraryBook libraryBook)
=> libraryBook?.Book?.Supplements?.FirstOrDefault()?.Url;

View File

@@ -40,5 +40,10 @@ namespace FileLiberator
return null;
}
}
public static async Task<StatusHandler> TryProcessAsync(this IProcessable processable, LibraryBook libraryBook)
=> await processable.ValidateAsync(libraryBook)
? await processable.ProcessAsync(libraryBook)
: new StatusHandler();
}
}

View File

@@ -9,7 +9,7 @@
<PublishTrimmed>true</PublishTrimmed>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishSingleFile>true</PublishSingleFile>
<!-- <PublishSingleFile>true</PublishSingleFile> -->
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>

View File

@@ -16,7 +16,14 @@ namespace LibationWinForm
private async void IndexLibraryDialog_Shown(object sender, System.EventArgs e)
{
(TotalBooksProcessed, NewBooksAdded) = await LibraryCommands.IndexLibraryAsync(new Login.WinformResponder());
try
{
(TotalBooksProcessed, NewBooksAdded) = await LibraryCommands.IndexLibraryAsync(new Login.WinformResponder());
}
catch
{
MessageBox.Show("Error importing library. Please try again. If this happens after 2 or 3 tries, contact administrator", "Error importing library", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
this.Close();
}

View File

@@ -1,13 +1,17 @@
-- begin VERSIONING ---------------------------------------------------------------------------------------------------------------------
https://github.com/rmcrackan/Libation/releases
v3.0.3 : Switch to SQLite. No longer relies on LocalDB, which must be installed separately
v3.0.2 : Final using LocalDB
v3.0.1 : Legacy inAudible wire-up code is still present but is commented out. All future check-ins are not guaranteed to have inAudible wire-up code
v3.0 : This version is fully powered by the Audible API. Legacy scraping code is still present but is commented out. All future check-ins are not guaranteed to have any scraping code
v2 : new library page scraping. still chrome cookies. all decryption is handled natively. no inAudible dependency
v1 : old library ajax scraping. wish list scraping. chrome cookies. directly call local inAudible. .net framework
-- end VERSIONING ---------------------------------------------------------------------------------------------------------------------
-- begin HOW TO PUBLISH ---------------------------------------------------------------------------------------------------------------------
OPTION 1: UI
rt-clk project > Publish...
rt-clk project project > Publish...
click Publish
OPTION 2: cmd line

View File

@@ -1,31 +1,35 @@
-- begin BETA ---------------------------------------------------------------------------------------------------------------------
TESTING BUG
dbl clk. long pause. exception:
System.ComponentModel.Win32Exception (2): The system cannot find the file specified.
"continue" button allows me to keep using
bottom #s do not update
login succeeded. IdentityTokens.json successfully created
received above error again during scan. continue
stuck on scan. force quit from task manager
only files:
Images -- empty dir
IdentityTokens.json -- populated
no mdf, ldf
REPLACE DB
need completely need db? replace LocalDb with sqlite? embedded document nosql?
FINAL PRE-BETA TEST
create release
v3.1 beta
update REFERENCE.txt with this release
publish exe and attach it to the beta release
start beta: contact beta members
CREATE INSTALLER
see REFERENCE.txt > HOW TO PUBLISH
RELEASE TO BETA
Note: run Libation.exe -- icon is a black wine glass
I recommend making a shortcut. I'm working on a more manageable install but it's low priority
Warn of known performance issues
- Library import
- Tag add/edit
- Grid is slow to respond loading when books aren't liberated
- get decrypt key -- unavoidable
- images can take a bit to initially load. downloading is throttled as to not get the IP blocked by audible
-- end BETA ---------------------------------------------------------------------------------------------------------------------
-- begin SINGLE FILE PUBLISH ---------------------------------------------------------------------------------------------------------------------
SINGLE FILE. FUTURE FIX
<!-- <PublishSingleFile>true</PublishSingleFile> -->
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
Runs from weird temp location
- Weird default location for files
- Cant find json
- don't have external exe.s
-- end SINGLE FILE PUBLISH ---------------------------------------------------------------------------------------------------------------------
-- begin ENHANCEMENT, IMPORT UI ---------------------------------------------------------------------------------------------------------------------
scan library in background?
can include a notice somewhere that a scan is in-process
@@ -124,6 +128,8 @@ move out of Book and into DtoMapper?
Extract file and tag stuff from domain objects. This should exist only in data layer. If domain objects are able to call EF context, it should go through data layer
Why are tags in file AND database?
why use a relational db? i'm treating it like a nosql db. use LiteDB instead?
extract FileManager dependency from data layer
-- end TAGS ---------------------------------------------------------------------------------------------------------------------