/// <summary>
        /// Checks if the filter applies to the object.
        /// </summary>
        /// <param name="Object">Object.</param>
        /// <param name="Serializer">Corresponding object serializer.</param>
        /// <param name="Provider">Files provider.</param>
        /// <returns>If the filter can be applied.</returns>
        public async Task <bool> AppliesTo(object Object, IObjectSerializer Serializer, FilesProvider Provider)
        {
            object Value = await Serializer.TryGetFieldValue(this.FieldName, Object);

            if (Value is null)
            {
                Type T = Object.GetType();
                if (Serializer.ValueType == T)
                {
                    return(false);
                }

                if (T == this.prevType)
                {
                    Serializer = this.prevSerializer;
                }
                else
                {
                    Serializer = this.prevSerializer = await Provider.GetObjectSerializer(T);

                    this.prevType = T;
                }

                Value = await Serializer.TryGetFieldValue(this.FieldName, Object);

                if (Value is null)
                {
                    return(false);
                }
            }

            int?ComparisonResult = Comparison.Compare(Value, this.Value);

            return(ComparisonResult.HasValue && ComparisonResult.Value > 0);
        }
示例#2
0
        /// <summary>
        /// Checks if the filter applies to the object.
        /// </summary>
        /// <param name="Object">Object.</param>
        /// <param name="Serializer">Corresponding object serializer.</param>
        /// <param name="Provider">Files provider.</param>
        /// <returns>If the filter can be applied.</returns>
        public bool AppliesTo(object Object, IObjectSerializer Serializer, FilesProvider Provider)
        {
            if (!Serializer.TryGetFieldValue(this.FieldName, Object, out object Value))
            {
                Type T = Object.GetType();
                if (Serializer.ValueType == T)
                {
                    return(false);
                }

                if (T == this.prevType)
                {
                    Serializer = this.prevSerializer;
                }
                else
                {
                    Serializer    = this.prevSerializer = Provider.GetObjectSerializer(T);
                    this.prevType = T;
                }

                if (!Serializer.TryGetFieldValue(this.FieldName, Object, out Value))
                {
                    return(false);
                }
            }

            int?ComparisonResult = Comparison.Compare(Value, this.Value);

            return(ComparisonResult.HasValue && ComparisonResult.Value == 0);
        }
        /// <summary>
        /// Checks if the filter applies to the object.
        /// </summary>
        /// <param name="Object">Object.</param>
        /// <param name="Serializer">Corresponding object serializer.</param>
        /// <param name="Provider">Files provider.</param>
        /// <returns>If the filter can be applied.</returns>
        public bool AppliesTo(object Object, IObjectSerializer Serializer, FilesProvider Provider)
        {
            if (!Serializer.TryGetFieldValue(this.FieldName, Object, out object Value))
            {
                Type T = Object.GetType();
                if (Serializer.ValueType == T)
                {
                    return(false);
                }

                if (T == this.prevType)
                {
                    Serializer = this.prevSerializer;
                }
                else
                {
                    Serializer    = this.prevSerializer = Provider.GetObjectSerializer(T);
                    this.prevType = T;
                }

                if (!Serializer.TryGetFieldValue(this.FieldName, Object, out Value))
                {
                    return(false);
                }
            }

            string s = Value.ToString();
            Match  M = this.regex.Match(s);

            return(M.Success && M.Index == 0 && M.Length == s.Length);
        }
