Ejemplo n.º 1
0
        protected override IEnumerable <ICommandOutput> ExecuteCore()
        {
            var targetDescriptor = HostEnvironment.GetOrCreateScopedDescriptor(Scope ?? string.Empty);

            yield return(VerifyDescriptor(targetDescriptor));

            yield return(VerifyProjectRepository());

            yield return(SetupEnvironmentForAdd());

            var sourceRepositories = GetSourceRepositories();


            if (Project && System)
            {
                var sysToAdd = new List <PackageIdentifier>();
                using (ChangeMonitor(targetDescriptor))
                {
                    foreach (var m in PackageManager.AddProjectPackage(PackageRequest, sourceRepositories, targetDescriptor.Value, HostEnvironment.ProjectRepository, AddOptions))
                    {
                        yield return(ToOutput(m));

                        ParseSuccess(m, sysToAdd.Add);
                    }
                    foreach (var identifier in sysToAdd)
                    {
                        foreach (var m in PackageManager.AddSystemPackage(PackageRequest.Exact(identifier.Name, identifier.Version), sourceRepositories, HostEnvironment.SystemRepository))
                        {
                            yield return(ToOutput(m));
                        }
                    }
                }
            }
            else if (Project)
            {
                using (ChangeMonitor(targetDescriptor))
                {
                    foreach (var m in PackageManager.AddProjectPackage(PackageRequest, sourceRepositories, targetDescriptor.Value, HostEnvironment.ProjectRepository, AddOptions))
                    {
                        yield return(ToOutput(m));
                    }
                }
            }
            else if (System)
            {
                foreach (var m in PackageManager.AddSystemPackage(PackageRequest, sourceRepositories, HostEnvironment.SystemRepository, AddOptions))
                {
                    yield return(ToOutput(m));
                }
            }

            if (_packageNotFound)
            {
                var hit = false;
                foreach (var m in PackageManager.ListPackages(sourceRepositories, Name))
                {
                    if (!hit)
                    {
                        yield return(new Info("Did you mean one of the following package?", Name));

                        hit = true;
                    }
                    yield return(ToOutput(m));
                }
            }
            if (ShouldUpdateDescriptor)
            {
                TrySaveDescriptorFile(targetDescriptor);
            }
        }