private async Task ParseInp(InpRecord inp) { Book book = new Book(); book.LibId = inp.LibId; book.Title = inp.Title; if (!string.IsNullOrWhiteSpace(inp.Series)) { book.Series = await _seriesCache.GetAsync(inp.Series); book.SeqNumber = inp.SeqNumber; } book.UpdateDate = inp.UpdateDate; book.LibRate = inp.LibRate; book.Lang = inp.Lang.ToUpper(); book.Folder = inp.Folder; book.FileName = inp.FileName; book.InsideNo = inp.Index; book.Ext = "." + inp.Ext; book.BookSize = inp.BookSize; book.KeyWords = inp.KeyWords; book.Search = book.Title.ToUpper(); book.GenreList = await GetBookGenres(book, inp.Genres); book.AuthorList = await GetBookAuthors(book, inp.Authors); _db.Add(book); }
private IEnumerable <InpRecord> LoadInp(InpxEntry entry, CancellationToken cancellationToken) { int index = 0; using (StreamReader reader = new StreamReader(entry.Entry)) { string line; while ((line = reader.ReadLine()) != null) { if (cancellationToken.IsCancellationRequested) { yield break; } InpRecord record = InpRecord.Parse(entry.Name, index, line); index++; if (record.IsDeleted && SkipDeleted) { continue; } if ((Languages.Count() > 0) && (!Languages.Any(x => string.Equals(x, record.Lang, StringComparison.InvariantCultureIgnoreCase)))) { continue; } yield return(record); } } }
public static InpRecord Parse(string name, int index, string line) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } if (string.IsNullOrWhiteSpace(line)) { throw new ArgumentNullException(nameof(line)); } string[] data = line.Split('\u0004'); if (data.Length != 15) { throw new ArgumentException($"Cannot parse line #{index} in {name}: '{line}'", nameof(line)); } InpRecord result = new InpRecord(); result.Index = index; result.Folder = name; result.Authors = ParseAuthors(data[0]); result.Genres = ParseGenres(data[1]); result.Title = data[2]; if (!string.IsNullOrWhiteSpace(data[3])) { result.Series = data[3]; result.SeqNumber = data[4] != "" ? data[4] : null; } result.LibId = data[5]; result.BookSize = int.Parse(data[6]); result.FileName = data[7]; result.IsDeleted = data[8] == "1"; result.Ext = data[9]; result.UpdateDate = DateTime.Parse(data[10]); result.Lang = data[11]; result.LibRate = data[12] != "" ? int.Parse(data[12]) : (int?)null; result.KeyWords = data[13] != "" ? data[13] : null; return(result); }