Exemple #1
0
        public void GetContent(int tid, EventHandler <DiscuzEventArgs> eHandler)
        {
            AsyncGetJsonResponse(DetailUrl(tid), (sender, e) =>
            {   //异步方式,获得帖子内容的信息Json,以开启多线程
                MessageDetail messageDetial = null;
                try
                {
                    var jsonObj = e.ResponseParseObject as JObject;
                    var replies = jsonObj["Variables"]["postlist"].Count() - 1;             //若上步错误,这里是会抛出异常的,立即终止
                    var uid     = (int)jsonObj["Variables"]["postlist"][0]["authorid"];
                    var Author  = jsonObj["Variables"]["postlist"][0]["author"].ToString();
                    var Title   = jsonObj["Variables"]["thread"]["subject"].ToString();
                    var Message = jsonObj["Variables"]["postlist"][0]["message"].ToString();

                    var locaHeadIcon = String.Format("{0}/{1}.gif", LocalTmpUsersIcon(), Author);
                    SaveAndCloseStream(locaHeadIcon, SyncGetPhotoResponse(String.Format("http://{0}/discuz/uc_server/avatar.php?uid={1}", m_sServer, uid)));    //同步获取照片若错误,会抛出异常。
                    MessageProfile profile = new MessageProfile(new UserInfo(locaHeadIcon, Author), tid, Title, Message);
                    messageDetial          = new MessageDetail(profile);

                    //加载回复
                    for (int i = 0; i < replies; i++)
                    {
                        var replyUid     = (int)jsonObj["Variables"]["postlist"][i + 1]["authorid"];
                        var replyAuthor  = jsonObj["Variables"]["postlist"][i + 1]["author"].ToString();
                        var replyTitle   = "Reply";
                        var replyMessage = jsonObj["Variables"]["postlist"][i + 1]["message"].ToString();

                        var localReplyHeadIcon = String.Format("{0}/{1}.gif", LocalTmpUsersIcon(), replyAuthor);
                        SaveAndCloseStream(localReplyHeadIcon, SyncGetPhotoResponse(String.Format("http://{0}/discuz/uc_server/avatar.php?uid={1}", m_sServer, replyUid)));
                        MessageProfile replyProfile = new MessageProfile(new UserInfo(localReplyHeadIcon, replyAuthor), 0, replyTitle, replyMessage);
                        messageDetial.AddReply(replyProfile);
                    }
                }
                catch (Exception error) { Console.WriteLine(error); messageDetial = null; }
                finally
                {
                    eHandler(this, new DiscuzEventArgs(messageDetial));
                }
            });
        }
Exemple #2
0
 public void AddReply(MessageProfile reply)
 {
     Replies.Add(reply);
 }
Exemple #3
0
 public MessageDetail(MessageProfile profile)
 {
     this.MainMessage = profile;
     this.Replies     = new List <MessageProfile>();
 }