Example #1
0
        private static ConditionResult ConvertToValueConditionAndVerify(List <object> objects, IValueCondition cond)
        {
            ConditionResult result = new ConditionResult()
            {
                Condition = cond
            };

            var refValue = cond.ReferenceValue;

            if (refValue == null)
            {
                BH.Engine.Reflection.Compute.RecordNote($"A {cond.GetType().Name}'s {nameof(cond.ReferenceValue)} was null. Make sure this is intended.\nTo check for null/not null, consider using a {nameof(IsNull)} instead.");
            }


            ValueCondition valueCondition = cond.ToValueCondition();

            ConditionResult valueCondRes = VerifyCondition(objects, valueCondition);

            result.FailedObjects = valueCondRes.FailedObjects;
            result.PassedObjects = valueCondRes.PassedObjects;
            result.Pattern       = valueCondRes.Pattern;
            result.FailInfo      = valueCondRes.FailInfo;

            return(result);
        }
Example #2
0
        private static ConditionResult VerifyCondition(List <object> objects, HasId idCondition)
        {
            ConditionResult result = new ConditionResult()
            {
                Condition = idCondition
            };

            foreach (var obj in objects)
            {
                IBHoMObject bhomObj = obj as IBHoMObject;

                if (bhomObj == null || idCondition.Ids.Contains(bhomObj.FindFragment <IAdapterId>()?.Id))
                {
                    result.PassedObjects.Add(obj);
                    result.Pattern.Add(true);
                }
                else
                {
                    result.FailedObjects.Add(obj);
                    result.FailInfo.Add($"{(string.IsNullOrWhiteSpace(idCondition.Clause) ? "" : idCondition.Clause + " failed: ")}" +
                                        $"does not have the requested id.");
                    result.Pattern.Add(false);
                }
            }
            return(result);
        }
        private async void ConditionClicked(object sender, int position)
        {
            ConditionResult item = results[position];

            // Save the current state of the selected view
            bool currentlySelected = item.Selected;

            // De-select everything
            for (int i = 0; i < results.Length; i++)
            {
                results[i].Selected = false;
            }

            // Toggle the state of the selected view
            item.Selected = !currentlySelected;
            adapterPrimary.NotifyDataSetChanged();
            adapterSecondary.NotifyDataSetChanged();

            try
            {
                // Update the image
                await SetOverlayVisibility(position, item.Selected);
            }
            catch (System.OperationCanceledException)
            {
                // Unhighlight the button
                item.Selected = false;
                adapterPrimary.NotifyDataSetChanged();
                adapterSecondary.NotifyDataSetChanged();
            }
        }
Example #4
0
        public string Process(string text, XmlAttributeCollection attributes, RequestProcess process)
        {
            var fields   = text.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
            var ruleSeed = int.Parse(fields[0]);
            var colours  = (from s in fields.Skip(1) select(Colour) Enum.Parse(typeof(Colour), s, true)).ToArray();
            var rules    = GetRules(ruleSeed);

            foreach (var rule in rules[colours.Length - 3])
            {
                var conditionResult = ConditionResult.FromBool(true);
                foreach (var condition in rule.Queries)
                {
                    conditionResult = conditionResult && condition.Delegate(process, colours);
                }
                if (conditionResult)
                {
                    var result = rule.Solution.Type.Delegate(process, rule.Solution.Colour ?? 0, colours);
                    return(result.ToString());
                }
                else if (conditionResult.Code == ConditionResultCode.Unknown)
                {
                    return(conditionResult.Details !);
                }
            }

            throw new InvalidOperationException("No rules matched?!");
        }
Example #5
0
        public ConditionResult filterByMonitorsize(string input)
        {
            ConditionResult condition = new ConditionResult();

            switch (input)
            {
            case level_1:
                condition.Min = 27;
                break;

            case level_2:
                condition.Min = 23;
                condition.Max = 26;
                break;

            case level_3:
                condition.Min = 20;
                condition.Max = 22;
                break;

            case level_4:
                condition.Min = 15;
                condition.Max = 16;
                break;

            case level_5:
                condition.Min = 11;
                condition.Max = 12;
                break;
            }
            return(condition);
        }
