public async Task VerifyFromInternet() { var b = new InfoBook("88046"); await b.GetInfoFromId(); Assert.AreEqual("Forbes, Colin", b.Creator); }
public async Task <ActionResult> Book(string id) { Guid g = Guid.Parse(id); //TODO: replace with database if (!dict.ContainsKey(g)) { return(Content("not found")); } string base64 = dict[g]; //var lines = await System.IO.File.ReadAllLinesAsync("a.txt"); //foreach(var line in lines) //{ // if (line.StartsWith(id + "-")) // { // base64 = line.Replace(id + "-", ""); // break; // } //} //if (base64 == "") // return Content("not found"); var timeInfo = LibTimeInfo.FromString(base64); if (!timeInfo.IsValid()) { return(Content("nu aveti dreptul sa vedeti cartea")); } string time = ""; var ts = timeInfo.Diff(); if (ts.TotalMinutes < 1) { time = "secunde ramase " + ts.TotalSeconds.ToString("0#"); } else { time = "minute ramase " + ts.TotalMinutes.ToString("0#"); } var b = new InfoBook(timeInfo.Info); await b.GetInfoFromId(); return(Content(" aici apare cartea " + b.Title + ";" + time)); }
public async Task <ActionResult> GenerateCode(int id, int minutes) { return(Content("No longer available")); var li = new LibTimeInfo(minutes); li.Info = id.ToString(); //TODO: replace with database var t = Guid.NewGuid();//.ToString("N"); //await System.IO.File.AppendAllTextAsync("a.txt", t + "-" + li.Generate()); dict[t] = li.Generate(); li.Info = t.ToString("N"); var b = new InfoBook(id.ToString()); await b.GetInfoFromId(); return(View(new Tuple <LibTimeInfo, InfoBook>(li, b))); }
public async Task <IActionResult> Create(string tinRead) { var idBooks = tinRead.Split(Environment.NewLine); foreach (var id in idBooks) { var exists = await _context.Book.FirstOrDefaultAsync(it => it.IdtinRead == id); if (exists != null) { _context.Book.Remove(exists); } var book = new Book(); book.IdtinRead = id; book.IsCorrect = true; try { var b = new InfoBook(id); await b.GetInfoFromId(); var val = b.Validate(null).FirstOrDefault(); book.Title = b.Title; book.Creator = b.Creator; book.Identifier = b.Identifier; if (val != null) { book.IsCorrect = false; book.ErrorMessage = val.ErrorMessage; } else { var l = Guid.NewGuid();//.ToString("N"); book.UniqueLink = l.ToString("N"); try { if (!io.Directory.Exists("epubs")) { io.Directory.CreateDirectory("epubs"); } string s = book.Identifier; var index = s.LastIndexOf("/"); string bookName = s.Substring(index + 1); string path = s.Substring(0, index); var url = Environment.GetEnvironmentVariable("deploy"); url = string.Format(url, path, bookName); using (var client = new HttpClient()) { using (var result = await client.GetAsync(url)) { if (result.IsSuccessStatusCode) { var bytes = await result.Content.ReadAsByteArrayAsync(); var f = io.Path.Combine("epubs", book.UniqueLink); io.File.WriteAllBytes(f, bytes); } } } } catch (Exception ex) { book.IsCorrect = false; book.ErrorMessage = "download :" + ex.Message; } } } catch (Exception ex) { book.ErrorMessage = ex.Message; book.IsCorrect = false; } _context.Add(book); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }