Example #1
0
        // 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);
        }
Example #2
0
 partial void DeleteRSSPlugin(RSSPlugin instance);
Example #3
0
        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);
        }
Example #4
0
 partial void UpdateRSSPlugin(RSSPlugin instance);
Example #5
0
 partial void InsertRSSPlugin(RSSPlugin instance);
 partial void DeleteRSSPlugin(RSSPlugin instance);
 partial void UpdateRSSPlugin(RSSPlugin instance);
 partial void InsertRSSPlugin(RSSPlugin instance);