Esempio n. 1
0
 protected void btnVerify_Click(object sender, System.EventArgs e)
 {
     try
     {
         this._feed = this._remoteContentModule.VerifyFeed(this.txtUrl.Text);
         BindFeed();
         this.btnSave.Enabled = true;
         base.ShowMessage("Feed is valid");
     }
     catch (Exception ex)
     {
         this.btnSave.Enabled = false;
         base.ShowError(ex.Message);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Delete a Feed.
 /// </summary>
 /// <param name="feed"></param>
 public void DeleteFeed(Feed feed)
 {
     ITransaction tx = base.NHSession.BeginTransaction();
     try
     {
         base.NHSession.Delete(feed);
         tx.Commit();
     }
     catch (Exception ex)
     {
         tx.Rollback();
         throw new Exception("Unable to delete Feed", ex);
     }
 }
Esempio n. 3
0
 private void UpdateFeed(ISession session, RemoteContentModule module, Feed feed)
 {
     using (ITransaction tx = session.BeginTransaction())
     {
         try
         {
             session.Lock(feed, LockMode.None);
             module.RefreshFeedContents(feed);
             session.Update(feed);
             tx.Commit();
         }
         catch
         {
             tx.Rollback();
             throw;
         }
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="feed"></param>
 /// <param name="session"></param>
 public FeedFetcher(Feed feed, ISession session)
 {
     this._feed = feed;
     this._session = session;
 }
Esempio n. 5
0
 /// <summary>
 /// Create a Feed object from XML content.
 /// </summary>
 /// <param name="doc"></param>
 /// <param name="feedUrl"></param>
 /// <returns></returns>
 private Feed XmlContentToFeed(XmlDocument doc, string feedUrl)
 {
     Feed feed = new Feed();
     feed.Url = feedUrl;
     feed.Title = doc.SelectSingleNode("//channel/title").InnerText;
     return feed;
 }
Esempio n. 6
0
 private void SaveFeed(Feed feed, ISession session)
 {
     // First check if the pubdate exists. If not, use DateTime.Now.
     if (feed.PubDate == DateTime.MinValue)
     {
         feed.PubDate = DateTime.Now;
     }
     ITransaction tx = session.BeginTransaction();
     try
     {
         session.SaveOrUpdate(feed);
         tx.Commit();
     }
     catch (Exception ex)
     {
         tx.Rollback();
         throw new Exception("Unable to save Feed", ex);
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Save a Feed.
 /// </summary>
 /// <param name="feed"></param>
 public void SaveFeed(Feed feed)
 {
     // uses the ISession from the HttpContext
     SaveFeed(feed, base.NHSession);
 }
Esempio n. 8
0
        /// <summary>
        /// Refresh the items of a single feed. It doesn't save the new items!
        /// </summary>
        /// <param name="feed"></param>
        public void RefreshFeedContents(Feed feed)
        {
            feed.FeedItems.Clear();
            try
            {
                XmlDocument doc = GetFeedXml(feed.Url);
                // Create an XmlNamespaceManager for resolving namespaces.
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
                nsmgr.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");

                XmlNodeList xmlItems = doc.SelectNodes("//channel/item");
                foreach (XmlNode xmlItem in xmlItems)
                {
                    FeedItem feedItem = new FeedItem();
                    // Truncate title to 100 characters
                    string title = xmlItem.SelectSingleNode("title").InnerText;
                    if (title.Length > 100)
                    {
                        title = title.Substring(0, 100);
                    }
                    feedItem.Title = title;
                    feedItem.Url = xmlItem.SelectSingleNode("link").InnerText;

                    if (xmlItem.SelectSingleNode("pubDate") != null)
                    {
                        feedItem.PubDate = RFC2822Date.Parse(xmlItem.SelectSingleNode("pubDate").InnerText);
                    }
                    else
                    {
                        feedItem.PubDate = DateTime.Now;
                    }
                    if (this._showContents && xmlItem.SelectSingleNode("description") != null)
                    {
                        feedItem.Content = xmlItem.SelectSingleNode("description").InnerText;
                    }
                    if (xmlItem.SelectSingleNode("author", nsmgr) != null)
                    {
                        feedItem.Author = xmlItem.SelectSingleNode("author", nsmgr).InnerText;
                    }
                    else if (xmlItem.SelectSingleNode("dc:creator", nsmgr) != null)
                    {
                        feedItem.Author = xmlItem.SelectSingleNode("dc:creator", nsmgr).InnerText;
                    }
                    feedItem.Feed = feed;
                    feed.FeedItems.Add(feedItem);
                }
                feed.SortAndFilter();
            }
            catch (Exception ex)
            {
                log.Error("Error refreshing feed contents for: " + feed.Title, ex);
                throw;
            }
        }
Esempio n. 9
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            this._remoteContentModule = base.Module as RemoteContentModule;
            this.btnCancel.Attributes.Add("onclick", String.Format("document.location.href='AdminRemoteContent.aspx{0}'", base.GetBaseQueryString()));

            if (Request.QueryString["FeedId"] != null)
            {
                int feedId = Int32.Parse(Request.QueryString["FeedId"]);
                if (feedId > 0)
                {
                    this._feed = this._remoteContentModule.GetFeedById(feedId);
                    if (! this.IsPostBack)
                    {
                        BindFeed();
                    }
                    this.btnSave.Enabled = true;
                    this.btnDelete.Visible = true;
                    this.btnDelete.Attributes.Add("onclick", "return confirm('Are you sure?');");
                }
                else
                {
                    this._feed = new Feed();
                    this.btnSave.Enabled = false;
                }
            }
        }