예제 #1
0
        public ActionResult SaveForm(string keyValue, RuleEntity entity)
        {
            try
            {
                if (keyValue != "")
                {
                    entity.RuleId = keyValue;
                    RuleBLL.Instance.Update(entity);
                }
                else
                {
                    entity.RuleId     = Util.Util.NewUpperGuid();
                    entity.CreateTime = DateTime.Now;
                    RuleBLL.Instance.Add(entity);
                }

                return(Success("保存成功"));
            }
            catch (Exception ex)
            {
                ex.Data["Method"] = "RuleController>>SaveForm";
                new ExceptionHelper().LogException(ex);
                return(Error("保存失败"));
            }
        }
예제 #2
0
        public ActionResult AddRule(int ruleSetId, RuleScope scope, string ruleType)
        {
            var provider   = _ruleProvider(scope);
            var descriptor = provider.RuleDescriptors.FindDescriptor(ruleType);
            var op         = descriptor.Operators.First();

            var rule = new RuleEntity
            {
                RuleSetId = ruleSetId,
                RuleType  = ruleType,
                Operator  = op.Operator
            };

            if (descriptor.RuleType == RuleType.Boolean)
            {
                // Do not store NULL. Irritating because UI indicates 'yes'.
                var val = op == RuleOperator.IsEqualTo;
                rule.Value = val.ToString(CultureInfo.InvariantCulture).ToLower();
            }
            else if (op == RuleOperator.In || op == RuleOperator.NotIn)
            {
                // Avoid ArgumentException "The 'In' operator only supports non-null instances from types that implement 'ICollection<T>'."
                rule.Value = string.Empty;
            }

            _ruleStorage.InsertRule(rule);

            var expression = provider.VisitRule(rule);

            PrepareTemplateViewBag(ruleSetId);

            return(PartialView("_Rule", expression));
        }
예제 #3
0
        public override async Task <IRuleExpression> VisitRuleAsync(RuleEntity rule)
        {
            var expression = new RuleExpression();
            await base.ConvertRuleAsync(rule, expression);

            return(expression);
        }
예제 #4
0
        public List <RuleEntity> GetAllRules()
        {
            SqlConnection     conn     = new SqlConnection("Server = mssql.fhict.local; Database = dbi346272; User Id = dbi346272; Password = Test123");
            List <RuleEntity> entities = new List <RuleEntity>();

            try
            {
                using (conn)
                {
                    conn.Open();

                    using (var cmd = new SqlCommand("SELECT * FROM regel ORDER BY Tournament_ID", conn))
                    {
                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                RuleEntity entity = new RuleEntity();

                                entity.ID           = reader.GetInt32(reader.GetOrdinal("ID"));
                                entity.TournamentID = reader.GetInt32(reader.GetOrdinal("Tournament_ID"));
                                entity.Rulestring   = reader.GetString(reader.GetOrdinal("Regel"));

                                entities.Add(entity);
                            }
                        }
                    }
                    conn.Close();
                }
            }
            catch (SqlException)
            {
            }
            return(entities);
        }
예제 #5
0
 public override async Task<IRuleExpression> VisitRuleAsync(RuleEntity rule)
 {
     var expression = new SearchFilterExpression();
     await base.ConvertRuleAsync(rule, expression);
     expression.Descriptor = ((RuleExpression)expression).Descriptor as SearchFilterDescriptor;
     return expression;
 }
        public ActionResult AddRule(int ruleSetId, RuleScope scope, string ruleType)
        {
            var provider   = _ruleProvider(scope);
            var descriptor = provider.RuleDescriptors.FindDescriptor(ruleType);
            var op         = descriptor.Operators.First();

            var rule = new RuleEntity
            {
                RuleSetId = ruleSetId,
                RuleType  = ruleType,
                Operator  = op.Operator
            };

            if (op == RuleOperator.In || op == RuleOperator.NotIn)
            {
                // Avoid ArgumentException "The 'In' operator only supports non-null instances from types that implement 'ICollection<T>'."
                rule.Value = string.Empty;
            }

            _ruleStorage.InsertRule(rule);

            var expression = provider.VisitRule(rule);

            PrepareTemplateViewBag(ruleSetId);

            return(PartialView("_Rule", expression));
        }
        public ActionResult AddGroup(int ruleSetId, RuleScope scope)
        {
            var provider = _ruleProvider(scope);

            var group = new RuleSetEntity
            {
                IsActive   = true,
                IsSubGroup = true,
                Scope      = scope
            };

            _ruleStorage.InsertRuleSet(group);

            var groupRefRule = new RuleEntity
            {
                RuleSetId = ruleSetId,
                RuleType  = "Group",
                Operator  = RuleOperator.IsEqualTo,
                Value     = group.Id.ToString()
            };

            _ruleStorage.InsertRule(groupRefRule);

            var expression = provider.VisitRuleSet(group);

            expression.RefRuleId = groupRefRule.Id;

            return(PartialView("_RuleSet", expression));
        }
