示例#1
0
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("typeName");
     writer.WriteStringValue(ConditionType.ToString());
     writer.WritePropertyName("operator");
     writer.WriteStringValue(RemoteAddressOperator.ToString());
     if (Optional.IsDefined(NegateCondition))
     {
         writer.WritePropertyName("negateCondition");
         writer.WriteBooleanValue(NegateCondition.Value);
     }
     if (Optional.IsCollectionDefined(MatchValues))
     {
         writer.WritePropertyName("matchValues");
         writer.WriteStartArray();
         foreach (var item in MatchValues)
         {
             writer.WriteStringValue(item);
         }
         writer.WriteEndArray();
     }
     if (Optional.IsCollectionDefined(Transforms))
     {
         writer.WritePropertyName("transforms");
         writer.WriteStartArray();
         foreach (var item in Transforms)
         {
             writer.WriteStringValue(item.ToString());
         }
         writer.WriteEndArray();
     }
     writer.WriteEndObject();
 }
示例#2
0
        private bool TryCompareValuesOfAsNumericValues(JToken lhs, JToken rhs, ConditionType conditionType)
        {
            double realLhs;
            double realRhs;

            try
            {
                realLhs = lhs.ToObject <double>();
                realRhs = rhs.ToObject <double>();
            }
            catch (Exception e)
            {
                throw new RuntimeException($"Values in condition could not be both parsed to numeric values, and therefore the condition could not be performed: {e.Message}");
            }
            switch (conditionType)
            {
            case ConditionType.LessThan:
                return(realLhs < realRhs);

            case ConditionType.LessEqualThan:
                return(realLhs <= realRhs);

            case ConditionType.GreaterThan:
                return(realLhs > realRhs);

            case ConditionType.GreaterEqualThan:
                return(realLhs >= realRhs);

            default:
                throw new RuntimeException($"Unknown condition type: {conditionType.ToString()}");
            }
        }
示例#3
0
        /// <summary>
        /// Checks if the thing has the given condition.
        /// </summary>
        /// <param name="thing">The thing to check the conditions on.</param>
        /// <param name="conditionType">The type of condition.</param>
        /// <returns>True if the thing has such condition, false otherwise.</returns>
        public static bool HasCondition(this IThing thing, ConditionType conditionType)
        {
            thing.ThrowIfNull(nameof(thing));
            conditionType.ThrowIfNull(nameof(conditionType));

            return(thing.TrackedEvents.ContainsKey(conditionType.ToString()));
        }
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="name">The token values.</param>
 /// <param name="values">Get the current token value.</param>
 /// <param name="isValidInContext">Get whether the token is applicable in the current context, or <c>null</c> if it's always applicable.</param>
 /// <param name="canHaveMultipleValues">Whether the root token may contain multiple values.</param>
 /// <param name="allowedValues">The allowed values (or <c>null</c> if any value is allowed).</param>
 public ConditionTypeToken(ConditionType name, Func <IEnumerable <string> > values, Func <bool> isValidInContext = null, bool canHaveMultipleValues = false, IEnumerable <string> allowedValues = null)
     : base(name.ToString(), canHaveMultipleValues)
 {
     this.IsValidInContextImpl = isValidInContext;
     this.AllowedRootValues    = allowedValues != null ? new InvariantHashSet(allowedValues) : null;
     this.FetchValues          = () => new InvariantHashSet(values());
     this.EnableSubkeys(required: false, canHaveMultipleValues: false);
 }
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="name">The token values.</param>
 /// <param name="values">Get the current token value.</param>
 /// <param name="needsLoadedSave">Whether a save must be loaded for the token to be available.</param>
 /// <param name="canHaveMultipleValues">Whether the root token may contain multiple values.</param>
 /// <param name="allowedValues">The allowed values (or <c>null</c> if any value is allowed).</param>
 public ConditionTypeToken(ConditionType name, Func <IEnumerable <string> > values, bool needsLoadedSave, bool canHaveMultipleValues = false, IEnumerable <string> allowedValues = null)
     : base(name.ToString(), canHaveMultipleValues)
 {
     this.NeedsLoadedSave   = needsLoadedSave;
     this.AllowedRootValues = allowedValues != null ? new InvariantHashSet(allowedValues) : null;
     this.FetchValues       = () => new InvariantHashSet(values());
     this.EnableSubkeys(required: false, canHaveMultipleValues: false);
 }
