Ejemplo n.º 1
0
        public async Task <IActionResult> Discovery([FromBody] JObject request)
        {
            var         watch      = System.Diagnostics.Stopwatch.StartNew();
            string      methodName = "Discovery";
            ResponseDTO response   = new ResponseDTO();

            try
            {
                Log.Write(appSettings, LogEnum.DEBUG.ToString(), label, className, methodName, $"REQUEST: {JsonConvert.SerializeObject(request)}");
                DiscoveryRequest requestBody = request.ToObject <DiscoveryRequest>();
                switch (requestBody.Operation)
                {
                case "environment":
                    response.Result = await Task.Run(() => DiscoveryService.Environments(appSettings, requestBody));

                    break;

                case "collection":
                    response.Result = await Task.Run(() => DiscoveryService.Collections(appSettings, requestBody));

                    break;

                case "field":
                    response.Result = await Task.Run(() => DiscoveryService.CollectionFields(appSettings, requestBody));

                    break;

                case "query":
                    response.Result = await Task.Run(() => DiscoveryService.QueryCollection(appSettings, requestBody));

                    break;

                default:
                    break;
                }
                response.Success = true;
                watch.Stop();
                Log.Write(appSettings, LogEnum.DEBUG.ToString(), label, className, methodName, $"RESULT: {JsonConvert.SerializeObject(response)} Execution Time: {watch.ElapsedMilliseconds} ms");
                return(Ok(response));
            }
            catch (Exception e)
            {
                response.Success = false;
                response.Msg     = e.Message;
                watch.Stop();
                Log.Write(appSettings, LogEnum.ERROR.ToString(), label, className, methodName, $"ERROR: {JsonConvert.SerializeObject(request)}");
                Log.Write(appSettings, LogEnum.ERROR.ToString(), label, className, methodName, $"ERROR: {e.Source + Environment.NewLine + e.Message + Environment.NewLine + e.StackTrace}");
                return(BadRequest(response));
            }
        }