//public Task<BlindTest> GetNewBlindTest(string test_name, out string error) //{ // error = ""; // int id = _tests.Count > 0 ? (_tests.Keys.Max() + 1) : 1; // BlindTest test = new BlindTest { Id = id }; // test.Name = test_name ?? test.Name; // _tests.Add(id, test); // return Task.FromResult(test); //} public async Task <ResultHolder <int> > GetNewBlindTest(string test_name) { int id = _tests.Count > 0 ? (_tests.Keys.Max() + 1) : 1; BlindTest test = new BlindTest { Id = id }; test.Name = test_name ?? test.Name; _tests.Add(id, test); //IntResult r = new IntResult { Code = id, Error = "" }; ResultHolder <int> r = new ResultHolder <int> { Result = id, Error = "" }; return(r); }
public async Task GetBlindTest(string id) { BlindTest bt = null; string error = ""; // Regelen blir at hvis vi mottar noe annet enn et nummer så startes en ny blindtest if (!int.TryParse(id, out int blind_test_id)) { // Start en ny blindtest ResultHolder <int> ret = await PollController.Instance.GetNewBlindTest(id); if (string.IsNullOrEmpty(ret.Error)) { ResultHolder <BlindTest> r = await PollController.Instance.GetBlindTest(ret.Result); if (string.IsNullOrEmpty(r.Error)) { bt = r.Result; } else { error = r.Error; } } else { error = ret.Error; } } else { // Prøv å finn en eksisterende blindtest ResultHolder <BlindTest> r = await PollController.Instance.GetBlindTest(blind_test_id); if (string.IsNullOrEmpty(r.Error)) { bt = r.Result; } else { error = r.Error; } } await Clients.Caller.pollGetBlindTestResponse(new { Result = string.IsNullOrEmpty(error) ? "Success" : "Failure", Error = error, Instance = bt }); }