Last active
August 24, 2016 15:27
-
-
Save alanstevens/be148595e865999edb35b51134ff79c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using EMCBTests.Shared.Extensions; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Linq; | |
namespace EMCBTests.Entities.Breaker | |
{ | |
public class Breaker | |
{ | |
public string AgentId { get; set; } | |
public List<BreakerReading> BreakerReadings { get; set; } | |
public static BreakerReading ParseBreakerReading(string json) | |
{ | |
var jsonData = JObject.Parse(json); | |
var breakerReading = JsonConvert.DeserializeObject<BreakerReading>(jsonData.ToString()); | |
var readings = new List<DemandResponseReading>(); | |
breakerReading.DemandResponse = new DemandResponse | |
{ | |
DemandResponseReadings = readings | |
}; | |
var readingsData = jsonData["demandResponse"].Children(); | |
foreach (var readingDatum in readingsData) | |
{ | |
var reading = ParseReading(readingDatum); | |
readings.Add(reading); | |
} | |
return breakerReading; | |
} | |
private static DemandResponseReading ParseReading(JToken readingDatum) | |
{ | |
var readingId = readingDatum.Path.Substring("demandResponse.-".Length); | |
var child = readingDatum.First; | |
return new DemandResponseReading | |
{ | |
ReadingId = readingId, | |
CompleteState = child["completeState"].ToString(), | |
Duration = child["duration"].ToString().As<long>(), | |
EventTime = child["eventTime"].ToString().As<long>(), | |
Optional = child["optional"].ToString().As<bool>(), | |
Status = child["status"].ToString() | |
}; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
namespace EMCBTests.Entities.Breaker | |
{ | |
public class UnderVoltageRelease | |
{ | |
public long TS { get; set; } | |
public bool Val { get; set; } | |
} | |
public class Configuration | |
{ | |
public UnderVoltageRelease UnderVoltageRelease { get; set; } | |
} | |
public class State | |
{ | |
public long TS { get; set; } | |
public bool Val { get; set; } | |
} | |
public class DynamicData | |
{ | |
public State State { get; set; } | |
} | |
public class CircuitNumber | |
{ | |
public long TS { get; set; } | |
public long Val { get; set; } | |
} | |
public class longerruptingCurrent | |
{ | |
public long TS { get; set; } | |
public long Val { get; set; } | |
} | |
public class LoadType | |
{ | |
public long TS { get; set; } | |
public string Val { get; set; } | |
} | |
public class NumPoles | |
{ | |
public long TS { get; set; } | |
public long Val { get; set; } | |
} | |
public class RatedCurrent | |
{ | |
public long TS { get; set; } | |
public long Val { get; set; } | |
} | |
public class RatedVoltage | |
{ | |
public long TS { get; set; } | |
public long Val { get; set; } | |
} | |
public class TotalPoles | |
{ | |
public long TS { get; set; } | |
public long Val { get; set; } | |
} | |
public class StaticData | |
{ | |
public CircuitNumber CircuitNumber { get; set; } | |
public longerruptingCurrent LongerruptingCurrent { get; set; } | |
public LoadType LoadType { get; set; } | |
public NumPoles NumPoles { get; set; } | |
public RatedCurrent RatedCurrent { get; set; } | |
public RatedVoltage RatedVoltage { get; set; } | |
public TotalPoles TotalPoles { get; set; } | |
} | |
public class BreakerReading | |
{ | |
public Configuration Configuration { get; set; } | |
public DynamicData DynamicData { get; set; } | |
public StaticData StaticData { get; set; } | |
public DemandResponse DemandResponse { get; set; } | |
} | |
public class DemandResponse | |
{ | |
public List<DemandResponseReading> DemandResponseReadings { get; set; } | |
} | |
public class DemandResponseReading | |
{ | |
public string ReadingId { get; set; } | |
public string CompleteState { get; set; } | |
public long Duration { get; set; } | |
public long EventTime { get; set; } | |
public bool Optional { get; set; } | |
public string Status { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment