private void HTTPCallback(HTTPResponse res) { // network error if (res.error) { if (!keepRetrying && !callbackDelivered) { failedCallback("Network error"); } return; } EventJSON jsonResponse = new EventJSON(System.Text.Encoding.UTF8.GetString(res.data, 0, res.data.Length)); // check that server response has status "ok" if (jsonResponse.hasInt("status")) { if (jsonResponse.getInt("status") == 200) { // event delivery successful keepRetrying = false; if (!callbackDelivered) { callbackDelivered = true; callback(res); } return; } } // if we didn't get status "ok", then whatever we got will be treated as error if (jsonResponse.hasBool("retryable")) { bool retry = jsonResponse.getBool("retryable"); if (!retry) { // We have received an error and retrying has been explicitly forbidden keepRetrying = false; if (!callbackDelivered) { failedCallback("Retrying forbidden by remote server"); } return; } } // We have received an error so if there are no more retries, deliver the callback if (!keepRetrying && !callbackDelivered) { failedCallback("Error"); } }
public IEnumerable<BreakerOperation> GetBreakerOperations(EventJSON json) { using (DataContext dataContext = new DataContext("systemSettings")) { DateTime startTime = (json != null ? (json.StartDate ?? DateTime.Parse("01/01/01")) : DateTime.Parse("01/01/01")); DateTime endTime = (json != null ? (json.EndDate ?? DateTime.Now) : DateTime.Now); IEnumerable<DataRow> table = Enumerable.Empty<DataRow>(); try { if (json == null || (json.EventIDList == null && json.MeterAssetKeyList == null && json.LineIDList == null && json.LineAssetKeyList == null && json.MeterIDList == null)) { table = dataContext.Connection.RetrieveData("Select * FROM BreakerOperation WHERE TripCoilEnergized >= {0} AND TripCoilEnergized <= {1}", startTime, endTime).Select(); return table.Select(row => dataContext.Table<BreakerOperation>().LoadRecord(row)).ToList(); } if (json.MeterIDList != null) { object[] ids = json.MeterIDList.Split(',').Select(int.Parse).Cast<object>().ToArray(); string param = string.Join(",", ids.Select((id, index) => $"{{{index}}}")); table = dataContext.Connection.RetrieveData($"Select * FROM BreakerOperation WHERE TripCoilEnergized >= '{startTime}' AND TripCoilEnergized <= '{endTime}' AND EventID IN (Select ID FROM Event WHERE MeterID IN ({param}))", ids).Select().Concat(table); } if (json.MeterAssetKeyList != null) { object[] ids = json.MeterAssetKeyList.Split(',').Cast<object>().ToArray(); string param = string.Join(",", ids.Select((id, index) => $"{{{index}}}")); table = dataContext.Connection.RetrieveData($"Select * FROM BreakerOperation WHERE TripCoilEnergized >= '{startTime}' AND TripCoilEnergized <= '{endTime}' AND EventID IN (Select ID FROM Event WHERE MeterID IN (SELECT ID FROM Meter WHERE AssetKey IN ({param})))", ids).Select().Concat(table); } if (json.LineIDList != null) { object[] ids = json.LineIDList.Split(',').Select(int.Parse).Cast<object>().ToArray(); string param = string.Join(",", ids.Select((id, index) => $"{{{index}}}")); table = dataContext.Connection.RetrieveData($"Select * FROM BreakerOperation WHERE TripCoilEnergized >= '{startTime}' AND TripCoilEnergized <= '{endTime}' AND EventID IN (Select ID FROM Event WHERE LineID IN ({param}))", ids).Select().Concat(table); } if (json.LineAssetKeyList != null) { object[] ids = json.LineAssetKeyList.Split(',').Cast<object>().ToArray(); string param = string.Join(",", ids.Select((id, index) => $"{{{index}}}")); table = dataContext.Connection.RetrieveData($"Select * FROM BreakerOperation WHERE TripCoilEnergized >= '{startTime}' AND TripCoilEnergized <= '{endTime}' AND EventID IN (Select ID FROM Event WHERE LineID IN (SELECT ID FROM Line WHERE AssetKey IN ({param})))", ids).Select().Concat(table); } if (json.EventIDList != null) { object[] ids = json.EventIDList.Split(',').Select(int.Parse).Cast<object>().ToArray(); string param = string.Join(",", ids.Select((id, index) => $"{{{index}}}")); table = dataContext.Connection.RetrieveData($"Select * FROM BreakerOperation WHERE TripCoilEnergized >= '{startTime}' AND TripCoilEnergized <= '{endTime}' AND EventID IN ({param})", ids).Select().Concat(table); } return table.Select(row => dataContext.Table<BreakerOperation>().LoadRecord(row)).DistinctBy(evt => evt.ID).ToList(); } catch (Exception) { return null; } } }
public IEnumerable <BreakerOperation> GetBreakerOperations(EventJSON json) { using (DataContext dataContext = new DataContext("systemSettings")) { DateTime startTime = (json != null ? (json.StartDate ?? DateTime.Parse("01/01/01")) : DateTime.Parse("01/01/01")); DateTime endTime = (json != null ? (json.EndDate ?? DateTime.Now) : DateTime.Now); IEnumerable <DataRow> table = Enumerable.Empty <DataRow>(); try { if (json == null || (json.EventIDList == null && json.MeterAssetKeyList == null && json.LineIDList == null && json.LineAssetKeyList == null && json.MeterIDList == null)) { table = dataContext.Connection.RetrieveData("Select * FROM BreakerOperation WHERE TripCoilEnergized >= {0} AND TripCoilEnergized <= {1}", startTime, endTime).Select(); return(table.Select(row => dataContext.Table <BreakerOperation>().LoadRecord(row)).ToList()); } if (json.MeterIDList != null) { object[] ids = json.MeterIDList.Split(',').Select(int.Parse).Cast <object>().ToArray(); string param = string.Join(",", ids.Select((id, index) => $"{{{index}}}")); table = dataContext.Connection.RetrieveData($"Select * FROM BreakerOperation WHERE TripCoilEnergized >= '{startTime}' AND TripCoilEnergized <= '{endTime}' AND EventID IN (Select ID FROM Event WHERE MeterID IN ({param}))", ids).Select().Concat(table); } if (json.MeterAssetKeyList != null) { object[] ids = json.MeterAssetKeyList.Split(',').Cast <object>().ToArray(); string param = string.Join(",", ids.Select((id, index) => $"{{{index}}}")); table = dataContext.Connection.RetrieveData($"Select * FROM BreakerOperation WHERE TripCoilEnergized >= '{startTime}' AND TripCoilEnergized <= '{endTime}' AND EventID IN (Select ID FROM Event WHERE MeterID IN (SELECT ID FROM Meter WHERE AssetKey IN ({param})))", ids).Select().Concat(table); } if (json.LineIDList != null) { object[] ids = json.LineIDList.Split(',').Select(int.Parse).Cast <object>().ToArray(); string param = string.Join(",", ids.Select((id, index) => $"{{{index}}}")); table = dataContext.Connection.RetrieveData($"Select * FROM BreakerOperation WHERE TripCoilEnergized >= '{startTime}' AND TripCoilEnergized <= '{endTime}' AND EventID IN (Select ID FROM Event WHERE LineID IN ({param}))", ids).Select().Concat(table); } if (json.LineAssetKeyList != null) { object[] ids = json.LineAssetKeyList.Split(',').Cast <object>().ToArray(); string param = string.Join(",", ids.Select((id, index) => $"{{{index}}}")); table = dataContext.Connection.RetrieveData($"Select * FROM BreakerOperation WHERE TripCoilEnergized >= '{startTime}' AND TripCoilEnergized <= '{endTime}' AND EventID IN (Select ID FROM Event WHERE LineID IN (SELECT ID FROM Line WHERE AssetKey IN ({param})))", ids).Select().Concat(table); } if (json.EventIDList != null) { object[] ids = json.EventIDList.Split(',').Select(int.Parse).Cast <object>().ToArray(); string param = string.Join(",", ids.Select((id, index) => $"{{{index}}}")); table = dataContext.Connection.RetrieveData($"Select * FROM BreakerOperation WHERE TripCoilEnergized >= '{startTime}' AND TripCoilEnergized <= '{endTime}' AND EventID IN ({param})", ids).Select().Concat(table); } return(table.Select(row => dataContext.Table <BreakerOperation>().LoadRecord(row)).DistinctBy(evt => evt.ID).ToList()); } catch (Exception) { return(null); } } }
private static EventJSON getJsonEvent(Event eventToConvert) { EventJSON json; json = new EventJSON(); json.Id = eventToConvert.Id.ToString(); if (eventToConvert.Color != null) { json.ColorName = getNamedColorFromColor(eventToConvert.Color.Value).Name; } json.Description = eventToConvert.Description; json.StartString = eventToConvert.StartTime.ToString("d"); if (eventToConvert.EndTime != null) { json.EndString = eventToConvert.EndTime.Value.ToString("d"); } if (eventToConvert.Category != null) { json.EventCategoryId = eventToConvert.Category.Id.ToString(); } json.Name = eventToConvert.Name; return(json); }