Ejemplo n.º 1
0
        /// <summary>
        /// Get exception info
        /// </summary>
        /// <param name="ex">Exception</param>
        /// <param name="msgId">Message id</param>
        /// <param name="code">Status code</param>
        /// <param name="param">Parameters</param>
        /// <param name="isInternal">Check if exception is internal</param>
        /// <returns>Service error</returns>
        public static ServiceError GetExceptionInfo(this Exception ex, string msgId = null, string code = null, IDictionary <string, string> param = null, bool isInternal = false)
        {
            var result = new ServiceError()
            {
                MessageId = msgId,
#if DEBUG
                Message = ExceptionUtilities.GetFullExceptionMessage(ex),
#else
                Message = ex.Message,
#endif
                Params = param
            };

            if (isInternal == true)
            {
                result.InternalCode = code;
            }
            else
            {
                result.ErrorCode = code;

                if (code.IsEquals(InternalServerErrorCode))
                {
                    result.InternalCode = InternalServerErrorCode;
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Resolve
        /// </summary>
        /// <typeparam name="T">T</typeparam>
        /// <returns>T</returns>
        public static T Resolve <T>()
        {
            T ret = default(T);

            try
            {
                ret = (T)Service.BuildServiceProvider().GetService(typeof(T));
            }
            catch (Exception ex)
            {
                throw new Exception($"Can't Resolve :{ExceptionUtilities.GetFullExceptionMessage(ex)}");
            }

            if (ret == null)
            {
                throw new InvalidOperationException(string.Format("Type {0} not registered in service", typeof(T).Name));
            }

            return(ret);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Invokes Business Logic's method by name
        /// </summary>
        /// <typeparam name="TResponse">Method responese</typeparam>
        /// <param name="methodArgs">Parameters's method</param>
        /// <returns>Response's method</returns>
        private async Task <TResponse> OnExecute <TResponse>(params object[] methodArgs)
            where TResponse : BaseResponse, new()
        {
            TResponse response;

            try
            {
                //using (var scope = GetTransactionScope())
                //{
                dynamic awaitable = MetaData.Method.Invoke(BusinessLogic, methodArgs);
                await   awaitable;
                response = (TResponse)awaitable.GetAwaiter().GetResult();

                //if (scope != null && response.Success)
                //{
                //  scope.Commit();
                //  if (scope.TransactionStatus == TransactionStatus.Aborted)
                //  {
                //    throw new TransactionAbortedException();
                //  }
                //}
                //}
            }
            catch (Exception ex)
            {
                _errorToLog = ExceptionUtilities.GetFullExceptionMessage(ex);
                return(new TResponse()
                {
                    Success = false,
                    Errors = new ServiceErrors {
                        ex.GetExceptionInfo()
                    }
                });
            }

            return(response);
        }