Ejemplo n.º 1
0
        public async Task <IActionResult> CallRest <D, T, G, A>(Func <T, G, A, Task <OperationResult <D> > > result, T input, G input1, A input2)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                OperationResult <D> res = await result(input, input1, input2);

                if (res.Succeeded)
                {
                    return(Ok(res.SuccessResult));
                }
                return(BadRequest(res.Errors));
            }
            catch (Exception e)
            {
                Loki.ExceptionError(e);
                HttpContext.Items["Exception"] = e;
                if (RethrowException)
                {
                    throw;
                }
                return(BadRequest(OperationResult.Fail <D>(GeneralErrorCode, GeneralErrorMessage).Errors));
            }
        }
Ejemplo n.º 2
0
        public IActionResult CallRest <D, T>(Func <T, OperationResult <D> > result, T input)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                OperationResult <D> res = result(input);
                if (res.Succeeded)
                {
                    return(Ok(res.SuccessResult));
                }
                return(BadRequest(res.Errors));
            }
            catch (Exception e)
            {
                Loki.ExceptionError(e);
                HttpContext.Items["Exception"] = e;
                if (RethrowException)
                {
                    throw;
                }

                return(BadRequest(OperationResult.Fail <D>(GeneralErrorCode, GeneralErrorMessage).Errors));
            }
        }
Ejemplo n.º 3
0
        public IActionResult CallRest <D, T, G, A, B, C, E, F, H, I, J>(Func <T, G, A, B, C, E, F, H, I, J, OperationResult <D> > result, T input, G input1, A input2, B input3, C input4, E input5, F input6, H input7, I input8, J input9)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                OperationResult <D> res = result(input, input1, input2, input3, input4, input5, input6, input7, input8, input9);
                if (res.Succeeded)
                {
                    return(Ok(res.SuccessResult));
                }
                return(BadRequest(res.Errors));
            }
            catch (Exception e)
            {
                Loki.ExceptionError(e);
                HttpContext.Items["Exception"] = e;
                if (RethrowException)
                {
                    throw;
                }

                return(BadRequest(OperationResult.Fail <D>(GeneralErrorCode, GeneralErrorMessage).Errors));
            }
        }
Ejemplo n.º 4
0
        public async Task Invoke(HttpContext context)
        {
            WebRestLog log = new WebRestLog()
            {
                TraceId = context.TraceIdentifier
            };

            try
            {
                log = await LogRequest(context.Request, log);
            }
            catch (Exception e)
            {
                Loki.ExceptionWarning("Error in Loki Middleware logging Request", e);
            }

            var originalBodyStream = context.Response.Body;

            using (var responseBody = new MemoryStream())
            {
                context.Response.Body = responseBody;

                await _next(context);

                await LogResponse(context.Response, log);

                await responseBody.CopyToAsync(originalBodyStream);
            }
        }
Ejemplo n.º 5
0
 public void Init(object instance, MethodBase method, object[] args)
 {
     _stopwatch  = new Stopwatch();
     _methodName = method.Name;
     _className  = method.DeclaringType.FullName;
     Loki.Write(Loki.INVOKE_TYP, LogLevel.SystemGenerated, null, _methodName, _className, -1, args);
 }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Loki loki = new Loki();

            // Install assistant
            loki.Install();

            // Start him
            loki.Start();
        }
Ejemplo n.º 7
0
 void Awake()
 {
     if (S == null)
     {
         S = this;
     }
     else
     {
     }
 }
Ejemplo n.º 8
0
 void Awake()
 {
     if (S == null)
     {
         S = this;
     }
     else
     {
         Debug.LogError("Hero.Awake() - attapted to assign second Hero.S!");
     }
 }
Ejemplo n.º 9
0
        public async Task <IActionResult> CallRest <D>(Func <Task <OperationResult <D> > > result)
        {
            try
            {
                OperationResult <D> res = await result();

                if (res.Succeeded)
                {
                    return(Ok(res.SuccessResult));
                }
                return(BadRequest(res.Errors));
            }
            catch (Exception e)
            {
                Loki.ExceptionError(e);
                HttpContext.Items["Exception"] = e;
                if (RethrowException)
                {
                    throw;
                }
                return(BadRequest(OperationResult.Fail <D>(GeneralErrorCode, GeneralErrorMessage).Errors));
            }
        }
Ejemplo n.º 10
0
 public LokiObjectAdapter()
 {
     _logs   = new ConcurrentQueue <Log>();
     _client = new HttpClient();
     Loki.UpdateAdapter(this);
 }
Ejemplo n.º 11
0
        public async Task Invoke(HttpContext context)
        {
            if (!LokiObjectAdapter.LokiConfig.UseLokiMiddleware || LokiObjectAdapter.LokiConfig.IgnoreRoutes.Any(x => context.Request.Path.ToString().Contains(x)))
            {
                await _next(context);
            }
            else
            {
                WebRestLog log = new WebRestLog()
                {
                    TraceId = context.TraceIdentifier
                };
                try
                {
                    if (!LokiObjectAdapter.LokiConfig.NoRequestRoutes.Any(x => context.Request.Path.ToString().Contains(x)))
                    {
                        log = await LogRequest(context.Request, log);
                    }
                }
                catch (Exception e)
                {
                    Loki.ExceptionWarning("Error in Loki Middleware logging Request", e);
                }

                var originalBodyStream = context.Response.Body;

                //Create a new memory stream...
                using (var responseBody = new MemoryStream())
                {
                    context.Response.Body = responseBody;
                    try
                    {
                        await _next(context);

                        if (context.Items.ContainsKey("Exception"))
                        {
                            Exception ex = (Exception)context.Items["Exception"];
                            log.Exception = ex.Message + "\n" + ex.StackTrace + "\n" + ex.Source;
                        }
                    }
                    catch (Exception e)
                    {
                        log.Exception = e.Message + "\n" + e.StackTrace + "\n" + e.Source;
                        await LogResponse(context.Response, log);

                        Loki.Write(Loki.REST_TYP, LogLevel.Error, "", "Invoke", "LokiWebExtension.Middleware.LokiMiddleware", 48, log);
                        throw;
                    }

                    try
                    {
                        if (!LokiObjectAdapter.LokiConfig.NoResponseRoutes.Any(x => context.Request.Path.ToString().Contains(x)))
                        {
                            await LogResponse(context.Response, log);
                        }
                    }
                    catch (Exception e)
                    {
                        Loki.ExceptionWarning("Error in Loki Middleware logging Response", e);
                    }
                    if (originalBodyStream.CanWrite && responseBody.CanRead)
                    {
                        await responseBody.CopyToAsync(originalBodyStream);
                    }
                }


                Loki.Write(Loki.REST_TYP, LogLevel.SystemGenerated, "", "Invoke", "LokiWebExtension.Middleware.LokiMiddleware", 55, log);
            }
        }
Ejemplo n.º 12
0
 public void OnException(Exception exception)
 {
     _stopwatch.Stop();
     Loki.Write(Loki.EXCEPTION_TYP, LogLevel.SystemGenerated, null, _methodName, _className, -1, exception);
 }
Ejemplo n.º 13
0
 public void OnExit()
 {
     _stopwatch.Stop();
     Loki.Write(Loki.RETURN_TYP, LogLevel.SystemGenerated, null, _methodName, _className, -1, _stopwatch.ElapsedTicks);
 }