private void SearchManagerDataLoaded(object sender, DataLoadedEventArgs e)
 {
     m_initialize = true;
     if (m_searchManager.EnablePage)
     {
         if (m_searchManager.MaxResult != 0)
         {
             int page = (m_searchManager.Count - 1) / m_searchManager.MaxResult + 1;
             base.DataSource = new int[page];
             base.DataMember = "";
             this.Position = m_searchManager.FirstResult / m_searchManager.MaxResult;
         }
         else
         {
             int page = 0;
             base.DataSource = new int[page];
             base.DataMember = "";
             this.Position = 0;
         }
     }
     else
     {
         int page = m_searchManager.MaxResult == 0 ? 0 : 1;
         base.DataSource = new int[page];
         base.DataMember = "";
         this.Position = 0;
     }
     m_initialize = false;
 }
Ejemplo n.º 2
0
        public bool LoadFromHtml(HtmlNode RootNode, DataLoadedEventArgs loadedEventArgs)
        {
            try
            {
                IEnumerable<HtmlNode> linkNodes = RootNode.Descendants("a");
                foreach (HtmlNode linkNode in linkNodes)
                {
                    MitbbsClubGroupLink clubGroupLink = new MitbbsClubGroupLink();
                    clubGroupLink.ParentUrl = Url;

                    if (clubGroupLink.LoadFromHtml(linkNode))
                    {
                        ClubGroupLinks.Add(clubGroupLink);
                        IsLoaded = true;
                    }
                }
            }
            catch (Exception e)
            {
                IsLoaded = false;
                loadedEventArgs.Error = e;
            }

            return IsLoaded;
        }
