public async Task DownloadTestData() { var packet = new { Action = "GetTestInfo" }; var str = (JsonConvert.SerializeObject(packet)); await netManager.WriteLine(str); var response = await netManager.ReadLine(); var jsonResponse = JObject.Parse(response); this.currentTest = JsonConvert.DeserializeObject <Test>(jsonResponse["Test"].ToString()); if (netManager.CurrentServer.ReconnectFlag) { TestState.State = MapDefaultTestState(CurrentTest.State); } else { TestState = new UserTestState { RemainingTime = currentTest.Time, State = MapDefaultTestState(CurrentTest.State) }; } }
/// <summary> /// Задает коллекцию вопросов. /// </summary> /// <param name="id">Идентификатор пользователя.</param> /// <param name="user">Имя пользователя.</param> /// <param name="command">Команда с типом вопросов.</param> private void SetQuestions(int id, string user, string command) { _subStates[id] = new UserTestState { User = user, Results = new List <bool>(), SubState = StateChoice }; switch (command) { case ConclusiveRoleMember: { _subStates[id].TasksInfos = _tasksStorage.GetTasksForConclusiveMembers(QuestionsNumbers) .Select(c => _tasksProcessing.Shake(c)).ToList(); break; } case ConsultativeRoleMember: { _subStates[id].TasksInfos = _tasksStorage.GetTasksForConsultativeMembers(QuestionsNumbers) .Select(c => _tasksProcessing.Shake(c)).ToList(); break; } case Observer: { _subStates[id].TasksInfos = _tasksStorage.GetTasksForObservers(QuestionsNumbers) .Select(c => _tasksProcessing.Shake(c)).ToList(); break; } } }
private string ReceivedServerMessage(Server s, JObject message) { if (message["Action"].ToString() == "UpdateTest") { var sentTest = (Test)message["Test"].ToObject(typeof(Test)); this.currentTest.State = sentTest.State; switch (currentTest.State) { case Test.TestState.OnHold: this.TestState.State = UserState.OnHold; break; case Test.TestState.Started: this.TestState.State = UserState.Testing; break; } SendStateUpdate(); ReloadUI?.Invoke(); return(null); } if (message["Action"].ToString() == "AddTime") { var time = (TimeSpan)message["TimeSpan"]; this.TestState.RemainingTime += time; SendStateUpdate(); ReloadUI?.Invoke(); return(null); } if (message["Action"].ToString() == "Sync") { this.TestState = message["UserState"].ToObject <UserTestState>(); ReloadUI?.Invoke(); } if (message["Action"].ToString() == "Pause") { this.TestState.State = UserTestState.UserState.OnHold; ReloadUI?.Invoke(); } if (message["Action"].ToString() == "Resume") { this.TestState.State = UserTestState.UserState.Testing; ReloadUI?.Invoke(); } if (message["Action"].ToString() == "Handover") { try { this.Handover().Wait(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Handover Failed"); } } return(null); }