示例#1
0
        public ActionResult GetVFRInfoByJobID(int jobID)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            GlobalVars.ResultsVFR resultVFR = new GlobalVars.ResultsVFR();
            try
            {
                logger.Info("GetVFRInfoByJobID API Request. Job ID: " + jobID);
                if (jobID == 0)
                {
                    Response.StatusCode  = (int)HttpStatusCode.BadRequest;
                    resultVFR.ReturnCode = -1;
                    resultVFR.Message    = "Missing argument Job ID";
                    logger.Warn("GetJobsByProjectID API Request ends with an Error.");
                    logger.Warn(resultVFR.Message);
                }
                else
                {
                    resultVFR = SQLFunctionsVFR.GetVFRInfoByJobID(jobID);
                    switch (resultVFR.ReturnCode)
                    {
                    case 0:
                        logger.Info("GetVFRInfoByJobID API Request was executed Successfully.");
                        Response.StatusCode = (int)HttpStatusCode.OK;
                        break;

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

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

            logger.Info("Leaving GetVFRInfoByJobID API.");
            //return Json(messaje);
            return(Content(messaje));
        }
示例#2
0
 /// <summary>
 /// Get VFR Server Information
 /// </summary>
 /// <returns></returns>
 static public GlobalVars.ResultsVFR GetVFRInfoByJobID(int jobID)
 {
     GlobalVars.VFR        vfr       = new GlobalVars.VFR();
     GlobalVars.ResultsVFR resultVFR = new GlobalVars.ResultsVFR()
     {
         ReturnCode     = 0,
         Message        = "",
         ReturnValue    = vfr,
         RecordsCount   = 0,
         HttpStatusCode = ""
     };
     try
     {
         logger.Trace("Entering into GetVFRInfoByJobID Method ...");
         using (ScanningDBContext DB = new ScanningDBContext())
         {
             var results = DB.Vfr.FirstOrDefault(x => x.JobId == jobID);
             if (results != null)
             {
                 resultVFR.RecordsCount = 1;
                 vfr.CADIUrl            = results.Cadiurl;
                 vfr.CaptureTemplate    = results.CaptureTemplate;
                 vfr.InstanceName       = results.InstanceName;
                 vfr.JobID          = results.JobId;
                 vfr.SettingID      = results.SettingId;
                 vfr.Password       = results.Password;
                 vfr.UserName       = results.UserName;
                 vfr.RepositoryName = results.RepositoryName;
                 vfr.QueryField     = results.QueryField;
             }
             else
             {
                 //There is no record in the database
             }
         }
         resultVFR.ReturnValue = vfr;
         resultVFR.Message     = "GetVFRInfoByJobID transaction completed successfully. Number of records found: " + resultVFR.RecordsCount;
         logger.Debug(resultVFR.Message);
     }
     catch (Exception e)
     {
         logger.Error("Error:" + e.Message + "\n" + "Exception: " + e.InnerException);
         resultVFR.ReturnCode = -2;
         resultVFR.Message    = e.Message;
         var baseException = e.GetBaseException();
         resultVFR.Exception = baseException.ToString();
     }
     logger.Trace("Leaving GetVFRInfoByJobID Method ...");
     return(resultVFR);
 }