コード例 #1
0
        protected override void ProcessRecord()
        {
            var baseResourceList = new List <ProjectGroupResource>();

            switch (ParameterSetName)
            {
            case All:
                baseResourceList = _connection.Repository.ProjectGroups.FindAll();
                break;

            case ByName:
                var projectGroupNameList = ProjectGroupName?.ToList().ConvertAll(s => s.ToLower());
                //Multiple values but one of them is wildcarded, which is not an accepted scenario (I.e -MachineName WebServer*, Database1)
                if (projectGroupNameList.Any(item => WildcardPattern.ContainsWildcardCharacters(item) && projectGroupNameList.Count > 1))
                {
                    throw OctoposhExceptions.ParameterCollectionHasRegularAndWildcardItem("ProjectGroupName");
                }
                //Only 1 wildcarded value (ie -MachineName WebServer*)
                else if (projectGroupNameList.Any(item => WildcardPattern.ContainsWildcardCharacters(item) && projectGroupNameList.Count == 1))
                {
                    var pattern = new WildcardPattern(projectGroupNameList.First());
                    baseResourceList = _connection.Repository.ProjectGroups.FindMany(x => pattern.IsMatch(x.Name.ToLower()));
                }
                //multiple non-wildcared values (i.e. -MachineName WebServer1,Database1)
                else if (!projectGroupNameList.Any(item => WildcardPattern.ContainsWildcardCharacters(item)))
                {
                    baseResourceList = _connection.Repository.ProjectGroups.FindMany(x => projectGroupNameList.Contains(x.Name.ToLower()));
                }
                break;
            }

            if (ResourceOnly)
            {
                if (baseResourceList.Count == 1)
                {
                    WriteObject(baseResourceList.FirstOrDefault(), true);
                }
                else
                {
                    WriteObject(baseResourceList, true);
                }
            }

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

                if (outputList.Count == 1)
                {
                    WriteObject(outputList.FirstOrDefault(), true);
                }
                else
                {
                    WriteObject(outputList, true);
                }
            }
        }