public static bool SaveUpdateMail(GNFeedItem item, bool IsPubDate, decimal PollTime, int Action)
 {
     //Write Code for Save Update Feeds in db.
     return true;
 }
Example #2
0
        public static void GetTwitterFeedsAsList(string url, int FeedId, int FeedType)
        {
            try
            {
                DateTime dt1 = DateTime.Now;
                string screenName = string.Empty;
                string userName = string.Empty;
                string json = GetTwitterFeedAsJSon(url);
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                dynamic items = serializer.Deserialize<object>(json);
                DateTime dt2 = DateTime.Now;
                TimeSpan ts = dt2 - dt1;
                decimal PollTime = Math.Round(Convert.ToDecimal(ts.TotalMilliseconds), 2);
                int Counter = 0;
                foreach (Dictionary<string, object> feedItem in items)
                {
                    GNFeedItem row = new GNFeedItem();
                    Dictionary<string, object> user = (Dictionary<string, object>)feedItem["user"];
                    screenName = user["screen_name"].ToString();
                    userName = user["name"].ToString();
                    string statusId = feedItem["id"].ToString();
                    row.URL = Utility.TwitterLink + screenName + "/statuses/" + statusId;
                    row.Title = Convert.IsDBNull(feedItem["text"]) ? "" : (string)feedItem["text"];
                    row.Summary = row.Title;
                    row.FeedId = FeedId;
                    row.InsertTime = DateTime.Now;
                    row.PublishDate = DateTime.Today;
                    bool IsPubDate = false;
                    if (!Convert.IsDBNull(feedItem["created_at"]))
                    {
                        DateTime PubDate = DateTime.Today;
                        bool check = DateTime.TryParseExact(feedItem["created_at"].ToString(), Utility.TwitterDateFormate, CultureInfo.InvariantCulture, DateTimeStyles.None, out PubDate);
                        if (!check)
                            check = FeedDate.TryParseDateTime(feedItem["created_at"].ToString(), out PubDate);
                        if (check)
                        {
                            row.PublishDate = PubDate;
                            IsPubDate = true;
                        }
                    }
                    if (Counter > 0)
                        PollTime = 0;
                    if (row.PublishDate >= DateTime.Now.AddDays(-3))
                    {
                        FeedOperations.SaveUpdateMail(row, IsPubDate, PollTime, FeedType);
                        Counter++;
                    }
                }

            }
            catch (Exception ex)
            {
                FeedOperations.UpdateFeedFailure(FeedId, ex.Message);
            }
        }
Example #3
0
 public static GNFeedList ParseXMLDocument(XmlDocument doc)
 {
     var objCraiglistFeed = new GNFeedList();
     bool IsPubDate = false;
     XmlNodeList nodeLists = doc.GetElementsByTagName("rss");
     foreach (XmlNode node in nodeLists)
     {
         foreach (XmlNode chielNode in node.ChildNodes)
         {
             if (chielNode.Name == "channel")
             {
                 objCraiglistFeed.Title = chielNode.InnerText;
                 foreach (XmlNode cchieNode in chielNode.ChildNodes)
                 {
                     if (cchieNode.Name == "title")
                     {
                         objCraiglistFeed.Title = cchieNode.InnerText;
                     }
                     else if (cchieNode.Name == "description")
                     {
                         objCraiglistFeed.Description = cchieNode.InnerText;
                     }
                     else if (cchieNode.Name == "link")
                     {
                         //
                     }
                     else if (cchieNode.Name == "item")
                     {
                         GNFeedItem item = new GNFeedItem();
                         item.Title = string.Empty;
                         item.Summary = string.Empty;
                         item.URL = string.Empty;
                         item.InsertTime = DateTime.Now;
                         item.PublishDate = DateTime.Today;
                         foreach (XmlNode cchielNode in cchieNode.ChildNodes)
                         {
                             if (cchielNode.Name == "title")
                                 item.Title = cchielNode.InnerText;
                             else if (cchielNode.Name == "link")
                                 item.URL = cchielNode.InnerText;
                             else if (cchielNode.Name == "description")
                                 item.Summary = cchielNode.InnerText;
                             else if (cchielNode.Name == "content:encoded" && !string.IsNullOrEmpty(cchielNode.InnerText))
                                 item.Summary = cchielNode.InnerText;
                             else if (cchielNode.Name == "pubDate" || cchielNode.Name == "dc:date")
                             {
                                 if (!string.IsNullOrEmpty(cchielNode.InnerText))
                                 {
                                     DateTime PubDate = DateTime.Now;
                                     bool check = DateTime.TryParse(cchielNode.InnerText, null, DateTimeStyles.RoundtripKind, out PubDate);
                                     if (!check)
                                         check = FeedDate.TryParseDateTime(cchielNode.InnerText, out PubDate);
                                     if (check)
                                     {
                                         item.PublishDate = PubDate;
                                         IsPubDate = true;
                                     }
                                 }
                             }
                         }
                         objCraiglistFeed.itemList.Add(item);
                     }
                 }
             }
         }
     }
     objCraiglistFeed.IsPubDate = IsPubDate;
     return objCraiglistFeed;
 }
Example #4
0
        public static void GetFeedAsList(string rssUrl, int FeedId, int FeedType)
        {
            try
            {
                DateTime dt1 = DateTime.Now;
                IEnumerable<SyndicationItem> items;
                SyndicationFeed rareBookNews = SyndicationFeed.Load(XmlReader.Create(rssUrl));
                items = rareBookNews.Items;
                if (items != null && items.Count() > 0)
                {
                    DateTime dt2 = DateTime.Now;
                    TimeSpan ts = dt2 - dt1;
                    decimal PollTime = Math.Round(Convert.ToDecimal(ts.TotalMilliseconds), 2);
                    int Counter = 0;
                    foreach (SyndicationItem feed in items)
                    {
                        if (feed.SourceFeed == null || feed.SourceFeed.ToString() == string.Empty)
                        {
                            GNFeedItem row = new GNFeedItem();
                            row.URL = string.Empty;
                            if (feed.Links.Count > 0)
                                row.URL = feed.Links[0].Uri.ToString().Trim();
                            row.Title = string.Empty;
                            if (feed.Title != null)
                                row.Title = feed.Title.Text.Trim();
                            string feedSummary = string.Empty;
                            if (feed.Summary != null)
                                feedSummary = feed.Summary.Text;
                            if (string.IsNullOrEmpty(feedSummary) && feed.Content != null)
                            {
                                TextSyndicationContent cont = (TextSyndicationContent)feed.Content;
                                if (!string.IsNullOrEmpty(cont.Text))
                                    feedSummary = cont.Text;
                            }
                            row.Summary = feedSummary;
                            row.FeedId = FeedId;
                            row.InsertTime = DateTime.Now;
                            row.PublishDate = DateTime.Today;
                            bool IsPubDate = false;
                            if (!Convert.IsDBNull(feed.PublishDate.DateTime) && feed.PublishDate.DateTime > DateTime.MinValue)
                            {
                                row.PublishDate = feed.PublishDate.DateTime;
                                IsPubDate = true;
                            }
                            if (Counter > 0)
                                PollTime = 0;
                            if (row.PublishDate >= DateTime.Now.AddDays(-3))
                            {
                                FeedOperations.SaveUpdateMail(row, IsPubDate, PollTime, FeedType);
                                Counter++;
                            }
                        }
                    }

                }
            }
            catch (Exception ex)
            {
                FeedOperations.UpdateFeedFailure(FeedId, ex.Message);
            }
        }