예제 #8
0
        protected virtual void ConvertRule(RuleEntity entity, RuleExpression expression)
        {
            Guard.NotNull(entity, nameof(entity));
            Guard.NotNull(expression, nameof(expression));

            var descriptor = RuleDescriptors.FindDescriptor(entity.RuleType);

            if (descriptor == null)
            {
                // A descriptor for this entity data does not exist. Allow deletion of it.
                descriptor = new InvalidRuleDescriptor(Scope)
                {
                    Name        = entity.RuleType,
                    DisplayName = entity.RuleType
                };
            }
            else if (descriptor.Scope != Scope)
            {
                throw new SmartException($"Differing rule scope {descriptor.Scope}. Expected {Scope}.");
            }

            expression.Id         = entity.Id;
            expression.RuleSetId  = entity.RuleSetId;
            expression.Descriptor = descriptor;
            expression.Operator   = entity.Operator;
            expression.RawValue   = entity.Value;
            expression.Value      = entity.Value.Convert(descriptor.RuleType.ClrType);
        }
예제 #9
0
        public override IRuleExpression VisitRule(RuleEntity rule)
        {
            var expression = new RuleExpression();

            base.ConvertRule(rule, expression);
            return(expression);
        }
예제 #10
0
        public static bool isPlayRuleOK(HREngine.Private.Rule rule, Playfield p)
        {
            bool       retval = true;
            RuleEntity entity = (RuleEntity)rule.Entity;
            RuleMethod method = (RuleMethod)rule.Method;

            // wrong target
            if (entity == RuleEntity.PlayerMinionField)
            {
                List <int> values = new List <int>();
                foreach (Minion m in p.ownMinions)
                {
                    if (method == RuleMethod.GetAttack)
                    {
                        values.Add(m.Angr);
                    }
                    if (method == RuleMethod.GetHealth)
                    {
                        values.Add(m.Hp);
                    }
                    if (method == RuleMethod.GetMana)
                    {
                        values.Add(m.Hp);
                    }
                }
            }

            if (entity == RuleEntity.EnemyMinionField)
            {
                return(false);
            }
            return(retval);
        }
