示例#1
0
        private void iconSend_Click(object sender, EventArgs e)
        {
            string tweet = txtContent.Text.Trim( );

            if (tweet.Length == 0)
            {
                MessageBox.Show("动弹内容请不要为空");
                return;
            }
            Dictionary <string, object> parameters = new Dictionary <string, object>
            {
                { "uid", Config.UID },
                { "msg", tweet },
            };

            #region 如果不需要传递图片
            this.g_stream = Config.Cache_TweetPic;
            if (this.g_stream == null)
            {
                (this as WP7_ControlsLib.Controls.ProgressTrayPage).LoadingText = "正在提交";
                (this as WP7_ControlsLib.Controls.ProgressTrayPage).ProgressIndicatorIsVisible = true;
                PostClient client = Tool.SendPostClient(Config.api_tweet_pub, parameters);
                client.DownloadStringCompleted += (s, e1) =>
                {
                    (this as WP7_ControlsLib.Controls.ProgressTrayPage).ProgressIndicatorIsVisible = false;
                    if (e1.Error != null)
                    {
                        System.Diagnostics.Debug.WriteLine("发布动弹时网络错误: {0}", e1.Error.Message);
                        return;
                    }
                    else
                    {
                        ApiResult result = Tool.GetApiResult(e1.Result);
                        if (result != null)
                        {
                            switch (result.errorCode)
                            {
                            case 1:
                                Config.ClearCacheTweet( );
                                Tool.To("/TweetsPage.xaml?tag=latest");
                                break;

                            case 0:
                            case -1:
                            case -2:
                                MessageBox.Show(result.errorMessage, "温馨提示", MessageBoxButton.OK);
                                break;
                            }
                        }
                    }
                };
            }
            #endregion

            #region 如果需要传递图片
            else
            {
                //Tool. AsyncPubTweetWithImage( this. g_fileName, this. g_stream, parameters );
                Tool.AsyncPubTweetWithImage("1.jpg", this.g_stream, parameters);
                //退回
                EventSingleton.Instance.ToastMessage(null, "后台正在发送此动弹");
            }
            #endregion
        }