Пример #1
0
        public ActionResult GetFieldsByNameAndJobID(string fieldName, int jobID)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            GlobalVars.ResultFields resultFields = new GlobalVars.ResultFields();
            try
            {
                logger.Info("GetFieldsByNameAndJobID API Request. Field Name: " + fieldName + " and Job ID: " + jobID);
                if (jobID == 0 || string.IsNullOrEmpty(fieldName))
                {
                    Response.StatusCode     = (int)HttpStatusCode.BadRequest;
                    resultFields.ReturnCode = -1;
                    resultFields.Message    = "Missing argument Job ID and/or Capture Pro Field Name";
                    logger.Warn("GetFieldsByNameAndJobID API Request ends with an Error.");
                    logger.Warn(resultFields.Message);
                }
                else
                {
                    resultFields = SQLFunctionsFields.GetFieldsByNameAndJobID(fieldName, jobID);
                    switch (resultFields.ReturnCode)
                    {
                    case 0:
                        logger.Info("GetFieldsByNameAndJobID API Request was executed Successfully.");
                        Response.StatusCode = (int)HttpStatusCode.OK;
                        break;

                    case -2:
                        Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                        logger.Fatal("GetFieldsByNameAndJobID API Request ends with a Fatal Error.");
                        logger.Debug("Returned value:" + JsonConvert.SerializeObject(resultFields, Formatting.Indented));
                        Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                logger.Fatal("GetFieldsByNameAndJobID API Request ends with a Fatal Error.");
                resultFields.ReturnCode = -2;
                resultFields.Message    = e.Message;
                var baseException = e.GetBaseException();
                resultFields.Exception = baseException.ToString();
                logger.Fatal("Returned value:" + JsonConvert.SerializeObject(resultFields, Formatting.Indented));
                Response.StatusCode = (int)HttpStatusCode.InternalServerError;
            }
            Response.ContentType = "application/json";
            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            elapsedMs = elapsedMs / 1000;
            resultFields.ElapsedTime = elapsedMs.ToString();
            logger.Debug("Returned value:" + JsonConvert.SerializeObject(resultFields, Formatting.Indented));
            resultFields.HttpStatusCode = Response.StatusCode.ToString();
            var messaje = JsonConvert.SerializeObject(resultFields, Formatting.Indented);

            logger.Info("Leaving GetFieldsByNameAndJobID API.");
            //return Json(messaje);
            return(Content(messaje));
        }