예제 #1
0
파일: Form1.cs 프로젝트: tanitall/Libation
        private void setBackupCounts(object _, object __)
        {
            var books = DbContexts.GetContext()
                        .GetLibrary_Flat_NoTracking()
                        .Select(sp => sp.Book)
                        .ToList();

            setBookBackupCounts(books);
            setPdfBackupCounts(books);
        }
예제 #2
0
        public static LibraryBook GetSingleLibraryBook(string productId)
        {
            using var context = DbContexts.GetContext();
            var libraryBook = context
                              .Library
                              .GetLibrary()
                              .SingleOrDefault(lb => lb.Book.AudibleProductId == productId);

            return(libraryBook);
        }
예제 #3
0
        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);
        }
예제 #4
0
        public void Display()
        {
            if (hasBeenDisplayed)
            {
                return;
            }
            hasBeenDisplayed = true;

            //
            // transform into sorted GridEntry.s BEFORE binding
            //
            context = DbContexts.GetContext();
            var lib = context.GetLibrary_Flat_WithTracking();

            // if no data. hide all columns. return
            if (!lib.Any())
            {
                for (var i = dataGridView.ColumnCount - 1; i >= 0; i--)
                {
                    dataGridView.Columns.RemoveAt(i);
                }
                return;
            }

            var orderedGridEntries = lib
                                     .Select(lb => new GridEntry(lb)).ToList()
                                     // default load order
                                     .OrderByDescending(ge => ge.Purchase_Date)
                                     //// more advanced example: sort by author, then series, then title
                                     //.OrderBy(ge => ge.Authors)
                                     //    .ThenBy(ge => ge.Series)
                                     //    .ThenBy(ge => ge.Title)
                                     .ToList();

            //
            // BIND
            //
            gridEntryBindingSource.DataSource = orderedGridEntries.ToSortableBindingList();

            //
            // FILTER
            //
            filter();

            BackupCountsChanged?.Invoke(this, EventArgs.Empty);
        }
예제 #5
0
        /// <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));
        }
예제 #6
0
 DbContext GetDbContext(DbContexts contexts, IInjectionPoint injectionPoint)
 {
     return(contexts.GetContext(injectionPoint));
 }
예제 #7
0
 public IDbSet <T> GetDbSet(DbContexts contexts, IInjectionPoint injectionPoint)
 {
     return(contexts.GetContext(injectionPoint).Set <T>());
 }
예제 #8
0
        //
        // 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));