Exemplo n.º 1
0
        private static void OnDataContextPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            MainWindow window = sender as MainWindow;

            ApplicationViewModelWrapper oldWrapper = args.OldValue as ApplicationViewModelWrapper;
            ApplicationViewModelWrapper newWrapper = args.NewValue as ApplicationViewModelWrapper;

            // Detach the old
            if (oldWrapper != null)
            {
                if (oldWrapper.ExperimentViewModel != null)
                {
                    oldWrapper.ExperimentViewModel.ExperimentCompleted -= window.vm_ExperimentCompleted;
                }
                oldWrapper.UnhandledException -= window.newWrapper_UnhandledException;
            }

            // Attach the new
            if (newWrapper != null)
            {
                if (newWrapper.ExperimentViewModel != null)
                {
                    newWrapper.ExperimentViewModel.ExperimentCompleted += window.vm_ExperimentCompleted;
                }
                newWrapper.UnhandledException += window.newWrapper_UnhandledException;
            }
        }
Exemplo n.º 2
0
        private void ShowDefineCompositeComponentWizard(object sender, ExecutedRoutedEventArgs e)
        {
            ApplicationViewModelWrapper appvm = (ApplicationViewModelWrapper)DataContext;
            var experiment = appvm.ExperimentDocumentWrapper[0] as ExperimentViewModel;

            if (experiment != null)
            {
                //create dialog with data contex of Define Benchmark
                var wizard = new DefineCompositeComponentWizard(this);

                Action <TraceLab.Core.Components.CompositeComponentMetadataDefinition> howToAddToComponentLibrary =
                    (TraceLab.Core.Components.CompositeComponentMetadataDefinition metadataDefinition) =>
                {
                    appvm.ComponentLibraryViewModel.AddReplaceCompositeComponentMetadataDefinition(metadataDefinition);
                };

                //create view model
                var setup = new DefiningCompositeComponentSetupViewModel(experiment, appvm.SettingsViewModel.ComponentPaths, howToAddToComponentLibrary);

                wizard.DataContext = setup;

                wizard.Owner = this;
                wizard.Show();
            }
        }
Exemplo n.º 3
0
        private void CanShowDefineCompositeComponentWizard(object sender, CanExecuteRoutedEventArgs e)
        {
            bool canDo = false;
            ApplicationViewModelWrapper appvm = (ApplicationViewModelWrapper)DataContext;

            if (appvm != null && appvm.ExperimentDocumentWrapper != null && appvm.ExperimentDocumentWrapper.Count() > 0)
            {
                var experiment = appvm.ExperimentDocumentWrapper[0] as ExperimentViewModel;
                if (experiment != null)
                {
                    bool isAnyNodeSelected = false;
                    var  enumerator        = experiment.TopLevel.Vertices.GetEnumerator();
                    while (isAnyNodeSelected == false && enumerator.MoveNext())
                    {
                        var node = enumerator.Current;
                        if (node is ExperimentStartNode == false && node is ExperimentEndNode == false)
                        {
                            isAnyNodeSelected = node.IsSelected;
                        }
                    }
                    canDo = isAnyNodeSelected;
                }
            }

            e.CanExecute = canDo;
        }
Exemplo n.º 4
0
        public static void Run(TraceLab.Core.ViewModels.ApplicationViewModel context)
        {
            var    wrapper = new ApplicationViewModelWrapper(context);
            var    app     = new Application();
            Window wind    = new MainWindow(wrapper);

            app.Run(wind);
        }
Exemplo n.º 5
0
        internal MainWindow(ApplicationViewModelWrapper context)
        {
            InitializeComponent();
            DataContext = context;

            this.Closing       += MainWindow_Closing;
            this.Loaded        += new RoutedEventHandler(MainWindow_Loaded);
            DockManager.Loaded += new RoutedEventHandler(DockManager_Loaded);
            DockManager.DeserializationCallback = DockManager_DeserializationHelper;
        }
Exemplo n.º 6
0
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            ApplicationViewModelWrapper appvm = (ApplicationViewModelWrapper)DataContext;

            this.Left   = appvm.SettingsViewModel.MainWindowRect.Left;
            this.Top    = appvm.SettingsViewModel.MainWindowRect.Top;
            this.Width  = appvm.SettingsViewModel.MainWindowRect.Width;
            this.Height = appvm.SettingsViewModel.MainWindowRect.Height;

            Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(LoadLayout));
        }
Exemplo n.º 7
0
        private bool CanShowDefineBenchmarkDialog(object param)
        {
            bool canDo = false;
            ApplicationViewModelWrapper appvm = (ApplicationViewModelWrapper)DataContext;

            if (appvm != null && appvm.ExperimentDocumentWrapper != null && appvm.ExperimentDocumentWrapper.Count() > 0)
            {
                var experiment = appvm.ExperimentDocumentWrapper[0] as ExperimentViewModel;
                canDo = experiment != null;
            }

            return(canDo);
        }
