예제 #1
0
        public ResultInfo <IDataReader, string> QueryToReader(DbExecuteParameter dbExecuteParameter)
        {
            while (Interlocked.CompareExchange(ref signal, 1, 0) == 1)
            {
                Thread.Sleep(LockTimeout);
                //waiting for lock to do;
            }
            try
            {
                DbConnection conn = CreateConnection(DbConnectionString);
                {
                    if (conn.State != ConnectionState.Open)
                    {
                        conn.Open();
                    }

                    DbCommand cmd = CreateCommand(dbExecuteParameter, conn);
                    {
                        IDataReader reader = cmd.ExecuteReader();
                        return(ResultInfo <IDataReader, string> .Create(reader, string.Empty));
                    }
                }
            }
            catch (Exception ex)
            {
                return(new ResultInfo <IDataReader, string>(null, ex.Message));
            }
            finally
            {
                Interlocked.Exchange(ref signal, 0);
            }
        }
예제 #2
0
 public Task OnExceptionAsync(ExceptionContext context)
 {
     if (context.ExceptionHandled == false)
     {
         context.Result = new ObjectResult(context.Exception is ExceptionBase ?
                                           ResultInfo.Create(((ExceptionBase)context.Exception).Code, ((ExceptionBase)context.Exception).Message)
             : ResultInfo.Create(StatusCode.Error, context.Exception.InnerException != null ? context.Exception.InnerException.Message : context.Exception.Message));
     }
     context.ExceptionHandled = true;
     return(Task.CompletedTask);
 }
예제 #3
0
        public ResultInfo <int, string> QueryTo <T>(DbExecuteParameter dbExecuteParameter, Func <T, bool> rowAction)
            where T : new()
        {
            while (Interlocked.CompareExchange(ref signal, 1, 0) == 1)
            {
                Thread.Sleep(LockTimeout);
                //waiting for lock to do;
            }
            try
            {
                int rows = 0;
                using (DbConnection conn = CreateConnection(DbConnectionString))
                {
                    if (conn.State != ConnectionState.Open)
                    {
                        conn.Open();
                    }

                    using (DbCommand cmd = CreateCommand(dbExecuteParameter, conn))
                    {
                        using (DbDataReader reader = cmd.ExecuteReader())
                        {
                            if (reader.HasRows == false)
                            {
                                return(ResultInfo <int, string> .Create(0, string.Empty));
                            }

                            bool isContinue = false;
                            while (reader.Read())
                            {
                                T row = reader.DataReaderTo <T>(dbExecuteParameter.IgnoreCase);
                                isContinue = rowAction(row);
                                if (isContinue == false)
                                {
                                    break;
                                }
                                ++rows;
                            }
                        }
                    }
                }

                return(ResultInfo <int, string> .Create <int, string>(rows, string.Empty));
            }
            catch (Exception ex)
            {
                return(new ResultInfo <int, string>(-1, ex.ToString()));
            }
            finally
            {
                Interlocked.Exchange(ref signal, 0);
            }
        }
예제 #4
0
        public TA GetY()
        {
            var invocationInfo = InvocationInfo.Create(
                typeof(ContainerAopProxy),
                nameof(GetY),
                GenericArgumentInfo.EmptyArray,
                _classGenericArguments,
                ResultInfo.Create(typeof(TA), _classGenericArgumentTa),
                GetY);

            var result = _interceptionHandler.Invoke(invocationInfo);

            return((TA)result.Result.Value);
        }
예제 #5
0
        public Task <List <int> > DoSomething(int parameter)
        {
            var invocationInfo = InvocationInfo.Create(
                typeof(TestInterfaceAopProxy),
                nameof(DoSomething),
                new[]
            {
                ArgumentInfo.Create(typeof(int), nameof(parameter), parameter)
            },
                ResultInfo.Create(typeof(Task <List <int> >)),
                DoSomethingInt32);

            var result = _interceptionHandler.Invoke(invocationInfo);

            return((Task <List <int> >)result.Result.Value);
        }
