public async Task <IHttpActionResult> GetPerfCounters([FromUri] UriParams uriParams)
        {
            HttpResponseMessage responseMessage = new HttpResponseMessage();

            System.Web.Http.Results.ResponseMessageResult resultMessage = null;

            ServerTrack.DataManager.DataManager dm = new ServerTrack.DataManager.DataManager();
            ServerTrack.Models.ServerTrack      st = await dm.MapDataTableToServerTrackModel(uriParams.SrvName, uriParams.TimeInterval);

            if (st == null)
            {
                responseMessage.StatusCode = HttpStatusCode.InternalServerError;
                resultMessage = new System.Web.Http.Results.ResponseMessageResult(responseMessage);
                return(resultMessage);
            }
            return(Ok(st));
        }
Пример #2
0
        /// <summary>
        /// Maps the data table to server track model.
        /// </summary>
        /// <param name="srvName">Name of the SRV.</param>
        /// <param name="timeFrame">The time frame.</param>
        /// <returns>Models.ServerTrack</returns>
        public async Task <ServerTrack.Models.ServerTrack> MapDataTableToServerTrackModel(string srvName, int timeFrame)
        {
            ServerTrack.Models.ServerTrack  serviceTrack = null;
            ServerTrack.Models.PerfCounters perfCounters = null;
            List <PerfCounters>             list         = new List <PerfCounters>();
            DataTable tbl = null;

            tbl = await _dataAccess.GetRecords(srvName, timeFrame);

            if (tbl != null && tbl.Rows.Count > 0)
            {
                try
                {
                    serviceTrack          = new Models.ServerTrack();
                    serviceTrack.Counters = new List <PerfCounters>();
                    serviceTrack.Server   = srvName;
                    foreach (DataRow r in tbl.Rows)
                    {
                        perfCounters           = new PerfCounters();
                        perfCounters.TimeStamp = ((DateTime)r.ItemArray.GetValue(0)).ToString("yyyy-MM-ddTHH:mm:ss");
                        perfCounters.Cpu_Usage = (double)r.ItemArray.GetValue(1);
                        perfCounters.Ram_Usage = (double)r.ItemArray.GetValue(2);
                        serviceTrack.Counters.Add(perfCounters);
                    }
                }
                catch (Exception ex)
                {
                    log.Error("DataManager.MapDataTableToServerTrackModel", ex);
                    ErrorHolder.StatusCode  = System.Net.HttpStatusCode.InternalServerError;
                    ErrorHolder.Description = ex.Message;
                    serviceTrack            = null;
                }
            }
            else
            {
                log.Error("DataManager.MapDataTableToServerTrackModel. Call 'await _dataAccess.GetRecords(srvName, timeFrame)' returned null or empty table");
                ErrorHolder.StatusCode  = System.Net.HttpStatusCode.InternalServerError;
                ErrorHolder.Description = "DataManager.MapDataTableToServerTrackModel.Call 'await _dataAccess.GetRecords(srvName, timeFrame)' returned null or empty table";
                serviceTrack            = null;
            }

            return(serviceTrack);
        }