예제 #1
0
        public ActionResult RemoveCommentRating(Guid commentRatingId)
        {
            var model = CommentProcessor.GetCommentRating(commentRatingId);

            CommentProcessor.RemoveCommentRating(commentRatingId);
            return(RedirectToAction("Details", "Products", new { id = model.StoreItemId }));
        }
예제 #2
0
        //public async Task PublishCommentDocuments()
        //{
        //    var restApi = new RestApi();
        //    var commentThreadIterator = new CommentThreadIterator(restApi);
        //    var commentThreadProvider = new CommentThreadProvider(commentThreadIterator);
        //    commentThreadProvider.Init(entry.Text, "snippet,replies");

        //    var tasks = new List<Task>();
        //    int commentCount = 0;
        //    var dateTimeBeforeCounting = DateTime.Now;

        //    //int minWorker, minIo;
        //    //ThreadPool.GetMinThreads(out minWorker, out minIo);
        //    //Console.WriteLine($"initial worker count = {minWorker}; initial IO handler count = {minIo}");
        //    //ThreadPool.SetMinThreads(4, minIo);

        //    for (int i = 0; i < 10; i++)
        //    {
        //        var newTask = Task.Run(() =>
        //        {
        //            var commentIterator = new CommentIterator(restApi);
        //            var commentProvider2 = new CommentProvider2(commentThreadProvider, commentIterator);

        //            var docBatchProvider2 = new DocumentBatchProvider2(
        //                new BatchedCommentsProviderConfig(20, 10000,
        //                    document => !string.IsNullOrWhiteSpace(document.Text)),
        //                commentProvider2
        //            );

        //            DocumentBatch docBatch = docBatchProvider2.GetNextDocumentBatch();
        //            while (docBatch.Documents.Any())
        //            {
        //                foreach (var docBatchDocument in docBatch.Documents)
        //                {
        //                    //AppendTextAndScroll($"{commentCount} - {docBatchDocument.Text}");

        //                    Interlocked.Increment(ref commentCount);
        //                }

        //                AppendTextAndScroll($"Comment count = {commentCount}");

        //                docBatch = docBatchProvider2.GetNextDocumentBatch();
        //            }
        //            Console.WriteLine($"{Task.CurrentId} ended");
        //        });
        //        tasks.Add(newTask);
        //    }

        //    await Task.WhenAll(tasks).ConfigureAwait(true);
        //    var countDuration = DateTime.Now.Subtract(dateTimeBeforeCounting);
        //    AppendTextAndScroll($"\nFinal comment count = {commentCount}, took {countDuration.TotalSeconds} seconds");
        //}

        public async Task ProcessComments()
        {
            var restApi = new RestApi();
            var commentThreadIterator = new CommentThreadIterator(restApi);
            var commentThreadProvider = new CommentThreadProvider(commentThreadIterator);

            var commentProcessor       = new CommentProcessor(restApi, commentThreadProvider, NewSentimentAnalyzer(restApi));
            var timeBeforeAnalysis     = DateTime.UtcNow;
            var averagesSummed         = 0.0d;
            var processedCommentsCount = 0;
            await commentProcessor.ProcessCommentsAsync(entry.Text, (CommentBatchResult commentBatchResult) =>
            {
                var docsInBatch      = commentBatchResult.DocumentBatchSentiment.Documents.Count;
                var sentimentAverage = commentBatchResult.DocumentBatchSentiment.Documents.Sum((arg) => arg.Score);
                var batchSentiment   = sentimentAverage / docsInBatch;

                averagesSummed         += sentimentAverage;
                processedCommentsCount += commentBatchResult.DocumentBatchSentiment.Documents.Count;

                var msg = $"Processed {processedCommentsCount} comments. Current batch score is {batchSentiment}";
                AppendTextAndScroll(msg);
            }).ConfigureAwait(true);

            var duration = DateTime.UtcNow.Subtract(timeBeforeAnalysis);
            await Task.Delay(500);

            AppendTextAndScroll($"Average sentiment score is {(averagesSummed / processedCommentsCount):0.####}");
            await Task.Delay(500);

            AppendTextAndScroll($"Sentiment analysis took {duration.TotalSeconds:0.##} seconds");
        }
예제 #3
0
        private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
#if __WASM__
            var restApi = new RestApi(new WasmHttpHandler());
#else
            var restApi = new RestApi();
