public String Heading() { var article1 = new Article1(); var json = ""; try { using (var client = new WebClient()) { json = client.DownloadString("http://www.gaa.ie/iphone/get_news_json.php"); } json = json.Replace("@attributes", "attributes"); json = json.Remove(0, 11); json = json.TrimEnd('}'); var articless = JsonConvert.DeserializeObject<List<Article>>(json); var q = (from a in articless select a).OrderByDescending(a => a.upload_date).FirstOrDefault(); var art = q; article1.title = WebUtility.HtmlDecode(art.title); } catch (Exception ex) { var sf = new StackFrame(); var methodBase = sf.GetMethod(); Database.InsertErrorToDb(methodBase.Name, ex.Message, ex.ToString()); } return article1.title; }
public Article1 GetTaskArticle() { Article1 article = null; var json = ""; var newCode = "Uploaded: "; try { using (var client = new WebClient()) { json = client.DownloadString("http://www.gaa.ie/iphone/get_news_json.php"); } json = json.Replace("@attributes", "attributes"); json = json.Remove(0, 11); json = json.TrimEnd('}'); var articless = JsonConvert.DeserializeObject<List<Article>>(json); var topArticle = (from a in articless select a).First(); topArticle.filename = topArticle.filename.Replace("http:", ""); foreach (var sec in topArticle.sections.section_id) { if (sec == "2") { newCode = "Football"; break; } if (sec == "3") { newCode = "Hurling"; break; } newCode = "General"; } article = new Article1 { content_image_id = topArticle.content_image_id, content_text_id = topArticle.content_text_id, filename = topArticle.filename, ID = Convert.ToInt32(topArticle.newsid), thumbnail = topArticle.thumbnail, title = WebUtility.HtmlDecode(topArticle.title), upload_date = DateTime.Parse(topArticle.upload_date), url = topArticle.url, code = newCode }; } catch (Exception ex) { var sf = new StackFrame(); var methodBase = sf.GetMethod(); Database.InsertErrorToDb(methodBase.Name, ex.Message, ex.ToString()); } return article; }
private FileResult Resize(int height, int width) { var article1 = new Article1(); var json = ""; try { using (var client = new WebClient()) { json = client.DownloadString("http://www.gaa.ie/iphone/get_news_json.php"); } json = json.Replace("@attributes", "attributes"); json = json.Remove(0, 11); json = json.TrimEnd('}'); var articless = JsonConvert.DeserializeObject<List<Article>>(json); var q = (from a in articless select a).OrderByDescending(a => a.upload_date).FirstOrDefault(); var art = q; article1.title = WebUtility.HtmlDecode(art.title); article1.filename = art.filename.Replace("http:", ""); var uri = "http:" + article1.filename; var rsSettings = new ResizeSettings {Format = "jpg", MaxHeight = height, MaxWidth = width}; rsSettings.Anchor = ContentAlignment.TopCenter; rsSettings.Mode = FitMode.Crop; rsSettings.Scale = ScaleMode.Both; var c = Config.Current; var wc = new WebClient { CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore) }; var dt = wc.DownloadData(uri); using (var ms = new MemoryStream(dt)) { var mStream = new MemoryStream(); c.CurrentImageBuilder.Build(ms, mStream, rsSettings); mStream.Seek(0, SeekOrigin.Begin); return new FileStreamResult(mStream, "image/jpeg"); } } catch (Exception ex) { var sf = new StackFrame(); var methodBase = sf.GetMethod(); Database.InsertErrorToDb(methodBase.Name, ex.Message, ex.ToString()); } return null; }
public IEnumerable<Article1> GetArticles() { var tc = new TelemetryClient(); tc.TrackEvent("ArticlesPageHit"); var articles = new List<Article1>(); try { //newArticles = GetXmlArticles(); //foreach (var newArticle in newArticles.Article) //{ // Article1 article = new Article1 // { // content_image_id = newArticle.content_image_id.ToString(), // content_text_id = newArticle.content_text_id.ToString(), // filename = newArticle.filename, // ID = newArticle.id, // thumbnail = newArticle.thumbnail, // title = WebUtility.HtmlDecode(newArticle.title), // upload_date = DateTime.Parse(newArticle.upload_date), // url = newArticle.url, // code = "General" // }; // articles.Add(article); // if (article.title.StartsWith("LIVE:") || article.title.Contains("Live!")) // { // InsertUpdateToDb(article.ID.ToString()); // } //} //To change comment from here var articlesNotInDb = new List<Article1>(); var articlesInDb = new List<Article1>(); var json = ""; var newCode = ""; using (var client = new WebClient()) { json = client.DownloadString("http://www.gaa.ie/iphone/get_news_json.php"); } json = json.Replace("@attributes", "attributes"); json = json.Remove(0, 11); json = json.TrimEnd('}'); var articless = JsonConvert.DeserializeObject<List<Article>>(json); foreach (var a in articless) { if (a.newsid != "12370") { var isFootball = false; foreach (var sec in a.sections.section_id) { if (sec == "13") { newCode = "Camogie"; break; } if (sec == "1") { newCode = "General"; continue; } if (sec == "2") { newCode = "Football"; isFootball = true; continue; } if (sec == "3" && isFootball) { newCode = "General"; continue; } if (sec == "3") { newCode = "Hurling"; } } a.filename = a.filename.Replace("http:", ""); if (a.title.StartsWith("LIVE:") || a.title.Contains("Live!") || a.title.Contains("LIVE!") || a.title.EndsWith("as it happens")) { InsertUpdateToDb(a.newsid); } var article = new Article1 { content_image_id = a.content_image_id, content_text_id = a.content_text_id, filename = a.filename, ID = Convert.ToInt32(a.newsid), thumbnail = a.thumbnail, title = WebUtility.HtmlDecode(a.title), upload_date = DateTime.Parse(a.upload_date), url = a.url, code = newCode }; articles.Add(article); } } //To Here //Get Articles from DB articlesInDb = GetArticlesFromDb(); //Change date based on db foreach (var article1 in articles) { var q = (from ar in articlesInDb where ar.ID == article1.ID select ar).FirstOrDefault(); if (q != null) { article1.upload_date = q.upload_date; } else { article1.upload_date = DateTime.Now; articlesNotInDb.Add(article1); } } foreach (var article1 in articlesNotInDb) { articles.Remove(article1); } //if new save to db SaveToDb(articlesNotInDb); articles.AddRange(articlesNotInDb); } catch (Exception ex) { var sf = new StackFrame(); var methodBase = sf.GetMethod(); Database.InsertErrorToDb(methodBase.Name, ex.Message, ex.ToString()); } return articles.OrderByDescending(a => a.ID).Take(25); }
private List<Article1> GetArticlesFromDb() { var articles = new List<Article1>(); try { _connection = new MySqlConnection(ConnectionString); var query = "SELECT * from GAA_Article order by Id desc Limit 50;"; using (_connection) { _connection.Open(); using (var cmd = new MySqlCommand(query, _connection)) { using (var r = cmd.ExecuteReader()) { while (r.Read()) { var article = new Article1(); article.ID = Convert.ToInt32(r.GetString("Id")); article.upload_date = DateTime.Parse(r.GetString("Upload_Date")); articles.Add(article); } } } } } catch (Exception ex) { var sf = new StackFrame(); var methodBase = sf.GetMethod(); Database.InsertErrorToDb(methodBase.Name, ex.Message, ex.ToString()); } return articles; }
public IEnumerable<Article1> GetArticlesWithTime(string lastLogin) { var articles = new List<Article1>(); var json = ""; var newCode = "Uploaded: "; try { using (var client = new WebClient()) { json = client.DownloadString("http://www.gaa.ie/iphone/get_news_json.php"); } json = json.Replace("@attributes", "attributes"); json = json.Remove(0, 11); json = json.TrimEnd('}'); var articless = JsonConvert.DeserializeObject<List<Article>>(json); foreach (var a in articless) { var isFootball = false; //bool isHurling = false; foreach (var sec in a.sections.section_id) { if (sec == "1") { newCode = "General"; continue; } if (sec == "2") { newCode = "Football"; isFootball = true; continue; } if (sec == "3" && isFootball) { newCode = "General"; //isHurling = true; continue; } if (sec == "3") { newCode = "Hurling"; //isHurling = true; } //if (sec == "11") //{ // newCode = "Top Daily"; // break; //} // newCode = "General"; } a.filename = a.filename.Replace("http:", ""); if (a.title.StartsWith("LIVE:") || a.title.Contains("Live!")) { InsertUpdateToDb(a.newsid); } var article = new Article1 { content_image_id = a.content_image_id, content_text_id = a.content_text_id, filename = a.filename, ID = Convert.ToInt32(a.newsid), thumbnail = a.thumbnail, title = WebUtility.HtmlDecode(a.title), upload_date = DateTime.Parse(a.upload_date), url = a.url, code = newCode, New = false }; articles.Add(article); } } catch (Exception ex) { var sf = new StackFrame(); var methodBase = sf.GetMethod(); Database.InsertErrorToDb(methodBase.Name, ex.Message, ex.ToString()); } foreach (var article1 in articles) { if (article1.upload_date > DateTime.Parse(lastLogin)) { article1.New = true; } } return articles; }