Example #6
0
        public Task <ConditionResult> VerifyAsync(ICommandContextEx context)
        {
            // Verify that a tag has been supplied where necessary and that
            if (RequireBotTag && !context.IsBotUserTagged)
            {
                return(Task.FromResult(ConditionResult.FromError("Invalid use of command, @tag required.", true)));
            }
            // Tagged commands without a prefix value.
            else if (!context.IsProperCommand && !AcceptBotTag && context.IsBotUserTagged)
            {
                return(Task.FromResult(ConditionResult.FromError("Invalid use of command, @tag is not accepted.", true)));
            }

            var valid = false;

            if (!valid && SourceLevel.HasFlag(CommandSourceLevel.Guild))
            {
                valid = context.Channel is IGuildChannel;
            }
            if (!valid && SourceLevel.HasFlag(CommandSourceLevel.Group))
            {
                valid = context.Channel is IGroupChannel;
            }
            if (!valid && SourceLevel.HasFlag(CommandSourceLevel.DM))
            {
                valid = context.Channel is IDMChannel;
            }
            return(Task.FromResult(valid ? ConditionResult.FromSuccess() : ConditionResult.FromError($"Invalid context for command; accepted contexts: {SourceLevel}", true)));
        }
Example #7
0
        public static ConditionResult CheckCondition(ConditionType Condition, RequestType request)
        {
            ConditionEvaluationFor[XacmlFunctions.TIME_IN_RANGE] = new TimeInRangeCondition();

            ConditionResult Result = XAML_Common.ConditionResult.DontCare;

            if (Condition == null)
            {
                return(XAML_Common.ConditionResult.True);
            }

            ApplyType Item = Condition.Item as ApplyType;

            bool ConditionResult = ConditionEvaluationFor[Item.FunctionId].EvaluateConditionFor(Item, request);

            if (ConditionResult)
            {
                Result = XAML_Common.ConditionResult.True;
            }
            else if (!ConditionResult)
            {
                Result = XAML_Common.ConditionResult.False;
            }
            else
            {
                Result = XAML_Common.ConditionResult.DontCare;
            }

            return(Result);
        }
Example #8
0
        public bool Equals(RunningScript other)
        {
            if (other == null)
            {
                return(false);
            }

            return(NextScriptPointer.Equals(other.NextScriptPointer) &&
                   PrevScriptPointer.Equals(other.PrevScriptPointer) &&
                   Name.Equals(other.Name) &&
                   InstructionPointer.Equals(other.InstructionPointer) &&
                   Stack.SequenceEqual(other.Stack) &&
                   StackPointer.Equals(other.StackPointer) &&
                   Locals.SequenceEqual(other.Locals) &&
                   TimerA.Equals(other.TimerA) &&
                   TimerB.Equals(other.TimerB) &&
                   ConditionResult.Equals(other.ConditionResult) &&
                   IsMissionScript.Equals(other.IsMissionScript) &&
                   ClearMessages.Equals(other.ClearMessages) &&
                   WakeTime.Equals(other.WakeTime) &&
                   AndOrState.Equals(other.AndOrState) &&
                   NotFlag.Equals(other.NotFlag) &&
                   WastedBustedCheckEnabled.Equals(other.WastedBustedCheckEnabled) &&
                   WastedBustedCheckResult.Equals(other.WastedBustedCheckResult) &&
                   MissionFlag.Equals(other.MissionFlag));
        }
Example #9
0
        public ConditionResult filterByCapacity(string input)
        {
            ConditionResult condition = new ConditionResult();

            switch (input)
            {
            case level_1:
                condition.Min = 0;
                condition.Max = 120;
                break;

            case level_2:
                condition.Min = 121;
                condition.Max = 250;
                break;

            case level_3:
                condition.Min = 251;
                condition.Max = 500;
                break;

            case level_4:
                condition.Min = 501;
                condition.Max = 1000;
                break;

            case level_5:
                condition.Min = 1001;
                break;
            }
            return(condition);
        }