예제 #11
0
        public async Task <Result> UpdateUserRules(IList <User> users)
        {
            foreach (User user in users)
            {
                UserEntity newUserEntity      = _clinicalFactory.MappingToUserEntityPlain.DefaultContext.Mapper.Map <UserEntity>(user);
                UserEntity originalUserEntity = ClinicalDbService.UserRepository.GetById(newUserEntity.UserId);

                IList <Rule> originalRules = (originalUserEntity.Rules)
                                             .Select(item => _clinicalFactory.MappingToRule.DefaultContext.Mapper.Map <Rule>(item)).ToList();


                string ruleConstraintException
                    = RuleConstraintException.CheckRulesConstraintConsistency(user.Rules.ToList(), user.Rules.Where(r => !originalRules.Any(or => or.RuleId == r.RuleId)).ToList());

                if (ruleConstraintException == null)
                {
                    IEnumerable <int> originalRulesId = originalUserEntity.Rules.Select(r => r.RuleId);
                    IEnumerable <int> editedRulesId   = newUserEntity.Rules.Select(r => r.RuleId);

                    IList <RuleEntity> rulesToAdd   = new List <RuleEntity>();
                    IEnumerable <int>  rulesIdToAdd = editedRulesId.Except(originalRulesId);
                    foreach (int ruleId in rulesIdToAdd)
                    {
                        RuleEntity segment = ClinicalDbService.RuleRepository.GetById(ruleId);
                        if (!rulesToAdd.Contains(segment))
                        {
                            rulesToAdd.Add(segment);
                        }
                    }

                    rulesToAdd.ToList().ForEach(r => originalUserEntity.Rules.Add(r));

                    IList <RuleEntity> rulesToRemove = new List <RuleEntity>();
                    IEnumerable <int>  rulesIdRemove = originalRulesId.Except(editedRulesId);

                    foreach (int ruleId in rulesIdRemove)
                    {
                        RuleEntity segment = originalUserEntity.Rules.FirstOrDefault(r => r.RuleId == ruleId);
                        if (!rulesToRemove.Contains(segment))
                        {
                            rulesToRemove.Add(segment);
                        }
                    }
                    rulesToRemove.ToList().ForEach(r => originalUserEntity.Rules.Remove(r));

                    ClinicalDbService.UserRepository.Update(originalUserEntity);

                    await ClinicalDbService.SaveAsync();
                }
                else
                {
                    Result result = Result.New(null);

                    return(result.SetError(null, ruleConstraintException));
                }
            }

            return(Result.New());
        }
예제 #12
0
        public void DeleteRule(RuleEntity rule)
        {
            Guard.NotNull(rule, nameof(rule));

            // TODO: Update parent set > hooking
            _rsRules.Delete(rule);
            InvalidateRuleSet(rule.RuleSetId);
        }
        /// <summary>Creates a new, empty RuleEntity object.</summary>
        /// <returns>A new, empty RuleEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new RuleEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewRule
            // __LLBLGENPRO_USER_CODE_REGION_END
            return(toReturn);
        }
예제 #14
0
        public override IRuleExpression VisitRule(RuleEntity rule)
        {
            var expression = new SearchFilterExpression();

            base.ConvertRule(rule, expression);
            expression.Descriptor = ((RuleExpression)expression).Descriptor as SearchFilterDescriptor;
            return(expression);
        }
예제 #15
0
 public RuleModel(RuleType ruleType, string regexSender, string regexText)
 {
     _entity = new RuleEntity
     {
         Id          = Guid.NewGuid(),
         RuleType    = (int)ruleType,
         RegexSender = regexSender,
         RegexText   = regexText
     };
 }
예제 #16
0
        static public RuleEntity dupRule(RuleEntity rule)
        {
            RuleEntity copy = new RuleEntity(rule.Id);

            duplicator.MarkEntityDirty(copy);
            copy.IsNew = true;

            copy.Condition = dupCondition(rule.Condition);

            return(copy);
        }
        public async Task <CreateRuleResult> HandleAsync(CreateRuleCommand cmd, CancellationToken ct)
        {
            await _context.semaphore.WaitAsync();

            try
            {
                var rules  = _context.Set <RuleEntity>();
                var groups = _context.Set <GroupEntity>();

                //If group does not exist throw exception
                //A rule must belong to a group

                var group = await groups.Where(g => g.ExternalId == cmd.GroupId).Select(g => g).FirstOrDefaultAsync();

                if (group == null)
                {
                    throw new NotFoundException($"Group '{cmd.GroupId}' not found");
                }

                //If Index already present throw exception
                //Two rules of the same group cannot have the same index

                var rulesDuplicateIndex = await rules.Where(r => r.Group.ExternalId == cmd.GroupId && r.Index == cmd.Index).Select(r => r).ToArrayAsync();

                if (rulesDuplicateIndex.Length > 0)
                {
                    throw new ConflictException($"Rule with index '{cmd.Index}' already exists.");
                }

                var        externalId  = Guid.NewGuid();
                RuleEntity createdRule = new RuleEntity
                {
                    ExternalId      = externalId,
                    Index           = cmd.Index,
                    Pattern         = cmd.Pattern,
                    SourceType      = cmd.SourceType,
                    DestinationType = cmd.DestinationType,
                    Group           = group
                };

                await rules.AddAsync(createdRule, ct);

                await _context.SaveChangesAsync();

                return(new CreateRuleResult
                {
                    Id = externalId
                });
            }
            finally
            {
                _context.semaphore.Release();
            }
        }
