예제 #1
0
 public Dictionary(IConvertibleToBsonDocument document)
 {
     if (document == null)
     {
         throw new ArgumentNullException("document");
     }
     _document = document.ToBsonDocument();
 }
예제 #2
0
        // public for tests
        public static Expression GetExpression(IConvertibleToBsonDocument update, IConvertibleToBsonDocument query, bool insert)
        {
            var        compiler   = new UpdateCompiler();
            Expression expression = Expression.Constant(compiler, typeof(UpdateCompiler));

            if (update == null)
            {
                return(expression);
            }

            if (insert)
            {
                expression = UpdateFromQueryExpression(expression, query);
            }

            var document = update.ToBsonDocument();

            bool isName = false;
            bool isOper = false;
            var  names  = new List <string>();

            foreach (var element in document)
            {
                var name = element.Name;
                if (name[0] == '$')
                {
                    if (isName)
                    {
                        ThrowMixedOperatorsAndNames();
                    }
                    isOper = true;

                    foreach (var fieldElement in element.Value.AsBsonDocument)
                    {
                        var fieldName = fieldElement.Name;
                        ValidateFieldName(fieldName, names);
                        expression = OperatorExpression(expression, name, Expression.Constant(fieldName, typeof(string)), fieldElement.Value, insert);
                    }
                }
                else                 //_131103_204607
                {
                    if (isOper)
                    {
                        ThrowMixedOperatorsAndNames();
                    }
                    isName = true;

                    ValidateFieldName(name, names);
                    expression = SetExpression(expression, Expression.Constant(name, typeof(string)), element.Value);
                }
            }

            return(expression);
        }
예제 #3
0
        // public for tests
        public static Expression GetExpression(IConvertibleToBsonDocument query)
        {
            if (query == null)
                return Expression.Constant(true, typeof(bool));

            var document = query.ToBsonDocument();
            switch (document.ElementCount)
            {
                case 1:
                    return ElementExpression(document.GetElement(0));
                case 0:
                    return Expression.Constant(true, typeof(bool));
                default:
                    return DocumentExpression(document);
            }
        }
예제 #4
0
        // public for tests
        public static Expression GetExpression(IConvertibleToBsonDocument update, IConvertibleToBsonDocument query, bool insert)
        {
            var compiler = new UpdateCompiler();
            Expression expression = Expression.Constant(compiler, typeof(UpdateCompiler));

            if (update == null)
                return expression;

            if (insert)
                expression = UpdateFromQueryExpression(expression, query);

            var document = update.ToBsonDocument();

            bool isName = false;
            bool isOper = false;
            var names = new List<string>();
            foreach (var element in document)
            {
                var name = element.Name;
                if (name[0] == '$')
                {
                    if (isName) ThrowMixedOperatorsAndNames();
                    isOper = true;

                    foreach (var fieldElement in element.Value.AsBsonDocument)
                    {
                        var fieldName = fieldElement.Name;
                        ValidateFieldName(fieldName, names);
                        expression = OperatorExpression(expression, name, Expression.Constant(fieldName, typeof(string)), fieldElement.Value, insert);
                    }
                }
                else //_131103_204607
                {
                    if (isOper) ThrowMixedOperatorsAndNames();
                    isName = true;

                    ValidateFieldName(name, names);
                    expression = SetExpression(expression, Expression.Constant(name, typeof(string)), element.Value);
                }
            }

            return expression;
        }
예제 #5
0
        // public for tests
        public static Expression GetExpression(IConvertibleToBsonDocument query)
        {
            if (query == null)
            {
                return(Expression.Constant(true, typeof(bool)));
            }

            var document = query.ToBsonDocument();

            switch (document.ElementCount)
            {
            case 1:
                return(ElementExpression(document.GetElement(0)));

            case 0:
                return(Expression.Constant(true, typeof(bool)));

            default:
                return(DocumentExpression(document));
            }
        }
예제 #6
0
        static Expression UpdateFromQueryExpression(Expression that, IConvertibleToBsonDocument query)
        {
            if (query == null)
            {
                return(that);
            }

            foreach (var element in query.ToBsonDocument())
            {
                // v2.6 fails
                if (element.Name[0] == '$')
                {
                    throw new ArgumentException(string.Format(null, "Unknown top level query operator: ({0}).", element.Name));
                }

                var selector = element.Value;
                switch (selector.BsonType)
                {
                case BsonType.RegularExpression:
                    continue;

                case BsonType.Document:                         //TODO _140223_223449
                    var document = selector.AsBsonDocument;
                    if (document.ElementCount > 0)
                    {
                        var name = document.GetElement(0).Name;
                        if (name[0] == '$' && name != "$ref")
                        {
                            continue;
                        }
                    }
                    break;
                }

                that = UpdateCompiler.SetExpression(that, Expression.Constant(element.Name, typeof(string)), selector);
            }

            return(that);
        }
예제 #7
0
파일: Dictionary.cs 프로젝트: jajp777/Mdbc
 public Dictionary(IConvertibleToBsonDocument document)
 {
     if (document == null) throw new ArgumentNullException("document");
     _document = document.ToBsonDocument();
 }
예제 #8
0
        static Expression UpdateFromQueryExpression(Expression that, IConvertibleToBsonDocument query)
        {
            if (query == null)
                return that;

            foreach (var element in query.ToBsonDocument())
            {
                if (element.Name[0] == '$')
                    continue;

                var selector = element.Value;
                switch(selector.BsonType)
                {
                    case BsonType.RegularExpression:
                        continue;
                    case BsonType.Document:
                        var document = selector.AsBsonDocument;
                        if (document.ElementCount > 0)
                        {
                            var name = document.GetElement(0).Name;
                            if (name[0] == '$' && name != "$ref")
                                continue;
                        }
                        break;
                }

                that = UpdateCompiler.SetExpression(that, Expression.Constant(element.Name, typeof(string)), selector);
            }

            return that;
        }