Example #10
0
    protected override void OnExecute(BattleSystem battleSystem)
    {
        // Evaluate pre attack conditions.
        ConditionResult result = null;

        foreach (var condition in Source.GetComponents <Condition>())
        {
            result = condition.Evaluate();

            if (result.Type == ConditionResultType.Removed)
            {
                //Source.Status.RemoveCondition(result.Condition.Type);
                result.Condition.Remove();

                // TODO: Do this later?
                Destroy(result.Condition);
            }
            else
            {
                // Show OnEvaluate message.
                if (result.Parameters.OnEvaluateMessage != string.Empty)
                {
                    battleSystem.Log(BattleLogger.Format(result.Parameters.OnEvaluateMessage, Source, Source));
                }

                if (result.Type == ConditionResultType.Failed)
                {
                    break;
                }
            }
        }

        if (result != null && result.Type == ConditionResultType.Failed)
        {
            // Show OnFail message.
            if (result.Parameters.OnFailMessage != string.Empty)
            {
                battleSystem.Log(BattleLogger.Format(result.Parameters.OnFailMessage, Source, Source));
            }

            // Instantiate OnFailAction and register action.
            if (result.Parameters.OnFailAction != null)
            {
                var action = Instantiate(result.Parameters.OnFailAction);
                action.SetReciever(Source);
                battleSystem.RegisterAction(action);
            }
        }
        else
        {
            battleSystem.Log(Source.name + " used {0}!", name.Replace("(Clone)", ""));

            // Relay to other attached components.
            Relay(battleSystem);
        }

        TriggerCompletion();
    }
Example #11
0
        public async Task <ConditionResult> DoCheck(List <EventFact> eventFacts, List <EventFactsType> neededEventFactsTypes, string sourceOutputText)
        {
            await Task.Delay(1000);

            var result = new ConditionResult();

            result.Type       = ConditionResultType.CompletedWithIssue;
            result.OutputText = "Issue found!";
            return(result);
        }
Example #12
0
 private PropertyComposition.Failure ConditionFailure(
     Path parentPath,
     ConditionResult conditionResult)
 {
     return(new PropertyComposition.Failure(
                _propertyComposer.Name,
                new PropertyCompositionFailed(
                    compositionPath: parentPath,
                    propertyName: _propertyComposer.Name,
                    innerErrors: conditionResult.Errors)));
 }
Example #13
0
        /***************************************************/
        /**** Private Methods                           ****/
        /***************************************************/

        private static SpecificationResult VerifySpecification(List <object> objects, Specification specification)
        {
            // First apply filter to get relevant objects
            ConditionResult filterResult = VerifyConditions(objects, specification.FilterConditions);

            // Then apply the check to the filteredObject
            ConditionResult checkResult = VerifyConditions(filterResult.PassedObjects, specification.CheckConditions);


            return(PopulateSpecificationResult(specification, filterResult, checkResult));
        }
Example #14
0
 private ElementComposition ConditionFailure(
     Path parentPath,
     int index,
     ConditionResult conditionResult)
 {
     return(new ElementComposition.Failure(
                index,
                new ElementCompositionFailed(
                    compositionPath: parentPath,
                    index: index,
                    innerErrors: conditionResult.Errors)));
 }
        public void OnArea(ConditionType eventType, Collider other)
        {
            if (Once == true && Result != ConditionResult.NEVER)
            {
                return;
            }

            if (Type == eventType)
            {
                Result = ConditionResult.CONDITION_ON;
            }
        }
Example #16
0
        public void OnArea(ConditionType eventType, Collider other)
        {
            if (Once == true && Result != ConditionResult.NEVER)
            {
                return;
            }

            if (Type == eventType)
            {
                Result = ConditionResult.CONDITION_ON;
            }
        }
