示例#1
0
文件: Page.cs 项目: nnovic/GetFacts
        private void Update(XPathNavigator nav)
        {
            BeginUpdate();

            UpdateInfo(nav, Template);

            // Si jamais la page n'a pas de titre à l'issu
            // de l'analyse, on propose le nom
            if (string.IsNullOrEmpty(this.Title))
            {
                this.Title = PageName;
            }

            foreach (SectionTemplate sectionTemplate in Template.Sections)
            {
                try
                {
                    foreach (XPathNavigator subTree in nav.Select(sectionTemplate.XPathFilter))
                    {
                        if (subTree == null)
                        {
                            continue;
                        }

                        string  configName = sectionTemplate.SectionName;
                        string  title      = sectionTemplate.TitleTemplate.Execute(subTree);
                        string  text       = sectionTemplate.TextTemplate.Execute(subTree);
                        Section s          = FindSection(configName, title, text);

                        if (s != null)
                        {
                            s.Update(subTree, sectionTemplate);
                        }
                    }
                }
                catch
                {
                    // ne pas bloquer la mise à jour des sections
                    // suivantes si une erreur s'est produite.
                }
            }

            EndUpdate();

            var notification = new NotificationSystem.Notification(this,
                                                                   (int)NotificationKeys.NoArticleInTheEntirePage)
            {
                Title       = PageName,
                Description = "No article has been found."
            };

            if (HasAnyArticle)
            {
                NotificationSystem.GetInstance().Remove(notification);
            }
            else
            {
                NotificationSystem.GetInstance().Add(notification);
            }
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="task"></param>
        /// <remarks>Ajoute une notification dans NotificationSystem en cas
        /// d'erreur durant l'obtention du flux d'entrée.</remarks>
        /// <seealso cref="NotificationKeys.CannotOpenConnection"/>
        private void OpenResponseStream(Task <WebResponse> task)
        {
            lock (_lock_)
            {
                var notification = new NotificationSystem.Notification(this,
                                                                       (int)NotificationKeys.CannotOpenConnection)
                {
                    Title       = Uri.ToString(),
                    Description = "Connection cannot be established."
                };


                switch (task.Status)
                {
                case TaskStatus.RanToCompletion:
                    pendingAsyncOperation = false;
                    webResponse           = (HttpWebResponse)task.Result;
                    readStream            = webResponse.GetResponseStream();
                    break;

                default:
                    break;

                case TaskStatus.Canceled:
                case TaskStatus.Faulted:
                    pendingAsyncOperation = false;
                    webResponse           = null;
                    readStream            = null;
                    NotificationSystem.GetInstance().Add(notification);
                    break;
                }
            }
        }
示例#3
0
        /// <summary>
        /// Initialise le contenu de cet article avec les
        /// infos provenant d'un XPathNavigator, en suivant
        /// les instructions d'un ArticleTemplate.
        /// </summary>
        /// <param name="nav"></param>
        /// <param name="template"></param>
        /// <remarks>Bloque toutes les exceptions qui pourraient survenir durant
        /// l'exécution de cette méthode.</remarks>
        /// <seealso cref="NotificationKeys.ArticleUpdateError"/>
        internal void Update(XPathNavigator nav, ArticleTemplate template)
        {
            var notification = new NotificationSystem.Notification(this,
                                                                   (int)NotificationKeys.ArticleUpdateError)
            {
                Title       = Identifier,
                Description = "Article update error."
            };

            try
            {
                UpdateInfo(nav, template);
                NotificationSystem.GetInstance().Remove(notification);
            }
            catch (Exception e)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(notification.Description);
                sb.AppendFormat("{0} occured while parsing data from {1}.",
                                e.GetType().Name, this.BaseUri.ToString()).AppendLine();
                sb.AppendFormat("The original error message is: \"{0}\"", e.Message);
                notification.Description = sb.ToString();
                NotificationSystem.GetInstance().Add(notification);
            }
        }
示例#4
0
 private void ArticleMedia_MediaFailed(object sender, ExceptionRoutedEventArgs e)
 {
     mediaNotification.Description = e.ErrorException.Message;
     NotificationSystem.GetInstance().Add(mediaNotification);
     dispatcherTimer.Stop();
     articleMedia.Stop();
     mediaProgressContainer.Visibility = Visibility.Hidden;
     mediaKO.Visibility     = Visibility.Visible;
     articleIcon.Visibility = Visibility.Hidden;
 }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="nav"></param>
        /// <param name="sectionTemplate"></param>
        /// <remarks>Ajoute une notification dans NotificationSystem si erreur durant
        /// la mise à jour de la section. Ne bloque pas les exceptions.</remarks>
        /// <seealso cref="NotificationKeys.SectionUpdateError"/>
        internal void Update(XPathNavigator nav, SectionTemplate sectionTemplate)
        {
            var notification = new NotificationSystem.Notification(this,
                                                                   (int)NotificationKeys.SectionUpdateError)
            {
                Title       = Identifier,
                Description = "Update error."
            };

            try
            {
                UpdateInfo(nav, sectionTemplate);

                foreach (ArticleTemplate articleTemplate in sectionTemplate.Articles)
                {
                    XPathNodeIterator iter;
                    if (string.IsNullOrEmpty(articleTemplate.XPathFilter))
                    {
                        iter = nav.SelectChildren(XPathNodeType.Element);
                    }
                    else
                    {
                        iter = nav.Select(articleTemplate.XPathFilter);
                    }

                    while (iter.MoveNext())
                    {
                        XPathNavigator subTree = iter.Current;
                        Article        tmp     = new Article()
                        {
                            BaseUri       = this.BaseUri,
                            IsNewBehavior = this.IsNewBehavior
                        };
                        tmp.Update(subTree, articleTemplate);
                        AddOrUpdateArticle(tmp);
                    }
                }

                NotificationSystem.GetInstance().Remove(notification);
            }
            catch
            {
                NotificationSystem.GetInstance().Add(notification);
                throw;
            }
        }
示例#6
0
 /// <summary>
 /// une fois le contrôle chargé, démarrer la lecture
 /// du média.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ArticleMedia_Loaded(object sender, RoutedEventArgs e)
 {
     NotificationSystem.GetInstance().Remove(mediaNotification);
     articleMedia.Play();
 }