private ProblemFile downloadFile(string url) { Uri uri = new Uri(Application.Get().Configuration.BaseApiAddress, url); logger.Debug("Statring download file from {0}", uri); ProblemFile file = new ProblemFile(); for (int i = 0; i < 2; i++) { try { file.Content = client.GetAsync(uri).Result.Content.ReadAsByteArrayAsync().Result; break; } catch (Exception ex) { file.Content = null; logger.Error(ex, "Download file failed."); } } if (file.Content is null) { return(null); } return(file); }
private void AddToFileList(ProblemFile problemFile) { if (!Dispatcher.CheckAccess()) { Dispatcher.Invoke(() => AddToFileList(problemFile)); return; } Wizard.FileList.Add(problemFile); }
public static void Main(string[] args) { EAConfig config; try { config = EAConfig.FromArguments(args); } catch (System.FormatException) { Console.WriteLine(String.Join(" ", args)); return; } CmnRandom.InitRandom(config.Seed); var problem = ProblemFile.Parse(config.ProblemFile); new StockCutterRunner().RunAll(config, problem.Item1, problem.Item2); }
public void AddProblem(ProblemFile p) { Problems.Add(p); ErrorsFound += 1; }
public Problem DownloadProblem(ulong problemId) { string endpoint = buildEndpoint("problems", problemId); string jsonProblem = client.GetStringAsync(endpoint).Result; logger.Debug("Download problem response length: {0}", jsonProblem.Length); JToken parsedProblem = JToken.Parse(jsonProblem); Test[] tests = new Test[parsedProblem["tests"].Count()]; for (int i = 0; i < parsedProblem["tests"].Count(); i++) { Test t = new Test(); t.Id = (UInt64)parsedProblem["tests"][i]["id"]; t.Num = (string)parsedProblem["tests"][i]["num"]; t.Input = downloadFile( (string)parsedProblem["tests"][i]["input_url"] ); if (t.Input is null) { return(null); } else { Application.Get().FileProvider.SaveFile(t.Input); } if (!(parsedProblem["tests"][i]["answer_url"] is null)) { t.Answer = downloadFile( (string)parsedProblem["tests"][i]["answer_url"] ); if (t.Answer is null) { return(null); } else { Application.Get().FileProvider.SaveFile(t.Answer); } } tests[i] = t; } ProblemFile checker = downloadFile((string)parsedProblem["checker_source_url"]); if (checker is null) { return(null); } return(new Problem( id: (ulong)parsedProblem["id"], tests: tests, checker: checker, checkerCompilerId: (byte)parsedProblem["checker_compiler_id"], lastUpdate: (DateTime)parsedProblem["updated_at"] )); }