public static LibraryStats GetCounts() { var libraryBooks = DbContexts.GetLibrary_Flat_NoTracking(); var results = libraryBooks .AsParallel() .Select(lb => Liberated_Status(lb.Book)) .ToList(); var booksFullyBackedUp = results.Count(r => r == LiberatedStatus.Liberated); var booksDownloadedOnly = results.Count(r => r == LiberatedStatus.PartialDownload); var booksNoProgress = results.Count(r => r == LiberatedStatus.NotLiberated); var booksError = results.Count(r => r == LiberatedStatus.Error); Log.Logger.Information("Book counts. {@DebugInfo}", new { total = results.Count, booksFullyBackedUp, booksDownloadedOnly, booksNoProgress, booksError }); var boolResults = libraryBooks .AsParallel() .Where(lb => lb.Book.HasPdf) .Select(lb => Pdf_Status(lb.Book)) .ToList(); var pdfsDownloaded = boolResults.Count(r => r == LiberatedStatus.Liberated); var pdfsNotDownloaded = boolResults.Count(r => r == LiberatedStatus.NotLiberated); Log.Logger.Information("PDF counts. {@DebugInfo}", new { total = boolResults.Count, pdfsDownloaded, pdfsNotDownloaded }); return(new(booksFullyBackedUp, booksDownloadedOnly, booksNoProgress, booksError, pdfsDownloaded, pdfsNotDownloaded)); }
public static void ToJson(string saveFilePath) { var dtos = DbContexts.GetLibrary_Flat_NoTracking().ToDtos(); var json = Newtonsoft.Json.JsonConvert.SerializeObject(dtos, Newtonsoft.Json.Formatting.Indented); System.IO.File.WriteAllText(saveFilePath, json); }
public static void FullReIndex(SearchEngine engine = null) { engine ??= new SearchEngine(); var library = DbContexts.GetLibrary_Flat_NoTracking(); engine.CreateNewIndex(library); }
public static void ToCsv(string saveFilePath) { var dtos = DbContexts.GetLibrary_Flat_NoTracking().ToDtos(); if (!dtos.Any()) { return; } using var writer = new System.IO.StreamWriter(saveFilePath); using var csv = new CsvWriter(writer, System.Globalization.CultureInfo.CurrentCulture); csv.WriteHeader(typeof(ExportDto)); csv.NextRecord(); csv.WriteRecords(dtos); }
public static void ToXlsx(string saveFilePath) { var dtos = DbContexts.GetLibrary_Flat_NoTracking().ToDtos(); var workbook = new XSSFWorkbook(); var sheet = workbook.CreateSheet("Library"); var detailSubtotalFont = workbook.CreateFont(); detailSubtotalFont.IsBold = true; var detailSubtotalCellStyle = workbook.CreateCellStyle(); detailSubtotalCellStyle.SetFont(detailSubtotalFont); // headers var rowIndex = 0; var row = sheet.CreateRow(rowIndex); var columns = new[] { nameof(ExportDto.Account), nameof(ExportDto.DateAdded), nameof(ExportDto.AudibleProductId), nameof(ExportDto.Locale), nameof(ExportDto.Title), nameof(ExportDto.AuthorNames), nameof(ExportDto.NarratorNames), nameof(ExportDto.LengthInMinutes), nameof(ExportDto.Publisher), nameof(ExportDto.HasPdf), nameof(ExportDto.SeriesNames), nameof(ExportDto.SeriesOrder), nameof(ExportDto.CommunityRatingOverall), nameof(ExportDto.CommunityRatingPerformance), nameof(ExportDto.CommunityRatingStory), nameof(ExportDto.PictureId), nameof(ExportDto.IsAbridged), nameof(ExportDto.DatePublished), nameof(ExportDto.CategoriesNames), nameof(ExportDto.MyRatingOverall), nameof(ExportDto.MyRatingPerformance), nameof(ExportDto.MyRatingStory), nameof(ExportDto.MyLibationTags), nameof(ExportDto.BookStatus), nameof(ExportDto.PdfStatus), nameof(ExportDto.ContentType) }; var col = 0; foreach (var c in columns) { var cell = row.CreateCell(col++); var name = ExportDto.GetName(c); cell.SetCellValue(name); cell.CellStyle = detailSubtotalCellStyle; } var dateFormat = workbook.CreateDataFormat(); var dateStyle = workbook.CreateCellStyle(); dateStyle.DataFormat = dateFormat.GetFormat("MM/dd/yyyy HH:mm:ss"); rowIndex++; // Add data rows foreach (var dto in dtos) { col = 0; row = sheet.CreateRow(rowIndex); row.CreateCell(col++).SetCellValue(dto.Account); var dateAddedCell = row.CreateCell(col++); dateAddedCell.CellStyle = dateStyle; dateAddedCell.SetCellValue(dto.DateAdded); row.CreateCell(col++).SetCellValue(dto.AudibleProductId); row.CreateCell(col++).SetCellValue(dto.Locale); row.CreateCell(col++).SetCellValue(dto.Title); row.CreateCell(col++).SetCellValue(dto.AuthorNames); row.CreateCell(col++).SetCellValue(dto.NarratorNames); row.CreateCell(col++).SetCellValue(dto.LengthInMinutes); row.CreateCell(col++).SetCellValue(dto.Publisher); row.CreateCell(col++).SetCellValue(dto.HasPdf); row.CreateCell(col++).SetCellValue(dto.SeriesNames); row.CreateCell(col++).SetCellValue(dto.SeriesOrder); col = createCell(row, col, dto.CommunityRatingOverall); col = createCell(row, col, dto.CommunityRatingPerformance); col = createCell(row, col, dto.CommunityRatingStory); row.CreateCell(col++).SetCellValue(dto.PictureId); row.CreateCell(col++).SetCellValue(dto.IsAbridged); var datePubCell = row.CreateCell(col++); datePubCell.CellStyle = dateStyle; if (dto.DatePublished.HasValue) { datePubCell.SetCellValue(dto.DatePublished.Value); } else { datePubCell.SetCellValue(""); } row.CreateCell(col++).SetCellValue(dto.CategoriesNames); col = createCell(row, col, dto.MyRatingOverall); col = createCell(row, col, dto.MyRatingPerformance); col = createCell(row, col, dto.MyRatingStory); row.CreateCell(col++).SetCellValue(dto.MyLibationTags); row.CreateCell(col++).SetCellValue(dto.BookStatus); row.CreateCell(col++).SetCellValue(dto.PdfStatus); row.CreateCell(col++).SetCellValue(dto.ContentType); rowIndex++; } using var fileData = new System.IO.FileStream(saveFilePath, System.IO.FileMode.Create); workbook.Write(fileData); }