public static Links StreamBrowserNavigation( this Links links, ListStreamsPage listStreamsPage, ListStreamsOperation operation) { if (operation.ContinuationToken != null) { links.Add( Constants.Relations.Next, LinkFormatter.ListStreams(operation.Pattern, operation.MaxCount, operation.ContinuationToken)); } if (listStreamsPage.ContinuationToken != null) { links.Add( Constants.Relations.Next, LinkFormatter.ListStreams(operation.Pattern, operation.MaxCount, operation.ContinuationToken)); } return(links .Add( Constants.Relations.Browse, LinkFormatter.ListStreams(operation.Pattern, operation.MaxCount, operation.ContinuationToken)) .Self()); }
public static Links StreamMessageNavigation( this Links links, StreamMessage message, ReadStreamMessageByStreamVersionOperation operation) { links.Add(Constants.Relations.First, $"{StreamId(operation)}/0"); if (operation.StreamVersion > 0) { links.Add(Constants.Relations.Previous, $"{StreamId(operation)}/{operation.StreamVersion - 1}"); } if (message.StreamId != default) { links.Add(Constants.Relations.Next, $"{StreamId(operation)}/{operation.StreamVersion + 1}"); } return(links.Add(Constants.Relations.Last, $"{StreamId(operation)}/-1") .Add( Constants.Relations.Feed, Links.FormatBackwardLink( StreamId(operation), Constants.MaxCount, StreamVersion.End, false), operation.StreamId) .Add( Constants.Relations.Message, $"{StreamId(operation)}/{operation.StreamVersion}", $"{operation.StreamId}@{operation.StreamVersion}").Self()); }
public static Links StreamsNavigation(this Links links, ReadStreamPage page, ReadStreamOperation operation) { var baseAddress = $"streams/{operation.StreamId}"; var first = Links.FormatForwardLink( baseAddress, operation.MaxCount, StreamVersion.Start, operation.EmbedPayload); var last = Links.FormatBackwardLink( baseAddress, operation.MaxCount, StreamVersion.End, operation.EmbedPayload); links.Add(Constants.Relations.First, first); if (operation.Self != first && !page.IsEnd) { links.Add( Constants.Relations.Previous, Links.FormatBackwardLink( baseAddress, operation.MaxCount, page.Messages.Min(m => m.StreamVersion) - 1, operation.EmbedPayload)); } links.Add(Constants.Relations.Feed, operation.Self, operation.StreamId).Self(); if (operation.Self != last && !page.IsEnd) { links.Add( Constants.Relations.Next, Links.FormatForwardLink( baseAddress, operation.MaxCount, page.Messages.Max(m => m.StreamVersion) + 1, operation.EmbedPayload)); } links.Add(Constants.Relations.Last, last) .Add(Constants.Relations.Metadata, $"{baseAddress}/metadata"); return(links); }
public override void Initialize() { if (_initialized) { return; } _initialized = true; Links.Clear(); if (AddAllLink) { Links.Add(new Link { DisplayName = UiStrings.FiltersLinkAll, Source = _source }); } foreach (var link in from x in ValuesStorage.GetStringList(KeyGroup) where !string.IsNullOrWhiteSpace(x) select new LinkInput(_source, x)) { Links.Add(link); link.PropertyChanged += Link_PropertyChanged; link.Close += OnLinkClose; } var rightLink = new LinkInputEmpty(Source); Links.Add(rightLink); rightLink.NewLink += OnNewLink; RecentlyClosedQueue.AddRange(ValuesStorage.GetStringList(KeyRecentlyClosed)); LoadSelected(); }
public void AddLinkLeilaoId() { Links.Add(new LinkResponse( href: _urlHelper.ActionLink("GetId", "Leilao", new { leilaoId = _leilao.Id }), rel: "self", metodo: "GET")); }
protected override void CreateHypermedia() { Href = LinkTemplates.Members.Root.Href; Links.Add(new Link("self", Href)); Links.Add(LinkTemplates.Members.Root); Links.Add(LinkTemplates.Members.Search); }
public void LN(string NameForLink, string WhatLinked, string Key = "-s") { switch (LNKeys[Key]) { case 1: // standart if (Links.ContainsKey(NameForLink)) { Console.WriteLine("It name used for another link"); return; } else { Links.Add(NameForLink, WhatLinked); } break; case 2: // rewrite if link with that name used if (Links.ContainsKey(NameForLink)) { Links[NameForLink] = WhatLinked; } else { Links.Add(NameForLink, WhatLinked); } break; } }
/// <summary> /// parse page contents, find all links /// if not found before: push on stack, add to list /// </summary> /// <param name="Page">page html contents</param> private void FindLinks(string Page) { HtmlDocument Doc = new HtmlDocument(); Doc.LoadHtml(Page); if (Doc.ParseErrors != null && Doc.ParseErrors.Count() > 0 && Doc.DeclaredEncoding != null && Doc.DeclaredEncoding.Equals(System.Text.Encoding.UTF8)) { foreach (var Error in Doc.ParseErrors) { Debug.WriteLine(Error.ToString()); } } if (Doc.DocumentNode != null && Doc.DeclaredEncoding != null && Doc.DeclaredEncoding.Equals(System.Text.Encoding.UTF8)) { foreach (var Link in Doc.DocumentNode.Descendants("a") .Select(a => a.GetAttributeValue("href", null)) .Where(u => !string.IsNullOrEmpty(u) && !IgnoreList.Any(s => u.Contains(s)) && !Links.Contains((u.StartsWith("/")) ? Domain + u : u) && (u.StartsWith("/") || u.StartsWith(Domain)))) { string Temp = (Link.StartsWith("/")) ? Domain + Link : Link; Links.Add(Temp); Crawler.Push(Temp); } } }
protected override void CreateHypermedia() { base.CreateHypermedia(); if (_linkTemplate == null) { throw new NullReferenceException("LinkTemplate is null"); } Href = _linkTemplate.Self.CreateLink(new { id = Id }).Href; Rel = _linkTemplate.Self.Rel; Links.Add(_linkTemplate.Root.CreateLink()); Links.Add(_linkTemplate.MetaData.CreateLink(new { id = Id })); if (HasChildren) { //templated links Links.Add(_linkTemplate.PagedChildren(Id)); Links.Add(_linkTemplate.PagedDescendants(Id)); } if (ParentId > 0) { Links.Add(_linkTemplate.Parent.CreateLink(new { parentId = ParentId })); } if (_linkTemplate.Upload != null) { Links.Add(_linkTemplate.Upload.CreateLink(new { id = Id })); } }
// PRIVATE METHODS ////////////////////////////////////////////////// #region Methods private Links GetLinks() { var links = new Links(); var domLinksNodes = this.Nodes(); foreach (var domLinksNode in domLinksNodes) { var domLinksNodeType = domLinksNode.NodeType; switch (domLinksNodeType) { case DomNodeType.Link: { var domLink = (IDomLink)domLinksNode; var rel = domLink.Rel; var link = domLink.Link; links.Add(rel, link); } break; default: { var detail = InfrastructureErrorStrings.DomExceptionDetailNodeHasUnexpectedChildNode .FormatWith(this.NodeType, domLinksNodeType); throw new DomException(detail); } } } return(links); }
public async void Update(Link.Link Link) { while (this.locked) { await Task.Delay(1); } this.locked = true; Link.Link existingLink = Links.Find(l => l.SourceNode == Link.SourceNode && l.TargetNode == Link.TargetNode); // && l.IPv4InterfaceAddress == Link.IPv4InterfaceAddress); if (existingLink == null && Link.OperationalStatus) { Links.Add(Link); this.OnLinkUpCallback?.Invoke(Link); } else { if (Link.OperationalStatus) { Links[Links.IndexOf(existingLink)] = Link; } else { Links.Remove(existingLink); this.OnLinkDownCallback?.Invoke(Link); } } this.OnLinkUpdateCallback?.Invoke(Link); this.locked = false; }
private void parseText() { MatchCollection matches = _urlEx.Matches(_originalText); Text = _originalText; Links.Clear(); foreach (Match match in matches) { if (match.Groups.Count < 3) { continue; } string link = match.Groups[1].Value; string linkText = match.Groups[2].Value; Text = Text.Replace(match.Value, match.Groups[2].Value); int linkIndex = Text.IndexOf(linkText, System.StringComparison.Ordinal); if (linkIndex == -1) { continue; } Links.Add(linkIndex, linkText.Length, link); } }
private void Next() { HttpHelper httpHelper = new HttpHelper() { }; var sr = httpHelper.GetHtml(new HttpItem() { URL = spliderInfo.Domain, Timeout = 5600 }); HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(sr.Html); var nodes = doc.DocumentNode.Descendants("a").Where(x => x.GetAttributeValue("href", true)).ToList(); foreach (var node in nodes) { Links.Add(new LinkModel() { Id = nodes.IndexOf(node) + 1, Title = node.InnerHtml, Url = node.GetAttributeValue("href", "") }); } IList <LinksModel> models = Mapper.DynamicMap <IList <LinkModel>, IList <LinksModel> >(Links); ILinksService service = IOCContainer.Instance.Resolve <ILinksService>(); service.Save(models); }
/// <summary> /// Generate representations for nodes /// </summary> /// <param name="node"></param> protected void GenerateRepresentations(Node node) { Guid objID = Guid.Empty; if (!Links.ContainsFirst(node.GUID)) { if (!node.IsDeleted) { objID = RhinoOutput.BakePoint(node.Position); Links.Add(node.GUID, objID); } } else { objID = Links.GetSecond(node.GUID); if (node.IsDeleted) { RhinoOutput.DeleteObject(objID); objID = Guid.Empty; } else { objID = RhinoOutput.BakeOrReplacePoint(objID, node.Position); Links.Set(node.GUID, objID); } } if (objID != Guid.Empty) { RhinoOutput.SetOriginalIDUserString(objID); string layerPath = NodesLayerName; RhinoOutput.SetObjectLayer(objID, layerPath); RhinoOutput.SetObjectName(objID, node.Description); } }
public void AddLink(Link link) { Debug.Assert(link != null); link.OnAdd(this); Links.Add(link); }
protected override void CreateHypermedia() { Links.Add(new Curie { Name = "br", Href = "/rels/{rel}" }); Links.Add(new Link("someRel", "someHref", "someTitle")); }
/// <summary> /// Adds all Queries from a NavigationQueries as Link using this hypermediaObject type target. /// Existing if a Query is added for which a Link with the same relation exists it is replaced. /// </summary> /// <param name="navigationQueries">The Queries to add</param> public void AddNavigationQueries(NavigationQueries navigationQueries) { foreach (var navigationQuery in navigationQueries.Queries) { Links.Add(navigationQuery.Key, new HypermediaObjectQueryReference(GetType(), navigationQuery.Value)); } }
public void AddLinks(DataTable table) { foreach (DataRow row in table.Rows) { Links.Add(new HyperLink(row)); } }
protected override void CreateHypermedia() { var prms = new List <object> { new { page = Page } }; if (UriTemplateSubstitutionParams != null) { prms.Add(UriTemplateSubstitutionParams); } Href = Href ?? uriTemplate.CreateLink(prms.ToArray()).Href; Links.Add(new Link { Href = Href, Rel = "self" }); if (Page > 1) { var item = UriTemplateSubstitutionParams == null ? uriTemplate.CreateLink("prev", new { page = Page - 1 }) : uriTemplate.CreateLink("prev", UriTemplateSubstitutionParams, new { page = Page - 1 }); // page overrides UriTemplateSubstitutionParams Links.Add(item); } if (Page < TotalPages) { var link = UriTemplateSubstitutionParams == null // kbr ? uriTemplate.CreateLink("next", new { page = Page + 1 }) : uriTemplate.CreateLink("next", UriTemplateSubstitutionParams, new { page = Page + 1 }); // page overrides UriTemplateSubstitutionParams Links.Add(link); } Links.Add(new Link("page", uriTemplate.Href)); }
public void AddFileToDb(string fileName) { lock (lockObjectProgress) { Links.Add(fileName); } }
void ProcessPropertyValue(IHypermediaResolver resolver, List <CuriesLink> curies, IResource resource) { var embeddedResource = new EmbeddedResource { IsSourceAnArray = false }; embeddedResource.Resources.Add(resource); Embedded.Add(embeddedResource); var representation = resource as Representation; if (representation == null) { return; } representation.RepopulateRecursively(resolver, curies); // traverse ... var link = representation.ToLink(resolver); if (link != null) { Links.Add(link); // add a link to embedded to the container ... } }
protected override void InternalExecute(object parameter) { Application.Current.Dispatcher.Invoke(delegate { Links.Clear(); }); var result = LinkCollection.FromFile(InputFile); Processed = 0; Total = result.Count; var no = 0; var itemtasks = new List <Task>(); var c = CancelToken; foreach (var item in result) { Helper.Sleep(); c.Token.ThrowIfCancellationRequested(); var xx = item; Application.Current.Dispatcher.Invoke(delegate { Links.Add((LinkModel)xx); }); ++no; item.No = no; var x = item; var itemtask = Task.Factory.StartNew(() => { x.CountAnchors(c); }, c.Token) .ContinueWith(a => TaskCompelted() ); itemtasks.Add(itemtask); } Task.WaitAll(itemtasks.ToArray(), c.Token); }
private void ProcessPropertyValue(IHypermediaResolver resolver, List <CuriesLink> curies, IEnumerable <IResource> resources) { var resourceList = resources.ToList(); var relationName = resources is IResourceList list ? list.RelationName : resourceList.FirstOrDefault()?.Rel ?? string.Empty; var embeddedResource = new EmbeddedResource { IsSourceAnArray = true, RelationName = relationName }; foreach (var resourceItem in resourceList) { embeddedResource.Resources.Add(resourceItem); if (!(resourceItem is Representation representation)) { continue; } representation.RepopulateRecursively(resolver, curies); // traverse ... var link = representation.ToLink(resolver); if (link != null) { Links.Add(link); // add a link to embedded to the container ... } } Embedded.Add(embeddedResource); }
void ProcessPropertyValue(IHypermediaResolver resolver, List <CuriesLink> curies, IEnumerable <IResource> resources) { var resourceList = resources.ToList(); if (!resourceList.Any()) { return; } var embeddedResource = new EmbeddedResource { IsSourceAnArray = true }; foreach (var resourceItem in resourceList) { embeddedResource.Resources.Add(resourceItem); var representation = resourceItem as Representation; if (representation == null) { continue; } representation.RepopulateRecursively(resolver, curies); // traverse ... var link = representation.ToLink(resolver); if (link != null) { Links.Add(link); // add a link to embedded to the container ... } } Embedded.Add(embeddedResource); }
public void SetLinks() { var ret = new List <Link>(); DataTable semanticLinkTable = new DataTable(); StringBuilder query = new StringBuilder(); query.AppendLine("SELECT links.*"); query.AppendLine("FROM semantic_links"); query.AppendLine(" INNER JOIN links ON semantic_links.link_id = links.link_id"); query.AppendLine("WHERE semantic_link_id = " + this.SemanticLinkId); query.AppendLine("ORDER BY link_id, num"); semanticLinkTable = DatabaseAccesserEcolog.GetResult(query.ToString()); foreach (DataRow row in semanticLinkTable.Rows) { Links.Add(new Link() { Num = row.Field <int>("num"), LinkId = row.Field <string>("link_id"), Latitude = row.Field <double>("latitude"), Longitude = row.Field <double>("longitude"), NodeId = row.Field <string>("node_id"), Direction = row.Field <int?>("direction") }); } }
public override void Deserialize(GenericReader reader) { base.Deserialize(reader); int version = reader.ReadInt(); Owner = reader.ReadMobile(); DeploymentType = (DeploymentType)reader.ReadInt(); int count = reader.ReadInt(); for (int i = 0; i < count; i++) { if (Links == null) { Links = new List <VvVTrap>(); } VvVTrap link = reader.ReadItem() as VvVTrap; if (link != null) { Links.Add(link); } } ParentTrap = reader.ReadItem() as VvVTrap; }
/// <summary> /// Deploys this instance. /// </summary> public void Deploy(PropertyMapGenerationOptions __options = PropertyMapGenerationOptions.none) { if (__options != PropertyMapGenerationOptions.none) { Options = __options; } if (FromType.hasParameterlessConstructor()) { FromDefaultInstance = FromType.getInstance(null); } if (ToType.hasParameterlessConstructor()) { ToDefaultInstance = ToType.getInstance(null); } if (Options.HasFlag(PropertyMapGenerationOptions.doAutoMapping)) { // fromProps.Select(x => toProps.ContainsKey(x.Key)); if (Options.HasFlag(PropertyMapGenerationOptions.matchName)) { List <String> matchFromList = fromProps.Keys.Where(x => toProps.ContainsKey(x)).ToList(); foreach (var k in matchFromList) { PropertyMapLink link = PropertyMapLink.Create(fromProps[k], toProps[k], this); if (link != null) { Links.Add(link); } } } } }
public void AddLink(string type, string path, string url = null) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (path == null) { throw new ArgumentNullException(nameof(path)); } if (!UPath.TryParse(path, out _)) { throw new ArgumentException($"Invalid path [{path}]", nameof(path)); } if (url != null) { if (!UPath.TryParse(url, out _)) { throw new ArgumentException($"Invalid url [{url}]", nameof(url)); } } if (path.Contains("*") && (url == null || !url.EndsWith("/"))) { throw new ArgumentException($"Invalid url [{path}]. Must end with a `/` if the path contains a wildcard.", nameof(url)); } var link = new BundleLink(this, type, path, url); Links.Add(link); }
public void Merge(ICollection <RoutingMapLink> links, IAddress source) { var oldLinks = Links.ToList(); var linksToAdd = links.Where(link => !link.Contains(OwnAddress) && ((link.Contains(source) && link.Connected != Links.FirstOrDefault(l => Equals(l, link)).Connected) || link.Version > Links.FirstOrDefault(l => Equals(l, link)).Version)).ToList(); if (linksToAdd.Count > 0) { Version++; } foreach (var link in linksToAdd) { Links.Remove(link); } Links.AddRange(linksToAdd); foreach (var link in links.Where(l => !l.Connected)) { if (!Links.Contains(link)) { Links.Add(link); } } //Console.WriteLine("[{0}] MERGE {1} with {2} from {3} => {4}", OwnAddress, // oldLinks.ToDOT(longNames: config.LongNames), links.ToDOT(longNames: config.LongNames), source, Links.ToDOT(longNames: config.LongNames)); }
public TestLinkContainer(IEnumerable <Link> links) { foreach (var link in links) { Links.Add(link); } }
static void Main(string[] args) { // Registering handler for unhandled exceptions AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; // Fetching global configuration var general = new ConfigurationGeneral(); general.LoadGeneral(Globals.SettingsFile); // Fetching data from command-line arguments var argumentdata = new ArgumentData(args); // Create temporary directory for copied files. Common.CreateTemporaryDirectory(); // List of URLs to be copied to clipboard. Links links = new Links(); for (int i = argumentdata.Files.Count - 1; i >= 0; i--) { var filename = Path.GetFileName(argumentdata.Files[i]); var currentclipboardurl = Common.ParseTemplate(argumentdata.Profile.ClipboardURL).Replace("%file%", HttpUtility.UrlPathEncode(filename)); links.Add(currentclipboardurl); var newfilename = Path.Combine(Globals.TemporaryDirectory, filename); File.Copy(argumentdata.Files[i], newfilename, true); // TODO: touch or not? Store this preference in profile configuration System.IO.File.SetLastWriteTimeUtc(newfilename, DateTime.UtcNow.AddSeconds(i)); } if (Directory.GetFileSystemEntries(Globals.TemporaryDirectory).Length > 0) { Upload.UploadFiles(argumentdata.Profile, Globals.TemporaryDirectory, argumentdata.Profile.RemoteDir); links.ToClipboard(argumentdata.Profile); Common.PlaySound(argumentdata.Profile); } Common.DeleteTemporaryDirectory(); Environment.Exit(0); }
/// <summary> /// Metoda slouží pro získání seznamu místností v kategorii, která je zadná linkem. /// Odkaz na místnost je ve formátu /modchat?op=mainframeset&rid=*******&js=0&nonjs=1 /// </summary> /// <param name="link">Link z kategorie</param> /// <returns>Seznam položek ve tvaru [název,link]</returns> public Links getChatRoomsList(String link) { Links chatRooms = new Links(); //uri na response se skládá z XCHAT_URI/ssk/link String uri = XCHAT_URI + "/" + SessionKey + "/" + link; //pro parsování HtmlDocument page = new HtmlDocument(); //načtení stránky WebClient wc = new WebClient(); String htmlString = wc.DownloadString(uri); //parsování page.LoadHtml(htmlString); //vybrat všechny td které mají id=c2 //z nich pak vybrat <a> -> href, který začíná na XCHAT_URI //HtmlNodeCollection tds = page.DocumentNode.SelectNodes("//a[contains(@href,'" + XCHAT_URI + "/" + SessionKey + "/room" + "')]"); //místnosti jsou v tabulce, v každém tr je kompletní záznam o místnosti HtmlNodeCollection tds = page.DocumentNode.SelectNodes("//tr"); bool first = true; //kvůli detekci prvního prvku, trochu prasárna /* * Přímej link na místnost má tvar * http://xchat.centrum.cz/ssk/modchat/room/nazev-mistnosti * * nazev-mistnosti je skutečnej název místnosti, bez diakritiky, s pomlčkama místo mezer. * Neni tedy nutný parsovat odkazy, stačí pouze získat jména místností a ty přeformátovat. * * Pokud chce uživatel domístnosti vstoupit poprvé, je odkázán na intro stránku, kde musí souhlasit s podmínkama. * To se dá přeskočit, když odešlu POST packet s disclaim=on. Budu muset použít předchozí verzi a vrátit se rid. */ foreach (HtmlNode node in tds) { //první tr je hlavička tabulky => ignorovat if (!first) { //potom u td.id: //c2 => link+jméno //c3 => info //výběr správného td a z tohoto td výběr správného odkazu ve tvaru <a href=....>JMÉNO MÍSTNOSTI</a> HtmlNode linkNameNode = node.SelectSingleNode(".//td[contains(@id,'c2')]").SelectSingleNode(".//a[contains(@href,'" + XCHAT_URI + "/" + SessionKey + "/room" + "')]"); HtmlNode infoNode = node.SelectSingleNode("//td[contains(@id,'c3')]"); //rid pres regex "rid=(\d{7})" String url = linkNameNode.GetAttributeValue("href", "nic").ToString(); Regex reg = new Regex("(?<rid>rid=[\\d]*)&"); Match rid = reg.Match(url); //name String name = linkNameNode.InnerText; //link name - zde se skutecne jmeno mistnosti preformatuje na jmeno mistnosti do odkazu String linkName = name.ToLower().Replace(' ', '-'); //odstranění diakritiky char[] diakritika = new char[] { 'á', 'č', 'ď', 'ě', 'é', 'í', 'ó', 'ř', 'š', 'ú', 'ů', 'ý', 'ž' }; char[] normalne = new char[] { 'a', 'c', 'd', 'e', 'e', 'i', 'o', 'r', 's', 'u', 'u', 'y', 'z' }; for(int i=0;i<diakritika.Length;i++) { linkName = linkName.Replace(diakritika[i], normalne[i]); } //info String info = infoNode.InnerText; //odebrání " " info = info.Substring(0, info.Length - 6); //info o místnosti zatím nepoužito chatRooms.Add(new RoomLink(name, "/modchat?op=mainframeset&"+rid.Value.ToString()+"&js=0&nonjs=1", info, rid.Groups["rid"].ToString())); } else { first = false; } } return chatRooms; }
/// <summary> /// Metoda získá seznam kategorií chatovacích místností. /// </summary> public Links getChatRoomCategories() { Links kategorie = new Links(); kategorie.Add(new CategoryLink("Města a kraje","modchat?op=roomlist&cid=1","info")); kategorie.Add(new CategoryLink("Pokec a klábosení","modchat?op=roomlist&cid=2","info")); kategorie.Add(new CategoryLink("Seznámení a flirt","modchat?op=roomlist&cid=4","info")); kategorie.Add(new CategoryLink("Lechtivá erotika","modchat?op=roomlist&cid=8","info")); kategorie.Add(new CategoryLink("Volný čas a sport","modchat?op=roomlist&cid=16","info")); kategorie.Add(new CategoryLink("Sex a neřesti do 18 let","modchat?op=roomlist&cid=32","info")); kategorie.Add(new CategoryLink("Hudební styly a kapely","modchat?op=roomlist&cid=64","info")); kategorie.Add(new CategoryLink("Filmy, knihy a počítače","modchat?op=roomlist&cid=128","info")); return kategorie; //možno řešit přes parsování html stránky - zatím zbytečně složité //metoda zatím vrátí jen seznam prvků [jméno,odkaz] //string httpContent = ""; ////odpovědí na tuhle request je packet z html stránkou, pokud je ssk správně //HttpWebRequest request = makeRequest(XCHAT_URI + "/" + ssk + "/index.php",httpContent); //HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //if(response.StatusCode == HttpStatusCode.OK) //{ // //načtení html stránky ze streamu // Stream stream = response.GetResponseStream(); // StreamReader sr = null; // //kvůli kódování řetězců // if(response.CharacterSet == null) // { // sr = new StreamReader(stream); // } // else // { // sr = new StreamReader(stream, Encoding.GetEncoding(response.CharacterSet)); // } // //přečtení streamu // string data = sr.ReadToEnd(); // WebBrowser wb = new WebBrowser(); // wb.NavigateToString(data); // sr.Close(); // response.Close(); //} }
public RawlerBase CreateRawler(HtmlNode node) { var baseUrl = BaseUrl; RawlerBase rawler = null; bool flag次のノードを調べる = true; if (targetTag.Contains(node.Name)) { Tags tags = new Tags() { Tag = node.Name }; if (node.Attributes.Where(n => n.Name == "class").Any()) { tags.ClassName = node.Attributes.Where(n => n.Name == "class").First().Value; } if (node.Attributes.Where(n => n.Name == "id").Any()) { tags.IdName = node.Attributes.Where(n => n.Name == "id").First().Value; } if (node.ChildNodes.Count() == 1 && node.ChildNodes.Where(n => n.Name == "#text").Any()) { tags.AddChildren(new DataWrite() { Attribute = tags.ClassName }); flag次のノードを調べる = false; } if (node.Attributes.Where(n => n.Name == "style" && n.Value.Contains("background")).Any()) { tags.TagVisbleType = TagVisbleType.Outer; rawler = tags.Add(new ImageLinks() { ImageType = ImageType.BackgroundImage }).DataWrite(node.GetClassName() + "_Image", DataAttributeType.Image).GetRoot(); } rawler = tags; } else if (node.Name == "a") { var resultUrlTFIDF = urlTfidf.GetResult(node.OuterHtml.ToHtml(baseUrl).GetLink().Select(n => n.Url)); var url = node.OuterHtml.ToHtml(baseUrl).GetLink().FirstDefault<RawlerLib.Web.Link, string>(n => n.Url, null); if (url != null) { //IDF が0以下の時、すべてのドキュメントで存在する。 if (urlTfidf.IDFDic.GetValueOrDefault(url) !=null && urlTfidf.IDFDic.GetValueOrDefault(url).Value <= 0) { rawler = null; flag次のノードを調べる = false; } else { if (resultUrlTFIDF.GetTakeTopValue(n => n.TFIDF).Where(n => n.Word == url).Any()) { rawler = new Links() { VisbleType = LinkVisbleType.Tag }.AddRange( new Links() { VisbleType = LinkVisbleType.Url }.DataWrite(node.GetClassName() + "_MainLink", DataAttributeType.Url).GetRoot()); if (node.ChildNodes.Count == 1 && node.ChildNodes.First().Name == "#text") { rawler.Add(new Links() { VisbleType = LinkVisbleType.Label }.DataWrite(node.GetClassName() + "_MainLabel").GetRoot()); } } else { rawler = new Links() { VisbleType = LinkVisbleType.Tag }.AddRange( new Links() { VisbleType = LinkVisbleType.Url, Enable = enableGetSubUrlLink }.DataWrite(node.GetClassName() + "_SubLink").GetRoot(), new Links() { VisbleType = LinkVisbleType.Label }.DataWrite(node.GetClassName() + "_SubLabel").GetRoot() ); } } } else { //URLがないAタグの場合。 Tags tags = new Tags() { Tag = node.Name }; if (node.Attributes.Where(n => n.Name == "class").Any()) { tags.ClassName = node.Attributes.Where(n => n.Name == "class").First().Value; } if (node.Attributes.Where(n => n.Name == "id").Any()) { tags.IdName = node.Attributes.Where(n => n.Name == "id").First().Value; } rawler = tags; } if (node.ChildNodes.Count == 1 && node.ChildNodes.Where(n => n.Name == "#text").Any()) { flag次のノードを調べる = false; } } else if (node.Name == "img") { var resultImgeTFIDF = imageTfidf.GetResult(node.OuterHtml.ToHtml(baseUrl).GetImageLink().Select(n => n.Url)); var url = node.OuterHtml.ToHtml(baseUrl).GetImageLink().FirstDefault(n => n.Url, null); if (url != null) { if (imageTfidf.IDFDic.Count>0 && imageTfidf.IDFDic.GetValueOrDefault(url).Value <= 0) { rawler = null; flag次のノードを調べる = false; } else { if (resultImgeTFIDF.GetTakeTopValue(n => n.TFIDF).Where(n => n.Word == url).Any()) { rawler = new ImageLinks().DataWrite(node.GetClassName() + "_Image", DataAttributeType.Image).GetRoot(); } else { if (iconImageColumn) { rawler = new DataWrite() { AttributeTree = new ImageLinks() { VisbleType = LinkVisbleType.Label }, Value = "1" }; } else { rawler = new ImageLinks().DataWrite(node.GetClassName() + "_Icon", DataAttributeType.Image).GetRoot(); } } } } } ///背景画像に反応させる。 else if (node.Attributes.Where(n => n.Name == "style" && n.Value.Contains("background")).Any()) { rawler = new ImageLinks() { ImageType = ImageType.BackgroundImage }.DataWrite(node.GetClassName() + "_Image", DataAttributeType.Image).GetRoot(); } else if (node.Name == "span") { Tags tags = new Tags() { Tag = node.Name }; if (node.Attributes.Where(n => n.Name == "class").Any()) { tags.ClassName = node.Attributes.Where(n => n.Name == "class").First().Value; } if (node.ChildNodes.Count() == 1 && node.ChildNodes.Where(n => n.Name == "#text").Any()) { tags.AddChildren(new DataWrite() { Attribute = tags.ClassName }); flag次のノードを調べる = false; } rawler = tags; } else if (node.Name == "#comment") { flag次のノードを調べる = false; } else { var t = node.OuterHtml.Replace("\n", "").Trim(); if (t.Length > 0) { rawler = new TagClear().Trim().Add(new DataWrite() { Attribute = node.GetClassName() + "_" + node.Name }).GetRoot(); if (node.ChildNodes.Count == 1 && node.ChildNodes.Where(n => n.Name == "#text").Any()) { flag次のノードを調べる = false; } } } if (rawler != null && node.ChildNodes.Count == 1 && node.ChildNodes.Where(n => n.Name == "span").Any()) { rawler.AddChildren(new DataWrite() { Attribute = node.GetClassName() }); } foreach (var item in node.ChildNodes) { if (flag次のノードを調べる) { var r = CreateRawler(item); if (r != null && rawler != null) { rawler.AddChildren(r); } else { if (r != null && rawler == null) { rawler = r; } } } } return rawler; }