private async void Button_Start(object sender, EventArgs e) { var result = await DisplayAlert("Викторина", "Вы уверены, что хотите начать?", "Да", "Нет"); if (result) { var questions = viewModel.GetQuestionsOnCategory(quiz.Category); QuizStart quizStartPage = new QuizStart(questions, quiz); quizStartPage.BindingContext = quiz; await Navigation.PushAsync(quizStartPage); } }
//have the id be optional so the event can be logged even in there is unknown information public static void QuizStart(string quizid = "") { if (sessionMetricList == null) { sessionMetricList = new List <MetricEvent>(); } if (answeredQuestions == null) { answeredQuestions = new List <AnswerQuizQuestion>(); } else { //clear any questions from a previous quiz answeredQuestions.Clear(); } MetricEvent newEvent = new MetricEvent(); //newEvent.SetEventInfo("FFFFFFFFF", user, "12ss", null); newEvent.SetEventInfo(uuid, user, sessionID, null); QuizStart metricData = new QuizStart(quizid); newEvent.Timestamp(DateTime.UtcNow); newEvent.Data(metricData); //Keep a tally of the events in a session in the case of time race conditions to still know which event occured first newEvent.SessionIndex(sessionMetricList.Count); //add it to the list of events this session sessionMetricList.Add(newEvent); //set the last action to have the duration easily accesible for the event end lastActionTime = newEvent.Timestamp(); //TODO: attempt to upload to database //if fail then save APIManager.SubmitMetrics((new MetricEvent[1] { newEvent }), (res) => HandleResponse(res)); sessioncount++; }
//void Start() //{ // //Save(); // //Load(); // if (Input.GetKeyDown(KeyCode.Y)) { Save(); } //} public static void Save() { Debug.Log("Delete me: Placeholder test save"); // Check for events that have not been uploaded and add them to a new list to save locally List <MetricEvent> eventsToSave = new List <MetricEvent>(); MetricEvent newEvent = new MetricEvent(); newEvent.SetEventInfo("0", "a", "0001", "0a"); QuizStart metricData = new QuizStart("quiz0"); newEvent.Timestamp(DateTime.Now); newEvent.Data(metricData); eventsToSave.Add(newEvent); Save(eventsToSave); // Save the data to disk. //string filepath = Application.persistentDataPath + "/save.dat"; //using (FileStream file = File.Create(filepath)) //{ // new BinaryFormatter().Serialize(file, eventsToSave); //} }