Ejemplo n.º 1
0
        private static async void RefreshModelRssFeed(ProgressBarHelper progressBarHelper)
        {
            App.MainViewModel.RssItems.Clear();
            string url = PreferenceHelper.GetPreference("RSS_FollowerPath");
            if (string.IsNullOrEmpty(url))
            {
                progressBarHelper.PopTask();
                return;
            }
            RestClient client = new RestClient();
            RestRequest request = new RestRequest();
            client.Authority = url;
            request.Method = Method.Get;
            RestResponse response = await client.BeginRequest(request);

            if(response.Error == RestError.ERROR_SUCCESS && response.Content != null)
            {                
                try
                {
                    SyndicationFeed feed = new SyndicationFeed();                    
                    feed.Load(response.Content);
                    foreach (SyndicationItem item in feed.Items)
                    {
                        ItemViewModel model = RSSFeedConverter.ConvertFeedToCommon(item);
                        if (model != null)
                        {
                            App.MainViewModel.RssItems.Add(model);
                        }
                    }   
                }
                catch (System.Exception ex)
                {
                    DialogHelper.ShowToastDialog("RSS获取中发生错误,可能是网络问题,也可能是对应站点地址变更");                   
                }
                finally
                {
                    progressBarHelper.PopTask(); 
                }
            }
            else
            {
                DialogHelper.ShowToastDialog("RSS获取中发生错误,可能是网络问题,也可能是对应站点地址变更");
                progressBarHelper.PopTask(); 
            }           
              
        }
Ejemplo n.º 2
0
        public static void RefreshMainViewModel(ProgressBarHelper progressBarHelper)
        {
            Task.Run(() =>
            {
                if (progressBarHelper == null)
                    return;
                progressBarHelper.PushTask("SinaWeibo");
                progressBarHelper.PushTask("Rss");
                progressBarHelper.PushTask("Renren");
                progressBarHelper.PushTask("Douban");

                // 1.Weibo
                RefreshModelSinaWeibo(progressBarHelper);
                // 2.Rss
                RefreshModelRssFeed(progressBarHelper);
                // 3.Renren
                RefreshModelRenren(progressBarHelper);
                // 4.Douban 
                RefreshModelDouban(progressBarHelper);
            });
        }
Ejemplo n.º 3
0
        private async void SearchByKey(String key)
        {
            if (m_progressBarHelper == null)
                m_progressBarHelper = new ProgressBarHelper(LoadProgessBar, () => { });
            m_progressBarHelper.PushTask();

            RestClient client = new RestClient();
            RestRequest request = new RestRequest();
            client.Authority = "http://www.search4rss.com/search.php";
            request.Method = Method.Get;
            request.AddParameter("lang", "en");
            request.AddParameter("q", key);

            RestResponse response = await client.BeginRequest(request);
            if (response.Error == RestError.ERROR_SUCCESS && response.Content != null)
            {
                HandleHtml(response.Content);
            }
            else
            {
                DialogHelper.ShowMessageDialog("网络无法连接,请检查当前网络状态。");
                m_progressBarHelper.PopTask();
            }
        }
Ejemplo n.º 4
0
        private void RefreshComments()
        {
            if (m_itemViewModel == null)
                return;

            if (m_progressBarHelper == null)
            {
                m_progressBarHelper = new ProgressBarHelper(CommentProgessBar, () => { });
            }
            m_progressBarHelper.PushTask();
            EntryType type = m_itemViewModel.Type;
            if (type == EntryType.SinaWeibo)
            {
                RefreshCommentsForSinaWeibo();
            }
            else if (type == EntryType.Renren)
            {
                RefreshCommentsForRenren();
            }
            else if (type == EntryType.Douban)
            {
                RefreshCommentsForDouban();
            }
        }
 private void Refresh_Tapped(object sender, TappedRoutedEventArgs e)
 {
     topAppBar.IsOpen = false;
     bottomAppBar.IsOpen = false;
     if (m_progressBarHelper == null)
     {
         m_progressBarHelper = new ProgressBarHelper(MainProgessBar, RefreshViewerHelper.RefreshViewItems);
     }
     RefreshViewerHelper.RefreshMainViewModel(m_progressBarHelper);
 }
 private void Page_Loaded(object sender, RoutedEventArgs e)
 {
     if (App.MainViewModel.IsChanged)
     {
         App.MainViewModel.IsChanged = false;
         if (m_progressBarHelper == null)
         {
             m_progressBarHelper = new ProgressBarHelper(MainProgessBar, RefreshViewerHelper.RefreshViewItems);
         }
         RefreshViewerHelper.RefreshMainViewModel(m_progressBarHelper);
     }
 }
