public async Task VerifyFromInternet() { var b = new InfoBook("88046"); await b.GetInfoFromId(); Assert.AreEqual("Forbes, Colin", b.Creator); }
public void TestInfoXML() { string xml = @"<?xml version='1.0' encoding='UTF-8'?> <OAI-PMH xsi:schemaLocation='http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://www.openarchives.org/OAI/2.0/'> <responseDate>2018-02-25T22:33:56Z</responseDate> <request identifier='oai:ime.ro:88046' metadataPrefix='oai_dc' verb='GetRecord'>http://opac.aman.ro//oai</request> <GetRecord> <record> <header> <identifier>oai:ime.ro:88046</identifier> <datestamp>2018-02-19T11:03:31Z</datestamp> </header> <metadata> <oai_dc:dc xsi:schemaLocation='http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:oai_dc='http://www.openarchives.org/OAI/2.0/oai_dc/'> <dc:title>Pe muchie de cuţit</dc:title> <dc:creator>Forbes, Colin</dc:creator> <dc:subject>roman poliţist</dc:subject> <dc:subject>821eng/F79</dc:subject> <dc:publisher>Editura Rao International Publishing Company</dc:publisher> <dc:contributors>Traducere : Flavia Iustina Bosnari</dc:contributors> <dc:date>2007</dc:date> <dc:identifier>an identifier</dc:identifier> <dc:rights>4</dc:rights> <dc:language>rum</dc:language> </oai_dc:dc> </metadata> </record> </GetRecord> </OAI-PMH>"; var b = new InfoBook("88046"); b.GetInfo(xml.Replace("'", "\"")); Assert.AreEqual("Forbes, Colin", b.Creator); Assert.AreEqual("an identifier", b.Identifier); }
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))); }