コード例 #1
0
ファイル: GetOctopusFeed.cs プロジェクト: tmpreston/OctoPosh
        protected override void ProcessRecord()
        {
            var baseResourceList = new List <FeedResource>();

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

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

            case ByUrl:
                //Multiple values but one of them is wildcarded, which is not an accepted scenario (I.e -MachineName WebServer*, Database1)
                if (_urlList.Any(item => WildcardPattern.ContainsWildcardCharacters(item) && _urlList.Count > 1))
                {
                    throw OctoposhExceptions.ParameterCollectionHasRegularAndWildcardItem("URL");
                }
                //Only 1 wildcarded value (ie -MachineName WebServer*)
                else if (_urlList.Any(item => WildcardPattern.ContainsWildcardCharacters(item) && _urlList.Count == 1))
                {
                    var pattern = new WildcardPattern(_urlList.First());
                    baseResourceList = _connection.Repository.Feeds.FindMany(t => pattern.IsMatch(t.FeedUri.ToLower()));
                }
                //multiple non-wildcared values (i.e. -MachineName WebServer1,Database1)
                else if (!_urlList.Any(WildcardPattern.ContainsWildcardCharacters))
                {
                    baseResourceList = _connection.Repository.Feeds.FindMany(t => _urlList.Contains(t.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.GetOctopusFeed(baseResourceList);

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