Beispiel #1
0
        private void NewWindowButton_Click(object sender, RoutedEventArgs e)
        {
            string datasetPath;

            if (ViewModel.Store != null)
            {
                datasetPath = ViewModel.Store.DataDirectory;
            }
            else
            {
                datasetPath = ".";
            }
            var newDatasetListWindow = new DatasetListWindow(ViewModel.JobStore, this.instanceManager, datasetPath);

            newDatasetListWindow.Show();
        }
Beispiel #2
0
        public DatasetListWindow(JobStore jobStore, SingleInstanceManager instanceManager, string initialWorkingDirectory)
        {
            try
            {
                this.initialWorkingDirectory = initialWorkingDirectory;

                this.ViewModel = new DatasetListWindowViewModel(jobStore);

                if (instanceManager == null)
                {
                    this.instanceManager = new SingleInstanceManager();
                    var uiContext = TaskScheduler.FromCurrentSynchronizationContext();
                    this.instanceManager.OnCreateForWorkingDirectory += (sender, args) =>
                    {
                        Task.Factory.StartNew(() =>
                        {
                            // Try and locate a window that already contains this working directory; raise it if one exists,
                            // rather than creating a new one.
                            foreach (var window in Application.Current.Windows)
                            {
                                var datasetWindow = window as DatasetListWindow;
                                if (datasetWindow != null && datasetWindow.Visibility == Visibility.Visible)
                                {
                                    try
                                    {
                                        var windowFullPath =
                                            System.IO.Path.GetFullPath(datasetWindow.ViewModel.Store.DataDirectory);
                                        var newDirectoryFullPath = System.IO.Path.GetFullPath(args.WorkingDirectory);

                                        if (windowFullPath == newDirectoryFullPath) // TODO: better way to check for path equality?
                                        {
                                            datasetWindow.Refresh();
                                            datasetWindow.Activate();
                                            return;
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        //quietly fail; if GetFullPath fails on either path, we don't really care (just move on to the next window)
                                    }
                                }
                            }

                            var newDatasetListWindow = new DatasetListWindow(ViewModel.JobStore, this.instanceManager, args.WorkingDirectory);
                            newDatasetListWindow.Show();
                            newDatasetListWindow.Activate();
                        }, new CancellationToken(), TaskCreationOptions.None, uiContext);
                    };
                }
                else
                {
                    this.instanceManager = instanceManager;
                }

                InitializeComponent();
                this.ViewModel.TrackedJobsChanged += (sender, args) =>
                {
                    TabControl.SelectedItem = JobsTab;
                };
                Console.WriteLine("Results browser window opened");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Trace.TraceError("Error occurred while creating window:");
                Trace.TraceError(e.ToString());
                throw e;
            }
        }