public void ActionAdd(ModRSSModel model) { if (model.RecordID > 0) { entity = ModRSSService.Instance.GetByID(model.RecordID); // khoi tao gia tri mac dinh khi update } else { entity = new ModRSSEntity(); // khoi tao gia tri mac dinh khi insert entity.MenuID = model.MenuID; } ViewBag.Data = entity; ViewBag.Model = model; }
public static void GetContentFromRSS(string domain, string rss, int menuID, string gettag, string getclass, string deltag, string delclass) { try { var reader = new XmlTextReader(rss); var ds = new DataSet(); try { ds.ReadXml(reader); } catch { } for (int i = 0; ds.Tables["item"] != null && i < ds.Tables["item"].Rows.Count; i++) { try { string pubdate = ds.Tables["item"].Rows[i]["pubDate"].ToString(); string[] formats = { "M/d/yyyy h:mm:ss tt", "M/d/yyyy h:mm tt", "MM/dd/yyyy hh:mm:ss", "M/d/yyyy h:mm:ss", "M/d/yyyy hh:mm tt", "M/d/yyyy hh tt", "M/d/yyyy h:mm", "M/d/yyyy h:mm", "MM/dd/yyyy hh:mm", "M/dd/yyyy hh:mm", "yyyy/M/d h:mm:ss tt", "yyyy/M/d h:mm tt", "yyyy/MM/dd hh:mm:ss", "yyyy/MM/dd h:mm:ss", "yyyy/M/d hh:mm tt", "yyyy/M/d hh tt", "yyyy/M/d h:mm", "yyyy/M/d h:mm", "yyyy/MM/dd hh:mm", "yyyy/MM/dd hh:mm", "M-d-yyyy h:mm:ss tt", "M-d-yyyy h:mm tt", "MM-dd-yyyy hh:mm:ss", "M-d-yyyy h:mm:ss", "M-d-yyyy hh:mm tt", "M-d-yyyy hh tt", "M-d-yyyy h:mm", "M-d-yyyy h:mm", "MM-dd-yyyy hh:mm", "M-dd-yyyy hh:mm", "yyyy-M-d h:mm:ss tt", "yyyy-M-d h:mm tt", "yyyy-MM-dd hh:mm:ss", "yyyy-MM-dd h:mm:ss", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd H:mm:ss", "yyyy-M-d hh:mm tt", "yyyy-M-d hh tt", "yyyy-M-d h:mm", "yyyy-M-d h:mm", "yyyy-MM-dd hh:mm", "yyyy-MM-dd hh:mm", "MM/dd/yyyy HH:mm:ss", "M/d/yyyy HH:mm tt", "M/d/yyyy HH tt", "MM/dd/yyyy HH:mm", "M/dd/yyyy HH:mm", "yyyy/MM/dd HH:mm:ss", "yyyy/M/d HH:mm tt", "yyyy/M/d HH tt", "yyyy/MM/dd HH:mm", "yyyy/MM/dd HH:mm", "MM-dd-yyyy HH:mm:ss", "M-d-yyyy HH:mm tt", "M-d-yyyy HH tt", "MM-dd-yyyy HH:mm", "M-dd-yyyy HH:mm", "yyyy-M-d H:mm:ss tt", "yyyy-M-d H:mm tt", "M-d-yyyy H:mm", "M-d-yyyy H:mm", "M-d-yyyy H:mm:ss tt", "M-d-yyyy H:mm tt", "M-d-yyyy H:mm:ss", "yyyy/M/d H:mm", "yyyy/M/d H:mm", "yyyy/M/d H:mm:ss tt", "yyyy/M/d H:mm tt", "yyyy/MM/dd H:mm:ss", "M/d/yyyy H:mm", "M/d/yyyy H:mm", "M/d/yyyy H:mm:ss", "M/d/yyyy H:mm:ss tt","M/d/yyyy H:mm tt", "yyyy-M-d HH:mm tt", "yyyy-M-d HH tt", "yyyy-M-d H:mm", "yyyy-M-d H:mm", "yyyy-MM-dd HH:mm", "yyyy-MM-dd HH:mm", "dddd, MMMM dd yyyy", "dddd, MMMM dd, yyyy h:mm tt", "dddd, MMMM dd, yyyy h:mm:ss tt", "MMMM dd", "MMMM, yyyy", "ddd, dd MMM yyyy HH:mm:ss GMT","ddd, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd HH:mm:ssZ", "MM/dd/yyyy HH:mm:ss GMT", "ddd, dd MMM yyyy HH:mm:ss GMTZ", //"Mon, 20 Mar 2017 21:56:05 GMT+7" "ddd, dd MMM yyyy HH':'mm':'ss 'GMT+7'" }; DateTime published = DateTime.Now; try { //published = DateTime.ParseExact(pubdate, formats, // CultureInfo.CurrentCulture, // DateTimeStyles.None); published = DateTime.ParseExact(pubdate, formats, CultureInfo.CurrentUICulture, DateTimeStyles.None); } catch (FormatException e) { continue; } //if (published.ToShortDateString() == DateTime.Now.ToShortDateString()) //{ string url = ds.Tables["item"].Rows[i]["link"].ToString().Replace(System.Environment.NewLine, " "); string description = ds.Tables["item"].Rows[i]["description"].ToString(); string img = string.Empty, des = string.Empty; if (description.Contains("<img")) { int start = description.IndexOf("<img"); int end = description.IndexOf("</a>"); if (start <= end) { img = description.Substring(start, description.Length - start - 1); } } string matchString = Regex.Match(img, "<img.+?src=[\"'](.+?)[\"'].+?>", RegexOptions.IgnoreCase).Groups[1].Value; if (string.IsNullOrEmpty(matchString) && description.Contains("<img")) { int start = description.IndexOf("<img"); int end = description.IndexOf("/>"); if (start <= end) { img = description.Substring(start, description.Length - start - 1); } matchString = Regex.Match(img, "<img.+?src=[\"'](.+?)[\"'].+?>", RegexOptions.IgnoreCase).Groups[1].Value; } //if (description.Contains("<img")) //{ // description = description.Replace(matchString, ""); //} if (description.Contains("<a")) { int start = description.IndexOf("<a"); int end = description.IndexOf("</a>"); if (start <= end) { des = description.Substring(start, end - start + 4); } description = description.Replace(des, "").Trim(); } if (description.Contains("<img")) { int start = description.IndexOf("<img"); int end = description.IndexOf("/>"); if (start <= end) { des = description.Substring(start, end - start + 2); } description = description.Replace(des, "").Trim(); } string title = ds.Tables["item"].Rows[i]["title"].ToString(); if (CheckNews(Data.GetCode(title), title) == false) { var entity = new ModRSSEntity { Name = title, Code = Data.GetCode(title), Url = url, Published = published, NgayLayTin = DateTime.Now, Nguon = domain, File = matchString, Summary = description, Content = GetContentFromURL(url, gettag, getclass, deltag, delclass), MenuID = menuID, Activity = false }; ModRSSService.Instance.Save(entity); } //} } catch (Exception ex) { continue; } } } catch (Exception) { } }