public void ErogamescapeParserTest() { string fileUrl= @"file:///C:/Users/Sergey/Documents/SQL.html"; var document = new HtmlDocument { OptionCheckSyntax = true, OptionFixNestedTags = true, OptionAutoCloseOnEnd = true, OptionReadEncoding = true, }; var fileWebRequest = WebRequest.Create(fileUrl) as FileWebRequest; var stream = fileWebRequest.GetResponse().GetResponseStream();//HtmlHelper.LoadDocumentWithEncoding(fileWebRequest); document.Load(stream,Encoding.UTF8); var parser = new ErogamescapeParser(); var infos = parser.ParseNode(document.DocumentNode); using (var ctx=new VNCommonContext("VNCommonConnectionString")) { ctx.NovelInfos.AddRange(infos); try { ctx.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex); throw; } } Console.WriteLine("Finished"); }
public static void DoWork() { List<NovelInfo> novelInfos; using (var ctx=new VNCommonContext("VNCommonConnectionString")) { novelInfos = ctx.NovelInfos.Where(w => w.Getchu != null).ToList(); } Assert.IsTrue(novelInfos.Any()); var parser=new GetchuParser(); int i = 0; foreach (var novelInfo in novelInfos) { i++; string url = null; try { url = parser.ProvideUrl(novelInfo); var novel = parser.ParsePage(url); novel.JapName = novelInfo.JapName; novel.Site = novelInfo.Site; novel.Source=NovelSource.Getchu; novel.SourceKey = novelInfo.Getchu; using (var ctx = new VNContext("GetchuConnectionString")) { ctx.Novels.Add(novel); ctx.SaveChanges(); } System.Console.WriteLine(i +@" finished"); } catch (Exception ex) { Logs.Error(String.Format(GetchuParser.ErrorMessagePattern, url,""),ex); System.Console.WriteLine(i + @" failed"); } } }