예제 #6
0
        public List <T> GetGenericList <T>()
        {
            var genericArgumentT = GenericArgumentInfo.Create(typeof(T), nameof(T));
            var invocationInfo   = InvocationInfo.Create(
                typeof(ContainerAopProxy),
                nameof(GetGenericList),
                new[]
            {
                genericArgumentT
            },
                ResultInfo.Create(typeof(List <T>), genericArgumentT),
                GetGenericList <T>);

            var result = _interceptionHandler.Invoke(invocationInfo);

            return((List <T>)result.Result.Value);
        }
예제 #7
0
        public long GetContactPhoneNumber(string firstName, string lastName)
        {
            var invocationInfo = InvocationInfo.Create(
                typeof(PhoneBookAopProxy),
                nameof(GetContactPhoneNumber),
                new[]
                {
                    ArgumentInfo.Create(typeof (string), nameof(firstName), firstName),
                    ArgumentInfo.Create(typeof (string), nameof(lastName), lastName)
                },
                ResultInfo.Create(typeof(long)),
                GetContactPhoneNumber);

            var result = _interceptionHandler.Invoke(invocationInfo);

            return (long)result.Result.Value;
        }
예제 #8
0
        public bool GetElement(int index, out object value)
        {
            var invocationInfo = InvocationInfo.Create(
                typeof(ContainerAopProxy),
                nameof(GetElement),
                new[]
            {
                ArgumentInfo.Create(typeof(int), nameof(index), index),
                ArgumentInfo.Create(typeof(object), nameof(value), default(object), ArgumentSpecialType.Out)
            },
                ResultInfo.Create(typeof(bool)),
                GetElement);

            var       result     = _interceptionHandler.Invoke(invocationInfo);
            const int valueIndex = 1;

            value = result.Arguments[valueIndex].Value;

            return((bool)result.Result.Value);
        }
        public T GetBar <T>() where T : struct
        {
            var genericArgumentT = GenericArgumentInfo.Create(
                typeof(T),
                nameof(T),
                new[] { GenericArgumentRestriction.Create(GenericArgumentRestrictionType.Struct) });

            var invocationInfo = InvocationInfo.Create(
                typeof(InterfaceWithGenericMethodAopProxy),
                nameof(GetBar),
                new[]
            {
                genericArgumentT
            },
                ResultInfo.Create(typeof(T), genericArgumentT),
                GetBar <T>);

            var result = _interceptionHandler.Invoke(invocationInfo);

            return((T)result.Result.Value);
        }
예제 #10
0
        public T GetElement <T>(int index)
        {
            var genericArgumentT = GenericArgumentInfo.Create(typeof(T), nameof(T));
            var invocationInfo   = InvocationInfo.Create(
                typeof(ContainerAopProxy),
                nameof(GetElement),
                new[]
            {
                ArgumentInfo.Create(typeof(int), nameof(index), index, genericArgumentT)
            },
                new[]
            {
                genericArgumentT
            },
                ResultInfo.Create(typeof(T), genericArgumentT),
                GetElement <T>);

            var result = _interceptionHandler.Invoke(invocationInfo);

            return((T)result.Result.Value);
        }
예제 #11
0
 public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
 {
     if (context.Result is EmptyResult)
     {
         context.Result = new ObjectResult(ResultInfo.Create());
     }
     else if (context.Result is ObjectResult objectResult)
     {
         if (objectResult.Value is ResultInfo resultInfo)
         {
             context.Result = new ObjectResult(resultInfo);
         }
         else
         {
             objectResult.StatusCode ??= 200;
             context.Result = new ObjectResult(ResultInfo.Create(
                                                   (StatusCode)objectResult.StatusCode,
                                                   objectResult.StatusCode == 200 ? "Success" : context.Result.GetType().Name.Replace("ObjectResult", ""),
                                                   objectResult.Value)
                                               );
         }
     }
     _ = await next();
 }