Exemplo n.º 1
0
        public void LoadSinaWeiboCommentByStatusID(String id, LoadSinaWeiboCommentsCompleteDelegate dele)
        {
            String MyID = PreferenceHelper.GetPreference("SinaWeibo_ID");
            if (string.IsNullOrEmpty(MyID))
                return;
            // Define a new net engine
            m_netEngine = new SdkNetEngine();
            // Define a new command base
            m_cmdBase = new SdkCmdBase
            {
                acessToken = App.SinaWeibo_AccessToken,
            };
            RestRequest request = new RestRequest();
            request.Method = WebMethod.Get;
            request.Path = "comments/show.json";
            request.AddParameter("access_token", App.SinaWeibo_AccessToken);
            request.AddParameter("id", id);
            //request.CacheOptions.Mode = Hammock.Caching.CacheMode.AbsoluteExpiration;

            ++App.Test3;
            System.Diagnostics.Debug.WriteLine("Test3: " + App.Test3);
            m_netEngine.SendRequest(request, m_cmdBase, (SdkResponse response) =>
            {
                ++App.Test2;
                System.Diagnostics.Debug.WriteLine("Test2: " + App.Test2);
                if (response.errCode == SdkErrCode.SUCCESS)
                {
                    Comments comments;
                    try
                    {
                        DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Comments));
                        comments = ser.ReadObject(response.stream) as Comments;
                        dele(comments);
                    }
                    catch (Exception)
                    {
                        dele(null);
                    }
                }
                else
                {
                    dele(null);
                }
            });
        }
Exemplo n.º 2
0
        private void SinaWeiboSend()
        {
            String statusID = m_itemViewModel.ID;
            if (String.IsNullOrEmpty(statusID))
                return;

            String commentText = StatusMessageBox.Text;

            netEngine = new SdkNetEngine();
            // Define a new command base
            cmdBase = new SdkCmdBase
            {
                acessToken = App.SinaWeibo_AccessToken,
            };

            RestRequest request = new RestRequest();
            request.Method = WebMethod.Post;
            request.Path = "comments/create.json";
            request.AddParameter("access_token", App.SinaWeibo_AccessToken);
            request.AddParameter("id", statusID);
            request.AddParameter("comment", commentText);
            request.AddParameter("comment_ori", "0");

            netEngine.SendRequest(request, cmdBase, (SdkResponse response) =>
            {
                if (response.errCode == SdkErrCode.SUCCESS)
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        MessageBox.Show("发送成功!");
                        // go back to CommentView.
                        // CommentView should refresh itself to show the newly added comment
                        NavigationService.GoBack();
                    }
                    );
                }
                else
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        MessageBox.Show("发送失败!");
                        // go back to CommentView.
                        // CommentView should refresh itself to show the newly added comment
                        NavigationService.GoBack();
                    });
                }
            });
        }
Exemplo n.º 3
0
        private bool LoadSinaWeiboItems(LoadSinaWeiboStatusesCompleteDelegate complete)
        {
            String followerID = PreferenceHelper.GetPreference("SinaWeibo_FollowerID");
            if (String.IsNullOrEmpty(followerID))
            {
                return false;
            }
            // Define a new net engine
            m_netEngine = new SdkNetEngine();

            // Define a new command base
            m_cmdBase = new cdmUserTimeline
            {
                acessToken = App.SinaWeibo_AccessToken,
                userId = followerID,
                count = "40"
            };
            // Request server, the last parameter is set as default (".xml")
            m_netEngine.RequestCmd(SdkRequestType.USER_TIMELINE, m_cmdBase,
                // Requeset callback
                delegate(SdkRequestType requestType, SdkResponse response)
                {
                    if (response.errCode == SdkErrCode.SUCCESS)
                    {
                        WStatuses statuses = null;
                        DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(WStatuses));
                        statuses = ser.ReadObject(response.stream) as WStatuses;
                        complete(statuses);
                    }
                    else
                    {
                        return;
                    }
                });
            return true;
        }
Exemplo n.º 4
0
        private void LoadSinaWeiboContent()
        {
            try
            {
                if (String.IsNullOrEmpty(PreferenceHelper.GetPreference("SinaWeibo_FollowerID")))
                {
                    MessageBox.Show("尚未设置新浪微博关注对象");
                    m_progressIndicatorHelper.PopTask();
                    return;
                }
                // Define a new net engine
                netEngine = new SdkNetEngine();

                // Define a new command base
                String strCount = PreferenceHelper.GetPreference("SinaWeibo_RecentCount");
                if (string.IsNullOrEmpty(strCount))
                {
                    strCount = "30";
                }
                String careID = PreferenceHelper.GetPreference("SinaWeibo_FollowerID");
                cmdBase = new cdmUserTimeline
                {
                    acessToken = App.SinaWeibo_AccessToken,
                    userId = careID,
                    count = strCount
                };
                // Request server, the last parameter is set as default (".xml")
                netEngine.RequestCmd(SdkRequestType.USER_TIMELINE, cmdBase,
                    // Requeset callback
                    LoadSinaWeiboContentComplete);
            }
            catch (System.Exception ex)
            {
                UmengSDK.UmengAnalytics.reportError(ex);
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show("新浪微博加载过程中发生未知错误", "悲剧了>_<", MessageBoxButton.OK);
                    m_progressIndicatorHelper.PopTask();
                });
            }
        }
