/// <summary> /// Comes back to main test editor page /// </summary> private void ChangePage() { // If something is being edited show the warning... if (EditingCriteriaMode) { // Show message box to ask the user if he wants to save changes or not var vm = new DecisionDialogViewModel { Title = LocalizationResource.CriteriaEdited, Message = LocalizationResource.CriteriaEditedPageChangeDiscardChanges + "\n " + LocalizationResource.ContinueQuestion, AcceptText = LocalizationResource.Yes, CancelText = LocalizationResource.No }; DI.UI.ShowMessage(vm); // If user has declined, don't do anything if (!vm.UserResponse) { return; } } // Change the page DI.Application.GoToPage(ApplicationPage.TestEditorInitial); }
public DecisionDialog(string title, string description) { DataContext = new DecisionDialogViewModel() { Title = title, Description = description }; InitializeComponent(); }
/// <summary> /// Deletes selected criteria /// </summary> private void DeleteCommand() { // Show message box to ask the user if he wants to delete criteria var vm = new DecisionDialogViewModel { Title = LocalizationResource.CriteriaDeletion, Message = LocalizationResource.ChoosenCriteriaWillBeDeleted + "\n" + LocalizationResource.ContinueQuestion, AcceptText = LocalizationResource.Yes, CancelText = LocalizationResource.No }; DI.UI.ShowMessage(vm); // If user has declined, don't do anything if (!vm.UserResponse) { return; } try { // Try to delete this criteria by old name because the user may have changed it meanwhile CriteriaFileWriter.DeleteXmlFileByName(EditingCriteriaOldName); } catch (Exception ex) { // If an error occured, show info to the user DI.UI.ShowMessage(new MessageBoxDialogViewModel { Title = LocalizationResource.Yes, Message = LocalizationResource.UnableToDeleteCriteria + "\n" + LocalizationResource.ErrorContentSemicolon + ex.Message, OkText = LocalizationResource.Ok }); DI.Logger.Log("Unable to delete criteria file, error message: " + ex.Message); // Don't do anything after the error is shown return; } // Reload items CriteriaListViewModel.Instance.LoadItems(); // Load brand new criteria LoadCriteria(new GradingPercentage()); // Hide all errors and flags EditingCriteriaMode = false; InvalidDataError = false; CriteriaChanged = false; // Mark all criteria unchecked CriteriaListViewModel.Instance.UncheckAll(); }
/// <summary> /// Selects and loads the criteria from the list so user can edit it /// </summary> /// <param name="param">Name of the criteria</param> private void EditCriteria(object param) { // Cast parameter to string var criteriaName = param.ToString(); // If we are in editing mode if (EditingCriteriaMode) { // If the user clicked on the criteria that is now edited, do nothing if (criteriaName == EditingCriteriaOldName) { return; } // If there are some unsaved changes if (CriteriaChanged) { // Show the message box with the info that there are some unsaved changes var vm = new DecisionDialogViewModel { Title = LocalizationResource.UnsavedChanges, Message = LocalizationResource.SomeChangesWereUnsaved + "\n" + LocalizationResource.ContinueQuestion, AcceptText = LocalizationResource.Yes, CancelText = LocalizationResource.No }; DI.UI.ShowMessage(vm); // If user has declined, don't do anything if (!vm.UserResponse) { return; } } } // Mark all criteria unchecked CriteriaListViewModel.Instance.UncheckAll(); // Hide any errors InvalidDataError = false; // Disable editing mode for items loading time, because it will fire the // property changed event and the CriteriaChanged will be set, which we don't want for now EditingCriteriaMode = false; // Load the new data LoadCriteriaByName(criteriaName, true); // Enter editing mode again EditingCriteriaMode = true; }
/// <summary> /// Asks the user if they want to save changes to the question or not /// </summary> /// <returns>True if they want to; otherwise, false</returns> private bool AskToSave() { var vm = new DecisionDialogViewModel() { Message = "Czy chcesz zapisać zmiany w obecnym pytaniu?", AcceptText = "Tak", CancelText = "Nie", Title = "Edytor testów", }; IoCServer.UI.ShowMessage(vm); return(vm.UserResponse); }
/// <summary> /// Deletes currently selected results /// </summary> private void DeleteResult() { var selectedItem = ListViewModel.SelectedItem(); if (selectedItem == null) { return; } var vm = new DecisionDialogViewModel() { Title = "Usuwanie rezultatu", Message = "Czy chcesz usunąć ten rezultat?", AcceptText = LocalizationResource.Yes, CancelText = LocalizationResource.No, }; DI.UI.ShowMessage(vm); if (vm.UserResponse == false) { return; } try { // Try to delete the file ResultFileWriter.DeleteFile(selectedItem); } catch (Exception ex) { // If an error occured, show info to the user DI.UI.ShowMessage(new MessageBoxDialogViewModel { Title = LocalizationResource.DeletionError, Message = "Nie udało się usunąć tego rezultatu." + "\n" + LocalizationResource.ErrorContentSemicolon + ex.Message, OkText = LocalizationResource.Ok }); DI.Logger.Log("Unable to delete result from local folder, error message: " + ex.Message); } // Reload items ListViewModel.LoadItems(); SetDefaults(); OnPropertyChanged(nameof(ItemsLoadedCount)); }
/// <summary> /// Deletes test from the list /// </summary> private void DeleteTest() { // Check if user has selected any test if (!TestListViewModel.Instance.IsAnySelected) { return; } // Confirm var vm = new DecisionDialogViewModel { Title = "Usuwanie testu", Message = "Czy jesteś pewny, że chcesz usunąć ten test?", AcceptText = LocalizationResource.Yes, CancelText = LocalizationResource.No }; DI.UI.ShowMessage(vm); // No if (!vm.UserResponse) { return; } try { // Finally try to delete selected test TestFileWriter.DeleteFile(TestListViewModel.Instance.SelectedItem); } catch (Exception ex) { // If an error occured, show info to the user DI.UI.ShowMessage(new MessageBoxDialogViewModel { Title = LocalizationResource.DeletionError, Message = "Nie udało się usunąć tego testu." + "\n" + LocalizationResource.ErrorContentSemicolon + ex.Message, OkText = LocalizationResource.Ok }); DI.Logger.Log("Unable to delete test from local folder, error message: " + ex.Message); } // Update test list TestListViewModel.Instance.LoadItems(); }
/// <summary> /// Exits from the editor /// </summary> public void Exit() { if (AnyUnsavedChanges) { var vm = new DecisionDialogViewModel() { Message = "There are some unsaved changes. Do you want to exit without saving?", AcceptText = "Yes", CancelText = "No", Title = "Exit", }; DI.UI.ShowMessage(vm); if (vm.UserResponse) { DI.Application.GoToPage(ApplicationPage.TestEditorInitial); } } }
/// <summary> /// Stops the test (test disappears completely, like it didn't even happened) /// </summary> private void StopTest() { // Ask the user if he wants to stop the test var vm = new DecisionDialogViewModel() { Title = "Przerywanie testu", Message = "Czy na pewno chcesz przerwać test?", AcceptText = "Tak", CancelText = "Nie", }; DI.UI.ShowMessage(vm); // If his will match if (vm.UserResponse) { // Stop the test StopTestForcefully(); } }
/// <summary> /// Stops the server /// </summary> private void StopServer() { // Check if any test is already in progress if (mTestHost.IsTestInProgress) { // Ask the user if he wants to stop the test var vm = new DecisionDialogViewModel() { Title = "Test w trakcie!", Message = "Test jest w trakcie. Czy chcesz go przerwać?", AcceptText = "Tak", CancelText = "Nie", }; DI.UI.ShowMessage(vm); // If he agreed if (vm.UserResponse) { // Stop the test StopTestForcefully(); } else { return; } UpdateView(); } // Stop the server mServerNetwork.ShutDown(); UpdateView(); // Go to the initial page DI.Application.GoToBeginTestPage(ApplicationPage.BeginTestInitial); }
/// <summary> /// Displays a result box to the user and catch the result /// </summary> /// <param name="viewModel">The view model</param> /// <returns></returns> public Task ShowMessage(DecisionDialogViewModel viewModel) { // Prepare a dummy task to return Task task = null; // If caller isn't on UIThread already, get to this thread first if (!Application.Current.Dispatcher.CheckAccess()) { Application.Current.Dispatcher.BeginInvoke((Action)(() => { // Set the task inside UIThread task = new DecisionDialogBox().ShowDialog(viewModel); })); } // If caller is on UIThread, just show the dialog else { task = new DecisionDialogBox().ShowDialog(viewModel); } // Finally return this task return(task); }
/// <summary> /// Fired when any data is resived from a client /// </summary> /// <param name="client">The sender client</param> /// <param name="dataPackage">The data received from the client</param> public void OnDataReceived(ClientModel client, DataPackage dataPackage) { // If the data is from client we dont care about don't do anything if (!ClientsInTest.Contains(client)) { return; } switch (dataPackage.PackageType) { case PackageType.ReportStatus: // Status package, contains only number of questions the client has done so far var content = dataPackage.Content as StatusPackage; client.CurrentQuestion = content.CurrentQuestion; break; case PackageType.ReadyForTest: client.CanStartTest = true; break; case PackageType.ResultForm: // Get the content var result = dataPackage.Content as ResultFormPackage; // Save them in client model client.Answers = result.Answers; client.PointsScored = result.PointsScored; client.Mark = result.Mark; client.QuestionsOrder = result.QuestionsOrder; client.HasResultsBeenReceived = true; if (HasEveryClientSentResults()) { SaveResults(); FinishTest(); } else if (OnlyClientsWithConnectionProblemLeft()) { var vm = new DecisionDialogViewModel() { Title = "Finishing test", Message = "Do you want to end the test before time as only users left are these with connection problem?", AcceptText = "Ok", CancelText = "No, wait for them", }; IoCServer.UI.ShowMessage(vm); // Stop before time if (vm.UserResponse) { SaveResults(); FinishTest(); } } break; } }
/// <summary> /// Checks if there is a new version of that application /// </summary> private async Task <bool> CheckUpdatesAsync() { try { // Set webservice's url and parameters we want to send var url = "http://minorsonek.pl/testinator/data/index.php"; var parameters = $"version={ IoCServer.Application.Version.ToString() }&type=Server"; // Catch the result var result = string.Empty; // Send request to webservice using (var wc = new WebClient()) { wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; result = wc.UploadString(url, parameters); } // Return the statement based on result... switch (result) { case "New update": { // There is new update, but not important one // Ask the user if he wants to update var vm = new DecisionDialogViewModel { Title = LocalizationResource.NewUpdate, Message = LocalizationResource.NewVersionCanDownload, AcceptText = LocalizationResource.Sure, CancelText = LocalizationResource.SkipUpdate }; await IoCServer.UI.ShowMessage(vm); // Depending on the answer... return(vm.UserResponse); } case "New update IMP": { // An important update, inform the user and update await IoCServer.UI.ShowMessage(new MessageBoxDialogViewModel { Title = LocalizationResource.NewImportantUpdate, Message = LocalizationResource.NewImportantUpdateInfo, OkText = LocalizationResource.Ok }); return(true); } default: // No updates return(false); } } catch { // Cannot connect to the web, no updates return(false); } }