public static async Task<RunSet> FromId (Machine local_machine, long local_runsetid, Config local_config, Commit local_mainCommit, List<Commit> local_secondaryCommits, string local_buildURL, string local_logURL) { using (var client = new HttpClient ()) { JObject db_result = await HttpApi.GetRunset (local_runsetid); if (db_result == null) { return null; } var runSet = new RunSet { Id = local_runsetid, StartDateTime = db_result ["StartedAt"].ToObject<DateTime> (), FinishDateTime = db_result ["FinishedAt"].ToObject<DateTime> (), BuildURL = db_result ["BuildURL"].ToObject<string> (), Machine = local_machine, LogURL = local_logURL, Config = local_config, Commit = local_mainCommit, TimedOutBenchmarks = db_result ["TimedOutBenchmarks"].ToObject<List<string>> (), CrashedBenchmarks = db_result ["CrashedBenchmarks"].ToObject<List<string>> () }; var db_mainProductCommit = db_result ["MainProduct"] ["Commit"].ToObject<string> (); if (local_mainCommit.Hash != db_mainProductCommit) throw new Exception (String.Format ("Commit ({0}) does not match the one in the database ({1}).", local_mainCommit.Hash, db_mainProductCommit)); var db_secondaryCommits = new List<Commit> (); foreach (var sc in db_result ["SecondaryProducts"]) { db_secondaryCommits.Add (new Commit { Hash = sc ["Commit"].ToObject<string> (), Product = new Product { Name = sc ["Name"].ToObject<string> () } }); } if (local_secondaryCommits != null) { if (local_secondaryCommits.Count != db_secondaryCommits.Count) throw new Exception ("Secondary commits don't match the database."); foreach (var sc in db_secondaryCommits) { if (!local_secondaryCommits.Any (c => c.Hash == sc.Hash && c.Product.Name == sc.Product.Name)) throw new Exception ("Secondary commits don't match the database."); } // local commits have more information (e.g. datetime) runSet.SecondaryCommits = local_secondaryCommits; } else { runSet.SecondaryCommits = db_secondaryCommits; } if (local_buildURL != null && local_buildURL != runSet.BuildURL) throw new Exception ("Build URL does not match the one in the database."); var db_machineName = db_result ["Machine"] ["Name"].ToObject<string> (); var db_machineArchitecture = db_result ["Machine"] ["Architecture"].ToObject<string> (); if (local_machine.Name != db_machineName || local_machine.Architecture != db_machineArchitecture) throw new Exception ("Machine does not match the one in the database. \"" + db_machineName + "\" vs. \"" + local_machine.Name + "\""); if (!local_config.EqualsApiObject (db_result ["Config"])) throw new Exception ("Config does not match the one in the database."); return runSet; } }
public static async Task <RunSet> FromId(Machine local_machine, long local_runsetid, Config local_config, Commit local_mainCommit, List <Commit> local_secondaryCommits, string local_buildURL, string local_logURL) { using (var client = new HttpClient()) { JObject db_result = await HttpApi.GetRunset(local_runsetid); if (db_result == null) { return(null); } Console.Error.WriteLine("trying to parse Start date: \"" + db_result ["StartedAt"].ToObject <DateTime> ().ToLocalTime().ToString(DATETIME_PRETTY) + "\""); var runSet = new RunSet { Id = local_runsetid, StartDateTime = db_result ["StartedAt"].ToObject <DateTime> ().ToLocalTime(), FinishDateTime = db_result ["FinishedAt"].ToObject <DateTime> ().ToLocalTime(), BuildURL = db_result ["BuildURL"].ToObject <string> (), Machine = local_machine, LogURL = local_logURL, Config = local_config, Commit = local_mainCommit, TimedOutBenchmarks = db_result ["TimedOutBenchmarks"].ToObject <List <string> > (), CrashedBenchmarks = db_result ["CrashedBenchmarks"].ToObject <List <string> > () }; var db_mainProductCommit = db_result ["MainProduct"] ["Commit"].ToObject <string> (); if (local_mainCommit.Hash != db_mainProductCommit) { throw new Exception(String.Format("Commit ({0}) does not match the one in the database ({1}).", local_mainCommit.Hash, db_mainProductCommit)); } var db_secondaryCommits = new List <Commit> (); foreach (var sc in db_result["SecondaryProducts"]) { db_secondaryCommits.Add(new Commit { Hash = sc ["Commit"].ToObject <string> (), Product = new Product { Name = sc ["Name"].ToObject <string> () } }); } if (local_secondaryCommits != null) { if (local_secondaryCommits.Count != db_secondaryCommits.Count) { throw new Exception("Secondary commits don't match the database."); } foreach (var sc in db_secondaryCommits) { if (!local_secondaryCommits.Any(c => c.Hash == sc.Hash && c.Product.Name == sc.Product.Name)) { throw new Exception("Secondary commits don't match the database."); } } // local commits have more information (e.g. datetime) runSet.SecondaryCommits = local_secondaryCommits; } else { runSet.SecondaryCommits = db_secondaryCommits; } if (local_buildURL != null && local_buildURL != runSet.BuildURL) { throw new Exception("Build URL does not match the one in the database."); } var db_machineName = db_result ["Machine"] ["Name"].ToObject <string> (); var db_machineArchitecture = db_result ["Machine"] ["Architecture"].ToObject <string> (); if (local_machine.Name != db_machineName || local_machine.Architecture != db_machineArchitecture) { throw new Exception("Machine does not match the one in the database. \"" + db_machineName + "\" vs. \"" + local_machine.Name + "\""); } if (!local_config.EqualsApiObject(db_result ["Config"])) { throw new Exception("Config does not match the one in the database."); } return(runSet); } }