// private methods
        private void AssertResultAspect(string name, BsonValue expectedValue)
        {
            switch (name)
            {
            case "matchedCount":
                _result.MatchedCount.Should().Be(expectedValue.ToInt64());
                break;

            case "modifiedCount":
                _result.ModifiedCount.Should().Be(expectedValue.ToInt64());
                break;

            case "upsertedCount":
                var upsertedCount = _result.UpsertedId == null ? 0 : 1;
                upsertedCount.Should().Be(expectedValue.ToInt32());
                break;

            case "upsertedId":
                _result.UpsertedId.Should().Be(expectedValue);
                break;

            default:
                throw new FormatException($"Invalid UpdateMany result aspect: {name}.");
            }
        }
        // private methods
        private void AssertResultAspect(string name, BsonValue expectedValue)
        {
            switch (name)
            {
            case "deletedCount":
                _result.DeletedCount.Should().Be(expectedValue.ToInt64());
                break;

            case "insertedIds":
                _result.InsertedCount.Should().Be(expectedValue.AsBsonDocument.ElementCount);
                break;

            case "insertedCount":
                _result.InsertedCount.Should().Be(expectedValue.ToInt64());
                break;

            case "matchedCount":
                _result.MatchedCount.Should().Be(expectedValue.ToInt64());
                break;

            case "modifiedCount":
                _result.ModifiedCount.Should().Be(expectedValue.ToInt64());
                break;

            case "upsertedCount":
                _result.Upserts.Count.Should().Be(expectedValue.ToInt32());
                break;

            case "upsertedIds":
                _result.Upserts.Select(u => u.Id).Should().Equal(expectedValue.AsBsonDocument.Values);
                break;

            default: throw new FormatException($"Invalid BulkWriteResult aspect name: {name}.");
            }
        }
        protected override bool TrySetArgument(string name, BsonValue value)
        {
            switch (name)
            {
                case "filter":
                    _filter = (BsonDocument)value;
                    return true;
                case "skip":
                    _options.Skip = value.ToInt64();
                    return true;
                case "limit":
                    _options.Limit = value.ToInt64();
                    return true;
            }

            return false;
        }
示例#4
0
        protected override bool TrySetArgument(string name, BsonValue value)
        {
            switch (name)
            {
            case "filter":
                _filter = (BsonDocument)value;
                return(true);

            case "skip":
                _options.Skip = value.ToInt64();
                return(true);

            case "limit":
                _options.Limit = value.ToInt64();
                return(true);
            }

            return(false);
        }
示例#5
0
        protected override bool TrySetArgument(string name, BsonValue value)
        {
            switch (name)
            {
                case "filter":
                    _filter = (BsonDocument)value;
                    return true;
                case "skip":
                    _options.Skip = value.ToInt64();
                    return true;
                case "limit":
                    _options.Limit = value.ToInt64();
                    return true;
                case "collation":
                    _options.Collation = Collation.FromBsonDocument(value.AsBsonDocument);
                    return true;
            }

            return false;
        }
示例#6
0
        protected override bool TrySetArgument(string name, BsonValue value)
        {
            switch (name)
            {
            case "limit":
                _options.MaxTime = new TimeSpan(value.ToInt64());
                return(true);
            }

            return(false);
        }
示例#7
0
        // private methods
        private void AssertResultAspect(string name, BsonValue expectedValue)
        {
            switch (name)
            {
            case "deletedCount":
                _result.DeletedCount.Should().Be(expectedValue.ToInt64());
                break;

            default:
                throw new FormatException($"Invalid DeleteMany result aspect: {name}.");
            }
        }
示例#8
0
        static Expression SizeExpression(Expression field, BsonValue args)
        {
            double size;

            if (args.IsNumeric)
            {
                size = args.ToDouble();
                if (size == args.ToInt64())
                {
                    return(Expression.Call(GetMethod("Size"), Data, field, Expression.Constant(size, typeof(double))));
                }
            }
            throw new ArgumentException("Invalid $size argument.");
        }
示例#9
0
        private object GetDataTypeValueFromBsonValue(BsonValue value, DataType dt)
        {
            if (dt == DataType.DT_I8 | dt == DataType.DT_I4)
            {
                if (value.IsString)
                {
                    Int64 parsedInt = -1;
                    if (!Int64.TryParse(value.ToString(), out parsedInt))
                    {
                        bool pbCancel = true;
                        ComponentMetaData.FireError(0, "MongoDataSource", "Cannot parse string value to integer: " + value.ToString(), "", 0, out pbCancel);
                    }
                    return(parsedInt);
                }
                else
                {
                    return(value.ToInt64());
                }
            }
            else if (dt == DataType.DT_BOOL)
            {
                return(value.ToBoolean());
            }
            else if (dt == DataType.DT_R8 | dt == DataType.DT_R4)
            {
                return(value.ToDouble());
            }
            else if (dt == DataType.DT_DATE | dt == DataType.DT_DBTIMESTAMPOFFSET | dt == DataType.DT_DBTIMESTAMP)
            {
                return(DateTime.Parse(value.ToString()));
            }
            else
            {
                if (dt != DataType.DT_STR && !value.IsObjectId && !value.IsString && !value.IsBsonSymbol)
                {
                    ComponentMetaData.FireWarning(0, "MongoDataSource", "Converting " + value.BsonType + " to string, though datatype was " + dt, String.Empty, 0);
                }

                return(value.ToString());
            }
        }
