separate the concepts of UserDefinedItem being updated in memory vs successful persistence
This commit is contained in:
parent
7b9c5c0f4f
commit
dc0dd3474b
@ -155,6 +155,11 @@ namespace ApplicationServices
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Update book details
|
#region Update book details
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when <see cref="UserDefinedItem.Tags"/>, <see cref="UserDefinedItem.BookStatus"/>, or <see cref="UserDefinedItem.PdfStatus"/>
|
||||||
|
/// changed values are successfully persisted.
|
||||||
|
/// </summary>
|
||||||
|
public static event EventHandler<string> BookUserDefinedItemCommitted;
|
||||||
|
|
||||||
public static int UpdateUserDefinedItem(Book book)
|
public static int UpdateUserDefinedItem(Book book)
|
||||||
{
|
{
|
||||||
@ -166,7 +171,10 @@ namespace ApplicationServices
|
|||||||
context.Attach(book.UserDefinedItem).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
context.Attach(book.UserDefinedItem).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
|
||||||
var qtyChanges = context.SaveChanges();
|
var qtyChanges = context.SaveChanges();
|
||||||
if (qtyChanges > 0)
|
if (qtyChanges > 0)
|
||||||
|
{
|
||||||
SearchEngineCommands.UpdateLiberatedStatus(book);
|
SearchEngineCommands.UpdateLiberatedStatus(book);
|
||||||
|
BookUserDefinedItemCommitted?.Invoke(null, book.AudibleProductId);
|
||||||
|
}
|
||||||
|
|
||||||
return qtyChanges;
|
return qtyChanges;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -136,6 +136,7 @@ namespace DataLayer
|
|||||||
#endregion
|
#endregion
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when <see cref="Tags"/>, <see cref="BookStatus"/>, or <see cref="PdfStatus"/> values change.
|
/// Occurs when <see cref="Tags"/>, <see cref="BookStatus"/>, or <see cref="PdfStatus"/> values change.
|
||||||
|
/// This signals the change of the in-memory value; it does not ensure that the new value has been persisted.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static event EventHandler<string> ItemChanged;
|
public static event EventHandler<string> ItemChanged;
|
||||||
public override string ToString() => $"{Book} {Rating} {Tags}";
|
public override string ToString() => $"{Book} {Rating} {Tags}";
|
||||||
|
|||||||
@ -1,57 +0,0 @@
|
|||||||
FOR QUICK MIGRATION INSTRUCTIONS:
|
|
||||||
_DB_NOTES.txt
|
|
||||||
|
|
||||||
|
|
||||||
HOW TO CREATE: EF CORE PROJECT
|
|
||||||
==============================
|
|
||||||
example is for sqlite but the same works with MsSql
|
|
||||||
|
|
||||||
|
|
||||||
nuget
|
|
||||||
Microsoft.EntityFrameworkCore.Tools (needed for using Package Manager Console)
|
|
||||||
Microsoft.EntityFrameworkCore.Sqlite
|
|
||||||
|
|
||||||
MIGRATIONS
|
|
||||||
require core, not standard
|
|
||||||
this can be a problem b/c standard and framework can only reference standard, not core
|
|
||||||
TO USE MIGRATIONS (core and/or standard)
|
|
||||||
add to csproj
|
|
||||||
<PropertyGroup>
|
|
||||||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
|
|
||||||
</PropertyGroup>
|
|
||||||
TO USE MIGRATIONS AS *BOTH* CORE AND STANDARD
|
|
||||||
edit csproj
|
|
||||||
pluralize this xml tag
|
|
||||||
from: TargetFramework
|
|
||||||
to: TargetFrameworks
|
|
||||||
inside of TargetFrameworks
|
|
||||||
from: netstandard2.1
|
|
||||||
to: netcoreapp3.1;netstandard2.1
|
|
||||||
|
|
||||||
run. error
|
|
||||||
SQLite Error 1: 'no such table: Blogs'.
|
|
||||||
|
|
||||||
set project "Set as StartUp Project"
|
|
||||||
|
|
||||||
Tools >> Nuget Package Manager >> Package Manager Console
|
|
||||||
default project: Examples\SQLite_NETCore2_0
|
|
||||||
|
|
||||||
PM> add-migration InitialCreate
|
|
||||||
PM> Update-Database
|
|
||||||
|
|
||||||
if add-migration xyz throws and error, don't take the error msg at face value. try again with add-migration xyz -verbose
|
|
||||||
|
|
||||||
new sqlite .db file created: Copy always/Copy if newer
|
|
||||||
or copy .db file to destination
|
|
||||||
|
|
||||||
relative:
|
|
||||||
optionsBuilder.UseSqlite("Data Source=blogging.db");
|
|
||||||
absolute (use fwd slashes):
|
|
||||||
optionsBuilder.UseSqlite("Data Source=C:/foo/bar/blogging.db");
|
|
||||||
|
|
||||||
|
|
||||||
REFERENCE ARTICLES
|
|
||||||
------------------
|
|
||||||
https://docs.microsoft.com/en-us/ef/core/get-started/netcore/new-db-sqlite
|
|
||||||
https://carlos.mendible.com/2016/07/11/step-by-step-dotnet-core-and-entity-framework-core/
|
|
||||||
https://www.benday.com/2017/12/19/ef-core-2-0-migrations-without-hard-coded-connection-strings/
|
|
||||||
@ -13,7 +13,7 @@
|
|||||||
<!-- <PublishSingleFile>true</PublishSingleFile> -->
|
<!-- <PublishSingleFile>true</PublishSingleFile> -->
|
||||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
|
|
||||||
<Version>5.6.1.0</Version>
|
<Version>5.6.2.1</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
|||||||
@ -32,7 +32,7 @@ namespace LibationWinForms
|
|||||||
// independent UI updates
|
// independent UI updates
|
||||||
this.Load += (_, __) => RestoreSizeAndLocation();
|
this.Load += (_, __) => RestoreSizeAndLocation();
|
||||||
this.Load += (_, __) => RefreshImportMenu();
|
this.Load += (_, __) => RefreshImportMenu();
|
||||||
UserDefinedItem.ItemChanged += setBackupCounts;
|
LibraryCommands.BookUserDefinedItemCommitted += setBackupCounts;
|
||||||
|
|
||||||
var format = System.Drawing.Imaging.ImageFormat.Jpeg;
|
var format = System.Drawing.Imaging.ImageFormat.Jpeg;
|
||||||
PictureStorage.SetDefaultImage(PictureSize._80x80, Properties.Resources.default_cover_80x80.ToBytes(format));
|
PictureStorage.SetDefaultImage(PictureSize._80x80, Properties.Resources.default_cover_80x80.ToBytes(format));
|
||||||
|
|||||||
@ -1,25 +1,9 @@
|
|||||||
-- begin VERSIONING ---------------------------------------------------------------------------------------------------------------------
|
-- begin VERSIONING ---------------------------------------------------------------------------------------------------------------------
|
||||||
https://github.com/rmcrackan/Libation/releases
|
https://github.com/rmcrackan/Libation/releases
|
||||||
|
|
||||||
v3.1.8 : Experimental: add Australia to locale options
|
pre-github versions:
|
||||||
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
|
|
||||||
v3.1.3 : fix weirdness with build number
|
|
||||||
v3.1.2 : minor bug fixes
|
|
||||||
v3.1.1 : Check if upgrade available on github
|
v3.1.1 : Check if upgrade available on github
|
||||||
v3.1.0 : FIRST PUBLIC RELEASE
|
v3.1.0 : FIRST PUBLIC RELEASE
|
||||||
v3.1-beta.11 : Improved configuration and settings file management. Configurable logging
|
|
||||||
v3.1-beta.10 : New feature: clicking Liberate button on a liberated item navigates to that audio file
|
|
||||||
v3.1-beta.9 : New feature: liberate individual book
|
|
||||||
v3.1-beta.8 : Bugfix: decrypt file conflict
|
|
||||||
v3.1-beta.7 : Bugfix: decrypt book with no author
|
|
||||||
v3.1-beta.6 : Improved logging
|
|
||||||
v3.1-beta.5 : Improved importing
|
|
||||||
v3.1-beta.4 : Added beta-specific logging
|
|
||||||
v3.1-beta.3 : fixed known performance issue: Full-screen grid is slow to respond loading when books aren't liberated
|
|
||||||
v3.1-beta.2 : fixed known performance issue: Tag add/edit
|
|
||||||
v3.1-beta.1 : RELEASE TO BETA
|
v3.1-beta.1 : RELEASE TO BETA
|
||||||
v3.0.3 : Switch to SQLite. No longer relies on LocalDB, which must be installed separately
|
v3.0.3 : Switch to SQLite. No longer relies on LocalDB, which must be installed separately
|
||||||
v3.0.2 : Final using LocalDB
|
v3.0.2 : Final using LocalDB
|
||||||
@ -29,29 +13,6 @@ v2 : new library page scraping. still chrome cookies. all decryption is handled
|
|||||||
v1 : old library ajax scraping. wish list scraping. chrome cookies. directly call local inAudible. .net framework
|
v1 : old library ajax scraping. wish list scraping. chrome cookies. directly call local inAudible. .net framework
|
||||||
-- end VERSIONING ---------------------------------------------------------------------------------------------------------------------
|
-- end VERSIONING ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- begin HOW TO PUBLISH ---------------------------------------------------------------------------------------------------------------------
|
|
||||||
OPTION 1: UI
|
|
||||||
rt-clk project project > Publish...
|
|
||||||
click Publish
|
|
||||||
|
|
||||||
OPTION 2: cmd line
|
|
||||||
change dir to folder containing project
|
|
||||||
cd C:\[full...path]\Libation\LibationWinForms
|
|
||||||
this will use the parameters specified in csproj
|
|
||||||
dotnet publish -c Release
|
|
||||||
|
|
||||||
OPTION 3: cmd line, custom
|
|
||||||
open csproj
|
|
||||||
remove: PublishTrimmed, PublishReadyToRun, RuntimeIdentifier
|
|
||||||
run customized publish. examples:
|
|
||||||
publish all platforms
|
|
||||||
dotnet publish -c Release
|
|
||||||
publish win64 platform only
|
|
||||||
dotnet publish -r win-x64 -c Release
|
|
||||||
publish win64 platform, single-file
|
|
||||||
dotnet publish -r win-x64 -c Release
|
|
||||||
-- end HOW TO PUBLISH ---------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
-- begin IMAGES/ICONS ---------------------------------------------------------------------------------------------------------------------
|
-- begin IMAGES/ICONS ---------------------------------------------------------------------------------------------------------------------
|
||||||
edit tags icon images from:
|
edit tags icon images from:
|
||||||
icons8.com
|
icons8.com
|
||||||
@ -60,32 +21,9 @@ edit tags icon images from:
|
|||||||
'edit' icon: https://www.iconfinder.com/icons/383147/edit_icon
|
'edit' icon: https://www.iconfinder.com/icons/383147/edit_icon
|
||||||
-- end IMAGES/ICONS ---------------------------------------------------------------------------------------------------------------------
|
-- end IMAGES/ICONS ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- begin AUDIBLE DETAILS ---------------------------------------------------------------------------------------------------------------------
|
|
||||||
alternate book id (eg BK_RAND_006061) is called 'sku' , 'sku_lite' , 'prod_id' , 'product_id' in different parts of the site
|
|
||||||
-- end AUDIBLE DETAILS ---------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
-- begin SOLUTION LAYOUT ---------------------------------------------------------------------------------------------------------------------
|
-- begin SOLUTION LAYOUT ---------------------------------------------------------------------------------------------------------------------
|
||||||
do NOT combine jsons for
|
do NOT combine jsons for
|
||||||
- audible-scraped persistence: library, book details
|
- audible-scraped persistence: library, book details
|
||||||
- libation-generated persistence: FileLocations.json
|
- libation-generated persistence: FileLocations.json
|
||||||
- user-defined persistence: BookTags.json
|
- user-defined persistence: BookTags.json
|
||||||
-- end SOLUTION LAYOUT ---------------------------------------------------------------------------------------------------------------------
|
-- end SOLUTION LAYOUT ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- begin EF CORE ---------------------------------------------------------------------------------------------------------------------
|
|
||||||
transaction notes
|
|
||||||
-----------------
|
|
||||||
// https://msdn.microsoft.com/en-us/data/dn456843.aspx
|
|
||||||
// Rollback is called by transaction Dispose(). No need to call it explicitly
|
|
||||||
using var dbContext = new LibationContext();
|
|
||||||
using var dbContextTransaction = dbContext.Database.BeginTransaction();
|
|
||||||
refreshAction(dbContext, productItems);
|
|
||||||
dbContext.SaveChanges();
|
|
||||||
dbContextTransaction.Commit();
|
|
||||||
|
|
||||||
aggregate root is transactional boundary
|
|
||||||
// //context.Database.CurrentTransaction
|
|
||||||
//var dbTransaction = Microsoft.EntityFrameworkCore.Storage.DbContextTransactionExtensions.GetDbTransaction(context.Database.CurrentTransaction);
|
|
||||||
// // test with and without : using TransactionScope scope = new TransactionScope();
|
|
||||||
//System.Transactions.Transaction.Current.TransactionCompleted += (sender, e) => { };
|
|
||||||
// also : https://docs.microsoft.com/en-us/dotnet/api/system.transactions.transaction.enlistvolatile
|
|
||||||
-- end EF CORE ---------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|||||||
@ -1,26 +1,5 @@
|
|||||||
Logging/Debugging (EF CORE)
|
Migrations, quick
|
||||||
===========================
|
=================
|
||||||
Once you configure logging on a DbContext instance it will be enabled on all instances of that DbContext type
|
|
||||||
using var context = new MyContext();
|
|
||||||
context.ConfigureLogging(s => System.Diagnostics.Debug.WriteLine(s)); // write to Visual Studio "Output" tab
|
|
||||||
//context.ConfigureLogging(s => Console.WriteLine(s));
|
|
||||||
see comments at top of file:
|
|
||||||
Dinah.EntityFrameworkCore\DbContextLoggingExtensions.cs
|
|
||||||
|
|
||||||
LocalDb
|
|
||||||
=======
|
|
||||||
only works if LocalDb is separately installed on host box
|
|
||||||
SSMS db connection: (LocalDb)\MSSQLLocalDB
|
|
||||||
eg: Server=(localdb)\mssqllocaldb;Database=DataLayer.LibationContext;Integrated Security=true;
|
|
||||||
LocalDb database files live at:
|
|
||||||
C:\Users\[user]\DataLayer.LibationContext.mdf
|
|
||||||
C:\Users\[user]\DataLayer.LibationContext_log.ldf
|
|
||||||
|
|
||||||
Migrations
|
|
||||||
==========
|
|
||||||
|
|
||||||
Visual Studio, EF Core
|
|
||||||
----------------------
|
|
||||||
View > Other Windows > Package Manager Console
|
View > Other Windows > Package Manager Console
|
||||||
Default project: DataLayer
|
Default project: DataLayer
|
||||||
Startup project: DataLayer
|
Startup project: DataLayer
|
||||||
@ -30,16 +9,34 @@ since we have mult contexts, must use -context:
|
|||||||
Startup project: reset to prev. eg: LibationLauncher
|
Startup project: reset to prev. eg: LibationLauncher
|
||||||
|
|
||||||
|
|
||||||
ERROR
|
Migrations, detailed
|
||||||
=====
|
====================
|
||||||
Add-Migration : The term 'Add-Migration' is not recognized as the name of a cmdlet, function, script file, or operable program
|
if only 1 context present, can omit -context arg:
|
||||||
|
Add-Migration MyComment
|
||||||
SOLUTION
|
Update-Database
|
||||||
--------
|
|
||||||
add nuget pkg: Microsoft.EntityFrameworkCore.Tools
|
|
||||||
|
|
||||||
|
|
||||||
SQLite
|
Migrations, errors
|
||||||
======
|
=================
|
||||||
SQLite does not support all migrations (schema changes) due to limitations in SQLite
|
if add-migration xyz throws and error, don't take the error msg at face value. try again with add-migration xyz -verbose
|
||||||
delete db before running Update-Database?
|
|
||||||
|
ERROR: Add-Migration : The term 'Add-Migration' is not recognized as the name of a cmdlet, function, script file, or operable program
|
||||||
|
SOLUTION: add nuget pkg: Microsoft.EntityFrameworkCore.Tools
|
||||||
|
|
||||||
|
|
||||||
|
SqLite config
|
||||||
|
=============
|
||||||
|
relative:
|
||||||
|
optionsBuilder.UseSqlite("Data Source=blogging.db");
|
||||||
|
absolute (use fwd slashes):
|
||||||
|
optionsBuilder.UseSqlite("Data Source=C:/foo/bar/blogging.db");
|
||||||
|
|
||||||
|
|
||||||
|
Logging/Debugging (EF CORE)
|
||||||
|
===========================
|
||||||
|
Once you configure logging on a DbContext instance it will be enabled on all instances of that DbContext type
|
||||||
|
using var context = new MyContext();
|
||||||
|
context.ConfigureLogging(s => System.Diagnostics.Debug.WriteLine(s)); // write to Visual Studio "Output" tab
|
||||||
|
//context.ConfigureLogging(s => Console.WriteLine(s));
|
||||||
|
see comments at top of file:
|
||||||
|
Dinah.EntityFrameworkCore\DbContextLoggingExtensions.cs
|
||||||
Loading…
x
Reference in New Issue
Block a user