Ejemplo n.º 1
0
 public ActionResult LoggedIn([IoCModelBinder(typeof(SetIPAddressModelBinder))] LoggedInUserAddCommentModel model)
 {
     if (ModelState.IsValid)
     {
         PostCommentResponse response = _commentsUiService.AddLoggedInComment(model);
         return(RedirectToPage(response));
     }
     return(RedirectToPage(new PostCommentResponse {
         Valid = false, RedirectUrl = Referrer.ToString()
     }));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Create synthetic comments by having each of the supplied users post the given number of comments
        /// on topics chosen randomly with replacement
        /// </summary>
        /// <param name="client">a valid SocialPlusClient</param>
        /// <param name="users">a list of UserInfo objects representing the users who will post comments</param>
        /// <param name="topics">a list of TopicInfo objects representing the topics to comment on</param>
        /// <param name="numCommentsPerUser">the number of comments each user should post</param>
        /// <returns>a list of comment handles for the created comments</returns>
        private static async Task <List <string> > CreateComments(SocialPlusClient client, List <UserInfo> users, List <TopicInfo> topics, int numCommentsPerUser)
        {
            List <string> commentHandles = new List <string>();

            for (int userIndex = 0; userIndex < users.Count; userIndex++)
            {
                for (int i = 0; i < numCommentsPerUser; i++)
                {
                    string topicHandle = topics[GenerateRandomInt(0, topics.Count)].TopicHandle;
                    PostCommentResponse postCommentResponse = await TestUtilities.PostGenericComment(client, users[userIndex].BearerToken, topicHandle);

                    string commentHandle = postCommentResponse.CommentHandle;
                    commentHandles.Add(commentHandle);
                }
            }

            return(commentHandles);
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> PostComment(string topicHandle, [FromBody] PostCommentRequest request)
        {
            string className  = "TopicCommentsController";
            string methodName = "PostComment";
            string logEntry   = $"TopicHandle = {topicHandle}, BlobHandle = {request?.BlobHandle}, BlobType = {request?.BlobType}";

            this.LogControllerStart(this.log, className, methodName, logEntry);

            var topicEntity = await this.topicsManager.ReadTopic(topicHandle);

            if (topicEntity == null)
            {
                return(this.NotFound(ResponseStrings.TopicNotFound));
            }

            if (topicEntity.AppHandle != this.AppHandle)
            {
                return(this.Unauthorized(ResponseStrings.NotAllowed));
            }

            string commentHandle = this.handleGenerator.GenerateShortHandle();

            await this.commentsManager.CreateComment(
                ProcessType.Frontend,
                commentHandle,
                request.Text,
                request.BlobType,
                request.BlobHandle,
                request.Language,
                this.UserHandle,
                topicHandle,
                topicEntity.PublisherType,
                topicEntity.UserHandle,
                DateTime.UtcNow,
                ReviewStatus.Active,
                this.AppHandle,
                null);

            // Log new comment to app metrics
            this.applicationMetrics.Comment(
                ProcessType.Frontend.ToString(),
                commentHandle,
                request.Text,
                request.BlobType.ToString(),
                request.BlobHandle,
                request.Language,
                this.UserHandle,
                topicHandle,
                topicEntity.PublisherType.ToString(),
                topicEntity.UserHandle,
                DateTime.UtcNow,
                ReviewStatus.Active.ToString(),
                this.AppHandle);

            var response = new PostCommentResponse()
            {
                CommentHandle = commentHandle
            };

            logEntry += $", CommentHandle = {commentHandle}";
            this.LogControllerEnd(this.log, className, methodName, logEntry);
            return(this.Created <PostCommentResponse>(new Uri(this.Request.RequestUri.AbsoluteUri + "/" + commentHandle), response));
        }
Ejemplo n.º 4
0
        public async Task <PostCommentResponse> SubmitComment(string comment, TimeSpan position, string commands)
        {
            if (CommentServerInfo == null)
            {
                return(null);
            }
            if (DefaultThreadSubmitInfo == null)
            {
                return(null);
            }

            if (CommentServerInfo == null)
            {
                throw new Exception("コメント投稿には事前に動画ページへのアクセスとコメント情報取得が必要です");
            }

            var threadType = DefaultThreadSubmitInfo.ThreadType;

            Debug.WriteLine("threadType:" + threadType.ToString());

            PostCommentResponse response = null;

            // 視聴中にコメント数が増えていってコメントのblock_noが100毎の境界を超える場合に対応するため
            // 投稿の試行ごとにコメント投稿先Blockを飛ばすため、コメント数に 試行数 * 100 を加算しています
            if (CommentServerInfo.CommunityThreadId.HasValue)
            {
                Debug.WriteLine($"書き込み先:{CommentServerInfo.CommunityThreadId.Value} (community thread)");

                var threadId = CommentServerInfo.CommunityThreadId.Value.ToString();
                {
                    try
                    {
                        response = await Context.Video.NMSGPostCommentAsync(
                            //                        CommentServerInfo.ServerUrl,
                            threadId,
                            DefaultThreadSubmitInfo.Ticket,
                            CommunityThreadSubmitInfo.CommentCount,
                            CommentServerInfo.ViewerUserId,
                            comment,
                            position,
                            commands,
                            threadType
                            );
                    }
                    catch
                    {
                        Debug.WriteLine("コメント投稿で致命的なエラー、投稿試行を中断します");
                        return(null);
                    }
                }
            }

            if (response?.Chat_result.Status != ChatResult.Success)
            {
                Debug.WriteLine($"書き込み先:{CommentServerInfo.DefaultThreadId} (default thread)");

                var threadId = CommentServerInfo.DefaultThreadId.ToString();

                try
                {
                    response = await Context.Video.NMSGPostCommentAsync(
                        //                        CommentServerInfo.ServerUrl,
                        threadId,
                        DefaultThreadSubmitInfo.Ticket,
                        DefaultThreadSubmitInfo.CommentCount,
                        CommentServerInfo.ViewerUserId,
                        comment,
                        position,
                        commands,
                        threadType
                        );
                }
                catch
                {
                    Debug.WriteLine("コメント投稿で致命的なエラー、投稿試行を中断します");
                    return(null);
                }
            }

            Debug.WriteLine("コメント投稿結果: " + response?.Chat_result.Status);

            if (response?.Chat_result.Status == ChatResult.Success)
            {
                DefaultThreadSubmitInfo.CommentCount = response?.Chat_result.No ?? DefaultThreadSubmitInfo.CommentCount;

                Debug.WriteLine("投稿後のコメント数: " + DefaultThreadSubmitInfo.CommentCount);
            }

            return(response);
        }