Exemplo n.º 5
0
        private void SinaWeiboSend()
        {
            txtInput.IsReadOnly = true;
            netEngine = new SdkNetEngine();

            netEngine = new SdkNetEngine();

            // m_picURL为空说明发送纯文本
            if (String.IsNullOrEmpty(m_picURL))
            {
                cmdBase = new cmdUploadMessage
                {
                    status = txtInput.Text,
                    acessToken = App.SinaWeibo_AccessToken
                };
                netEngine.RequestCmd(SdkRequestType.UPLOAD_MESSAGE, cmdBase, weiboRequestCompleted);
            }
            else
            {
                cmdBase = new cmdUploadPic
                {
                    messageText = txtInput.Text,
                    picPath = m_picURL,
                    acessToken = App.SinaWeibo_AccessToken
                };
                netEngine.RequestCmd(SdkRequestType.UPLOAD_MESSAGE_PIC, cmdBase, weiboRequestCompleted);
            }
        }
Exemplo n.º 6
0
        private void GetFriendList(int cursor)
        {
            m_progressIndicatorHelper.PushTask();
            String myID = PreferenceHelper.GetPreference("SinaWeibo_ID");
            if (string.IsNullOrEmpty(myID))
                return;
            // Define a new net engine
            netEngine = new SdkNetEngine();
            // Define a new command base
            cmdBase = new SdkCmdBase
            {
                acessToken = App.SinaWeibo_AccessToken,
            };
            RestRequest request = new RestRequest();
            request.Method = WebMethod.Get;
            request.Path = "friendships/friends.json";
            request.AddParameter("access_token", App.SinaWeibo_AccessToken);
            request.AddParameter("uid", myID);
            if (cursor != -1)
            {
                request.AddParameter("cursor", cursor.ToString());
            }

            // use my uid to get the friends list.
            netEngine.SendRequest(request, cmdBase, (SdkResponse response) =>
            {
                if (response.errCode == SdkErrCode.SUCCESS)
                {
                    Friends friends;
                    try
                    {
                        DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Friends));
                        friends = ser.ReadObject(response.stream) as Friends;
                        m_nPrevois = int.Parse(friends.previous_cursor);
                        if (m_nCurrentIndex > m_listPrevios.Count - 1)
                        {
                            m_listPrevios.Add(m_nPrevois);
                        }
                        else
                        {
                            m_listPrevios[m_nCurrentIndex] = m_nPrevois;
                        }

                        m_nNext = int.Parse(friends.next_cursor);
                        m_nTotalNumber = int.Parse(friends.total_number);

                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            m_progressIndicatorHelper.PopTask();
                            Friends.Clear();
                            foreach (User friend in friends.users)
                            {
                                //App.ViewModel.Friends.Add(friend);
                                Friends.Add(friend);
                            }
                            ScrollViewer v = VisualTreeHelper.GetChild(this.ResultListBox, 0) as ScrollViewer;
                            v.ScrollToVerticalOffset(0);
                        }
                        );
                    }
                    catch (Exception)
                    {
                        m_progressIndicatorHelper.PopTask();
                        throw;
                    }
                }
                else
                {
                    m_progressIndicatorHelper.PopTask();
                }
            });
        }
Exemplo n.º 7
0
        // 得到关注用户信息
        private void refreshFollowerSinaAccountInfo()
        {
            // Define a new net engine
            SdkNetEngine netEngine = new SdkNetEngine();

            // Define a new command base
            SdkCmdBase cmdBase = new SdkCmdBase
            {
                acessToken = App.SinaWeibo_AccessToken,
            };
            RestRequest request = new RestRequest();
            request.Method = WebMethod.Get;

            request.Path = "/users/show.json";
            request.AddParameter("access_token", App.SinaWeibo_AccessToken);
            request.AddParameter("uid", PreferenceHelper.GetPreference("SinaWeibo_FollowerID"));
            netEngine.SendRequest(request, cmdBase, (SdkResponse e1) =>
            {
                if (e1.errCode == SdkErrCode.SUCCESS)
                {
                    User user = null;
                    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(User));
                    user = ser.ReadObject(e1.stream) as User;
                    String nickName = user.screen_name;
                    PreferenceHelper.SetPreference("SinaWeibo_FollowerNickName", nickName);
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        NavigationService.Navigate(new Uri("/Views/SinaWeibo/SinaAcount.xaml", UriKind.Relative));
                    });
                }
                else
                {
                    PreferenceHelper.RemovePreference("SinaWeibo_FollowerNickName");
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            MessageBox.Show("此人不存在");
                        });
                        NavigationService.Navigate(new Uri("/Views/SinaWeibo/SinaAcount.xaml", UriKind.Relative));
                    });
                }
            });
        }
