Ejemplo n.º 1
0
        public IActionResult Get(int limit, int year, int?month, int?day,
                                 [FromQuery(Name = "filters")] List <Dictionary <string, string> > filters,
                                 [FromQuery(Name = "order[]")] string[] order)
        {
            var path = _config.GetValue <string>("LogPath");
            var file = String.Format("u_ex{0}{1}{2}.log", year % 100, month?.ToString("00") ?? "??", day?.ToString("00") ?? "??");

            if (Directory.GetFiles(path, file).Length == 0)
            {
                return(BadRequest("No log files"));
            }

            var sb = new SelectBuilder()
                     .Select($"TOP {limit} *")
                     .From(Path.Combine(path, file))
                     .Where("1 = 1");

            foreach (var dict in filters)
            {
                var value = "'" + (dict["condition"].Contains("LIKE") ? "%" + dict["value"] + "%" : dict["value"]) + "'";
                sb.And(String.Concat(dict["field"], " ", dict["condition"], " ", value));
            }

            sb.OrderBy(order);

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return(Ok(GetData(sb.Build())));
            }
            else
            {
                return(StatusCode(StatusCodes.Status501NotImplemented));
            }
        }