public static async Task <StatusHandler> ProcessSingleAsync(this IProcessable processable, LibraryBook libraryBook) { if (!processable.Validate(libraryBook)) { return new StatusHandler { "Validation failed" } } ; return(await processable.ProcessBookAsync_NoValidation(libraryBook)); }
private static LibraryBook getNextValidBook(this IProcessable processable) { var libraryBooks = DbContexts.GetContext().GetLibrary_Flat_NoTracking(); foreach (var libraryBook in libraryBooks) { if (processable.Validate(libraryBook)) { return(libraryBook); } } return(null); }
/// <summary>Process the first valid product. Create default context</summary> /// <returns>Returns either the status handler from the process, or null if all books have been processed</returns> public static async Task <StatusHandler> ProcessSingleAsync(this IProcessable processable, string productId) { using var context = DbContexts.GetContext(); var libraryBook = context .Library .GetLibrary() .SingleOrDefault(lb => lb.Book.AudibleProductId == productId); if (libraryBook == null) { return(null); } if (!processable.Validate(libraryBook)) { return new StatusHandler { "Validation failed" } } ; return(await processBookAsync(processable, libraryBook)); }
public static async Task <StatusHandler> TryProcessAsync(this IProcessable processable, LibraryBook libraryBook) => processable.Validate(libraryBook) ? await processable.ProcessAsync(libraryBook) : new StatusHandler();
// // DO NOT USE ConfigureAwait(false) WITH ProcessAsync() unless ensuring ProcessAsync() implementation is cross-thread compatible // ProcessAsync() often does a lot with forms in the UI context // // when used in foreach: stateful. deferred execution public static IEnumerable <LibraryBook> GetValidLibraryBooks(this IProcessable processable) => DbContexts.GetContext() .GetLibrary_Flat_NoTracking() .Where(libraryBook => processable.Validate(libraryBook));