Exemplo n.º 1
0
        public QueryRange <IContent> ExecuteQuery(IQueryParameters parameters)
        {
            var query = new ContentApprovalQuery
            {
                OnlyActiveSteps = true,
                Username        = HttpContext.Current.User.Identity.Name
            };

            return(this.ExecuteQueryInternal(query));
        }
        private string DoJob()
        {
            var approved = 0;
            var rejected = 0;

            foreach (var bot in _bots)
            {
                // Get all approvals waiting for approval
                var query = new ContentApprovalQuery
                {
                    Status          = ApprovalStatus.InReview,
                    Username        = bot.Username,
                    OnlyActiveSteps = true
                };
                var approvals = _approvalRepository.Service
                                .ListAsync <ContentApproval>(query).Result;

                // Approve or reject all of them
                foreach (var approval in approvals)
                {
                    var page = _contentRepository.Service
                               .Get <PageData>(approval.ContentLink);
                    var decision = bot.DoDecide(page);

                    if (decision.Item1 == ApprovalStatus.Approved)
                    {
                        _approvalEngine.Service.ApproveAsync(
                            approval.ID,
                            bot.Username,
                            approval.ActiveStepIndex,
                            ApprovalDecisionScope.Step).Wait();
                        approved++;
                    }
                    else if (decision.Item1 == ApprovalStatus.Rejected)
                    {
                        _approvalEngine.Service.RejectAsync(
                            approval.ID,
                            bot.Username,
                            approval.ActiveStepIndex,
                            ApprovalDecisionScope.Step).Wait();
                        rejected++;
                        // Note: Rejecting will throw an exception if the step has already been approved.
                        break;
                    }
                }
            }

            return($"Legion has {_bots.Count()} daemons, that reports {approved} approvals and {rejected} rejections.");
        }