Exemplo n.º 1
0
        private static IEnumerable <KeyValuePair <string, object> > CreateCriteriaDictionary(InvokeMemberBinder binder, IList <object> args)
        {
            IDictionary <string, object> criteriaDictionary = null;

            if (binder.Name.Equals("FindBy") || binder.Name.Equals("find_by"))
            {
                if (args.Count == 0)
                {
                    throw new ArgumentException("FindBy requires arguments.");
                }
                if (binder.CallInfo.ArgumentNames != null && binder.CallInfo.ArgumentNames.Count > 0)
                {
                    criteriaDictionary = binder.NamedArgumentsToDictionary(args);
                }
                else if (args.Count == 1)
                {
                    if (ReferenceEquals(args[0], null))
                    {
                        throw new ArgumentException("FindBy does not accept unnamed null argument.");
                    }
                    criteriaDictionary = args[0].ObjectToDictionary();
                }
            }
            else
            {
                criteriaDictionary = MethodNameParser.ParseFromBinder(binder, args);
            }
            return(criteriaDictionary);
        }
Exemplo n.º 2
0
        internal static IEnumerable <KeyValuePair <string, object> > CreateCriteriaDictionary(InvokeMemberBinder binder, IList <object> args, params string[] exactNames)
        {
            IDictionary <string, object> criteriaDictionary = null;

            if (exactNames.Contains(binder.Name))
            {
                if (binder.CallInfo.ArgumentNames != null && binder.CallInfo.ArgumentNames.Count > 0)
                {
                    criteriaDictionary = binder.NamedArgumentsToDictionary(args);
                }
                else if (args.Count == 1)
                {
                    if (ReferenceEquals(args[0], null))
                    {
                        throw new ArgumentException("FindBy does not accept unnamed null argument.");
                    }
                    criteriaDictionary = args[0].ObjectToDictionary();
                }
            }
            else
            {
                criteriaDictionary = MethodNameParser.ParseFromBinder(binder, args);
            }

            if (criteriaDictionary == null || criteriaDictionary.Count == 0)
            {
                throw new ArgumentException(binder.Name + " requires an equal number of column names and values to filter data by.");
            }
            return(criteriaDictionary);
        }
Exemplo n.º 3
0
        private static SimpleExpression GetCriteriaExpression(InvokeMemberBinder binder, object[] args, DynamicTable table)
        {
            var criteria = binder.Name.Equals("delete", StringComparison.InvariantCultureIgnoreCase) ?
                           binder.NamedArgumentsToDictionary(args)
                               :
                           MethodNameParser.ParseFromBinder(binder, args);

            return(ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), criteria));
        }
Exemplo n.º 4
0
        public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            if (binder.HasSingleUnnamedArgument())
            {
                return(UpdateByKeyFields(table.GetQualifiedName(), dataStrategy, args[0],
                                         MethodNameParser.ParseCriteriaNamesFromMethodName(binder.Name)));
            }

            var criteria           = MethodNameParser.ParseFromBinder(binder, args);
            var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), criteria);
            var data = binder.NamedArgumentsToDictionary(args)
                       .Where(kvp => !criteria.ContainsKey(kvp.Key))
                       .ToDictionary();

            return(dataStrategy.Update(table.GetQualifiedName(), data, criteriaExpression));
        }
Exemplo n.º 5
0
        private static IDictionary <string, object> CreateCriteriaDictionary(InvokeMemberBinder binder, IList <object> args)
        {
            IDictionary <string, object> criteriaDictionary = null;

            if (binder.Name.Equals("FindBy") || binder.Name.Equals("find_by"))
            {
                if (binder.CallInfo.ArgumentNames != null && binder.CallInfo.ArgumentNames.Count > 0)
                {
                    criteriaDictionary = binder.NamedArgumentsToDictionary(args);
                }
            }
            else
            {
                criteriaDictionary = MethodNameParser.ParseFromBinder(binder, args);
            }
            return(criteriaDictionary);
        }