示例#6
0
 /// <summary>
 /// 获取条件关系字符串
 /// </summary>
 /// <param name="conditionType">条件关系</param>
 protected virtual string GetConditionType(ConditionType conditionType)
 {
     if (conditionType != ConditionType.None)
     {
         return(conditionType.ToString());
     }
     return(string.Empty);
 }
示例#7
0
        public static bool InvokeComparison(this ConditionType parameter, double leftValue, double rightValue)
        {
            if (Comparisons.TryGetValue(parameter, out Func <double, double, bool> comparison))
            {
                return(comparison.Invoke(leftValue, rightValue));
            }

            throw new ArgumentException(paramName: parameter.ToString(), message: String.Format("Метод сравнения для параметра {0} не найден", parameter.ToString()));
        }
示例#8
0
        public static string GetDesignation(this ConditionType parameter)
        {
            if (Designations.TryGetValue(parameter, out string designation))
            {
                return(designation);
            }

            throw new ArgumentException(paramName: parameter.ToString(), message: String.Format("Обозначение для параметра {0} не найдено", parameter.ToString()));
        }
    public bool Validate(ConditionType condition, string arg)
    {
        MethodInfo method = GetType().GetMethod("Validate" + condition.ToString());

        if (method == null)
        {
            Debug.LogError("Error condition type: " + condition);
        }
        return((bool)method.Invoke(this, new System.Object[] { arg }));
    }
示例#10
0
    public void writeLine(ConditionType condition, TaskType task, int repetition, TimeSpan elapsedTime)
    {
        string line = "";

        line += DateTime.Now.ToString("yyyy/MM/dd-HH:mm:ss") + _sep;
        line += condition.ToString() + _sep;
        line += task.ToString() + _sep;
        line += repetition + _sep;
        line += elapsedTime.TotalMilliseconds.ToString() + _sep;

        _lines.Add(line);
    }
示例#11
0
        /// <summary>
        /// Open a new bracket in the query (ex: "(").
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public SqlCondition BeginBrackets(ConditionType type)
        {
            if (_builder.Length > 0)
            {
                _builder.Append($" { type.ToString().ToUpper() } ");
            }

            _builder.Append("(");
            _bracketInput = true;

            return(this);
        }
        public override string ToString()
        {
            String Text    = String.Empty;
            String format1 = "{0} {1}";
            String format2 = "{0} {1} and {2}";

            switch (ConditionType)
            {
            case CellConditionType.Equal:
                Text = String.Format(format1, Localization.ValueFilter_Equal, Value1.ToString());
                break;

            case CellConditionType.NotEqual:
                Text = String.Format(format1, Localization.ValueFilter_NotEqual, Value1.ToString());
                break;

            case CellConditionType.Less:
                Text = String.Format(format1, Localization.ValueFilter_Less, Value1.ToString());
                break;

            case CellConditionType.LessOrEqual:
                Text = String.Format(format1, Localization.ValueFilter_LessOrEqual, Value1.ToString());
                break;

            case CellConditionType.Greater:
                Text = String.Format(format1, Localization.ValueFilter_Greater, Value1.ToString());
                break;

            case CellConditionType.GreaterOrEqual:
                Text = String.Format(format1, Localization.ValueFilter_GreaterOrEqual, Value1.ToString());
                break;

            case CellConditionType.Between:
                Text = String.Format(format2, Localization.ValueFilter_Between, Value1.ToString(), Value2.ToString());
                break;

            case CellConditionType.NotBetween:
                Text = String.Format(format2, Localization.ValueFilter_NotBetween, Value1.ToString(), Value2.ToString());
                break;

            case CellConditionType.None:
                Text = Localization.ComboBoxItem_None;
                break;

            default:
                Text = ConditionType.ToString();
                break;
            }
            return(Text);
        }
