示例#1
0
        public DebugArticle(Article a)
        {
            source = a;

            InitializeComponent();

            articleTitleLabel.Text = a.Title;

            articleContentTextBox.Text = a.Content;

            articleUriLinkLabel.Text = a.Uri.ToString();

            TimeSpan diff = DateTime.Now.Subtract(a.CreationTime);
            string creationTimeString = string.Format("Article créé il y a {0} minute(s), le {1}, à {2}.",
                diff.TotalMinutes.ToString(),
                a.CreationTime.ToShortDateString(),
                a.CreationTime.ToShortTimeString());
            creationDateTimeLabel.Text = creationTimeString;

            pushedCounterLabel.Text = string.Format("Article poussé {0} fois dans la base de données.", a.PushCounter);

            viewCounterLabel.Text = string.Format("Article affiché {0} fois.", a.ViewCounter);

            clickCounterLabel.Text = string.Format("Lien cliqué {0} fois.", a.ClickCounter);
        }
示例#2
0
        public RegularArticlePanel(IControllerPlugin ctrl, Article a)
            : base(ctrl, a)
        {
            InitializeComponent();

            if (a.IsNew()==true )
            {
                BackColor = plugins.Default.EmphasizedBackColor;
            }

            splitContainer1.Panel2.BackColor = plugins.Default.MouseOverArticleBackColor;
            splitContainer1.Panel2Collapsed = true;

            TextControl titleControl = new TextControl( Toolkit.UnHTML(a.Title) );
            titleControl.Dock = DockStyle.Fill;
            titleControl.MouseEnter += new EventHandler(titleControl_MouseEnter);
            titleControl.MouseClick += new MouseEventHandler(TextControl_MouseClick);
            splitContainer1.Panel1.Controls.Add(titleControl);

            TextControl contentControl = new TextControl( Toolkit.UnHTML(a.Content) );
            contentControl.Cursor = Cursors.Hand;
            contentControl.Dock = DockStyle.Fill;
            contentControl.MouseLeave += new EventHandler(contentControl_MouseLeave);
            contentControl.MouseClick += new MouseEventHandler(TextControl_MouseClick);
            splitContainer1.Panel2.Controls.Add(contentControl);

            mediaControl = MediaControl.Get();
            mediaControl.Dock = DockStyle.Fill;
            panel1.Controls.Add(mediaControl);

            Resize += new EventHandler(RegularArticlePanel_Resize);
            RegularArticlePanel_Load(null, EventArgs.Empty);
        }
示例#3
0
 protected override Article CreateArticle(Site s, XPathNavigator navigator)
 {
     Article output = new Article(s.Guid);
     UpdateTitle(output, navigator);
     UpdateContent(output, navigator);
     UpdateUri(output, navigator);
     UpdateMedias(output, navigator);
     return output;
 }
示例#4
0
 private void Update(TreeNode tn, Article a)
 {
     tn.Text = a.Title;
     Touch(tn, a);
 }
示例#5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="a"></param>
        /// <param name="navigator"></param>
        /// <param name="expression"></param>
        /// <returns>Returns a reference to the Media that has been pushed into the database, or null
        /// if no Media has been created as a main media for the Article</returns>
        private Media TryUpdateMedia(Article a, XPathNavigator navigator, string[] patterns)
        {
            Database database = Database.GetInstance();

            try
            {
                string mediaUri = null;

                foreach (string pattern in patterns)
                {
                    try
                    {
                        mediaUri = XmlFetcher.GetSingleValue(navigator, pattern, xmlnsManager);
                        break;
                    }
                    catch
                    {
                        mediaUri = null;
                    }
                }

                if(string.IsNullOrEmpty(mediaUri))
                {
                    return null;
                }

                Console.WriteLine("   MEDIA= {0}", mediaUri);

                Media media = new Media();
                media.Uri = new Uri(mediaUri);
                media = database.Push(media);
                a.Media = media.Guid;
                return media;
            }
            catch (ArgumentException)
            {
                return null;
            }
        }
示例#6
0
 public void Add(Article a)
 {
     articles.Add(a);
 }
