Esempio n. 1
0
        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);
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Opens the experiment using given application window
 /// </summary>
 /// <param name="filename">Filename.</param>
 /// <param name="applicationContext">Application context.</param>
 internal static void OpenExperiment(string filename, ApplicationContext applicationContext)
 {
     try
     {
         Experiment           experiment = TraceLab.Core.Experiments.ExperimentManager.Load(filename, TraceLab.Core.Components.ComponentsLibrary.Instance);
         ApplicationViewModel newApplicationViewModel = ApplicationViewModel.CreateNewApplicationViewModel(applicationContext.Application, experiment);
         RecentExperimentsHelper.UpdateRecentExperimentList(TraceLab.Core.Settings.Settings.RecentExperimentsPath, experiment.ExperimentInfo.FilePath);
         applicationContext.OpenInWindow(newApplicationViewModel);
     }
     catch (TraceLab.Core.Exceptions.ExperimentLoadException ex)
     {
         string msg = String.Format("Unable to open the file {0}. Error: {1}", filename, ex.Message);
         NLog.LogManager.GetCurrentClassLogger().Error(msg);
     }
 }
Esempio n. 3
0
 internal void OpenExperiment(string file)
 {
     try
     {
         var experiment = ExperimentManager.Load(file, (TraceLab.Core.Components.ComponentsLibrary)m_viewModel.ComponentLibraryViewModel);
         ApplicationViewModel newApplicationViewModel = ApplicationViewModel.CreateNewApplicationViewModel(m_viewModel, experiment);
         RecentExperimentsHelper.UpdateRecentExperimentList(TraceLab.Core.Settings.Settings.RecentExperimentsPath, file);
         OpenInWindow(newApplicationViewModel);
     }
     catch (TraceLab.Core.Exceptions.ExperimentLoadException ex)
     {
         string msg = String.Format("Unable to open the file {0}. Error: {1}", file, ex.Message);
         NLog.LogManager.GetCurrentClassLogger().ErrorException(msg, ex);
         MessageBox.Show(msg, "Failed to load experiment", MessageBoxButton.OK, MessageBoxImage.Exclamation);
     }
 }
Esempio n. 4
0
        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);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Opens the experiment using given application window
        /// </summary>
        /// <param name="filename">Filename.</param>
        /// <param name="applicationContext">Application context.</param>
        internal static void OpenExperiment(string filename, ApplicationContext applicationContext)
        {
            bool   isPasswordTestPassed = false;
            bool   isAChallenge         = false;
            string userPassword         = null;

            Experiment experiment = null;

            try {
                string extension = filename.Substring(filename.Length - 6);

                if (extension.Equals(".temlx"))
                {
                    isAChallenge = true;
                    //It's a crypted file so decrypt it
                    try {
                        Stream decryptedFileStream = Crypto.DecryptFile(@filename, @filename);
                        experiment = TraceLab.Core.Experiments.ExperimentManager.Load(decryptedFileStream, filename, TraceLab.Core.Components.ComponentsLibrary.Instance);
                        string challengePwd  = experiment.ExperimentInfo.ChallengePassword;
                        string experimentPwd = experiment.ExperimentInfo.ExperimentPassword;

                        userPassword = PasswordDialog.TakePwd(applicationContext.MainWindow.WindowShell, challengePwd, experimentPwd);
                        if (userPassword != null)
                        {
                            isPasswordTestPassed         = true;
                            experiment.unlockingPassword = userPassword;
                        }
                    } catch (Exception ex) {
                        Console.WriteLine(ex.ToString());
                    }
                }
                else
                {
                    //if it isn't a cryptd file continue with the standard flow
                    experiment = TraceLab.Core.Experiments.ExperimentManager.Load(filename, TraceLab.Core.Components.ComponentsLibrary.Instance);
                }

                //Collection<ExperimentNode> c = experiment.Vertices;

                /*
                 * foreach (ExperimentNode experimentNode in experiment.Vertices)
                 * {
                 *  string type = experimentNode.GetType().ToString();
                 *  Console.WriteLine(type);
                 *
                 *  if(experimentNode.GetType().Equals(TraceLab.Core.Experiments.ChallengeNode)){
                 *      ChallengeNode node = experimentNode as ChallengeNode;
                 *
                 *
                 *  }
                 * }
                 *
                 */
                if (isPasswordTestPassed || !isAChallenge)   //TODO check this if condition
                {
                    ApplicationViewModel newApplicationViewModel = ApplicationViewModel.CreateNewApplicationViewModel(applicationContext.Application, experiment);
                    RecentExperimentsHelper.UpdateRecentExperimentList(TraceLab.Core.Settings.Settings.RecentExperimentsPath, experiment.ExperimentInfo.FilePath);
                    applicationContext.OpenInWindow(newApplicationViewModel);
                }

                // HERZUM SPRINT 3: TLAB-86
                string typeBaseline  = experiment.ExperimentInfo.ExperimentResultsUnittype;
                string valueBaseline = experiment.ExperimentInfo.ExperimentResultsUnitvalue;
                if (valueBaseline != null)
                {
                    applicationContext.MainWindow.WorkspaceWindowPad.ShowBaseline(typeBaseline, valueBaseline);
                }
                // END HERZUM SPRINT 3: TLAB-86
            } catch (TraceLab.Core.Exceptions.ExperimentLoadException ex) {
                string msg = String.Format("Unable to open the file {0}. Error: {1}", filename, ex.Message);
                NLog.LogManager.GetCurrentClassLogger().Error(msg);
            }
        }
