public Int64 AddPremalinkMetaChar(DtoMeta dtometa) { try { _dalpremalink = new DalPremalink(); return(_dalpremalink.AddPremalinkMetaChar(dtometa)); } catch (Exception ex) { ex.ToExceptionless().Submit(); } return(0); }
public long AddPremalinkMetaChar(DtoMeta dtometa) { _command = new SqlCommand(StoredProcedure.Names.spAddPremalinkMetaChar.ToString(), _connection) { CommandType = CommandType.StoredProcedure }; _command.Parameters.Add("@description", SqlDbType.VarChar); _command.Parameters.Add("@url", SqlDbType.VarChar); _command.Parameters.Add("@image", SqlDbType.VarChar); _command.Parameters.Add("@title", SqlDbType.VarChar); _command.Parameters.Add("@keywords", SqlDbType.VarChar); _command.Parameters.Add("@site_name", SqlDbType.VarChar); _command.Parameters.Add("@published_time", SqlDbType.VarChar); _command.Parameters.Add("@emotion", SqlDbType.VarChar); _command.Parameters.Add("@type", SqlDbType.VarChar); _command.Parameters.Add("@pricecurrency", SqlDbType.VarChar); _command.Parameters.Add("@availability", SqlDbType.VarChar); _command.Parameters.Add("@priceamount", SqlDbType.VarChar); _command.Parameters.Add("@rating", SqlDbType.VarChar); _command.Parameters.Add("@gender", SqlDbType.VarChar); _command.Parameters.Add("@pricestartdate", SqlDbType.VarChar); _command.Parameters.Add("@priceenddate", SqlDbType.VarChar); _command.Parameters.Add("@ingredients", SqlDbType.VarChar); _command.Parameters.Add("@avilabilitydestinations", SqlDbType.VarChar); _command.Parameters.Add("@cooktime", SqlDbType.VarChar); _command.Parameters.Add("@preptime", SqlDbType.VarChar); _command.Parameters.Add("@totaltime", SqlDbType.VarChar); _command.Parameters.Add("@recipeyield", SqlDbType.VarChar); _command.Parameters.Add("@aggregaterating", SqlDbType.VarChar); _command.Parameters.Add("@duration", SqlDbType.VarChar); _command.Parameters.Add("@genre", SqlDbType.VarChar); _command.Parameters.Add("@actor", SqlDbType.VarChar); _command.Parameters.Add("@director", SqlDbType.VarChar); _command.Parameters.Add("@contentrating", SqlDbType.VarChar); _command.Parameters.Add("@author", SqlDbType.VarChar); _command.Parameters.Add("@section", SqlDbType.VarChar); _command.Parameters.Add("@locationlatitude", SqlDbType.VarChar); _command.Parameters.Add("@locationlongitude", SqlDbType.VarChar); _command.Parameters.Add("@street_address", SqlDbType.VarChar); _command.Parameters.Add("@locality", SqlDbType.VarChar); _command.Parameters.Add("@region", SqlDbType.VarChar); _command.Parameters.Add("@postal_code", SqlDbType.VarChar); _command.Parameters.Add("@brand", SqlDbType.VarChar); _command.Parameters.Add("@AllMetachar_Link", SqlDbType.VarChar); _command.Parameters.Add("@WebsiteUrl", SqlDbType.VarChar); _command.Parameters.Add("@WebsiteLogo", SqlDbType.VarChar); _command.Parameters[0].Value = dtometa.Ogdescription; _command.Parameters[1].Value = dtometa.Ogurl; _command.Parameters[2].Value = dtometa.Ogimage; _command.Parameters[3].Value = dtometa.Ogtitle; _command.Parameters[4].Value = dtometa.Ogkeywords; _command.Parameters[5].Value = dtometa.OgsiteName; _command.Parameters[6].Value = dtometa.OgpublishedTime; _command.Parameters[7].Value = dtometa.Ogemotion; _command.Parameters[8].Value = dtometa.Ogtype; _command.Parameters[9].Value = dtometa.Ogpricecurrency; _command.Parameters[10].Value = dtometa.Ogavailability; _command.Parameters[11].Value = dtometa.Ogpriceamount; _command.Parameters[12].Value = dtometa.Ograting; _command.Parameters[13].Value = dtometa.Oggender; _command.Parameters[14].Value = dtometa.Ogpricestartdate; _command.Parameters[15].Value = dtometa.Ogpriceenddate; _command.Parameters[16].Value = dtometa.Ogingredients; _command.Parameters[17].Value = dtometa.Ogavilabilitydestinations; _command.Parameters[18].Value = dtometa.Ogcooktime; _command.Parameters[19].Value = dtometa.Ogpreptime; _command.Parameters[20].Value = dtometa.Ogtotaltime; _command.Parameters[21].Value = dtometa.Ogrecipeyield; _command.Parameters[22].Value = dtometa.Ogaggregaterating; _command.Parameters[23].Value = dtometa.Ogduration; _command.Parameters[24].Value = dtometa.Oggenre; _command.Parameters[25].Value = dtometa.Ogactor; _command.Parameters[26].Value = dtometa.Ogdirector; _command.Parameters[27].Value = dtometa.Ogcontentrating; _command.Parameters[28].Value = dtometa.Ogauthor; _command.Parameters[29].Value = dtometa.Ogsection; _command.Parameters[30].Value = dtometa.Oglocationlatitude; _command.Parameters[31].Value = dtometa.Oglocationlongitude; _command.Parameters[32].Value = dtometa.OgstreetAddress; _command.Parameters[33].Value = dtometa.Oglocality; _command.Parameters[34].Value = dtometa.Ogregion; _command.Parameters[35].Value = dtometa.OgpostalCode; _command.Parameters[36].Value = dtometa.Ogbrand; _command.Parameters[37].Value = dtometa.AllMetachars; _command.Parameters[38].Value = dtometa.WebsiteUrl; _command.Parameters[39].Value = dtometa.WebsiteLogo; _connection.Open(); long premalinkId = Convert.ToInt64(_command.ExecuteScalar().ToString()); _connection.Close(); return(premalinkId); }
public string Getmetadata(string link) { System.Diagnostics.Debugger.Launch(); var dtometa = new DtoMeta(); var uri = new Uri(link); var request = (HttpWebRequest)WebRequest.Create(uri); var response = (HttpWebResponse)request.GetResponse(); var reader = new StreamReader(response.GetResponseStream()); var doc = new HtmlDocument(); doc.Load(reader); HtmlNode node = doc.DocumentNode; //All metachars HtmlNodeCollection All = node.SelectNodes("//meta"); string allmetachars = ""; if (All != null) { foreach (HtmlNode item in All) { allmetachars += item.OuterHtml; } } //General HtmlNodeCollection ogtitle = node.SelectNodes("//meta[@property='og:title']"); HtmlNodeCollection ogurl = node.SelectNodes("//meta[@property='og:url']"); HtmlNodeCollection ogsite_name = node.SelectNodes("//meta[@property='og:site_name']"); HtmlNodeCollection ogdescription = node.SelectNodes("//meta[@property='og:description']"); HtmlNodeCollection ogimage = node.SelectNodes("//meta[@property='og:image']"); HtmlNodeCollection ogpublished_time = node.SelectNodes("//meta[@property='og:published_time']"); HtmlNodeCollection ogkeywords = node.SelectNodes("//meta[@name='keywords']"); HtmlNodeCollection ogemotion = node.SelectNodes("//meta[@property='og:emotion']"); HtmlNodeCollection ogtype = node.SelectNodes("//meta[@property='og:type']"); //Product HtmlNodeCollection ogpriceamount = node.SelectNodes("//meta[@property='og:price:amount']"); HtmlNodeCollection ogpricecurrency = node.SelectNodes("//meta[@property='og:price:currency']"); HtmlNodeCollection ogavailability = node.SelectNodes("//meta[@property='og:availability']"); HtmlNodeCollection ograting = node.SelectNodes("//meta[@property='og:rating']"); HtmlNodeCollection oggender = node.SelectNodes("//meta[@property='og:gender']"); HtmlNodeCollection ogpricestartdate = node.SelectNodes("//meta[@property='og:price:start_date']"); HtmlNodeCollection ogpriceenddate = node.SelectNodes("//meta[@property='og:price:end_date']"); HtmlNodeCollection ogbrand = node.SelectNodes("//meta[@property='og:brand']"); //Receipe HtmlNodeCollection ogingredients = node.SelectNodes("//meta[@property='og:ingredients']"); HtmlNodeCollection ogavilabilitydestinations = node.SelectNodes("//meta[@property='og:avilability:destinations']"); HtmlNodeCollection ogcooktime = node.SelectNodes("//meta[@property='og:cooktime']"); HtmlNodeCollection ogpreptime = node.SelectNodes("//meta[@property='og:preptime']"); HtmlNodeCollection ogtotaltime = node.SelectNodes("//meta[@property='og:totaltime']"); HtmlNodeCollection ogrecipeyield = node.SelectNodes("//meta[@property='og:recipeyield']"); HtmlNodeCollection ogaggregaterating = node.SelectNodes("//meta[@property='og:aggregaterating']"); //movies HtmlNodeCollection ogduration = node.SelectNodes("//meta[@property='og:duration']"); HtmlNodeCollection oggenre = node.SelectNodes("//meta[@property='og:genre']"); HtmlNodeCollection ogactor = node.SelectNodes("//meta[@property='og:actor']"); HtmlNodeCollection ogdirector = node.SelectNodes("//meta[@property='og:director']"); HtmlNodeCollection ogcontentrating = node.SelectNodes("//meta[@property='og:contentrating']"); //Article HtmlNodeCollection ogauthor = node.SelectNodes("//meta[@property='og:author']"); HtmlNodeCollection ogsection = node.SelectNodes("//meta[@property='og:section']"); //Place HtmlNodeCollection oglocationlatitude = node.SelectNodes("//meta[@property='og:location:latitude']"); HtmlNodeCollection oglocationlongitude = node.SelectNodes("//meta[@property='og:location:longitude']"); HtmlNodeCollection ogstreet_address = node.SelectNodes("//meta[@property='og:street_address']"); HtmlNodeCollection oglocality = node.SelectNodes("//meta[@property='og:locality']"); HtmlNodeCollection ogregion = node.SelectNodes("//meta[@property='og:region']"); HtmlNodeCollection ogpostal_code = node.SelectNodes("//meta[@property='og:postal_code']"); if (ogtitle != null) { if (ogtitle[0].Attributes["content"].Value == "") { ogtitle = node.SelectNodes("//meta[@property='og:name']"); if (ogtitle != null) { if (ogtitle[0].Attributes["content"].Value == "") { ogtitle = node.SelectNodes("//title"); dtometa.Ogtitle = ogtitle[0].InnerText; } else { dtometa.Ogtitle = ogtitle[0].Attributes["content"].Value; } } } else { dtometa.Ogtitle = ogtitle[0].Attributes["content"].Value; } } if (ogurl != null) { if (ogurl[0].Attributes["content"].Value != "") { dtometa.Ogurl = ogurl[0].Attributes["content"].Value; } else { dtometa.Ogurl = link; } } if (ogsite_name != null) { if (ogsite_name[0].Attributes["content"].Value != "") { dtometa.OgsiteName = ogsite_name[0].Attributes["content"].Value; } else { dtometa.OgsiteName = uri.Host; } } if (ogdescription != null) { if (ogdescription[0].Attributes["content"].Value != "") { ogdescription = node.SelectNodes("//meta[@name='description']"); if (ogdescription != null) { dtometa.Ogdescription = ogdescription[0].Attributes["content"].Value; } } else { dtometa.Ogdescription = ogdescription[0].Attributes["content"].Value; } } if (ogimage != null) { if (ogimage[0].Attributes["content"].Value == "") { ogimage = node.SelectNodes("//link [@rel='image_src']"); if (ogimage != null) { dtometa.Ogimage = ogimage[0].Attributes["href"].Value; } } else { dtometa.Ogimage = ogimage[0].Attributes["content"].Value; } } if (ogpublished_time != null) { dtometa.OgpublishedTime = ogpublished_time[0].Attributes["content"].Value; } if (ogkeywords != null) { if (ogkeywords[0].Attributes["content"].Value == "") { ogkeywords = node.SelectNodes("//meta[@name='keywords']"); if (ogkeywords != null) { if (ogkeywords[0].Attributes["content"].Value == "") { ogkeywords = node.SelectNodes("//meta[@name='news_keywords']"); } dtometa.Ogkeywords = ogkeywords[0].Attributes["content"].Value; } } else { dtometa.Ogkeywords = ogkeywords[0].Attributes["content"].Value; } } if (ogemotion != null) { dtometa.Ogemotion = ogemotion[0].Attributes["content"].Value; } if (ogtype != null) { if (ogtype[0].Attributes["content"].Value == "") { dtometa.Ogtype = "others"; } else { dtometa.Ogtype = ogtype[0].Attributes["content"].Value; } } if (ogpriceamount != null) { dtometa.Ogpriceamount = ogpriceamount[0].Attributes["content"].Value; } if (ogpricecurrency != null) { dtometa.Ogpricecurrency = ogpricecurrency[0].Attributes["content"].Value; } if (ogavailability != null) { dtometa.Ogavailability = ogavailability[0].Attributes["content"].Value; } if (ograting != null) { dtometa.Ograting = ograting[0].Attributes["content"].Value; } if (oggender != null) { dtometa.Oggender = oggender[0].Attributes["content"].Value; } if (ogpricestartdate != null) { dtometa.Ogpricestartdate = ogpricestartdate[0].Attributes["content"].Value; } if (ogpriceenddate != null) { dtometa.Ogpriceenddate = ogpriceenddate[0].Attributes["content"].Value; } if (ogingredients != null) { dtometa.Ogingredients = ogingredients[0].Attributes["content"].Value; } if (ogavilabilitydestinations != null) { dtometa.Ogavilabilitydestinations = ogavilabilitydestinations[0].Attributes["content"].Value; } if (ogcooktime != null) { dtometa.Ogcooktime = ogcooktime[0].Attributes["content"].Value; } if (ogpreptime != null) { dtometa.Ogpreptime = ogpreptime[0].Attributes["content"].Value; } if (ogtotaltime != null) { dtometa.Ogtotaltime = ogtotaltime[0].Attributes["content"].Value; } if (ogrecipeyield != null) { dtometa.Ogrecipeyield = ogrecipeyield[0].Attributes["content"].Value; } if (ogaggregaterating != null) { dtometa.Ogaggregaterating = ogaggregaterating[0].Attributes["content"].Value; } if (ogduration != null) { dtometa.Ogduration = ogduration[0].Attributes["content"].Value; } if (oggenre != null) { dtometa.Oggenre = oggenre[0].Attributes["content"].Value; } if (ogactor != null) { dtometa.Ogactor = ogactor[0].Attributes["content"].Value; } if (ogdirector != null) { dtometa.Ogdirector = ogdirector[0].Attributes["content"].Value; } if (ogcontentrating != null) { dtometa.Ogcontentrating = ogcontentrating[0].Attributes["content"].Value; } if (ogauthor != null) { if (ogauthor[0].Attributes["content"].Value == "") { ogauthor = node.SelectNodes("//meta[@name='author']"); if (ogauthor != null) { dtometa.Ogauthor = ogauthor[0].Attributes["content"].Value; } } else { dtometa.Ogauthor = ogauthor[0].Attributes["content"].Value; } } if (ogsection != null) { if (ogsection[0].Attributes["content"].Value == "") { ogsection = node.SelectNodes("//meta[@property='article:section']"); if (ogsection != null) { dtometa.Ogsection = ogsection[0].Attributes["content"].Value; } } else { dtometa.Ogsection = ogsection[0].Attributes["content"].Value; } } if (oglocationlatitude != null) { dtometa.Oglocationlatitude = oglocationlatitude[0].Attributes["content"].Value; } if (oglocationlongitude != null) { dtometa.Oglocationlongitude = oglocationlongitude[0].Attributes["content"].Value; } if (ogstreet_address != null) { dtometa.OgstreetAddress = ogstreet_address[0].Attributes["content"].Value; } if (oglocality != null) { dtometa.Oglocality = oglocality[0].Attributes["content"].Value; } if (ogregion != null) { dtometa.Ogregion = ogregion[0].Attributes["content"].Value; } if (ogpostal_code != null) { dtometa.OgpostalCode = ogpostal_code[0].Attributes["content"].Value; } if (allmetachars != "") { dtometa.AllMetachars = allmetachars; } string[] Logo; string character = ""; if (dtometa.OgsiteName != null) { if (dtometa.OgsiteName != "") { character = dtometa.OgsiteName.Trim().Substring(0, 1); } } if (character == "") { if (dtometa.Ogurl != null) { if (dtometa.Ogurl != "") { Logo = dtometa.Ogurl.Split('.'); if (Logo.Length == 2) { character = Logo[1].Trim().Substring(0, 1); } else { character = Logo[0].Trim().Substring(0, 1); } } } } if (character == "") { character = "W"; } dtometa.WebsiteLogo = ConvertTextToImage(character.ToUpper(), "Arial", 30, Color.White, Color.Black, 50, 50); var bllpremalink = new BllPremalink(); bllpremalink.AddPremalinkMetaChar(dtometa); if (dtometa.Ogimage.Length > 0) { return(null); } return(link); }