public void PathUpdatedOnSaveExperiment() { IExperiment experiment = ExperimentManager.New(); Assert.IsNotNull(experiment); Assert.AreEqual(2, experiment.VertexCount); Assert.IsTrue(string.IsNullOrEmpty(experiment.ExperimentInfo.FilePath)); string filename = System.IO.Path.Combine(AppContext.BaseTestDirectory, "testSave.gml"); try { bool success = ExperimentManager.Save(experiment, filename); Assert.IsTrue(success); Assert.IsTrue(File.Exists(filename)); //did experiment info filepath got update on save Assert.AreEqual(experiment.ExperimentInfo.FilePath, filename); } finally { if (File.Exists(filename)) { //cleanup File.Delete(filename); } } }
/// <summary> /// Extracts all assemblies containing the components and types used in the current experiment and passes /// them to the Package Builder. /// </summary> /// <param name="param">The Application View Model Wrapper.</param> private void PackExperimentFunc(object param) { bool isExperimentSaved = !this.CurrentView.IsModified; if (isExperimentSaved == false) { MessageBoxResult result = MessageBox.Show("To create a package, the experiment needs to be saved first.\nWould you like to proceed?", "Save modified experiment", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { try { isExperimentSaved = ExperimentManager.Save(this.CurrentView.GetExperiment(), this.CurrentView.ExperimentInfo.FilePath); } catch (Exception e) { isExperimentSaved = false; MessageBox.Show("Package building process interrupted. The following error ocurred:\n" + e.Message, "Error while saving experiment", MessageBoxButton.OK, MessageBoxImage.Error); } } } if (isExperimentSaved && param is ApplicationViewModelWrapper) { ApplicationViewModelWrapper AppVMWrapper = (ApplicationViewModelWrapper)param; Experiment originalExperiment = (Experiment)this.TopLevel; TraceLab.UI.WPF.Views.PackageBuilder.PackageBuilderMainWindow pkgBuilderWindow = new TraceLab.UI.WPF.Views.PackageBuilder.PackageBuilderMainWindow(originalExperiment, AppVMWrapper.WorkspaceViewModel.SupportedTypes); pkgBuilderWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen; pkgBuilderWindow.ShowDialog(); } }
private void Activated(object sender, EventArgs eargs) { Experiment experiment = ExperimentManager.New(); bool success = FileDialogs.NewExperimantDialog(m_applicationContext.MainWindow.WindowShell, ref experiment); if (success) { ApplicationViewModel newApplicationViewModel = ApplicationViewModel.CreateNewApplicationViewModel(m_applicationContext.Application, experiment); RecentExperimentsHelper.UpdateRecentExperimentList(TraceLab.Core.Settings.Settings.RecentExperimentsPath, experiment.ExperimentInfo.FilePath); m_applicationContext.OpenInWindow(newApplicationViewModel); String file = experiment.ExperimentInfo.FilePath; try { ExperimentManager.Save(experiment, file); } catch (System.IO.IOException e) { NLog.LogManager.GetCurrentClassLogger().Error(String.Format("Failed to Save File {0}. {1}", file, e.Message), e); FileDialogs.ShowSaveErrorDialog(m_applicationContext.MainWindow.WindowShell, "Failed to Save File", file); } catch (UnauthorizedAccessException e) { NLog.LogManager.GetCurrentClassLogger().Error(String.Format("Failed to Save File {0}. {1}", file, e.Message), e); FileDialogs.ShowSaveErrorDialog(m_applicationContext.MainWindow.WindowShell, "Failed to Save File", file); } catch (Exception e) { NLog.LogManager.GetCurrentClassLogger().ErrorException(String.Format("Failed to Save File {0}. {1}", file, e.Message), e); FileDialogs.ShowSaveErrorDialog(m_applicationContext.MainWindow.WindowShell, "Failed to Save File", file); } } }
public void SaveExperimentTest() { IExperiment experiment = ExperimentManager.New(); Assert.IsNotNull(experiment); Assert.AreEqual(2, experiment.VertexCount); Assert.IsTrue(string.IsNullOrEmpty(experiment.ExperimentInfo.FilePath)); string filename = System.IO.Path.Combine(AppContext.BaseTestDirectory, "testSave.gml"); try { bool success = ExperimentManager.Save(experiment, filename); Assert.IsTrue(success); Assert.IsTrue(File.Exists(filename)); IExperiment loadedExperiment = ExperimentManager.Load(filename, AppContext.Components); Assert.AreEqual(experiment.ExperimentInfo, loadedExperiment.ExperimentInfo); } finally { if (File.Exists(filename)) { //cleanup File.Delete(filename); } } }
public void SaveOverReadOnlyFile() { IExperiment experiment = ExperimentManager.New(); experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml"; // set it to read only System.IO.FileInfo finfo = new System.IO.FileInfo(ExperimentFile); finfo.IsReadOnly = true; // attempt to save expecting an exception regarding it being read only ExperimentManager.Save(experiment, ExperimentFile); }
/// <summary> /// When activated saves current experiment from associated application view model. /// </summary> /// <param name='sender'> /// Sender. /// </param> /// <param name='args'> /// Arguments. /// </param> private void Activated(object sender, EventArgs args) { //save the experiment of this application view model Experiment experiment = m_applicationContext.Application.Experiment; if (experiment != null) { string file = null; if (String.IsNullOrEmpty(experiment.ExperimentInfo.FilePath)) { // if file path is not set show save as dialog file = FileDialogs.ShowSaveAsDialog(m_applicationContext.MainWindow.WindowShell); } else { file = experiment.ExperimentInfo.FilePath; } if (file != null) { try { string extension = file.Substring(file.Length - 6); if (extension.Equals(".temlx")) { ExperimentManager.SaveToCrypt(experiment, file); } else { ExperimentManager.Save(experiment, file); } } catch (System.IO.IOException e) { FileDialogs.ShowSaveErrorDialog(m_applicationContext.MainWindow.WindowShell, e.Message, file); } catch (UnauthorizedAccessException e) { FileDialogs.ShowSaveErrorDialog(m_applicationContext.MainWindow.WindowShell, e.Message, file); } catch (Exception e) { FileDialogs.ShowSaveErrorDialog(m_applicationContext.MainWindow.WindowShell, e.Message, file); } } } }
private void SaveFunc(object param) { //save the experiment of this application view model Experiment experiment = m_viewModel.Experiment; if (experiment != null) { string file; if (experiment.ExperimentInfo.FilePath == String.Empty) { file = FileDialogs.GetExperimentFilename <Ookii.Dialogs.Wpf.VistaSaveFileDialog>(); } else { file = experiment.ExperimentInfo.FilePath; } if (file != null) { try { ExperimentManager.Save(experiment, file); } catch (System.IO.IOException e) { NLog.LogManager.GetCurrentClassLogger().Error(String.Format("Failed to Save File {0}. {1}", file, e.Message), e); System.Windows.MessageBox.Show(e.Message, "Failed To Save", MessageBoxButton.OK); } catch (UnauthorizedAccessException e) { NLog.LogManager.GetCurrentClassLogger().Error(String.Format("Failed to Save File {0}. {1}", file, e.Message), e); System.Windows.MessageBox.Show(e.Message, "Failed To Save", MessageBoxButton.OK); } catch (Exception e) { NLog.LogManager.GetCurrentClassLogger().ErrorException(String.Format("Failed to Save File {0}. {1}", file, e.Message), e); System.Windows.MessageBox.Show(e.Message, "Failed To Save", MessageBoxButton.OK); } } } }
public void passwordPickerDestroyed(object sender, EventArgs e) { if (pwdPicker.passwordChanged) { this.Modal = true; //update passwords in the metadata this.m_applicationViewModel.Experiment.ExperimentInfo.ChallengePassword = pwdPicker.challengePwd; this.m_applicationViewModel.Experiment.ExperimentInfo.ExperimentPassword = pwdPicker.experimentPwd; string oldPath = m_applicationViewModel.Experiment.ExperimentInfo.FilePath; string extension = System.IO.Path.GetFileNameWithoutExtension(oldPath); if (!string.IsNullOrEmpty(pwdPicker.challengePwd) || !string.IsNullOrEmpty(pwdPicker.experimentPwd)) { //there is AT LEAST one password //call the procedure to save a locked esxperiment in TEMLX format string path; if (!extension.Equals(".temlx")) { path = addExt(m_applicationViewModel.Experiment.ExperimentInfo.FilePath, ".temlx"); } else { //save an updated version of the experiment path = m_applicationViewModel.Experiment.ExperimentInfo.FilePath; } ExperimentManager.SaveToCrypt(this.m_applicationViewModel.Experiment, path); } else { //there are no password so we should decrypt the file, if this is a TEMLX //save the experiment decrypted and delete the .temlx file string uniquePat = GetUniqueName(m_applicationViewModel.Experiment.ExperimentInfo.FilePath, ".teml"); ExperimentManager.Save(this.m_applicationViewModel.Experiment, uniquePat); } //delete old file TEML ExperimentManager.DeleteFile(oldPath); } pwdPicker = null; }
private void NewFunc(object param) { var experiment = ExperimentManager.New(); Window parentWindow = param as Window; NewExperimentDialog dialog = new NewExperimentDialog(parentWindow, this.SettingsViewModel.DefaultExperimentsDirectory); dialog.DataContext = experiment.ExperimentInfo; bool?success = dialog.ShowDialog(); if (success == true) { ApplicationViewModel newApplicationViewModel = ApplicationViewModel.CreateNewApplicationViewModel(m_viewModel, experiment); RecentExperimentsHelper.UpdateRecentExperimentList(TraceLab.Core.Settings.Settings.RecentExperimentsPath, experiment.ExperimentInfo.FilePath); OpenInWindow(newApplicationViewModel); string file = experiment.ExperimentInfo.FilePath; try { ExperimentManager.Save(experiment, file); } catch (System.IO.IOException e) { NLog.LogManager.GetCurrentClassLogger().Error(String.Format("Failed to Save File {0}. {1}", file, e.Message), e); System.Windows.MessageBox.Show(e.Message, "Failed To Save", MessageBoxButton.OK); } catch (UnauthorizedAccessException e) { NLog.LogManager.GetCurrentClassLogger().Error(String.Format("Failed to Save File {0}. {1}", file, e.Message), e); System.Windows.MessageBox.Show(e.Message, "Failed To Save", MessageBoxButton.OK); } catch (Exception e) { NLog.LogManager.GetCurrentClassLogger().ErrorException(String.Format("Failed to Save File {0}. {1}", file, e.Message), e); System.Windows.MessageBox.Show(e.Message, "Failed To Save", MessageBoxButton.OK); } } }