public HttpResponseMessage GenerateCSV() { //Initialize service and model properties var connectionFactory = new HelperConnectionFactory(ConnectionHelper.Helper()); var sqlRepo = new SqlServerRepository(connectionFactory); var svc = new FileLatencyService(sqlRepo); var model = PopulateFileLatencyModelSettings(); model.GridConditions.StartRow = 1; model.GridConditions.EndRow = int.MaxValue; //Get the data model.GridConditions.EndRow = 0; model.GridConditions.StartRow = 0; String fileData = GetFileLatencyCsvData(svc, model); //Serialize response HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK); message.Content = new StringContent(fileData); message.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/csv"); message.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment"); message.Content.Headers.ContentDisposition.FileName = string.Format("FileLatencyReport-{0}.csv", DateTime.Now.ToString("yyyyMMdd-HHmmss")); return(message); }
/// <summary> /// Translates a recommendation view into grid data /// </summary> /// <param name="viewModel"></param> /// <returns></returns> private DataTableResponse GetFileLatencyGridData(FileLatencyService svc, FileLatencyViewModel viewModel) { var data = GetFilteredFileLatencyData(svc, viewModel); var dtResponse = new DataTableResponse() { sEcho = string.IsNullOrEmpty(viewModel.GridConditions.sEcho) ? "1" : viewModel.GridConditions.sEcho, aaData = data.Data, recordsTotal = data.Data.Count(), recordsFiltered = data.TotalRecordCount }; return(dtResponse); }
public HttpResponseMessage FileLatencyLastRun() { var connectionFactory = new HelperConnectionFactory(ConnectionHelper.Helper()); var sqlRepo = new SqlServerRepository(connectionFactory); var svc = new FileLatencyService(sqlRepo); //get data DateTime lastRunTime = svc.FileLatencyLastRun(); //Serialize response var json = lastRunTime.ToJson(); var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json"); return(response); }
private string GetFileLatencyCsvData(FileLatencyService svc, FileLatencyViewModel viewModel) { var filterResult = GetFilteredFileLatencyData(svc, viewModel); using (var sw = new System.IO.StringWriter()) { var heaaderArr = new string[] { "Server Name", "Database Name", "Score", "Data Read Latency", "Data Write Latency", "Log Read Latency", "Log Write Latency", }; sw.WriteLine(string.Join(",", heaaderArr)); foreach (var row in filterResult.Data) { sw.WriteCsvSafeLine(row); } return(sw.ToString()); } }
private FilterResult GetFilteredFileLatencyData(FileLatencyService svc, FileLatencyViewModel viewModel) { var grid = svc.FileLatencies(viewModel.GridConditions, viewModel.FilterConditions, viewModel.FilterOperands); var aaDataRel = grid.Data.Select(d => new String[] { d.ServerName, d.DatabaseName, d.Score.HasValue ? d.Score.Value.ToString("F2") : String.Empty, d.DataReadLatency.HasValue ? d.DataReadLatency.ToString() : String.Empty, d.DataWriteLatency.HasValue ? d.DataWriteLatency.ToString() : String.Empty, d.LogReadLatency.HasValue ? d.LogReadLatency.ToString() : String.Empty, d.LogWriteLatency.HasValue ? d.LogWriteLatency.ToString() : String.Empty }).ToArray(); return(new FilterResult() { Data = aaDataRel, TotalRecordCount = grid.Count }); }
public HttpResponseMessage GetDatabaseLatencyReport() { //Initialize service and model properties var connectionFactory = new HelperConnectionFactory(ConnectionHelper.Helper()); var sqlRepo = new SqlServerRepository(connectionFactory); var svc = new FileLatencyService(sqlRepo); var model = PopulateFileLatencyModelSettings(); var session = (HttpSessionState)GetSession(); session[DataTableSessionConstants.FileLatencyReportState] = model; //Get the data var dtResponse = GetFileLatencyGridData(svc, model); //Serialize response var json = dtResponse.ToJson(); var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json"); return(response); }