コード例 #1
0
        public static List<Comment> ReadComments(string blogIds)
        {
            List<Comment> commentList = new List<Comment>();

            using (var webClient = new WebClient())
            {
                try
                {
                    webClient.Headers.Add("Rest-User-Token", TelligentAuth());

                    var requestUrl = GetApiEndPoint("comments.xml?PageSize=100&SortOrder=Descending");
                    var xml = webClient.DownloadString(requestUrl);

                    var xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(xml);

                    XmlNodeList nodes = xmlDoc.SelectNodes("Response/Comments/Comment");

                    foreach (XmlNode xn in nodes)
                    {
                        XmlNode author = xn.SelectSingleNode("User");
                        XmlNode app = xn.SelectSingleNode("Content/Application");
                        XmlNode content = xn.SelectSingleNode("Content");

                        var commentId = xn["CommentId"].InnerText;
                        var isApproved = xn["IsApproved"].InnerText;
                        var replyCount = xn["ReplyCount"].InnerText;
                        var commentContentTypeId = xn["CommentContentTypeId"].InnerText;
                        var body = xn["Body"].InnerText;
                        var publishedDate = UnderstoodDotOrg.Common.Helpers.DataFormatHelper.FormatDate(xn["CreatedDate"].InnerText);
                        var authorId = author["Id"].InnerText;
                        var authorAvatarUrl = author["AvatarUrl"].InnerText;
                        var authorDisplayName = author["DisplayName"].InnerText;
                        var authorProfileUrl = author["ProfileUrl"].InnerText;
                        var authorUsername = author["Username"].InnerText;
                        var parentTitle = content["HtmlName"].InnerText;
                        if (app["HtmlName"].InnerText != "Articles" && app["HtmlName"].InnerText != "General"
                            && app["HtmlName"].InnerText != "Assistive Tools")
                        {
                            Comment comment = new Comment()
                            {
                                CommentId = commentId,
                                IsApproved = isApproved,
                                ReplyCount = replyCount,
                                CommentContentTypeId = commentContentTypeId,
                                Body = body,
                                PublishedDate = publishedDate,
                                AuthorId = authorId,
                                AuthorAvatarUrl = authorAvatarUrl,
                                AuthorDisplayName = authorDisplayName,
                                AuthorProfileUrl = authorProfileUrl,
                                AuthorUsername = authorUsername,
                                ParentTitle = parentTitle,
                                Url = "~/Community and Events/Blogs/" + app["HtmlName"].InnerText + "/" + parentTitle,
                            };
                            commentList.Add(comment);
                        }
                    }
                }
                catch { } // TODO: add logging
            }
            return commentList;
        }
コード例 #2
0
        public static List<Comment> ListUserComments(string username)
        {
            List<Comment> commentsList = new List<Comment>();

            using (var webClient = new WebClient())
            {
                string adminKeyBase64 = CommunityHelper.TelligentAuth();
                try
                {
                    var userId = ReadUserId(username);
                    webClient.Headers.Add("Rest-User-Token", adminKeyBase64);
                    var requestUrl = GetApiEndPoint(String.Format("comments.xml?PageSize=100&SortBy=CreatedUtcDate&SortOrder=Descending&UserId={0}", userId));
                    var xml = webClient.DownloadString(requestUrl);

                    var xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(xml);

                    XmlNodeList nodes = xmlDoc.SelectNodes("Response/Comments/Comment");

                    int nodecount = 0;
                    foreach (XmlNode xn in nodes)
                    {
                        Comment comment = new Comment(xn);
                        commentsList.Add(comment);

                        nodecount++;
                    }
                }
                catch { } // TODO: add logging
            }
            return commentsList;
        }
コード例 #3
0
        //public static List<GroupModel> GetUserGroups(string username)
        //{
        //    List<GroupModel> groupsList = new List<GroupModel>();

        //    using (var webClient = new WebClient())
        //    {
        //        if (!String.IsNullOrEmpty(username))
        //        {
        //            username = username.Trim();
        //            username = username.ToLower();
        //            string adminKeyBase64 = CommunityHelper.TelligentAuth();
        //            try
        //            {
        //                webClient.Headers.Add("Rest-User-Token", adminKeyBase64);
        //                //webClient.Headers.Add("Rest-Impersonate-User", userId);
        //                var requestUrl = GetApiEndPoint(String.Format("groups.xml?Username={0}", username));
        //                var xml = webClient.DownloadString(requestUrl);

        //                var xmlDoc = new XmlDocument();
        //                xmlDoc.LoadXml(xml);

        //                XmlNodeList nodes = xmlDoc.SelectNodes("Response/Groups/Group");
        //                foreach (XmlNode xn in nodes)
        //                {
        //                    GroupModel group = new GroupModel
        //                    {
        //                        Title = xn["Name"].InnerText,
        //                        Url = "/Community and Events/Groups/" + xn["Name"].InnerText,
        //                        Id = xn["Id"].InnerText
        //                    };
        //                    groupsList.Add(group);
        //                }
        //            }
        //            catch (Exception ex) { groupsList = null; Sitecore.Diagnostics.Error.LogError("GetuserGroups Error:\n" + ex.Message); } // TODO: add logging
        //        }
        //    }
        //    return groupsList;
        //}

        public static List<Comment> ReadComments()
        {
            List<Comment> commentList = new List<Comment>();

            using (var webClient = new WebClient())
            {
                try
                {
                    webClient.Headers.Add("Rest-User-Token", TelligentAuth());

                    var requestUrl = GetApiEndPoint("comments.xml?PageSize=100");
                    var xml = webClient.DownloadString(requestUrl);

                    var xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(xml);

                    XmlNodeList nodes = xmlDoc.SelectNodes("Response/Comments/Comment");

                    foreach (XmlNode xn in nodes)
                    {
                        Comment comment = new Comment(xn);
                        commentList.Add(comment);
                    }
                }
                catch { } // TODO: add logging
            }
            return commentList;
        }
コード例 #4
0
        public static Comment ReadComment(string commentId)
        {
            var webClient = new WebClient();

            Comment comment = null;

            string adminKeyBase64 = CommunityHelper.TelligentAuth();
            if (!String.IsNullOrEmpty(commentId))
            {
                try
                {
                    webClient.Headers.Add("Rest-User-Token", adminKeyBase64);

                    var requestUrl = GetApiEndPoint(String.Format("comments/{0}.xml", commentId));

                    var xml = webClient.DownloadString(requestUrl);
                    var xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(xml);
                    var node = xmlDoc.SelectSingleNode("Response/Comment");
                    if (node != null)
                        comment = new Comment(node);
                }
                catch (Exception ex)
                {
                    comment = null;
                }
            }
            return comment;
        }