Example #17
0
        /// <summary>
        /// Callback for when a cell is tapped from either <see cref="primaryTableView"/> or <see cref="secondaryTableView"/>
        /// </summary>
        /// <param name="index">The index of the cell</param>
        public async void HandleCellClick(int index)
        {
            ConditionResult result = conditionResults[index];

            // Get cell selected and its current highlight state
            bool curHighlightState = result.Selected;

            // Re-assign displayed image
            imageView.Image = InputImage;

            // Dispose of blended image
            blendedImage?.Dispose();

            // Set all cells to un-highlight
            foreach (ConditionResult model in conditionResults)
            {
                model.Selected = false;
            }

            result.Selected = !curHighlightState;

            // Reload all cells
            primaryTableView.ReloadData();
            secondaryTableView.ReloadData();

            // If result is not selected, no need to generate a CAM
            if (!result.Selected)
            {
                return;
            }

            // Generate blended CAM
            try
            {
                blendedImage = await GenerateBlendedCAMImage(conditionResults[index].CAM, result.HighlightColor);

                imageView.Image       = blendedImage;
                imageView.ContentMode = UIViewContentMode.ScaleAspectFit;
            }
            catch (OperationCanceledException)
            {
                // Unhighlight the button
                result.Selected = false;

                // Reload all cells
                primaryTableView.ReloadData();
                secondaryTableView.ReloadData();

                System.Diagnostics.Debug.WriteLine("CAM overlay task cancelled");
            }
        }
        public async Task ExecCompletes_Issue943()
        {
            int hashHit = 0, hashMiss = 0, expireHit = 0, expireMiss = 0;

            using (var conn = Create())
            {
                var db = conn.GetDatabase();
                for (int i = 0; i < 40000; i++)
                {
                    RedisKey key = Me();
                    await db.KeyDeleteAsync(key);

                    HashEntry[] hashEntries = new HashEntry[]
                    {
                        new HashEntry("blah", DateTime.UtcNow.ToString("R"))
                    };
                    ITransaction    transaction  = db.CreateTransaction();
                    ConditionResult keyNotExists = transaction.AddCondition(Condition.KeyNotExists(key));
                    Task            hashSetTask  = transaction.HashSetAsync(key, hashEntries);
                    Task <bool>     expireTask   = transaction.KeyExpireAsync(key, TimeSpan.FromSeconds(30));
                    bool            committed    = await transaction.ExecuteAsync();

                    if (committed)
                    {
                        if (hashSetTask.IsCompleted)
                        {
                            hashHit++;
                        }
                        else
                        {
                            hashMiss++;
                        }
                        if (expireTask.IsCompleted)
                        {
                            expireHit++;
                        }
                        else
                        {
                            expireMiss++;
                        }
                        await hashSetTask;
                        await expireTask;
                    }
                }
            }

            Writer.WriteLine($"hash hit: {hashHit}, miss: {hashMiss}; expire hit: {expireHit}, miss: {expireMiss}");
            Assert.Equal(0, hashMiss);
            Assert.Equal(0, expireMiss);
        }
Example #19
0
 /// <summary>
 /// Fills in or modifies the given display info for the item</summary>
 /// <param name="item">Item</param>
 /// <param name="info">Display info to update</param>
 public void GetInfo(object item, ItemInfo info)
 {
     info.Label      = Enabled.ToString();
     info.Properties =
         new[]
     {
         File.Name,
         Line.ToString(),
         Condition,
         ConditionEnabled.ToString(),
         ConditionResult.ToString(),
         (UseFunctionEnvironment ? "Environment" : "Global")
     };
     info.ImageIndex = info.GetImageIndex(Atf.Resources.DataImage);
     info.IsLeaf     = true;
 }
Example #20
0
        /// <param name="text">Usage: [rule seed] [colour] [label]?</param>
        public string Process(string text, XmlAttributeCollection attributes, RequestProcess process)
        {
            var fields = text.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
            var colour = (Colour)Enum.Parse(typeof(Colour), fields[1], true);
            var rules  = GetRules(int.Parse(fields[0]));

            if (fields.Length > 2)
            {
                // Initial stage
                var             label       = (Label)Enum.Parse(typeof(Label), fields[2], true);
                InitialSolution?instruction = null;

                foreach (var rule in rules.InitialRules)
                {
                    var result = ConditionResult.FromBool(true);
                    foreach (var condition in rule.Conditions)
                    {
                        result = result && condition.Delegate(process, new ButtonData()
                        {
                            Colour = colour, Label = label
                        });
                    }

                    if (result.Code == ConditionResultCode.True)
                    {
                        instruction = rule.Solution;
                        break;
                    }
                    else if (result.Code == ConditionResultCode.Unknown)
                    {
                        return(result.Details !);
                    }
                }
                if (instruction == null)
                {
                    throw new InvalidOperationException("No rules matched?!");
                }

                return(instruction.Value.ToString());
            }
            else
            {
                // Held stage
                var rule = rules.HeldRules.FirstOrDefault(r => r.Colour == colour) ?? rules.HeldRules.Single(r => r.Colour == null);
                return($"{rule.Solution.Type} {rule.Solution.Digit}");
            }
        }