示例#13
0
        public static string Format(this ConditionType condition)
        {
            switch (condition)
            {
            case ConditionType.Cancer:
            case ConditionType.Diabetes:
            case ConditionType.Obesity:
            case ConditionType.Smoking:
                return(condition.ToString());

            case ConditionType.WeakendImmuneSystem:
                return("Weakened Immune System");

            default:
                throw new Exception($"Unexpected Condition {condition}");
            }
        }
示例#14
0
文件: Condition.cs 项目: xvrsl/UXSWL
    public bool Evaluate()
    {
        switch (conditionType)
        {
        case ConditionType.valueLargerThan:
            return(GameManager.instance.gameStatus.IsValueLargerThan(valueName, comparingValue));

        case ConditionType.valueSmallerThan:
            return(GameManager.instance.gameStatus.IsValueSmallerThan(valueName, comparingValue));

        case ConditionType.valueEquals:
            return(GameManager.instance.gameStatus.IsValueEquals(valueName, comparingValue));

        default:
            Debug.LogWarning("This condition:" + conditionType.ToString() + " is under construction. It's not supported for now.");
            return(false);
        }
    }
示例#15
0
        public override bool PerformComparisonOnRhs(JToken lhsToken, ConditionType conditionType, Scope scope)
        {
            string lhsLiteral;

            try
            {
                lhsLiteral = lhsToken.ToObject <string>();
            }
            catch (Exception e)
            {
                throw new RuntimeException($"Error occured when parsing object to string in condition: {e.Message}");
            }
            if (conditionType == ConditionType.Equal)
            {
                return(lhsLiteral == StringValueBuilder.Build(this, scope));
            }
            else if (conditionType == ConditionType.NotEqual)
            {
                return(lhsLiteral != StringValueBuilder.Build(this, scope));
            }
            throw new RuntimeException($"Cannot make comparison of type {conditionType.ToString()} when comparing with a literal.");
        }
示例#16
0
        public override bool PerformComparisonOnRhs(JToken lhsToken, ConditionType conditionType, Scope scope)
        {
            var rhsToken = scope.FindValueOfValueOf(this);

            switch (conditionType)
            {
            case ConditionType.Equal:
                return(CheckIfTwoValuesOfAreEqual(lhsToken, rhsToken));

            case ConditionType.NotEqual:
                return(!CheckIfTwoValuesOfAreEqual(lhsToken, rhsToken));

            case ConditionType.LessThan:
            case ConditionType.LessEqualThan:
            case ConditionType.GreaterThan:
            case ConditionType.GreaterEqualThan:
                return(TryCompareValuesOfAsNumericValues(lhsToken, rhsToken, conditionType));

            default:
                throw new RuntimeException($"Unknown condition type: {conditionType.ToString()}");
            }
        }
示例#17
0
        public override bool PerformComparisonOnRhs(JToken lhsToken, ConditionType conditionType, Scope scope)
        {
            double lhsRealValue;

            try
            {
                lhsRealValue = lhsToken.ToObject <double>();
            }
            catch (Exception e)
            {
                throw new RuntimeException($"Cannot parse object to a number in comparison: ${e.Message}");
            }
            double rhsRealValue = this.Integer ? this.IntValue : this.RealValue;

            switch (conditionType)
            {
            case ConditionType.Equal:
                return(lhsRealValue == rhsRealValue);

            case ConditionType.NotEqual:
                return(lhsRealValue != rhsRealValue);

            case ConditionType.LessThan:
                return(lhsRealValue < rhsRealValue);

            case ConditionType.LessEqualThan:
                return(lhsRealValue <= rhsRealValue);

            case ConditionType.GreaterThan:
                return(lhsRealValue > rhsRealValue);

            case ConditionType.GreaterEqualThan:
                return(lhsRealValue >= rhsRealValue);

            default:
                throw new RuntimeException($"Unknown condition type: {conditionType.ToString()}");
            }
        }
