public static void HandleResponse(APIManager.MetricsResponse res) { if (res == null || res.success == false) { isSending = false; if (res != null) { SaveLoadSessionData.Save(res.metrics); } else { SaveLoadSessionData.Save(sessionMetricList[sessionMetricList.Count - 1]); } } else { isSending = true; //if there is a ./save.dat file there is metric data that was not sent to the server if (SaveLoadSessionData.HasLocalSaveData()) { APIManager.SubmitMetrics(SaveLoadSessionData.Load().ToArray(), (loadres) => HandleResponse(loadres)); } } }
private static List <AnswerQuizQuestion> answeredQuestions; //keep track of the questions to have a full list to append to the quiz end public static void StartSession() { //Check if a user is logged in if (User.current != null) { user = User.current._id; team = User.current.selectedMembership._id; //check for saved data that was not sent to the server if (SaveLoadSessionData.HasLocalSaveData()) { APIManager.SubmitMetrics(SaveLoadSessionData.Load().ToArray(), (res) => HandleResponse(res)); } } //break out if the session had already be intialized //covering the scenario where a user is active and logs in while the session is in progress if (sessionInstialized == true) { return; } sessionInstialized = true; sessionStart = DateTime.UtcNow; //create a unique identifier for the session for parsing multiple sessions on the same day GenerateSessionID(); //systeminfo gives a unique id for the device is use uuid = SystemInfo.deviceUniqueIdentifier; //instialize the empty lists if (sessionMetricList == null) { sessionMetricList = new List <MetricEvent>(); } if (answeredQuestions == null) { answeredQuestions = new List <AnswerQuizQuestion>(); } }