示例#7
0
 internal bool Contains(Article a)
 {
     return articles.Contains(a);
 }
示例#8
0
 private Article(Article src)
     : base(src)
 {
     Update(src);
 }
示例#9
0
        public bool IsSimilarTo(Article a)
        {
            if (this.Site != a.Site)
            {
                throw new ArgumentException();
            }

            if (string.Compare(this.title, a.title) == 0)
            {
                if (Toolkit.Equals(this.uri, a.uri) == true)
                {
                    return true;
                }
            }

            return false;
        }
示例#10
0
        private void UpdateUri(Article a, XPathNavigator navigator)
        {
            string[] patterns = new string[]
            {
                "./atom:link[@rel='alternate']/@href", // atom
                "./atom:link/@href", // atom
                "./link",   // rss
            };

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

            foreach (string pattern in patterns)
            {
                try
                {
                    a.Title = XmlFetcher.GetSingleValue(navigator, pattern, xmlnsManager);
                    Console.WriteLine(">> TITLE= {0}", a.Title);
                    return;
                }
                catch
                {
                }
            }
        }
示例#12
0
        private void UpdateMedias(Article a, XPathNavigator navigator)
        {
            Media thumbnail = null;
            Media media = null;

            // Try obtaining URL to a thumbnail
            // that accompanies the Article

            thumbnail = TryUpdateThumbnail(a, navigator, ThumbnailPatterns);

            // Try to obtain a URL to a media
            // that accompanies the Article

            media = TryUpdateMedia(a, navigator, MediaPatterns);
            /*if (media == null)
            {
                media = TryUpdateMedia(a, navigator, "./enclosure/@url");
            }*/

            // Tweak priorities:
            // If the Article has no thumbnail, but has a main media,
            // and if that main media is an image, set the Priority
            // flag to accelerate the download.
            if( (thumbnail==null) && (media!=null) )
            {
                if (media.Type == Media.MediaType.IMAGE)
                {
                    media.Priority = true;
                }
            }
        }
示例#13
0
        private void UpdateContent(Article a, XPathNavigator navigator)
        {
            string[] patterns = new string[]
            {
                "./description", // rss
                "./atom:summary" // atom
            };

            foreach (string pattern in patterns)
            {
                try
                {
                    a.Content = XmlFetcher.GetSingleValue(navigator, pattern, xmlnsManager);
                    return;
                }
                catch
                {
                }
            }
        }
示例#14
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="a"></param>
        /// <param name="navigator"></param>
        /// <param name="expression"></param>
        /// <returns>Returns a reference to the Media that has been pushed into the database, or null
        /// if no Media has been created as a thumbnail for the Article.</returns>
        private Media TryUpdateThumbnail(Article a, XPathNavigator navigator, string[] patterns)
        {
            Database database = Database.GetInstance();

            try
            {
                string thumbnailUri = null;

                foreach (string pattern in patterns)
                {
                    try
                    {
                        thumbnailUri = XmlFetcher.GetSingleValue(navigator, pattern, xmlnsManager);
                        break;
                    }
                    catch
                    {
                        thumbnailUri = null;
                    }
                }

                if (string.IsNullOrEmpty(thumbnailUri))
                {
                    return null;
                }

                Console.WriteLine("   THUMB= {0}", thumbnailUri);

                Media thumbnail = new Media();
                thumbnail.Uri = new Uri(thumbnailUri);
                thumbnail.Priority = true;
                thumbnail = database.Push(thumbnail);
                a.Thumbnail = thumbnail.Guid;
                return thumbnail;
            }
            catch (ArgumentException)
            {
                return null;
            }
        }
示例#15
0
文件: Site.cs 项目: nnovic/GetFacts
        /// <summary>
        /// Returns true if the specified Article is new,
        /// with regards to the configuration of this Site.
        /// </summary>
        /// <param name="a"></param>
        /// <returns></returns>
        public bool IsNew(Article a)
        {
            bool isNew = false;

            // the article is new if it is
            // less than 3 hours old
            TimeSpan diff = DateTime.Now.Subtract(a.CreationTime);
            isNew |= (diff.TotalMinutes < 3*60);

            // or if it has never been seen
            // by the user
            isNew |= (a.ViewCounter <= 1);

            // but the article is not new anymore
            // if it has been clicked
            isNew &= (a.ClickCounter == 0);

            return isNew;
        }
