Convert to new Core 3.0 using declarations
This commit is contained in:
parent
b0fec23a51
commit
1b6c577044
@ -117,7 +117,7 @@ namespace AaxDecrypter
|
|||||||
|
|
||||||
private void saveCover(string aaxFile)
|
private void saveCover(string aaxFile)
|
||||||
{
|
{
|
||||||
using (var file = TagLib.File.Create(aaxFile, "audio/mp4", TagLib.ReadStyle.Average))
|
using var file = TagLib.File.Create(aaxFile, "audio/mp4", TagLib.ReadStyle.Average);
|
||||||
this.coverBytes = file.Tag.Pictures[0].Data.Data;
|
this.coverBytes = file.Tag.Pictures[0].Data.Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -25,8 +25,7 @@ namespace AaxDecrypter
|
|||||||
|
|
||||||
public Tags(string file)
|
public Tags(string file)
|
||||||
{
|
{
|
||||||
using (TagLib.File tagLibFile = TagLib.File.Create(file, "audio/mp4", ReadStyle.Average))
|
using TagLib.File tagLibFile = TagLib.File.Create(file, "audio/mp4", ReadStyle.Average);
|
||||||
{
|
|
||||||
this.title = tagLibFile.Tag.Title.Replace(" (Unabridged)", "");
|
this.title = tagLibFile.Tag.Title.Replace(" (Unabridged)", "");
|
||||||
this.album = tagLibFile.Tag.Album.Replace(" (Unabridged)", "");
|
this.album = tagLibFile.Tag.Album.Replace(" (Unabridged)", "");
|
||||||
this.author = tagLibFile.Tag.FirstPerformer;
|
this.author = tagLibFile.Tag.FirstPerformer;
|
||||||
@ -41,19 +40,16 @@ namespace AaxDecrypter
|
|||||||
this.comments = !string.IsNullOrWhiteSpace(tag.LongDescription) ? tag.LongDescription : tag.Description;
|
this.comments = !string.IsNullOrWhiteSpace(tag.LongDescription) ? tag.LongDescription : tag.Description;
|
||||||
this.id = tag.AudibleCDEK;
|
this.id = tag.AudibleCDEK;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void AddAppleTags(string file)
|
public void AddAppleTags(string file)
|
||||||
{
|
{
|
||||||
using (var file1 = TagLib.File.Create(file, "audio/mp4", ReadStyle.Average))
|
using var file1 = TagLib.File.Create(file, "audio/mp4", ReadStyle.Average);
|
||||||
{
|
|
||||||
var tag = (AppleTag)file1.GetTag(TagTypes.Apple, true);
|
var tag = (AppleTag)file1.GetTag(TagTypes.Apple, true);
|
||||||
tag.Publisher = this.publisher;
|
tag.Publisher = this.publisher;
|
||||||
tag.LongDescription = this.comments;
|
tag.LongDescription = this.comments;
|
||||||
tag.Description = this.comments;
|
tag.Description = this.comments;
|
||||||
file1.Save();
|
file1.Save();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public string GenerateFfmpegTags()
|
public string GenerateFfmpegTags()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -110,11 +110,11 @@ var pageSource = new AudiblePageSource(AudiblePageType.Library, html, null);
|
|||||||
// var postData = $"progType=all&timeFilter=all&itemsPerPage={itemsPerPage}&searchTerm=&searchType=&sortColumn=&sortType=down&page={pageNum}&mode=normal&subId=&subTitle=";
|
// var postData = $"progType=all&timeFilter=all&itemsPerPage={itemsPerPage}&searchTerm=&searchType=&sortColumn=&sortType=down&page={pageNum}&mode=normal&subId=&subTitle=";
|
||||||
// var data = Encoding.UTF8.GetBytes(postData);
|
// var data = Encoding.UTF8.GetBytes(postData);
|
||||||
// webRequest.ContentLength = data.Length;
|
// webRequest.ContentLength = data.Length;
|
||||||
// using (var dataStream = webRequest.GetRequestStream())
|
// using var dataStream = webRequest.GetRequestStream();
|
||||||
// dataStream.Write(data, 0, data.Length);
|
// dataStream.Write(data, 0, data.Length);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
var destination = "https://" + $"www.audible.com/lib?purchaseDateFilter=all&programFilter=all&sortBy=PURCHASE_DATE.dsc&page={pageNum}";
|
var destination = "https://" + $"www.audible.com/lib?purchaseDateFilter=all&programFilter=all&sortBy=PURCHASE_DATE.dsc&page={pageNum}";
|
||||||
var webRequest = (HttpWebRequest)WebRequest.Create(destination);
|
var webRequest = (HttpWebRequest)WebRequest.Create(destination);
|
||||||
webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)";
|
webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)";
|
||||||
|
|
||||||
|
|||||||
@ -26,14 +26,12 @@ namespace CookieMonster
|
|||||||
// eg: this will not work unless the winforms proj adds sqlite to ref.s:
|
// eg: this will not work unless the winforms proj adds sqlite to ref.s:
|
||||||
// LibationWinForm > AudibleDotComAutomation > CookieMonster
|
// LibationWinForm > AudibleDotComAutomation > CookieMonster
|
||||||
//
|
//
|
||||||
using (var conn = new SQLiteConnection("Data Source=" + strPath + ";pooling=false"))
|
using var conn = new SQLiteConnection("Data Source=" + strPath + ";pooling=false");
|
||||||
using (var cmd = conn.CreateCommand())
|
using var cmd = conn.CreateCommand();
|
||||||
{
|
|
||||||
cmd.CommandText = "SELECT host_key, name, value, encrypted_value, last_access_utc, expires_utc FROM cookies;";
|
cmd.CommandText = "SELECT host_key, name, value, encrypted_value, last_access_utc, expires_utc FROM cookies;";
|
||||||
|
|
||||||
conn.Open();
|
conn.Open();
|
||||||
using (var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false))
|
using var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false);
|
||||||
{
|
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
var host_key = reader.GetString(0);
|
var host_key = reader.GetString(0);
|
||||||
@ -52,8 +50,7 @@ namespace CookieMonster
|
|||||||
|
|
||||||
col.Add(new CookieValue { Browser = "chrome", Domain = host_key, Name = name, Value = value, LastAccess = chromeTimeToDateTimeUtc(last_access_utc), Expires = chromeTimeToDateTimeUtc(expires_utc) });
|
col.Add(new CookieValue { Browser = "chrome", Domain = host_key, Name = name, Value = value, LastAccess = chromeTimeToDateTimeUtc(last_access_utc), Expires = chromeTimeToDateTimeUtc(expires_utc) });
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,14 +29,12 @@ namespace CookieMonster
|
|||||||
File.Copy(strPath, strTemp, true);
|
File.Copy(strPath, strTemp, true);
|
||||||
|
|
||||||
// Now open the temporary cookie jar and extract Value from the cookie if we find it.
|
// Now open the temporary cookie jar and extract Value from the cookie if we find it.
|
||||||
using (var conn = new SQLiteConnection("Data Source=" + strTemp + ";pooling=false"))
|
using var conn = new SQLiteConnection("Data Source=" + strTemp + ";pooling=false");
|
||||||
using (var cmd = conn.CreateCommand())
|
using var cmd = conn.CreateCommand();
|
||||||
{
|
|
||||||
cmd.CommandText = "SELECT host, name, value, lastAccessed, expiry FROM moz_cookies; ";
|
cmd.CommandText = "SELECT host, name, value, lastAccessed, expiry FROM moz_cookies; ";
|
||||||
|
|
||||||
conn.Open();
|
conn.Open();
|
||||||
using (var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false))
|
using var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false);
|
||||||
{
|
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
var host_key = reader.GetString(0);
|
var host_key = reader.GetString(0);
|
||||||
@ -47,8 +45,6 @@ namespace CookieMonster
|
|||||||
|
|
||||||
col.Add(new CookieValue { Browser = "firefox", Domain = host_key, Name = name, Value = value, LastAccess = lastAccessedToDateTime(lastAccessed), Expires = expiryToDateTime(expiry) });
|
col.Add(new CookieValue { Browser = "firefox", Domain = host_key, Name = name, Value = value, LastAccess = lastAccessedToDateTime(lastAccessed), Expires = expiryToDateTime(expiry) });
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FileUtility.FileExists(strTemp))
|
if (FileUtility.FileExists(strTemp))
|
||||||
File.Delete(strTemp);
|
File.Delete(strTemp);
|
||||||
|
|||||||
@ -10,19 +10,19 @@ namespace DataLayer
|
|||||||
{
|
{
|
||||||
public static int BooksWithoutDetailsCount()
|
public static int BooksWithoutDetailsCount()
|
||||||
{
|
{
|
||||||
using (var context = LibationContext.Create())
|
using var context = LibationContext.Create();
|
||||||
return context
|
return context
|
||||||
.Books
|
.Books
|
||||||
.Count(b => !b.HasBookDetails);
|
.Count(b => !b.HasBookDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Book GetBook_Flat_NoTracking(string productId)
|
public static Book GetBook_Flat_NoTracking(string productId)
|
||||||
{
|
{
|
||||||
using (var context = LibationContext.Create())
|
using var context = LibationContext.Create();
|
||||||
return context
|
return context
|
||||||
.Books
|
.Books
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.GetBook(productId);
|
.GetBook(productId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Book GetBook(this IQueryable<Book> books, string productId)
|
public static Book GetBook(this IQueryable<Book> books, string productId)
|
||||||
|
|||||||
@ -8,21 +8,21 @@ namespace DataLayer
|
|||||||
{
|
{
|
||||||
public static List<LibraryBook> GetLibrary_Flat_NoTracking()
|
public static List<LibraryBook> GetLibrary_Flat_NoTracking()
|
||||||
{
|
{
|
||||||
using (var context = LibationContext.Create())
|
using var context = LibationContext.Create();
|
||||||
return context
|
return context
|
||||||
.Library
|
.Library
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.GetLibrary()
|
.GetLibrary()
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LibraryBook GetLibraryBook_Flat_NoTracking(string productId)
|
public static LibraryBook GetLibraryBook_Flat_NoTracking(string productId)
|
||||||
{
|
{
|
||||||
using (var context = LibationContext.Create())
|
using var context = LibationContext.Create();
|
||||||
return context
|
return context
|
||||||
.Library
|
.Library
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.GetLibraryBook(productId);
|
.GetLibraryBook(productId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>This is still IQueryable. YOU MUST CALL ToList() YOURSELF</summary>
|
/// <summary>This is still IQueryable. YOU MUST CALL ToList() YOURSELF</summary>
|
||||||
|
|||||||
@ -13,13 +13,11 @@ namespace _scratch_pad
|
|||||||
// var user = new Student() { Name = "Dinah Cheshire" };
|
// var user = new Student() { Name = "Dinah Cheshire" };
|
||||||
// var udi = new UserDef { UserDefId = 1, TagsRaw = "my,tags" };
|
// var udi = new UserDef { UserDefId = 1, TagsRaw = "my,tags" };
|
||||||
|
|
||||||
// using (var context = new MyTestContextDesignTimeDbContextFactory().Create())
|
// using var context = new MyTestContextDesignTimeDbContextFactory().Create();
|
||||||
// {
|
|
||||||
// context.Add(user);
|
// context.Add(user);
|
||||||
// //context.Add(udi);
|
// //context.Add(udi);
|
||||||
// context.Update(udi);
|
// context.Update(udi);
|
||||||
// context.SaveChanges();
|
// context.SaveChanges();
|
||||||
// }
|
|
||||||
|
|
||||||
// Console.WriteLine($"Student was saved in the database with id: {user.Id}");
|
// Console.WriteLine($"Student was saved in the database with id: {user.Id}");
|
||||||
// }
|
// }
|
||||||
|
|||||||
@ -43,13 +43,11 @@ namespace DomainServices
|
|||||||
.Replace("&DownloadType=Now", "")
|
.Replace("&DownloadType=Now", "")
|
||||||
+ "&asin=&source=audible_adm&size=&browser_type=&assemble_url=http://cds.audible.com/download";
|
+ "&asin=&source=audible_adm&size=&browser_type=&assemble_url=http://cds.audible.com/download";
|
||||||
var uri = new Uri(aaxDownloadLink);
|
var uri = new Uri(aaxDownloadLink);
|
||||||
using (var webClient = await GetWebClient(tempAaxFilename))
|
|
||||||
{
|
using var webClient = await GetWebClient(tempAaxFilename);
|
||||||
// for book downloads only: pretend to be the audible download manager. from inAudible:
|
// for book downloads only: pretend to be the audible download manager. from inAudible:
|
||||||
webClient.Headers["User-Agent"] = "Audible ADM 6.6.0.15;Windows Vista Service Pack 1 Build 7601";
|
webClient.Headers["User-Agent"] = "Audible ADM 6.6.0.15;Windows Vista Service Pack 1 Build 7601";
|
||||||
|
|
||||||
await webClient.DownloadFileTaskAsync(uri, tempAaxFilename);
|
await webClient.DownloadFileTaskAsync(uri, tempAaxFilename);
|
||||||
}
|
|
||||||
|
|
||||||
// move
|
// move
|
||||||
var aaxFilename = FileUtility.GetValidFilename(
|
var aaxFilename = FileUtility.GetValidFilename(
|
||||||
|
|||||||
@ -43,7 +43,7 @@ namespace DomainServices
|
|||||||
|
|
||||||
var destinationFilename = Path.Combine(destinationDir, Path.GetFileName(url));
|
var destinationFilename = Path.Combine(destinationDir, Path.GetFileName(url));
|
||||||
|
|
||||||
using (var webClient = await GetWebClient(destinationFilename))
|
using var webClient = await GetWebClient(destinationFilename);
|
||||||
await webClient.DownloadFileTaskAsync(url, destinationFilename);
|
await webClient.DownloadFileTaskAsync(url, destinationFilename);
|
||||||
|
|
||||||
var statusHandler = new StatusHandler();
|
var statusHandler = new StatusHandler();
|
||||||
|
|||||||
@ -55,9 +55,7 @@ namespace DomainServices
|
|||||||
|
|
||||||
productItems = filterAndValidate(productItems);
|
productItems = filterAndValidate(productItems);
|
||||||
|
|
||||||
int newEntries;
|
using var context = LibationContext.Create();
|
||||||
using (var context = LibationContext.Create())
|
|
||||||
{
|
|
||||||
var dtoImporter = new DtoImporter(context);
|
var dtoImporter = new DtoImporter(context);
|
||||||
|
|
||||||
#region // benchmarks. re-importing a library with 500 books, all with book details json files
|
#region // benchmarks. re-importing a library with 500 books, all with book details json files
|
||||||
@ -69,14 +67,13 @@ namespace DomainServices
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
// LONG RUNNING
|
// LONG RUNNING
|
||||||
newEntries = await Task.Run(() => dtoImporter.ReplaceLibrary(productItems));
|
var newEntries = await Task.Run(() => dtoImporter.ReplaceLibrary(productItems));
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
|
|
||||||
// must be broken out. see notes in dtoImporter.ReplaceLibrary()
|
// must be broken out. see notes in dtoImporter.ReplaceLibrary()
|
||||||
// LONG RUNNING
|
// LONG RUNNING
|
||||||
await Task.Run(() => dtoImporter.ReloadBookDetails(productItems));
|
await Task.Run(() => dtoImporter.ReloadBookDetails(productItems));
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
}
|
|
||||||
|
|
||||||
await postIndexActionAsync?.Invoke();
|
await postIndexActionAsync?.Invoke();
|
||||||
|
|
||||||
@ -112,12 +109,9 @@ namespace DomainServices
|
|||||||
public static int IndexChangedTags(Book book)
|
public static int IndexChangedTags(Book book)
|
||||||
{
|
{
|
||||||
// update disconnected entity
|
// update disconnected entity
|
||||||
int qtyChanges;
|
using var context = LibationContext.Create();
|
||||||
using (var context = LibationContext.Create())
|
|
||||||
{
|
|
||||||
context.Update(book);
|
context.Update(book);
|
||||||
qtyChanges = context.SaveChanges();
|
var qtyChanges = context.SaveChanges();
|
||||||
}
|
|
||||||
|
|
||||||
// this part is tags-specific
|
// this part is tags-specific
|
||||||
if (qtyChanges > 0)
|
if (qtyChanges > 0)
|
||||||
@ -151,8 +145,7 @@ namespace DomainServices
|
|||||||
|
|
||||||
validate(bookDetailDTO);
|
validate(bookDetailDTO);
|
||||||
|
|
||||||
using (var context = LibationContext.Create())
|
using var context = LibationContext.Create();
|
||||||
{
|
|
||||||
var dtoImporter = new DtoImporter(context);
|
var dtoImporter = new DtoImporter(context);
|
||||||
// LONG RUNNING
|
// LONG RUNNING
|
||||||
await Task.Run(() => dtoImporter.UpdateBookDetails(bookDetailDTO));
|
await Task.Run(() => dtoImporter.UpdateBookDetails(bookDetailDTO));
|
||||||
@ -160,10 +153,7 @@ namespace DomainServices
|
|||||||
|
|
||||||
// after saving, delete orphan contributors
|
// after saving, delete orphan contributors
|
||||||
var count = context.RemoveOrphans();
|
var count = context.RemoveOrphans();
|
||||||
if (count > 0)
|
if (count > 0) { } // don't think there's a to-do here
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await postIndexActionAsync?.Invoke();
|
await postIndexActionAsync?.Invoke();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,8 +72,7 @@ namespace DomainServices
|
|||||||
// download htm
|
// download htm
|
||||||
string source;
|
string source;
|
||||||
var url = AudiblePage.Product.GetUrl(productId);
|
var url = AudiblePage.Product.GetUrl(productId);
|
||||||
using (var webClient = await GetWebClient($"Getting Book Details for {libraryBook.Book.Title}"))
|
using var webClient = await GetWebClient($"Getting Book Details for {libraryBook.Book.Title}");
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
source = await webClient.DownloadStringTaskAsync(url);
|
source = await webClient.DownloadStringTaskAsync(url);
|
||||||
@ -102,7 +101,6 @@ namespace DomainServices
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
DataConverter.Value_2_JsonFile(bookDetailDTO, jsonFileInfo.FullName);
|
DataConverter.Value_2_JsonFile(bookDetailDTO, jsonFileInfo.FullName);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,8 +39,7 @@ namespace FileManager
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var webClient = new System.Net.WebClient())
|
using var webClient = new System.Net.WebClient();
|
||||||
{
|
|
||||||
// download any that don't exist
|
// download any that don't exist
|
||||||
{
|
{
|
||||||
if (!FileUtility.FileExists(path80))
|
if (!FileUtility.FileExists(path80))
|
||||||
@ -71,7 +70,6 @@ namespace FileManager
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch { retry++; }
|
catch { retry++; }
|
||||||
}
|
}
|
||||||
while (retry < 3);
|
while (retry < 3);
|
||||||
|
|||||||
@ -178,26 +178,19 @@ namespace LibationSearchEngine
|
|||||||
log();
|
log();
|
||||||
|
|
||||||
// location of index/create the index
|
// location of index/create the index
|
||||||
using (var index = getIndex())
|
using var index = getIndex();
|
||||||
{
|
|
||||||
var exists = IndexReader.IndexExists(index);
|
var exists = IndexReader.IndexExists(index);
|
||||||
var createNewIndex = overwrite || !exists;
|
var createNewIndex = overwrite || !exists;
|
||||||
|
|
||||||
// analyzer for tokenizing text. same analyzer should be used for indexing and searching
|
// analyzer for tokenizing text. same analyzer should be used for indexing and searching
|
||||||
using (var analyzer = new StandardAnalyzer(Version))
|
using var analyzer = new StandardAnalyzer(Version);
|
||||||
using (var ixWriter = new IndexWriter(index, analyzer, createNewIndex, IndexWriter.MaxFieldLength.UNLIMITED))
|
using var ixWriter = new IndexWriter(index, analyzer, createNewIndex, IndexWriter.MaxFieldLength.UNLIMITED);
|
||||||
{
|
|
||||||
foreach (var libraryBook in library)
|
foreach (var libraryBook in library)
|
||||||
{
|
{
|
||||||
var doc = createBookIndexDocument(libraryBook);
|
var doc = createBookIndexDocument(libraryBook);
|
||||||
ixWriter.AddDocument(doc);
|
ixWriter.AddDocument(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't optimize. deprecated: ixWriter.Optimize();
|
|
||||||
// ixWriter.Commit(); not needed if we're about to dispose of writer anyway. could be needed within the using() block
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log();
|
log();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,33 +240,28 @@ namespace LibationSearchEngine
|
|||||||
var document = createBookIndexDocument(libraryBook);
|
var document = createBookIndexDocument(libraryBook);
|
||||||
var createNewIndex = false;
|
var createNewIndex = false;
|
||||||
|
|
||||||
using (var index = getIndex())
|
using var index = getIndex();
|
||||||
using (var analyzer = new StandardAnalyzer(Version))
|
using var analyzer = new StandardAnalyzer(Version);
|
||||||
using (var ixWriter = new IndexWriter(index, analyzer, createNewIndex, IndexWriter.MaxFieldLength.UNLIMITED))
|
using var ixWriter = new IndexWriter(index, analyzer, createNewIndex, IndexWriter.MaxFieldLength.UNLIMITED);
|
||||||
{
|
|
||||||
ixWriter.DeleteDocuments(term);
|
ixWriter.DeleteDocuments(term);
|
||||||
ixWriter.AddDocument(document);
|
ixWriter.AddDocument(document);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateTags(string productId, string tags)
|
public void UpdateTags(string productId, string tags)
|
||||||
{
|
{
|
||||||
var productTerm = new Term(_ID_, productId);
|
var productTerm = new Term(_ID_, productId);
|
||||||
|
|
||||||
using (var index = getIndex())
|
using var index = getIndex();
|
||||||
{
|
|
||||||
Document document;
|
|
||||||
|
|
||||||
// get existing document
|
// get existing document
|
||||||
using (var searcher = new IndexSearcher(index))
|
using var searcher = new IndexSearcher(index);
|
||||||
{
|
|
||||||
var query = new TermQuery(productTerm);
|
var query = new TermQuery(productTerm);
|
||||||
var docs = searcher.Search(query, 1);
|
var docs = searcher.Search(query, 1);
|
||||||
var scoreDoc = docs.ScoreDocs.SingleOrDefault();
|
var scoreDoc = docs.ScoreDocs.SingleOrDefault();
|
||||||
if (scoreDoc == null)
|
if (scoreDoc == null)
|
||||||
throw new Exception("document not found");
|
throw new Exception("document not found");
|
||||||
document = searcher.Doc(scoreDoc.Doc);
|
var document = searcher.Doc(scoreDoc.Doc);
|
||||||
}
|
|
||||||
|
|
||||||
// update document entry with new tags
|
// update document entry with new tags
|
||||||
// fields are key value pairs and MULTIPLE FIELDS CAN HAVE THE SAME KEY. must remove old before adding new
|
// fields are key value pairs and MULTIPLE FIELDS CAN HAVE THE SAME KEY. must remove old before adding new
|
||||||
@ -283,11 +271,10 @@ namespace LibationSearchEngine
|
|||||||
|
|
||||||
// update index
|
// update index
|
||||||
var createNewIndex = false;
|
var createNewIndex = false;
|
||||||
using (var analyzer = new StandardAnalyzer(Version))
|
using var analyzer = new StandardAnalyzer(Version);
|
||||||
using (var ixWriter = new IndexWriter(index, analyzer, createNewIndex, IndexWriter.MaxFieldLength.UNLIMITED))
|
using var ixWriter = new IndexWriter(index, analyzer, createNewIndex, IndexWriter.MaxFieldLength.UNLIMITED);
|
||||||
ixWriter.UpdateDocument(productTerm, document, analyzer);
|
ixWriter.UpdateDocument(productTerm, document, analyzer);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public SearchResultSet Search(string searchString)
|
public SearchResultSet Search(string searchString)
|
||||||
{
|
{
|
||||||
@ -381,10 +368,9 @@ namespace LibationSearchEngine
|
|||||||
|
|
||||||
var defaultField = ALL;
|
var defaultField = ALL;
|
||||||
|
|
||||||
using (var index = getIndex())
|
using var index = getIndex();
|
||||||
using (var searcher = new IndexSearcher(index))
|
using var searcher = new IndexSearcher(index);
|
||||||
using (var analyzer = new StandardAnalyzer(Version))
|
using var analyzer = new StandardAnalyzer(Version);
|
||||||
{
|
|
||||||
var query = analyzer.GetQuery(defaultField, searchString);
|
var query = analyzer.GetQuery(defaultField, searchString);
|
||||||
|
|
||||||
|
|
||||||
@ -409,7 +395,6 @@ namespace LibationSearchEngine
|
|||||||
.ToList();
|
.ToList();
|
||||||
return new SearchResultSet(query.ToString(), docs);
|
return new SearchResultSet(query.ToString(), docs);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private IEnumerable<Occur> getOccurs_recurs(BooleanQuery query)
|
private IEnumerable<Occur> getOccurs_recurs(BooleanQuery query)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -11,9 +11,9 @@ namespace LibationWinForm.BookLiberation
|
|||||||
{
|
{
|
||||||
async Task BackupBookAsync(string productId)
|
async Task BackupBookAsync(string productId)
|
||||||
{
|
{
|
||||||
LibraryBook libraryBook;
|
using var context = LibationContext.Create();
|
||||||
using (var context = LibationContext.Create())
|
|
||||||
libraryBook = context
|
var libraryBook = context
|
||||||
.Library
|
.Library
|
||||||
.GetLibrary()
|
.GetLibrary()
|
||||||
.SingleOrDefault(lb => lb.Book.AudibleProductId == productId);
|
.SingleOrDefault(lb => lb.Book.AudibleProductId == productId);
|
||||||
|
|||||||
@ -25,9 +25,8 @@ namespace LibationWinForm
|
|||||||
|
|
||||||
public async Task DoMainWorkAsync()
|
public async Task DoMainWorkAsync()
|
||||||
{
|
{
|
||||||
List<FileInfo> jsonFilepaths;
|
using var pageRetriever = websiteProcessorControl1.GetPageRetriever();
|
||||||
using (var pageRetriever = websiteProcessorControl1.GetPageRetriever())
|
var jsonFilepaths = await DownloadLibrary.DownloadLibraryAsync(pageRetriever).ConfigureAwait(false);
|
||||||
jsonFilepaths = await DownloadLibrary.DownloadLibraryAsync(pageRetriever).ConfigureAwait(false);
|
|
||||||
|
|
||||||
successMessages.Add($"Downloaded {"library page".PluralizeWithCount(jsonFilepaths.Count)}");
|
successMessages.Add($"Downloaded {"library page".PluralizeWithCount(jsonFilepaths.Count)}");
|
||||||
|
|
||||||
|
|||||||
@ -63,18 +63,16 @@ transaction notes
|
|||||||
-----------------
|
-----------------
|
||||||
// https://msdn.microsoft.com/en-us/data/dn456843.aspx
|
// https://msdn.microsoft.com/en-us/data/dn456843.aspx
|
||||||
// Rollback is called by transaction Dispose(). No need to call it explicitly
|
// Rollback is called by transaction Dispose(). No need to call it explicitly
|
||||||
using (var dbContext = new LibationContext())
|
using var dbContext = new LibationContext();
|
||||||
using (var dbContextTransaction = dbContext.Database.BeginTransaction())
|
using var dbContextTransaction = dbContext.Database.BeginTransaction();
|
||||||
{
|
|
||||||
refreshAction(dbContext, productItems);
|
refreshAction(dbContext, productItems);
|
||||||
dbContext.SaveChanges();
|
dbContext.SaveChanges();
|
||||||
dbContextTransaction.Commit();
|
dbContextTransaction.Commit();
|
||||||
}
|
|
||||||
|
|
||||||
aggregate root is transactional boundary
|
aggregate root is transactional boundary
|
||||||
// //context.Database.CurrentTransaction
|
// //context.Database.CurrentTransaction
|
||||||
//var dbTransaction = Microsoft.EntityFrameworkCore.Storage.DbContextTransactionExtensions.GetDbTransaction(context.Database.CurrentTransaction);
|
//var dbTransaction = Microsoft.EntityFrameworkCore.Storage.DbContextTransactionExtensions.GetDbTransaction(context.Database.CurrentTransaction);
|
||||||
// // test with and without : using (TransactionScope scope = new TransactionScope())
|
// // test with and without : using TransactionScope scope = new TransactionScope();
|
||||||
//System.Transactions.Transaction.Current.TransactionCompleted += (sender, e) => { };
|
//System.Transactions.Transaction.Current.TransactionCompleted += (sender, e) => { };
|
||||||
// also : https://docs.microsoft.com/en-us/dotnet/api/system.transactions.transaction.enlistvolatile
|
// also : https://docs.microsoft.com/en-us/dotnet/api/system.transactions.transaction.enlistvolatile
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
Logging/Debugging (EF CORE)
|
Logging/Debugging (EF CORE)
|
||||||
===========================
|
===========================
|
||||||
Once you configure logging on a DbContext instance it will be enabled on all instances of that DbContext type
|
Once you configure logging on a DbContext instance it will be enabled on all instances of that DbContext type
|
||||||
using (var context = new MyContext())
|
using var context = new MyContext();
|
||||||
context.ConfigureLogging(s => System.Diagnostics.Debug.WriteLine(s)); // write to Visual Studio "Output" tab
|
context.ConfigureLogging(s => System.Diagnostics.Debug.WriteLine(s)); // write to Visual Studio "Output" tab
|
||||||
//context.ConfigureLogging(s => Console.WriteLine(s));
|
//context.ConfigureLogging(s => Console.WriteLine(s));
|
||||||
see comments at top of file:
|
see comments at top of file:
|
||||||
|
|||||||
@ -23,8 +23,7 @@ namespace ffmpeg_decrypt
|
|||||||
|
|
||||||
private void inpbutton_Click(object sender, EventArgs e)
|
private void inpbutton_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
using (var ofd = new OpenFileDialog { Filter = "Audible Audio Files|*.aax", Title = "Select an Audible Audio File", FileName = "" })
|
using var ofd = new OpenFileDialog { Filter = "Audible Audio Files|*.aax", Title = "Select an Audible Audio File", FileName = "" };
|
||||||
{
|
|
||||||
if (ofd.ShowDialog() == DialogResult.OK)
|
if (ofd.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
inputdisplay.Text = ofd.FileName;
|
inputdisplay.Text = ofd.FileName;
|
||||||
@ -32,11 +31,10 @@ namespace ffmpeg_decrypt
|
|||||||
convertbutton.Enabled = true;
|
convertbutton.Enabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void outpbutton_Click(object sender, EventArgs e)
|
private void outpbutton_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
using (var fbd = new FolderBrowserDialog())
|
using var fbd = new FolderBrowserDialog();
|
||||||
if (fbd.ShowDialog() == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
|
if (fbd.ShowDialog() == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
|
||||||
outputdisplay.Text = fbd.SelectedPath;
|
outputdisplay.Text = fbd.SelectedPath;
|
||||||
}
|
}
|
||||||
@ -87,18 +85,15 @@ namespace ffmpeg_decrypt
|
|||||||
WorkingDirectory = Directory.GetCurrentDirectory()
|
WorkingDirectory = Directory.GetCurrentDirectory()
|
||||||
};
|
};
|
||||||
|
|
||||||
string ffprobeStderr;
|
using var ffp = new Process { StartInfo = startInfo };
|
||||||
using (var ffp = new Process { StartInfo = startInfo })
|
|
||||||
{
|
|
||||||
ffp.Start();
|
ffp.Start();
|
||||||
|
|
||||||
// checksum is in the debug info. ffprobe's debug info is written to stderr, not stdout
|
// checksum is in the debug info. ffprobe's debug info is written to stderr, not stdout
|
||||||
ffprobeStderr = ffp.StandardError.ReadToEnd();
|
var ffprobeStderr = ffp.StandardError.ReadToEnd();
|
||||||
|
|
||||||
await Task.Run(() => ffp.WaitForExit());
|
await Task.Run(() => ffp.WaitForExit());
|
||||||
|
|
||||||
ffp.Close();
|
ffp.Close();
|
||||||
}
|
|
||||||
|
|
||||||
// example checksum line:
|
// example checksum line:
|
||||||
// ... [aax] file checksum == 0c527840c4f18517157eb0b4f9d6f9317ce60cd1
|
// ... [aax] file checksum == 0c527840c4f18517157eb0b4f9d6f9317ce60cd1
|
||||||
@ -135,16 +130,13 @@ namespace ffmpeg_decrypt
|
|||||||
WorkingDirectory = Directory.GetCurrentDirectory()
|
WorkingDirectory = Directory.GetCurrentDirectory()
|
||||||
};
|
};
|
||||||
|
|
||||||
string rcrackStdout;
|
using var rcr = new Process { StartInfo = startInfo };
|
||||||
using (var rcr = new Process { StartInfo = startInfo })
|
|
||||||
{
|
|
||||||
rcr.Start();
|
rcr.Start();
|
||||||
|
|
||||||
rcrackStdout = rcr.StandardOutput.ReadToEnd();
|
var rcrackStdout = rcr.StandardOutput.ReadToEnd();
|
||||||
|
|
||||||
await Task.Run(() => rcr.WaitForExit());
|
await Task.Run(() => rcr.WaitForExit());
|
||||||
rcr.Close();
|
rcr.Close();
|
||||||
}
|
|
||||||
|
|
||||||
// example result
|
// example result
|
||||||
// 0c527840c4f18517157eb0b4f9d6f9317ce60cd1 \xbd\x89X\x09 hex:bd895809
|
// 0c527840c4f18517157eb0b4f9d6f9317ce60cd1 \xbd\x89X\x09 hex:bd895809
|
||||||
@ -202,8 +194,7 @@ namespace ffmpeg_decrypt
|
|||||||
WorkingDirectory = Directory.GetCurrentDirectory()
|
WorkingDirectory = Directory.GetCurrentDirectory()
|
||||||
};
|
};
|
||||||
|
|
||||||
using (var ffm = new Process { StartInfo = startInfo, EnableRaisingEvents = true })
|
using var ffm = new Process { StartInfo = startInfo, EnableRaisingEvents = true };
|
||||||
{
|
|
||||||
ffm.ErrorDataReceived += (s, ea) => debugWindow.UIThread(() => debugWindow.AppendText($"DEBUG: {ea.Data}\r\n"));
|
ffm.ErrorDataReceived += (s, ea) => debugWindow.UIThread(() => debugWindow.AppendText($"DEBUG: {ea.Data}\r\n"));
|
||||||
|
|
||||||
ffm.Start();
|
ffm.Start();
|
||||||
@ -211,7 +202,6 @@ namespace ffmpeg_decrypt
|
|||||||
await Task.Run(() => ffm.WaitForExit());
|
await Task.Run(() => ffm.WaitForExit());
|
||||||
ffm.Close();
|
ffm.Close();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>extract embedded resource to file if it doesn't already exist</summary>
|
/// <summary>extract embedded resource to file if it doesn't already exist</summary>
|
||||||
private static void Extract(string resourceName)
|
private static void Extract(string resourceName)
|
||||||
@ -224,10 +214,10 @@ namespace ffmpeg_decrypt
|
|||||||
// this technique works but there are easier ways:
|
// this technique works but there are easier ways:
|
||||||
// https://stackoverflow.com/questions/13031778/how-can-i-extract-a-file-from-an-embedded-resource-and-save-it-to-disk
|
// https://stackoverflow.com/questions/13031778/how-can-i-extract-a-file-from-an-embedded-resource-and-save-it-to-disk
|
||||||
Directory.CreateDirectory(resdir);
|
Directory.CreateDirectory(resdir);
|
||||||
using (var resource = System.Reflection.Assembly.GetCallingAssembly().GetManifestResourceStream($"{nameof(ffmpeg_decrypt)}.res." + resourceName))
|
using var resource = System.Reflection.Assembly.GetCallingAssembly().GetManifestResourceStream($"{nameof(ffmpeg_decrypt)}.res." + resourceName);
|
||||||
using (var reader = new BinaryReader(resource))
|
using var reader = new BinaryReader(resource);
|
||||||
using (var file = new FileStream(Path.Combine(resdir, resourceName), FileMode.OpenOrCreate))
|
using var file = new FileStream(Path.Combine(resdir, resourceName), FileMode.OpenOrCreate);
|
||||||
using (var writer = new BinaryWriter(file))
|
using var writer = new BinaryWriter(file);
|
||||||
writer.Write(reader.ReadBytes((int)resource.Length));
|
writer.Write(reader.ReadBytes((int)resource.Length));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ incl episodes. eg: "Bill Bryson's Appliance of Science"
|
|||||||
replace all scraping with audible api
|
replace all scraping with audible api
|
||||||
public partial class ScanLibraryDialog : Form, IIndexLibraryDialog
|
public partial class ScanLibraryDialog : Form, IIndexLibraryDialog
|
||||||
public async Task DoMainWorkAsync()
|
public async Task DoMainWorkAsync()
|
||||||
using (var pageRetriever = websiteProcessorControl1.GetPageRetriever())
|
using var pageRetriever = websiteProcessorControl1.GetPageRetriever();
|
||||||
jsonFilepaths = await DownloadLibrary.DownloadLibraryAsync(pageRetriever).ConfigureAwait(false);
|
jsonFilepaths = await DownloadLibrary.DownloadLibraryAsync(pageRetriever).ConfigureAwait(false);
|
||||||
|
|
||||||
break out DTOs. currently coupled with scraping
|
break out DTOs. currently coupled with scraping
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user