Ejemplo n.º 7
0
        private static async void RefreshModelSinaWeibo(ProgressBarHelper progressBarHelper)
        {
            App.MainViewModel.SinaWeiboPicItems.Clear();
            App.MainViewModel.SinaWeiboItems.Clear();

            // 1.检查有没有登陆
            if (String.IsNullOrEmpty(PreferenceHelper.GetPreference("SinaWeibo_ID")))
            {
                progressBarHelper.PopTask("Sina");
                return;
            }
            // 2.检查有没有指定帐号
            String followerID = PreferenceHelper.GetPreference("SinaWeibo_FollowerID");
            if (String.IsNullOrEmpty(followerID))
            {
                //DialogHelper.ShowToastDialog("尚未设置新浪微博关注对象");
                progressBarHelper.PopTask();
                return;
            }

            // 3.检查有授权有没有过期
            if (App.SinaWeiboAPI.IsAccessTokenOutOfDate())
            {
                DialogHelper.ShowToastDialog("新浪授权已过期,请重新登陆");
                PreferenceHelper.RemoveSinaWeiboLoginAccountPreference();
                progressBarHelper.PopTask();
            }
            
            String strCount = PreferenceHelper.GetPreference("SinaWeibo_RecentCount");
            if (String.IsNullOrEmpty(strCount))
            {
                strCount = "40";
            }

            int nCount;
            try
            {
                nCount = int.Parse(strCount);
            }
            catch (System.Exception ex)
            {
                nCount = 40;
            }
            
            SinaWeiboSDK.GetUserTimelineResponse response = await App.SinaWeiboAPI.StatuesAPI.GetUserTimeline(followerID, nCount);
            if (response.Error == RestBase.RestError.ERROR_SUCCESS && response.statuses != null)
            {
                foreach (SinaWeiboSDK.Status status in response.statuses)
                {
                    ItemViewModel model = SinaWeiboConverter.ConvertItemToCommon(status);
                    if (model != null)
                    {
                        App.MainViewModel.SinaWeiboItems.Add(model);
                    }
                }
                progressBarHelper.PopTask();
            }
            else
            {
                if (response.Error == RestBase.RestError.ERROR_EXPIRED)
                {
                    DialogHelper.ShowMessageDialog("新浪微博帐号已过期,请重新登陆", "温馨提示");
                    PreferenceHelper.RemoveSinaWeiboLoginAccountPreference();
                }
                progressBarHelper.PopTask();
            }
        }
Ejemplo n.º 8
0
        private static async void RefreshModelRenren(ProgressBarHelper progressBarHelper)
        {
            App.MainViewModel.RenrenPicItems.Clear();
            App.MainViewModel.RenrenItems.Clear();

            // 1.检查有没有登陆
            if (String.IsNullOrEmpty(PreferenceHelper.GetPreference("Renren_ID")))
            {
                progressBarHelper.PopTask("Renren");
                return;
            }

            // 2.检查有没有指定帐号
            String followerID = PreferenceHelper.GetPreference("Renren_FollowerID");
            if (String.IsNullOrEmpty(followerID))
            {
                //DialogHelper.ShowToastDialog("尚未设置人人关注对象");
                progressBarHelper.PopTask();
                return;
            }

            // 3.检查有授权有没有过期
            if (App.RenrenAPI.IsAccessTokenOutOfDate())
            {
                DialogHelper.ShowToastDialog("人人授权已过期,请重新登陆");
                PreferenceHelper.RemoveRenrenLoginAccountPreference();
                progressBarHelper.PopTask();
            }

            String strCount = PreferenceHelper.GetPreference("Renren_RecentCount");
            if (String.IsNullOrEmpty(strCount))
            {
                strCount = "40";
            }

            int nCount;
            try
            {
                nCount = int.Parse(strCount);
            }
            catch (System.Exception ex)
            {
                nCount = 40;
            }

            RenrenSDK.GetUserTimelineResponse response = await App.RenrenAPI.FeedAPI.GetUserTimeline(followerID, "10,30,32" ,nCount);
            if (response.Error == RestBase.RestError.ERROR_SUCCESS && response.ListRenrenNews != null)
            {
                foreach (RenrenSDK.RenrenNews news in response.ListRenrenNews)
                {
                    ItemViewModel model = RenrenConverter.ConvertRenrenNewsToCommon(news);
                    if (model != null)
                    {
                        App.MainViewModel.RenrenItems.Add(model);
                    }
                }
                progressBarHelper.PopTask();
            }
            else
            {
                if (response.Error == RestBase.RestError.ERROR_EXPIRED)
                {
                    DialogHelper.ShowMessageDialog("人人帐号已过期或者出现了网络问题,请重新登陆", "温馨提示");
                    PreferenceHelper.RemoveSinaWeiboLoginAccountPreference();
                }
                progressBarHelper.PopTask();
            }
        }
