18 using Newtonsoft.Json;
21 using Newtonsoft.Json.Linq;
24 using System.Collections.Generic;
48 public override void WriteJson(JsonWriter writer,
object value, JsonSerializer serializer)
50 throw new NotImplementedException(
"The LiveAlgorithmResultsJsonConverter does not implement a WriteJson method.");
73 public override object ReadJson(JsonReader reader, Type objectType,
object existingValue, JsonSerializer serializer)
75 var jObject = JObject.Load(reader);
81 Message = jObject[
"message"].Value<
string>(),
82 Status = jObject[
"status"].Value<string>(),
83 DeployId = jObject[
"deployId"].Value<
string>(),
84 CloneId = jObject[
"cloneId"].Value<int>(),
85 Launched = jObject[
"launched"].Value<DateTime>(),
86 Stopped = jObject[
"stopped"].Value<DateTime?>(),
87 Brokerage = jObject[
"brokerage"].Value<
string>(),
89 ProjectName = jObject[
"projectName"].Value<
string>(),
90 Datacenter = jObject[
"datacenter"].Value<string>(),
91 Public = jObject[
"public"].Value<
bool>(),
92 Success = jObject[
"success"].Value<bool>()
95 if (!liveAlgoResults.Success)
98 liveAlgoResults.Errors = jObject.Last.Children().Select(error => error.ToString()).ToList();
99 return liveAlgoResults;
103 var chartDictionary =
new Dictionary<string, Chart>();
104 var charts = jObject[
"charts"] ?? jObject[
"Charts"];
107 var stringCharts = jObject[
"charts"]?.ToString() ?? jObject[
"Charts"].ToString();
108 if(!
string.IsNullOrEmpty(stringCharts))
110 chartDictionary = JsonConvert.DeserializeObject<Dictionary<string, Chart>>(stringCharts);
115 var projectFiles =
new List<ProjectFile>();
116 var files = jObject[
"files"] ?? jObject[
"Files"];
119 var stringFiles = jObject[
"files"]?.ToString() ?? jObject[
"Files"].ToString();
120 if (!
string.IsNullOrEmpty(stringFiles))
122 projectFiles = JsonConvert.DeserializeObject<List<ProjectFile>>(stringFiles);
126 liveAlgoResults.Charts = chartDictionary;
127 liveAlgoResults.Files = projectFiles;
129 return liveAlgoResults;