static void Test1() { var manager = new FCDiscuzManager("C:/workspace/", "http://192.168.10.242/discuz", 37); manager.GetMessages(1, (sender, e) => { if (!e.isSuccess) { Console.WriteLine("failed"); return; } var Messages = e.ResponseParseObject as List <MessageProfile>; messageDetail.SetMessageMainBody(Messages[0]); foreach (var message in Messages) { Console.WriteLine("=================================================="); Console.WriteLine("tid: " + message.Identify); Console.WriteLine("Title: " + message.MessageTitle); Console.WriteLine("Content: " + message.MessageContent); Console.WriteLine("\n"); foreach (var photo in message.MessagePhotos) { Console.WriteLine("photo: " + photo["src"]); } Console.WriteLine("\t\tAuthor: " + message.User.Name); Console.WriteLine("\t\tHead: " + message.User.HeadIcon); } }); }
public async void GetContent(int tid, EventHandler <DiscuzEventArgs> eHandler) { MessageDetail messageDetial = new MessageDetail(); try { var methodViewThread = new ViewThread() { ThreadID = tid }; var posts = await ApiClient.Execute(methodViewThread); var PostID = posts.First().ID; var Title = posts.First().ThreadID.ToString(); var Content = posts.First().Content; var Author = posts.First().Author; var AuthorID = posts.First().AuthorID; var AuthorImgURL = posts.First().AuthorImg; List <Dictionary <string, string> > messagePhotos = new List <Dictionary <string, string> >(); var AuthorImgLocalPath = LocalTmpUsersIcon() + "/" + Author + ".gif"; SaveAndCloseStream(AuthorImgLocalPath, await GetPhotoResponse(GetUserImgUrl(AuthorID))); //浏览帖子内容 foreach (ThreadPost p in posts) { //获取所有回复 if (!p.IsFirst) { var replyPostID = posts.First().ID; var replyTitle = "reply"; var replyContent = posts.First().Content; var replyAuthor = posts.First().Author; var replyAuthorID = posts.First().AuthorID; var replyAuthorImgURL = posts.First().AuthorImg; var replyImgLocalPath = LocalTmpUsersIcon() + "/" + replyAuthor + ".gif"; SaveAndCloseStream(replyImgLocalPath, await GetPhotoResponse(GetUserImgUrl(replyAuthorID))); messageDetial.AddReply(new MessageProfile(new UserInfo(replyImgLocalPath, replyAuthor), replyPostID, replyTitle, replyContent)); } //获取附件 if (p.Attachments != null) { foreach (KeyValuePair <string, Attachement> a in p.Attachments) { var Attachments = new Dictionary <string, string>() { { "src", a.Value.Url } }; messagePhotos.Add(Attachments); } } } //保存附件图像 for (int i = 0; i < messagePhotos.Count; i++) { var photoURL = baseUrl + "/" + messagePhotos[i]["src"]; var fileName = photoURL.Substring(photoURL.LastIndexOf('/') + 1); var localDir = String.Format("{0}/{1}/", LocalTmpPosts(), Title); var photoLocalPath = localDir + fileName; if (!Directory.Exists(localDir)) { Directory.CreateDirectory(localDir); } //文件夹不存在,则创建文件夹 SaveAndCloseStream(photoLocalPath, GetPhotoResponse(photoURL).Result); messagePhotos[i]["src"] = photoLocalPath; } messageDetial.SetMessageMainBody(new MessageProfile(new UserInfo(AuthorImgLocalPath, Author), PostID, Title, Content, messagePhotos)); } catch (Exception e) { Console.WriteLine(e); messageDetial = null; } finally { eHandler(this, new DiscuzEventArgs(messageDetial)); } }