Example #21
0
        private static ConditionResult VerifyCondition(List <object> objects, IsInZone isInZone)
        {
            ConditionResult result = new ConditionResult()
            {
                Condition = isInZone
            };
            List <string> failInfo = new List <string>();

            foreach (var obj in objects)
            {
                bool passed = false;

                IObject iObj = obj as IObject;
                if (iObj != null)
                {
                    foreach (var cv in isInZone.ClosedVolumes)
                    {
                        if (BH.Engine.CIH.Query.IsContaining(cv, iObj, isInZone.ContainmentRule))
                        {
                            passed = true;
                            break;
                        }
                    }

                    if (passed)
                    {
                        result.PassedObjects.Add(obj);
                    }
                    else
                    {
                        result.FailedObjects.Add(obj);
                        failInfo.Add($"{(string.IsNullOrWhiteSpace(isInZone.Clause) ? "" : isInZone.Clause + " failed: ")}" +
                                     $"{isInZone.ToString()}");
                    }
                }
                else
                {
                    result.FailedObjects.Add(obj);
                    failInfo.Add($"Could not evaluate containment for an object of type `{obj.GetType().Name}`.");
                }

                result.Pattern.Add(passed);
            }

            result.FailInfo = failInfo;
            return(result);
        }
        private static ConditionResult VerifyCondition(List <object> objects, IsInDomain domainCondition)
        {
            ConditionResult result = new ConditionResult()
            {
                Condition = domainCondition
            };
            List <string> failInfo = new List <string>();

            foreach (var obj in objects)
            {
                bool passed = false;

                object value = obj.ValueFromSource(domainCondition.PropertyName);
                double numericalValue;
                double tolerance;
                double.TryParse(domainCondition.Tolerance.ToString(), out tolerance);

                if (double.TryParse(value?.ToString(), out numericalValue))
                {
                    passed = NumberInDomain(numericalValue, domainCondition.Domain, tolerance);
                }
                else if (obj is DateTime)
                {
                    DateTime?dt = obj as DateTime?;
                    passed = NumberInDomain(dt.Value.Ticks, domainCondition.Domain, tolerance);
                }

                if (passed)
                {
                    result.PassedObjects.Add(obj);
                }
                else
                {
                    result.FailedObjects.Add(obj);
                    failInfo.Add($"{(string.IsNullOrWhiteSpace(domainCondition.Clause) ? "" : domainCondition.Clause + " failed: ")}" +
                                 $"value is {value}, which is not in ({domainCondition.Domain.Min},{domainCondition.Domain.Max}).");
                }

                result.Pattern.Add(passed);
            }

            result.FailInfo = failInfo;
            return(result);
        }
        private static ConditionResult VerifyCondition(List <object> objects, FragmentCondition fragmentCondition)
        {
            ConditionResult result = new ConditionResult()
            {
                Condition = fragmentCondition
            };

            foreach (var obj in objects)
            {
                IBHoMObject bhomObj = obj as IBHoMObject;

                if (bhomObj != null && !IsAnyConditionNull(fragmentCondition.Condition, nameof(FragmentCondition) + "." + nameof(FragmentCondition.Condition)))
                {
                    // If there is only one fragment of the specified type, no problem, the check will be done on it.
                    // If the specified type is a parent type, all fragments of that type will be retrieved:
                    // the condition will have to be satisfied for all fragments (forced AND).
                    // To have an OR condition on the child fragments,
                    // multiple conditions that target the individual fragment child type combined with a logical OR condition is needed.
                    List <IFragment> fragments = bhomObj.GetAllFragments(fragmentCondition.FragmentType);

                    ConditionResult subConditionResult = new ConditionResult();
                    subConditionResult = IVerifyCondition(fragments.OfType <object>().ToList(), fragmentCondition.Condition);

                    // Forced AND on all child fragments. See comment above.
                    if (subConditionResult.Pattern.TrueForAll(v => v == true))
                    {
                        result.PassedObjects.Add(obj);
                        result.Pattern.Add(true);
                    }
                    else
                    {
                        result.FailedObjects.Add(obj);
                        result.Pattern.Add(false);
                    }
                }
                else
                {
                    // If the object is not a BHoMObject, the condition can't apply to it.
                    result.FailedObjects.Add(obj);
                    result.Pattern.Add(false);
                }
            }
            return(result);
        }