Exemplo n.º 6
0
        public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            object result;

            if (binder.HasSingleUnnamedArgument() || args.Length == 2 && args[1] is ErrorCallback)
            {
                result = UpsertByKeyFields(table.GetQualifiedName(), dataStrategy, args[0],
                                           MethodNameParser.ParseCriteriaNamesFromMethodName(binder.Name),
                                           !binder.IsResultDiscarded(),
                                           args.Length == 2 ? (ErrorCallback)args[1] : ((item, exception) => false));
            }
            else
            {
                var criteria           = MethodNameParser.ParseFromBinder(binder, args);
                var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(),
                                                                                         criteria);
                var data = binder.NamedArgumentsToDictionary(args);
                result = dataStrategy.Run.Upsert(table.GetQualifiedName(), data, criteriaExpression, !binder.IsResultDiscarded());
            }

            return(ResultHelper.TypeResult(result, table, dataStrategy));
        }
Exemplo n.º 7
0
        private static SimpleExpression GetCriteriaExpression(InvokeMemberBinder binder, object[] args, DynamicTable table)
        {
            IDictionary <string, object> criteria;

            if (binder.Name.Equals("delete", StringComparison.InvariantCultureIgnoreCase))
            {
                criteria = binder.NamedArgumentsToDictionary(args);
                if (criteria.Count == 0 && args.Length == 1)
                {
                    criteria = args[0] as IDictionary <string, object> ?? args[0].ObjectToDictionary();
                }
            }
            else
            {
                criteria = MethodNameParser.ParseFromBinder(binder, args);
            }

            if (criteria.Count == 0)
            {
                throw new InvalidOperationException("No criteria specified for Delete. To delete all data, use DeleteAll().");
            }

            return(ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), criteria));
        }
Exemplo n.º 8
0
        private static object CreateSimpleQuery(DynamicTable table, InvokeMemberBinder binder, object[] args, DataStrategy dataStrategy)
        {
            var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args));

            return(new SimpleQuery(dataStrategy, table.GetQualifiedName()).Where(criteriaExpression));
        }
Exemplo n.º 9
0
        public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args));
            var data     = dataStrategy.Find(table.GetQualifiedName(), criteria);

            return(new SimpleResultSet(data != null
                         ? data.Where(dict => dict != null).Select(dict => new SimpleRecord(dict, table.GetQualifiedName(), dataStrategy))
                         : Enumerable.Empty <SimpleRecord>()));
        }
Exemplo n.º 10
0
        public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args));
            var data = dataStrategy.FindOne(table.GetQualifiedName(), criteriaExpression);

            return(data != null ? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy) : null);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="dataStrategy">The data strategy.</param>
        /// <param name="table"></param>
        /// <param name="binder">The binder from the <see cref="DynamicTable"/> method invocation.</param>
        /// <param name="args">The arguments from the <see cref="DynamicTable"/> method invocation.</param>
        /// <returns></returns>
        public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args));

            return(new SimpleQuery(dataStrategy.GetAdapter(), table.GetQualifiedName()).Where(criteria).Count());
        }
Exemplo n.º 12
0
        public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            SimpleExpression criteriaExpression;

            if (binder.Name.Equals("FindAllBy") || binder.Name.Equals("find_all_by"))
            {
                criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), binder.NamedArgumentsToDictionary(args));
            }
            else
            {
                criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args));
            }
            return(new SimpleQuery(dataStrategy.GetAdapter(), table.GetQualifiedName()).Where(criteriaExpression));
        }
Exemplo n.º 13
0
        public Func <object[], object> CreateDelegate(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args));

            try
            {
                var func = dataStrategy.Adapter.CreateFindOneDelegate(table.GetQualifiedName(), criteriaExpression);
                return(a => new SimpleRecord(func(a), table.GetQualifiedName(), dataStrategy));
            }
            catch (NotImplementedException)
            {
                return(null);
            }
        }
Exemplo n.º 14
0
        public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args));
            var data     = dataStrategy.Find(table.GetQualifiedName(), criteria);

            return(CreateSimpleResultSet(table, dataStrategy, data));
        }