/// <summary> /// Loads the user non-saved test file. /// </summary> /// <returns>Returns no value.</returns> private async Task LoadDummyTestFileAsync(string currentFile) { await IoC.Task.Run(() => { // generate a TestFileListItems temporarily. ObservableCollection <TestFileListItemViewModel> tempFileList = new ObservableCollection <TestFileListItemViewModel>() { }; if (IoC.Communication.TestFileListItems.Count > 0) { foreach (var item in IoC.Communication.TestFileListItems) { tempFileList.Add(item); } } // store file names to TestFileListItemViewModel // initialize a new test file list TestFileListItemViewModel testFile = new TestFileListItemViewModel { // since this is the first loading... IsDeletable = false, // so the user have chance to fix their mistakes and such... ShortTestFileName = Path.GetFileNameWithoutExtension(currentFile), // the file name only... TestDeleteToolTip = $"{Strings.tooltips_remove_file}", TestStepBackgroundColor = $"{Strings.color_test_enqueued}", TestToolTip = $"{Path.GetFileName(currentFile)}.{Environment.NewLine}{Strings.test_status_enqueued}", FullFileName = $"{currentFile}", }; // add new generated to tempFileList. tempFileList.Add(testFile); // add the new test list to the multi-test list. IoC.Communication.TestFileListItems = tempFileList; // always show multiple test user interface. IoC.Communication.IsMultipleTest = true; // (IoC.Communication.TestFileListItems.Count > 0) ? true : false; // fill TestDetails view with first file == 0 LoadTestFile(0); }); }
/// <summary> /// Occurs when the user selects a file name by either clicking the Open button of the OpenFileDialog /// or the Save button of the SaveFileDialog. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Dlg_FileOk(object sender, System.ComponentModel.CancelEventArgs e) { // Sender is a FileDialog var dlg = sender as FileDialog; // handles "SaveFileDialog" if (Equals(dlg.Tag, FileDialogOption.Save)) { // update TestFileName IoC.TestDetails.TestFileName = dlg.SafeFileName; // generate a new Test Steps Logger var fileOkTask = IoC.Task.Run(() => new TestStepsLogger( // file location and name as specified by the user filePath: dlg.FileName, // don't need to save time logTime: false, // test details need to be saved test: IoC.TestDetails )); // saving completed successfully. if (TaskStatus.RanToCompletion == fileOkTask.Status) { // dispose dialog box dlg = null; } // saving the file failed. else if (TaskStatus.Faulted == fileOkTask.Status) { // inform the developer about error IoC.Logger.Log(fileOkTask.Exception.GetBaseException().Message); // update the user about the error. IoC.Communication.Log = fileOkTask.Exception.GetBaseException().Message; } } // handles "OpenFileDialog" else if (Equals(dlg.Tag, FileDialogOption.Open)) { // grab all the file name(s) selected by the user. foreach (var currentFile in dlg.FileNames) { // store file names to TestFileListItemViewModel // initialize a new test file list TestFileListItemViewModel testFile = new TestFileListItemViewModel { // since this is the first loading... IsDeletable = true, // so the user have chance to fix their mistakes and such... ShortTestFileName = Path.GetFileNameWithoutExtension(currentFile), // the file name only... TestDeleteToolTip = $"{Strings.tooltips_remove_file}", TestStepBackgroundColor = $"{Strings.color_test_enqueued}", TestToolTip = $"{Path.GetFileName(currentFile)}.{Environment.NewLine}{Strings.test_status_enqueued}", FullFileName = $"{currentFile}", }; // add the new test file to the multi-test list. IoC.Communication.TestFileListItems.Add(testFile); } // always show multiple test user interface. IoC.Communication.IsMultipleTest = true; // (IoC.Communication.TestFileListItems.Count > 0) ? true : false; // clear previous test values. IoC.TestDetails.AnalogSignals.Clear(); // dispose dialog box dlg = null; // fill TestDetails view with first file == 0 LoadTestFile(0); } }
/// <summary> /// Loads multiple tests in order /// </summary> public void LoadTestFile(int testFileNumber) { if (IoC.Communication.TestFileListItems.Count > 0) { // initialize multiple test view model. TestFileListItemViewModel currentTestFile = new TestFileListItemViewModel(); // retrieve the first test currentTestFile = IoC.Communication.TestFileListItems[testFileNumber]; // convert a JSON file to a TestDetailsViewModel to show it the user. using (StreamReader file = File.OpenText(currentTestFile.FullFileName)) { // initialize a new TestDetailsViewModel TestDetailsViewModel test = new TestDetailsViewModel(); // initialize JsonSerializer JsonSerializer serializer = new JsonSerializer(); // convert the JsonSerializer to TestDetailsViewModel test = (TestDetailsViewModel)serializer.Deserialize(file, typeof(TestDetailsViewModel)); // Update values in the single instance of TestDetailsViewModel // update AnalogSignals IoC.TestDetails.AnalogSignals = test.AnalogSignals; // Select Ramping Signal property // Ramping Signal property is Magnitude. // This is also default setting for this property. IoC.TestDetails.IsMagnitude = string.Equals(test.SelectedRampingSignal, nameof(TestDetailsViewModel.RampingSignals.Magnitude)) || string.IsNullOrWhiteSpace(test.SelectedRampingSignal); // Ramping Signal property is Phase. IoC.TestDetails.IsPhase = string.Equals(test.SelectedRampingSignal, nameof(TestDetailsViewModel.RampingSignals.Phase)); // Ramping Signal property is Frequency. IoC.TestDetails.IsFrequency = string.Equals(test.SelectedRampingSignal, nameof(TestDetailsViewModel.RampingSignals.Frequency)); // Ramping Signal property is Harmonics. IoC.TestDetails.IsHarmonics = string.Equals(test.SelectedRampingSignal, nameof(TestDetailsViewModel.RampingSignals.Harmonics)); // update Harmonics Order IoC.TestDetails.HarmonicsOrder = test.HarmonicsOrder; // update Register IoC.TestDetails.Register = test.Register; // update DwellTime IoC.TestDetails.DwellTime = test.DwellTime; // update StartDelayTime IoC.TestDetails.StartDelayTime = test.StartDelayTime; // update MeasurementInterval IoC.TestDetails.MeasurementInterval = test.MeasurementInterval; // update StartMeasurementDelay IoC.TestDetails.StartMeasurementDelay = test.StartMeasurementDelay; // update SelectedRampingSignal IoC.TestDetails.SelectedRampingSignal = test.SelectedRampingSignal; // update Link Ramping Signals status // If SelectedRampingSignal == "Frequency" or If SelectedRampingSignal == "Harmonics" if (Equals(nameof(TestDetailsViewModel.RampingSignals.Frequency), test.SelectedRampingSignal) || Equals(nameof(TestDetailsViewModel.RampingSignals.Harmonics), test.SelectedRampingSignal)) { // frequencies are linked. IoC.TestDetails.IsLinked = test.IsLinked; } else { // frequencies are not linked IoC.TestDetails.IsLinked = false; } // update Hardware Configuration = Voltage IoC.TestDetails.SelectedVoltageConfiguration = test.SelectedVoltageConfiguration; // update Hardware Configuration = Current IoC.TestDetails.SelectedCurrentConfiguration = test.SelectedCurrentConfiguration; // update TestFileName IoC.TestDetails.TestFileName = test.TestFileName; // update Settings view model IoC.Settings.SelectedCurrent = test.SelectedCurrentConfiguration.WiringDiagramString; IoC.Settings.SelectedVoltage = test.SelectedVoltageConfiguration.WiringDiagramString; // if the test file is old, // add a new fileName attribute, // add some missing attributes to "SelectedVoltageConfiguration", // add some missing attributes to "SelectedCurrentConfiguration". if (string.IsNullOrWhiteSpace(IoC.TestDetails.TestFileName)) { // add saved file name IoC.TestDetails.TestFileName = Path.GetFileName(currentTestFile.FullFileName); // add new "WiringDiagramFileLocation" test.SelectedVoltageConfiguration.WiringDiagramFileLocation = "../Images/Omicron/not used voltage.png"; test.SelectedCurrentConfiguration.WiringDiagramFileLocation = "../Images/Omicron/not used current.png"; // add new SelectedCurrent and SelectedVoltage } // update Settings view model IoC.Settings.CurrentDiagramLocation = test.SelectedCurrentConfiguration.WiringDiagramFileLocation; IoC.Settings.VoltageDiagramLocation = test.SelectedVoltageConfiguration.WiringDiagramFileLocation; // change CancelForegroundColor to Red IoC.Commands.CancelForegroundColor = "ff0000"; // set Command buttons IoC.Commands.StartTestAvailable = true; IoC.Commands.NewTestAvailable = false; IoC.Commands.Cancellation = true; IoC.Commands.ConfigurationAvailable = true; IoC.Commands.IsConfigurationAvailable = false; // Show TestDetails page IoC.Application.GoToPage(ApplicationPage.TestDetails, IoC.TestDetails); test = null; serializer = null; } // dispose dialog box Dlg = null; // dispose temp multiple test view model. currentTestFile = null; } }