示例#10
0
        private static object Convert(BsonValue value, Type type)
        {
            switch (type.Name)
            {
            case "String":
                return(value.ToString());

            case "Int32":
                return(value.ToInt32());

            case "Int64":
                return(value.ToInt64());

            case "Decimal":
                return((decimal)value.ToDouble());

            case "Double":
                return(value.ToDouble());

            case "DateTime":
                return(value.ToLocalTime());

            case "Boolean":
                return(value.ToBoolean());

            case "Nullable`1":
                var nullType = type.GetProperty("Value").PropertyType;
                switch (nullType.Name)
                {
                case "DateTime":
                    return(value.ToNullableLocalTime());

                default:
                    return(Convert(value, nullType));
                }
            }
            return(value);
        }
示例#11
0
        private object GetDataTypeValueFromBsonValue(BsonValue value, DataType dt)
        {
            if (dt == DataType.DT_I8 | dt == DataType.DT_I4)
            {
                if (value.IsString)
                {
                    Int64 parsedInt = -1;
                    if (!Int64.TryParse(value.ToString(), out parsedInt))
                    {
                        bool pbCancel = true;
                        ComponentMetaData.FireError(0, "MongoDataSource", "Cannot parse string value to integer: " + value.ToString(), "", 0, out pbCancel);
                    }
                    return parsedInt;
                }
                else
                {
                    return value.ToInt64();
                }
            }
            else if (dt == DataType.DT_BOOL)
            {
                return value.ToBoolean();
            }
            else if (dt == DataType.DT_R8 | dt == DataType.DT_R4)
            {
                return value.ToDouble();
            }
            else if (dt == DataType.DT_DATE | dt == DataType.DT_DBTIMESTAMPOFFSET | dt == DataType.DT_DBTIMESTAMP)
            {
                return DateTime.Parse(value.ToString());
            }
            else
            {
                if (dt != DataType.DT_STR && !value.IsObjectId && !value.IsString && !value.IsBsonSymbol)
                    ComponentMetaData.FireWarning(0, "MongoDataSource", "Converting " + value.BsonType + " to string, though datatype was " + dt, String.Empty, 0);

                return value.ToString();
            }
        }
示例#12
0
 protected override long ConvertExpectedResult(BsonValue expectedResult)
 {
     return expectedResult.ToInt64();
 }
示例#13
0
 /// <summary>
 /// Converts a <see cref="BsonValue" /> into a <see cref="UInt32" />
 /// </summary>
 /// <param name="value">The <see cref="BsonValue" /></param>
 /// <returns>The corresponding <see cref="UInt32" /></returns>
 public static uint ToUint(this BsonValue value)
 {
     return(Convert.ToUInt32(value.ToInt64()));
 }
示例#14
0
        private MongoNode AddBsonValueNode(string key, BsonValue v, MongoNode parent)
        {
            MongoNode node = new MongoNode {
                Key = key
            };

            if (v.IsBsonNull)
            {
                node = AddTreeNode(key, null, parent);
            }
            else if (v.IsBoolean)
            {
                node = AddTreeNode(key, v.ToBoolean(), parent);
            }
            else if (v.IsInt32)
            {
                node = AddTreeNode(key, v.ToInt32(), parent);
            }
            else if (v.IsInt32 || v.IsInt64)
            {
                node = AddTreeNode(key, v.ToInt64(), parent);
            }
            else if (v.IsDouble)
            {
                node = AddTreeNode(key, v.ToDouble(), parent);
            }
            else if (v.IsDecimal128 || v.IsNumeric)
            {
                node = AddTreeNode(key, v.ToDecimal(), parent);
            }
            else if (v.IsObjectId)
            {
                node = AddTreeNode(key, v.AsObjectId, parent);
            }
            else if (v.IsString || v.IsGuid)
            {
                node = AddTreeNode(key, v.ToString(), parent);
            }
            else if (v.IsValidDateTime || v.IsBsonDateTime)
            {
                node = AddTreeNode(key, v.ToLocalTime(), parent);
            }
            else if (v.IsString)
            {
                node = AddTreeNode(key, v.ToString(), parent);
            }
            else if (v.IsValidDateTime)
            {
                node = AddTreeNode(key, v.ToLocalTime(), parent);
            }
            else if (v.IsBsonArray)
            {
                var array = v.AsBsonArray;
                node.Value     = $"[{array.Count}]";
                node.Type      = "Array";
                node.ImagePath = ResourcesBase + @"/Images/arr.png";
                var i = 0;
                foreach (var item in array)
                {
                    AddBsonValueNode($"[{i}]", item, node);
                    i++;
                }
            }
            else
            {
                node = AddTreeNode(key, v.ToString(), parent);
            }

            return(node);
        }