Beispiel #1
0
        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);
            }
        }
Beispiel #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;
                }
            }
        }
Beispiel #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);
            }
        }
Beispiel #4
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;
            }
        }
Beispiel #5
0
        public void ShowMedia(string file)
        {
            try
            {
                mediaNotification = new NotificationSystem.Notification(this,
                                                                        (int)NotificationKeys.MediaError)
                {
                    Title       = file,
                    Description = "Media playback error."
                };

                articleMedia.Visibility = Visibility.Visible;
                articleMedia.Source     = new Uri(file, UriKind.Absolute);
                downloadProgressContainer.Visibility = Visibility.Hidden;
            }
            // Since the action is executed asynchronously, the Dispatcher
            // might execute the above code at a time when mediaTask has
            // already become invalid. Just ignore all errors.
            catch { }
        }