Ejemplo n.º 3
0
        public bool LoadFromHtml(HtmlNode RootNode, DataLoadedEventArgs loadedEventArgs)
        {
            try
            {
                IEnumerable<HtmlNode> titleNodes = RootNode.Descendants("title");
                foreach (HtmlNode titleNode in titleNodes)
                {
                    String titleText = HtmlUtilities.GetPlainHtmlText(titleNode.FirstChild.InnerText);
                    Match match = Regex.Match(titleText, _titleTemplate);
                    if (match.Success)
                    {
                        BoardGroupName = match.Groups[2].Value;
                        break;
                    }
                    else
                    {
                        return false;
                    }
                }

                IEnumerable<HtmlNode> divNodes = RootNode.Descendants("div");

                foreach (HtmlNode divNode in divNodes)
                {
                    if (divNode.Attributes["id"].Value == "bmwz")
                    {
                        HtmlNodeCollection boardLinkNodes = divNode.FirstChild.ChildNodes;
                        for (int i = 0; i < boardLinkNodes.Count; i++)
                        {
                            HtmlNode boardLinkNode = boardLinkNodes[i];
                            MitbbsLink boardLink = MitbbsLink.CreateLinkInstance(boardLinkNode, Url);

                            if (boardLink != null)
                            {
                                BoardLinks.Add(boardLink);
                                IsLoaded = true;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                IsLoaded = false;
                loadedEventArgs.Error = e;
            }

            return IsLoaded;
        }
Ejemplo n.º 4
0
        public override bool LoadFromHtml(HtmlNode RootNode, DataLoadedEventArgs loadedEventArgs)
        {
            ClearContent();

            MitbbsMailPostMobile post = new MitbbsMailPostMobile();
            post.ParentUrl = Url;
            post.IgnoreMissingHeader = true;

            IEnumerable<HtmlNode> divNodes = RootNode.Descendants("div");

            foreach (HtmlNode divNode in divNodes)
            {
                if (divNode.Attributes.Contains("id"))
                {
                    if (divNode.Attributes["id"].Value == "wenzhangyudu")
                    {
                        if (divNode.ChildNodes.Count >= 2 && divNode.ChildNodes[1].Name == "p")
                        {
                            if (post.LoadMailFooterFromHtml(divNode))
                            {
                                ReplyUrl = post.ReplyPostUrl;
                                DeleteUrl = post.DeletePostUrl;
                            }
                        }
                        else if (post.LoadMailBodyFromHtml(divNode))
                        {
                            if (Posts.Count <= 0)
                            {
                                Title = post.Title;
                                FirstAuthor = post.Author;

                                Posts.Add(post);

                                IsLoaded = true;
                            }
                        }
                    }
                }
            }

            return IsLoaded;
        }
Ejemplo n.º 5
0
        public override bool LoadFromHtml(HtmlNode RootNode, DataLoadedEventArgs loadedEventArgs)
        {
            try
            {
                ClearContent();

                CalculateBoardUrl();

                IEnumerable<HtmlNode> divNodes = RootNode.Descendants("div");

                foreach (HtmlNode divNode in divNodes)
                {
                    if ((divNode.Attributes["id"] != null) && (divNode.Attributes["id"].Value == "wenzhangyudu"))
                    {
                        HtmlNode postNode = divNode;
                        MitbbsPostBase post = new MitbbsEssencePostMobile();
                        post.ParentUrl = Url;
                        if (post.LoadFromHtml(postNode))
                        {
                            if (Posts.Count <= 0)
                            {
                                Title = post.Title + " (精华区)";
                                BoardName = post.BoardName;
                                FirstAuthor = post.Author;
                                ReplyUrl = post.ReplyPostUrl;

                                IsLoaded = true;
                            }

                            Posts.Add(post);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                loadedEventArgs.Error = e;
                IsLoaded = false;
            }

            return IsLoaded;
        }
Ejemplo n.º 6
0
        public void DeletePost(String delLinkParameters)
        {
            IsPostDeleted = false;

            if (!IsInited || !ParseDelLinkParameters(delLinkParameters))
            {
                if (DeletePostCompleted != null)
                {
                    DataLoadedEventArgs loadedArgs = new DataLoadedEventArgs();
                    DeletePostCompleted(this, loadedArgs);
                }

                return;
            }

            _web.FormElements["file"] = File;
            _web.FormElements["id"] = ID;
            _web.FormElements["dingflag"] = DingFlag;

            _web.LoadCompleted += OnDeletePageLoaded;
            _web.LoadAsync(_submitUrl, HtmlWeb.OpenMode.Post);
        }
Ejemplo n.º 7
0
        private void Post_Deleted(object sender, DataLoadedEventArgs e)
        {
            bool success;
            if (_fullPage)
            {
                MitbbsTopic fullTopic = (_topic as MitbbsTopic);
                fullTopic.PostDelete.DeletePostCompleted -= Post_Deleted;
                success = fullTopic.PostDelete.IsPostDeleted;
            }
            else
            {
                _postDeleteMobile.DeletePostCompleted -= Post_Deleted;
                success = _postDeleteMobile.IsPostDeleted;
            }

            if (!success)
            {
                MessageBox.Show("删除操作失败!请确认你已经登录,或者尝试重新登录。");
            }
            else if((_topic.Posts.Count <= 1) && (_topic.PrevPageUrl == null) && (_topic.NextPageUrl == null))
            {
                App.ForceRefreshContent = true;

                if (!_offline)
                {
                    App.Settings.OfflineContentManager.CleanupOfflineContent(_offlineID);
                }

                NavigationService.GoBack();
                return;
            }

            LoadTopic(false);
        }
Ejemplo n.º 8
0
        private void OnResultPageLoaded(object sender, HtmlDocumentLoadCompleted args)
        {
            _web.LoadCompleted -= OnResultPageLoaded;
            DataLoadedEventArgs loadedArgs = new DataLoadedEventArgs();

            if (args.Document != null)
            {
                try
                {
                    IEnumerable<HtmlNode> trNodes = args.Document.DocumentNode.Descendants("tr");
                    foreach (HtmlNode trNode in trNodes)
                    {
                        MitbbsTopicSearchLink searchLink = new MitbbsTopicSearchLink();
                        searchLink.ParentUrl = _resultUrl;

                        if (searchLink.LoadFromHtml(trNode))
                        {
                            TopicLinks.Insert(0, searchLink);
                        }
                    }

                    IsSearchCompleted = true;
                }
                catch (Exception e)
                {
                    loadedArgs.Error = e;
                }
            }
            else
            {
                loadedArgs.Error = args.Error;
            }

            if (SearchCompleted != null)
            {
                SearchCompleted(this, loadedArgs);
            }
        }
Ejemplo n.º 9
0
        public override bool LoadFromHtml(HtmlNode RootNode, DataLoadedEventArgs loadedEventArgs)
        {
            bool isHomeLoaded = false;

            try
            {
                if (loadArticleList(TopArticles, RootNode, "index_other_news"))
                {
                    isHomeLoaded = true;
                }

                if (loadArticleList(HotArticles, RootNode, "index_ten_big_left"))
                {
                    isHomeLoaded = true;
                }

                if (loadArticleList(RecommendedArticles, RootNode, "index_ten_big_right"))
                {
                    isHomeLoaded = true;
                }

                //var topArticleNodes = from tdNode in RootNode.Descendants("td")
                //                      where tdNode.Attributes.Contains("class") &&
                //                      tdNode.Attributes["class"].Value == "huibian_3"
                //                      select tdNode;

                //int index = 0;
                //foreach (HtmlNode topArticleNode in topArticleNodes)
                //{
                //    ObservableCollection<MitbbsLink> articleList = null;
                //    switch (index)
                //    {
                //        case 0:
                //            articleList = TopArticles;
                //            break;
                //        case 1:
                //            articleList = HotArticles;
                //            break;
                //        case 2:
                //            articleList = RecommendedArticles;
                //            break;
                //    }

                //    if (articleList == null)
                //    {
                //        break;
                //    }

                //    foreach (HtmlNode linkNode in topArticleNode.Descendants("a"))
                //    {
                //        MitbbsSimpleTopicLink topicLink = new MitbbsSimpleTopicLink();
                //        topicLink.ParentUrl = Url;

                //        if (topicLink.LoadFromHtml(linkNode))
                //        {
                //            articleList.Add(topicLink);
                //            isHomeLoaded = true;
                //        }
                //    }

                //    index++;
                //}
            }
            catch (Exception e)
            {
                loadedEventArgs.Error = e;
            }

            return isHomeLoaded;
        }
Ejemplo n.º 10
0
 private void OnDataLoaded(object sender, DataLoadedEventArgs e)
 {
     mapControl1.ZoomToFitLayerItems();
 }
Ejemplo n.º 11
0
        private void Mailbox_Loaded(object sender, DataLoadedEventArgs e)
        {
            if (sender == _unreadMailbox)
            {
                if (_unreadMailbox.MailLinks.Count > 0)
                {
                    UnreadMailIndicator.Text = _unreadMailbox.MailLinks.Count.ToString();
                    UnreadMailIndicator.Visibility = System.Windows.Visibility.Visible;

                    if (_showMailMessage)
                    {
                        ShowNewMailMessage(_unreadMailbox.MailLinks.Count);
                    }

                    App.Settings.NotficationCenter.HasNewMail = true;
                }
                else
                {
                    UnreadMailIndicator.Visibility = System.Windows.Visibility.Collapsed;
                    App.Settings.NotficationCenter.HasNewMail = false;
                }
            }
        }
 private void searchManager_DataLoaded(object sender, DataLoadedEventArgs e)
 {
     if (!m_sm.UseStreamLoad)
     {
         this.StopLoadData();
     }
 }
Ejemplo n.º 13
0
        private void OnSearchCompleted(object sender, DataLoadedEventArgs args)
        {
            if (_search.IsSearchCompleted)
            {
                TitleText.Text = _boardName + "版内查询(" + _search.TopicLinks.Count + "条结果)";
                ShowSearchPanel(false);
            }
            else
            {
                TitleText.Text = _boardName + "版内查询";
                MessageBox.Show("搜索失败。请稍后再试一次。");
                ShowSearchPanel(true);
            }

            SearchProgress.Visibility = Visibility.Collapsed;

            (ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = true; //search button
            (ApplicationBar.Buttons[1] as ApplicationBarIconButton).IsEnabled = true; //close button
        }
Ejemplo n.º 14
0
        private void OnUrlLoaded(object sender, HtmlDocumentLoadCompleted args)
        {
            _web.LoadCompleted -= OnUrlLoaded;
            DataLoadedEventArgs loadedEventArgs = new DataLoadedEventArgs();
            loadedEventArgs.Error = args.Error;

            if (args.Document != null)
            {
                try
                {
                    LoadFromHtml(args.Document.DocumentNode);
                }
                catch (Exception e)
                {
                    loadedEventArgs.Error = e;
                }
            }

            if (MailboxLoaded != null)
            {
                MailboxLoaded(this, loadedEventArgs);
            }
        }
        void ItemsLayer_DataLoaded(object sender, DataLoadedEventArgs e)
        {
            var mapItem = ItemsLayer.Data.Items.FirstOrDefault();

            ItemsLayer.SelectedItem = (mapItem != null) ? ItemsLayer.Data.GetItemSourceObject(mapItem) : null;
        }
 void layer_DataLoaded(object sender, DataLoadedEventArgs e)
 {
     mapControl1.ZoomToFitLayerItems(0.4);
 }
Ejemplo n.º 17
0
        private void OnMyClubLoaded(object sender, DataLoadedEventArgs args)
        {
            // Add local favorites to the board list
            // TODO: add an option to control the behavior
            //
            foreach (MitbbsLink boardLink in App.Settings.BoardBookmarks)
            {
                InsertMyBoard(boardLink);
            }

            //IsLoaded = MyClubGroup.IsLoaded;

            if (UserHomeLoaded != null)
            {
                UserHomeLoaded(this, args);
            }
        }
Ejemplo n.º 18
0
        private void OnUrlLoaded(object sender, HtmlDocumentLoadCompleted args)
        {
            _web.LoadCompleted -= OnUrlLoaded;

            DataLoadedEventArgs loadedEventArgs = new DataLoadedEventArgs();

            if (args.Document != null)
            {
                LoadFromHtml(args.Document.DocumentNode, loadedEventArgs);
            }
            else
            {
                loadedEventArgs.Error = args.Error;
            }

            if (BoardGroupLoaded != null)
            {
                BoardGroupLoaded(this, loadedEventArgs);
            }
        }
Ejemplo n.º 19
0
        private void OnUrlLoaded(object sender, HtmlDocumentLoadCompleted args)
        {
            _web.LoadCompleted -= OnUrlLoaded;
            DataLoadedEventArgs loadedArgs = new DataLoadedEventArgs();

            if (args.Document != null)
            {
                if (LoadFromHtml(args.Document.DocumentNode, loadedArgs))
                {
                    IsLoaded = true;
                    MyClubGroup.LoadFromUrl(_web, App.Settings.BuildUrl(MitbbsClubGroup.UserClubGroupUrl));
                    return;
                }
            }
            else
            {
                loadedArgs.Error = args.Error;
            }

            if (UserHomeLoaded != null)
            {
                UserHomeLoaded(this, loadedArgs);
            }
        }
Ejemplo n.º 20
0
 public abstract bool LoadFromHtml(HtmlNode RootNode, DataLoadedEventArgs loadedEventArgs);
        void SearchManager_DataLoaded(object sender, DataLoadedEventArgs e)
        {
            try
            {
                m_masterGrid.BeginInit();

                ResetCheckColumnValue(m_masterGrid);

                foreach (Feng.Grid.Columns.CheckColumn column in m_checkColumns)
                {
                    column.ResetSumRow();
                }
            }
            catch (Exception ex)
            {
                ExceptionProcess.ProcessWithResume(ex);
            }
            finally
            {
                m_masterGrid.EndInit();
            }
        }
Ejemplo n.º 22
0
        protected void OnUrlLoaded(object sender, HtmlDocumentLoadCompleted args)
        {
            bool isHomeLoaded = false;
            _web.LoadCompleted -= OnUrlLoaded;

            DataLoadedEventArgs loadedEventArgs = new DataLoadedEventArgs();

            if (args.Document != null)
            {
                isHomeLoaded = LoadFromHtml(args.Document.DocumentNode, loadedEventArgs);
            }
            else
            {
                loadedEventArgs.Error = args.Error;
            }

            if (isHomeLoaded && LoadClubHome)
            {
                ClubHome.LoadFromUrl(_web, App.Settings.BuildUrl(MitbbsClubHome.ClubHomeUrl));
                return;
            }
            else
            {
                IsLoaded = isHomeLoaded;
                TriggerHomeLoaded(loadedEventArgs);
            }
        }
Ejemplo n.º 23
0
        private void UserHome_Loaded(object sender, DataLoadedEventArgs e)
        {
            _userHome.UserHomeLoaded -= UserHome_Loaded;
            LoadHomeProgressBar.Visibility = Visibility.Collapsed;

            if (_userHome.IsLoaded)
            {
                if (PivotControl.SelectedItem != null)
                {
                    //ScrollViewer scrollPanel = (PivotControl.SelectedItem as PivotItem).Content as ScrollViewer;
                    //if (_scrollOffset >= 0)
                    //{
                    //    scrollPanel.UpdateLayout();
                    //    scrollPanel.ScrollToVerticalOffset(_scrollOffset);
                    //    _scrollOffset = -1;
                    //}
                    //else
                    //{
                    //    scrollPanel.UpdateLayout();
                    //    scrollPanel.ScrollToVerticalOffset(0);
                    //}
                }
            }
            else
            {
                MessageBox.Show("请确认你已经登录,或者尝试重新登录。重试请按刷新按钮。", "无法打开家页", MessageBoxButton.OK);
            }

            (ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = true; //refresh button
            (ApplicationBar.Buttons[1] as ApplicationBarIconButton).IsEnabled = true; //home button
            (ApplicationBar.Buttons[2] as ApplicationBarIconButton).IsEnabled = true; //history button
            (ApplicationBar.Buttons[3] as ApplicationBarIconButton).IsEnabled = true; //setting button
        }
Ejemplo n.º 24
0
 protected virtual void OnDataLoaded(DataLoadedEventArgs <T> e)
 {
     DataLoaded?.Invoke(this, e);
 }
Ejemplo n.º 25
0
        protected void OnClubHomeLoad(object sender, DataLoadedEventArgs args)
        {
            IsLoaded = ClubHome.IsLoaded;

            TriggerHomeLoaded(args);
        }
Ejemplo n.º 26
0
        protected virtual void OnUrlLoaded(object sender, HtmlDocumentLoadCompleted args)
        {
            DataLoadedEventArgs loadedEventArgs = new DataLoadedEventArgs();

            if (args.Document != null)
            {
                try
                {
                    if (!LoadFromHtml(args.Document.DocumentNode, loadedEventArgs))
                    {
                        if (_alternateUrl != null)
                        {
                            Url = _alternateUrl;
                            _web.LoadAsync(Url);
                            return;
                        }
                    }
                    else if (_pageToLoad >= 1 && PageIndex >= 1 && _pageToLoad != PageIndex)
                    {
                        int pageNum = _pageToLoad;
                        if (_pageToLoad == int.MaxValue)
                        {
                            pageNum = LastPageIndex;
                        }

                        String newUrl;
                        if (PageLinks.TryGetValue(pageNum, out newUrl))
                        {
                            Url = newUrl;
                            ClearContent();
                            _web.LoadAsync(Url);
                            return;
                        }
                    }
                }
                catch (Exception e)
                {
                    loadedEventArgs.Error = e;
                }
            }
            else
            {
                loadedEventArgs.Error = args.Error;
            }

            _web.LoadCompleted -= OnUrlLoaded;

            if (_alternateUrl == null)
            {
                TriggerLoadedEvent(loadedEventArgs);
            }
        }
Ejemplo n.º 27
0
 protected void TriggerHomeLoaded(DataLoadedEventArgs args)
 {
     if (HomeLoaded != null)
     {
         HomeLoaded(this, args);
     }
 }
Ejemplo n.º 28
0
 protected void TriggerLoadedEvent(DataLoadedEventArgs loadedEventArgs)
 {
     if (TopicLoaded != null)
     {
         TopicLoaded(this, loadedEventArgs);
     }
 }
Ejemplo n.º 29
0
        public override bool LoadFromHtml(HtmlNode RootNode, DataLoadedEventArgs loadedEventArgs)
        {
            bool isHomeLoaded = false;

            try
            {
                IEnumerable<HtmlNode> divNodes = RootNode.Descendants("div");
                int counter = 0;
                foreach (HtmlNode divNode in divNodes)
                {
                    if (divNode.Attributes.Contains("id") && divNode.Attributes["id"].Value == "mnpage_first")
                    {
                        if (counter == 3)
                        {
                            // because the mitbbs mobile home page is mal-formated
                            // we have to do some special handling for the hot boards
                            // section
                            //
                            ExtractHotBoardEntries(divNode);
                        }
                        else
                        {
                            HtmlNodeCollection listNodes = divNode.ChildNodes[1].ChildNodes;
                            for (int i = 0; i < listNodes.Count; i++)
                            {
                                HtmlNode listNode = listNodes[i];

                                if (listNode.Name == "li")
                                {
                                    MitbbsSimpleTopicLinkMobile topicLink = new MitbbsSimpleTopicLinkMobile();
                                    topicLink.ParentUrl = Url;

                                    if (topicLink.LoadFromHtml(listNode))
                                    {
                                        switch (counter)
                                        {
                                            case 0:
                                                TopArticles.Add(topicLink);
                                                break;
                                            case 1:
                                                HotArticles.Add(topicLink);
                                                break;
                                            case 2:
                                                RecommendedArticles.Add(topicLink);
                                                break;
                                        }
                                    }
                                }
                            }
                        }

                        counter++;

                        if (counter >= 4)
                        {
                            isHomeLoaded = true;
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                loadedEventArgs.Error = e;
            }

            return isHomeLoaded;
        }
Ejemplo n.º 30
0
        public override bool LoadFromHtml(HtmlNode RootNode, DataLoadedEventArgs loadedEventArgs)
        {
            try
            {
                ClearContent();

                CalculateBoardUrl();

                IEnumerable<HtmlNode> divNodes = RootNode.Descendants("div");

                foreach (HtmlNode divNode in divNodes)
                {
                    if (divNode.Attributes.Contains("id"))
                    {
                        if (divNode.Attributes["id"].Value == "wenzhangye1")
                        {
                            HtmlNodeCollection headNodes = divNode.ChildNodes[0].ChildNodes;

                            for (int i = 0; i < headNodes.Count; i++)
                            {
                                HtmlNode headNode = headNodes[i];
                                if (headNode.Name == "a")
                                {
                                    HtmlNode linkNode = headNode.FirstChild;
                                    if (linkNode != null)
                                    {
                                        if (linkNode.InnerText == "首页")
                                        {
                                            FirstPageUrl = HtmlUtilities.GetAbsoluteUrl(Url, headNode.Attributes["href"].Value);
                                        }
                                        else if (linkNode.InnerText == "上页")
                                        {
                                            PrevPageUrl = HtmlUtilities.GetAbsoluteUrl(Url, headNode.Attributes["href"].Value);
                                        }
                                        else if (linkNode.InnerText == "下页")
                                        {
                                            NextPageUrl = HtmlUtilities.GetAbsoluteUrl(Url, headNode.Attributes["href"].Value);
                                        }
                                        else if (linkNode.InnerText == "末页")
                                        {
                                            LastPageUrl = HtmlUtilities.GetAbsoluteUrl(Url, headNode.Attributes["href"].Value);
                                        }
                                    }
                                }
                            }
                        }
                        else if (divNode.Attributes["id"].Value == "wenzhangyudu")
                        {
                            HtmlNodeCollection postNodes = divNode.ChildNodes[0].ChildNodes;

                            for (int i = 0; i < postNodes.Count; i++)
                            {
                                HtmlNode postNode = postNodes[i];
                                if (postNode.Name == "li")
                                {
                                    MitbbsPostBase post = new MitbbsPostMobile();
                                    post.ParentUrl = Url;
                                    if (post.LoadFromHtml(postNode))
                                    {
                                        if (Posts.Count <= 0)
                                        {
                                            Title = post.Title;
                                            BoardName = post.BoardName;
                                            FirstAuthor = post.Author;
                                            ReplyUrl = post.ReplyPostUrl;

                                            IsLoaded = true;
                                        }

                                        Posts.Add(post);
                                    }
                                }
                                else if (postNode.Name == "a")
                                {
                                    if (postNode.FirstChild.InnerText == "同主题阅读")
                                    {
                                        _alternateUrl = HtmlUtilities.GetAbsoluteUrl(Url, postNode.Attributes["href"].Value);
                                        return false;
                                    }
                                }
                            }
                        }
                    }
                }

            }
            catch (Exception e)
            {
                loadedEventArgs.Error = e;
                IsLoaded = false;
            }

            return IsLoaded;
        }
Ejemplo n.º 31
0
        private void OnSearchPageLoaded(object sender, HtmlDocumentLoadCompleted args)
        {
            _web.LoadCompleted -= OnSearchPageLoaded;

            DataLoadedEventArgs loadedArgs = new DataLoadedEventArgs();

            if (args.Document != null)
            {
                try
                {
                    IEnumerable<HtmlNode> formNodes = args.Document.DocumentNode.Descendants("form");
                    foreach (HtmlNode formNode in formNodes)
                    {
                        if ((formNode.Attributes["name"] != null) && (formNode.Attributes["name"].Value == "form_query"))
                        {
                            _web.FormElements = new FormElementCollection(formNode.ParentNode);
                            _resultUrl = HtmlUtilities.GetAbsoluteUrl(_searchUrl, formNode.Attributes["action"].Value);

                            _isSearchPageLoaded = true;
                        }
                    }
                }
                catch (Exception e)
                {
                    loadedArgs.Error = e;
                }
            }
            else
            {
                loadedArgs.Error = args.Error;
            }

            if (_isSearchPageLoaded)
            {
                LoadResultPage();
            }
            else
            {
                if (SearchCompleted != null)
                {
                    SearchCompleted(this, loadedArgs);
                }
            }
        }
Ejemplo n.º 32
0
        public override bool LoadFromHtml(HtmlNode RootNode, DataLoadedEventArgs loadedEventArgs)
        {
            try
            {
                _alternateUrl = null;

                bool headNodeFound = false;
                var headNodes = from tdNode in RootNode.Descendants("td")
                                where (tdNode.Attributes.Contains("class") && tdNode.Attributes["class"].Value == "news-bg")
                                select tdNode;

                foreach (HtmlNode headNode in headNodes)
                {
                    foreach (HtmlNode linkNode in headNode.Descendants("a"))
                    {
                        try
                        {
                            String linkText = linkNode.GetLinkText();
                            String linkUrl = linkNode.GetLinkUrl(Url);

                            if (linkText == "首页")
                            {
                                FirstPageUrl = linkUrl;
                                headNodeFound = true;
                            }
                            else if (linkText == "上页")
                            {
                                PrevPageUrl = linkUrl;
                                headNodeFound = true;
                            }
                            else if (linkText == "下页")
                            {
                                NextPageUrl = linkUrl;
                                headNodeFound = true;
                            }
                            else if (linkText == "末页")
                            {
                                LastPageUrl = linkUrl;
                                headNodeFound = true;
                            }
                            else
                            {
                                int pageNum;
                                if (int.TryParse(linkText, out pageNum))
                                {
                                    if (!PageLinks.ContainsKey(pageNum))
                                    {
                                        PageLinks.Add(pageNum, linkUrl);
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine(e.ToString());
                        }
                    }

                    if (headNodeFound)
                    {
                        break;
                    }
                }

                headNodes = from tdNode in RootNode.Descendants("td")
                            where (tdNode.Attributes.Contains("class") && tdNode.Attributes["class"].Value == "logo-bg")
                            select tdNode;
                foreach (HtmlNode headNode in headNodes)
                {
                    foreach (HtmlNode linkNode in headNode.Descendants("a"))
                    {
                        String linkText = linkNode.GetLinkText();
                        String linkUrl = linkNode.GetLinkUrl(Url);

                        if (linkText == "同主题阅读")
                        {
                            _alternateUrl = linkUrl;
                            return false;
                        }
                    }
                }

                var postNodes = from tdNode in RootNode.Descendants("td")
                                where (tdNode.Attributes.Contains("class") && tdNode.Attributes["class"].Value == "jiawenzhang-type")
                                select tdNode;

                foreach (HtmlNode postNode in postNodes)
                {
                    MitbbsPost post = new MitbbsPost();
                    post.ParentUrl = Url;
                    if (post.LoadFromHtml(postNode))
                    {
                        if (Posts.Count <= 0)
                        {
                            Title = post.Title;
                            BoardName = post.BoardName;
                            FirstAuthor = post.Author;
                            ReplyUrl = post.ReplyPostUrl;

                            IsLoaded = true;
                        }

                        Posts.Add(post);
                    }
                }

                var delFormNodes = from formNode in RootNode.Descendants("form")
                                   where formNode.Attributes.Contains("name") && formNode.Attributes["name"].Value == "delform"
                                   select formNode;

                foreach (HtmlNode delFormNode in delFormNodes)
                {
                    PostDelete.Initialize(App.WebSession.CreateWebClient(), delFormNode, Url);
                    break;
                }

                CalculateBoardUrl();
                CalculatePageIndex();
            }
            catch (Exception e)
            {
                loadedEventArgs.Error = e;
                IsLoaded = false;
            }

            return IsLoaded;
        }
Ejemplo n.º 33
0
        private void Topic_Loaded(object sender, DataLoadedEventArgs e)
        {
            LoadTopicProgressBar.Visibility = Visibility.Collapsed;
            TopicBodyPanel.Children.Clear();
            _imageLoader.ClearImages();

            if (_topic.IsLoaded)
            {
                if (!_offline && App.Settings.Preload && (_topic.PrevPageUrl != null || _topic.NextPageUrl != null))
                {
                    var downloader = CreateTopicDownloader();
                    downloader.AddTopicUrl("", _topic.PrevPageUrl);
                    downloader.AddTopicUrl("", _topic.NextPageUrl);

                    downloader.StartDownload(App.WebSession.CreateWebClient(), null);
                }

                _url = _topic.Url;

                RenderTopic();

                if (_topic.PrevPageUrl != null)
                {
                    (ApplicationBar.Buttons[1] as ApplicationBarIconButton).IsEnabled = true; //prev page button
                }

                if (_topic.NextPageUrl != null)
                {
                    (ApplicationBar.Buttons[2] as ApplicationBarIconButton).IsEnabled = true; //next page button
                }

                if (_topic.ReplyUrl != null && !_offline)
                {
                    (ApplicationBar.Buttons[3] as ApplicationBarIconButton).IsEnabled = true; //reply button

                    if (_showQuickReply)
                    {
                        (ApplicationBar.MenuItems[3] as ApplicationBarMenuItem).IsEnabled = true; //quick reply menu
                    }
                }

                if (_topic.FirstPageUrl != null)
                {
                    (ApplicationBar.MenuItems[0] as ApplicationBarMenuItem).IsEnabled = true; //first page menu
                }

                if (_topic.LastPageUrl != null)
                {
                    (ApplicationBar.MenuItems[1] as ApplicationBarMenuItem).IsEnabled = true; //last page menu
                }

                if (_openFromBoard || (_topic.BoardUrl != null && !_offline))
                {
                    (ApplicationBar.MenuItems[2] as ApplicationBarMenuItem).IsEnabled = true; //open board menu

                    if (_club)
                    {
                        (ApplicationBar.MenuItems[2] as ApplicationBarMenuItem).Text = "进入" + _topic.BoardName + "俱乐部";
                    }
                    else
                    {
                        (ApplicationBar.MenuItems[2] as ApplicationBarMenuItem).Text = "进入" + _topic.BoardName + "版";
                    }
                }

                if (App.Settings.IsUrlBookmarked(_topic.Url))
                {
                    (ApplicationBar.MenuItems[4] as ApplicationBarMenuItem).Text = "删除书签"; //bookmark menu
                }
                else
                {
                    (ApplicationBar.MenuItems[4] as ApplicationBarMenuItem).Text = "加入书签"; //bookmark menu
                }

                if (App.Settings.IsUrlBeingWatched(_originalUrl))
                {
                    (ApplicationBar.MenuItems[6] as ApplicationBarMenuItem).Text = "停止关注"; //ad watch menu
                }
                else
                {
                    (ApplicationBar.MenuItems[6] as ApplicationBarMenuItem).Text = "关注"; //ad watch menu
                }

                if (_offline)
                {
                    OfflineTag.Visibility = System.Windows.Visibility.Visible;
                }
            }
            else
            {
                TopicTitleTextBlock.Text = "读取文章失败";
                TopicBodyPanel.Visibility = Visibility.Collapsed;

                if (_club)
                {
                    if (App.WebSession.IsLoggedIn)
                    {
                        MessageBox.Show("请确认你有访问此俱乐部的权限。请访问未名空间的网站管理你的俱乐部设置", "无法读取俱乐部文章", MessageBoxButton.OK);
                    }
                    else
                    {
                        MessageBox.Show("因为你尚未登录,所以你可能无法访问此俱乐部。请在设置页面中设置登录信息,并确认你的账户有访问此俱乐部的权限。请访问未名空间的网站管理你的俱乐部设置", "无法读取俱乐部文章", MessageBoxButton.OK);
                    }

                    if (!_offline)
                    {
                        App.Settings.OfflineContentManager.CleanupOfflineContent(_offlineID);
                    }

                    NavigationService.GoBack();
                }
            }

            if (!_offline)
            {
                (ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = true; //refresh button
            }

            if (App.Settings.IsUrlBookmarked(_topic.Url) || _topic.IsLoaded)
            {
                (ApplicationBar.MenuItems[4] as ApplicationBarMenuItem).IsEnabled = true; //bookmark menu
            }

            if (!_offline && _fullPage)
            {
                (ApplicationBar.MenuItems[5] as ApplicationBarMenuItem).IsEnabled = true; //download menu
            }

            if (!_offline && _topic.IsLoaded)
            {
                (ApplicationBar.MenuItems[6] as ApplicationBarMenuItem).IsEnabled = true; //add watch menu
            }
        }
Ejemplo n.º 34
0
        public bool LoadFromHtml(HtmlNode rootNode, DataLoadedEventArgs loadedArgs)
        {
            bool isUserHomeLoaded = false;

            try
            {
                IEnumerable<HtmlNode> divNodes = rootNode.Descendants("div");
                foreach (HtmlNode divNode in divNodes)
                {
                    if (divNode.Attributes["id"].Value == "wenzhangyudu")
                    {
                        HtmlNodeCollection liNodes = divNode.ChildNodes[1].ChildNodes;
                        for (int i = 0; i < liNodes.Count; i++)
                        {
                            HtmlNode liNode = liNodes[i];
                            if (liNode.Name == "li")
                            {
                                String bText = "";
                                IEnumerable<HtmlNode> bNodes = liNode.Descendants("b");
                                foreach (HtmlNode bNode in bNodes)
                                {
                                    bText = HtmlUtilities.GetPlainHtmlText(bNode.FirstChild.InnerText);
                                    break;
                                }

                                IEnumerable<HtmlNode> linkNodes = liNode.Descendants("a");

                                foreach (HtmlNode linkNode in linkNodes)
                                {
                                    String linkText = HtmlUtilities.GetPlainHtmlText(linkNode.FirstChild.InnerText);

                                    if (linkText == "站内邮箱")
                                    {
                                        MailboxUrl = linkNode.Attributes["href"].Value;
                                        isUserHomeLoaded = true;
                                    }
                                    else if(bText != "")
                                    {
                                        if (bText == "我的讨论区:")
                                        {
                                            MitbbsBoardLinkMobile boardLink = new MitbbsBoardLinkMobile();
                                            boardLink.ParentUrl = Url;
                                            if (boardLink.LoadFromHtml(linkNode))
                                            {
                                                MyBoards.Add(MitbbsBoardLink.CreateFromMobileLink(boardLink));
                                            }
                                        }
                                        else if (bText == "我的最新文章:")
                                        {
                                            MitbbsSimpleTopicLinkMobile topicLink = new MitbbsSimpleTopicLinkMobile();
                                            topicLink.ParentUrl = Url;
                                            if (topicLink.LoadFromHtml(linkNode))
                                            {
                                                MyArticles.Add(MitbbsSimpleTopicLink.CreateFromMobileLink(topicLink));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch(Exception e)
            {
                loadedArgs.Error = e;
            }

            return isUserHomeLoaded;
        }