public static List<GSRDataReading> LoadFromFile(string json) { //Timestamp string[] commaSeparated = json.Split(new string[] { ",", "{" }, StringSplitOptions.RemoveEmptyEntries); string startTimeString = commaSeparated.First(s => s.Contains("startTime")); startTimeString = startTimeString.Split(new string[] { "\"" }, StringSplitOptions.RemoveEmptyEntries)[3]; DateTime loadedStartTime; DateTime.TryParse(startTimeString, out loadedStartTime); List<GSRDataReading> list = new List<GSRDataReading>(); string[] data = json.Split(new string[] { "[", "]" }, StringSplitOptions.RemoveEmptyEntries); string[] readings = data[1].Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (string r in readings) { GSRDataReading gsr = new GSRDataReading(false); gsr.loadedStartTime = loadedStartTime; string[] stats = r.Split(new string[] { ",", "{", "}" }, StringSplitOptions.RemoveEmptyEntries); string s0 = stats[0].Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries)[1]; gsr.resistance = int.Parse(s0); string s1 = stats[1].Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries)[1]; gsr.timestamp = long.Parse(s1); list.Add(gsr); } return list; }
public static List <GSRDataReading> LoadFromFile(string json) { //Timestamp string[] commaSeparated = json.Split(new string[] { ",", "{" }, StringSplitOptions.RemoveEmptyEntries); string startTimeString = commaSeparated.First(s => s.Contains("startTime")); startTimeString = startTimeString.Split(new string[] { "\"" }, StringSplitOptions.RemoveEmptyEntries)[3]; DateTime loadedStartTime; DateTime.TryParse(startTimeString, out loadedStartTime); List <GSRDataReading> list = new List <GSRDataReading>(); string[] data = json.Split(new string[] { "[", "]" }, StringSplitOptions.RemoveEmptyEntries); string[] readings = data[1].Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (string r in readings) { GSRDataReading gsr = new GSRDataReading(false); gsr.loadedStartTime = loadedStartTime; string[] stats = r.Split(new string[] { ",", "{", "}" }, StringSplitOptions.RemoveEmptyEntries); string s0 = stats[0].Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries)[1]; gsr.resistance = int.Parse(s0); string s1 = stats[1].Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries)[1]; gsr.timestamp = long.Parse(s1); list.Add(gsr); } return(list); }
public void AddGSRData(GSRDataReading data) { data.Write(); gsrData.Add(data); }