public List <NavUnit> RetriveUnitSet(int max) { List <NavUnit> tempNav = new List <NavUnit>(); SQLiteCommand nextUnitSet = new SQLiteCommand("select * from navunit limit " + max, Connection); SQLiteDataReader reader = nextUnitSet.ExecuteReader(System.Data.CommandBehavior.Default); while (reader.Read()) { NavUnit tempN = new NavUnit { ID = Guid.Parse(reader.GetString(1)), Address = new Uri(reader.GetString(2)), AddressHash = reader.GetString(3), TimeFound = DateTime.Parse(reader.GetString(4)), ScriptRef = reader.GetString(6) }; if (reader.GetString(5) == "URL") { tempN.Type = NavType.URL; } else { tempN.Type = NavType.Script; } tempNav.Add(tempN); } return(tempNav); }
public string StoreNavUnit(NavUnit unit) { if (!CheckForMatchUnit(unit.Address.ToString())) { if (string.IsNullOrEmpty(unit.ScriptRef)) { unit.ScriptRef = "none"; } SQLiteCommand storeUnit = new SQLiteCommand("insert into navunit (id, address, addresshash, timefound, navtype, scriptref) " + "values ('" + unit.ID.ToString() + "', '" + unit.Address.ToString() + "', '" + unit.AddressHash + "', '" + unit.TimeFound.ToString() + "', '" + unit.Type.ToString() + "', '" + unit.ScriptRef + "')", Connection); int rows = storeUnit.ExecuteNonQuery(); return(unit.ID.ToString()); } return(string.Empty); }
public void Navigate() { //if config is chrome IWebDriver Driver = new ChromeDriver(); // Navigate to the Starting URL Driver.Navigate().GoToUrl(UnitToPreform.Address); // Gather all information needed from Webdriver List <IWebElement> urls = Driver.FindElements(By.CssSelector("a[href]")).ToList(); Uri resolvedURL = new Uri(Driver.Url); byte[] screenShoot = ((ITakesScreenshot)Driver).GetScreenshot().AsByteArray; string contentMD5 = NavUnit.CalculateMD5Hash(Driver.PageSource); // generate a new resolved unit ResolvedNavUnit resolvedUnit = new ResolvedNavUnit(UnitToPreform, resolvedURL, screenShoot, contentMD5); // fill the resolved units url results foreach (IWebElement currentEle in urls) { try { if (!string.IsNullOrEmpty(currentEle.GetAttribute("href"))) { resolvedUnit.URLSFound.Add(currentEle.GetAttribute("href")); } } catch (Exception e) { resolvedUnit.NavigationErrors.Add("Webdriver error on " + resolvedUnit.Address + ": " + e.ToString()); } } // assign the resolved unit to pass back UnitToPassBack = resolvedUnit; // close down the browser and clean up Driver.Close(); }
public void FirstTimeURLStore(Config cfg, DBAccess db) { // this is only done before had for the first url NavUnit firstNav = new NavUnit(cfg.StartURL); db.StoreNavUnit(firstNav); NavThread thread = new NavThread(firstNav); Thread navThread = new Thread(thread.Navigate); navThread.Start(); while (navThread.IsAlive) { Thread.Sleep(1000); } db.StoreResolvedNavUnit(thread.UnitToPassBack); // temp code List <NavUnit> temp = db.RetriveUnitSet(4); return; }
public NavThread(NavUnit unit) { UnitToPreform = unit; }