private IEnumerable <QvxDataRow> GetData() { //Debugger.Launch(); dynamic data; recordsLoaded = 0; //Get a reference to the QvxTable from MTables QvxTable qTable = FindTable(liveTable, MTables); helper.Prep(); while (helper.IsMore) { data = helper.GetJSON(); //if we have a child link configured if (helper.ActiveTable.has_link_to_child != null && helper.ActiveTable.has_link_to_child == true) { dynamic childData = data; if (helper.ActiveTable.data_element_override == null || helper.ActiveTable.data_element_override.ToString() == "") { QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Error, "Data Element Override has not been set for Table - " + helper.ActiveTable.qName); } else { String backupUrl = helper.ActiveUrl; String childDataElementParam = helper.ActiveTable.data_element_override.ToString(); List <String> childDataElement = childDataElementParam.Split(new String[] { "." }, StringSplitOptions.RemoveEmptyEntries).ToList(); String childDataUrlElement = childDataElement.Last(); childDataElement.Remove(childDataElement.Last()); foreach (String elem in childDataElement) { childData = childData[elem]; } foreach (dynamic child in childData) { helper.ActiveUrl = ((dynamic)child)[childDataUrlElement]; childData = helper.GetJSON(); if (helper.ActiveTable.child_data_element != null && helper.ActiveTable.child_data_element.ToString() != "") { String childDataElemParam = helper.ActiveTable.child_data_element.ToString(); List <String> childDataElem = childDataElemParam.Split(new String[] { "." }, StringSplitOptions.RemoveEmptyEntries).ToList(); foreach (String elem in childDataElem) { childData = childData[elem]; } } Boolean dataIsArray; try { dynamic check = ((Newtonsoft.Json.Linq.JArray)(childData)).Type; //if this works then the data is an array dataIsArray = true; } catch (Exception ex) { dataIsArray = false; } if (dataIsArray) { foreach (dynamic row in childData) { if (recordsLoaded < helper.pageInfo.LoadLimit) { yield return(InsertRow(row, qTable, child)); } else { helper.IsMore = false; break; } } } else { if (recordsLoaded < helper.pageInfo.LoadLimit) { yield return(InsertRow(childData, qTable, child)); } else { helper.IsMore = false; break; } } } helper.ActiveUrl = backupUrl; } } else { if (!String.IsNullOrEmpty(helper.DataElement)) { List <String> dataElemPath = helper.DataElement.Split(new String[] { "." }, StringSplitOptions.RemoveEmptyEntries).ToList(); foreach (String elem in dataElemPath) { data = data[elem]; } } helper.pageInfo.CurrentPageSize = data.Count; helper.pageInfo.CurrentPage++; foreach (dynamic row in data) { if (recordsLoaded < helper.pageInfo.LoadLimit) { yield return(InsertRow(row, qTable, null)); } else { helper.IsMore = false; break; } } } helper.pageInfo.CurrentRecord = recordsLoaded; helper.Page(); } }
private IEnumerable <QvxDataRow> GetData() { //Debugger.Launch(); dynamic data; recordsLoaded = 0; //Get a reference to the QvxTable from MTables QvxTable qTable = FindTable(liveTable, MTables); helper.Prep(); bool isFromCache = helper.cacheEndpointMap.ContainsKey(helper.ActiveTable.endpoint.ToString()); while (helper.IsMore) { if (isFromCache) { String cachedTable = helper.cacheEndpointMap[helper.ActiveTable.endpoint.ToString()]; if (cachedTable != liveTable) { data = helper.getCachedData(cachedTable, helper.pageInfo.CurrentPage); } else { data = helper.GetJSON(); } } else { data = helper.GetJSON(); } if (data == null) { QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "End of data (" + liveTable + ")"); break; } if (data.GetType().Name == "JArray") { if (((Newtonsoft.Json.Linq.JArray)(data)).Count == 0) { QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "End of data (" + liveTable + ")"); break; } } if (helper.tableCacheList.IndexOf(liveTable) != -1) { if (!helper.cacheEndpointMap.ContainsKey(helper.ActiveTable.endpoint.ToString())) { helper.cacheEndpointMap.Add(helper.ActiveTable.endpoint.ToString(), liveTable); } helper.cacheTable(liveTable, helper.pageInfo.CurrentPage, data); } //if we have a child link configured if (helper.ActiveTable.has_link_to_child != null && helper.ActiveTable.has_link_to_child == true) { dynamic childData = data; if (helper.ActiveTable.data_element_override == null || helper.ActiveTable.data_element_override.ToString() == "") { QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Error, "Data Element Override has not been set for Table - " + helper.ActiveTable.qName); } else { String backupUrl = helper.ActiveUrl; String childDataElementParam = helper.ActiveTable.data_element_override.ToString(); List <String> childDataElement = childDataElementParam.Split(new String[] { "." }, StringSplitOptions.RemoveEmptyEntries).ToList(); String childDataUrlElement = childDataElement.Last(); childDataElement.Remove(childDataElement.Last()); foreach (String elem in childDataElement) { childData = childData[elem]; } foreach (dynamic child in childData) { helper.ActiveUrl = ((dynamic)child)[childDataUrlElement]; childData = helper.GetJSON(); if (helper.ActiveTable.child_data_element != null && helper.ActiveTable.child_data_element.ToString() != "") { String childDataElemParam = helper.ActiveTable.child_data_element.ToString(); List <String> childDataElem = childDataElemParam.Split(new String[] { "." }, StringSplitOptions.RemoveEmptyEntries).ToList(); foreach (String elem in childDataElem) { childData = childData[elem]; } } Boolean dataIsArray; try { dynamic check = ((Newtonsoft.Json.Linq.JArray)(childData)).Type; //if this works then the data is an array dataIsArray = true; } catch (Exception ex) { dataIsArray = false; } if (dataIsArray) { if (((Newtonsoft.Json.Linq.JArray)(childData)).Count == 0) { helper.IsMore = false; break; } foreach (dynamic row in childData) { if (recordsLoaded < helper.pageInfo.LoadLimit) { yield return(InsertRow(row, qTable, child)); recordsLoaded++; } else { helper.IsMore = false; break; } } } else { if (recordsLoaded < helper.pageInfo.LoadLimit) { yield return(InsertRow(childData, qTable, child)); } else { helper.IsMore = false; break; } } } helper.ActiveUrl = backupUrl; } } else { if (!String.IsNullOrEmpty(helper.DataElement)) { //Debugger.Launch(); List <String> dataElemPath = helper.DataElement.Split(new String[] { "." }, StringSplitOptions.RemoveEmptyEntries).ToList(); foreach (String elem in dataElemPath) { data = data[elem]; } } if (helper.ActiveTable.child_data_element != null && helper.ActiveTable.child_data_element.ToString() != "") { String childDataElemParam = helper.ActiveTable.child_data_element.ToString(); if (((Newtonsoft.Json.Linq.JArray)(data)).Count == 0) { helper.IsMore = false; break; } foreach (dynamic row in data) { dynamic childData = row; List <String> childDataElem = childDataElemParam.Split(new String[] { "." }, StringSplitOptions.RemoveEmptyEntries).ToList(); foreach (String elem in childDataElem) { if (elem == "*") { try { childData = ((Newtonsoft.Json.Linq.JProperty)(childData)).Value; } catch (Exception ex) { } } else { childData = childData[elem]; } } if (childData != null) { foreach (dynamic childRow in childData) { yield return(InsertRow(childRow, qTable, row)); } } if (recordsLoaded >= helper.pageInfo.LoadLimit) { helper.IsMore = false; break; } recordsLoaded++; } } else { //helper.pageInfo.CurrentPageSize = Convert.ToInt32(data.Count); //helper.pageInfo.CurrentPage++; if (data.GetType().Name == "JArray") { helper.pageInfo.CurrentPageSize = ((Newtonsoft.Json.Linq.JArray)(data)).Count; if (((Newtonsoft.Json.Linq.JArray)(data)).Count == 0) { helper.IsMore = false; break; } foreach (dynamic row in data) { if (recordsLoaded < helper.pageInfo.LoadLimit) { yield return(InsertRow(row, qTable, null)); recordsLoaded++; } else { helper.IsMore = false; break; } } } else { helper.pageInfo.CurrentPageSize = Convert.ToInt32(data.Count); if (recordsLoaded < helper.pageInfo.LoadLimit) { yield return(InsertRow(data, qTable, null)); recordsLoaded++; } else { helper.IsMore = false; break; } } } } helper.pageInfo.CurrentRecord = recordsLoaded; if (isFromCache) { helper.pageInfo.CurrentPage++; } else { helper.Page(); } } }