// /** // * File: CrawlHost.cs // * Author: haraldwolff // * // * This file and it's content is copyrighted by the Author and / or copyright holder. // * Any use wihtout proper permission is illegal and may lead to legal actions. // * // * // **/ using System; using ln.types.threads; using ln.logging; using System.Net.NetworkInformation; using ln.snmp.endpoint; using ln.snmp; using System.Net; using ln.snmp.types; using System.Collections.Generic; using ln.snmp.rfc1213; using ln.types; using Newtonsoft.Json; using ln.skyscanner.crawl.tests; using System.Runtime.Remoting.Messaging; namespace ln.skyscanner.crawl { public class HostCrawl : PoolJob { [JsonIgnore] public Crawler Crawler { get; } [JsonIgnore] public CrawledHost CrawledHost { get; } public HostCrawl(Crawler crawler,CrawledHost crawledHost) { Crawler = crawler; CrawledHost = crawledHost; Name = String.Format("Host crawl {0} [ {1} ]", crawledHost.Name, crawledHost.PrimaryIP); } public override void RunJob() { State = "Prepare"; DateTime dateTime = DateTime.Now; if (Crawling.Crawl(this)) { if (CrawledHost.FirstSeen.Equals(DateTime.MinValue)) CrawledHost.FirstSeen = DateTime.Now; CrawledHost.LastSeen = DateTime.Now; } CrawledHost.LastCheckTime = DateTime.Now - dateTime; CrawledHost.LastCheck = dateTime; CrawledHost.NextCheck = dateTime + TimeSpan.FromHours(1); Crawler.Sync(CrawledHost); } public override int GetHashCode() { return CrawledHost.GetHashCode(); } public override bool Equals(object obj) { if (obj is HostCrawl) { HostCrawl you = obj as HostCrawl; return Crawler.Equals(you.Crawler) && CrawledHost.Equals(you.CrawledHost); } return false; } } }