示例#1
0
        /// <summary>
        /// Analyze the content of the XML data freshly fetched from
        /// the Site and return a FrontPage filled with all the required information.
        /// The method does not process the Articles.
        /// </summary>
        /// <param name="s">The Site from which the XML data has been collected</param>
        /// <param name="navigator">The XPathNavigator set to explore the XML data</param>
        /// <returns>A fully filled FrontPage object, without Articles.</returns>
        protected override FrontPage CreateFrontPage(Site s, XPathNavigator navigator)
        {
            // Create the front page with the default values
            FrontPage output = new FrontPage(s.Guid);

            UpdateTitle(output, navigator);
            UpdateCaption(output, navigator);
            UpdateUri(output, navigator);

            return output;
        }
示例#2
0
        public RegularFrontPagePanel(FrontPage fp)
        {
            frontPage = fp;

            InitializeComponent();

            titleControl.Text = fp.Title;
            captionControl.Text = fp.Caption;

            SizeChanged += RegularFrontPagePanel_SizeChanged;
            Disposed += RegularFrontPagePanel_Disposed;
        }
示例#3
0
        /// <summary>
        /// Updates the content of this front page with
        /// the content of the front page specified in argument.
        /// Warning: the articles are not procesed.
        /// </summary>
        /// <param name="fp"></param>
        /// <returns>true is any field in this frontpage has been changed because of the update. false otherwise (implies that this front page and the one in argument has similar content).</returns>
        public bool Update(FrontPage fp)
        {
            bool output = false;

            if (this.Site != fp.Site)
            {
                throw new ArgumentException();
            }

            if (string.Compare(this.title, fp.title) != 0)
            {
                this.title = fp.title;
                output = true;
            }

            if (string.Compare(this.caption, fp.caption) != 0)
            {
                this.caption = fp.caption;
                output = true;
            }

            if (Toolkit.Equals(this.uri, fp.uri)==false)
            {
                this.uri = fp.uri;
                output = true;
            }

            return output;
        }
示例#4
0
 public bool IsSimilarTo(FrontPage fp)
 {
     return this.Site == fp.Site;
 }
示例#5
0
 private void Update(TreeNode tn, FrontPage fp)
 {
     StringBuilder text = new StringBuilder();
     text.Append(fp.Title);
     if (string.IsNullOrEmpty(fp.Caption) == false)
     {
         text.AppendFormat(" [{0}]",  fp.Caption);
     }
     tn.Text = text.ToString();
     Touch(tn, fp);
 }
示例#6
0
 private void Touch(TreeNode tn, FrontPage fp)
 {
 }
示例#7
0
        private TreeNode FindOrCreateNode(FrontPage fp)
        {
            TreeNode siteNode = FindOrCreateRoot(fp.Site);

            foreach (TreeNode tn in siteNode.Nodes)
            {
                Guid id = (Guid)tn.Tag;
                if (id.CompareTo(fp.Guid) == 0)
                {
                    return tn;
                }
            }

            TreeNode newTn = new TreeNode();
            Update(newTn, fp);
            newTn.Tag = fp.Guid;
            newTn.ImageKey = "frontpage.png";
            newTn.SelectedImageKey = "frontpage.png";
            siteNode.Nodes.Add(newTn);

            return newTn;
        }
示例#8
0
 private FrontPage TouchOrUpdate(FrontPage newFp)
 {
     FrontPage fp = FindOrAdd(newFp);
     if (fp.Update(newFp) == true)
     {
         if (FrontPageUpdated != null)
         {
             FrontPageUpdated(fp, EventArgs.Empty);
         }
     }
     else
     {
         if (FrontPageTouched != null)
         {
             FrontPageTouched(fp, EventArgs.Empty);
         }
     }
     return fp;
 }
示例#9
0
 public static Site FindSiteOf(FrontPage fp)
 {
     return FindSite(fp.Site);
 }
示例#10
0
        /// <summary>
        /// Check in the database if an article similar to "newA"
        /// already exists. If the answer is "yes", then the article
        /// from the database is returned. If the answer is "no", then
        /// the provided article is added into the database and returned
        /// to the caller.
        /// </summary>
        /// <param name="fp"></param>
        /// <param name="newA"></param>
        /// <returns></returns>
        private Article FindOrAdd(FrontPage fp, Article newA)
        {
            foreach (Article a in fp.Articles)
            {
                if (a.IsSimilarTo(newA) == true)
                {
                    return a;
                }
            }

            newA = (Article)newA.Clone();
            fp.Add(newA);
            if (ArticleAdded != null)
            {
                ArticleAdded(newA, EventArgs.Empty);
            }
            return newA;
        }