Esempio n. 6
0
        private bool InitViewModel()
        {
            bool startTraceLab = true;
            var  settings      = TraceLab.Core.Settings.Settings.GetSettings();

            for (int i = 0; i < TypeDirectories.Count; ++i)
            {
                var newSettingPath = new TraceLab.Core.Settings.SettingsPath(true, TypeDirectories[i]);

                if (!settings.TypePaths.Contains(newSettingPath))
                {
                    settings.TypePaths.Insert(i, newSettingPath);
                }
            }

            for (int i = 0; i < ComponentDirectories.Count; ++i)
            {
                var newSettingPath = new TraceLab.Core.Settings.SettingsPath(true, ComponentDirectories[i]);

                if (!settings.ComponentPaths.Contains(newSettingPath))
                {
                    settings.ComponentPaths.Insert(i, newSettingPath);
                }
            }

            for (int i = 0; i < PackageDirectories.Count; ++i)
            {
                settings.PackagePaths.Insert(i, new TraceLab.Core.Settings.SettingsPath(true, PackageDirectories[i]));
            }

            TraceLab.Core.PackageSystem.PackageManager.Instance.SetPackageLocations(settings.PackagePaths);
            TraceLab.Core.PackageSystem.PackageManager.Instance.ScanForPackages();

            // Install any packages that were queued at the start
            var packagesDir = settings.PackagePaths.LastOrDefault();

            if (PackagesToInstall.Count > 0)
            {
                UnpackNewPackagesIn((string)packagesDir);
            }

            /*
             * if (UnpackNewPackagesIn((string)packagesDir))
             * {
             *  System.Windows.Forms.MessageBox.Show("New package(s) have been installed. TraceLab needs to be re-launched.",
             *      "Closing TraceLab", System.Windows.Forms.MessageBoxButtons.OK,
             *      System.Windows.Forms.MessageBoxIcon.Exclamation);
             *  startTraceLab = false;
             * }
             * else
             * {
             *  System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show("Would you like to continue openning TraceLab?",
             *      "Start TraceLab", System.Windows.Forms.MessageBoxButtons.YesNo,
             *      System.Windows.Forms.MessageBoxIcon.Question);
             *  if (result == System.Windows.Forms.DialogResult.No)
             *  {
             *      startTraceLab = false;
             *  }
             * }
             * }
             *
             * if (TraceLabSDK.RuntimeInfo.IsRunInMono) {
             * //  we force Tracelab execution because if Tracelab runs in mono when one opens a package mono.exe remains in execution
             * // also after the unpacking operation is done
             * startTraceLab = true;
             * }
             */
            if (startTraceLab)
            {
                // Append all the type directories from the package locations.
                var typeDirectories = new List <string>(settings.TypePaths.Select(path => path.Path));

                Workspace     = InitWorkspace(typeDirectories, WorkspaceDirectory, CacheDirectory);
                MainViewModel = new ApplicationViewModel(Workspace);
                MainViewModel.LogViewModel     = initialLogViewModel;
                MainViewModel.Settings         = settings;
                MainViewModel.PropertyChanged += MainViewModel_PropertyChanged;

                var componentLibrary = CreateComponentLibraryViewModel(PackageManager.Instance, settings, DecisionDirectory, UserDirectory);
                Workspace.RegisterPackageTypes(componentLibrary.PackageTypeDirectories);
                MainViewModel.ComponentLibraryViewModel = componentLibrary;
                MainViewModel.BenchmarkWizard           = new BenchmarkWizard(BenchmarkDirectory, ComponentsLibrary.Instance, Workspace, typeDirectories, UserDirectory, settings);

                if (String.IsNullOrEmpty(ExperimentFileToBeOpen) == false || string.IsNullOrEmpty(settings.DefaultExperiment) == false)
                {
                    string file = string.IsNullOrEmpty(ExperimentFileToBeOpen) ? settings.DefaultExperiment : ExperimentFileToBeOpen;
                    try
                    {
                        var w2 = new List <string>(settings.TypePaths.Select(path => path.Path));
                        ComponentsLibrary.Instance.Rescan(PackageManager.Instance, w2, false);
                        MainViewModel.Experiment = TraceLab.Core.Experiments.ExperimentManager.Load(file, ComponentsLibrary.Instance);
                        RecentExperimentsHelper.UpdateRecentExperimentList(TraceLab.Core.Settings.Settings.RecentExperimentsPath, file);
                    }
                    catch (TraceLab.Core.Exceptions.ExperimentLoadException ex)
                    {
                        string msg = String.Format("Unable to open the file {0}. Error: {1}", file, ex.Message);
                        NLog.LogManager.GetCurrentClassLogger().Warn(msg);

                        if (!TraceLabSDK.RuntimeInfo.IsRunInMono)
                        {
                            System.Windows.Forms.MessageBox.Show(msg, "Experiment Loading Failure",
                                                                 System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
                        }
                    }
                }
            }

            return(startTraceLab);
        }
Esempio n. 7
0
 static ApplicationViewModel()
 {
     WebsiteLink.LoadLinksFromXML(null, out s_videos, out s_links);
     s_recentExperiments = RecentExperimentsHelper.LoadRecentExperimentListFromXML(TraceLab.Core.Settings.Settings.RecentExperimentsPath);
 }