Пример #1
0
        protected override void ProcessRecord()
        {
            var TagSetNameList = TagSetName?.ToList().ConvertAll(s => s.ToLower());

            var baseResourceList = new List <TagSetResource>();

            if (TagSetNameList == null)
            {
                baseResourceList.AddRange(_connection.Repository.TagSets.FindAll());
            }

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

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

            else
            {
                var converter = new OutputConverter();
                List <OutputOctopusTagSet> outputList = converter.GetOctopusTagSet(baseResourceList);

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