示例#4
0
        /// <summary>
        /// Checks if the filter applies to the object.
        /// </summary>
        /// <param name="Object">Object.</param>
        /// <param name="Serializer">Corresponding object serializer.</param>
        /// <param name="Provider">Files provider.</param>
        /// <returns>If the filter can be applied.</returns>
        public async Task <bool> AppliesTo(object Object, IObjectSerializer Serializer, FilesProvider Provider)
        {
            object Value = await Serializer.TryGetFieldValue(this.FieldName, Object);

            if (Value is null)
            {
                Type T = Object.GetType();
                if (Serializer.ValueType == T)
                {
                    return(false);
                }

                if (T == this.prevType)
                {
                    Serializer = this.prevSerializer;
                }
                else
                {
                    Serializer = this.prevSerializer = await Provider.GetObjectSerializer(T);

                    this.prevType = T;
                }

                Value = await Serializer.TryGetFieldValue(this.FieldName, Object);

                if (Value is null)
                {
                    return(false);
                }
            }

            Match M;

            if (Value is string s)
            {
                if (this.regexCs is null)
                {
                    this.regexCs = new Regex(this.RegularExpression, RegexOptions.Singleline);
                }

                M = this.regexCs.Match(s);
            }
            else if (Value is CaseInsensitiveString cis)
            {
                if (this.regexCi is null)
                {
                    this.regexCi = new Regex(this.RegularExpression, RegexOptions.Singleline | RegexOptions.IgnoreCase);
                }

                M = this.regexCi.Match(s = cis.Value);
            }
            else
            {
                s = Value.ToString();

                if (!(this.regexCs is null))
                {
                    M = this.regexCs.Match(s);
                }
        /// <summary>
        /// Gets the value of a field or property of an object, given its name.
        /// </summary>
        /// <param name="FieldName">Name of field or property.</param>
        /// <param name="Object">Object.</param>
        /// <returns>Corresponding field or property value, if found, or null otherwise.</returns>
        public override async Task <object> TryGetFieldValue(string FieldName, object Object)
        {
            if (Object is GenericObject GenObj)
            {
                if (GenObj.TryGetFieldValue(FieldName, out object Value))
                {
                    return(Value);
                }
                else
                {
                    return(null);
                }
            }
            else if (!(Object is null) && this.returnTypedObjects)
            {
                IObjectSerializer Serializer2 = await this.Context.GetObjectSerializer(Object.GetType());

                return(await Serializer2.TryGetFieldValue(FieldName, Object));
            }
示例#6
0
        /// <summary>
        /// Advances the enumerator to the previous element of the collection.
        /// </summary>
        /// <returns>true if the enumerator was successfully advanced to the previous element; false if
        /// the enumerator has passed the beginning of the collection.</returns>
        /// <exception cref="InvalidOperationException">The collection was modified after the enumerator was created.</exception>
        public async Task <bool> MovePreviousAsync()
        {
            int i;

            while (true)
            {
                if (this.currentRange is null)
                {
                    List <KeyValuePair <string, object> >            SearchParameters = new List <KeyValuePair <string, object> >();
                    List <KeyValuePair <string, IApplicableFilter> > StartFilters     = null;
                    List <KeyValuePair <string, IApplicableFilter> > EndFilters       = null;
                    RangeInfo Range;
                    object    Value;

                    for (i = 0; i < this.nrRanges; i++)
                    {
                        Range = this.currentLimits[i];

                        if (Range.IsPoint)
                        {
                            if (EndFilters is null)
                            {
                                EndFilters = new List <KeyValuePair <string, IApplicableFilter> >();
                            }

                            SearchParameters.Add(new KeyValuePair <string, object>(Range.FieldName, Range.Point));
                            EndFilters.Add(new KeyValuePair <string, IApplicableFilter>(Range.FieldName, new FilterFieldEqualTo(Range.FieldName, Range.Point)));
                        }
                        else
                        {
                            if (Range.HasMin)
                            {
                                Value = Range.Min;

                                if (this.ascending[i])
                                {
                                    if (EndFilters is null)
                                    {
                                        EndFilters = new List <KeyValuePair <string, IApplicableFilter> >();
                                    }

                                    if (Range.MinInclusive)
                                    {
                                        EndFilters.Add(new KeyValuePair <string, IApplicableFilter>(Range.FieldName, new FilterFieldGreaterOrEqualTo(Range.FieldName, Value)));
                                    }
                                    else
                                    {
                                        EndFilters.Add(new KeyValuePair <string, IApplicableFilter>(Range.FieldName, new FilterFieldGreaterThan(Range.FieldName, Value)));
                                    }
                                }
                                else
                                {
                                    if (StartFilters is null)
                                    {
                                        StartFilters = new List <KeyValuePair <string, IApplicableFilter> >();
                                    }

                                    if (Range.MinInclusive)
                                    {
                                        StartFilters.Add(new KeyValuePair <string, IApplicableFilter>(Range.FieldName, new FilterFieldGreaterOrEqualTo(Range.FieldName, Value)));
                                    }
                                    else
                                    {
                                        StartFilters.Add(new KeyValuePair <string, IApplicableFilter>(Range.FieldName, new FilterFieldGreaterThan(Range.FieldName, Value)));

                                        if (!Comparison.Increment(ref Value))
                                        {
                                            return(false);
                                        }
                                    }

                                    SearchParameters.Add(new KeyValuePair <string, object>(Range.FieldName, Value));
                                }
                            }

                            if (Range.HasMax)
                            {
                                Value = Range.Max;

                                if (this.ascending[i])
                                {
                                    if (StartFilters is null)
                                    {
                                        StartFilters = new List <KeyValuePair <string, IApplicableFilter> >();
                                    }

                                    if (Range.MaxInclusive)
                                    {
                                        StartFilters.Add(new KeyValuePair <string, IApplicableFilter>(Range.FieldName, new FilterFieldLesserOrEqualTo(Range.FieldName, Value)));
                                    }
                                    else
                                    {
                                        StartFilters.Add(new KeyValuePair <string, IApplicableFilter>(Range.FieldName, new FilterFieldLesserThan(Range.FieldName, Value)));

                                        if (!Comparison.Decrement(ref Value))
                                        {
                                            return(false);
                                        }
                                    }

                                    SearchParameters.Add(new KeyValuePair <string, object>(Range.FieldName, Value));
                                }
                                else
                                {
                                    if (EndFilters is null)
                                    {
                                        EndFilters = new List <KeyValuePair <string, IApplicableFilter> >();
                                    }

                                    if (Range.MaxInclusive)
                                    {
                                        EndFilters.Add(new KeyValuePair <string, IApplicableFilter>(Range.FieldName, new FilterFieldLesserOrEqualTo(Range.FieldName, Value)));
                                    }
                                    else
                                    {
                                        EndFilters.Add(new KeyValuePair <string, IApplicableFilter>(Range.FieldName, new FilterFieldLesserThan(Range.FieldName, Value)));
                                    }
                                }
                            }
                        }
                    }

                    if (this.firstAscending)
                    {
                        this.currentRange = await this.index.FindLastLesserOrEqualTo <T>(this.lockType, this.lockParent, SearchParameters.ToArray());
                    }
                    else
                    {
                        this.currentRange = await this.index.FindFirstGreaterOrEqualTo <T>(this.lockType, this.lockParent, SearchParameters.ToArray());
                    }

                    this.startRangeFilters = StartFilters?.ToArray();
                    this.endRangeFilters   = EndFilters?.ToArray();
                    this.limitsUpdatedAt   = this.nrRanges;
                }

                if (!await this.currentRange.MovePreviousAsync())
                {
                    this.currentRange.Dispose();
                    this.currentRange = null;

                    if (this.limitsUpdatedAt >= this.nrRanges)
                    {
                        return(false);
                    }

                    continue;
                }

                if (!this.currentRange.CurrentTypeCompatible)
                {
                    continue;
                }

                object            CurrentValue         = this.currentRange.Current;
                IObjectSerializer CurrentSerializer    = this.currentRange.CurrentSerializer;
                string            OutOfStartRangeField = null;
                string            OutOfEndRangeField   = null;
                bool Ok = true;
                bool Smaller;

                if (!(this.additionalfilters is null))
                {
                    foreach (IApplicableFilter Filter in this.additionalfilters)
                    {
                        if (!Filter.AppliesTo(CurrentValue, CurrentSerializer, this.provider))
                        {
                            Ok = false;
                            break;
                        }
                    }
                }

                if (!(this.startRangeFilters is null))
                {
                    foreach (KeyValuePair <string, IApplicableFilter> Filter in this.startRangeFilters)
                    {
                        if (!Filter.Value.AppliesTo(CurrentValue, CurrentSerializer, this.provider))
                        {
                            OutOfStartRangeField = Filter.Key;
                            Ok = false;
                            break;
                        }
                    }
                }

                if (!(this.endRangeFilters is null) && OutOfStartRangeField is null)
                {
                    foreach (KeyValuePair <string, IApplicableFilter> Filter in this.endRangeFilters)
                    {
                        if (!Filter.Value.AppliesTo(CurrentValue, CurrentSerializer, this.provider))
                        {
                            OutOfEndRangeField = Filter.Key;
                            Ok = false;
                            break;
                        }
                    }
                }

                for (i = 0; i < this.limitsUpdatedAt; i++)
                {
                    if (CurrentSerializer.TryGetFieldValue(this.ranges[i].FieldName, CurrentValue, out object FieldValue))
                    {
                        if (this.ascending[i])
                        {
                            if (this.currentLimits[i].SetMax(FieldValue, !(OutOfStartRangeField is null), out Smaller) && Smaller)
                            {
                                i++;
                                this.limitsUpdatedAt = i;

                                while (i < this.nrRanges)
                                {
                                    this.ranges[i].CopyTo(this.currentLimits[i]);
                                    i++;
                                }
                            }
                        }
                        else
                        {
                            if (this.currentLimits[i].SetMin(FieldValue, !(OutOfStartRangeField is null), out Smaller) && Smaller)
                            {
                                i++;
                                this.limitsUpdatedAt = i;

                                while (i < this.nrRanges)
                                {
                                    this.ranges[i].CopyTo(this.currentLimits[i]);
                                    i++;
                                }
                            }
                        }
                    }
                }

                if (Ok)
                {
                    return(true);
                }
                else if (!(OutOfStartRangeField is null) || !(OutOfEndRangeField is null))
                {
                    this.currentRange.Dispose();
                    this.currentRange = null;

                    if (this.limitsUpdatedAt >= this.nrRanges)
                    {
                        return(false);
                    }
                }
            }
        }
示例#7
0
        /// <summary>
        /// Checks if the filter applies to the object.
        /// </summary>
        /// <param name="Object">Object.</param>
        /// <param name="Serializer">Corresponding object serializer.</param>
        /// <param name="Provider">Files provider.</param>
        /// <returns>If the filter can be applied.</returns>
        public bool AppliesTo(object Object, IObjectSerializer Serializer, FilesProvider Provider)
        {
            if (!Serializer.TryGetFieldValue(this.FieldName, Object, out object Value))
            {
                Type T = Object.GetType();
                if (Serializer.ValueType == T)
                {
                    return(false);
                }

                if (T == this.prevType)
                {
                    Serializer = this.prevSerializer;
                }
                else
                {
                    Serializer    = this.prevSerializer = Provider.GetObjectSerializer(T);
                    this.prevType = T;
                }

                if (!Serializer.TryGetFieldValue(this.FieldName, Object, out Value))
                {
                    return(false);
                }
            }

            Match M;

            if (Value is string s)
            {
                if (this.regexCs is null)
                {
                    this.regexCs = new Regex(RegularExpression, RegexOptions.Singleline);
                }

                M = this.regexCs.Match(s);
            }
            else if (Value is CaseInsensitiveString cis)
            {
                if (this.regexCi is null)
                {
                    this.regexCi = new Regex(RegularExpression, RegexOptions.Singleline | RegexOptions.IgnoreCase);
                }

                M = this.regexCi.Match(s = cis.Value);
            }
            else
            {
                s = Value.ToString();

                if (this.regexCs != null)
                {
                    M = this.regexCs.Match(s);
                }
                else if (this.regexCi != null)
                {
                    M = this.regexCi.Match(s);
                }
                else
                {
                    this.regexCs = new Regex(RegularExpression, RegexOptions.Singleline);
                    M            = this.regexCs.Match(s);
                }
            }

            return(M.Success && M.Index == 0 && M.Length == s.Length);
        }