示例#11
0
        /// <summary>
        /// Check in the database if a front page similar to "newFp"
        /// already exists. If the answer is "yes", then the front page
        /// from the database is returned. If the answer is "no", then
        /// the provided frontpage is added into the database and returned
        /// to the caller.
        /// </summary>
        /// <param name="fp"></param>
        /// <returns></returns>
        private FrontPage FindOrAdd(FrontPage newFp)
        {
            foreach (FrontPage fp in frontPages)
            {
                if( fp.IsSimilarTo(newFp) == true )
                {
                    return fp;
                }
            }

            newFp = (FrontPage)newFp.Clone();
            frontPages.Add(newFp);
            if (FrontPageAdded != null)
            {
                FrontPageAdded(newFp, EventArgs.Empty);
            }
            return newFp;
        }
示例#12
0
        private void Backup(FrontPage fp, XmlTextWriter w)
        {
            w.WriteStartElement("site");
            w.WriteAttributeString("guid", fp.Site.ToString());

            // FRONT PAGE

            fp.ToXML(w);

            // ARTICLES

            foreach (Article a in fp.Articles)
            {
                a.ToXML(w);
            }
            w.WriteEndElement();
        }
示例#13
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="newFp"></param>
        /// <returns>A list of articles (withing the given frontpage) that have not been updated or touched.</returns>
        public List<Article> Push(FrontPage newFp)
        {
            List<Article> untouched = new List<Article>();

            lock (_lock_)
            {
                //- - - - - - - - - - - - -
                // PUSH/UPDATE FRONT PAGE
                //- - - - - - - - - - - - -

                FrontPage fp = TouchOrUpdate(newFp);
                fp.Pushed();

                //- - - - - - - - - - - -
                // PUSH/UPDATE ARTICLES
                //- - - - - - - - - - - -

                untouched.AddRange(fp.Articles);

                foreach (Article newA in newFp.Articles)
                {
                    Article a = TouchOrUpdate(newA);
                    a.Pushed();
                    untouched.Remove(a);
                }
            }

            return untouched;
        }
示例#14
0
        private void UpdateUri(FrontPage fp, XPathNavigator navigator)
        {
            string[] patterns = new string[]
            {
                "/rss/channel/link", // rss
                "/atom:feed/atom:link/@href" // atom
            };

            foreach (string pattern in patterns)
            {
                try
                {
                    fp.Uri = new Uri(XmlFetcher.GetSingleValue(navigator, pattern, xmlnsManager));
                    return;
                }
                catch
                {
                }
            }
        }
示例#15
0
        private void UpdateTitle(FrontPage fp, XPathNavigator navigator)
        {
            string[] patterns = new string[]
            {
                "/rss/channel/title", // rss
                "/atom:feed/atom:title" // atom
            };

            foreach (string pattern in patterns)
            {
                try
                {
                    fp.Title = XmlFetcher.GetSingleValue(navigator, pattern, xmlnsManager);
                    return;
                }
                catch
                {
                }
            }
        }
示例#16
0
 private FrontPage(FrontPage src)
     : base(src)
 {
     Update(src);
 }
示例#17
0
 /// <summary>
 /// Warning: does not clone the list of articles (and that's made on purpose!)
 /// </summary>
 /// <returns></returns>
 public object Clone()
 {
     FrontPage clone = new FrontPage(this);
     //clone.Update(this);
     return clone;
 }
示例#18
0
        private void LoadSite(Guid siteId, XmlReader input)
        {
            while (input.Read())
            {
                if (input.NodeType == XmlNodeType.Element)
                {
                    if (input.Name == "frontpage")
                    {
                        using (XmlReader subTree = input.ReadSubtree())
                        {
                            FrontPage newFp = new FrontPage(siteId, subTree);
                            TouchOrUpdate(newFp);
                        }
                    }

                    else if (input.Name == "article")
                    {
                        using (XmlReader subTree = input.ReadSubtree())
                        {
                            Article a = new Article(siteId, subTree);
                            TouchOrUpdate(a);
                        }
                    }
                }
            }
        }