Inheritance: System.Attribute
Ejemplo n.º 1
0
 public override void Execute(IInvocation invocation, DbAttributeBase attribute)
 {
     Database db = DatabaseHelper.GetDatabase();
     db.Connection.Open();
     int result = db.Delete(invocation.Arguments.FirstOrDefault());
     base.SetInvocationResult(invocation, result);
 }
Ejemplo n.º 2
0
        public override void Execute(IInvocation invocation, DbAttributeBase attribute)
        {
            Contract.Requires(invocation.Arguments.Length > 0);
            Database db = DatabaseHelper.GetDatabase();
            db.Connection.Open();
            object result = null;

            object arg = null;
            for (int i = 0; i < invocation.Arguments.Length; i++)
            {
                arg = invocation.Arguments[i];
                if (arg is IEnumerable)
                {
                    foreach (var argItem in (arg as IEnumerable))
                    {
                        result = db.Insert(argItem);
                    }
                }
                else
                {
                    result = db.Insert(arg);
                }

            }

            base.SetInvocationResult(invocation, result);
        }
Ejemplo n.º 3
0
 public override void Execute(IInvocation invocation, DbAttributeBase attribute)
 {
     Database db = DatabaseHelper.GetDatabase();
     QueryCommand command = QueryStore.Commands[string.Format("{0}.{1}", invocation.TargetType.GetInterfaces()[0].Name, invocation.Method.Name)];
     db.Connection.Open();
     int result = db.Execute(command.Query);
     base.SetInvocationResult(invocation, result);
 }
Ejemplo n.º 4
0
        internal static DbOperationBase GetOperator(DbAttributeBase dbAttribute)
        {
            DbOperationBase operationBase = null;

            bool hasValue = _operator.ContainsKey(dbAttribute.GetType());
            if (!hasValue)
            {
                operationBase = new SelectOperator();
            }
            else
            {
                operationBase = _operator[dbAttribute.GetType()];
            }

            return operationBase;
        }
Ejemplo n.º 5
0
        public override void Execute(IInvocation invocation, DbAttributeBase attribute)
        {
            string key = string.Format("{0}.{1}", invocation.TargetType.GetInterfaces()[0].Name, invocation.Method.Name);
            bool hasKey = QueryStore.Commands.ContainsKey(key);
            if (!hasKey)
            {
                string interfaceName = invocation.TargetType.GetInterfaces()[0].Name;
                string methodName = invocation.Method.Name;
                throw new QueryForMethodNotFoundException(interfaceName, methodName);
            }
            QueryCommand command = QueryStore.Commands[key];
            string query = command.Query;

            Database db = DatabaseHelper.GetDatabase();

            Type genericParameter = invocation.Method.ReturnType;

            if (genericParameter.IsGenericType)
            {
                genericParameter = genericParameter.GetGenericArguments()[0];
            }

            MethodInfo info = _genericQueryMethod.MakeGenericMethod(genericParameter);
            Debug.Assert(info != null);
            dynamic expando = new DynamicArgumentHolder(invocation);
            db.Connection.Open();

            IEnumerable xx = (IEnumerable)info.Invoke(db, new object[] { query, new object[] { expando } });
            if (typeof(IList).IsAssignableFrom(invocation.Method.ReturnType))
            {
                IList collectionInstance = (IList)Activator.CreateInstance(invocation.Method.ReturnType);
                foreach (var item in xx)
                {
                    collectionInstance.Add(item);
                }
                invocation.ReturnValue = collectionInstance;
            }
            else
            {
                foreach (var item in xx)
                {
                    invocation.ReturnValue = item;
                    break;
                }
            }
        }
Ejemplo n.º 6
0
 public abstract void Execute(IInvocation invocation,DbAttributeBase attribute);