#endif

            var commentThreadIterator = new CommentThreadIterator(restApi);
            var commentThreadProvider = new CommentThreadProvider(commentThreadIterator);

            var commentProcessor       = new CommentProcessor(restApi, commentThreadProvider, NewSentimentAnalyzer(restApi));
            var timeBeforeAnalysis     = DateTime.UtcNow;
            var averagesSummed         = 0.0d;
            var processedCommentsCount = 0;
            await commentProcessor.ProcessCommentsAsync(VideoIdTxtBox.Text, (CommentBatchResult commentBatchResult) =>
            {
                var docsInBatch      = commentBatchResult.DocumentBatchSentiment.Documents.Count;
                var sentimentAverage = commentBatchResult.DocumentBatchSentiment.Documents.Sum((arg) => arg.Score);
                var batchSentiment   = sentimentAverage / docsInBatch;

                averagesSummed         += sentimentAverage;
                processedCommentsCount += commentBatchResult.DocumentBatchSentiment.Documents.Count;

                var msg = $"Processed {processedCommentsCount} comments. Current batch score is {batchSentiment}";
                AppendTextAndScroll(msg).GetAwaiter().GetResult();
            }).ConfigureAwait(true);

            var duration = DateTime.UtcNow.Subtract(timeBeforeAnalysis);
            await Task.Delay(500);
            await AppendTextAndScroll($"Average sentiment score is {(averagesSummed / processedCommentsCount):0.####}");

            await Task.Delay(500);
            await AppendTextAndScroll($"Sentiment analysis took {duration.TotalSeconds:0.##} seconds");
        }
예제 #4
0
 public static void ExtractCommentBlocks(Context cx, CommentProcessor gen)
 {
     cx.Try(null, null, () =>
     {
         gen.GenerateBindings((entity, duplicationGuardKey, block, binding) =>
         {
             var commentBlock = Entities.CommentBlock.Create(cx, block);
             Action a         = () =>
             {
                 commentBlock.BindTo(entity, binding);
             };
             // When the duplication guard key exists, it means that the entity is guarded against
             // trap duplication (<see cref = "Context.BindComments(IEntity, Location)" />).
             // We must therefore also guard comment construction.
             if (duplicationGuardKey is not null)
             {
                 cx.WithDuplicationGuard(duplicationGuardKey, a);
             }
             else
             {
                 a();
             }
         });
     });
 }
예제 #5
0
        public ActionResult CommentRatingDetails(Guid id)
        {
            var model           = CommentProcessor.GetCommentRating(id);
            var reportedComment = CommentProcessor.GetUserComment(model.CommentId);

            ViewData["ReportedComment"] = reportedComment;

            return(View(model));
        }
예제 #6
0
        public ActionResult ComplaintsList(string search, int?i)
        {
            ViewBag.Message = "All Complaints";
            var models = CommentProcessor.GetCommentRating();

            return(View(models
                        .Where(x => search == null || x.OpinionText.ToLower().StartsWith(search.ToLower()))
                        .Where(x => x.Report)
                        .ToList()
                        .ToPagedList(i ?? 1, 10)));
        }
예제 #7
0
        public ActionResult PostComment(Guid storeItemId, string text)
        {
            if (text == null || text == "")
            {
                return(RedirectToAction("Details", "Products", new { id = storeItemId }));
            }

            string identity = User.Identity.Name;
            Guid   userId   = Guid.Parse(identity);

            CommentProcessor.AddComment(userId, storeItemId, text);

            return(RedirectToAction("Details", "Products", new { id = storeItemId }));
        }
예제 #8
0
        public ActionResult CommentRating(CommentRatingModel model)
        {
            string identity = User.Identity.Name;
            Guid   userId   = Guid.Parse(identity);

            if (model == null)
            {
                return(View(model));
            }

            model.OwnerId     = userId;
            model.Id          = Guid.NewGuid();
            model.DataCreated = DateTime.Now;

            CommentProcessor.AddCommentRating(model);
            return(RedirectToAction("Details", "Products", new { id = model.StoreItemId }));
        }
