Ejemplo n.º 1
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);
                }
            }

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

            return(ComparisonResult.HasValue && ComparisonResult.Value > 0);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reads a typed array.
        /// </summary>
        /// <param name="T">Element type.</param>
        /// <param name="Provider">Database provider object.</param>
        /// <param name="Reader">Binary reader.</param>
        /// <param name="FieldDataType">Field data type.</param>
        /// <returns>String value.</returns>
        /// <exception cref="ArgumentException">If the <paramref name="FieldDataType"/> was invalid.</exception>
        public static Array ReadArray(Type T, FilesProvider Provider, BinaryDeserializer Reader, uint FieldDataType)
        {
            switch (FieldDataType)
            {
            case ObjectSerializer.TYPE_ARRAY:
                IObjectSerializer S          = Provider.GetObjectSerializer(T);
                ulong             NrElements = Reader.ReadVariableLengthUInt64();
                if (NrElements > int.MaxValue)
                {
                    throw new Exception("Array too long.");
                }

                int   i, c = (int)NrElements;;
                Array Result = Array.CreateInstance(T, c);

                uint ElementDataType  = Reader.ReadBits(6);
                uint?ElementDataTypeN = ElementDataType == ObjectSerializer.TYPE_NULL ? (uint?)null : (uint?)ElementDataType;

                for (i = 0; i < c; i++)
                {
                    Result.SetValue(S.Deserialize(Reader, ElementDataTypeN, true), i);
                }

                return(Result);

            case ObjectSerializer.TYPE_NULL:
                return(null);

            default:
                throw new Exception("Array expected.");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Reads a typed array.
        /// </summary>
        /// <typeparam name="T">Element type.</typeparam>
        /// <param name="Provider">Database provider object.</param>
        /// <param name="Reader">Binary reader.</param>
        /// <param name="FieldDataType">Field data type.</param>
        /// <returns>String value.</returns>
        /// <exception cref="ArgumentException">If the <paramref name="FieldDataType"/> was invalid.</exception>
        public static T[] ReadArray <T>(FilesProvider Provider, BinaryDeserializer Reader, uint FieldDataType)
        {
            switch (FieldDataType)
            {
            case ObjectSerializer.TYPE_ARRAY:
                List <T>          Elements   = new List <T>();
                IObjectSerializer S          = Provider.GetObjectSerializer(typeof(T));
                ulong             NrElements = Reader.ReadVariableLengthUInt64();
                uint ElementDataType         = Reader.ReadBits(6);
                uint?ElementDataTypeN        = ElementDataType == ObjectSerializer.TYPE_NULL ? (uint?)null : (uint?)ElementDataType;

                while (NrElements-- > 0)
                {
                    Elements.Add((T)S.Deserialize(Reader, ElementDataTypeN, true));
                }

                return(Elements.ToArray());

            case ObjectSerializer.TYPE_NULL:
                return(null);

            default:
                throw new Exception("Array expected.");
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
                }
Ejemplo n.º 7
0
        /// <summary>
        /// Writes an array.
        /// </summary>
        /// <param name="T">Element type.</param>
        /// <param name="Provider">Database provider object.</param>
        /// <param name="Writer">Binary writer.</param>
        /// <param name="Value">Value to serialize.</param>
        public static void WriteArray(Type T, FilesProvider Provider, BinarySerializer Writer, Array Value)
        {
            if (Value == null)
            {
                Writer.WriteBits(ObjectSerializer.TYPE_NULL, 6);
            }
            else
            {
                Type LastType       = T;
                IObjectSerializer S = Provider.GetObjectSerializer(LastType);
                Type ItemType;
                bool Nullable;

                Writer.WriteBits(ObjectSerializer.TYPE_ARRAY, 6);
                Writer.WriteVariableLengthUInt64((ulong)Value.Length);

                if (Nullable = S.IsNullable)
                {
                    Writer.WriteBits(ObjectSerializer.TYPE_NULL, 6);
                }
                else
                {
                    Writer.WriteBits(FilesProvider.GetFieldDataTypeCode(LastType), 6);
                }

                foreach (object Item in Value)
                {
                    if (Item == null)
                    {
                        Writer.WriteBits(ObjectSerializer.TYPE_NULL, 6);
                    }
                    else
                    {
                        ItemType = Item.GetType();
                        if (ItemType != LastType)
                        {
                            S        = Provider.GetObjectSerializer(ItemType);
                            LastType = ItemType;
                        }

                        S.Serialize(Writer, Nullable, true, Item);
                    }
                }
            }
        }
Ejemplo n.º 8
0
 private static void SaveLastObject(FilesProvider Provider, object LastObjectAdded)
 {
     if (LastObjectAdded != null)
     {
         IObjectSerializer Serializer = Provider.GetObjectSerializer(LastObjectAdded.GetType());
         BinarySerializer  Writer     = new BinarySerializer(CollectionName, Encoding.UTF8);
         Serializer.Serialize(Writer, false, false, LastObjectAdded);
         byte[] Bin = Writer.GetSerialization();
         System.IO.File.WriteAllBytes(ObjFileName, Bin);
     }
 }
Ejemplo n.º 9
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);
        }