示例#18
0
        public virtual bool Select(ref ConditionType c, Dictionary <int, string> conditionUsages)
        {
            bool changed = false;
            int  t       = (int)c;

            if (!conditionUsages.ContainsKey(t))
            {
                if (("Is " + c.ToString() + ". FIX ").Click())
                {
                    c = (ConditionType)(conditionUsages.First().Key);
                }
                changed = true;
            }
            else
            {
                if (pegi.select(ref t, conditionUsages, 40))
                {
                    changed = true;
                    c       = (ConditionType)t;
                }
            }
            return(changed);
        }
示例#19
0
 /// <summary>Construct an instance.</summary>
 /// <param name="tokenKey">The condition type.</param>
 /// <param name="subkey">A unique key indicating which in-game object the condition type applies to. For example, the NPC name when <paramref name="tokenKey"/> is <see cref="ConditionType.Relationship"/>.</param>
 public TokenName(ConditionType tokenKey, string subkey = null)
     : this(tokenKey.ToString(), subkey)
 {
 }
 /// <summary>Get whether the condition is for a given condition type.</summary>
 /// <param name="type">The condition type.</param>
 public bool Is(ConditionType type)
 {
     return(this.Name.EqualsIgnoreCase(type.ToString()));
 }
 public void getReport(StringWriter stringWriter)
 {
     stringWriter.WriteLine("<TR><TD>" + m_conditionType.ToString() + "</TD>");
     //stringWriter.WriteLine("<TD>" + "</TD>");
     stringWriter.WriteLine("<TD>" + getFormattedValue() + "</TD></TR>");
 }
示例#22
0
 /// <summary>
 /// Returns the translated displayname for a condition
 /// </summary>
 /// <param name="conditionType">Condition Type to translate</param>
 public string TranslateConditionType(ConditionType conditionType)
 {
     return(_localizer[string.Format("ConditionType{0}", conditionType.ToString())]);
 }
示例#23
0
 /// <summary>Construct an instance.</summary>
 /// <param name="type">The value provider name.</param>
 /// <param name="canHaveMultipleValuesForRoot">Whether the root value provider may contain multiple values.</param>
 protected BaseValueProvider(ConditionType type, bool canHaveMultipleValuesForRoot)
     : this(type.ToString(), canHaveMultipleValuesForRoot)
 {
 }
