private void ActionFilterInclude(BsonDocument doc, IList <TrxAction> trxActions)
        {
            if (this.m_ActionFilters.Length == 0)
            {
                return;
            }

            MongoDB.Bson.BsonArray bsonArray = null;
            MongoDB.Bson.BsonValue bsonValue;

            if (doc.TryGetValue("action_traces", out bsonValue) || doc.TryGetValue("traces", out bsonValue) || doc.TryGetValue("inline_traces", out bsonValue))
            {
                bsonArray = bsonValue.AsBsonArray;
            }

            if (bsonArray == null)
            {
                return;
            }

            foreach (MongoDB.Bson.BsonValue bsonItem in bsonArray)
            {
                BsonSerializationArgs args           = new BsonSerializationArgs();
                BsonDocument          bsonDocument   = bsonItem.ToBsonDocument <MongoDB.Bson.BsonValue>((IBsonSerializer <MongoDB.Bson.BsonValue>)null, (Action <BsonSerializationContext.Builder>)null, args);
                BsonDocument          asBsonDocument = bsonDocument.GetValue("act").AsBsonDocument;
                string account = asBsonDocument.GetValue("account").AsString;
                string name    = asBsonDocument.GetValue("name").AsString;
                if (this.m_ActionFilters.Any(af =>
                {
                    if (!(af.Account == "*") && !(af.Account == account))
                    {
                        return(false);
                    }
                    if (!(af.Name == "*"))
                    {
                        return(af.Name == name);
                    }
                    return(true);
                }))
                {
                    this.AddToTrxActions(trxActions, bsonDocument);
                }
                this.ActionFilterInclude(bsonDocument, trxActions);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Tries to map an object to an instance of the closest BsonValue class.
        /// </summary>
        /// <param name="value">An object.</param>
        /// <param name="bsonValue">The BsonValue.</param>
        /// <returns>True if the mapping was successfull.</returns>
        public static bool TryMapToBsonValue(object value, out BsonValue bsonValue)
        {
            if (value == null)
            {
                bsonValue = BsonNull.Value;
                return(true);
            }

            var valueType = value.GetType();

            if (valueType.IsEnum)
            {
                valueType = Enum.GetUnderlyingType(valueType);
                switch (Type.GetTypeCode(valueType))
                {
                case TypeCode.Byte: value = (int)(byte)value; break;

                case TypeCode.Int16: value = (int)(short)value; break;

                case TypeCode.Int32: value = (int)value; break;

                case TypeCode.Int64: value = (long)value; break;

                case TypeCode.SByte: value = (int)(sbyte)value; break;

                case TypeCode.UInt16: value = (int)(ushort)value; break;

                case TypeCode.UInt32: value = (long)(uint)value; break;

                case TypeCode.UInt64: value = (long)(ulong)value; break;
                }
                valueType = value.GetType();
            }

            Conversion conversion;

            if (__fromMappings.TryGetValue(valueType, out conversion))
            {
                bsonValue = Convert(value, conversion);
                return(true);
            }

            // these mappings can't be handled by the mappings table (because of the interfaces)
            if (value is IDictionary <string, object> )
            {
                bsonValue = new BsonDocument((IDictionary <string, object>)value);
                return(true);
            }
            if (value is IDictionary)
            {
                bsonValue = new BsonDocument((IDictionary)value);
                return(true);
            }

            // NOTE: the check for IEnumerable must be after the check for IDictionary
            // because IDictionary implements IEnumerable
            if (value is IEnumerable)
            {
                bsonValue = new BsonArray((IEnumerable)value);
                return(true);
            }

            ICustomBsonTypeMapper customTypeMapper;

            if (__customTypeMappers.TryGetValue(valueType, out customTypeMapper))
            {
                return(customTypeMapper.TryMapToBsonValue(value, out bsonValue));
            }

            bsonValue = null;
            return(false);
        }
Esempio n. 3
0
 /// <summary>
 /// Compares the array to another array.
 /// </summary>
 /// <param name="other">The other array.</param>
 /// <returns>A 32-bit signed integer that indicates whether this array is less than, equal to, or greather than the other.</returns>
 public override int CompareTo(BsonArray other)
 {
     EnsureIsMaterialized();
     return(base.CompareTo(other));
 }
Esempio n. 4
0
        /// <summary>
        /// Tries to map an object to a BsonValue.
        /// </summary>
        /// <param name="value">An object.</param>
        /// <param name="bsonValue">The BsonValue.</param>
        /// <returns>True if the mapping was successfull.</returns>
        public static bool TryMapToBsonValue(
            object value, // will be mapped to an instance of the closest BsonValue class
            out BsonValue bsonValue
            )
        {
            if (value == null)
            {
                throw new ArgumentNullException("Value to be mapped to BsonValue cannot be null");
            }

            var valueType = value.GetType();

            if (valueType.IsEnum)
            {
                valueType = Enum.GetUnderlyingType(valueType);
                switch (Type.GetTypeCode(valueType))
                {
                case TypeCode.Byte: value = (int)(byte)value; break;

                case TypeCode.Int16: value = (int)(short)value; break;

                case TypeCode.Int32: value = (int)value; break;

                case TypeCode.Int64: value = (long)value; break;

                case TypeCode.SByte: value = (int)(sbyte)value; break;

                case TypeCode.UInt16: value = (int)(ushort)value; break;

                case TypeCode.UInt32: value = (long)(uint)value; break;

                case TypeCode.UInt64: value = (long)(ulong)value; break;
                }
                valueType = value.GetType();
            }

            Conversion conversion;

            if (fromMappings.TryGetValue(valueType, out conversion))
            {
                bsonValue = Convert(value, conversion);
                return(true);
            }

            // these mappings can't be handled by the mappings table (because of the interfaces)
            if (value is IEnumerable <object> )
            {
                bsonValue = new BsonArray((IEnumerable <object>)value);
                return(true);
            }
            if (value is IDictionary <string, object> )
            {
                bsonValue = new BsonDocument((IDictionary <string, object>)value);
                return(true);
            }
            if (value is IDictionary)
            {
                bsonValue = new BsonDocument((IDictionary)value);
                return(true);
            }

            bsonValue = null;
            return(false);
        }
Esempio n. 5
0
 /// <summary>
 /// Compares the array to another array.
 /// </summary>
 /// <param name="other">The other array.</param>
 /// <returns>A 32-bit signed integer that indicates whether this array is less than, equal to, or greather than the other.</returns>
 public override int CompareTo(BsonArray other)
 {
     EnsureDataIsAccessible();
     return(base.CompareTo(other));
 }
Esempio n. 6
0
 public static dynamic ToDynamic(this BsonArray bsonArray) => bsonArray.Select(x => x.ToDynamic()).ToArray();