Exemplo n.º 1
0
        protected override CommandResult ExecuteDetailed(GetTargetsCommandArgs args, ChangeObservable observable)
        {
            IEnumerable <Exception> exceptions = Enumerable.Empty <Exception>();
            TargetsCommandResult    commandResult;

            if (args.All)
            {
                commandResult = new TargetsCommandResult(sdkRepository.GetAllTargets()
                                                         .Select(t => new TargetResult(t.Name, t.Version,
                                                                                       t.LongVersion,
                                                                                       t.ShortVersion))
                                                         .OrderBy(t => t.Name).ThenByDescending(t => t.Version));
            }
            else
            {
                ExecutionContext.WriteWarning("This command is deprecated. Use 'get project-information' instead.", false);

                ProjectEntity project          = ProjectEntity.Decorate(entityFactory.Create(Guid.NewGuid().ToByteString(), args).Root);
                TargetsResult targetsResult    = targetParser.Targets(project, false);
                Target[]      availableTargets = sdkRepository.GetAllTargets().ToArray();
                commandResult = new TargetsCommandResult(targetsResult.ValidTargets
                                                         .Select(t => new TargetResult(t.Name, t.Version,
                                                                                       t.LongVersion,
                                                                                       t.ShortVersion,
                                                                                       availableTargets.Any(at => t.Name == at.Name && at.LongVersion == t.LongVersion)))
                                                         .OrderBy(t => t.Name).ThenByDescending(t => t.Version));
                exceptions = targetsResult.Errors;
            }

            return(new CommandResult(0, commandResult, exceptions));
        }
        public ProjectTargetValueEditorModel(IServiceProvider serviceProvider, string projectDirectory)
        {
            this.serviceProvider = serviceProvider;
            IPlcncliCommunication cliCommunication = serviceProvider.GetService(typeof(SPlcncliCommunication)) as IPlcncliCommunication;

            if (cliCommunication != null)
            {
                TargetsCommandResult targetsCommandResult =
                    cliCommunication.ExecuteCommand(Resources.Command_get_targets, null, typeof(TargetsCommandResult))
                    as TargetsCommandResult;
                InstalledTargets = targetsCommandResult.Targets;

                ProjectInformationCommandResult projectInfo = cliCommunication.ExecuteCommand(
                    Resources.Command_get_project_information, null, typeof(ProjectInformationCommandResult),
                    Resources.Option_get_project_information_no_include_detection,
                    Resources.Option_get_project_information_project, $"\"{projectDirectory}\"") as
                                                              ProjectInformationCommandResult;
                ProjectTargets = projectInfo.Targets;
                //TODO extract these commands somewhere after the viewModel.Showmodal call (and possibly asyncron), otherwise the ui seems to be too unresponsive
            }
        }