예제 #18
0
 public static RuleDetail ToDetail(this RuleEntity entity)
 {
     return(new RuleDetail
     {
         RuleId = entity.Id,
         DatePassed = entity.DatePassed,
         OriginalOrderId = entity.OriginalOrderId,
         Title = entity.OrderOfBusiness.Title,
         Description = entity.OrderOfBusiness.Description,
         Amendments = entity.Amendments.Where(a => a.IsPassed).Select(a => a.ToDetail()).ToList()
     });
 }
예제 #19
0
        public ActionResult GetPageListJson(Pagination pagination, string queryJson)
        {
            var        watch = CommonHelper.TimerStart();
            RuleEntity para  = new RuleEntity();

            if (!string.IsNullOrWhiteSpace(queryJson))
            {
                var queryParam = queryJson.ToJObject();

                //类型
                if (!queryParam["condition"].IsEmpty() && !queryParam["keyword"].IsEmpty())
                {
                    var condition = queryParam["condition"].ToString().ToLower();
                    switch (condition)
                    {
                    case "name":
                        para.Name = queryParam["keyword"].ToString();
                        break;
                    }
                }
            }

            var pageList = RuleBLL.Instance.GetPageList(para, ref pagination);

            if (pageList != null)
            {
                pageList.ForEach((o) =>
                {
                    if (o.RuleOperation != null)
                    {
                        o.RuleOperationName = ((RCHL.Model.Enums.OperationType)o.RuleOperation).ToString();
                        if (o.RuleOperation == (int)RCHL.Model.Enums.OperationType.登陆操作)
                        {
                            o.RuleDesc = string.Format("每日登陆系统增加{0}积分", o.GivePoint);
                        }
                        else
                        {
                            o.RuleDesc = string.Format("每消费{0}元赠送{1}积分", o.CosMoney, o.GivePoint);
                        }
                    }
                });
            }
            var JsonData = new
            {
                rows     = pageList,
                total    = pagination.total,
                page     = pagination.page,
                records  = pagination.records,
                costtime = CommonHelper.TimerEnd(watch)
            };

            return(Content(JsonData.ToJson()));
        }
예제 #20
0
 public RuleModel(RuleType ruleType, string regexSender, string regexText)
 {
     Id      = Guid.NewGuid();
     _entity = new RuleEntity
     {
         PartitionKey = nameof(RuleModel),
         RowKey       = Id.ToString(),
         RuleType     = (int)ruleType,
         RegexSender  = regexSender,
         RegexText    = regexText
     };
 }
예제 #21
0
        public async Task Should_not_enrich_if_statistics_not_found()
        {
            var source = new RuleEntity {
                AppId = appId
            };

            var result = await sut.EnrichAsync(source, requestContext);

            Assert.Equal(0, result.NumFailed);
            Assert.Equal(0, result.NumSucceeded);
            Assert.Null(result.LastExecuted);
        }
예제 #22
0
 private void generate(StringBuilder sb, RuleEntity rule)
 {
     newLine(sb);
     sb.AppendFormat("<rule effect=\"{0}\">", rule.Effect.Name);
     if (rule.Condition.Children.Count > 0)
     {
         m_indent++;
         generate(sb, rule.Condition, false);
         m_indent--;
     }
     newLine(sb);
     sb.Append("</rule>");
 }
예제 #23
0
        public async Task Should_get_rules_from_index()
        {
            var rule = new RuleEntity();

            A.CallTo(() => indexForRules.GetRulesAsync(app.Id, ct))
            .Returns(new List <IRuleEntity> {
                rule
            });

            var result = await sut.GetRulesAsync(app.Id, ct);

            Assert.Equal(rule, result.Single());
        }
예제 #24
0
        private IRuleExpression CreateExpression(RuleEntity ruleEntity, IRuleVisitor visitor)
        {
            if (!ruleEntity.IsGroup)
            {
                return(visitor.VisitRule(ruleEntity));
            }

            // It's a group, do recursive call
            var group = CreateExpressionGroup(ruleEntity.Value.Convert <int>(), visitor);

            group.RefRuleId = ruleEntity.Id;

            return(group);
        }