Ejemplo n.º 9
0
        private static async void RefreshModelDouban(ProgressBarHelper progressBarHelper)
        {
            //App.MainViewModel.DoubanPicItems.Clear();
            App.MainViewModel.DoubanItems.Clear();
            
            // 1.检查有没有登陆
            if (String.IsNullOrEmpty(PreferenceHelper.GetPreference("Douban_ID")))
            {
                progressBarHelper.PopTask("Douban");
                return;
            }

            // 2.检查有没有指定帐号
            String followerID = PreferenceHelper.GetPreference("Douban_FollowerID");
            if (String.IsNullOrEmpty(followerID))
            {                
                progressBarHelper.PopTask();
                return;
            }

            // 3.检查有授权有没有过期
            if (App.DoubanAPI.IsAccessTokenOutOfDate())
            {            
                // 1)先尝试用refresh_token刷新
                DoubanSDK.GetTokenByCodeResponse response = await App.DoubanAPI.AuthorityAPI.GetTokenByRefreshToken();
                if (response.Error == RestError.ERROR_SUCCESS && !String.IsNullOrEmpty(response.access_token))
                {
                    // 成功,则重新把这个函数跑一遍
                    PreferenceHelper.SetPreference("Douban_Token", response.access_token);
                    RefreshModelDouban(progressBarHelper);
                }
                // 2)刷新不了,提示错误信息
                else
                {
                    DialogHelper.ShowToastDialog("豆瓣授权已过期,请重新登陆");
                    PreferenceHelper.RemoveDoubanLoginAccountPreference();
                    progressBarHelper.PopTask();
                }
            }
            else
            {

                String strCount = PreferenceHelper.GetPreference("Douban_RecentCount");
                if (String.IsNullOrEmpty(strCount))
                {
                    strCount = "40";
                }

                int nCount;
                try
                {
                    nCount = int.Parse(strCount);
                }
                catch (System.Exception ex)
                {
                    nCount = 40;
                }

                DoubanSDK.GetUserTimelineResponse response = await App.DoubanAPI.ShuoAPI.GetUserTimeline(followerID, nCount);
                if (response.Error == RestBase.RestError.ERROR_SUCCESS && response.ListStatus != null)
                {
                    foreach (DoubanSDK.Status status in response.ListStatus)
                    {
                        ItemViewModel model = DoubanConverter.ConvertDoubanUnionStatues(status);
                        if (model != null)
                        {
                            App.MainViewModel.DoubanItems.Add(model);
                        }
                    }
                    progressBarHelper.PopTask();
                }
                else
                {
                    if (response.Error == RestBase.RestError.ERROR_EXPIRED)
                    {
                        DialogHelper.ShowMessageDialog("豆瓣帐号已过期,请重新登陆", "温馨提示");
                        PreferenceHelper.RemoveDoubanLoginAccountPreference();
                    }
                    progressBarHelper.PopTask();
                }
            }

        }
Ejemplo n.º 10
0
 private void RefreshMainViewModel()
 {
     if (m_progressBarHelper == null)
     {
         m_progressBarHelper = new ProgressBarHelper(MainProgessBar, RefreshViewerHelper.RefreshViewItems);
     }
     RefreshViewerHelper.RefreshMainViewModel(m_progressBarHelper);
 }
Ejemplo n.º 11
0
        private void Refresh()
        {
            Name1 = "";
            Name2 = "";
            Name3 = "";
            Value1 = 0;
            Value2 = 0;
            Value3 = 0;

            if (m_progressBarHelper == null)
            {
                m_progressBarHelper = new ProgressBarHelper(LoadProgessBar, () => { });
            }
            m_progressBarHelper.PushTask();
            BaseFetcher fetcher = null;
            switch (m_type)
            {
                case EntryType.SinaWeibo:
                    fetcher = new SinaWeiboFetcher();
                    AvatarSource = PreferenceHelper.GetPreference("SinaWeibo_FollowerAvatar2");
                    Name = PreferenceHelper.GetPreference("SinaWeibo_FollowerNickName");
                    m_herID = PreferenceHelper.GetPreference("SinaWeibo_FollowerID");
                    break;
                case EntryType.Renren:
                    fetcher = new RenrenFetcher();
                    AvatarSource = PreferenceHelper.GetPreference("Renren_FollowerAvatar2");
                    Name = PreferenceHelper.GetPreference("Renren_FollowerNickName");
                    m_herID = PreferenceHelper.GetPreference("Renren_FollowerID");
                    break;
                case EntryType.Douban:
                    fetcher = new DoubanFetcher();
                    AvatarSource = PreferenceHelper.GetPreference("Douban_FollowerAvatar2");
                    Name = PreferenceHelper.GetPreference("Douban_FollowerNickName");
                    m_herID = PreferenceHelper.GetPreference("Douban_FollowerID");
                    break;
                default:
                    fetcher = SelectDefaultFetcher();
                    break;
            }
            if (fetcher == null)
            {
                DialogHelper.ShowMessageDialog("请至少登陆一个平台并设置好关注人");
                m_progressBarHelper.PopTask();
                return;
            }
            fetcher.FetchCommentManList((List<CommentMan> list) =>
            {
                m_listMan = list;
                if (list == null)
                {
                    m_progressBarHelper.PopTask();
                    return;
                }
                GetData();

                ControlPanel.Children.Clear();
                ControlPanel.Children.Add(new PotentialEnemyControl(Name1, Value1, Name2, Value2, Name3, Value3));

                m_progressBarHelper.PopTask();
            });
        }
 private void Refresh_Tapped(object sender, TappedRoutedEventArgs e)
 {
     if (m_progressBarHelper == null)
         m_progressBarHelper = new ProgressBarHelper(LoadProgessBar, () => { });
     RefreshViewerHelper.RefreshMainViewModel(m_progressBarHelper);
 }