public bool RemoveRSSItem(int rssid) { bool result = true; try { RSSDBDataContext data = new RSSDBDataContext(); RSSItem item = (from rssitem in data.RSSItems where rssitem.ID == rssid select rssitem).Single(); if (item.Tab.UserID != GetCurrentUserID()) { return(false); } data.RSSItems.DeleteOnSubmit(item); data.SubmitChanges(); } catch { result = false; } finally { } return(result); }
// 0 - successful // 1 - existed // 2 - incorrect link // 3 - Different onwer // 4 - failed public int AddRSSItem(int tabid, string rsslink) { int result = 0; try { if (IsExist(rsslink, tabid)) { result = 1; return(result); } string nameStr = ""; string descriptionStr = ""; if (!IsValid(rsslink, ref nameStr, ref descriptionStr)) { result = 2; return(result); } RSSDBDataContext data = new RSSDBDataContext(); Tab tabToInsert = (from tab in data.Tabs where tab.ID == tabid select tab).Single(); if (tabToInsert.UserID != GetCurrentUserID()) { return(3); } RSSItem newRssItem = new RSSItem(); newRssItem.Name = nameStr; newRssItem.Description = descriptionStr; newRssItem.RSSLink = rsslink; newRssItem.TabID = tabid; newRssItem.PluginID = null; tabToInsert.RSSItems.Add(newRssItem); data.SubmitChanges(); } catch { result = 4; } finally { } return(result); }
public int AddRSSItem(int tabid, string rsslink) { int result = 0; try { if (IsExist(rsslink, tabid)) { result = 1; return result; } string nameStr = ""; string descriptionStr = ""; if (!IsValid(rsslink, ref nameStr, ref descriptionStr)) { result = 2; return result; } RSSDBDataContext data = new RSSDBDataContext(); Tab tabToInsert = (from tab in data.Tabs where tab.ID == tabid select tab).Single(); if (tabToInsert.UserID != GetCurrentUserID()) return 3; RSSItem newRssItem = new RSSItem(); newRssItem.Name = nameStr; newRssItem.Description = descriptionStr; newRssItem.RSSLink = rsslink; newRssItem.TabID = tabid; newRssItem.PluginID = null; tabToInsert.RSSItems.Add(newRssItem); data.SubmitChanges(); } catch { result = 4; } finally { } return result; }
// 0 - successful // 1 - existed // 2 - tab not exist // 3 - Different onwer // 4 - plugin not exist // 5 - failed public int AddRSSItemWithPlugin(int tabid, int pluginID) { int result = 5; try { RSSDBDataContext data = new RSSDBDataContext(); List <Tab> tabs = (from tab in data.Tabs where tab.ID == tabid select tab).ToList(); if (tabs.Count == 0) { return(2); } Tab tabToAdd = tabs[0]; if (tabToAdd.UserID != GetCurrentUserID()) { return(3); } List <RSSPlugin> plugins = (from plu in data.RSSPlugins where plu.ID == pluginID select plu).ToList(); if (plugins.Count == 0) { return(4); } RSSPlugin plugin = plugins[0]; //Kiểm tra đã tồn tại plugin trong tab hay chưa for (int i = 0; i < tabToAdd.RSSItems.Count; i++) { if (tabToAdd.RSSItems[i].PluginID == pluginID) { return(1); } } //--------------------------------------------------------------------------- string[] fileNames = Directory.GetFiles(Server.MapPath("~") + @"\bin", plugin.DLLName); foreach (string fileName in fileNames) { Assembly asm = Assembly.LoadFile(fileName); Type[] types = asm.GetTypes(); foreach (Type type in types) { if (type.GetInterface("IRSSPlugin") != null) { IRSSPlugin pluginObject = Activator.CreateInstance(type) as IRSSPlugin; RSSItem newItem = new RSSItem(); newItem.Name = pluginObject.GetRSSName(); newItem.Description = pluginObject.GetRSSDescription(); newItem.RSSLink = pluginObject.GetRSSWebsiteLink(); newItem.TabID = tabid; newItem.PluginID = plugin.ID; data.RSSItems.InsertOnSubmit(newItem); data.SubmitChanges(); result = 0; } } } } catch { result = 5; } finally { } return(result); }
public string GetRSSResult(int rssid, int count) { string resultStr = ""; try { RSSDBDataContext data = new RSSDBDataContext(); List <RSSItem> items = (from rssitem in data.RSSItems where rssitem.ID == rssid select rssitem).ToList(); if (items.Count == 0) { return(CreateXmlErrorMessage("Error!", "Not exist RSSItem with ID = " + rssid.ToString())); } RSSItem item = items[0]; //kiểm tra bool test_1 = true; bool test_2 = true; int currentUserID = GetCurrentUserID(); if (item.Tab.UserID != currentUserID) { test_1 = false; } int tabParentID = item.TabID; List <Share> listOfShare_test = (from share in data.Shares where share.TabID == tabParentID && share.AccountID == currentUserID select share).ToList(); if (listOfShare_test.Count == 0) { test_2 = false; } if (!test_1 && !test_2) { return(CreateXmlErrorMessage("Error!", "Permission Denied")); } //------------------------------------------------------ if (item.PluginID == null) { string rssLink = item.RSSLink; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(rssLink); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); XmlDocument doc = new XmlDocument(); doc.LoadXml(reader.ReadToEnd()); XmlNode rssNode = doc.DocumentElement.SelectSingleNode("//rss"); XmlNode channelNode = rssNode.SelectSingleNode("./channel"); XmlNodeList listOfItemnNode = channelNode.SelectNodes(".//item"); int nItemNode = listOfItemnNode.Count; for (int i = count; i < nItemNode; i++) { if (i < 0) { continue; } channelNode.RemoveChild(listOfItemnNode[i]); } resultStr = doc.OuterXml; } else { List <RSSPlugin> itemPlugins = (from plu in data.RSSPlugins where plu.ID == item.PluginID select plu).ToList(); if (itemPlugins.Count == 0) { return(CreateXmlErrorMessage("Error!", "Not exist RSSItem with ID = " + rssid.ToString())); } RSSPlugin itemPlugin = itemPlugins[0]; string[] fileNames = Directory.GetFiles(Server.MapPath("~") + @"\bin", itemPlugin.DLLName); foreach (string fileName in fileNames) { Assembly asm = Assembly.LoadFile(fileName); Type[] types = asm.GetTypes(); foreach (Type type in types) { if (type.GetInterface("IRSSPlugin") != null) { IRSSPlugin pluginObject = Activator.CreateInstance(type) as IRSSPlugin; return(pluginObject.GetRSSResult(count)); } } } } } catch { return(CreateXmlErrorMessage("Error!", "Some thing wrong" + rssid.ToString())); } finally { } return(resultStr); }
private void detach_RSSItems(RSSItem entity) { this.SendPropertyChanging(); entity.RSSPlugin = null; }
private void attach_RSSItems(RSSItem entity) { this.SendPropertyChanging(); entity.RSSPlugin = this; }
partial void DeleteRSSItem(RSSItem instance);
partial void UpdateRSSItem(RSSItem instance);
partial void InsertRSSItem(RSSItem instance);
public int AddRSSItemWithPlugin(int tabid, int pluginID) { int result = 5; try { RSSDBDataContext data = new RSSDBDataContext (); List<Tab> tabs = (from tab in data.Tabs where tab.ID == tabid select tab).ToList(); if (tabs.Count == 0) return 2; Tab tabToAdd = tabs[0]; if (tabToAdd.UserID != GetCurrentUserID()) return 3; List<RSSPlugin> plugins = (from plu in data.RSSPlugins where plu.ID == pluginID select plu).ToList(); if (plugins.Count == 0) return 4; RSSPlugin plugin = plugins[0]; //Kiểm tra đã tồn tại plugin trong tab hay chưa for (int i = 0; i < tabToAdd.RSSItems.Count; i++) { if (tabToAdd.RSSItems[i].PluginID == pluginID) return 1; } //--------------------------------------------------------------------------- string[] fileNames = Directory.GetFiles(Server.MapPath("~") + @"\bin", plugin.DLLName); foreach (string fileName in fileNames) { Assembly asm = Assembly.LoadFile(fileName); Type[] types = asm.GetTypes(); foreach (Type type in types) { if (type.GetInterface("IRSSPlugin") != null) { IRSSPlugin pluginObject = Activator.CreateInstance(type) as IRSSPlugin; RSSItem newItem = new RSSItem(); newItem.Name = pluginObject.GetRSSName(); newItem.Description = pluginObject.GetRSSDescription(); newItem.RSSLink = pluginObject.GetRSSWebsiteLink(); newItem.TabID = tabid; newItem.PluginID = plugin.ID; data.RSSItems.InsertOnSubmit(newItem); data.SubmitChanges(); result = 0; } } } } catch { result = 5; } finally { } return result; }