示例#16
0
文件: Site.cs 项目: nnovic/GetFacts
        /// <summary>
        /// Returns true if the specified Article is old,
        /// with regards to the configuration of this Site.
        /// </summary>
        /// <param name="a"></param>
        /// <returns></returns>
        public bool IsOld(Article a)
        {
            bool isOld = false;

            // the article is old if it is
            // more than 8 hours old
            TimeSpan diff = DateTime.Now.Subtract(a.CreationTime);
            isOld |= (diff.TotalMinutes > 8 * 60);

            return isOld;
        }
示例#17
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;
        }
示例#18
0
        /// <summary>
        /// Updates the content of this article with
        /// the content of the article specified in argument.
        /// </summary>
        /// <param name="fp"></param>
        /// <returns>true is any field in this article has been changed because of the update. false otherwise (implies that this article and the one in argument have similar content).</returns>
        public bool Update(Article a)
        {
            bool output = false;

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

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

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

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

            if(this.thumbnail != a.thumbnail)
            {
                this.thumbnail = a.thumbnail;
                output = true;
            }

            if (this.media != a.media)
            {
                this.media = a.media;
                output = true;
            }

            return output;
        }
示例#19
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);
                        }
                    }
                }
            }
        }
示例#20
0
 public object Clone()
 {
     Article output = new Article(this);
     return output;
 }
示例#21
0
 private Article TouchOrUpdate(Article newA)
 {
     FrontPage fp = FindFrontPage(newA.Site);
     Article a = FindOrAdd(fp, newA);
     if (a.Update(newA) == true)
     {
         if (ArticleUpdated != null)
         {
             ArticleUpdated(a, EventArgs.Empty);
         }
     }
     else
     {
         if (ArticleTouched != null)
         {
             ArticleTouched(a, EventArgs.Empty);
         }
     }
     return a;
 }
示例#22
0
 internal bool Remove(Article a)
 {
     return articles.Remove(a);
 }
示例#23
0
        private void DisplayArticle(Article a)
        {
            if( articlesSplitContainer.Panel2.Controls.Count==1)
            {
                Control old = articlesSplitContainer.Panel2.Controls[0];
                articlesSplitContainer.Panel2.Controls.Clear();
                old.Dispose();
            }

            if (a != null)
            {
                DebugArticle p = new DebugArticle(a);
                p.Dock = DockStyle.Fill;
                articlesSplitContainer.Panel2.Controls.Add(p);
            }
        }
示例#24
0
        private TreeNode FindOrCreateNode(Article a)
        {
            TreeNode siteNode = FindOrCreateRoot(a.Site);
            TreeNode frontPageNode = siteNode.Nodes[0];

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

            TreeNode newTn = new TreeNode();
            newTn.Tag = a.Guid;
            Update(newTn, a);
            //newTn.ImageKey = "article.png";
            //newTn.SelectedImageKey = "article.png";
            frontPageNode.Nodes.Add(newTn);

            return newTn;
        }
示例#25
0
 private void Touch(TreeNode tn, Article a)
 {
     Site s = FindSite(a.Site);
     if (s == null)
     {
         tn.ImageKey = "article_removed.png";
     }
     else if (s.IsNew(a) == true)
     {
         tn.ImageKey = "article_new.png";
     }
     else if (s.IsOld(a) == true)
     {
         tn.ImageKey = "article_old.png";
     }
     else
     {
         tn.ImageKey = "article.png";
     }
     tn.SelectedImageKey = tn.ImageKey;
 }
示例#26
0
 public ArticleControl(IControllerPlugin ctrl, Article a)
 {
     controller = ctrl;
     article = a;
 }
示例#27
0
 public static Site FindSiteOf(Article a)
 {
     return FindSite(a.Site);
 }