예제 #9
0
 public void btnRefer_Click(object sender, System.EventArgs e)
 {
     if (!Hidistro.Membership.Context.HiContext.Current.CheckVerifyCode(this.txtLeaveCode.Value))
     {
         this.ShowMessage("验证码不正确", false);
     }
     else
     {
         if (this.ValidateConvert() && (Hidistro.Membership.Context.HiContext.Current.User.UserRole == Hidistro.Membership.Core.Enums.UserRole.Member || Hidistro.Membership.Context.HiContext.Current.User.UserRole == Hidistro.Membership.Core.Enums.UserRole.Underling || this.userRegion(this.txtLeaveUserName.Value, this.txtLeavePsw.Value)))
         {
             LeaveCommentInfo leaveCommentInfo = new LeaveCommentInfo();
             leaveCommentInfo.UserName       = Globals.HtmlEncode(this.txtUserName.Text);
             leaveCommentInfo.UserId         = new int?(Hidistro.Membership.Context.HiContext.Current.User.UserId);
             leaveCommentInfo.Title          = Globals.HtmlEncode(this.txtTitle.Text);
             leaveCommentInfo.PublishContent = Globals.HtmlEncode(this.txtContent.Text);
             ValidationResults validationResults = Validation.Validate <LeaveCommentInfo>(leaveCommentInfo, new string[]
             {
                 "Refer"
             });
             string text = string.Empty;
             if (!validationResults.IsValid)
             {
                 foreach (ValidationResult current in (System.Collections.Generic.IEnumerable <ValidationResult>)validationResults)
                 {
                     text += Formatter.FormatErrorMessage(current.Message);
                 }
                 this.ShowMessage(text, false);
             }
             else
             {
                 if (CommentProcessor.InsertLeaveComment(leaveCommentInfo))
                 {
                     this.Page.ClientScript.RegisterClientScriptBlock(base.GetType(), "success", string.Format("<script>alert(\"{0}\");window.location.href=\"{1}\"</script>", "留言成功,管理员回复后即可显示", Globals.GetSiteUrls().UrlData.FormatUrl("LeaveComments")));
                 }
                 else
                 {
                     this.ShowMessage("留言失败", false);
                 }
                 this.txtTitle.Text   = string.Empty;
                 this.txtContent.Text = string.Empty;
             }
         }
     }
 }
예제 #10
0
        public ActionResult RemoveComment(Guid Id)
        {
            string identity = User.Identity.Name;
            Guid   userId   = Guid.Parse(identity);

            var model = CommentProcessor.GetUserComment(Id);

            if (model == null)
            {
                return(RedirectToAction("AllProducts", "Products"));
            }

            if (userId != model.OwnerId)
            {
                return(RedirectToAction("Details", "Products", new { id = model.StoreItemId }));
            }

            CommentProcessor.RemoveComment(Id);

            return(RedirectToAction("Details", "Products", new { id = model.StoreItemId }));
        }
예제 #11
0
 public void btnRefer_Click(object sender, EventArgs e)
 {
     if (!HiContext.Current.CheckVerifyCode(this.txtLeaveCode.Value))
     {
         this.ShowMessage("验证码不正确", false);
     }
     else if (this.ValidateConvert() && (((HiContext.Current.User.UserRole == UserRole.Member) || (HiContext.Current.User.UserRole == UserRole.Underling)) || this.userRegion(this.txtLeaveUserName.Value, this.txtLeavePsw.Value)))
     {
         LeaveCommentInfo target = new LeaveCommentInfo();
         target.UserName       = Globals.HtmlEncode(this.txtUserName.Text);
         target.UserId         = new int?(HiContext.Current.User.UserId);
         target.Title          = Globals.HtmlEncode(this.txtTitle.Text);
         target.PublishContent = Globals.HtmlEncode(this.txtContent.Text);
         ValidationResults results = Hishop.Components.Validation.Validation.Validate <LeaveCommentInfo>(target, new string[] { "Refer" });
         string            msg     = string.Empty;
         if (!results.IsValid)
         {
             foreach (ValidationResult result in (IEnumerable <ValidationResult>)results)
             {
                 msg = msg + Formatter.FormatErrorMessage(result.Message);
             }
             this.ShowMessage(msg, false);
         }
         else
         {
             if (CommentProcessor.InsertLeaveComment(target))
             {
                 this.Page.ClientScript.RegisterClientScriptBlock(base.GetType(), "success", string.Format("<script>alert(\"{0}\");window.location.href=\"{1}\"</script>", "留言成功,管理员回复后即可显示", Globals.GetSiteUrls().UrlData.FormatUrl("LeaveComments")));
             }
             else
             {
                 this.ShowMessage("留言失败", false);
             }
             this.txtTitle.Text   = string.Empty;
             this.txtContent.Text = string.Empty;
         }
     }
 }
예제 #12
0
        public ActionResult EditCommentRating(Guid commentRatingId)
        {
            var model = CommentProcessor.GetCommentRating(commentRatingId);

            return(View(model));
        }
예제 #13
0
 public ActionResult EditCommentRating(CommentRatingModel model)
 {
     CommentProcessor.UpdateCommentRating(model);
     return(RedirectToAction("Details", "Products", new { id = model.StoreItemId }));
 }
예제 #14
0
 private static void ProcessComment(Comment comment, IKernel Kernel)
 {
     using (CommentProcessor processor = Kernel.Get <CommentProcessor>()) {
         processor.Process(comment);
     }
 }
예제 #15
0
        public void SubmitComment(string text)
        {
            CommentProcessor.Process(text, Proxy, Id);
//      Task.Factory.StartNew(() => Proxy.SubmitComment(Id, text))
//        .ContinueWith(r => QueryForComments(Id));
        }