protected void HandlePostClicked(object sender, EventArgs e) { var status = txbStatus.Text; var statusInfo = new UpdateStatusInfo(); statusInfo.Status = status; AMicroblog.PostStatus(statusInfo); Response.Redirect(Request.Path); }
public void TestStatusLifecycle() { var rnd = new Random(); var statusInfo = new UpdateStatusInfo(); statusInfo.Status = "#AMicroblogAPI# This is a test " + rnd.Next().ToString(); statusInfo.Latitude = 125.12f; statusInfo.Longitude = 125.12f; var status = AMicroblog.PostStatus(statusInfo); Assert.IsNotNull(status); Assert.AreEqual(statusInfo.Status, status.Text); // Get status var retrievedStatus = AMicroblog.GetStatus(status.ID); Assert.AreEqual(statusInfo.Status, retrievedStatus.Text); // Repost as comment var repostStatusText = "#AMicroblogAPI# This is a repost " + rnd.Next().ToString(); var repostedStatus = AMicroblog.Forward(retrievedStatus.ID, repostStatusText, true); Assert.IsNotNull(repostedStatus); Assert.AreEqual(repostStatusText, repostedStatus.Text); // Comment var commentText = "This is a comment " + rnd.Next().ToString(); var comment = AMicroblog.Comment(retrievedStatus.ID, commentText); Assert.IsNotNull(comment); Assert.AreEqual(commentText, comment.Text); // Reply comment var replyCommentText = "Reply comment " + rnd.Next().ToString(); var replyComment = AMicroblog.ReplyComment(comment.ID, replyCommentText, retrievedStatus.ID); Assert.IsNotNull(replyComment); Assert.IsTrue(replyComment.Text.Contains(replyCommentText)); var commentsCounter = AMicroblog.GetCountersOfCommentNForward(new long[] { status.ID, repostedStatus.ID }); Assert.IsNotNull(replyComment); Assert.AreEqual(2, commentsCounter.Items.Count); // Delete comment var destroiedComment = AMicroblog.DeleteComment(comment.ID); Assert.AreEqual(comment.ID, destroiedComment.ID); // Delete another comment var destroiedReplyComments = AMicroblog.DeleteComments(new long[] { replyComment.ID }); Assert.AreEqual(1, destroiedReplyComments.Items.Count); AMicroblog.DeleteStatus(status.ID); AMicroblog.DeleteStatus(repostedStatus.ID); }
private void HandlePostBtnClicked(object sender, RoutedEventArgs e) { try { var availableLen = GetAvailableStatusText(); if (availableLen < 0) { ShowMessage("Exceeds the status length limit. Try the post-as-pic option.", false); IsPostAsPic = true; return; } ClearMessage(); if (!Validate()) return; if (null != Posting) { var args = new PostingEventArgs(); args.PostingText = Text; Posting(this, args); if (!args.IsContinue) return; } ShowMessage("Posting..."); if (!this.IsPicAttached) { var updateStatusInfo = new UpdateStatusInfo() { Status = Text, Latitude = 31.22f, Longitude = 121.48f }; AMicroblog.PostStatusAsync( delegate(AsyncCallResult<StatusInfo> result) { if (result.Success) { var statusInfo = result.Data; AddStatusToView(statusInfo); ShowMessage("Message posted successfully at {0}", statusInfo.CreatedAt); } else ShowMessage("Failed to post message due to: {0}", false, result.Exception.Message); if (null != Posted) Posted(this, null); }, updateStatusInfo); } else { try { var updStatusData = new UpdateStatusWithPicInfo(); updStatusData.Status = Text; updStatusData.Pic = this.AttachedPicLocation; var postCallback = new AsyncCallback<StatusInfo>(delegate(AsyncCallResult<StatusInfo> result) { if (result.Success) { var statusInfo = result.Data; AddStatusToView(statusInfo); this.AttachedPicLocation = string.Empty; ShowMessage("Message posted successfully at {0}", statusInfo.CreatedAt); } else { this.IsPicAttached = true; ShowMessage("Failed to post message due to: {0}", false, result.Exception.Message); } }); AMicroblog.PostStatusWithPicAsync(postCallback, updStatusData); } catch (Exception ex) { ShowMessage(ex.Message, false); } } this.IsPicAttached = false; txbStatus.Clear(); } catch (Exception ex) { ShowMessage(ex.Message, false); } }
/// <summary> /// The async implementation of <see cref="PostStatus"/> /// </summary> public static void PostStatusAsync(AsyncCallback<StatusInfo> callback, UpdateStatusInfo updateStatusInfo) { // Validates arguments ValidateArgument(updateStatusInfo, "updateStatusInfo"); ValidateArgument(updateStatusInfo.Status, "updateStatusInfo.Status"); Collection<ParamPair> customParams = new Collection<ParamPair>(); customParams.Add(new ParamPair("status", RFC3986Encoder.UrlEncode(updateStatusInfo.Status))); if (updateStatusInfo.ReplyTo.HasValue) { customParams.Add(new ParamPair("in_reply_to_status_id", updateStatusInfo.ReplyTo.Value.ToString())); } if (updateStatusInfo.Latitude.HasValue && updateStatusInfo.Longitude.HasValue) { customParams.Add(new ParamPair("lat", updateStatusInfo.Latitude.Value.ToString(InvariantCulture))); customParams.Add(new ParamPair("long", updateStatusInfo.Longitude.Value.ToString(InvariantCulture))); } // The status text must be url-encoded. var requester = new OAuthHttpPost(APIUri.UpdateStatus, customParams); requester.RequestAsync(delegate(AsyncCallResult<string> result) { ProcessAsyncCallbackResponse(result, callback); }); }
public JsonResult SubmitNews( string json ) { try { News news = JsonConvert.Import<News>(json); var cates = news.NewsCategories.ToList(); news.NewsCategories.Clear(); foreach (var cate in cates) { var temp = newsService.GetCategory(cate.ID); if (temp != null) news.NewsCategories.Add(temp); } if (string.IsNullOrEmpty(news.WebFrom)) { news.WebFrom = UserContext.Instance.User.NickName; news.WebFromAddress = string.Format("/user/{0}/", UserContext.Instance.UserID); } //if (UserContext.Instance.User.((int)SysRoles.NewsEditor)) { news.State = (int)RecordState.Approved; //} else { // news.CommentsCount = (int)RecordState.Pending; //} if (news.TopicID == 0) { news.TopicID = null; } news.CreateTime = DateTime.Now; news.CreatorID = UserContext.Instance.UserID; news.AnymousComment = false; news.EnableComment = true; news.LastChanged = DateTime.Now; int newsid = newsService.CreateNews(news); bool result = newsid > 0; if (result) { HomeContent content = new HomeContent(); content.Title = news.Title; content.LinkUrl = string.Format("/news/detail/{0}", newsid); content.ContentType = (int)HomeContentType.News; content.ContentData = news.Summary; content.InsertTime = DateTime.Now; homecontentService.CreateHomeContent(content); foreach (var auth in UserContext.Instance.User.OpenAuths) { switch ((OpenAuthType)auth.OpenAuthType) { case OpenAuthType.Sinaweibo: { try { UpdateStatusInfo updateStatusInfo = new UpdateStatusInfo(); updateStatusInfo.Status = string.Format("【{0}】{1}@devtext http://www.devtext.com/news/detail/{2}", news.Title.Length > 30 ? news.Title.Substring(0, 30) : news.Title, news.Summary.Length > 90 ? news.Summary.Substring(0, 90) : news.Summary, newsid); AMicroblogAPI.AMicroblog.PostStatus(updateStatusInfo); } catch (Exception ex) { } break; } case OpenAuthType.QQ: { try { QConnectSDK.QOpenClient qzone = new QOpenClient(new OAuthToken() { AccessToken = auth.AccessTokenKey, OpenId = auth.OpenId }); if (qzone != null) { qzone.AddFeeds(news.Title.Length > 30 ? news.Title.Substring(0, 30) : news.Title, string.Format("http://www.devtext.com/news/detail/{0}", newsid)); } } catch (Exception ex) { } break; } } } } return Json(new { success = result, message = result ? "投递成功" : "投递失败" }); } catch (Exception ex) { //log.Error(ex); return Json(new { success = false, message = "发生异常,投递失败,请稍候再试" }); } }
public JsonResult SubmitPost( string json ) { try { Article article = JsonConvert.Import<Article>(json); if (string.IsNullOrEmpty(article.WebFrom)) { article.WebFrom = UserContext.Instance.User.NickName; article.WebFromAddress = "/user/" + UserContext.Instance.UserID + "/"; } var cates = article.ArticleCategories.ToList(); article.ArticleCategories.Clear(); foreach (var cate in cates) { var temp = articleService.GetArticleCategory(cate.ID); if (temp != null) article.ArticleCategories.Add(temp); } article.State = (int)RecordState.Approved; article.CreateTime = DateTime.Now; article.CreatorID = UserContext.Instance.UserID; article.AnymousComment = false; article.EnableComment = true; article.LastChanged = DateTime.Now; int aritlceid = articleService.CreateArticle(article); bool result = aritlceid > 0; if (result) { HomeContent content = new HomeContent(); content.Title = article.Title; content.LinkUrl = string.Format("/blogs/detail/{0}", aritlceid); content.ContentType = (int)HomeContentType.Article; content.ContentData = article.Summary; content.InsertTime = DateTime.Now; homecontentService.CreateHomeContent(content); foreach (var auth in UserContext.Instance.User.OpenAuths) { switch ((OpenAuthType)auth.OpenAuthType) { case OpenAuthType.Sinaweibo: { try { UpdateStatusInfo updateStatusInfo = new UpdateStatusInfo(); updateStatusInfo.Status = string.Format("【{0}】{1}@devtext http://www.devtext.com/blogs/detail/{2}", article.Title.Length > 30 ? article.Title.Substring(0, 30) : article.Title, article.Summary.Length > 90 ? article.Summary.Substring(0, 90) : article.Summary, aritlceid); AMicroblogAPI.AMicroblog.PostStatus(updateStatusInfo); } catch (Exception ex) { } break; } case OpenAuthType.QQ: { try { QConnectSDK.QOpenClient qzone = new QOpenClient(new OAuthToken() { AccessToken = auth.AccessTokenKey, OpenId = auth.OpenId }); if (qzone != null) { qzone.AddFeeds(article.Title.Length > 30 ? article.Title.Substring(0, 30) : article.Title, string.Format("http://www.devtext.com/blogs/detail/{0}", aritlceid)); } } catch (Exception ex) { } break; } } } } return Json(new { success = result, message = result ? "发布成功" : "发布失败" }); } catch (Exception ex) { //log.Error(ex); return Json(new { success = false, message = "发生异常,请检查收再试" }); } }