示例#1
0
        public string GetNewRSSFromTab(int tabid)
        {
            XmlDocument      resultXml = new XmlDocument();
            RSSDBDataContext dt        = new RSSDBDataContext();

            try
            {
                int        currentUserID  = GetCurrentUserID();
                List <Tab> listOfTab_test = (from tab in dt.Tabs
                                             where tab.ID == tabid && tab.UserID == currentUserID
                                             select tab).ToList();
                List <Share> listOfShare_test = (from share in dt.Shares
                                                 where share.TabID == tabid && share.AccountID == currentUserID
                                                 select share).ToList();
                if (listOfShare_test.Count == 0 && listOfTab_test.Count == 0)
                {
                    return(CreateXmlErrorMessage("Permission Error", "You are not allowed to view this tab"));
                }
                Tab _tabToCheck = dt.Tabs.Single(_s => _s.ID == tabid);
                List <XmlElement> itemElements = new List <XmlElement>();
                foreach (RSSItem rssitem in _tabToCheck.RSSItems)
                {
                    try
                    {
                        string response = GetRSSResult(rssitem.ID, 999);
                        response = response.Replace("pubdate", "pubDate");
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(response);
                        foreach (XmlElement element in doc.GetElementsByTagName("item"))
                        {
                            XmlElement  pubDate        = (XmlElement)element.GetElementsByTagName("pubDate").Item(0);
                            string      dateTimeString = pubDate.InnerText;
                            CultureInfo cultureInfo    = new CultureInfo("fr-FR", false);
                            DateTime    result         = new DateTime();

                            if (dateTimeString.Contains("SA") || dateTimeString.Contains("CH"))
                            {
                                dateTimeString = dateTimeString.Replace("SA", "AM").Replace("CH", "PM");
                                result         = DateTime.Parse(dateTimeString, cultureInfo);
                            }
                            else
                            {
                                result = DateTime.Parse(dateTimeString);
                            }
                            pubDate.InnerText = result.ToString();
                            itemElements.Add(element);
                        }
                    }
                    catch
                    {
                    }
                }

                var sorted = itemElements.OrderByDescending(c => DateTime.Parse(c.GetElementsByTagName("pubDate")[0].InnerText));
                itemElements = sorted.ToList();

                string title       = _tabToCheck.Name;
                string description = "All new from " + title + " tab";
                string link        = "/CoreService.asmx";
                resultXml.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?><rss version=\"2.0\"><channel><title>" + title + "</title><description>" + description + "</description><link>" + link + "</link></channel></rss>");

                XmlElement channel = (XmlElement)resultXml.DocumentElement.SelectNodes("channel")[0];
                if (itemElements.Count == 0)
                {
                    return(CreateXmlErrorMessage("Notification", "This tab is empty"));
                }
                int count = 0;
                foreach (XmlElement element in itemElements)
                {
                    XmlElement item = resultXml.CreateElement("item");
                    item.InnerXml = element.InnerXml;
                    channel.AppendChild(item);
                    count++;
                    if (count == 15)
                    {
                        break;
                    }
                }
            }
            catch
            {
                return(CreateXmlErrorMessage("Error!", "Not exist Tab that had ID = " + tabid.ToString()));
            }
            return(resultXml.InnerXml);
        }
        public int AddTab(string tabName)
        {
            int result = -1;
            try
            {
                RSSDBDataContext dt = new RSSDBDataContext();
                var tabs = dt.Tabs.Where(tab => tab.Name.CompareTo(tabName) == 0 && tab.UserID == GetCurrentUserID());
                if (tabs.Count<Tab>() == 0)
                {
                    int UserID = GetCurrentUserID();

                    Tab newTab = new Tab()
                    {
                        Name = tabName,
                        UserID = UserID,
                    };

                    dt.Tabs.InsertOnSubmit(newTab);
                    dt.SubmitChanges();

                    result = 0;
                }
                else
                {
                    result = 1;
                }
            }
            catch
            {
                result = 2;
            }
            finally
            {
            }

            return result;
        }
示例#3
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);
        }
 partial void DeleteTab(Tab instance);
 partial void UpdateTab(Tab instance);
 partial void InsertTab(Tab instance);
		private void detach_Tabs(Tab entity)
		{
			this.SendPropertyChanging();
			entity.Account = null;
		}
		private void attach_Tabs(Tab entity)
		{
			this.SendPropertyChanging();
			entity.Account = this;
		}