Esempio n. 1
0
        protected virtual List <Rule> EvaluateAllRules(Dictionary <string, object> dataDictionary)
        {
            if (Conditions.Any(c => !c.EvaluateCondition(dataDictionary)))
            {
                return(null);
            }

            List <Rule> rulesMet = new List <Rule>();

            rulesMet = EvaluateSubRules(dataDictionary);
            if (ReturnSelf)
            {
                rulesMet.Add(this);
            }
            if ((RuleEvaluationFlags & RuleEvaluationFlags.UsePriority) == RuleEvaluationFlags.UsePriority)
            {
                HighestPriority(ref rulesMet);
            }
            if ((RuleEvaluationFlags & RuleEvaluationFlags.UseWeight) == RuleEvaluationFlags.UseWeight)
            {
                HighestWeight(ref rulesMet);
            }

            if (rulesMet.Count > 0)
            {
                return(rulesMet);
            }
            else
            {
                return(null);
            }
        }
        public override string ToString()
        {
            var str1 = Conditions.Any() ? "\n" + string.Join("\n", Conditions) : string.Empty;
            var str2 = "[" + RightAlias + "]";

            return(string.Format("{0} [{1}].[{2}]{3}{4}", (object)SpecificationType, (object)RightSchema, (object)RightTable, string.IsNullOrWhiteSpace(RightAlias) ? (object)string.Empty : (object)(" AS [" + str2 + "]"), (object)str1));
        }
Esempio n. 3
0
 public int MaxClauseOrder()
 {
     if (!Conditions.Any())
     {
         return(0);
     }
     return(Conditions.Max(qc => qc.Order));
 }
Esempio n. 4
0
 public override bool Eval([NotNull] PlayerInfo info)
 {
     if (info == null)
     {
         throw new ArgumentNullException("info");
     }
     return(Conditions == null || Conditions.Any(t => t.Eval(info)));
 }
Esempio n. 5
0
        protected void AddQuantity(int amount = 1)
        {
            if (Conditions.Any(c => !c.Check()))
            {
                return;
            }

            ChangeQuantity(Quantity + amount);
        }
Esempio n. 6
0
        public override bool IsTrue(DateTime Value)
        {
            var ret = true;

            if (Conditions.Count > 0)
            {
                ret = Conditions.Any(x => x.IsTrue(Value));
            }
            return(ret);
        }
Esempio n. 7
0
        public void FilterQuery <T>(ref IEnumerable <T> enumerable)
        {
            if (string.IsNullOrEmpty(Column) && !Conditions.Any())
            {
                return;
            }

            enumerable      = enumerable.AsQueryable().Where(WhereCondition.Item1, WhereCondition.Item2);
            _argumentNumber = 0;
        }
 public void ValidateChildren()
 {
     if (Conditions.Any(c => c.IsValid == false) || IsValid == false)
     {
         AreChildrenValid = false;
     }
     else
     {
         AreChildrenValid = true;
     }
 }
Esempio n. 9
0
        internal string ToBodyConditions()
        {
            var body = new CWConditionBody
            {
                Conditions            = Conditions != null && Conditions.Any() ? and(Conditions) : null,
                ChildConditions       = ChildConditions != null && ChildConditions.Any() ? and(ChildConditions) : null,
                CustomFieldConditions = CustomFieldConditions != null && CustomFieldConditions.Any() ? and(CustomFieldConditions) : null,
                OrderBy = !string.IsNullOrWhiteSpace(OrderBy) ? OrderBy : null
            };

            return(JsonConvert.SerializeObject(body));
        }
Esempio n. 10
0
        /// <summary>
        /// 文字列取得
        /// </summary>
        /// <param name="index">前スペース数</param>
        /// <returns>文字列</returns>
        public override string ToString(int index = 0)
        {
            var result     = new StringBuilder();
            var indexSpace = string.Concat(Enumerable.Repeat("  ", index));

            foreach (var comment in Comments)
            {
                result.Append(indexSpace);
                result.AppendLine($"{comment}");
            }

            result.Append(indexSpace);
            if (Conditions.Any())
            {
                result.Append("else if(");
                for (var i = 0; i < Conditions.Count; i++)
                {
                    var isSetSpace = true;
                    if (i == Conditions.Count - 1)
                    {
                        isSetSpace = false;
                    }
                    else if (Conditions[i].Name == "." || Conditions[i + 1].Name == ".")
                    {
                        isSetSpace = false;
                    }
                    result.Append($"{Conditions[i].Name}");
                    if (isSetSpace)
                    {
                        result.Append(" ");
                    }
                }
                result.AppendLine(")");
            }
            else
            {
                result.AppendLine("else");
            }

            result.Append(indexSpace);
            result.AppendLine("{");
            foreach (var statement in Block)
            {
                result.AppendLine(statement.ToString(index + 1));
            }
            result.Append(indexSpace);
            result.AppendLine("}");

            return(result.ToString());
        }