예제 #25
0
        public async Task Should_get_rule_from_index()
        {
            var rule = new RuleEntity {
                Id = DomainId.NewGuid()
            };

            A.CallTo(() => indexForRules.GetRulesAsync(app.Id, ct))
            .Returns(new List <IRuleEntity> {
                rule
            });

            var result = await sut.GetRuleAsync(app.Id, rule.Id, ct);

            Assert.Equal(rule, result);
        }
예제 #26
0
        public async Task Should_not_invoke_enricher_if_already_enriched()
        {
            var result = new RuleEntity();

            var command = CreateCommand(new MyCommand());
            var context = CreateContextForCommand(command);

            context.Complete(result);

            await sut.HandleAsync(context);

            Assert.Same(result, context.Result <IEnrichedRuleEntity>());

            A.CallTo(() => ruleEnricher.EnrichAsync(A <IEnrichedRuleEntity> ._, requestContext))
            .MustNotHaveHappened();
        }
예제 #27
0
        // Conclude OOB
        public async Task <bool> ConcludeOrderAsync(int orderOfBusinessId)
        {
            var orderOfBusiness = await _context.OrdersOfBusiness.FindAsync(orderOfBusinessId);

            if (orderOfBusiness == null || orderOfBusiness.IsTabled || !orderOfBusiness.IsActive)
            {
                return(false);
            }

            int ayes = 0, nays = 0;

            foreach (var vote in orderOfBusiness.Votes)
            {
                switch (vote.Status)
                {
                case VoteStatus.Aye:
                    ayes++;
                    break;

                case VoteStatus.Nay:
                    nays++;
                    break;
                }
            }

            orderOfBusiness.IsActive = false;

            if (ayes > nays)
            {
                if (!(orderOfBusiness is AmendmentEntity))
                {
                    var newRule = new RuleEntity {
                        DatePassed = DateTime.UtcNow, OriginalOrderId = orderOfBusiness.Id
                    };
                    _context.Rules.Add(newRule);
                }
                else
                {
                    var amendment = (AmendmentEntity)orderOfBusiness;
                    amendment.IsPassed = true;
                }

                return(await _context.SaveChangesAsync() == 2);
            }

            return(await _context.SaveChangesAsync() == 1);
        }
예제 #28
0
        private IRuleEntity SetupRule(long version, bool deleted)
        {
            var ruleId = Guid.NewGuid();

            var ruleEntity = new RuleEntity {
                Id = ruleId, AppId = appId, Version = version, IsDeleted = deleted
            };
            var ruleGrain = A.Fake <IRuleGrain>();

            A.CallTo(() => ruleGrain.GetStateAsync())
            .Returns(J.Of <IRuleEntity>(ruleEntity));

            A.CallTo(() => grainFactory.GetGrain <IRuleGrain>(ruleId, null))
            .Returns(ruleGrain);

            return(ruleEntity);
        }
예제 #29
0
        protected virtual void ConvertRule(RuleEntity entity, RuleExpression expression)
        {
            Guard.NotNull(entity, nameof(entity));
            Guard.NotNull(expression, nameof(expression));

            var descriptor = RuleDescriptors.FindDescriptor(entity.RuleType);

            if (descriptor == null || descriptor.Scope != this.Scope)
            {
                // TODO: ErrHandling and EmptynessCheck
            }

            expression.Id         = entity.Id;
            expression.Descriptor = descriptor;
            expression.Operator   = entity.Operator;
            expression.RawValue   = entity.Value;
            expression.Value      = entity.Value.Convert(descriptor.RuleType.ClrType);
        }
예제 #30
0
        public async Task Should_enrich_rule_result()
        {
            var result = A.Fake <IRuleEntity>();

            var command = CreateCommand(new MyCommand());
            var context = CreateContextForCommand(command);

            context.Complete(result);

            var enriched = new RuleEntity();

            A.CallTo(() => ruleEnricher.EnrichAsync(result, requestContext))
            .Returns(enriched);

            await sut.HandleAsync(context);

            Assert.Same(enriched, context.Result <IEnrichedRuleEntity>());
        }