示例#24
0
        /*
         * <propertyDescription name="Microsoft.SDKSample.DirectoryLevel" formatID="{581CF603-2925-4acf-BB5A-3D3EB39EACD3}" propID="3">
         *  <description>Number of directory levels to this item.</description>
         *  <searchInfo inInvertedIndex="false" isColumn="false,
         *  <typeInfo canStackBy="false" type="Int32"/>
         *  <labelInfo label="Directory Level"/>
         * </propertyDescription>
         */
        internal XmlElement GetXmlPropertyDescription(XmlDocument doc)
        {
            var desc = doc.CreateElement("propertyDescription");

            desc.SetAttribute("name", CanonicalName);
            desc.SetAttribute("formatID", FormatId.ToString("B").ToUpper());
            desc.SetAttribute("propID", PropertyId.ToString());

            var search = doc.CreateElement("searchInfo");

            search.SetAttribute("inInvertedIndex", InInvertedIndex.ToString());
            if (IsColumn)
            {
                search.SetAttribute("isColumn", IsColumn.ToString());
                search.SetAttribute("isColumnSparse", IsColumnSparse.ToString());
                search.SetAttribute("columnIndexType", ColumnIndexType.ToString());
            }
            if (MaxSize != 512)
            {
                search.SetAttribute("maxSize", MaxSize.ToString());
            }
            if (Mnemonics != null && Mnemonics.Length > 0)
            {
                search.SetAttribute("mnemonics", Mnemonics);
            }
            desc.AppendChild(search);

            var label = doc.CreateElement("labelInfo");

            label.SetAttribute("label", DisplayName);
            label.SetAttribute("sortDescription", SortDescription.ToString());
            if (EditInvitation != null && EditInvitation.Length > 0)
            {
                label.SetAttribute("invitationText", EditInvitation);
            }
            if (HideLabel)
            {
                label.SetAttribute("hideLabel", HideLabel.ToString());
            }
            desc.AppendChild(label);

            var type = doc.CreateElement("typeInfo");

            type.SetAttribute("type", Type.ToString());
            if (GroupingRange != PropertyGroupingRange.Discrete)
            {
                type.SetAttribute("groupingRange", GroupingRange.ToString());
            }
            if (IsInnate)
            {
                type.SetAttribute("isInnate", IsInnate.ToString());
            }
            if (IsInnate && CanBePurged)
            {
                type.SetAttribute("canBePurged", CanBePurged.ToString());
            }
            //if (MultipleValues)
            type.SetAttribute("multipleValues", MultipleValues.ToString());
            if (IsGroup)
            {
                type.SetAttribute("isGroup", IsGroup.ToString());
            }
            if (AggregationType != PropertyAggregationType.Default)
            {
                type.SetAttribute("aggregationType", AggregationType.ToString());
            }
            if (IsTreeProperty)
            {
                type.SetAttribute("isTreeProperty", IsTreeProperty.ToString());
            }
            if (IsViewable)
            {
                type.SetAttribute("isViewable", IsViewable.ToString());
            }
            if (SearchRawValue)
            {
                type.SetAttribute("searchRawValue", SearchRawValue.ToString());
            }
            if (ConditionType != PropertyConditionType.String)
            {
                type.SetAttribute("conditionType", ConditionType.ToString());
            }
            if (ConditionOperation != ConditionOperationConfigured.Equal)
            {
                type.SetAttribute("defaultOperation", ConditionOperation.ToString());
            }
            desc.AppendChild(type);

            var display = doc.CreateElement("displayInfo");

            display.SetAttribute("displayType", DisplayType.ToString());
            if (DisplayType == PropertyDisplayType.String && StringFormat != StringFormat.General)
            {
                var format = doc.CreateElement("stringFormat");
                format.SetAttribute("formatAs", StringFormat.ToString());
                display.AppendChild(format);
            }
            if (DisplayType == PropertyDisplayType.Boolean && BooleanFormat != BooleanFormat.YesNo)
            {
                var format = doc.CreateElement("booleanFormat");
                format.SetAttribute("formatAs", BooleanFormat.ToString());
                display.AppendChild(format);
            }
            if (DisplayType == PropertyDisplayType.Number && NumberFormat != NumberFormat.General)
            {
                var format = doc.CreateElement("numberFormat");
                format.SetAttribute("formatAs", NumberFormat.ToString());
                display.AppendChild(format);
            }
            if (DisplayType == PropertyDisplayType.DateTime && DateTimeFormat != DateTimeFormat.General)
            {
                var format = doc.CreateElement("dateTimeFormat");
                format.SetAttribute("formatAs", DateTimeFormat.ToString());
                display.AppendChild(format);
            }



            if (DefaultColumnWidth != 20)
            {
                display.SetAttribute("defaultColumnWidth", DefaultColumnWidth.ToString());
            }
            if (Alignment != PropertyAlignmentType.Left)
            {
                display.SetAttribute("alignment", Alignment.ToString());
            }
            //if (RelativeDescriptionType != RelativeDescriptionType.General)
            //  display.SetAttribute("relativeDescriptionType", RelativeDescriptionType.ToString());
            if (DefaultSortDirection != SortDirection.Ascending)
            {
                display.SetAttribute("defaultSortDirection", DefaultSortDirection.ToString());
            }
            if (EditControl != EditControl.Default)
            {
                var edit = doc.CreateElement("editControl");
                edit.SetAttribute("control", EditControl.ToString());
                display.AppendChild(edit);
            }
            desc.AppendChild(display);

            return(desc);
        }