protected override void ProcessRecord()
        {
            var baseResourceList = new List <ReleaseResource>();

            var project = _connection.Repository.Projects.FindByName(ProjectName);

            if (project == null)
            {
                throw OctoposhExceptions.ResourceNotFound(ProjectName, "Project");
            }
            else
            {
                switch (ParameterSetName)
                {
                case ByVersion:
                    foreach (var version in ReleaseVersion)
                    {
                        try
                        {
                            baseResourceList.Add(_connection.Repository.Projects.GetReleaseByVersion(project, version));
                        }
                        catch (Exception e)
                        {
                            WriteError(new ErrorRecord(e, "ResourceNotFound", ErrorCategory.ObjectNotFound, e.Message));
                        }
                    }
                    break;

                case ByLatest:

                    var releases = new List <ReleaseResource>();

                    if (Latest > 30)
                    {
                        releases = _connection.Repository.Projects.GetAllReleases(project).ToList();
                    }
                    else
                    {
                        releases = _connection.Repository.Projects.GetReleases(project).Items.ToList();
                    }

                    if (releases.Count > Latest)
                    {
                        baseResourceList.AddRange(releases.GetRange(0, Latest));
                    }
                    else
                    {
                        baseResourceList.AddRange(releases);
                    }

                    break;

                default:
                    baseResourceList.AddRange(_connection.Repository.Projects.GetAllReleases(project).ToList());
                    break;
                }
            }

            if (ResourceOnly)
            {
                WriteObject(baseResourceList);
            }

            else
            {
                var converter  = new OutputConverter();
                var outputList = converter.GetOctopusRelease(baseResourceList);

                WriteObject(outputList);
            }
        }
Exemplo n.º 2
0
        protected override void ProcessRecord()
        {
            var baseResourceList = new List <ChannelResource>();

            if (_projectNameList == null)
            {
                var allProjects = _connection.Repository.Projects.FindAll();

                if (_channelNameList == null)
                {
                    allProjects.ForEach(p => baseResourceList.AddRange(_connection.Repository.Projects.GetChannels(p).Items.ToList()));
                }
                else
                {
                    allProjects.ForEach(p => baseResourceList.AddRange(_connection.Repository.Projects.GetChannels(p).Items.Where(c => _channelNameList.Contains(c.Name.ToLower())).ToList()));
                }
            }
            else
            {
                var projects = new List <ProjectResource>();

                foreach (var name in _projectNameList)
                {
                    var project = _connection.Repository.Projects.FindByName(name);

                    if (project == null)
                    {
                        throw OctoposhExceptions.ResourceNotFound(name, "Project");
                    }

                    projects.Add(project);
                }

                foreach (var project in projects)
                {
                    if (_channelNameList == null)
                    {
                        baseResourceList.AddRange(_connection.Repository.Projects.GetChannels(project).Items.ToList());
                    }

                    else
                    {
                        //Multiple values but one of them is wildcarded, which is not an accepted scenario (I.e -MachineName WebServer*, Database1)
                        if (_channelNameList.Any(item => WildcardPattern.ContainsWildcardCharacters(item) && _channelNameList.Count > 1))
                        {
                            throw OctoposhExceptions.ParameterCollectionHasRegularAndWildcardItem("ChannelName");
                        }
                        //Only 1 wildcarded value (ie -MachineName WebServer*)
                        else if (_channelNameList.Any(item => WildcardPattern.ContainsWildcardCharacters(item) && _channelNameList.Count == 1))
                        {
                            var pattern = new WildcardPattern(_channelNameList.First());
                            baseResourceList.AddRange(_connection.Repository.Projects.GetChannels(project).Items.Where(t => pattern.IsMatch(t.Name.ToLower())).ToList());
                        }
                        //multiple non-wildcared values (i.e. -MachineName WebServer1,Database1)
                        else if (!_channelNameList.Any(WildcardPattern.ContainsWildcardCharacters))
                        {
                            baseResourceList.AddRange(_connection.Repository.Projects.GetChannels(project).Items.Where(t => _channelNameList.Contains(t.Name.ToLower())).ToList());
                        }
                    }
                }
            }

            if (ResourceOnly)
            {
                WriteObject(baseResourceList);
            }

            else
            {
                var converter  = new OutputConverter();
                var outputList = converter.GetOctopusChannel(baseResourceList);

                WriteObject(outputList);
            }
        }