public CalculatedSpecialty(SpecialtyInfo specialty) { var tb = specialty.GetType(); var properties = tb.GetProperties(); var t = GetType(); properties.ToList().ForEach(property => { var isPresent = t.GetProperty(property.Name); if (isPresent != null) { var value = tb.GetProperty(property.Name).GetValue(specialty, null); t.GetProperty(property.Name).SetValue(this, value, null); } }); }
private async void ParsePage(HttpContent httpContent, string link) { #if DEBUG Console.WriteLine($"Parsing {link}"); #endif var page = await httpContent.ReadAsStringAsync(); httpContent.Dispose(); var doc = new HtmlDocument(); doc.LoadHtml(page); var sp = new SpecialtyInfo { Content = new ContentVisualiser { Content = new Dictionary <string, List <string> >() }, Links = new LinksVisualiser { Links = new Dictionary <string, List <LinkItem> >() }, ChairsProvidesProg = new TupleVisualiser() }; try { var f = doc.GetElementbyId("yoo-zoo").Element("div"); foreach (var el in f.Elements("div")) { switch (el.GetAttributeValue("class", "null")) { case "pos-top": { // List<string> tmpContent = new List<string>(); var er = el.Element("div"); sp.BranchName = new Item { Content = new List <string>() }; sp.BranchName.Content.Add(er.ChildNodes[2].InnerText); var urltmp = er.ChildNodes[2].GetAttributeValue("href", ""); sp.BranchName.Url = string.IsNullOrEmpty(urltmp) ? "" : abitUrl + urltmp; sp.BranchName.Title = er.ChildNodes[1].InnerText.TrimEnd(' ').TrimStart(' '); break; } case "pos-content": { foreach (var i in el.Elements("div")) { var atr = i.GetAttributeValue("class", "null"); if (atr != "null") { switch (atr.Substring("element element-".Length)) { /* case "relateditems": * { * try * { * if (i.Element("h3").InnerText.ToLowerInvariant().Contains("контракт")) * { * sp.Modulus = Specialty.ModulusList.GetModulusFromHtml(i.Element("ul").Elements("li"), sp.Modulus, false); * } * else if (i.Element("h3").InnerText.ToLowerInvariant().Contains("держ")) * { * sp.Modulus = Specialty.ModulusList.GetModulusFromHtml(i.Element("ul").Elements("li"), sp.Modulus, true); * } * } * catch (Exception) * { * Console.SetCursorPosition(0, rx++); * Console.Write("Check this url: " + sitesUrl + link as string); * } * break; * }*/ case "text first": { try { sp.Code = i.ChildNodes[2].InnerText; } catch (Exception) { #if DEBUG Console.WriteLine("Check this url: " + abitUrl + link); #endif } break; } case "text": { List <string> tmpContent = new List <string> { i.ChildNodes[2].InnerText }; sp.Content.Content.Add(i.ChildNodes[1].InnerText, tmpContent); break; } case "textarea": { List <string> list = new List <string>(); var ds = i.Element("h3").NextSibling; list.Add(ds.OuterHtml); while (true) { if (ds.NextSibling != null) { ds = ds.NextSibling; if (ds.OuterHtml.Length > 3) { list.Add(ds.OuterHtml); } } else { break; } } sp.Content.Content.Add(i.ChildNodes[1].InnerText, list); break; } case "link": { var links = new List <LinkItem>(); foreach (var op in i.Elements("a")) { links.Add(new LinkItem { Url = op.GetAttributeValue("href", ""), Title = op.GetAttributeValue("title", "") }); } sp.Links.Links.Add(i.ChildNodes[1].InnerText, links); break; } case "relatedcategories": { var links = new List <LinkItem>(); foreach (var r in i.ChildNodes[2].ChildNodes) { var urltmp = r.ChildNodes[0].GetAttributeValue("href", ""); links.Add(new LinkItem { Url = string.IsNullOrEmpty(urltmp) ? "" : abitUrl + urltmp, Title = r.ChildNodes[0].InnerText }); } sp.ChairsProvidesProg.ChairsProvidesProg = new Tuple <string, List <LinkItem> >(i.ChildNodes[1].InnerText, links); break; } } } } break; } } } var title = f.Element("h1").InnerText.Trim(); if (title.Contains('(')) { sp.Title = title.Substring(0, title.IndexOf('(')); var sb = new Regex(@"(?<=\()\W.*?(?=\))", RegexOptions.ECMAScript).Match(title).Groups[0].Value; if (sb != "Бакалавр") { sp.SubTitle = UppercaseFirst(sb); } } else { sp.Title = title; } sp.Title = sp.Title.Trim().Replace('\n', ' ').Replace(" ", " ").Replace('’', '\'').Replace('`', '\''); sp.URL = abitUrl + link; SpecialtyList.Add(sp); } catch (Exception ex) { sp.Errors = new List <string> { ex.Message + ' ' + Tools.AnonymizeStack(ex.StackTrace) }; SpecialtyList.Add(sp); } #if DEBUG Console.WriteLine($"Finished {link}"); #endif }