static async Task <MyHtmlModel> Proxy(string path) { HtmlStoreProxy proxyOb = new HtmlStoreProxy(); var model = await proxyOb.GetMyHtmlModel(path); //Console.WriteLine(model.HTML); return(model); }
public override object Handle(string path) { if (Regex.IsMatch(path, PatternWeb)) { var proxy = new HtmlStoreProxy(); return(proxy.GetMyHtmlModel(path).Result); } return(base.Handle(path)); }
static async void Composite(string path) { WebCrawler crawler = WebCrawler.GetInstance(); HtmlStoreProxy proxy = new HtmlStoreProxy(); MyHtmlModel model = await proxy.GetMyHtmlModel(path); HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(model.HTML); HtmlNode html = crawler.GetFirstNode("html", htmlDoc); var bodyNode = html.SelectSingleNode("//body"); var navigationNode = crawler.GetNode ( "class", "navbar navbar-expand-lg navbar-light fixed-top", htmlDoc ); var headerNode = crawler.GetNode ( "class", "masthead", htmlDoc ); var aboutSectionNode = crawler.GetNode ( "id", "about", htmlDoc ); var signupSection = crawler.GetNode ( "id", "signup", htmlDoc ); var contentOfsignupSection = crawler.GetFirstNode("body/section[3]/div[1]", htmlDoc); signupSection.RemoveAllChildren(); html.RemoveChild(bodyNode);//html tag is without body tag Console.WriteLine(html.OuterHtml); ////////////////Composite realization Composite.Component htmlComposite = new CompositeComponent ( new MyHtmlModel() { HTML = html.OuterHtml, Name = "WithoutBody" } ); htmlComposite.Node = html; bodyNode.RemoveAllChildren();//body tag is empty //composite components Composite.Component EmptyBody = new CompositeComponent ( new MyHtmlModel() { HTML = bodyNode.OuterHtml, Name = "EmptyBody" } ); EmptyBody.Node = bodyNode; //leaf HtmlElem navigation = new HtmlElem(new MyHtmlModel() { HTML = navigationNode.OuterHtml, Name = "NavBar" }); navigation.Node = navigationNode; //leaf HtmlElem header = new HtmlElem(new MyHtmlModel() { HTML = headerNode.OuterHtml, Name = "Header" }); header.Node = headerNode; //leaf HtmlElem AboutSection = new HtmlElem(new MyHtmlModel() { HTML = aboutSectionNode.OuterHtml, Name = "NavBar" }); AboutSection.Node = aboutSectionNode; //append children to body EmptyBody.Add(navigation); EmptyBody.Node.AppendChild(navigation.Node); EmptyBody.Add(header); EmptyBody.Node.AppendChild(header.Node); EmptyBody.Add(AboutSection); EmptyBody.Node.AppendChild(AboutSection.Node); htmlComposite.Add(EmptyBody); htmlComposite.Node.AppendChild(EmptyBody.Node); htmlComposite.Display();//displaying tree Console.WriteLine("--------------------htmlComposite html----------------"); Console.WriteLine(htmlComposite.Node.OuterHtml); //displaying node html EmptyBody.Remove(AboutSection); //remove child EmptyBody.Node.RemoveChild(AboutSection.Node); //remove node Console.WriteLine("--------------------htmlComposite html after remove----------------"); Console.WriteLine(htmlComposite.Node.OuterHtml);//displaying body without child EmptyBody.Add(AboutSection); EmptyBody.Node.AppendChild(AboutSection.Node); //add one more composite element Composite.Component signUpSectionComposite = new CompositeComponent (new MyHtmlModel() { HTML = signupSection.OuterHtml, Name = "EmptySignUpSection" }); signUpSectionComposite.Node = signupSection; //leaf HtmlElem signUpSectionContainer = new HtmlElem ( new MyHtmlModel() { HTML = contentOfsignupSection.OuterHtml, Name = "SignUpSectionContainer" } ); signUpSectionContainer.Node = contentOfsignupSection; signUpSectionComposite.Add(signUpSectionContainer); signUpSectionComposite.Node.AppendChild(signUpSectionContainer.Node); EmptyBody.Add(signUpSectionComposite); EmptyBody.Node.AppendChild(signUpSectionComposite.Node); htmlComposite.Display(); Console.WriteLine("--------------------htmlComposite html----------------"); Console.WriteLine(htmlComposite.Node.OuterHtml); //htmlComposite.MyHtmlmodel.HTML=htmlComposite.Node.OuterHtml;//saving all html MyHtmlModel final = new MyHtmlModel() { HTML = htmlComposite.MyHtmlmodel.HTML, Name = "ResultOfComposition" }; try { GenericSerializer serializer = new GenericSerializer("res", @"E:\studying\education\6сем\трпз\lab5\Saves\"); serializer.BinarySerializing(FileMode.Create, final); serializer.DataContractSerialization(FileMode.Create, typeof(MyHtmlModel), final); } catch (Exception e) { } EmptyBody.Remove(header); //remove child EmptyBody.Node.RemoveChild(header.Node); //remove node htmlComposite.Display(); }