Skip to content

Instantly share code, notes, and snippets.

@alanstevens
Last active August 24, 2016 15:27
Show Gist options
  • Save alanstevens/be148595e865999edb35b51134ff79c4 to your computer and use it in GitHub Desktop.
Save alanstevens/be148595e865999edb35b51134ff79c4 to your computer and use it in GitHub Desktop.
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()
};
}
}
}
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