Esempio n. 11
0
        public bool MeetsFilter(IRecord record)
        {
            var result = true;

            if (ConditionOperator == FilterOperator.Or)
            {
                result =
                    (!Conditions.Any() && !SubFilters.Any()) ||
                    Conditions.Any(c => c.MeetsCondition(record)) ||
                    SubFilters.Any(f => f.MeetsFilter(record));
            }
            else
            {
                result = Conditions.All(c => c.MeetsCondition(record)) &&
                         SubFilters.All(f => f.MeetsFilter(record));
            }

            return(result);
        }
Esempio n. 12
0
        public bool IsActive(IStatisticsWriter writer, IToggleContext context)
        {
            var stats = new Statistic
            {
                ToggleID  = ID,
                Timestamp = DateTime.Now,
                User      = context.GetCurrentUser()
            };

            var isActive = ConditionMode == ConditionModes.Any
                                ? Conditions.Any(c => c.IsMatch(stats, context))
                                : Conditions.All(c => c.IsMatch(stats, context));

            stats.Active = isActive;

            writer.Write(stats);

            return(isActive);
        }
Esempio n. 13
0
        public virtual Rule EvaluateRules(Dictionary <string, object> dataDictionary, RuleEvaluationFlags ruleFlags)
        {
            if (Conditions.Any(c => !c.EvaluateCondition(dataDictionary)))
            {
                return(null);
            }

            List <Rule> rulesMet = new List <Rule>();

            rulesMet = EvaluateSubRules(dataDictionary);
            if (ReturnSelf)
            {
                rulesMet.Add(this);
            }
            if ((ruleFlags & RuleEvaluationFlags.UsePriority) == RuleEvaluationFlags.UsePriority)
            {
                HighestPriority(ref rulesMet);
            }
            if ((ruleFlags & RuleEvaluationFlags.UseWeight) == RuleEvaluationFlags.UseWeight)
            {
                HighestWeight(ref rulesMet);
            }

            if (rulesMet.Count > 0)
            {
                if ((ruleFlags & RuleEvaluationFlags.ReturnRandom) == RuleEvaluationFlags.ReturnRandom)
                {
                    return(RandomRule(ref rulesMet));
                }
                else
                {
                    return(rulesMet[0]);
                }
            }
            else
            {
                return(null);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Returns true if all conditions are passing
        /// Returns true if there are no conditions
        /// Returns false if any condition is failing
        /// Returns false if any variable does not exist
        /// Returns false if there is an exception of any kind
        /// </summary>
        private bool Passing(int update)
        {
            if (!Conditions.Any())
            {
                if (_dataObject.IsDebugMode())
                {
                    var debugItemStaticDataParams = new DebugItemStaticDataParams(nameof(Passing), "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                }
                return(true);
            }

            try
            {
                var res = Conditions.Select(a => a.Eval(GetArgumentsFunc, _dataObject.Environment.HasErrors()));
                return(res.All(o => o));
            }
            catch (Exception e)
            {
                Dev2Logger.Warn("failed checking passing state of gate", e, _dataObject?.ExecutionID?.ToString());
                return(false);
            }
        }
Esempio n. 15
0
        void IRule <PromotionCart> .Initialize(PromotionCart promotionCart)
        {
            int cartValue = 0;

            if (validateCart(promotionCart))
            {
                return;
            }
            foreach (var promotionRule in _promtionRules)
            {
                bool validate = Conditions.Any(o => o.SKUid.Contains(promotionRule.SKUids) && o.CondnPassed());
                if (validate)
                {
                    continue;
                }
                switch (promotionRule.PromotionType)
                {
                case PromotionType.ItemCount:
                    cartValue = promotionCart.Products.Where(o => o.SKUId == promotionRule.SKUids).Count();
                    Conditions.Add(new CountPromo(cartValue, promotionRule));
                    break;

                case PromotionType.Combo:
                    var purchaselist = promotionCart.Products.Select(o => o.SKUId).ToArray();
                    Conditions.Add(new ComboPromo(purchaselist, promotionRule));
                    break;

                case PromotionType.Percentage:
                    cartValue = promotionCart.Products.Where(o => o.SKUId == promotionRule.SKUids).Count();
                    decimal cartPrice = promotionCart.Products.Where(o => o.SKUId == promotionRule.SKUids).Sum(o => o.Price);
                    Conditions.Add(new PercentagePromo(cartValue, cartPrice, promotionRule));
                    break;

                default: break;
                }
            }
        }
Esempio n. 16
0
        public HttpCheck(
            long id,
            Environment environment,
            Service service,
            TimeSpan interval,
            Uri url,
            IReadOnlyCollection <HttpCheckCondition> conditions,
            HttpMethod method,
            TimeSpan?connectTimeout = null,
            TimeSpan?readTimeout    = null,
            int maxContentLength    = DefaultMaxContentLength) : base(id, environment, service, interval, conditions)
        {
            if (method == default(HttpMethod))
            {
                throw new ArgumentOutOfRangeException(nameof(method));
            }
            if (interval <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(interval));
            }
            if (maxContentLength <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(maxContentLength));
            }

            Url              = url ?? throw new ArgumentNullException(nameof(url));
            Method           = method;
            ConnectTimeout   = connectTimeout ?? DefaultConnectTimeout;
            ReadTimeout      = readTimeout ?? DefaultReadTimeout;
            MaxContentLength = maxContentLength;

            if (Conditions.Any(c => c == null))
            {
                throw new ArgumentException("conditions contains a null");
            }
        }
Esempio n. 17
0
 public bool AreConditionsVerified(T input)
 {
     Conditions.ForEach(i => i.Validate(input));
     return(!Conditions.Any(c => c.ValidationErrors.Any()));
 }
Esempio n. 18
0
            public override bool IsMatch(UIApplication uiApp, CategorySet selectedCategories)
            {
                bool res = Conditions.Any(c => c.IsMatch(uiApp, selectedCategories));

                return(IsNot ? !res : res);
            }
Esempio n. 19
0
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            var methodKeyName = binder.Name;
            var baseMethod    = BaseType.GetMethod(binder.Name);

            result = null;

            //Do we meet all the conditions outlined for this method
            if (Conditions.Any(cond => cond.Item1.Equals(methodKeyName)))
            {
                var method = BaseType.GetMethods().First(m => m.Name.Equals(methodKeyName));

                if (method != null)
                {
                    var parameters = method.GetParameters();

                    int metConditions = 0;
                    for (int i = 0; i < parameters.Count(); i++)
                    {
                        var argument = parameters.ElementAt(i);
                        var value    = args[i];

                        foreach (var condition in Conditions.Where(cond => cond.Item1.Equals(methodKeyName) && cond.Item2.Equals(argument.Name, StringComparison.OrdinalIgnoreCase)))
                        {
                            if (condition.Item3(value))
                            {
                                metConditions++;
                            }
                        }
                    }

                    if (metConditions.Equals(Conditions.Count(cond => cond.Item1.Equals(methodKeyName))))
                    {
                        //We have a match
                        methodKeyName = string.Format("{0}_{1}", binder.Name, Serialization.GenerateHashKey(Conditions.Where(cond => cond.Item1.Equals(methodKeyName)).ToArray()));
                    }
                }
            }

            //Do we want to throw an error?
            if (ExpectedErrors.Any(x => methodKeyName.Equals(x.Item1)))
            {
                Exception instance = (Exception)Activator.CreateInstance(ExpectedErrors.First(x => methodKeyName.Equals(x.Item1)).Item2);

                throw instance;
            }

            //Do we exist in the list of naked or conditional-hash-appended methods
            if (MockedMembers.ContainsKey(methodKeyName) && MockedMembers[methodKeyName] is Delegate)
            {
                Delegate del = MockedMembers[methodKeyName] as Delegate;

                result = del.DynamicInvoke();

                //Try and set out parameters
                if (OutParameters.ContainsKey(methodKeyName) && baseMethod.GetParameters().Any(param => param.IsOut))
                {
                    var outValues = OutParameters[methodKeyName];

                    int i = -1;
                    foreach (var param in baseMethod.GetParameters())
                    {
                        i++;

                        if (!param.IsOut || !outValues.ContainsKey(param.Name))
                        {
                            continue;
                        }

                        args[i] = (object)outValues[param.Name];
                    }
                }

                return(true);
            }

            //We don't exist in the list at all just try to call the base method
            return(base.TryInvokeMember(binder, args, out result));
        }
Esempio n. 20
0
 /// <summary>
 /// Check if filter has any condition of a specific type.
 /// </summary>
 /// <param name="condition_guid">The condition type to check.</param>
 /// <returns>True if the filter has a condition of the specified type.</returns>
 public bool HasCondition(Guid condition_guid)
 {
     return(Conditions.Any(c => c.FieldKey == condition_guid));
 }
Esempio n. 21
0
        void IJsonSerializable.Serialize(JsonWriter writer)
        {
            // Types
            if (Types != null && Types.Any())
            {
                writer.WritePropertyName("types");
                writer.WriteStartObject();
                foreach (var type in Types)
                {
                    writer.WritePropertyName(type);
                    writer.WriteRawValue(GetTypeJson(type));
                }
                writer.WriteEndObject();
            }

            if (Instances != null && Instances.Any())
            {
                writer.WritePropertyName("instances");
                writer.WriteStartObject();

                foreach (var typeItem in Instances)
                {
                    writer.WritePropertyName(typeItem.Key);
                    writer.WriteStartObject();

                    // Serialize static property values
                    if (typeItem.Value.StaticProperties.Count > 0)
                    {
                        writer.WritePropertyName("static");
                        writer.Serialize(
                            typeItem.Value.StaticProperties.ToDictionary(
                                property => property.Name,
                                property => JsonConverter.GetPropertyValue(property, property.DeclaringType)));
                    }

                    // Serialize instances
                    foreach (var instanceItem in typeItem.Value.Instances)
                    {
                        writer.WritePropertyName(instanceItem.Key);
                        writer.Serialize(instanceItem.Value);
                    }

                    writer.WriteEndObject();
                }

                writer.WriteEndObject();
            }

            if (Conditions != null && Conditions.Any())
            {
                writer.WritePropertyName("conditions");
                writer.Serialize(Conditions);
            }

            if (Events != null && Events.Any())
            {
                writer.WritePropertyName("events");
                writer.Serialize(Events);
            }

            if (Model != null && Model.Any())
            {
                writer.WritePropertyName("model");
                writer.Serialize(Model);
            }

            if (ServerInfo != null)
            {
                writer.WritePropertyName("serverInfo");
                writer.Serialize(ServerInfo);
            }

            if (Changes != null && Changes.Any())
            {
                writer.WritePropertyName("changes");
                writer.Serialize(Changes.Where(modelEvent => !(modelEvent is ModelValueChangeEvent) || ExoWeb.IncludeInClientModel(((ModelValueChangeEvent)modelEvent).Property)));
            }
        }
Esempio n. 22
0
 public override bool EvalCondition(IDmlfNamespace ns)
 {
     return(Conditions.Any(x => x.EvalCondition(ns)));
 }
Esempio n. 23
0
 public override bool Match(FilterableObjectData obj) => Conditions.Any(x => x.Match(obj));
Esempio n. 24
0
        private string BuildWhere()
        {
            if (BlackList.Contains(Conditions.SelectMany(condition => condition.Field)))
            {
                throw new Exception($"'Field' contains blacklist word.");
            }
            if (BlackList.Contains(Conditions.SelectMany(condition => condition.Value)))
            {
                throw new Exception($"'Value' contains blacklist word.");
            }

            var where = new List <string>();

            if (Conditions.Any())
            {
                foreach (var condition in Conditions)
                {
                    switch (condition.Operator)
                    {
                    case Operator.Equals:

                        where.Add($"[{condition.Field}] = @{condition.Field}");

                        Parameters.Add(condition.Field, condition.Value);

                        break;

                    case Operator.Like:

                        where.Add($"[{condition.Field}] LIKE '%@{condition.Field}%'");

                        Parameters.Add(condition.Field, condition.Value);

                        break;

                    case Operator.LessThan:

                        where.Add($"[{condition.Field}] < @{condition.Field}");

                        Parameters.Add(condition.Field, condition.Value);

                        break;

                    case Operator.LessThanOrEqual:

                        where.Add($"[{condition.Field}] <= @{condition.Field}");

                        Parameters.Add(condition.Field, condition.Value);

                        break;

                    case Operator.GreaterThan:

                        where.Add($"[{condition.Field}] > @{condition.Field}");

                        Parameters.Add(condition.Field, condition.Value);

                        break;

                    case Operator.GreaterThanOrEqual:

                        where.Add($"[{condition.Field}] >= @{condition.Field}");

                        Parameters.Add(condition.Field, condition.Value);

                        break;

                    case Operator.Between:

                        where.Add($"[{condition.Field}] BETWEEN @{@condition.Field}_LEFT AND @{condition.Field}_RIGHT");

                        Parameters.Add($"{condition.Field}_LEFT", condition.Left);
                        Parameters.Add($"{condition.Field}_RIGHT", condition.Right);

                        break;

                    case Operator.Near:

                        where.Add($"[{condition.Field}].STDistance('POINT({condition.Latitude.ToString(Format)} {condition.Longitude.ToString(Format)})') IS NOT NULL");
                        where.Add($"[{condition.Field}].STDistance('POINT({condition.Latitude.ToString(Format)} {condition.Longitude.ToString(Format)})') < {condition.Radio}");

                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(condition.Operator), condition.Operator, null);
                    }
                }
            }

            return(!where.Any()
                ? string.Empty
                : $"WHERE {string.Join(" AND ", @where)}");
        }
