Пример #1
0
        public MainViewModel()
        {
            NewProjectCommand = new RelayCommand(newProject);
            OpenCommand = new RelayCommand(openButtonCommand);
            OpenFolderCommand = new RelayCommand(openFolder);
            RemoveRecentFolderCommand = new RelayCommand(removeRecentFolder);

            SettingsCommand = new RelayCommand(showSettings);

            ClearConsoleCommand = new ListenRelayCommand(Dispatcher.CurrentDispatcher)
            {
                Execute = clearConsole,
                CanExecuteDelegate = (o) => !string.IsNullOrWhiteSpace(Project.Output)
            }.ListenOn(Project, t => t.Output);

            ClearParametersCommand = new ListenRelayCommand(Dispatcher.CurrentDispatcher)
            {
                Execute = clearParameters,
                CanExecuteDelegate = (o) => Project.Parameters.Count > 0
            }.ListenOn(Project, p => p.Parameters);

            SaveParametersCommand = new ListenRelayCommand(Dispatcher.CurrentDispatcher)
            {
                Execute = saveParameters,
                CanExecuteDelegate = (o) => Project.Parameters.Count > 0
            }.ListenOn(Project, p => p.Parameters);
        }
Пример #2
0
        public void OnDeserialied(StreamingContext context)
        {
            Project = context.Context as Project;

            if (BatchPath != null && !File.Exists(BatchPath))
            {
                // Fixing BatchPath to be a full file extension by first searching for it in the project's directory and subdirectories
                var candidates = Directory.GetFiles(Project.DirectoryPath, BatchPath, SearchOption.AllDirectories);
                if (candidates.Length > 1)
                    throw new FileNotFoundException("Multiple " + BatchPath + " files were found.", BatchPath);

                if (candidates.Length == 1)
                    BatchPath = candidates[0];
                else // assert candidates.Length == 0
                { // Otherwise search for it in the default batch files
                    candidates = Directory.GetFiles(Project.executingDirectory + "\\Resources\\batch", BatchPath);
                    if (candidates.Length > 1)
                        throw new FileNotFoundException("Multiple " + BatchPath + " files were found in " + Project.executingDirectory + "\\Resources\\batch");

                    if (candidates.Length == 1)
                        BatchPath = candidates[0];
                    else
                        throw new FileNotFoundException("Unable to find " + BatchPath + " in the project or in the default batch files.");
                }
            }


            ExecuteCommand = new ListenRelayCommand()
            {
                Execute = Execute,
                CanExecuteDelegate = (r) => !Project.IsExecuting
            }.ListenOn(Project, p => p.IsExecuting);
        }