public async Task <JsonResult> getData(string json = null) { Error.TraceStart(); string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); //Error.TraceLog("GraphController.getData, point1"); StreamReader stream = new StreamReader(Request.InputStream); if (json == null) { json = stream.ReadToEnd(); } if (json != "") { object data = new object(); DataRequest dataRequest = new JavaScriptSerializer().Deserialize <DataRequest>(json); Error.TraceLog("GraphController.getData, point1"); try { GraphHandler GH = new GraphHandler(); DataRequest dataResponse = await GH.proceedSQLquery(dataRequest, config); Error.TraceLog("GraphController.getData, point2"); if ((dataRequest.beginTime + dataRequest.timeAxisLength) <= AlarmHelper.DateTimeTopkTime(DateTime.Now)) { if (dataResponse.tags.All(p => p.vals.All(q => (q == double.MaxValue)) == true)) { for (int i = 0; i < dataResponse.tags.Count; i++) { dataResponse.tags[i].vals = null; } } } data = dataResponse; Error.TraceLog("GraphController.getData, point3"); return(Json(data, "application/json", JsonRequestBehavior.AllowGet)); } catch (Exception e) { data = dataRequest; string k = e.Message.ToString() + e.Source.ToString() + e.StackTrace.ToString(); string name = this.ControllerContext.RouteData.Values["controller"].ToString(); Error.toFile(k, name); Session["tempforview"] = Error.timestamp + " Error " + MvcApplication.ErrorId.ToString() + " occured so please try it again after some time"; //To screen also with id return(Json(data, "application/json", JsonRequestBehavior.AllowGet)); } } else { return(null); } }
public async Task <JsonResult> getEventsHeader() { int batchStart = 0; int batchEnd = 0; StreamReader stream = new StreamReader(Request.InputStream); string json = stream.ReadToEnd(); DataRequest dataRequest = new JavaScriptSerializer().Deserialize <DataRequest>(json); string DB = string.Empty; string table = string.Empty; foreach (string key in Session.Keys) { if (key.Contains("dbName") && key.Contains(Request.QueryString["plc"].ToString())) { DB = Session[key].ToString(); } if (key.Contains("tableName") && key.Contains(Request.QueryString["plc"].ToString())) { table = Session[key].ToString(); } } ReportDBHelper db = new ReportDBHelper(DB, 2); DataReportModel data = await db.SelectHeaderDataAsync(dataRequest.beginTime, dataRequest.beginTime + dataRequest.timeAxisLength, table); GraphEventsData GED = new GraphEventsData(); GED.events = new List <ColumnGraphModel>(); foreach (ColumnReportModel CRM in data.Data) { ColumnGraphModel CGM = new ColumnGraphModel(); CGM.RecordNo = CRM.RecordNo; CGM.RecordType = (int)CRM.RecordType; CGM.TimeStart = AlarmHelper.DateTimeTopkTime(CRM.TimeStart); CGM.TimeEnd = AlarmHelper.DateTimeTopkTime(CRM.TimeEnd); CGM.BatchNo = CRM.BatchNo; CGM.Destination = CRM.Destination; CGM.Need = CRM.Need; CGM.Actual = CRM.Actual; CGM.Variant1 = CRM.Variant1; CGM.Variant2 = CRM.Variant2; CGM.Variant3 = CRM.Variant3; if (CGM.RecordType == 10 || CGM.RecordType == 14) { if (data.Data.Exists(p => (int)p.RecordType == 10 && p.BatchNo == CGM.BatchNo)) { batchStart = AlarmHelper.DateTimeTopkTime(data.Data.Single(p => (int)p.RecordType == 10 && p.BatchNo == CGM.BatchNo).TimeStart); } if (data.Data.Exists(p => (int)p.RecordType == 14 && p.BatchNo == CGM.BatchNo)) { batchEnd = AlarmHelper.DateTimeTopkTime(data.Data.Single(p => (int)p.RecordType == 14 && p.BatchNo == CGM.BatchNo).TimeEnd); } if (data.Data.Exists(p => (int)p.RecordType == 10 && p.BatchNo == CGM.BatchNo) && data.Data.Exists(p => (int)p.RecordType == 14 && p.BatchNo == CGM.BatchNo)) { CGM.Variant3 = batchEnd - batchStart; } //Duration is for George graphs in recordType 10 and 14 } CGM.Variant4 = CRM.Variant4; GED.events.Add(CGM); } return(Json(GED)); //it add data in the reguested shape to client }