private void GetMakers() { var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(this.pageContent); HtmlNodeCollection Maker_div = null; if (htmlDoc.DocumentNode != null && htmlDoc.ParseErrors != null && !htmlDoc.ParseErrors.Any()) { Maker_div = htmlDoc.DocumentNode.SelectNodes("//*[@id=\"marke\"]"); } if (Maker_div != null) { htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(Maker_div.First().InnerHtml); var MakerNodes = htmlDoc.DocumentNode.SelectNodes("//*//td"); foreach (var node in MakerNodes ) //.Zip(descriptions, (n, d) => new MakerClass { MakerName = n.InnerText, MakerUrlPath = d.InnerText })) { MakerObj MakerObj = new MakerObj(); MakerObj.MakerName = node.InnerText; string value = node.Attributes.AttributesWithName("onclick").First().Value; value = value.Substring(value.IndexOf("'") + 1, value.LastIndexOf("'") - value.IndexOf("'") - 1); MakerObj.MakerUrlPath = value; this.MakersList.Add(MakerObj); } } }
public void Update_CarMaker(long id, MakerObj maker) { try { string query = string.Format("UPDATE {0} SET name=@name, url=@url, logo=@logo WHERE id = {1};", MySQLExporter.MAKER_TABLE, id); System.IO.FileStream fs = new FileStream(maker.MakerLogoLocalFile, FileMode.Open); System.IO.BufferedStream bf = new BufferedStream(fs); byte[] buffer = new byte[bf.Length]; bf.Read(buffer, 0, buffer.Length); byte[] buffer_new = buffer; //Open connection if (_mySqlExporter.connection.State == ConnectionState.Open || _mySqlExporter.OpenConnection() == true) { //create mysql command MySqlCommand cmd = new MySqlCommand { CommandText = query, Connection = _mySqlExporter.connection }; //Assign the query using CommandText //Assign the connection using Connection cmd.Parameters.AddWithValue("@name", maker.MakerName); cmd.Parameters.AddWithValue("@url", string.Empty); cmd.Parameters.AddWithValue("@logo", buffer_new); //Execute query cmd.ExecuteNonQuery(); //close connection _mySqlExporter.CloseConnection(); } } catch (Exception ex) { if (Core != null && Core.Log != null) { Core.Log.Error(string.Format("SQLCarMaker::Update_CarMaker : {0}", ex.Message)); } else { throw new Exception("SQLCarMaker::Update_CarMaker", ex); } } }
public void Insert_CarMaker(MakerObj maker) { try { string query = string.Format("INSERT INTO {0} (name, url, logo) VALUES (@name, @url, @logo)", MySQLExporter.MAKER_TABLE); System.IO.FileStream fs = new FileStream(maker.MakerLogoLocalFile, FileMode.Open); System.IO.BufferedStream bf = new BufferedStream(fs); byte[] buffer = new byte[bf.Length]; bf.Read(buffer, 0, buffer.Length); byte[] buffer_new = buffer; //open connection if (_mySqlExporter.connection.State == ConnectionState.Open || _mySqlExporter.OpenConnection() == true) { //create command and assign the query and connection from the constructor MySqlCommand cmd = new MySqlCommand(query, _mySqlExporter.connection); cmd.Parameters.AddWithValue("@name", maker.MakerName); cmd.Parameters.AddWithValue("@url", string.Empty); cmd.Parameters.AddWithValue("@logo", buffer_new); //Execute command cmd.ExecuteNonQuery(); //close connection _mySqlExporter.CloseConnection(); } } catch (Exception ex) { if (Core != null && Core.Log != null) { Core.Log.Error(string.Format("SQLCarMaker::Insert_CarMaker : {0}", ex.Message)); } else { throw new Exception("SQLCarMaker::Insert_CarMaker", ex); } } }
private void GetMakers() { var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(pageContent); HtmlNodeCollection Maker_div = null; if (htmlDoc.DocumentNode != null) { Maker_div = htmlDoc.DocumentNode.SelectNodes( "//*[@id=\"ctl00_ctl00_cphContentRow_cphContent_wucNFBAutokatalogMarken1_updatePanelMarken\"]/div[2]/div[2]/ul"); } if (Maker_div != null) { htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(Maker_div.First().InnerHtml); var MakerNodes = htmlDoc.DocumentNode.SelectNodes("//li"); foreach (var node in MakerNodes ) //.Zip(descriptions, (n, d) => new MakerClass { MakerName = n.InnerText, MakerUrlPath = d.InnerText })) { if (Core.Conf.MakerName.Trim().Equals(string.Empty) || Core.Conf.MakerName.Trim().Equals("*") || Core.Conf.MakerName.ToUpper().Equals(CleanNameString(node.InnerText.Trim().ToUpper()))) { try { MakerObj MakerObj = new MakerObj(); MakerObj.MakerName = CleanNameString(node.InnerText.Trim()); //MakerObj.MakerLogoUrl = node.SelectSingleNode("/li[1]/a[1]/div[1]/img[1]").Attributes //"//*[@id=\" // // .AttributesWithName("src").First().Value; MakerObj.MakerLogoUrl = node.FirstChild.ChildNodes[1].FirstChild.ChildAttributes("src") .First().Value; // .AttributesWithName("src").First().Value; //Maker name // ChildNodes[1].ChildNodes[0].InnerText; string localImgFile = DownloadMakerImage(MakerObj.MakerLogoUrl); MakerObj.MakerLogoLocalFile = localImgFile; //string value = node.Attributes.AttributesWithName("onclick").First().Value; //value = value.Substring(value.IndexOf("'") + 1, value.LastIndexOf("'") - value.IndexOf("'") - 1); //MakerObj.MakerUrlPath = node.SelectSingleNode("/li[1]/a[1]").Attributes.AttributesWithName("href") // .First().Value; MakerObj.MakerUrlPath = node.FirstChild.Attributes.AttributesWithName("href") .First().Value; MakersList.Add(MakerObj); Thread.Sleep(100); } catch (Exception ex) { if (Core != null && Core.Log != null) { Core.Log.Error(string.Format("ADACImporter::GetMakers : {0}", ex.Message)); } else { throw new Exception("ADACImporter::GetMakers", ex); } } } } if (Core != null && Core.Log != null) { Core.Log.Info(string.Format("{0} Maker Records imported.", MakersList.Count)); } } }