Exemplo n.º 8
0
        private void GetFriendListIterator(int cursor, FetchAllFriendsCallback callback)
        {
            m_progressIndicatorHelper.PushTask();
            String myID = PreferenceHelper.GetPreference("SinaWeibo_ID");
            if (string.IsNullOrEmpty(myID))
            {
                m_progressIndicatorHelper.PopTask();
                return;
            }
            // Define a new net engine
            netEngine = new SdkNetEngine();
            // Define a new command base
            cmdBase = new SdkCmdBase
            {
                acessToken = App.SinaWeibo_AccessToken,
            };
            RestRequest request = new RestRequest();
            request.Method = WebMethod.Get;
            request.Path = "friendships/friends.json";
            request.AddParameter("access_token", App.SinaWeibo_AccessToken);
            request.AddParameter("uid", myID);
            // curosr = -1 说明是第一次进来
            if (cursor != -1)
            {
                request.AddParameter("cursor", cursor.ToString());
            }
            else
            {
                AllFriends.Clear();
            }

            // use my uid to get the friends list.
            netEngine.SendRequest(request, cmdBase, (SdkResponse response) =>
            {
                if (response.errCode == SdkErrCode.SUCCESS)
                {
                    Friends friends;
                    try
                    {
                        DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Friends));
                        friends = ser.ReadObject(response.stream) as Friends;
                        int next = int.Parse(friends.next_cursor);
                        foreach (User friend in friends.users)
                        {
                            AllFriends.Add(friend);
                        }
                        // 如果还没有遍历完,则继续遍历
                        if (next != 0)
                        {
                            GetFriendListIterator(next, callback);
                        }
                        // 遍历完后执行后续回调(其实就是从得到的名单中搜索,刷新UI)
                        else
                        {
                            callback();
                        }
                        m_progressIndicatorHelper.PopTask();
                    }
                    catch (Exception)
                    {
                        m_progressIndicatorHelper.PopTask();
                        throw;
                    }
                }
                else
                {
                    m_progressIndicatorHelper.PopTask();
                }
            });
        }
Exemplo n.º 9
0
        // 得到当前用户信息
        private void refreshMySinaAccountInfo()
        {
            // Define a new net engine
            SdkNetEngine netEngine = new SdkNetEngine();

            // Define a new command base
            SdkCmdBase cmdBase = new SdkCmdBase
            {
                acessToken = App.SinaWeibo_AccessToken,
            };
            RestRequest request = new RestRequest();
            request.Method = WebMethod.Get;

            request.Path = "/users/show.json";
            String myID = PreferenceHelper.GetPreference("SinaWeibo_ID");
            request.AddParameter("access_token", App.SinaWeibo_AccessToken);
            request.AddParameter("uid", myID);
            netEngine.SendRequest(request, cmdBase, (SdkResponse e1) =>
            {
                if (e1.errCode == SdkErrCode.SUCCESS)
                {
                    User user = null;
                    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(User));
                    user = ser.ReadObject(e1.stream) as User;
                    // TODO NULL detect
                    PreferenceHelper.SetPreference("SinaWeibo_NickName", user.screen_name);
                    PreferenceHelper.SetPreference("SinaWeibo_Avatar", user.profile_image_url);
                    // 设置显示当前用户昵称的UI
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        NavigationService.Navigate(new Uri("/Views/SinaWeibo/SinaAcount.xaml", UriKind.Relative));
                    });
                }
            });
        }
Exemplo n.º 10
0
        // 得到当前用户ID4
        // 新浪微博必须要先得到当前用户ID,再根据此ID拿到当前用户信息
        private void refreshMySinaAccountID()
        {
            // Define a new net engine
            SdkNetEngine netEngine = new SdkNetEngine();

            // Define a new command base
            SdkCmdBase cmdBase = new SdkCmdBase
            {
                acessToken = App.SinaWeibo_AccessToken,
            };
            RestRequest request = new RestRequest();
            request.Method = WebMethod.Get;

            request.Path = "/account/get_uid.json";
            request.AddParameter("access_token", App.SinaWeibo_AccessToken);
            netEngine.SendRequest(request, cmdBase, (SdkResponse e1) =>
            {
                if (e1.errCode == SdkErrCode.SUCCESS)
                {
                    try
                    {
                        JSONObject json = JSONConvert.DeserializeObject(e1.content);
                        string uid = json["uid"] as string;
                        PreferenceHelper.SetPreference("SinaWeibo_ID", uid);
                        refreshMySinaAccountInfo();
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e.ToString());
                        int a = 1;
                    }
                }
                else
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        MessageBoxResult result = MessageBox.Show("新浪微博用户尚未登陆,或登陆已过期", "提示", MessageBoxButton.OK);
                        if (result == MessageBoxResult.OK)
                        {
                            //  WeiboLogin(null, null);
                        }
                    });
                }
            });
        }