public void StoreResolvedNavUnit(ResolvedNavUnit unit)
        {
            SQLiteCommand removeNavUnitRec = new SQLiteCommand("delete from navunit where address = '" + unit.Address + "'", Connection);

            removeNavUnitRec.ExecuteNonQuery();

            if (string.IsNullOrEmpty(unit.ScriptRef))
            {
                unit.ScriptRef = "none";
            }

            SQLiteCommand storeUnit = new SQLiteCommand("insert into navunitresolved (id, address, addresshash, timefound, navtype, scriptref, contenthash, timescrapped, resolvedaddress, image) " + "values ('" + unit.ID.ToString() +
                                                        "', '" + unit.Address.ToString() + "', '" + unit.AddressHash + "', '" + unit.TimeFound.ToString() + "', '" + unit.Type.ToString() + "', '" + unit.ScriptRef +
                                                        "', '" + unit.ContentHash + "', '" + unit.TimeScrapped.ToString() + "', '" + unit.ResolvedAddress.ToString() + "', '" + unit.Image + "')", Connection);
            int rows = storeUnit.ExecuteNonQuery();

            foreach (string currentURL in unit.URLSFound)
            {
                string newID = StoreNavUnit(new NavUnit(currentURL));

                if (!string.IsNullOrEmpty(newID))
                {
                    SQLiteCommand storeLink = new SQLiteCommand("insert into navunitlinks (navunitid, linkedunitid) values ('" + unit.ID.ToString() + "', '" + newID + "')", Connection);
                    storeLink.ExecuteNonQuery();
                }
            }
        }
Beispiel #2
0
        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();
        }