Esempio n. 25
0
 internal bool HasCondition(Condition.Type type)
 {
     return(Conditions.Any(c => c.Name == type));
 }
 protected override bool InputValidates()
 {
     return(Conditions.Any(c => c.Validates()));
 }
 public bool HasCondition(string condition)
 {
     return(Conditions.Any(c => c.Name == condition));
 }
Esempio n. 28
0
 public bool Call(GameContext context)
 {
     return(Conditions.Any(c => c.Call(context)));
 }
Esempio n. 29
0
        internal void AddConditions(DicModel dic)
        {
            if (!string.IsNullOrWhiteSpace(dic.CsValue) &&
                dic.CsValue.Contains(",") &&
                dic.Option == OptionEnum.In)
            {
                var vals = dic.CsValue.Split(',').Select(it => it);
                var i    = 0;
                foreach (var val in vals)
                {
                    //
                    i++;
                    var op = OptionEnum.None;
                    if (i == 1)
                    {
                        op = OptionEnum.In;
                    }
                    else
                    {
                        op = OptionEnum.InHelper;
                    }

                    //
                    var dicx = new DicModel
                    {
                        TableOne      = dic.TableOne,
                        ClassFullName = dic.ClassFullName,
                        ColumnOne     = dic.ColumnOne,
                        TableAliasOne = dic.TableAliasOne,
                        TableTwo      = dic.TableTwo,
                        KeyTwo        = dic.KeyTwo,
                        AliasTwo      = dic.AliasTwo,
                        Param         = dic.Param,
                        ParamRaw      = dic.ParamRaw,
                        CsValue       = val,
                        ValueType     = dic.ValueType,
                        ColumnType    = dic.ColumnType,
                        Option        = op,
                        Action        = dic.Action,
                        Crud          = dic.Crud,
                        Compare       = dic.Compare,
                        TvpIndex      = dic.TvpIndex
                    };
                    AddConditions(dicx);
                }
                Conditions.Remove(dic);
            }
            else if (!string.IsNullOrWhiteSpace(dic.Param) &&
                     Conditions.Any(it => dic.Param.Equals(it.Param, StringComparison.OrdinalIgnoreCase)))
            {
                if (dic.Param.Contains("__"))
                {
                    var arr = dic.Param.Split(new string[] { "__" }, StringSplitOptions.RemoveEmptyEntries);
                    var val = Convert.ToInt32(arr[arr.Length - 1]);
                    val++;
                    dic.Param = dic.ParamRaw + "__" + val.ToString();
                }
                else
                {
                    dic.Param += "__1";
                }
                AddConditions(dic);
            }
            else
            {
                Conditions.Add(dic);
            }
        }