예제 #1
0
        private void ChooseExecutable()
        {
            string[] files = service.ChooseFiles(null, "Executable files (*.exe;*.dll)|*.exe;*.dll|ZIP files (*.zip)|*.zip|All Files (*.*)|*.*", "exe");
            if (files == null || files.Length == 0)
            {
                return;
            }

            if (files.Length > 1)
            {
                string[] exeFiles = files.Where(f => f.EndsWith(".exe")).ToArray();
                if (exeFiles.Length == 0)
                {
                    service.ShowError("No executable files have been chosen.", "New experiment");
                    return;
                }
                string mainFile = null;
                if (exeFiles.Length == 1)
                {
                    mainFile = exeFiles[0];
                }
                else
                {
                    mainFile = service.ChooseOption("Select main executable",
                                                    new AsyncLazy <string[]>(() => Task.FromResult(exeFiles)),
                                                    new Predicate <string>(file => file == exeFiles[0]));
                    if (mainFile == null)
                    {
                        return;
                    }
                }

                // First element of the file names array must be main executable
                int i = Array.IndexOf(files, mainFile);
                if (i < 0)
                {
                    throw new InvalidOperationException("The chosen main executable is not found in the original file list");
                }
                files[i] = files[0];
                files[0] = mainFile;
            }
            fileNames = files;
            NotifyPropertyChanged("MainExecutable");
            NotifyPropertyChanged("ExecutableFileNames");
            UseMostRecentExecutable = false;
        }