示例#1
0
        private Comment CleanCommentText(Comment data)
        {
            data.content = CleanContentText(data.content);

            foreach (var item in data.comments)
                CleanContentText(CleanCommentText(item).content);

            return data;
        }
示例#2
0
        public async Task GetComments(Action<CommentResponse> callback, string postId)
        {
            HttpWebRequest request = HttpWebRequest.Create("http://" + serverAddress + "/item/" + postId) as HttpWebRequest;
            request.Accept = "application/json";

            var response = await request.GetResponseAsync().ConfigureAwait(false);

            Stream stream = response.GetResponseStream();
            UTF8Encoding encoding = new UTF8Encoding();
            StreamReader sr = new StreamReader(stream, encoding);

            JsonTextReader tr = new JsonTextReader(sr);
            CommentResponse data = new JsonSerializer().Deserialize<CommentResponse>(tr);

            tr.Close();
            sr.Dispose();

            stream.Dispose();

            if (data.url.StartsWith("http") == false)
                data.url = "http://news.ycombinator.com/item?id=" + data.id;

            data = FormatCommentPost(data);

            if (data.content != null)
            {
                Comment child = new Comment();

                child.comments = new List<Comment>();
                child.content = data.content;
                child.id = null;
                child.level = 0;
                child.time_ago = data.time_ago;
                child.title = data.user + " " + data.time_ago;
                child.user = data.user;

                data.comments.Insert(0, child);
            }

            int i = data.comments.Count - 1;

            while (i >= 0)
            {
                data.comments[i] = CleanCommentText(data.comments[i]);
                data.comments[i] = FormatComment(data.comments[i]);

                i--;
            }

            callback(data);
        }
示例#3
0
        private Comment FormatComment(Comment data)
        {
            if (data.time_ago.StartsWith("0 minutes ago") == true) data.time_ago = "just now";
            data.title = data.user + " " + data.time_ago;

            for (int i = 0; i < data.comments.Count; i++)
            {
                data.comments[i] = FormatComment(data.comments[i]);
            }

            return data;
        }
示例#4
0
 public CommentItem(Comment source)
 {
     id = source.id;
     level = source.level;
     user = source.user;
     time_ago = source.time_ago;
     title = source.title;
     content = source.content;
 }