Example #24
0
        private async Task <UpsertResult> UpsertRowInternal(MembershipEntry entry, TableVersion tableVersion, bool updateTableVersion, bool allowInsertOnly)
        {
            var tx     = _db.CreateTransaction();
            var rowKey = entry.SiloAddress.ToString();

            if (updateTableVersion)
            {
                if (tableVersion.Version == 0 && "0".Equals(tableVersion.VersionEtag, StringComparison.Ordinal))
                {
                    await _db.HashSetAsync(_clusterKey, TableVersionKey, SerializeVersion(tableVersion), When.NotExists);
                }

                tx.HashSetAsync(_clusterKey, TableVersionKey, SerializeVersion(tableVersion)).Ignore();
            }

            var             versionCondition = tx.AddCondition(Condition.HashEqual(_clusterKey, TableVersionKey, SerializeVersion(Predeccessor(tableVersion))));
            ConditionResult insertCondition  = null;

            if (allowInsertOnly)
            {
                insertCondition = tx.AddCondition(Condition.HashNotExists(_clusterKey, rowKey));
            }

            tx.HashSetAsync(_clusterKey, rowKey, Serialize(entry)).Ignore();

            var success = await tx.ExecuteAsync();

            if (success)
            {
                return(UpsertResult.Success);
            }

            if (!versionCondition.WasSatisfied)
            {
                return(UpsertResult.Conflict);
            }

            if (!insertCondition.WasSatisfied)
            {
                return(UpsertResult.Failure);
            }

            return(UpsertResult.Failure);
        }
    public void CheckConditions()
    {
        ConditionResult result = verifyResult();

        switch (result)
        {
        case ConditionResult.SUCCESS:
            m_actionOnSuccess();
            break;

        case ConditionResult.FAILURE:
            m_actionOnFailure();
            break;

        case ConditionResult.NONE:
            // do nothing
            break;
        }
    }
        private static ConditionResult VerifyCondition(List <object> objects, IsNull valueNullCondition)
        {
            ConditionResult result = new ConditionResult()
            {
                Condition = valueNullCondition
            };
            List <string> info = new List <string>();

            var requiredState = valueNullCondition.NullCondition;

            foreach (var obj in objects)
            {
                bool   passed = false;
                object value  = obj.ValueFromSource(valueNullCondition.PropertyName);

                if (requiredState == ValueNullConditions.MustBeNull)
                {
                    passed = value == null;
                }
                else if (requiredState == ValueNullConditions.MustBeNotNull)
                {
                    passed = value != null;
                }

                if (passed)
                {
                    result.PassedObjects.Add(obj);
                }
                else
                {
                    result.FailedObjects.Add(obj);
                    info.Add($"{(string.IsNullOrWhiteSpace(valueNullCondition.Clause) ? "" : valueNullCondition.Clause + " failed: ")}" +
                             $"{valueNullCondition.PropertyName} was {value ?? "empty"}, which does not respect '{valueNullCondition.ToString()}'.");
                }

                result.Pattern.Add(passed);
            }

            result.FailInfo = info;
            return(result);
        }
Example #27
0
            public ConditionResult EvaluateConditions(RequestProcess process, Colour colour, Label label)
            {
                var result = new ConditionResult(ConditionResultCode.True);

                foreach (var condition in this.Conditions)
                {
                    var result2 = condition.Delegate(process, new ButtonData()
                    {
                        Colour = colour, Label = label
                    });
                    if (result2.Code == ConditionResultCode.False)
                    {
                        return(result2);
                    }
                    if (result2.Code == ConditionResultCode.Unknown && result.Code != ConditionResultCode.Unknown)
                    {
                        result = result2;
                    }
                }
                return(result);
            }