Exemplo n.º 8
0
        private void ShowBenchmarkWizardDialog(object param)
        {
            ApplicationViewModelWrapper appvm = (ApplicationViewModelWrapper)DataContext;
            var experimentToBeBenchmarked     = appvm.ExperimentDocumentWrapper[0] as ExperimentViewModel;

            if (experimentToBeBenchmarked != null)
            {
                //start wizard - load benchmarks from benchmarks directory, initiates wizard state
                appvm.BenchmarkWizardViewModel.StartWizard((Experiment)experimentToBeBenchmarked.TopLevel);

                //create wizard with data contex of benchmark wizard view model
                BenchmarkWizardDialog box = new BenchmarkWizardDialog(this);
                box.DataContext = appvm.BenchmarkWizardViewModel;
                box.ShowDialog();
            }
        }
Exemplo n.º 9
0
        private void ShowDefineBenchmarkDialog(object param)
        {
            ApplicationViewModelWrapper appvm = (ApplicationViewModelWrapper)DataContext;
            var experiment = appvm.ExperimentDocumentWrapper[0] as ExperimentViewModel;

            if (experiment != null)
            {
                var loggerNameRoot = new TraceLab.Core.Components.LoggerNameRoot(experiment.TopLevel.ExperimentInfo.Id);
                //validate experiment first
                bool isValid = TraceLab.Core.ExperimentExecution.ExperimentValidator.ValidateExperiment((IExperiment)experiment.TopLevel,
                                                                                                        appvm.WorkspaceViewModel.WorkspaceTypeDirectories, loggerNameRoot);

                if (isValid == false)
                {
                    //show error dialog
                    string caption   = TraceLab.Core.Messages.ExperimentNotValid;
                    string errorText = TraceLab.Core.Messages.InvalidExperimentErrorMessage;
                    MessageBox.Show(errorText, caption, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
                else
                {
                    //create dialog with data contex of Define Benchmark
                    DefineBenchmarkDialog box = new DefineBenchmarkDialog();

                    //until multiple benchmark directories are not implemented
                    List <string> benchmarkDirectories = new List <string>();
                    benchmarkDirectories.Add(appvm.BenchmarkWizardViewModel.BenchmarksDirectory);

                    //create view model
                    DefiningBenchmarkViewModel definingBenchmarkViewModel = new DefiningBenchmarkViewModel((Experiment)experiment.TopLevel,
                                                                                                           benchmarkDirectories,
                                                                                                           (TraceLab.Core.Components.ComponentsLibrary)appvm.ComponentLibraryViewModel,
                                                                                                           (TraceLab.Core.Workspaces.Workspace)appvm.WorkspaceViewModel,
                                                                                                           appvm.WorkspaceViewModel.WorkspaceTypeDirectories,
                                                                                                           appvm.SettingsViewModel.WebserviceAddress);

                    box.DataContext = definingBenchmarkViewModel;
                    box.Owner       = this;
                    box.ShowDialog();
                }
            }
        }
Exemplo n.º 10
0
        void LoadLayout()
        {
            if (m_isLoaded == false)
            {
                try
                {
                    ApplicationViewModelWrapper appvm = (ApplicationViewModelWrapper)DataContext;

                    string layoutPath = TraceLab.Core.Settings.Settings.LayoutPath;
                    if (string.IsNullOrEmpty(layoutPath) == false && System.IO.File.Exists(layoutPath))
                    {
                        DockManager.RestoreLayout(layoutPath);
                    }

                    m_isLoaded = true;
                }
                catch (Exception ex)
                {
                    NLog.LogManager.GetCurrentClassLogger().ErrorException("Layout failed to be restored from previously saved layout.xml (in %APPDATA%/TraceLab). File was corrupted. Application restored default layout.", ex);
                }
            }
        }
Exemplo n.º 11
0
        void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            ApplicationViewModelWrapper appvm = (ApplicationViewModelWrapper)DataContext;

            ExperimentViewModel experimentVM = null;

            if (appvm.ExperimentDocumentWrapper != null)
            {
                experimentVM = appvm.ExperimentDocumentWrapper[0] as ExperimentViewModel;
                if (experimentVM != null && experimentVM.IsModified)
                {
                    var result = MessageBox.Show(TraceLab.Core.Messages.ClosingUnsavedDocumentWarning,
                                                 "Modified Experiment Not Saved", MessageBoxButton.YesNo, MessageBoxImage.Warning);

                    if (result == MessageBoxResult.No)
                    {
                        e.Cancel = true;
                        return;
                    }
                }
            }
            appvm.SettingsViewModel.MainWindowRect.Height = Height;
            appvm.SettingsViewModel.MainWindowRect.Width  = Width;
            appvm.SettingsViewModel.MainWindowRect.Left   = Left;
            appvm.SettingsViewModel.MainWindowRect.Top    = Top;

            appvm.SaveSettings();
            appvm.SaveUserTags();

            DockManager.SaveLayout(TraceLab.Core.Settings.Settings.LayoutPath);

            if (experimentVM != null && String.IsNullOrEmpty(experimentVM.TopLevel.ExperimentInfo.FilePath) == true)
            {
                //experiment was never saved, so delete its units from the workspace
                appvm.WorkspaceViewModel.DeleteExperimentUnits();
            }
        }