Example #28
0
        private static ConditionResult VerifyCondition(List <object> objects, IsInSet setCondition)
        {
            ConditionResult result = new ConditionResult()
            {
                Condition = setCondition
            };
            List <string> info = new List <string>();

            foreach (var obj in objects)
            {
                bool passed = false;

                object value = obj.ValueFromSource(setCondition.PropertyName);

                if (setCondition.ComparisonConfig != null) // use hashComparer
                {
                    passed = setCondition.Set.Contains(value, new HashComparer <object>(setCondition.ComparisonConfig));
                }
                else if (setCondition.Set.Contains(value)) // use default comparer
                {
                    passed = true;
                }

                if (passed)
                {
                    result.PassedObjects.Add(obj);
                }
                else
                {
                    result.FailedObjects.Add(obj);
                    info.Add($"{(string.IsNullOrWhiteSpace(setCondition.Clause) ? "" : setCondition.Clause + " failed: ")}" +
                             $": value of {setCondition.PropertyName} is {value}, which is not among: {string.Join(" | ", setCondition.Set.Select(v => v.ToString()))}.");
                }

                result.Pattern.Add(passed);
            }

            result.FailInfo = info;
            return(result);
        }
Example #29
0
        private static ConditionResult VerifyCondition(List <object> objects, IsInBoundingBox bbc)
        {
            ConditionResult result = new ConditionResult()
            {
                Condition = bbc
            };
            List <string> failInfo = new List <string>();

            foreach (var obj in objects)
            {
                bool passed = false;

                IObject iObj = obj as IObject;
                if (iObj != null)
                {
                    passed = BH.Engine.CIH.Query.IsContaining(bbc.BoundingBox, iObj, bbc.ContainmentRule);
                    if (passed)
                    {
                        result.PassedObjects.Add(obj);
                    }
                    else
                    {
                        result.FailedObjects.Add(obj);
                        failInfo.Add($"{(string.IsNullOrWhiteSpace(bbc.Clause) ? "" : bbc.Clause + " failed: ")}" +
                                     $"Object not in the specified Bounding Box.");
                    }
                }
                else
                {
                    result.FailedObjects.Add(obj);
                    failInfo.Add($"Could not evaluate containment for an object of type `{obj.GetType().Name}`.");
                }

                result.Pattern.Add(passed);
            }

            result.FailInfo = failInfo;
            return(result);
        }
        public async Task <IEnumerable <string> > DequeueAsync(string queue, uint number)
        {
            var queueKey = Key.ForQueue(queue);

            _lengthCondition = _transaction.AddCondition(Condition.SortedSetLengthGreaterThan(queueKey, number - 1));
            var results = await _transaction.ScriptEvaluateAsync(_zpopMinScript,
                                                                 new { key = (RedisKey)queueKey, count = $"{number}" });

            var returned = new List <string>();

            foreach (var r in (RedisResult[])results)
            {
                var arr = (RedisResult[])r;
                if (arr.Length != 2)
                {
                    continue;
                }
                returned.Add((string)arr[0]);
            }

            return(returned);
        }
Example #31
0
        public ConditionResult filterByCPU(string input)
        {
            ConditionResult condition = new ConditionResult();

            switch (input)
            {
            case level_1:
                condition.Min = 0;
                condition.Max = 1.61;
                break;

            case level_2:
                condition.Min = 1.61;
                condition.Max = 1.8;
                break;

            case level_3:
                condition.Min = 1.81;
                condition.Max = 2.0;
                break;

            case level_4:
                condition.Min = 2.01;
                condition.Max = 2.5;
                break;

            case level_5:
                condition.Min = 2.51;
                condition.Max = 3;
                break;

            case level_6:
                condition.Min = 3.01;
                condition.Max = 3.4;
                break;
            }
            return(condition);
        }
 public void Finish()
 {
     Result = ConditionResult.EXECUTED;
 }