예제 #1
0
 /// <summary>
 ///     Create a WildcardAlias with two patterns, the
 ///     stored pattern and the pattern that is to be used
 ///     at runtime.
 /// </summary>
 /// <remarks>
 ///     Create a WildcardAlias with two patterns, the
 ///     stored pattern and the pattern that is to be used
 ///     at runtime. One single '*' is allowed as a wildcard
 ///     character.
 /// </remarks>
 public WildcardAlias(string storedPattern, string runtimePattern)
 {
     if (null == storedPattern)
     {
         throw new ArgumentNullException("storedPattern");
     }
     if (null == runtimePattern)
     {
         throw new ArgumentNullException("runtimePattern");
     }
     _storedPattern = new WildcardPattern(storedPattern);
     _runtimePattern = new WildcardPattern(runtimePattern);
 }
        /// <summary>
        /// Get control panel item by the canonical name.
        /// </summary>
        /// <param name="controlPanelItems"></param>
        /// <param name="withCategoryFilter"></param>
        /// <returns></returns>
        internal List <ShellFolderItem> GetControlPanelItemByCanonicalName(List <ShellFolderItem> controlPanelItems, bool withCategoryFilter)
        {
            List <ShellFolderItem> list    = new List <ShellFolderItem>();
            HashSet <string>       itemSet = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            if (CanonicalNames == null)
            {
                bool found = false;
                foreach (ShellFolderItem item in controlPanelItems)
                {
                    string canonicalName = (string)item.ExtendedProperty("System.ApplicationName");
                    if (canonicalName == null)
                    {
                        found = true;
                        list.Add(item);
                    }
                }

                if (!found)
                {
                    string errMsg = withCategoryFilter
                                        ? ControlPanelResources.NoControlPanelItemFoundWithNullCanonicalNameWithCategory
                                        : ControlPanelResources.NoControlPanelItemFoundWithNullCanonicalName;
                    ErrorRecord error = new ErrorRecord(new InvalidOperationException(errMsg), string.Empty,
                                                        ErrorCategory.InvalidArgument, CanonicalNames);
                    WriteError(error);
                }

                return(list);
            }

            foreach (string pattern in CanonicalNames)
            {
                bool            found    = false;
                WildcardPattern wildcard = WildcardPattern.Get(pattern, WildcardOptions.IgnoreCase);
                foreach (ShellFolderItem item in controlPanelItems)
                {
                    string path          = item.Path;
                    string canonicalName = (string)item.ExtendedProperty("System.ApplicationName");
                    canonicalName = canonicalName != null
                                        ? canonicalName.Substring(0, canonicalName.IndexOf("\0", StringComparison.OrdinalIgnoreCase))
                                        : null;

                    if (canonicalName == null)
                    {
                        if (pattern.Equals("*", StringComparison.OrdinalIgnoreCase))
                        {
                            found = true;
                            if (!itemSet.Contains(path))
                            {
                                itemSet.Add(path);
                                list.Add(item);
                            }
                        }
                    }
                    else
                    {
                        if (!wildcard.IsMatch(canonicalName))
                        {
                            continue;
                        }
                        if (itemSet.Contains(path))
                        {
                            found = true;
                            continue;
                        }

                        found = true;
                        itemSet.Add(path);
                        list.Add(item);
                    }
                }

                if (!found && !WildcardPattern.ContainsWildcardCharacters(pattern))
                {
                    string formatString = withCategoryFilter
                                              ? ControlPanelResources.NoControlPanelItemFoundForGivenCanonicalNameWithCategory
                                              : ControlPanelResources.NoControlPanelItemFoundForGivenCanonicalName;
                    string      errMsg = StringUtil.Format(formatString, pattern);
                    ErrorRecord error  = new ErrorRecord(new InvalidOperationException(errMsg),
                                                         "NoControlPanelItemFoundForGivenCanonicalName",
                                                         ErrorCategory.InvalidArgument, pattern);
                    WriteError(error);
                }
            }

            return(list);
        }
예제 #3
0
        public void FindPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, PackageSourceListRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (!ValidatePackageManagementVersion(request))
            {
                return;
            }

            request.Debug(Resources.Messages.DebugInfoCallMethod, PackageProviderName, string.Format(CultureInfo.InvariantCulture, "FindPackage' - name='{0}', requiredVersion='{1}',minimumVersion='{2}', maximumVersion='{3}'", name, requiredVersion, minimumVersion, maximumVersion));

            promptForSampleJSON(request);

            // no package name or the name with wildcard
            if (string.IsNullOrWhiteSpace(name) || WildcardPattern.ContainsWildcardCharacters(name))
            {
                // In the case of the package name is null or contains wildcards, error out if a user puts version info
                if (!string.IsNullOrWhiteSpace(requiredVersion) || !string.IsNullOrWhiteSpace(minimumVersion) || !string.IsNullOrWhiteSpace(maximumVersion))
                {
                    request.Warning(Resources.Messages.WildCardCharsAreNotSupported, name);
                    return;
                }

                var packages = request.GetPackages(name);
                if (request.GetOptionValue("AllVersions").IsTrue())
                {
                    // if version is specified then name can not be empty or with wildcard. in this case the cmdlet has been errored out already.
                    // here we just return all packages we can find
                    if (request.FilterOnVersion(packages, requiredVersion, minimumVersion, maximumVersion, minInclusive: true, maxInclusive: true, latest: false).OrderBy(p => p.Name).Any(p => !request.YieldFromSwidtag(p, p.Name)))
                    {
                        return;
                    }
                    return;
                }

                //return the latest version
                if (packages.GroupBy(p => p.Name)
                    .Select(each => each.OrderByDescending(pp => pp.Version).FirstOrDefault()).OrderBy(p => p.Name).Any(item => !request.YieldFromSwidtag(item, item.Name)))
                {
                    return;
                }
            }
            else
            {
                // a user specifies name
                // asked for a specific version?
                if (!string.IsNullOrWhiteSpace(requiredVersion))
                {
                    request.YieldFromSwidtag(request.GetPackage(name, requiredVersion), name);
                    return;
                }

                var allVersion = request.GetOptionValue("AllVersions").IsTrue();
                // asked for a version range?
                if (!string.IsNullOrWhiteSpace(minimumVersion) || !string.IsNullOrEmpty(maximumVersion) || allVersion)
                {
                    var packages = request.GetPackagesWithinVersionRange(name, minimumVersion, maximumVersion);
                    if (allVersion)
                    {
                        if (packages.Any(p => !request.YieldFromSwidtag(p, name)))
                        {
                            return;
                        }
                    }
                    else
                    {
                        if (request.YieldFromSwidtag(packages.FirstOrDefault(), name))
                        {
                            return;
                        }
                    }

                    return;
                }

                // just return by name
                request.YieldFromSwidtag(request.GetPackage(name), name);
            }
        }
        /// <summary>
        /// A filter that matches the Name property of the object passed using PowerShell wildcard
        /// matching.
        /// </summary>
        /// <param name="m">The object to test for a match.</param>
        /// <param name="filterCriteria">The wildcard pattern to test.</param>
        /// <returns>A value indicating whether the object matches.</returns>
        protected static bool WildcardNameFilter(TMemberType m, object filterCriteria)
        {
            WildcardPattern pattern = filterCriteria as WildcardPattern;

            return(pattern == null ? false : pattern.IsMatch(m.Name));
        }
예제 #5
0
        public void FindPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, BootstrapRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            request.Verbose(Resources.Messages.FindingPackage, string.Format(CultureInfo.CurrentCulture, "{0}::FindPackage' '{1}','{2}','{3}','{4}'", PackageProviderName, name, requiredVersion, minimumVersion, maximumVersion));

            if (name != null && name.EqualsIgnoreCase("PackageManagement"))
            {
                // they are looking for PackageManagement itself.
                // future todo: let PackageManagement update itself.
                return;
            }

            if (request.LocalSource.Any())
            {
                // find a provider from given path
                request.FindProviderFromFile(name, requiredVersion, minimumVersion, maximumVersion);
                return;
            }

            // are they are looking for a specific provider?
            if (string.IsNullOrWhiteSpace(name) || WildcardPattern.ContainsWildcardCharacters(name))
            {
                // no, return all providers that match the range.
                var wildcardPattern = new WildcardPattern(name, WildcardOptions);

                if (request.GetOptionValue("AllVersions").IsTrue())
                {
                    // Feed.Query() can return an empty provider, so here we need to exclude it by checking p.Name !=null or empty.
                    foreach (var p in request.Providers.Distinct(PackageEqualityComparer).Where(p => !string.IsNullOrWhiteSpace(p.Name) && (string.IsNullOrWhiteSpace(name) || wildcardPattern.IsMatch(p.Name))))
                    {
                        FindPackage(p.Name, null, "0.0", null, 0, request);
                    }
                    return;
                }

                if (request.Providers.Distinct(PackageEqualityComparer).Where(p => string.IsNullOrWhiteSpace(name) || wildcardPattern.IsMatch(p.Name)).Any(p => !request.YieldFromSwidtag(p, requiredVersion, minimumVersion, maximumVersion, name)))
                {
                    // if there is a problem, exit.
                    return;
                }
            }
            else
            {
                // return just the one they asked for.

                // asked for a specific version?
                if (!string.IsNullOrWhiteSpace(requiredVersion))
                {
                    request.YieldFromSwidtag(request.GetProvider(name, requiredVersion), name);
                    return;
                }

                if (request.GetOptionValue("AllVersions").IsTrue())
                {
                    if (request.GetProviderAll(name, minimumVersion, maximumVersion).Distinct(PackageEqualityComparer).Any(provider => !request.YieldFromSwidtag(provider, name)))
                    {
                        // if there is a problem, exit.
                        return;
                    }
                    return;
                }

                // asked for a version range?
                if (!string.IsNullOrWhiteSpace(minimumVersion) || !string.IsNullOrEmpty(maximumVersion))
                {
                    if (request.GetProvider(name, minimumVersion, maximumVersion).Distinct(PackageEqualityComparer).Any(provider => !request.YieldFromSwidtag(provider, name)))
                    {
                        // if there is a problem, exit.
                        return;
                    }
                    return;
                }

                // just return by name
                request.YieldFromSwidtag(request.GetProvider(name), name);
            }

            // return any matches in the name
        }
예제 #6
0
        /// <summary>
        /// Gets the IContentReaders for the current path(s)
        /// </summary>
        /// <returns>
        /// An array of IContentReaders for the current path(s)
        /// </returns>
        internal List <ContentHolder> GetContentReaders(
            string[] readerPaths,
            CmdletProviderContext currentCommandContext)
        {
            // Resolve all the paths into PathInfo objects

            Collection <PathInfo> pathInfos = ResolvePaths(readerPaths, false, true, currentCommandContext);

            // Create the results array

            List <ContentHolder> results = new List <ContentHolder>();

            foreach (PathInfo pathInfo in pathInfos)
            {
                // For each path, get the content writer

                Collection <IContentReader> readers = null;

                try
                {
                    string pathToProcess = WildcardPattern.Escape(pathInfo.Path);

                    if (currentCommandContext.SuppressWildcardExpansion)
                    {
                        pathToProcess = pathInfo.Path;
                    }

                    readers =
                        InvokeProvider.Content.GetReader(pathToProcess, currentCommandContext);
                }
                catch (PSNotSupportedException notSupported)
                {
                    WriteError(
                        new ErrorRecord(
                            notSupported.ErrorRecord,
                            notSupported));
                    continue;
                }
                catch (DriveNotFoundException driveNotFound)
                {
                    WriteError(
                        new ErrorRecord(
                            driveNotFound.ErrorRecord,
                            driveNotFound));
                    continue;
                }
                catch (ProviderNotFoundException providerNotFound)
                {
                    WriteError(
                        new ErrorRecord(
                            providerNotFound.ErrorRecord,
                            providerNotFound));
                    continue;
                }
                catch (ItemNotFoundException pathNotFound)
                {
                    WriteError(
                        new ErrorRecord(
                            pathNotFound.ErrorRecord,
                            pathNotFound));
                    continue;
                }

                if (readers != null && readers.Count > 0)
                {
                    if (readers.Count == 1 && readers[0] != null)
                    {
                        ContentHolder holder =
                            new ContentHolder(pathInfo, readers[0], null);

                        results.Add(holder);
                    }
                }
            } // foreach pathInfo in pathInfos

            return(results);
        } // GetContentReaders
예제 #7
0
        /// <summary>
        /// Unsubscribe from the event
        /// </summary>
        protected override void ProcessRecord()
        {
            // Go through all the received events and write them to the output
            // pipeline
            foreach (PSEventSubscriber subscriber in Events.Subscribers)
            {
                // If the event identifier matches, remove the subscription
                if (
                    ((_sourceIdentifier != null) && _matchPattern.IsMatch(subscriber.SourceIdentifier)) ||
                    ((SubscriptionId >= 0) && (subscriber.SubscriptionId == SubscriptionId))
                    )
                {
                    // If this is a support event but they aren't explicitly
                    // looking for them, continue.
                    if (subscriber.SupportEvent && (!Force))
                    {
                        continue;
                    }

                    _foundMatch = true;

                    if (ShouldProcess(
                            String.Format(
                                System.Globalization.CultureInfo.CurrentCulture,
                                EventingStrings.EventSubscription,
                                subscriber.SourceIdentifier),
                            EventingStrings.Unsubscribe))
                    {
                        Events.UnsubscribeEvent(subscriber);
                    }
                }
            }

            // Generate an error if we couldn't find the subscription identifier,
            // and no globbing was done.
            if ((_sourceIdentifier != null) &&
                (!WildcardPattern.ContainsWildcardCharacters(_sourceIdentifier)) &&
                (!_foundMatch))
            {
                ErrorRecord errorRecord = new ErrorRecord(
                    new ArgumentException(
                        String.Format(
                            System.Globalization.CultureInfo.CurrentCulture,
                            EventingStrings.EventSubscriptionNotFound, _sourceIdentifier)),
                    "INVALID_SOURCE_IDENTIFIER",
                    ErrorCategory.InvalidArgument,
                    null);

                WriteError(errorRecord);
            }
            else if ((SubscriptionId >= 0) &&
                     (!_foundMatch))
            {
                ErrorRecord errorRecord = new ErrorRecord(
                    new ArgumentException(
                        String.Format(
                            System.Globalization.CultureInfo.CurrentCulture,
                            EventingStrings.EventSubscriptionNotFound, SubscriptionId)),
                    "INVALID_SUBSCRIPTION_IDENTIFIER",
                    ErrorCategory.InvalidArgument,
                    null);

                WriteError(errorRecord);
            }
        }
예제 #8
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);
            }
        }
예제 #9
0
        public static List <PSRepositoryInfo> Read(string[] repoNames, out string[] errorList)
        {
            List <string> tempErrorList = new List <string>();
            var           foundRepos    = new List <PSRepositoryInfo>();

            XDocument doc;

            try
            {
                // Open file
                doc = LoadXDocument(FullRepositoryPath);
            }
            catch (Exception e)
            {
                throw new PSInvalidOperationException(String.Format("Loading repository store failed: {0}", e.Message));
            }

            if (repoNames == null || !repoNames.Any() || string.Equals(repoNames[0], "*") || repoNames[0] == null)
            {
                // Name array or single value is null so we will list all repositories registered
                // iterate through the doc
                foreach (XElement repo in doc.Descendants("Repository"))
                {
                    if (!Uri.TryCreate(repo.Attribute("Uri").Value, UriKind.Absolute, out Uri thisUri))
                    {
                        tempErrorList.Add(String.Format("Unable to read incorrectly formatted Uri for repo {0}", repo.Attribute("Name").Value));
                        continue;
                    }

                    PSCredentialInfo thisCredentialInfo;
                    string           credentialInfoErrorMessage = $"Repository {repo.Attribute("Name").Value} has invalid CredentialInfo. {PSCredentialInfo.VaultNameAttribute} and {PSCredentialInfo.SecretNameAttribute} should both be present and non-empty";
                    // both keys are present
                    if (repo.Attribute(PSCredentialInfo.VaultNameAttribute) != null && repo.Attribute(PSCredentialInfo.SecretNameAttribute) != null)
                    {
                        try
                        {
                            // both values are non-empty
                            // = valid credentialInfo
                            thisCredentialInfo = new PSCredentialInfo(repo.Attribute(PSCredentialInfo.VaultNameAttribute).Value, repo.Attribute(PSCredentialInfo.SecretNameAttribute).Value);
                        }
                        catch (Exception)
                        {
                            thisCredentialInfo = null;
                            tempErrorList.Add(credentialInfoErrorMessage);
                            continue;
                        }
                    }
                    // both keys are missing
                    else if (repo.Attribute(PSCredentialInfo.VaultNameAttribute) == null && repo.Attribute(PSCredentialInfo.SecretNameAttribute) == null)
                    {
                        // = valid credentialInfo
                        thisCredentialInfo = null;
                    }
                    // one of the keys is missing
                    else
                    {
                        thisCredentialInfo = null;
                        tempErrorList.Add(credentialInfoErrorMessage);
                        continue;
                    }

                    PSRepositoryInfo currentRepoItem = new PSRepositoryInfo(repo.Attribute("Name").Value,
                                                                            thisUri,
                                                                            Int32.Parse(repo.Attribute("Priority").Value),
                                                                            Boolean.Parse(repo.Attribute("Trusted").Value),
                                                                            thisCredentialInfo);

                    foundRepos.Add(currentRepoItem);
                }
            }
            else
            {
                foreach (string repo in repoNames)
                {
                    bool            repoMatch           = false;
                    WildcardPattern nameWildCardPattern = new WildcardPattern(repo, WildcardOptions.IgnoreCase);

                    foreach (var node in doc.Descendants("Repository").Where(e => nameWildCardPattern.IsMatch(e.Attribute("Name").Value)))
                    {
                        repoMatch = true;
                        if (!Uri.TryCreate(node.Attribute("Uri").Value, UriKind.Absolute, out Uri thisUri))
                        {
                            //debug statement
                            tempErrorList.Add(String.Format("Unable to read incorrectly formatted Uri for repo {0}", node.Attribute("Name").Value));
                            continue;
                        }

                        PSCredentialInfo thisCredentialInfo;
                        string           credentialInfoErrorMessage = $"Repository {node.Attribute("Name").Value} has invalid CredentialInfo. {PSCredentialInfo.VaultNameAttribute} and {PSCredentialInfo.SecretNameAttribute} should both be present and non-empty";
                        // both keys are present
                        if (node.Attribute(PSCredentialInfo.VaultNameAttribute) != null && node.Attribute(PSCredentialInfo.SecretNameAttribute) != null)
                        {
                            try
                            {
                                // both values are non-empty
                                // = valid credentialInfo
                                thisCredentialInfo = new PSCredentialInfo(node.Attribute(PSCredentialInfo.VaultNameAttribute).Value, node.Attribute(PSCredentialInfo.SecretNameAttribute).Value);
                            }
                            catch (Exception)
                            {
                                thisCredentialInfo = null;
                                tempErrorList.Add(credentialInfoErrorMessage);
                                continue;
                            }
                        }
                        // both keys are missing
                        else if (node.Attribute(PSCredentialInfo.VaultNameAttribute) == null && node.Attribute(PSCredentialInfo.SecretNameAttribute) == null)
                        {
                            // = valid credentialInfo
                            thisCredentialInfo = null;
                        }
                        // one of the keys is missing
                        else
                        {
                            thisCredentialInfo = null;
                            tempErrorList.Add(credentialInfoErrorMessage);
                            continue;
                        }

                        PSRepositoryInfo currentRepoItem = new PSRepositoryInfo(node.Attribute("Name").Value,
                                                                                thisUri,
                                                                                Int32.Parse(node.Attribute("Priority").Value),
                                                                                Boolean.Parse(node.Attribute("Trusted").Value),
                                                                                thisCredentialInfo);

                        foundRepos.Add(currentRepoItem);
                    }

                    if (!repo.Contains("*") && !repoMatch)
                    {
                        tempErrorList.Add(String.Format("Unable to find repository with Name '{0}'.  Use Get-PSResourceRepository to see all available repositories.", repo));
                    }
                }
            }

            errorList = tempErrorList.ToArray();
            // Sort by priority, then by repo name
            var reposToReturn = foundRepos.OrderBy(x => x.Priority).ThenBy(x => x.Name);

            return(reposToReturn.ToList());
        }
        /// <summary>
        /// The ProcessRecord method does the following for each of the
        /// requested process names:
        /// 1) Check that the process is not a critical process.
        /// 2) Attempt to stop that process.
        /// If no process is requested then nothing occurs.
        /// </summary>
        protected override void ProcessRecord()
        {
            Process[] processes = null;

            try
            {
                processes = Process.GetProcesses();
            }
            catch (InvalidOperationException ioe)
            {
                base.ThrowTerminatingError(new ErrorRecord(ioe,
                                                           "UnableToAcessProcessList",
                                                           ErrorCategory.InvalidOperation,
                                                           null));
            }


            // For every process name passed to the cmdlet, get the associated
            // processes.
            // Write a nonterminating error for failure to retrieve
            // a process.
            foreach (string name in processNames)
            {
                // Write a user-friendly verbose message to the pipeline. These
                // messages are intended to give the user detailed information
                // on the operations performed by the cmdlet. These messages will
                // appear with the -Verbose option.
                string message = String.Format(CultureInfo.CurrentCulture,
                                               "Attempting to stop process \"{0}\".", name);
                WriteVerbose(message);

                // Validate the process name against a wildcard pattern.
                // If the name does not contain any wildcard patterns, it
                // will be treated as an exact match.
                WildcardOptions options = WildcardOptions.IgnoreCase |
                                          WildcardOptions.Compiled;
                WildcardPattern wildcard = new WildcardPattern(name, options);

                foreach (Process process in processes)
                {
                    string processName;

                    try
                    {
                        processName = process.ProcessName;
                    }
                    catch (Win32Exception e)
                    {
                        WriteError(new ErrorRecord(
                                       e, "ProcessNameNotFound",
                                       ErrorCategory.ObjectNotFound,
                                       process)
                                   );
                        continue;
                    }

                    // Write a debug message to the host that can be used when
                    // troubleshooting a problem. All debug messages will appear
                    // with the -Debug option.
                    message = String.Format(CultureInfo.CurrentCulture,
                                            "Acquired name for pid {0} : \"{1}\"",
                                            process.Id, processName);
                    WriteDebug(message);

                    // Check to see if this process matches the current process
                    // name pattern. Skip this process if it does not.
                    if (!wildcard.IsMatch(processName))
                    {
                        continue;
                    }

                    // Stop the process.
                    SafeStopProcess(process);
                } // foreach (Process...
            }     // foreach (string...
        }         // ProcessRecord
예제 #11
0
        private bool YieldPackages(string hive, RegistryKey regkey, string name, string requiredVersion, string minimumVersion, string maximumVersion, Request request)
        {
            if (regkey != null)
            {
                var includeWindowsInstaller = request.GetOptionValue("IncludeWindowsInstaller").IsTrue();
                var includeSystemComponent  = request.GetOptionValue("IncludeSystemComponent").IsTrue();

                var wildcardPattern = new WildcardPattern(name ?? "", WildcardOptions.CultureInvariant | WildcardOptions.IgnoreCase);


                foreach (var key in regkey.GetSubKeyNames())
                {
                    var subkey = regkey.OpenSubKey(key);
                    if (subkey != null)
                    {
                        var properties = subkey.GetValueNames().ToDictionaryNicely(each => each.ToString(), each => (subkey.GetValue(each) ?? string.Empty).ToString(), StringComparer.OrdinalIgnoreCase);

                        if (!includeWindowsInstaller && properties.ContainsKey("WindowsInstaller") && properties["WindowsInstaller"] == "1")
                        {
                            continue;
                        }

                        if (!includeSystemComponent && properties.ContainsKey("SystemComponent") && properties["SystemComponent"] == "1")
                        {
                            continue;
                        }

                        var productName = "";

                        if (!properties.TryGetValue("DisplayName", out productName))
                        {
                            // no product name?
                            continue;
                        }

                        if (!string.IsNullOrWhiteSpace(productName) && (string.IsNullOrWhiteSpace(name) || wildcardPattern.IsMatch(productName)))
                        {
                            var productVersion  = properties.Get("DisplayVersion") ?? "";
                            var publisher       = properties.Get("Publisher") ?? "";
                            var uninstallString = properties.Get("QuietUninstallString") ?? properties.Get("UninstallString") ?? "";
                            var comments        = properties.Get("Comments") ?? "";

                            var fp = hive + @"\" + subkey;

                            if (!string.IsNullOrEmpty(requiredVersion))
                            {
                                if (SoftwareIdentityVersionComparer.CompareVersions("unknown", requiredVersion, productVersion) != 0)
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(minimumVersion) && SoftwareIdentityVersionComparer.CompareVersions("unknown", productVersion, minimumVersion) < 0)
                                {
                                    continue;
                                }
                                if (!string.IsNullOrEmpty(maximumVersion) && SoftwareIdentityVersionComparer.CompareVersions("unknown", productVersion, maximumVersion) > 0)
                                {
                                    continue;
                                }
                            }

                            if (request.YieldSoftwareIdentity(fp, productName, productVersion, "unknown", comments, "", name, "", "") != null)
                            {
                                if (properties.Keys.Where(each => !string.IsNullOrWhiteSpace(each)).Any(k => request.AddMetadata(fp, k.MakeSafeFileName(), properties[k]) == null))
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                }
            }
            return(true);
        }
예제 #12
0
        /// <summary>
        /// Remove the event from the queue.
        /// </summary>
        protected override void ProcessRecord()
        {
            // Go through all the received events and write them to the output
            // pipeline
            bool foundMatch = false;

            lock (Events.ReceivedEvents.SyncRoot)
            {
                PSEventArgsCollection currentEvents = Events.ReceivedEvents;

                for (int eventCounter = currentEvents.Count; eventCounter > 0; eventCounter--)
                {
                    PSEventArgs currentEvent = currentEvents[eventCounter - 1];

                    // If they specified a event identifier and we don't match, continue
                    if ((_sourceIdentifier != null) &&
                        (!_matchPattern.IsMatch(currentEvent.SourceIdentifier)))
                    {
                        continue;
                    }

                    // If they specified a TimeGenerated and we don't match, continue
                    if ((_eventIdentifier >= 0) &&
                        (currentEvent.EventIdentifier != _eventIdentifier))
                    {
                        continue;
                    }

                    foundMatch = true;
                    if (ShouldProcess(
                            string.Format(
                                System.Globalization.CultureInfo.CurrentCulture,
                                EventingStrings.EventResource,
                                currentEvent.SourceIdentifier),
                            EventingStrings.Remove))
                    {
                        currentEvents.RemoveAt(eventCounter - 1);
                    }
                }
            }

            // Generate an error if we couldn't find the subscription identifier,
            // and no globbing was done.
            if ((_sourceIdentifier != null) &&
                (!WildcardPattern.ContainsWildcardCharacters(_sourceIdentifier)) &&
                (!foundMatch))
            {
                ErrorRecord errorRecord = new(
                    new ArgumentException(
                        string.Format(
                            System.Globalization.CultureInfo.CurrentCulture,
                            EventingStrings.SourceIdentifierNotFound, _sourceIdentifier)),
                    "INVALID_SOURCE_IDENTIFIER",
                    ErrorCategory.InvalidArgument,
                    null);

                WriteError(errorRecord);
            }
            else if ((_eventIdentifier >= 0) && (!foundMatch))
            {
                ErrorRecord errorRecord = new(
                    new ArgumentException(
                        string.Format(
                            System.Globalization.CultureInfo.CurrentCulture,
                            EventingStrings.EventIdentifierNotFound, _eventIdentifier)),
                    "INVALID_EVENT_IDENTIFIER",
                    ErrorCategory.InvalidArgument,
                    null);

                WriteError(errorRecord);
            }
        }
예제 #13
0
 private string Resolve(WildcardPattern from, WildcardPattern
     to, string typeName)
 {
     var match = from.Matches(typeName);
     return match != null ? to.Inject(match) : null;
 }
예제 #14
0
        private static string WildcardToWqlLikeOperand(WildcardPattern wildcardPattern, out bool needsClientSideFiltering)
        {
            string nakedOperand = WildcardPatternToCimQueryParser.Parse(wildcardPattern, out needsClientSideFiltering);

            return(ObjectToWqlLiteral(nakedOperand));
        }
예제 #15
0
        /// <summary>
        /// Gets a list of matching commands
        /// </summary>
        /// <param name="pattern">command pattern</param>
        /// <param name="commandOrigin"></param>
        /// <param name="context"></param>
        /// <param name="rediscoverImportedModules"></param>
        /// <param name="moduleVersionRequired"></param>
        /// <returns></returns>
        internal static IEnumerable <CommandInfo> GetMatchingCommands(string pattern, ExecutionContext context, CommandOrigin commandOrigin, bool rediscoverImportedModules = false, bool moduleVersionRequired = false)
        {
            // Otherwise, if it had wildcards, just return the "AvailableCommand"
            // type of command info.
            WildcardPattern commandPattern = WildcardPattern.Get(pattern, WildcardOptions.IgnoreCase);

            CmdletInfo cmdletInfo = context.SessionState.InvokeCommand.GetCmdlet("Microsoft.PowerShell.Core\\Get-Module");
            PSModuleAutoLoadingPreference moduleAutoLoadingPreference = CommandDiscovery.GetCommandDiscoveryPreference(context, SpecialVariables.PSModuleAutoLoadingPreferenceVarPath, "PSModuleAutoLoadingPreference");

            if ((moduleAutoLoadingPreference != PSModuleAutoLoadingPreference.None) &&
                ((commandOrigin == CommandOrigin.Internal) || ((cmdletInfo != null) && (cmdletInfo.Visibility == SessionStateEntryVisibility.Public))
                )
                )
            {
                foreach (string modulePath in GetDefaultAvailableModuleFiles(true, false, context))
                {
                    // Skip modules that have already been loaded so that we don't expose private commands.
                    string       moduleName     = Path.GetFileNameWithoutExtension(modulePath);
                    var          modules        = context.Modules.GetExactMatchModules(moduleName, all: false, exactMatch: true);
                    PSModuleInfo tempModuleInfo = null;

                    if (modules.Count != 0)
                    {
                        // 1. We continue to the next module path if we don't want to re-discover those imported modules
                        // 2. If we want to re-discover the imported modules, but one or more commands from the module were made private,
                        //    then we don't do re-discovery
                        if (!rediscoverImportedModules || modules.Exists(module => module.ModuleHasPrivateMembers))
                        {
                            continue;
                        }

                        if (modules.Count == 1)
                        {
                            PSModuleInfo psModule = modules[0];
                            tempModuleInfo = new PSModuleInfo(psModule.Name, psModule.Path, null, null);
                            tempModuleInfo.SetModuleBase(psModule.ModuleBase);

                            foreach (var entry in psModule.ExportedCommands)
                            {
                                if (commandPattern.IsMatch(entry.Value.Name))
                                {
                                    CommandInfo current = null;
                                    switch (entry.Value.CommandType)
                                    {
                                    case CommandTypes.Alias:
                                        current = new AliasInfo(entry.Value.Name, null, context);
                                        break;

                                    case CommandTypes.Function:
                                        current = new FunctionInfo(entry.Value.Name, ScriptBlock.EmptyScriptBlock, context);
                                        break;

                                    case CommandTypes.Filter:
                                        current = new FilterInfo(entry.Value.Name, ScriptBlock.EmptyScriptBlock, context);
                                        break;

                                    case CommandTypes.Configuration:
                                        current = new ConfigurationInfo(entry.Value.Name, ScriptBlock.EmptyScriptBlock, context);
                                        break;

                                    case CommandTypes.Cmdlet:
                                        current = new CmdletInfo(entry.Value.Name, null, null, null, context);
                                        break;

                                    default:
                                        Dbg.Assert(false, "cannot be hit");
                                        break;
                                    }

                                    current.Module = tempModuleInfo;
                                    yield return(current);
                                }
                            }

                            continue;
                        }
                    }

                    string moduleShortName  = System.IO.Path.GetFileNameWithoutExtension(modulePath);
                    var    exportedCommands = AnalysisCache.GetExportedCommands(modulePath, false, context);

                    if (exportedCommands == null)
                    {
                        continue;
                    }

                    tempModuleInfo = new PSModuleInfo(moduleShortName, modulePath, null, null);
                    if (InitialSessionState.IsEngineModule(moduleShortName))
                    {
                        tempModuleInfo.SetModuleBase(Utils.DefaultPowerShellAppBase);
                    }

                    //moduleVersionRequired is bypassed by FullyQualifiedModule from calling method. This is the only place where guid will be involved.
                    if (moduleVersionRequired && modulePath.EndsWith(StringLiterals.PowerShellDataFileExtension, StringComparison.OrdinalIgnoreCase))
                    {
                        tempModuleInfo.SetVersion(ModuleIntrinsics.GetManifestModuleVersion(modulePath));
                        tempModuleInfo.SetGuid(ModuleIntrinsics.GetManifestGuid(modulePath));
                    }

                    foreach (var pair in exportedCommands)
                    {
                        var commandName  = pair.Key;
                        var commandTypes = pair.Value;

                        if (commandPattern.IsMatch(commandName))
                        {
                            bool shouldExportCommand = true;

                            // Verify that we don't already have it represented in the initial session state.
                            if ((context.InitialSessionState != null) && (commandOrigin == CommandOrigin.Runspace))
                            {
                                foreach (SessionStateCommandEntry commandEntry in context.InitialSessionState.Commands[commandName])
                                {
                                    string moduleCompareName = null;

                                    if (commandEntry.Module != null)
                                    {
                                        moduleCompareName = commandEntry.Module.Name;
                                    }
                                    else if (commandEntry.PSSnapIn != null)
                                    {
                                        moduleCompareName = commandEntry.PSSnapIn.Name;
                                    }

                                    if (String.Equals(moduleShortName, moduleCompareName, StringComparison.OrdinalIgnoreCase))
                                    {
                                        if (commandEntry.Visibility == SessionStateEntryVisibility.Private)
                                        {
                                            shouldExportCommand = false;
                                        }
                                    }
                                }
                            }

                            if (shouldExportCommand)
                            {
                                if ((commandTypes & CommandTypes.Alias) == CommandTypes.Alias)
                                {
                                    yield return(new AliasInfo(commandName, null, context)
                                    {
                                        Module = tempModuleInfo
                                    });
                                }
                                if ((commandTypes & CommandTypes.Cmdlet) == CommandTypes.Cmdlet)
                                {
                                    yield return(new CmdletInfo(commandName, implementingType: null, helpFile: null, PSSnapin: null, context: context)
                                    {
                                        Module = tempModuleInfo
                                    });
                                }
                                if ((commandTypes & CommandTypes.Function) == CommandTypes.Function)
                                {
                                    yield return(new FunctionInfo(commandName, ScriptBlock.EmptyScriptBlock, context)
                                    {
                                        Module = tempModuleInfo
                                    });
                                }
                                if ((commandTypes & CommandTypes.Configuration) == CommandTypes.Configuration)
                                {
                                    yield return(new ConfigurationInfo(commandName, ScriptBlock.EmptyScriptBlock, context)
                                    {
                                        Module = tempModuleInfo
                                    });
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #16
0
  /** the generated parser.
      Maintains a state and a value stack, currently with fixed maximum size.
      @param yyLex scanner.
      @return result of the last reduction, if any.
      @throws yyException on irrecoverable parse error.
    */
  internal Object yyparse (yyParser.yyInput yyLex)
  {
    if (yyMax <= 0) yyMax = 256;		// initial size
    int yyState = 0;                   // state stack ptr
    int [] yyStates;               	// state stack 
    yyVal = null;
    yyToken = -1;
    int yyErrorFlag = 0;				// #tks to shift
	if (use_global_stacks && global_yyStates != null) {
		yyVals = global_yyVals;
		yyStates = global_yyStates;
   } else {
		yyVals = new object [yyMax];
		yyStates = new int [yyMax];
		if (use_global_stacks) {
			global_yyVals = yyVals;
			global_yyStates = yyStates;
		}
	}

    /*yyLoop:*/ for (yyTop = 0;; ++ yyTop) {
      if (yyTop >= yyStates.Length) {			// dynamically increase
        global::System.Array.Resize (ref yyStates, yyStates.Length+yyMax);
        global::System.Array.Resize (ref yyVals, yyVals.Length+yyMax);
      }
      yyStates[yyTop] = yyState;
      yyVals[yyTop] = yyVal;
//t      if (debug != null) debug.push(yyState, yyVal);

      /*yyDiscarded:*/ while (true) {	// discarding a token does not change stack
        int yyN;
        if ((yyN = yyDefRed[yyState]) == 0) {	// else [default] reduce (yyN)
          if (yyToken < 0) {
            yyToken = yyLex.advance() ? yyLex.token() : 0;
//t            if (debug != null)
//t              debug.lex(yyState, yyToken, yyname(yyToken), yyLex.value());
          }
          if ((yyN = yySindex[yyState]) != 0 && ((yyN += yyToken) >= 0)
              && (yyN < yyTable.Length) && (yyCheck[yyN] == yyToken)) {
//t            if (debug != null)
//t              debug.shift(yyState, yyTable[yyN], yyErrorFlag-1);
            yyState = yyTable[yyN];		// shift to yyN
            yyVal = yyLex.value();
            yyToken = -1;
            if (yyErrorFlag > 0) -- yyErrorFlag;
            goto continue_yyLoop;
          }
          if ((yyN = yyRindex[yyState]) != 0 && (yyN += yyToken) >= 0
              && yyN < yyTable.Length && yyCheck[yyN] == yyToken)
            yyN = yyTable[yyN];			// reduce (yyN)
          else
            switch (yyErrorFlag) {
  
            case 0:
              yyExpectingState = yyState;
              // yyerror(String.Format ("syntax error, got token `{0}'", yyname (yyToken)), yyExpecting(yyState));
//t              if (debug != null) debug.error("syntax error");
              if (yyToken == 0 /*eof*/ || yyToken == eof_token) throw new yyParser.yyUnexpectedEof ();
              goto case 1;
            case 1: case 2:
              yyErrorFlag = 3;
              do {
                if ((yyN = yySindex[yyStates[yyTop]]) != 0
                    && (yyN += Token.yyErrorCode) >= 0 && yyN < yyTable.Length
                    && yyCheck[yyN] == Token.yyErrorCode) {
//t                  if (debug != null)
//t                    debug.shift(yyStates[yyTop], yyTable[yyN], 3);
                  yyState = yyTable[yyN];
                  yyVal = yyLex.value();
                  goto continue_yyLoop;
                }
//t                if (debug != null) debug.pop(yyStates[yyTop]);
              } while (-- yyTop >= 0);
//t              if (debug != null) debug.reject();
              throw new yyParser.yyException("irrecoverable syntax error");
  
            case 3:
              if (yyToken == 0) {
//t                if (debug != null) debug.reject();
                throw new yyParser.yyException("irrecoverable syntax error at end-of-file");
              }
//t              if (debug != null)
//t                debug.discard(yyState, yyToken, yyname(yyToken),
//t  							yyLex.value());
              yyToken = -1;
              goto continue_yyDiscarded;		// leave stack alone
            }
        }
        int yyV = yyTop + 1-yyLen[yyN];
//t        if (debug != null)
//t          debug.reduce(yyState, yyStates[yyV-1], yyN, YYRules.getRule (yyN), yyLen[yyN]);
        yyVal = yyV > yyTop ? null : yyVals[yyV]; // yyVal = yyDefault(yyV > yyTop ? null : yyVals[yyV]);
        switch (yyN) {
case 1:
#line 392 "cs-parser.jay"
  {
		Lexer.check_incorrect_doc_comment ();
	  }
  break;
case 2:
#line 393 "cs-parser.jay"
  { Lexer.CompleteOnEOF = false; }
  break;
case 6:
  case_6();
  break;
case 7:
#line 412 "cs-parser.jay"
  {
		module.AddAttributes ((Attributes) yyVals[0+yyTop], current_namespace);
	  }
  break;
case 8:
  case_8();
  break;
case 13:
  case_13();
  break;
case 14:
#line 457 "cs-parser.jay"
  {
		Error_SyntaxError (yyToken);
	  }
  break;
case 17:
  case_17();
  break;
case 18:
  case_18();
  break;
case 19:
  case_19();
  break;
case 20:
  case_20();
  break;
case 23:
  case_23();
  break;
case 24:
  case_24();
  break;
case 25:
  case_25();
  break;
case 26:
  case_26();
  break;
case 29:
  case_29();
  break;
case 30:
  case_30();
  break;
case 31:
  case_31();
  break;
case 32:
  case_32();
  break;
case 45:
  case_45();
  break;
case 46:
#line 660 "cs-parser.jay"
  {
		current_namespace.DeclarationFound = true;
	  }
  break;
case 47:
  case_47();
  break;
case 55:
  case_55();
  break;
case 56:
  case_56();
  break;
case 57:
  case_57();
  break;
case 58:
  case_58();
  break;
case 59:
  case_59();
  break;
case 60:
  case_60();
  break;
case 61:
  case_61();
  break;
case 62:
  case_62();
  break;
case 63:
  case_63();
  break;
case 64:
  case_64();
  break;
case 65:
#line 787 "cs-parser.jay"
  { yyVal = "event"; PushLocation (GetLocation (yyVals[0+yyTop])); }
  break;
case 66:
#line 788 "cs-parser.jay"
  { yyVal = "return"; PushLocation (GetLocation (yyVals[0+yyTop])); }
  break;
case 67:
#line 795 "cs-parser.jay"
  {
		yyVal = new List<Attribute> (4) { (Attribute) yyVals[0+yyTop] };
	  }
  break;
case 68:
  case_68();
  break;
case 69:
#line 812 "cs-parser.jay"
  {
		++lexer.parsing_block;
	  }
  break;
case 70:
  case_70();
  break;
case 72:
#line 840 "cs-parser.jay"
  { yyVal = null; HadAttributeParens = false;  }
  break;
case 73:
  case_73();
  break;
case 74:
#line 852 "cs-parser.jay"
  { yyVal = null; }
  break;
case 75:
  case_75();
  break;
case 76:
  case_76();
  break;
case 77:
  case_77();
  break;
case 78:
  case_78();
  break;
case 79:
#line 896 "cs-parser.jay"
  {
	  	yyVal = new Argument ((Expression) yyVals[0+yyTop]);
	  }
  break;
case 81:
  case_81();
  break;
case 82:
#line 909 "cs-parser.jay"
  {
		++lexer.parsing_block;
	  }
  break;
case 83:
  case_83();
  break;
case 84:
  case_84();
  break;
case 86:
#line 940 "cs-parser.jay"
  { yyVal = null; }
  break;
case 87:
#line 944 "cs-parser.jay"
  { 
		yyVal = Argument.AType.Ref;
	  }
  break;
case 88:
#line 948 "cs-parser.jay"
  { 
		yyVal = Argument.AType.Out;
	  }
  break;
case 91:
  case_91();
  break;
case 92:
  case_92();
  break;
case 106:
  case_106();
  break;
case 107:
  case_107();
  break;
case 108:
  case_108();
  break;
case 109:
#line 1025 "cs-parser.jay"
  {
	  }
  break;
case 110:
  case_110();
  break;
case 111:
  case_111();
  break;
case 112:
  case_112();
  break;
case 113:
  case_113();
  break;
case 114:
  case_114();
  break;
case 115:
#line 1075 "cs-parser.jay"
  {
		Error_SyntaxError (yyToken);
	  }
  break;
case 116:
  case_116();
  break;
case 117:
  case_117();
  break;
case 118:
  case_118();
  break;
case 121:
#line 1124 "cs-parser.jay"
  {
		current_field.AddDeclarator ((FieldDeclarator) yyVals[0+yyTop]);
	  }
  break;
case 122:
#line 1128 "cs-parser.jay"
  {
		current_field.AddDeclarator ((FieldDeclarator) yyVals[0+yyTop]);
	  }
  break;
case 123:
  case_123();
  break;
case 124:
#line 1144 "cs-parser.jay"
  {
		++lexer.parsing_block;
	  }
  break;
case 125:
  case_125();
  break;
case 126:
  case_126();
  break;
case 129:
  case_129();
  break;
case 130:
  case_130();
  break;
case 131:
  case_131();
  break;
case 132:
  case_132();
  break;
case 133:
#line 1223 "cs-parser.jay"
  {
		report.Error (1641, GetLocation (yyVals[-1+yyTop]), "A fixed size buffer field must have the array size specifier after the field name");
	  }
  break;
case 135:
  case_135();
  break;
case 136:
  case_136();
  break;
case 139:
#line 1253 "cs-parser.jay"
  {
		current_field.AddDeclarator ((FieldDeclarator) yyVals[0+yyTop]);
	  }
  break;
case 140:
#line 1257 "cs-parser.jay"
  {
		current_field.AddDeclarator ((FieldDeclarator) yyVals[0+yyTop]);
	  }
  break;
case 141:
  case_141();
  break;
case 142:
#line 1270 "cs-parser.jay"
  {
		++lexer.parsing_block;
	  }
  break;
case 143:
  case_143();
  break;
case 146:
#line 1289 "cs-parser.jay"
  {
		current_field.AddDeclarator ((FieldDeclarator) yyVals[0+yyTop]);
	  }
  break;
case 147:
#line 1293 "cs-parser.jay"
  {
		current_field.AddDeclarator ((FieldDeclarator) yyVals[0+yyTop]);
	  }
  break;
case 148:
  case_148();
  break;
case 149:
#line 1309 "cs-parser.jay"
  {
		++lexer.parsing_block;
	  }
  break;
case 150:
  case_150();
  break;
case 151:
  case_151();
  break;
case 154:
  case_154();
  break;
case 155:
  case_155();
  break;
case 156:
  case_156();
  break;
case 157:
#line 1377 "cs-parser.jay"
  {
		valid_param_mod = ParameterModifierType.All;
	  }
  break;
case 158:
  case_158();
  break;
case 159:
  case_159();
  break;
case 160:
#line 1416 "cs-parser.jay"
  {
		lexer.parsing_generic_declaration = true;
	  }
  break;
case 161:
  case_161();
  break;
case 162:
#line 1426 "cs-parser.jay"
  {
		lexer.ConstraintsParsing = true;
	  }
  break;
case 163:
  case_163();
  break;
case 164:
  case_164();
  break;
case 165:
  case_165();
  break;
case 169:
#line 1504 "cs-parser.jay"
  { savedLocation = GetLocation (yyVals[0+yyTop]); yyVal = null; }
  break;
case 170:
  case_170();
  break;
case 171:
  case_171();
  break;
case 172:
#line 1528 "cs-parser.jay"
  { yyVal = ParametersCompiled.EmptyReadOnlyParameters; }
  break;
case 174:
  case_174();
  break;
case 175:
  case_175();
  break;
case 176:
  case_176();
  break;
case 177:
  case_177();
  break;
case 178:
  case_178();
  break;
case 179:
  case_179();
  break;
case 180:
  case_180();
  break;
case 181:
#line 1600 "cs-parser.jay"
  {
		yyVal = new ParametersCompiled (new Parameter[] { (Parameter) yyVals[0+yyTop] } );
	  }
  break;
case 182:
#line 1604 "cs-parser.jay"
  {
		yyVal = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation (yyVals[0+yyTop])) }, true);
	  }
  break;
case 183:
  case_183();
  break;
case 184:
  case_184();
  break;
case 185:
  case_185();
  break;
case 186:
  case_186();
  break;
case 187:
  case_187();
  break;
case 188:
  case_188();
  break;
case 189:
  case_189();
  break;
case 190:
#line 1685 "cs-parser.jay"
  {
	  	++lexer.parsing_block;
	  }
  break;
case 191:
  case_191();
  break;
case 192:
#line 1726 "cs-parser.jay"
  { yyVal = Parameter.Modifier.NONE; }
  break;
case 194:
#line 1734 "cs-parser.jay"
  {
		yyVal = yyVals[0+yyTop];
	  }
  break;
case 195:
  case_195();
  break;
case 196:
  case_196();
  break;
case 197:
  case_197();
  break;
case 198:
  case_198();
  break;
case 199:
  case_199();
  break;
case 200:
  case_200();
  break;
case 201:
  case_201();
  break;
case 202:
  case_202();
  break;
case 203:
  case_203();
  break;
case 204:
#line 1828 "cs-parser.jay"
  {
		Error_DuplicateParameterModifier (GetLocation (yyVals[-1+yyTop]), Parameter.Modifier.PARAMS);
	  }
  break;
case 205:
  case_205();
  break;
case 206:
  case_206();
  break;
case 207:
  case_207();
  break;
case 208:
  case_208();
  break;
case 209:
  case_209();
  break;
case 210:
#line 1878 "cs-parser.jay"
  {
		current_property = null;
	  }
  break;
case 211:
  case_211();
  break;
case 212:
  case_212();
  break;
case 214:
  case_214();
  break;
case 215:
  case_215();
  break;
case 218:
#line 1940 "cs-parser.jay"
  {
	  	valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
	  }
  break;
case 219:
  case_219();
  break;
case 220:
  case_220();
  break;
case 221:
#line 1986 "cs-parser.jay"
  {
		lbag.AppendToMember (current_property, GetLocation (yyVals[-2+yyTop]), GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 222:
  case_222();
  break;
case 227:
  case_227();
  break;
case 228:
  case_228();
  break;
case 229:
  case_229();
  break;
case 230:
  case_230();
  break;
case 231:
  case_231();
  break;
case 233:
  case_233();
  break;
case 234:
  case_234();
  break;
case 235:
#line 2127 "cs-parser.jay"
  {
	  }
  break;
case 236:
  case_236();
  break;
case 237:
  case_237();
  break;
case 238:
  case_238();
  break;
case 239:
  case_239();
  break;
case 240:
#line 2167 "cs-parser.jay"
  {
		Error_SyntaxError (yyToken);	  
	  }
  break;
case 243:
  case_243();
  break;
case 244:
  case_244();
  break;
case 245:
#line 2192 "cs-parser.jay"
  {
		report.Error (525, GetLocation (yyVals[0+yyTop]), "Interfaces cannot contain fields or constants");
	  }
  break;
case 246:
#line 2196 "cs-parser.jay"
  {
		report.Error (525, GetLocation (yyVals[0+yyTop]), "Interfaces cannot contain fields or constants");
	  }
  break;
case 251:
#line 2204 "cs-parser.jay"
  {
	  	report.Error (567, GetLocation (yyVals[0+yyTop]), "Interfaces cannot contain operators");
	  }
  break;
case 252:
#line 2208 "cs-parser.jay"
  {
	  	report.Error (526, GetLocation (yyVals[0+yyTop]), "Interfaces cannot contain contructors");
	  }
  break;
case 253:
#line 2212 "cs-parser.jay"
  {
	  	report.Error (524, GetLocation (yyVals[0+yyTop]), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
	  }
  break;
case 254:
#line 2218 "cs-parser.jay"
  {
	  }
  break;
case 255:
  case_255();
  break;
case 257:
  case_257();
  break;
case 258:
  case_258();
  break;
case 259:
  case_259();
  break;
case 261:
#line 2312 "cs-parser.jay"
  { yyVal = Operator.OpType.LogicalNot; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 262:
#line 2313 "cs-parser.jay"
  { yyVal = Operator.OpType.OnesComplement; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 263:
#line 2314 "cs-parser.jay"
  { yyVal = Operator.OpType.Increment; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 264:
#line 2315 "cs-parser.jay"
  { yyVal = Operator.OpType.Decrement; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 265:
#line 2316 "cs-parser.jay"
  { yyVal = Operator.OpType.True; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 266:
#line 2317 "cs-parser.jay"
  { yyVal = Operator.OpType.False; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 267:
#line 2319 "cs-parser.jay"
  { yyVal = Operator.OpType.Addition; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 268:
#line 2320 "cs-parser.jay"
  { yyVal = Operator.OpType.Subtraction; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 269:
#line 2322 "cs-parser.jay"
  { yyVal = Operator.OpType.Multiply; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 270:
#line 2323 "cs-parser.jay"
  {  yyVal = Operator.OpType.Division; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 271:
#line 2324 "cs-parser.jay"
  { yyVal = Operator.OpType.Modulus; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 272:
#line 2325 "cs-parser.jay"
  { yyVal = Operator.OpType.BitwiseAnd; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 273:
#line 2326 "cs-parser.jay"
  { yyVal = Operator.OpType.BitwiseOr; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 274:
#line 2327 "cs-parser.jay"
  { yyVal = Operator.OpType.ExclusiveOr; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 275:
#line 2328 "cs-parser.jay"
  { yyVal = Operator.OpType.LeftShift; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 276:
#line 2329 "cs-parser.jay"
  { yyVal = Operator.OpType.RightShift; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 277:
#line 2330 "cs-parser.jay"
  { yyVal = Operator.OpType.Equality; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 278:
#line 2331 "cs-parser.jay"
  { yyVal = Operator.OpType.Inequality; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 279:
#line 2332 "cs-parser.jay"
  { yyVal = Operator.OpType.GreaterThan; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 280:
#line 2333 "cs-parser.jay"
  { yyVal = Operator.OpType.LessThan; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 281:
#line 2334 "cs-parser.jay"
  { yyVal = Operator.OpType.GreaterThanOrEqual; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 282:
#line 2335 "cs-parser.jay"
  { yyVal = Operator.OpType.LessThanOrEqual; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 283:
  case_283();
  break;
case 284:
#line 2349 "cs-parser.jay"
  {
		valid_param_mod = ParameterModifierType.DefaultValue;
	  }
  break;
case 285:
  case_285();
  break;
case 286:
#line 2372 "cs-parser.jay"
  {
		valid_param_mod = ParameterModifierType.DefaultValue;
	  }
  break;
case 287:
  case_287();
  break;
case 288:
  case_288();
  break;
case 289:
  case_289();
  break;
case 290:
  case_290();
  break;
case 291:
  case_291();
  break;
case 292:
  case_292();
  break;
case 293:
  case_293();
  break;
case 295:
#line 2496 "cs-parser.jay"
  { current_block = null; yyVal = null; }
  break;
case 298:
#line 2508 "cs-parser.jay"
  {
		++lexer.parsing_block;
	  }
  break;
case 299:
  case_299();
  break;
case 300:
#line 2518 "cs-parser.jay"
  {
		++lexer.parsing_block;
	  }
  break;
case 301:
  case_301();
  break;
case 302:
  case_302();
  break;
case 303:
  case_303();
  break;
case 304:
  case_304();
  break;
case 305:
  case_305();
  break;
case 306:
  case_306();
  break;
case 307:
  case_307();
  break;
case 308:
  case_308();
  break;
case 309:
  case_309();
  break;
case 310:
  case_310();
  break;
case 311:
  case_311();
  break;
case 313:
#line 2645 "cs-parser.jay"
  {
	  	++lexer.parsing_block;
	  }
  break;
case 314:
  case_314();
  break;
case 317:
#line 2663 "cs-parser.jay"
  {
		current_event_field.AddDeclarator ((FieldDeclarator) yyVals[0+yyTop]);
	  }
  break;
case 318:
#line 2667 "cs-parser.jay"
  {
		current_event_field.AddDeclarator ((FieldDeclarator) yyVals[0+yyTop]);
	  }
  break;
case 319:
  case_319();
  break;
case 320:
#line 2680 "cs-parser.jay"
  {
		++lexer.parsing_block;
	  }
  break;
case 321:
  case_321();
  break;
case 322:
  case_322();
  break;
case 323:
#line 2705 "cs-parser.jay"
  {
		yyVal = yyVals[0+yyTop];
	  }
  break;
case 326:
  case_326();
  break;
case 327:
  case_327();
  break;
case 328:
  case_328();
  break;
case 329:
  case_329();
  break;
case 330:
  case_330();
  break;
case 331:
  case_331();
  break;
case 332:
  case_332();
  break;
case 333:
  case_333();
  break;
case 335:
  case_335();
  break;
case 336:
  case_336();
  break;
case 337:
  case_337();
  break;
case 338:
  case_338();
  break;
case 339:
  case_339();
  break;
case 340:
  case_340();
  break;
case 342:
  case_342();
  break;
case 343:
  case_343();
  break;
case 346:
#line 2893 "cs-parser.jay"
  {
		lbag.AppendToMember (current_container, GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 348:
  case_348();
  break;
case 349:
  case_349();
  break;
case 350:
  case_350();
  break;
case 351:
  case_351();
  break;
case 352:
  case_352();
  break;
case 354:
#line 2967 "cs-parser.jay"
  {
		valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
	  }
  break;
case 355:
  case_355();
  break;
case 356:
#line 2986 "cs-parser.jay"
  {
		lexer.ConstraintsParsing = false;
	  }
  break;
case 357:
  case_357();
  break;
case 359:
  case_359();
  break;
case 361:
  case_361();
  break;
case 362:
  case_362();
  break;
case 364:
  case_364();
  break;
case 365:
  case_365();
  break;
case 366:
  case_366();
  break;
case 367:
  case_367();
  break;
case 369:
  case_369();
  break;
case 370:
  case_370();
  break;
case 371:
  case_371();
  break;
case 372:
  case_372();
  break;
case 373:
#line 3111 "cs-parser.jay"
  {
		lexer.parsing_generic_declaration = true;
	  }
  break;
case 374:
  case_374();
  break;
case 375:
  case_375();
  break;
case 377:
  case_377();
  break;
case 378:
  case_378();
  break;
case 379:
  case_379();
  break;
case 380:
  case_380();
  break;
case 381:
  case_381();
  break;
case 382:
  case_382();
  break;
case 384:
  case_384();
  break;
case 385:
  case_385();
  break;
case 386:
  case_386();
  break;
case 387:
  case_387();
  break;
case 388:
  case_388();
  break;
case 390:
#line 3236 "cs-parser.jay"
  {
		yyVal = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 391:
#line 3243 "cs-parser.jay"
  {
		lexer.parsing_generic_declaration = true;
	  }
  break;
case 397:
  case_397();
  break;
case 399:
#line 3273 "cs-parser.jay"
  {
		yyVal = new ComposedCast ((FullNamedExpression) yyVals[-1+yyTop], (ComposedTypeSpecifier) yyVals[0+yyTop]);
	  }
  break;
case 400:
  case_400();
  break;
case 401:
#line 3292 "cs-parser.jay"
  {
		yyVal = new ComposedCast ((ATypeNameExpression) yyVals[-1+yyTop], (ComposedTypeSpecifier) yyVals[0+yyTop]);
	  }
  break;
case 403:
  case_403();
  break;
case 404:
  case_404();
  break;
case 405:
#line 3313 "cs-parser.jay"
  {
		yyVal = new ComposedCast ((FullNamedExpression) yyVals[-1+yyTop], (ComposedTypeSpecifier) yyVals[0+yyTop]);
	  }
  break;
case 406:
#line 3317 "cs-parser.jay"
  {
		yyVal = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation (yyVals[-1+yyTop])), (ComposedTypeSpecifier) yyVals[0+yyTop]);
	  }
  break;
case 407:
  case_407();
  break;
case 408:
  case_408();
  break;
case 409:
  case_409();
  break;
case 410:
#line 3351 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation (yyVals[0+yyTop])); }
  break;
case 411:
#line 3352 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.String, GetLocation (yyVals[0+yyTop])); }
  break;
case 412:
#line 3353 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation (yyVals[0+yyTop])); }
  break;
case 413:
#line 3354 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation (yyVals[0+yyTop])); }
  break;
case 414:
#line 3355 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation (yyVals[0+yyTop])); }
  break;
case 415:
#line 3356 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation (yyVals[0+yyTop])); }
  break;
case 417:
#line 3361 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation (yyVals[0+yyTop])); }
  break;
case 418:
#line 3362 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation (yyVals[0+yyTop])); }
  break;
case 419:
#line 3363 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation (yyVals[0+yyTop])); }
  break;
case 420:
#line 3364 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation (yyVals[0+yyTop])); }
  break;
case 421:
#line 3365 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation (yyVals[0+yyTop])); }
  break;
case 422:
#line 3366 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation (yyVals[0+yyTop])); }
  break;
case 423:
#line 3367 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation (yyVals[0+yyTop])); }
  break;
case 424:
#line 3368 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation (yyVals[0+yyTop])); }
  break;
case 425:
#line 3369 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation (yyVals[0+yyTop])); }
  break;
case 448:
  case_448();
  break;
case 452:
#line 3413 "cs-parser.jay"
  { yyVal = new NullLiteral (GetLocation (yyVals[0+yyTop])); }
  break;
case 453:
#line 3417 "cs-parser.jay"
  { yyVal = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation (yyVals[0+yyTop])); }
  break;
case 454:
#line 3418 "cs-parser.jay"
  { yyVal = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation (yyVals[0+yyTop])); }
  break;
case 455:
#line 3425 "cs-parser.jay"
  {
		yyVal = new InterpolatedString ((StringLiteral) yyVals[-2+yyTop], (List<Expression>) yyVals[-1+yyTop], (StringLiteral) yyVals[0+yyTop]);
	  }
  break;
case 456:
#line 3429 "cs-parser.jay"
  {
		yyVal = new InterpolatedString ((StringLiteral) yyVals[0+yyTop], null, null);
	  }
  break;
case 457:
  case_457();
  break;
case 458:
  case_458();
  break;
case 459:
#line 3452 "cs-parser.jay"
  {
		yyVal = new InterpolatedStringInsert ((Expression) yyVals[0+yyTop]);
	  }
  break;
case 460:
  case_460();
  break;
case 461:
#line 3462 "cs-parser.jay"
  {
		lexer.parsing_interpolation_format = true;
	  }
  break;
case 462:
  case_462();
  break;
case 463:
#line 3474 "cs-parser.jay"
  {
		lexer.parsing_interpolation_format = true;
	  }
  break;
case 464:
  case_464();
  break;
case 469:
  case_469();
  break;
case 470:
#line 3516 "cs-parser.jay"
  {
		yyVal = new ParenthesizedExpression ((Expression) yyVals[-1+yyTop], GetLocation (yyVals[-2+yyTop]));
	  }
  break;
case 471:
  case_471();
  break;
case 472:
  case_472();
  break;
case 473:
  case_473();
  break;
case 474:
  case_474();
  break;
case 475:
  case_475();
  break;
case 476:
  case_476();
  break;
case 477:
  case_477();
  break;
case 478:
  case_478();
  break;
case 479:
#line 3577 "cs-parser.jay"
  {
		yyVal = new CompletionMemberAccess ((Expression) yyVals[-2+yyTop], null,GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 480:
  case_480();
  break;
case 481:
#line 3585 "cs-parser.jay"
  {
		yyVal = new CompletionMemberAccess ((Expression) yyVals[-2+yyTop], null, lexer.Location);
	  }
  break;
case 482:
  case_482();
  break;
case 483:
  case_483();
  break;
case 484:
  case_484();
  break;
case 485:
  case_485();
  break;
case 486:
#line 3615 "cs-parser.jay"
  { yyVal = null; }
  break;
case 488:
  case_488();
  break;
case 489:
  case_489();
  break;
case 490:
#line 3637 "cs-parser.jay"
  { yyVal = null; }
  break;
case 491:
#line 3641 "cs-parser.jay"
  {
		yyVal = yyVals[0+yyTop];
	}
  break;
case 492:
  case_492();
  break;
case 493:
  case_493();
  break;
case 494:
  case_494();
  break;
case 495:
  case_495();
  break;
case 496:
  case_496();
  break;
case 497:
#line 3680 "cs-parser.jay"
  {
		yyVal = new CompletionElementInitializer (null, GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 498:
  case_498();
  break;
case 499:
  case_499();
  break;
case 500:
  case_500();
  break;
case 501:
  case_501();
  break;
case 504:
#line 3720 "cs-parser.jay"
  { yyVal = null; }
  break;
case 506:
  case_506();
  break;
case 507:
  case_507();
  break;
case 508:
  case_508();
  break;
case 509:
  case_509();
  break;
case 510:
  case_510();
  break;
case 511:
#line 3774 "cs-parser.jay"
  {
		yyVal = new Argument ((Expression) yyVals[0+yyTop]);
	  }
  break;
case 515:
  case_515();
  break;
case 516:
#line 3792 "cs-parser.jay"
  {
		yyVal = new Argument ((Expression) yyVals[0+yyTop], Argument.AType.Ref);
	  }
  break;
case 517:
  case_517();
  break;
case 518:
#line 3801 "cs-parser.jay"
  {
		yyVal = new Argument ((Expression) yyVals[0+yyTop], Argument.AType.Out);
	  }
  break;
case 519:
  case_519();
  break;
case 520:
  case_520();
  break;
case 521:
  case_521();
  break;
case 522:
  case_522();
  break;
case 523:
  case_523();
  break;
case 525:
  case_525();
  break;
case 526:
  case_526();
  break;
case 527:
  case_527();
  break;
case 528:
  case_528();
  break;
case 529:
  case_529();
  break;
case 530:
  case_530();
  break;
case 531:
  case_531();
  break;
case 532:
  case_532();
  break;
case 533:
#line 3928 "cs-parser.jay"
  {
	  	yyVal = new Argument ((Expression) yyVals[0+yyTop]);
	  }
  break;
case 535:
#line 3936 "cs-parser.jay"
  {
		yyVal = new This (GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 536:
  case_536();
  break;
case 537:
  case_537();
  break;
case 538:
#line 3956 "cs-parser.jay"
  {
		yyVal = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) yyVals[-1+yyTop], GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 539:
#line 3963 "cs-parser.jay"
  {
		yyVal = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) yyVals[-1+yyTop], GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 540:
  case_540();
  break;
case 541:
  case_541();
  break;
case 542:
  case_542();
  break;
case 543:
  case_543();
  break;
case 544:
  case_544();
  break;
case 545:
  case_545();
  break;
case 546:
  case_546();
  break;
case 547:
#line 4030 "cs-parser.jay"
  {
		++lexer.parsing_type;
	  }
  break;
case 548:
  case_548();
  break;
case 549:
  case_549();
  break;
case 550:
#line 4052 "cs-parser.jay"
  {
		yyVal = new EmptyCompletion ();
	  }
  break;
case 553:
#line 4061 "cs-parser.jay"
  { yyVal = null; }
  break;
case 555:
  case_555();
  break;
case 556:
  case_556();
  break;
case 557:
#line 4083 "cs-parser.jay"
  {
		yyVal = new EmptyCompletion ();
	  }
  break;
case 558:
#line 4087 "cs-parser.jay"
  {
	  	yyVal = yyVals[-1+yyTop];
	  }
  break;
case 559:
  case_559();
  break;
case 560:
  case_560();
  break;
case 561:
  case_561();
  break;
case 562:
  case_562();
  break;
case 566:
  case_566();
  break;
case 567:
  case_567();
  break;
case 568:
  case_568();
  break;
case 569:
#line 4147 "cs-parser.jay"
  {
		yyVal = 2;
	  }
  break;
case 570:
#line 4151 "cs-parser.jay"
  {
		yyVal = ((int) yyVals[-1+yyTop]) + 1;
	  }
  break;
case 571:
#line 4158 "cs-parser.jay"
  {
		yyVal = null;
	  }
  break;
case 572:
#line 4162 "cs-parser.jay"
  {
		yyVal = yyVals[0+yyTop];
	  }
  break;
case 573:
  case_573();
  break;
case 574:
  case_574();
  break;
case 575:
  case_575();
  break;
case 576:
  case_576();
  break;
case 577:
  case_577();
  break;
case 579:
  case_579();
  break;
case 580:
  case_580();
  break;
case 581:
  case_581();
  break;
case 582:
  case_582();
  break;
case 583:
  case_583();
  break;
case 584:
  case_584();
  break;
case 585:
  case_585();
  break;
case 586:
  case_586();
  break;
case 587:
  case_587();
  break;
case 588:
  case_588();
  break;
case 589:
#line 4295 "cs-parser.jay"
  {
		start_anonymous (false, (ParametersCompiled) yyVals[0+yyTop], false, GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 590:
  case_590();
  break;
case 591:
#line 4308 "cs-parser.jay"
  {
		start_anonymous (false, (ParametersCompiled) yyVals[0+yyTop], true, GetLocation (yyVals[-2+yyTop]));
	  }
  break;
case 592:
  case_592();
  break;
case 593:
#line 4325 "cs-parser.jay"
  {
		yyVal = ParametersCompiled.Undefined;
	  }
  break;
case 595:
#line 4333 "cs-parser.jay"
  {
	  	valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
	  }
  break;
case 596:
  case_596();
  break;
case 597:
  case_597();
  break;
case 599:
#line 4359 "cs-parser.jay"
  {
		yyVal = new Unary (Unary.Operator.LogicalNot, (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 600:
#line 4363 "cs-parser.jay"
  {
		yyVal = new Unary (Unary.Operator.OnesComplement, (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 601:
  case_601();
  break;
case 602:
  case_602();
  break;
case 603:
  case_603();
  break;
case 604:
  case_604();
  break;
case 605:
  case_605();
  break;
case 606:
  case_606();
  break;
case 608:
#line 4427 "cs-parser.jay"
  { 
	  	yyVal = new Unary (Unary.Operator.UnaryPlus, (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 609:
#line 4431 "cs-parser.jay"
  { 
		yyVal = new Unary (Unary.Operator.UnaryNegation, (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 610:
#line 4435 "cs-parser.jay"
  {
		yyVal = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 611:
#line 4439 "cs-parser.jay"
  {
		yyVal = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 612:
#line 4443 "cs-parser.jay"
  {
		yyVal = new Indirection ((Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 613:
#line 4447 "cs-parser.jay"
  {
		yyVal = new Unary (Unary.Operator.AddressOf, (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 614:
  case_614();
  break;
case 615:
  case_615();
  break;
case 616:
  case_616();
  break;
case 617:
  case_617();
  break;
case 618:
  case_618();
  break;
case 619:
  case_619();
  break;
case 621:
  case_621();
  break;
case 622:
  case_622();
  break;
case 623:
  case_623();
  break;
case 624:
  case_624();
  break;
case 625:
  case_625();
  break;
case 626:
  case_626();
  break;
case 628:
  case_628();
  break;
case 629:
  case_629();
  break;
case 630:
  case_630();
  break;
case 631:
  case_631();
  break;
case 632:
#line 4555 "cs-parser.jay"
  {
		yyVal = new As ((Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 633:
  case_633();
  break;
case 634:
  case_634();
  break;
case 635:
  case_635();
  break;
case 636:
  case_636();
  break;
case 637:
  case_637();
  break;
case 638:
  case_638();
  break;
case 641:
#line 4611 "cs-parser.jay"
  {
		yyVal = new Unary (Unary.Operator.UnaryPlus, (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 642:
#line 4615 "cs-parser.jay"
  {
		yyVal = new Unary (Unary.Operator.UnaryNegation, (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 645:
  case_645();
  break;
case 646:
#line 4626 "cs-parser.jay"
  {
		yyVal = new WildcardPattern (GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 649:
#line 4635 "cs-parser.jay"
  {
		yyVal = new RecursivePattern ((ATypeNameExpression) yyVals[-3+yyTop], (Arguments) yyVals[-1+yyTop], GetLocation (yyVals[-2+yyTop]));
	  }
  break;
case 650:
#line 4642 "cs-parser.jay"
  {
		yyVal = new PropertyPattern ((ATypeNameExpression) yyVals[-3+yyTop], (List<PropertyPatternMember>) yyVals[-1+yyTop], GetLocation (yyVals[-2+yyTop]));
	  }
  break;
case 651:
  case_651();
  break;
case 652:
  case_652();
  break;
case 653:
  case_653();
  break;
case 655:
  case_655();
  break;
case 656:
#line 4684 "cs-parser.jay"
  {
		yyVal = new Arguments (0);
	  }
  break;
case 658:
  case_658();
  break;
case 659:
  case_659();
  break;
case 660:
#line 4710 "cs-parser.jay"
  {
		yyVal = new Argument ((Expression) yyVals[0+yyTop]);
	  }
  break;
case 661:
  case_661();
  break;
case 663:
  case_663();
  break;
case 664:
  case_664();
  break;
case 665:
  case_665();
  break;
case 666:
  case_666();
  break;
case 668:
  case_668();
  break;
case 669:
  case_669();
  break;
case 670:
  case_670();
  break;
case 671:
  case_671();
  break;
case 672:
  case_672();
  break;
case 673:
  case_673();
  break;
case 674:
  case_674();
  break;
case 675:
  case_675();
  break;
case 677:
  case_677();
  break;
case 678:
  case_678();
  break;
case 679:
  case_679();
  break;
case 680:
  case_680();
  break;
case 682:
  case_682();
  break;
case 683:
  case_683();
  break;
case 685:
  case_685();
  break;
case 686:
  case_686();
  break;
case 688:
  case_688();
  break;
case 689:
  case_689();
  break;
case 691:
  case_691();
  break;
case 692:
  case_692();
  break;
case 694:
  case_694();
  break;
case 695:
  case_695();
  break;
case 697:
  case_697();
  break;
case 699:
  case_699();
  break;
case 700:
  case_700();
  break;
case 701:
  case_701();
  break;
case 702:
  case_702();
  break;
case 703:
  case_703();
  break;
case 704:
  case_704();
  break;
case 705:
  case_705();
  break;
case 706:
  case_706();
  break;
case 707:
  case_707();
  break;
case 708:
  case_708();
  break;
case 709:
  case_709();
  break;
case 710:
  case_710();
  break;
case 711:
  case_711();
  break;
case 712:
  case_712();
  break;
case 713:
  case_713();
  break;
case 714:
  case_714();
  break;
case 715:
  case_715();
  break;
case 716:
  case_716();
  break;
case 717:
  case_717();
  break;
case 718:
  case_718();
  break;
case 719:
  case_719();
  break;
case 720:
#line 5055 "cs-parser.jay"
  { yyVal = ParametersCompiled.EmptyReadOnlyParameters; }
  break;
case 721:
  case_721();
  break;
case 722:
#line 5066 "cs-parser.jay"
  {
		start_block (Location.Null);
	  }
  break;
case 723:
  case_723();
  break;
case 725:
  case_725();
  break;
case 727:
  case_727();
  break;
case 728:
  case_728();
  break;
case 729:
  case_729();
  break;
case 730:
  case_730();
  break;
case 731:
  case_731();
  break;
case 732:
  case_732();
  break;
case 733:
  case_733();
  break;
case 734:
#line 5133 "cs-parser.jay"
  {
	  	valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
	  }
  break;
case 735:
  case_735();
  break;
case 736:
  case_736();
  break;
case 737:
#line 5147 "cs-parser.jay"
  {
	  	valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;	  
	  }
  break;
case 738:
  case_738();
  break;
case 739:
  case_739();
  break;
case 745:
#line 5172 "cs-parser.jay"
  {
		yyVal = new ArglistAccess (GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 746:
  case_746();
  break;
case 747:
  case_747();
  break;
case 748:
  case_748();
  break;
case 750:
#line 5201 "cs-parser.jay"
  {
		yyVal = new BooleanExpression ((Expression) yyVals[0+yyTop]);
	  }
  break;
case 751:
#line 5208 "cs-parser.jay"
  {
	  	yyVal = null;
	  }
  break;
case 753:
  case_753();
  break;
case 754:
#line 5229 "cs-parser.jay"
  {
	  	yyVal = null;
	  }
  break;
case 755:
#line 5233 "cs-parser.jay"
  {
		yyVal = null;
	  }
  break;
case 756:
#line 5237 "cs-parser.jay"
  {
		yyVal = yyVals[0+yyTop];
	  }
  break;
case 757:
#line 5241 "cs-parser.jay"
  {
		yyVal = yyVals[-1+yyTop];
	  }
  break;
case 758:
  case_758();
  break;
case 759:
  case_759();
  break;
case 760:
#line 5266 "cs-parser.jay"
  {
	  }
  break;
case 761:
  case_761();
  break;
case 762:
  case_762();
  break;
case 763:
  case_763();
  break;
case 764:
  case_764();
  break;
case 765:
#line 5318 "cs-parser.jay"
  { yyVal = null; }
  break;
case 766:
#line 5320 "cs-parser.jay"
  { yyVal = yyVals[0+yyTop]; StoreModifierLocation (Modifiers.PARTIAL, GetLocation (yyVals[0+yyTop])); }
  break;
case 767:
  case_767();
  break;
case 768:
#line 5333 "cs-parser.jay"
  {
		lexer.parsing_modifiers = false;		
	  }
  break;
case 770:
  case_770();
  break;
case 771:
  case_771();
  break;
case 772:
  case_772();
  break;
case 773:
  case_773();
  break;
case 774:
  case_774();
  break;
case 775:
  case_775();
  break;
case 776:
  case_776();
  break;
case 777:
  case_777();
  break;
case 778:
  case_778();
  break;
case 779:
  case_779();
  break;
case 780:
  case_780();
  break;
case 781:
  case_781();
  break;
case 782:
  case_782();
  break;
case 783:
  case_783();
  break;
case 784:
  case_784();
  break;
case 785:
  case_785();
  break;
case 788:
  case_788();
  break;
case 789:
  case_789();
  break;
case 791:
#line 5463 "cs-parser.jay"
  {
		yyVal = yyVals[0+yyTop];
	  }
  break;
case 792:
  case_792();
  break;
case 793:
  case_793();
  break;
case 794:
  case_794();
  break;
case 795:
  case_795();
  break;
case 796:
  case_796();
  break;
case 797:
  case_797();
  break;
case 798:
  case_798();
  break;
case 799:
  case_799();
  break;
case 800:
#line 5556 "cs-parser.jay"
  {
		yyVal = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 801:
#line 5560 "cs-parser.jay"
  {
		yyVal = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 802:
#line 5567 "cs-parser.jay"
  {
		yyVal = null;
	  }
  break;
case 803:
  case_803();
  break;
case 804:
  case_804();
  break;
case 805:
  case_805();
  break;
case 806:
  case_806();
  break;
case 807:
#line 5612 "cs-parser.jay"
  {
		yyVal = yyVals[0+yyTop];
	  }
  break;
case 808:
  case_808();
  break;
case 809:
  case_809();
  break;
case 810:
  case_810();
  break;
case 811:
  case_811();
  break;
case 812:
  case_812();
  break;
case 813:
  case_813();
  break;
case 814:
  case_814();
  break;
case 819:
#line 5674 "cs-parser.jay"
  {
		current_block.AddStatement ((Statement) yyVals[0+yyTop]);
	  }
  break;
case 820:
#line 5678 "cs-parser.jay"
  {
		current_block.AddStatement ((Statement) yyVals[0+yyTop]);
	  }
  break;
case 822:
  case_822();
  break;
case 823:
  case_823();
  break;
case 826:
#line 5712 "cs-parser.jay"
  {
		current_block.AddStatement ((Statement) yyVals[0+yyTop]);
	  }
  break;
case 827:
#line 5716 "cs-parser.jay"
  {
		current_block.AddStatement ((Statement) yyVals[0+yyTop]);
	  }
  break;
case 856:
  case_856();
  break;
case 857:
  case_857();
  break;
case 858:
  case_858();
  break;
case 859:
  case_859();
  break;
case 860:
  case_860();
  break;
case 863:
  case_863();
  break;
case 864:
  case_864();
  break;
case 865:
  case_865();
  break;
case 869:
  case_869();
  break;
case 870:
#line 5857 "cs-parser.jay"
  {
		yyVal = ComposedTypeSpecifier.CreatePointer (GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 872:
#line 5865 "cs-parser.jay"
  {
	  	yyVal = Error_AwaitAsIdentifier (yyVals[0+yyTop]);
	  }
  break;
case 873:
  case_873();
  break;
case 874:
  case_874();
  break;
case 875:
  case_875();
  break;
case 876:
  case_876();
  break;
case 878:
  case_878();
  break;
case 880:
  case_880();
  break;
case 881:
  case_881();
  break;
case 885:
  case_885();
  break;
case 888:
  case_888();
  break;
case 889:
  case_889();
  break;
case 890:
#line 5979 "cs-parser.jay"
  {
		report.Error (145, lexer.Location, "A const field requires a value to be provided");
	  }
  break;
case 891:
  case_891();
  break;
case 896:
  case_896();
  break;
case 898:
  case_898();
  break;
case 899:
  case_899();
  break;
case 900:
  case_900();
  break;
case 901:
#line 6029 "cs-parser.jay"
  { yyVal = yyVals[-1+yyTop]; }
  break;
case 902:
  case_902();
  break;
case 903:
#line 6039 "cs-parser.jay"
  { yyVal = yyVals[-1+yyTop]; }
  break;
case 904:
#line 6040 "cs-parser.jay"
  { yyVal = yyVals[-1+yyTop]; }
  break;
case 905:
  case_905();
  break;
case 906:
  case_906();
  break;
case 907:
  case_907();
  break;
case 910:
  case_910();
  break;
case 911:
  case_911();
  break;
case 912:
  case_912();
  break;
case 913:
#line 6112 "cs-parser.jay"
  {
		start_block (GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 914:
  case_914();
  break;
case 915:
  case_915();
  break;
case 916:
#line 6132 "cs-parser.jay"
  {
		report.Warning (1522, 1, current_block.StartLocation, "Empty switch block"); 
	  }
  break;
case 920:
#line 6142 "cs-parser.jay"
  {
		Error_SyntaxError (yyToken);
	  }
  break;
case 922:
  case_922();
  break;
case 923:
#line 6159 "cs-parser.jay"
  {
		current_block.AddStatement ((Statement) yyVals[0+yyTop]);
	  }
  break;
case 924:
  case_924();
  break;
case 925:
  case_925();
  break;
case 926:
#line 6188 "cs-parser.jay"
  {
		yyVal = new SwitchLabel (null, GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 931:
  case_931();
  break;
case 932:
  case_932();
  break;
case 933:
  case_933();
  break;
case 934:
  case_934();
  break;
case 935:
  case_935();
  break;
case 936:
  case_936();
  break;
case 937:
#line 6249 "cs-parser.jay"
  {
		yyVal = yyVals[0+yyTop];
	  }
  break;
case 938:
  case_938();
  break;
case 939:
#line 6264 "cs-parser.jay"
  {
		yyVal = yyVals[0+yyTop];
	  }
  break;
case 940:
  case_940();
  break;
case 941:
  case_941();
  break;
case 942:
#line 6285 "cs-parser.jay"
  {
		yyVal = yyVals[0+yyTop];
	  }
  break;
case 943:
  case_943();
  break;
case 944:
  case_944();
  break;
case 945:
  case_945();
  break;
case 946:
#line 6319 "cs-parser.jay"
  { yyVal = new EmptyStatement (lexer.Location); }
  break;
case 948:
  case_948();
  break;
case 949:
  case_949();
  break;
case 951:
#line 6343 "cs-parser.jay"
  { yyVal = null; }
  break;
case 953:
#line 6348 "cs-parser.jay"
  { yyVal = new EmptyStatement (lexer.Location); }
  break;
case 957:
  case_957();
  break;
case 958:
  case_958();
  break;
case 959:
  case_959();
  break;
case 960:
  case_960();
  break;
case 961:
  case_961();
  break;
case 962:
  case_962();
  break;
case 963:
  case_963();
  break;
case 970:
  case_970();
  break;
case 971:
  case_971();
  break;
case 972:
  case_972();
  break;
case 973:
  case_973();
  break;
case 974:
  case_974();
  break;
case 975:
  case_975();
  break;
case 976:
  case_976();
  break;
case 977:
  case_977();
  break;
case 978:
  case_978();
  break;
case 979:
  case_979();
  break;
case 980:
  case_980();
  break;
case 981:
  case_981();
  break;
case 982:
  case_982();
  break;
case 983:
  case_983();
  break;
case 984:
  case_984();
  break;
case 987:
#line 6594 "cs-parser.jay"
  {
		yyVal = new TryCatch ((Block) yyVals[-1+yyTop], (List<Catch>) yyVals[0+yyTop], GetLocation (yyVals[-2+yyTop]), false);
	  }
  break;
case 988:
  case_988();
  break;
case 989:
  case_989();
  break;
case 990:
  case_990();
  break;
case 991:
  case_991();
  break;
case 992:
  case_992();
  break;
case 995:
  case_995();
  break;
case 996:
  case_996();
  break;
case 997:
  case_997();
  break;
case 998:
  case_998();
  break;
case 999:
#line 6685 "cs-parser.jay"
  {
		yyVal = yyVals[-1+yyTop];
	  }
  break;
case 1000:
  case_1000();
  break;
case 1001:
#line 6697 "cs-parser.jay"
  {
		lexer.parsing_catch_when = false;
	  }
  break;
case 1002:
#line 6701 "cs-parser.jay"
  {
		lexer.parsing_catch_when = false;
	  }
  break;
case 1003:
  case_1003();
  break;
case 1004:
#line 6716 "cs-parser.jay"
  {
		yyVal = new Checked ((Block) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 1005:
#line 6723 "cs-parser.jay"
  {
		yyVal = new Unchecked ((Block) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 1006:
  case_1006();
  break;
case 1007:
#line 6733 "cs-parser.jay"
  {
		yyVal = new Unsafe ((Block) yyVals[0+yyTop], GetLocation (yyVals[-2+yyTop]));
	  }
  break;
case 1008:
  case_1008();
  break;
case 1009:
  case_1009();
  break;
case 1010:
  case_1010();
  break;
case 1011:
  case_1011();
  break;
case 1012:
  case_1012();
  break;
case 1013:
  case_1013();
  break;
case 1014:
  case_1014();
  break;
case 1015:
  case_1015();
  break;
case 1016:
  case_1016();
  break;
case 1017:
  case_1017();
  break;
case 1019:
  case_1019();
  break;
case 1020:
#line 6838 "cs-parser.jay"
  {
		Error_MissingInitializer (lexer.Location);
	  }
  break;
case 1021:
  case_1021();
  break;
case 1022:
  case_1022();
  break;
case 1023:
  case_1023();
  break;
case 1024:
  case_1024();
  break;
case 1025:
  case_1025();
  break;
case 1026:
  case_1026();
  break;
case 1027:
  case_1027();
  break;
case 1028:
  case_1028();
  break;
case 1029:
  case_1029();
  break;
case 1030:
#line 6943 "cs-parser.jay"
  {
		current_block = new Linq.QueryBlock (current_block, lexer.Location);
	  }
  break;
case 1031:
  case_1031();
  break;
case 1032:
#line 6958 "cs-parser.jay"
  {
		current_block = new Linq.QueryBlock (current_block, lexer.Location);
	  }
  break;
case 1033:
  case_1033();
  break;
case 1034:
  case_1034();
  break;
case 1035:
  case_1035();
  break;
case 1037:
  case_1037();
  break;
case 1038:
  case_1038();
  break;
case 1039:
#line 7022 "cs-parser.jay"
  {
	  	current_block = new Linq.QueryBlock (current_block, lexer.Location);
	  }
  break;
case 1040:
  case_1040();
  break;
case 1041:
  case_1041();
  break;
case 1042:
  case_1042();
  break;
case 1043:
  case_1043();
  break;
case 1044:
#line 7061 "cs-parser.jay"
  {
	  	yyVal = new object[] { yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]) };
	  }
  break;
case 1045:
  case_1045();
  break;
case 1047:
  case_1047();
  break;
case 1053:
#line 7090 "cs-parser.jay"
  {
	  	current_block = new Linq.QueryBlock (current_block, lexer.Location);
	  }
  break;
case 1054:
  case_1054();
  break;
case 1055:
#line 7109 "cs-parser.jay"
  {
	  	current_block = new Linq.QueryBlock (current_block, lexer.Location);
	  }
  break;
case 1056:
  case_1056();
  break;
case 1057:
  case_1057();
  break;
case 1058:
  case_1058();
  break;
case 1059:
  case_1059();
  break;
case 1060:
  case_1060();
  break;
case 1061:
  case_1061();
  break;
case 1062:
  case_1062();
  break;
case 1063:
  case_1063();
  break;
case 1064:
  case_1064();
  break;
case 1066:
  case_1066();
  break;
case 1067:
  case_1067();
  break;
case 1068:
  case_1068();
  break;
case 1070:
  case_1070();
  break;
case 1071:
  case_1071();
  break;
case 1073:
  case_1073();
  break;
case 1074:
  case_1074();
  break;
case 1075:
#line 7310 "cs-parser.jay"
  {
		yyVal = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)yyVals[0+yyTop]);	
	  }
  break;
case 1076:
  case_1076();
  break;
case 1077:
  case_1077();
  break;
case 1078:
#line 7327 "cs-parser.jay"
  {
		yyVal = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)yyVals[0+yyTop]);	
	  }
  break;
case 1079:
  case_1079();
  break;
case 1080:
  case_1080();
  break;
case 1082:
  case_1082();
  break;
case 1083:
  case_1083();
  break;
case 1086:
  case_1086();
  break;
case 1087:
  case_1087();
  break;
case 1095:
#line 7452 "cs-parser.jay"
  {
		module.DocumentationBuilder.ParsedName = (MemberName) yyVals[0+yyTop];
	  }
  break;
case 1096:
#line 7459 "cs-parser.jay"
  {
		module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)yyVals[0+yyTop];
	  }
  break;
case 1097:
  case_1097();
  break;
case 1098:
  case_1098();
  break;
case 1099:
  case_1099();
  break;
case 1100:
#line 7482 "cs-parser.jay"
  {
		yyVal = new MemberName ((MemberName) yyVals[-2+yyTop], MemberCache.IndexerNameAlias, Location.Null);
	  }
  break;
case 1101:
#line 7486 "cs-parser.jay"
  {
		valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
	  }
  break;
case 1102:
  case_1102();
  break;
case 1103:
  case_1103();
  break;
case 1104:
  case_1104();
  break;
case 1105:
  case_1105();
  break;
case 1107:
#line 7522 "cs-parser.jay"
  {
		yyVal = new MemberName (((MemberName) yyVals[-2+yyTop]), (MemberName) yyVals[0+yyTop]);
	  }
  break;
case 1109:
#line 7530 "cs-parser.jay"
  {
		valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
	  }
  break;
case 1110:
#line 7534 "cs-parser.jay"
  {
		yyVal = yyVals[-1+yyTop];
	  }
  break;
case 1111:
#line 7541 "cs-parser.jay"
  {
		yyVal = new List<DocumentationParameter> (0);
	  }
  break;
case 1113:
  case_1113();
  break;
case 1114:
  case_1114();
  break;
case 1115:
  case_1115();
  break;
#line default
        }
        yyTop -= yyLen[yyN];
        yyState = yyStates[yyTop];
        int yyM = yyLhs[yyN];
        if (yyState == 0 && yyM == 0) {
//t          if (debug != null) debug.shift(0, yyFinal);
          yyState = yyFinal;
          if (yyToken < 0) {
            yyToken = yyLex.advance() ? yyLex.token() : 0;
//t            if (debug != null)
//t               debug.lex(yyState, yyToken,yyname(yyToken), yyLex.value());
          }
          if (yyToken == 0) {
//t            if (debug != null) debug.accept(yyVal);
            return yyVal;
          }
          goto continue_yyLoop;
        }
        if (((yyN = yyGindex[yyM]) != 0) && ((yyN += yyState) >= 0)
            && (yyN < yyTable.Length) && (yyCheck[yyN] == yyState))
          yyState = yyTable[yyN];
        else
          yyState = yyDgoto[yyM];
//t        if (debug != null) debug.shift(yyStates[yyTop], yyState);
	 goto continue_yyLoop;
      continue_yyDiscarded: ;	// implements the named-loop continue: 'continue yyDiscarded'
      }
    continue_yyLoop: ;		// implements the named-loop continue: 'continue yyLoop'
    }
  }
예제 #17
0
        /// <summary>
        /// The main processing loop of the command.
        /// </summary>
        ///
        protected override void ProcessRecord()
        {
            // First get the alias table (from the proper scope if necessary)
            IDictionary <string, AliasInfo> aliasTable = null;

            if (!String.IsNullOrEmpty(Scope))
            {
                // This can throw PSArgumentException and PSArgumentOutOfRangeException
                // but just let them go as this is terminal for the pipeline and the
                // exceptions are already properly adorned with an ErrorRecord.

                aliasTable = SessionState.Internal.GetAliasTableAtScope(Scope);
            }
            else
            {
                aliasTable = SessionState.Internal.GetAliasTable();
            }

            foreach (string aliasName in _names)
            {
                bool resultFound = false;

                // Create the name pattern

                WildcardPattern namePattern =
                    WildcardPattern.Get(
                        aliasName,
                        WildcardOptions.IgnoreCase);

                // Now loop through the table and write out any aliases that
                // match the name and don't match the exclude filters and are
                // visible to the caller...
                CommandOrigin origin = MyInvocation.CommandOrigin;
                foreach (KeyValuePair <string, AliasInfo> tableEntry in aliasTable)
                {
                    if (!namePattern.IsMatch(tableEntry.Key))
                    {
                        continue;
                    }

                    if (SessionState.IsVisible(origin, tableEntry.Value))
                    {
                        resultFound = true;
                        _matchingAliases.Add(tableEntry.Value);
                    }
                }

                if (!resultFound &&
                    !WildcardPattern.ContainsWildcardCharacters(aliasName))
                {
                    // Need to write an error if the user tries to get an alias
                    // that doesn't exist and they are not globbing.

                    ItemNotFoundException itemNotFound =
                        new ItemNotFoundException(
                            aliasName,
                            "AliasNotFound",
                            SessionStateStrings.AliasNotFound);

                    WriteError(
                        new ErrorRecord(
                            itemNotFound.ErrorRecord,
                            itemNotFound));
                }
            }
        }
예제 #18
0
        /// <summary>
        /// Searches a list of jobs with a given set of filters for all
        /// the V2 search parameters. This function searches in a specific
        /// order so that a get call from an API returns without having
        /// to do much processing in terms of wildcard pattern matching
        /// </summary>
        /// <param name="jobsToSearch">incoming enumeration of jobs to
        /// search</param>
        /// <param name="filter">dictionary of filters to use as search
        /// criteria</param>
        /// <returns>narrowed down list of jobs that satisfy the filter
        /// criteria</returns>
        internal static List <Job2> SearchJobsOnV2Parameters(IEnumerable <Job2> jobsToSearch, IDictionary <string, object> filter)
        {
            List <Job2> searchList = new List <Job2>();

            searchList.AddRange(jobsToSearch);

            List <Job2> newlist;

            if (filter.ContainsKey(Constants.JobMetadataSessionId))
            {
                int searchId = (int)filter[Constants.JobMetadataSessionId];
                newlist = searchList.Where(job => job.Id == searchId).ToList();
                searchList.Clear();
                searchList = newlist;
            }
            if (filter.ContainsKey(Constants.JobMetadataInstanceId))
            {
                var  value = filter[Constants.JobMetadataInstanceId];
                Guid searchGuid;
                LanguagePrimitives.TryConvertTo(value, CultureInfo.InvariantCulture, out searchGuid);
                newlist = searchList.Where(job => job.InstanceId == searchGuid).ToList();
                searchList.Clear();
                searchList = newlist;
            }
            if (filter.ContainsKey(Constants.JobMetadataFilterState))
            {
                JobState searchState =
                    (JobState)
                    LanguagePrimitives.ConvertTo(filter[Constants.JobMetadataFilterState], typeof(JobState), CultureInfo.InvariantCulture);
                newlist = searchList.Where(job => job.JobStateInfo.State == searchState).ToList();
                searchList.Clear();
                searchList = newlist;
            }
            if (filter.ContainsKey(Constants.JobMetadataName))
            {
                Debug.Assert(filter[Constants.JobMetadataName] is string ||
                             filter[Constants.JobMetadataName] is WildcardPattern, "filter value should be a string or wildcard");

                WildcardPattern patternForName;
                if (filter[Constants.JobMetadataName] is string)
                {
                    string name = (string)filter[Constants.JobMetadataName];
                    patternForName = new WildcardPattern(name, WildcardOptions.IgnoreCase | WildcardOptions.Compiled);
                }
                else
                {
                    patternForName = (WildcardPattern)filter[Constants.JobMetadataName];
                }

                newlist =
                    searchList.Where(parentJob => patternForName.IsMatch(parentJob.Name)).ToList();
                searchList.Clear();
                searchList = newlist;
            }
            if (filter.ContainsKey(Constants.JobMetadataCommand))
            {
                Debug.Assert(filter[Constants.JobMetadataCommand] is string ||
                             filter[Constants.JobMetadataCommand] is WildcardPattern, "filter value should be a string or wildcard");

                WildcardPattern patternForCommand;
                if (filter[Constants.JobMetadataCommand] is string)
                {
                    string command = (string)filter[Constants.JobMetadataCommand];
                    patternForCommand = new WildcardPattern(command, WildcardOptions.IgnoreCase | WildcardOptions.Compiled);
                }
                else
                {
                    patternForCommand = (WildcardPattern)filter[Constants.JobMetadataCommand];
                }

                newlist =
                    searchList.Where(parentJob => patternForCommand.IsMatch(parentJob.Command)).ToList();
                searchList.Clear();
                searchList = newlist;
            }
            return(searchList);
        }
예제 #19
0
        /// <summary>
        /// Gets the matching PSTraceSource instances for the
        /// specified patterns.
        /// </summary>
        ///
        /// <param name="patternsToMatch">
        /// The patterns used to match the PSTraceSource name.
        /// </param>
        ///
        /// <param name="writeErrorIfMatchNotFound">
        /// If true and the pattern does not contain wildcard patterns and no
        /// match is found, then WriteError will be called.
        /// </param>
        ///
        /// <param name="notMatched">
        /// The patterns for which a match was not found.
        /// </param>
        ///
        /// <returns>
        /// A collection of the matching PSTraceSource instances.
        /// </returns>
        ///
        internal Collection <PSTraceSource> GetMatchingTraceSource(
            string[] patternsToMatch,
            bool writeErrorIfMatchNotFound,
            out Collection <string> notMatched)
        {
            notMatched = new Collection <string>();

            Collection <PSTraceSource> results = new Collection <PSTraceSource>();

            foreach (string patternToMatch in patternsToMatch)
            {
                bool matchFound = false;

                if (String.IsNullOrEmpty(patternToMatch))
                {
                    notMatched.Add(patternToMatch);
                    continue;
                }

                WildcardPattern pattern =
                    WildcardPattern.Get(
                        patternToMatch,
                        WildcardOptions.IgnoreCase);

                Dictionary <String, PSTraceSource> traceCatalog = PSTraceSource.TraceCatalog;

                foreach (PSTraceSource source in traceCatalog.Values)
                {
                    // Try matching by full name

                    if (pattern.IsMatch(source.FullName))
                    {
                        matchFound = true;
                        results.Add(source);
                    }
                    // Try matching by the short name.
                    else if (pattern.IsMatch(source.Name))
                    {
                        matchFound = true;
                        results.Add(source);
                    }
                }

                if (!matchFound)
                {
                    notMatched.Add(patternToMatch);

                    // Only write an error if no match was found, the pattern doesn't
                    // contain wildcard characters, and caller wants us to.

                    if (writeErrorIfMatchNotFound &&
                        !WildcardPattern.ContainsWildcardCharacters(patternToMatch))
                    {
                        ItemNotFoundException itemNotFound =
                            new ItemNotFoundException(
                                patternToMatch,
                                "TraceSourceNotFound",
                                SessionStateStrings.TraceSourceNotFound);

                        ErrorRecord errorRecord = new ErrorRecord(itemNotFound.ErrorRecord, itemNotFound);
                        WriteError(errorRecord);
                    }
                }
            }

            return(results);
        }
예제 #20
0
        //
        // ProcessListSet().
        // Does the work to process ListSet parameter set.
        //
        private void ProcessListSet()
        {
            uint res = _pdhHelper.ConnectToDataSource(_resolvedPaths);

            if (res != 0)
            {
                ReportPdhError(res, true);
                return;
            }

            StringCollection machineNames = new StringCollection();

            res = _pdhHelper.EnumBlgFilesMachines(ref machineNames);
            if (res != 0)
            {
                ReportPdhError(res, true);
                return;
            }

            foreach (string machine in machineNames)
            {
                StringCollection counterSets = new StringCollection();
                res = _pdhHelper.EnumObjects(machine, ref counterSets);
                if (res != 0)
                {
                    return;
                }

                StringCollection validPaths = new StringCollection();

                foreach (string pattern in _listSet)
                {
                    bool bMatched = false;

                    WildcardPattern wildLogPattern = new WildcardPattern(pattern, WildcardOptions.IgnoreCase);

                    foreach (string counterSet in counterSets)
                    {
                        if (!wildLogPattern.IsMatch(counterSet))
                        {
                            continue;
                        }

                        StringCollection counterSetCounters  = new StringCollection();
                        StringCollection counterSetInstances = new StringCollection();

                        res = _pdhHelper.EnumObjectItems(machine, counterSet, ref counterSetCounters, ref counterSetInstances);
                        if (res != 0)
                        {
                            ReportPdhError(res, false);
                            continue;
                        }

                        string[] instanceArray = new string[counterSetInstances.Count];
                        int      i             = 0;
                        foreach (string instance in counterSetInstances)
                        {
                            instanceArray[i++] = instance;
                        }

                        Dictionary <string, string[]> counterInstanceMapping = new Dictionary <string, string[]>();
                        foreach (string counter in counterSetCounters)
                        {
                            counterInstanceMapping.Add(counter, instanceArray);
                        }

                        PerformanceCounterCategoryType categoryType = PerformanceCounterCategoryType.Unknown;
                        if (counterSetInstances.Count > 1)
                        {
                            categoryType = PerformanceCounterCategoryType.MultiInstance;
                        }
                        else // if (counterSetInstances.Count == 1) //???
                        {
                            categoryType = PerformanceCounterCategoryType.SingleInstance;
                        }

                        string setHelp = _pdhHelper.GetCounterSetHelp(machine, counterSet);

                        CounterSet setObj = new CounterSet(counterSet, machine, categoryType, setHelp, ref counterInstanceMapping);
                        WriteObject(setObj);
                        bMatched = true;
                    }

                    if (!bMatched)
                    {
                        string    msg = _resourceMgr.GetString("NoMatchingCounterSetsInFile");
                        Exception exc = new Exception(string.Format(CultureInfo.InvariantCulture, msg,
                                                                    CommonUtilities.StringArrayToString(_resolvedPaths),
                                                                    pattern));
                        WriteError(new ErrorRecord(exc, "NoMatchingCounterSetsInFile", ErrorCategory.ObjectNotFound, null));
                    }
                }
            }
        }
예제 #21
0
        protected override void ProcessRecord()
        {
            try
            {
                switch (Type)
                {
                case ProfileType.VirtualDisk:
                    DiskProfileService = new VirtualDiskProfileService(Connection);

                    Task <Result <List <VirtualDiskProfile> > > callTask1 = Task.Run(() => DiskProfileService.AllAsync());

                    callTask1.Wait();
                    var result1 = callTask1.Result;


                    if (result1.Object != default(List <VirtualDiskProfile>))
                    {
                        if (!string.IsNullOrEmpty(Name))
                        {
                            var pattern = new WildcardPattern(Name);
                            result1.Object.Where(x => pattern.IsMatch(x.Id)).ToList().ForEach(WriteObject);
                        }
                        else
                        {
                            result1.Object.ToList().ForEach(WriteObject);
                        }
                    }
                    else if (result1.Error != null)
                    {
                        throw new RemoteException("Conflict Error: " + result1.Error.ErrorType + "\r\n" + result1.Error.FaultyValues);
                    }
                    else
                    {
                        throw new RemoteException("API returns: " + result1.Code.ToString());
                    }
                    break;

                case ProfileType.VirtualMachine:

                    MachineProfileService = new VirtualMachineProfileService(Connection);

                    Task <Result <List <VirtualMachineProfile> > > callTask2 = Task.Run(() => MachineProfileService.AllAsync());

                    callTask2.Wait();
                    var result2 = callTask2.Result;

                    if (result2.Object != default(List <VirtualMachineProfile>))
                    {
                        if (!string.IsNullOrEmpty(Name))
                        {
                            var pattern = new WildcardPattern(Name);
                            result2.Object.Where(x => pattern.IsMatch(x.Id)).ToList().ForEach(WriteObject);
                        }
                        else
                        {
                            result2.Object.ToList().ForEach(WriteObject);
                        }
                    }
                    else if (result2.Error != null)
                    {
                        throw new RemoteException("Conflict Error: " + result2.Error.ErrorType + "\r\n" + result2.Error.FaultyValues);
                    }
                    else
                    {
                        throw new RemoteException("API returns: " + result2.Code.ToString());
                    }
                    break;

                case ProfileType.VirtualNetworkAdapter:
                    NetworkAdapterProfileService = new VirtualNetworkAdapterProfileService(Connection);

                    Task <Result <List <VirtualNetworkAdapterProfile> > > callTask3 = Task.Run(() => NetworkAdapterProfileService.AllAsync());

                    callTask3.Wait();
                    var result3 = callTask3.Result;

                    if (result3.Object != default(List <VirtualNetworkAdapterProfile>))
                    {
                        if (!string.IsNullOrEmpty(Name))
                        {
                            var pattern = new WildcardPattern(Name);
                            result3.Object.Where(x => pattern.IsMatch(x.Id)).ToList().ForEach(WriteObject);
                        }
                        else
                        {
                            result3.Object.ToList().ForEach(WriteObject);
                        }
                    }
                    else if (result3.Error != null)
                    {
                        throw new RemoteException("Conflict Error: " + result3.Error.ErrorType + "\r\n" + result3.Error.FaultyValues);
                    }
                    else
                    {
                        throw new RemoteException("API returns: " + result3.Code.ToString());
                    }
                    break;
                }
            }
            catch (Exception e)
            {
                throw new RemoteException("An API Error has happen");
            }
        }
예제 #22
0
        } // GetContentReaders

        /// <summary>
        /// Resolves the specified paths to PathInfo objects
        /// </summary>
        /// <param name="pathsToResolve">
        /// The paths to be resolved. Each path may contain glob characters.
        /// </param>
        /// <param name="allowNonexistingPaths">
        /// If true, resolves the path even if it doesn't exist.
        /// </param>
        /// <param name="allowEmptyResult">
        /// If true, allows a wildcard that returns no results.
        /// </param>
        /// <param name="currentCommandContext">
        /// The context under which the command is running.
        /// </param>
        /// <returns>
        /// An array of PathInfo objects that are the resolved paths for the
        /// <paramref name="pathsToResolve"/> parameter.
        /// </returns>
        internal Collection <PathInfo> ResolvePaths(
            string[] pathsToResolve,
            bool allowNonexistingPaths,
            bool allowEmptyResult,
            CmdletProviderContext currentCommandContext)
        {
            Collection <PathInfo> results = new Collection <PathInfo>();

            foreach (string path in pathsToResolve)
            {
                bool pathNotFound   = false;
                bool filtersHidPath = false;

                ErrorRecord pathNotFoundErrorRecord = null;

                try
                {
                    // First resolve each of the paths
                    Collection <PathInfo> pathInfos =
                        SessionState.Path.GetResolvedPSPathFromPSPath(
                            path,
                            currentCommandContext);

                    if (pathInfos.Count == 0)
                    {
                        pathNotFound = true;

                        // If the item simply did not exist,
                        // we would have got an ItemNotFoundException.
                        // If we get here, it's because the filters
                        // excluded the file.
                        if (!currentCommandContext.SuppressWildcardExpansion)
                        {
                            filtersHidPath = true;
                        }
                    }

                    foreach (PathInfo pathInfo in pathInfos)
                    {
                        results.Add(pathInfo);
                    }
                }
                catch (PSNotSupportedException notSupported)
                {
                    WriteError(
                        new ErrorRecord(
                            notSupported.ErrorRecord,
                            notSupported));
                }
                catch (DriveNotFoundException driveNotFound)
                {
                    WriteError(
                        new ErrorRecord(
                            driveNotFound.ErrorRecord,
                            driveNotFound));
                }
                catch (ProviderNotFoundException providerNotFound)
                {
                    WriteError(
                        new ErrorRecord(
                            providerNotFound.ErrorRecord,
                            providerNotFound));
                }
                catch (ItemNotFoundException pathNotFoundException)
                {
                    pathNotFound            = true;
                    pathNotFoundErrorRecord = new ErrorRecord(pathNotFoundException.ErrorRecord, pathNotFoundException);
                }

                if (pathNotFound)
                {
                    if (allowNonexistingPaths &&
                        (!filtersHidPath) &&
                        (currentCommandContext.SuppressWildcardExpansion ||
                         (!WildcardPattern.ContainsWildcardCharacters(path))))
                    {
                        ProviderInfo provider       = null;
                        PSDriveInfo  drive          = null;
                        string       unresolvedPath =
                            SessionState.Path.GetUnresolvedProviderPathFromPSPath(
                                path,
                                currentCommandContext,
                                out provider,
                                out drive);

                        PathInfo pathInfo =
                            new PathInfo(
                                drive,
                                provider,
                                unresolvedPath,
                                SessionState);
                        results.Add(pathInfo);
                    }
                    else
                    {
                        if (pathNotFoundErrorRecord == null)
                        {
                            // Detect if the path resolution failed to resolve to a file.
                            String    error = StringUtil.Format(NavigationResources.ItemNotFound, Path);
                            Exception e     = new Exception(error);

                            pathNotFoundErrorRecord = new ErrorRecord(
                                e,
                                "ItemNotFound",
                                ErrorCategory.ObjectNotFound,
                                Path);
                        }

                        WriteError(pathNotFoundErrorRecord);
                    }
                }
            }

            return(results);
        } // ResolvePaths
예제 #23
0
        /// <summary>
        /// Get the requested events
        /// </summary>
        protected override void EndProcessing()
        {
            bool foundMatch = false;

            // Go through all the received events and write them to the output
            // pipeline
            List <PSEventArgs> eventArgsCollection;

            lock (Events.ReceivedEvents.SyncRoot)
            {
                eventArgsCollection = new List <PSEventArgs>(Events.ReceivedEvents);
            }

            foreach (PSEventArgs eventArg in eventArgsCollection)
            {
                // If they specified a event identifier and we don't match, continue
                if ((_sourceIdentifier != null) &&
                    (!_matchPattern.IsMatch(eventArg.SourceIdentifier)))
                {
                    continue;
                }

                // If they specified an event identifier and we don't match, continue
                if ((_eventId >= 0) &&
                    (eventArg.EventIdentifier != _eventId))
                {
                    continue;
                }

                WriteObject(eventArg);
                foundMatch = true;
            }

            // Generate an error if we couldn't find the subscription identifier,
            // and no globbing was done.
            if (!foundMatch)
            {
                bool lookingForSource = (_sourceIdentifier != null) &&
                                        (!WildcardPattern.ContainsWildcardCharacters(_sourceIdentifier));
                bool lookingForId = (_eventId >= 0);

                if (lookingForSource || lookingForId)
                {
                    object identifier = null;
                    string error      = null;

                    if (lookingForSource)
                    {
                        identifier = _sourceIdentifier;
                        error      = EventingStrings.SourceIdentifierNotFound;
                    }
                    else if (lookingForId)
                    {
                        identifier = _eventId;
                        error      = EventingStrings.EventIdentifierNotFound;
                    }

                    ErrorRecord errorRecord = new ErrorRecord(
                        new ArgumentException(String.Format(System.Globalization.CultureInfo.CurrentCulture, error, identifier)),
                        "INVALID_SOURCE_IDENTIFIER",
                        ErrorCategory.InvalidArgument,
                        null);

                    WriteError(errorRecord);
                }
            }
        }
예제 #24
0
        internal Collection <PSTraceSource> ConfigureTraceSource(
            string[] sourceNames,
            bool preConfigure,
            out Collection <PSTraceSource> preconfiguredSources)
        {
            preconfiguredSources = new Collection <PSTraceSource>();

            // Find the matching and unmatched trace sources.

            Collection <string>        notMatched      = null;
            Collection <PSTraceSource> matchingSources = GetMatchingTraceSource(sourceNames, false, out notMatched);

            if (preConfigure)
            {
                // Set the flags if they were specified
                if (optionsSpecified)
                {
                    SetFlags(matchingSources);
                }

                AddTraceListenersToSources(matchingSources);
                SetTraceListenerOptions(matchingSources);
            }

            // Now try to preset options for sources which have not yet been
            // constructed.

            foreach (string notMatchedName in notMatched)
            {
                if (string.IsNullOrEmpty(notMatchedName))
                {
                    continue;
                }

                if (WildcardPattern.ContainsWildcardCharacters(notMatchedName))
                {
                    continue;
                }

                PSTraceSource newTraceSource =
                    PSTraceSource.GetNewTraceSource(
                        notMatchedName,
                        string.Empty,
                        true);

                preconfiguredSources.Add(newTraceSource);
            }

            // Preconfigure any trace sources that were not already present

            if (preconfiguredSources.Count > 0)
            {
                if (preConfigure)
                {
                    // Set the flags if they were specified
                    if (optionsSpecified)
                    {
                        SetFlags(preconfiguredSources);
                    }

                    AddTraceListenersToSources(preconfiguredSources);
                    SetTraceListenerOptions(preconfiguredSources);
                }

                // Add the sources to the preconfigured table so that they are found
                // when the trace source finally gets created by the system.

                foreach (PSTraceSource sourceToPreconfigure in preconfiguredSources)
                {
                    if (!PSTraceSource.PreConfiguredTraceSource.ContainsKey(sourceToPreconfigure.Name))
                    {
                        PSTraceSource.PreConfiguredTraceSource.Add(sourceToPreconfigure.Name, sourceToPreconfigure);
                    }
                }
            }

            return(matchingSources);
        }
예제 #25
0
        protected override void ProcessRecord()
        {
            var baseResourceList = new List <MachineResource>();

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

            case ByName:
                var machineNameList = MachineName?.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 (machineNameList.Any(item => WildcardPattern.ContainsWildcardCharacters(item) && machineNameList.Count > 1))
                {
                    throw OctoposhExceptions.ParameterCollectionHasRegularAndWildcardItem("MachineName");
                }
                //Only 1 wildcarded value (ie -MachineName WebServer*)
                else if (machineNameList.Any(item => WildcardPattern.ContainsWildcardCharacters(item) && machineNameList.Count == 1))
                {
                    var pattern = new WildcardPattern(machineNameList.First());
                    baseResourceList = _connection.Repository.Machines.FindMany(x => pattern.IsMatch(x.Name.ToLower()));
                }
                //multiple non-wildcared values (i.e. -MachineName WebServer1,Database1)
                else if (!machineNameList.Any(item => WildcardPattern.ContainsWildcardCharacters(item)))
                {
                    baseResourceList = _connection.Repository.Machines.FindMany(x => machineNameList.Contains(x.Name.ToLower()));
                }
                break;

            case ByUrl:

                var urlList = URL.ToList().ConvertAll(s => s.ToLower());

                //Multiple values but one of them is wildcarded, which is not an accepted scenario (I.e -URL http://Tentacle*, http://Database1)
                if (urlList.Any(item => WildcardPattern.ContainsWildcardCharacters(item) && urlList.Count > 1))
                {
                    throw OctoposhExceptions.ParameterCollectionHasRegularAndWildcardItem("URL");
                }
                //Only 1 wildcarded value (ie -URL http://Tentacle*)
                else if (urlList.Any(item => WildcardPattern.ContainsWildcardCharacters(item) && urlList.Count == 1))
                {
                    var pattern = new WildcardPattern(urlList.First());
                    baseResourceList = _connection.Repository.Machines.FindMany(x => pattern.IsMatch(x.Uri));
                }
                //multiple non-wildcared values (i.e. -URL http://Tentacle ,http://Database)
                else if (!urlList.Any(item => WildcardPattern.ContainsWildcardCharacters(item)))
                {
                    baseResourceList = _connection.Repository.Machines.FindMany(x => urlList.Contains(x.Uri));
                }
                break;

            case ByCommunicationStyle:

                var endpointtype = "";

                switch (CommunicationStyle)
                {
                case "Polling":
                    endpointtype = "Octopus.Client.Model.Endpoints.PollingTentacleEndpointResource";
                    break;

                case "Listening":
                    endpointtype = "Octopus.Client.Model.Endpoints.ListeningTentacleEndpointResource";
                    break;

                case "CloudRegion":
                    endpointtype = "Octopus.Client.Model.Endpoints.CloudRegionEndpointResource";
                    break;

                case "OfflineDrop":
                    endpointtype = "Octopus.Client.Model.Endpoints.OfflineDropEndpointResource";
                    break;

                case "SSH":
                    endpointtype = "Octopus.Client.Model.Endpoints.SSHEndpointResource";
                    break;
                }

                baseResourceList = _connection.Repository.Machines.FindMany(x => String.Equals(x.Endpoint.GetType().ToString(), endpointtype, StringComparison.CurrentCultureIgnoreCase));

                break;

            case ByEnvironment:

                var environmentNameList = EnvironmentName.ToList().ConvertAll(s => s.ToLower());

                foreach (var name in environmentNameList)
                {
                    var environment = _connection.Repository.Environments.FindByName(name);
                    baseResourceList.AddRange(_connection.Repository.Environments.GetMachines(environment));
                }
                break;
            }

            if (ResourceOnly)
            {
                WriteObject(baseResourceList);
            }
            else
            {
                var converter  = new OutputConverter();
                var outputList = converter.GetOctopusMachine(baseResourceList);

                WriteObject(outputList);
            }
        }
예제 #26
0
        //
        // ProcessListSetPerMachine() helper lists counter sets on a machine.
        // NOTE: machine argument should be NULL for the local machine
        //
        private void ProcessListSetPerMachine(string machine)
        {
            StringCollection counterSets = new StringCollection();
            uint             res         = _pdhHelper.EnumObjects(machine, ref counterSets);

            if (res != 0)
            {
                // add an error message
                string    msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("NoCounterSetsOnComputer"), machine, res);
                Exception exc = new Exception(msg);
                WriteError(new ErrorRecord(exc, "NoCounterSetsOnComputer", ErrorCategory.InvalidResult, machine));
                return;
            }

            CultureInfo culture = GetCurrentCulture();
            List <Tuple <char, char> > characterReplacementList = null;
            StringCollection           validPaths = new StringCollection();

            _cultureAndSpecialCharacterMap.TryGetValue(culture.Name, out characterReplacementList);

            foreach (string pattern in _listSet)
            {
                bool   bMatched          = false;
                string normalizedPattern = pattern;

                if (characterReplacementList != null)
                {
                    foreach (Tuple <char, char> pair in characterReplacementList)
                    {
                        normalizedPattern = normalizedPattern.Replace(pair.Item1, pair.Item2);
                    }
                }

                WildcardPattern wildLogPattern = new WildcardPattern(normalizedPattern, WildcardOptions.IgnoreCase);

                foreach (string counterSet in counterSets)
                {
                    if (!wildLogPattern.IsMatch(counterSet))
                    {
                        continue;
                    }

                    StringCollection counterSetCounters  = new StringCollection();
                    StringCollection counterSetInstances = new StringCollection();

                    res = _pdhHelper.EnumObjectItems(machine, counterSet, ref counterSetCounters, ref counterSetInstances);
                    if (res == PdhResults.PDH_ACCESS_DENIED)
                    {
                        string    msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterSetEnumAccessDenied"), counterSet);
                        Exception exc = new Exception(msg);
                        WriteError(new ErrorRecord(exc, "CounterSetEnumAccessDenied", ErrorCategory.InvalidResult, null));
                        continue;
                    }
                    else if (res != 0)
                    {
                        ReportPdhError(res, false);
                        continue;
                    }

                    string[] instanceArray = new string[counterSetInstances.Count];
                    int      i             = 0;
                    foreach (string instance in counterSetInstances)
                    {
                        instanceArray[i++] = instance;
                    }

                    //
                    // Special case: no instances present: change to * to create a valid paths
                    //
                    if (instanceArray.Length == 1 &&
                        instanceArray[0].Length == 0)
                    {
                        instanceArray[0] = "*";
                    }

                    Dictionary <string, string[]> counterInstanceMapping = new Dictionary <string, string[]>();
                    foreach (string counter in counterSetCounters)
                    {
                        if (!counterInstanceMapping.ContainsKey(counter))
                        {
                            counterInstanceMapping.Add(counter, instanceArray);
                        }
                    }

                    PerformanceCounterCategoryType categoryType = PerformanceCounterCategoryType.Unknown;
                    if (counterSetInstances.Count > 1)
                    {
                        categoryType = PerformanceCounterCategoryType.MultiInstance;
                    }
                    else // if (counterSetInstances.Count == 1) //???
                    {
                        categoryType = PerformanceCounterCategoryType.SingleInstance;
                    }

                    string setHelp = _pdhHelper.GetCounterSetHelp(machine, counterSet);

                    CounterSet setObj = new CounterSet(counterSet, machine, categoryType, setHelp, ref counterInstanceMapping);
                    WriteObject(setObj);
                    bMatched = true;
                }

                if (!bMatched)
                {
                    string    msg = _resourceMgr.GetString("NoMatchingCounterSetsFound");
                    Exception exc = new Exception(string.Format(CultureInfo.InvariantCulture, msg,
                                                                machine ?? "localhost", normalizedPattern));
                    WriteError(new ErrorRecord(exc, "NoMatchingCounterSetsFound", ErrorCategory.ObjectNotFound, null));
                }
            }
        }
예제 #27
0
        static void Main(string[] args)
        {
            _arguments = new Arguments(args);

            // Print help screen. Ignore other arguments
            if (args.Length == 0 || _arguments.Help)
            {
                PrintHelp();
                goto exit;
            }

            if (_arguments.Inputs.Count == 0)
            {
                Console.WriteLine("No input file(s) found");
                goto exit;
            }

            // Setup filtering
            if (_arguments.Filtering != Filtering.None)
            {
                if (_arguments.Filtering == Filtering.Simple)
                {
                    _pattern = new WildcardPattern(
                        $"*{WildcardPattern.Escape(_arguments.FilterString).Replace("`*", "*")}*",
                        WildcardOptions.Compiled | WildcardOptions.IgnoreCase);
                }
                else if (_arguments.Filtering == Filtering.Regex)
                {
                    try
                    {
                        _regex = new Regex(_arguments.FilterString, RegexOptions.Compiled | RegexOptions.Singleline);
                    }
                    catch
                    {
                        Console.WriteLine("Invalid regex filter string");
                        goto exit;
                    }
                }
            }

            if (_arguments.List || (!_arguments.List && !_arguments.Extract && !_arguments.Help))
            {
                PrintFileList(_arguments.Inputs.ToList(), _arguments.ListOptions);
            }

            if (_arguments.Extract)
            {
                if (string.IsNullOrEmpty(_arguments.Destination) || !Directory.Exists(_arguments.Destination))
                {
                    Console.WriteLine($"Destination \'{_arguments.Destination}\' not found!");
                    goto exit;
                }

                ExtractFiles(_arguments.Inputs.ToList(), _arguments.ATI, _arguments.Destination);
            }

            exit :;

#if DEBUG
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
#endif
        }
예제 #28
0
        public void GetInstalledPackages(string name, string requiredVersion, string minimumVersion, string maximumVersion, PackageSourceListRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (!ValidatePackageManagementVersion(request))
            {
                return;
            }

            request.Debug(Resources.Messages.DebugInfoCallMethod, PackageProviderName, string.Format(CultureInfo.InvariantCulture, "GetInstalledPackages' - name='{0}', requiredVersion='{1}',minimumVersion='{2}', maximumVersion='{3}'", name, requiredVersion, minimumVersion, maximumVersion));

            IEnumerable <PackageJson> packagesDefinedInJsonSpec;

            if (string.IsNullOrWhiteSpace(name) || WildcardPattern.ContainsWildcardCharacters(name))
            {
                // In the case of the package name is null or contains wildcards, error out if a user puts version info
                if (!string.IsNullOrWhiteSpace(requiredVersion) || !string.IsNullOrWhiteSpace(minimumVersion) || !string.IsNullOrWhiteSpace(maximumVersion))
                {
                    request.Warning(Resources.Messages.WildCardCharsAreNotSupported, name);
                    return;
                }
                packagesDefinedInJsonSpec = request.GetPackages(name).ToArray();
            }
            else
            {
                //return all installed
                packagesDefinedInJsonSpec = request.GetPackages(name, requiredVersion, minimumVersion, maximumVersion).ToArray();
            }
            _fastPackReftable.Clear();

            if (!packagesDefinedInJsonSpec.Any())
            {
                request.Verbose(Resources.Messages.NoPackageFound, Constants.ProviderName);
                return;
            }

            foreach (var package in packagesDefinedInJsonSpec)
            {
                switch (package.Type.ToLowerInvariant())
                {
                case Constants.MediaType.AppxPackage:
                    //TODO for future
                    break;

                case Constants.MediaType.PsArtifacts:
                    PowerShellArtifactInstaller.GetInstalledPowershellArtifacts(package, requiredVersion, minimumVersion, maximumVersion, _fastPackReftable, request);
                    break;

                case Constants.MediaType.ExePackage:
#if CORECLR
                    request.WriteError(ErrorCategory.InvalidOperation, package.Type, Resources.Messages.UnsupportedPowerShellEnvironment, Constants.ProviderName, "Get-Package", package.Type);
#else
                    //program provider can handle get-package git for git.exe
                    ExePackageInstaller.GetInstalledExePackages(package, requiredVersion, minimumVersion, minimumVersion, request);
#endif
                    break;

                case Constants.MediaType.MsiPackage:
#if CORECLR
                    request.WriteError(ErrorCategory.InvalidOperation, package.Type, Resources.Messages.UnsupportedPowerShellEnvironment, Constants.ProviderName, "Get-Package", package.Type);
#else
                    //msi provider can handle get-package node.js for node.js.msi
                    GetMsiInstalledPackage(name, package, requiredVersion, minimumVersion, maximumVersion, request);
#endif
                    break;

                case Constants.MediaType.ZipPackage:
                    ZipPackageInstaller.GetInstalledZipPackage(package, request);
                    break;

                case Constants.MediaType.NuGetPackage:
                    NupkgInstaller.GeInstalledNuGetPackages(package, requiredVersion, minimumVersion, maximumVersion, _fastPackReftable, request);
                    break;
                } //switch
            }
        }
예제 #29
0
        private void WriteMatches(string value, string parametersetname)
        {
            // First get the alias table (from the proper scope if necessary)
            IDictionary <string, AliasInfo> aliasTable = null;

            // get the command origin
            CommandOrigin origin        = MyInvocation.CommandOrigin;
            string        displayString = "name";

            if (!string.IsNullOrEmpty(Scope))
            {
                // This can throw PSArgumentException and PSArgumentOutOfRangeException
                // but just let them go as this is terminal for the pipeline and the
                // exceptions are already properly adorned with an ErrorRecord.

                aliasTable = SessionState.Internal.GetAliasTableAtScope(Scope);
            }
            else
            {
                aliasTable = SessionState.Internal.GetAliasTable();
            }

            bool            matchfound       = false;
            bool            ContainsWildcard = WildcardPattern.ContainsWildcardCharacters(value);
            WildcardPattern wcPattern        = WildcardPattern.Get(value, WildcardOptions.IgnoreCase);

            // excluding patter for Default paramset.
            Collection <WildcardPattern> excludePatterns =
                SessionStateUtilities.CreateWildcardsFromStrings(
                    _excludes,
                    WildcardOptions.IgnoreCase);

            List <AliasInfo> results = new();

            foreach (KeyValuePair <string, AliasInfo> tableEntry in aliasTable)
            {
                if (parametersetname.Equals("Definition", StringComparison.OrdinalIgnoreCase))
                {
                    displayString = "definition";
                    if (!wcPattern.IsMatch(tableEntry.Value.Definition))
                    {
                        continue;
                    }

                    if (SessionStateUtilities.MatchesAnyWildcardPattern(tableEntry.Value.Definition, excludePatterns, false))
                    {
                        continue;
                    }
                }
                else
                {
                    if (!wcPattern.IsMatch(tableEntry.Key))
                    {
                        continue;
                    }
                    // excludes pattern
                    if (SessionStateUtilities.MatchesAnyWildcardPattern(tableEntry.Key, excludePatterns, false))
                    {
                        continue;
                    }
                }

                if (ContainsWildcard)
                {
                    // Only write the command if it is visible to the requestor
                    if (SessionState.IsVisible(origin, tableEntry.Value))
                    {
                        matchfound = true;
                        results.Add(tableEntry.Value);
                    }
                }
                else
                {
                    // For specifically named elements, generate an error for elements that aren't visible...
                    try
                    {
                        SessionState.ThrowIfNotVisible(origin, tableEntry.Value);
                        results.Add(tableEntry.Value);
                        matchfound = true;
                    }
                    catch (SessionStateException sessionStateException)
                    {
                        WriteError(
                            new ErrorRecord(
                                sessionStateException.ErrorRecord,
                                sessionStateException));
                        // Even though it resulted in an error, a result was found
                        // so we don't want to generate the nothing found error
                        // at the end...
                        matchfound = true;
                        continue;
                    }
                }
            }

            results.Sort(
                (AliasInfo left, AliasInfo right) => StringComparer.CurrentCultureIgnoreCase.Compare(left.Name, right.Name));
            foreach (AliasInfo alias in results)
            {
                this.WriteObject(alias);
            }

            if (!matchfound && !ContainsWildcard && (excludePatterns == null || excludePatterns.Count == 0))
            {
                // Need to write an error if the user tries to get an alias
                // tat doesn't exist and they are not globbing.

                ItemNotFoundException itemNotFound = new(StringUtil.Format(AliasCommandStrings.NoAliasFound, displayString, value));
                ErrorRecord           er           = new(itemNotFound, "ItemNotFoundException", ErrorCategory.ObjectNotFound, value);
                WriteError(er);
            }
        }
예제 #30
0
        /// <summary>
        /// Implements the ProcessRecord() method for get-help command.
        /// </summary>
        protected override void ProcessRecord()
        {
            HelpSystem helpSystem = this.Context.HelpSystem;

            try
            {
#if !UNIX
                if (this.ShowWindow)
                {
                    this.graphicalHostReflectionWrapper = GraphicalHostReflectionWrapper.GetGraphicalHostReflectionWrapper(this, "Microsoft.PowerShell.Commands.Internal.HelpWindowHelper");
                }
#endif
                helpSystem.OnProgress += new HelpSystem.HelpProgressHandler(HelpSystem_OnProgress);

                bool         failed       = false;
                HelpCategory helpCategory = ToHelpCategory(Category, ref failed);

                if (failed)
                {
                    return;
                }

                // Validate input parameters
                ValidateAndThrowIfError(helpCategory);

                HelpRequest helpRequest = new HelpRequest(this.Name, helpCategory);

                helpRequest.Provider        = _provider;
                helpRequest.Component       = Component;
                helpRequest.Role            = Role;
                helpRequest.Functionality   = Functionality;
                helpRequest.ProviderContext = new ProviderContext(
                    this.Path,
                    this.Context.Engine.Context,
                    this.SessionState.Path);
                helpRequest.CommandOrigin = this.MyInvocation.CommandOrigin;

                // the idea is to use yield statement in the help lookup to speed up
                // perceived user experience....So HelpSystem.GetHelp returns an
                // IEnumerable..
                IEnumerable <HelpInfo> helpInfos = helpSystem.GetHelp(helpRequest);
                // HelpCommand acts differently when there is just one help object and when
                // there are more than one object...so handling this behavior through
                // some variables.
                HelpInfo firstHelpInfoObject = null;
                int      countOfHelpInfos    = 0;
                foreach (HelpInfo helpInfo in helpInfos)
                {
                    // honor Ctrl-C from user.
                    if (IsStopping)
                    {
                        return;
                    }

                    if (0 == countOfHelpInfos)
                    {
                        firstHelpInfoObject = helpInfo;
                    }
                    else
                    {
                        // write first help object only once.
                        if (firstHelpInfoObject != null)
                        {
                            WriteObjectsOrShowOnlineHelp(firstHelpInfoObject, false);
                            firstHelpInfoObject = null;
                        }

                        WriteObjectsOrShowOnlineHelp(helpInfo, false);
                    }

                    countOfHelpInfos++;
                }

                _timer.Stop();

#if LEGACYTELEMETRY
                if (!string.IsNullOrEmpty(Name))
                {
                    Microsoft.PowerShell.Telemetry.Internal.TelemetryAPI.ReportGetHelpTelemetry(Name, countOfHelpInfos, _timer.ElapsedMilliseconds, _updatedHelp);
                }
#endif
                // Write full help as there is only one help info object
                if (1 == countOfHelpInfos)
                {
                    WriteObjectsOrShowOnlineHelp(firstHelpInfoObject, true);
                }
                else if (_showOnlineHelp && (countOfHelpInfos > 1))
                {
                    throw PSTraceSource.NewInvalidOperationException(HelpErrors.MultipleOnlineTopicsNotSupported, "Online");
                }

                // show errors only if there is no wildcard search or VerboseHelpErrors is true.
                if (((countOfHelpInfos == 0) && (!WildcardPattern.ContainsWildcardCharacters(helpRequest.Target))) ||
                    helpSystem.VerboseHelpErrors)
                {
                    // Check if there is any error happened. If yes,
                    // pipe out errors.
                    if (helpSystem.LastErrors.Count > 0)
                    {
                        foreach (ErrorRecord errorRecord in helpSystem.LastErrors)
                        {
                            WriteError(errorRecord);
                        }
                    }
                }
            }
            finally
            {
                helpSystem.OnProgress -= new HelpSystem.HelpProgressHandler(HelpSystem_OnProgress);
                HelpSystem_OnComplete();

                // finally clear the ScriptBlockAst -> Token[] cache
                helpSystem.ClearScriptBlockTokenCache();
            }
        }
예제 #31
0
        private bool IsMatch <T>(T resource, string property, WildcardPattern pattern)
        {
            var value = (string)GetPropertyValue(resource, property);

            return(!string.IsNullOrEmpty(value) && pattern.IsMatch(value));
        }
예제 #32
0
 public void VisitWildcardPattern(WildcardPattern wildcardPattern)
 {
     throw new NotImplementedException();
 }
예제 #33
0
        /// <summary>
        /// Gets a Virtual Network Rule from the service.
        /// </summary>
        /// <returns>A single Virtual Network Rule</returns>
        protected override IEnumerable <AzureSqlServerVirtualNetworkRuleModel> GetEntity()
        {
            ICollection <AzureSqlServerVirtualNetworkRuleModel> results = null;

            if (this.MyInvocation.BoundParameters.ContainsKey("VirtualNetworkRuleName") && !WildcardPattern.ContainsWildcardCharacters(VirtualNetworkRuleName))
            {
                results = new List <AzureSqlServerVirtualNetworkRuleModel>();
                results.Add(ModelAdapter.GetVirtualNetworkRule(this.ResourceGroupName, this.ServerName, this.VirtualNetworkRuleName));
            }
            else
            {
                results = ModelAdapter.ListVirtualNetworkRules(this.ResourceGroupName, this.ServerName);
            }

            return(SubResourceWildcardFilter(VirtualNetworkRuleName, results));
        }
예제 #34
0
 public void VisitWildcardPattern(WildcardPattern wildcardPattern)
 {
     // no op
 }
예제 #35
0
        public static List <PSRepositoryInfo> Read(string[] repoNames, out string[] errorList)
        {
            List <string> tempErrorList = new List <string>();
            var           foundRepos    = new List <PSRepositoryInfo>();

            XDocument doc;

            try
            {
                // Open file
                doc = LoadXDocument(FullRepositoryPath);
            }
            catch (Exception e)
            {
                throw new PSInvalidOperationException(String.Format("Loading repository store failed: {0}", e.Message));
            }

            if (repoNames == null || repoNames.Length == 0 || string.Equals(repoNames[0], "*") || repoNames[0] == null)
            {
                // Name array or single value is null so we will list all repositories registered
                // iterate through the doc
                foreach (XElement repo in doc.Descendants("Repository"))
                {
                    if (repo.Attribute("Name") == null)
                    {
                        tempErrorList.Add(String.Format("Repository element does not contain neccessary 'Name' attribute, in file located at path: {0}. Fix this in your file and run again.", FullRepositoryPath));
                        continue;
                    }

                    if (repo.Attribute("Priority") == null)
                    {
                        tempErrorList.Add(String.Format("Repository element does not contain neccessary 'Priority' attribute, in file located at path: {0}. Fix this in your file and run again.", FullRepositoryPath));
                        continue;
                    }

                    if (repo.Attribute("Trusted") == null)
                    {
                        tempErrorList.Add(String.Format("Repository element does not contain neccessary 'Trusted' attribute, in file located at path: {0}. Fix this in your file and run again.", FullRepositoryPath));
                        continue;
                    }

                    bool urlAttributeExists = repo.Attribute("Url") != null;
                    bool uriAttributeExists = repo.Attribute("Uri") != null;
                    // case: neither Url nor Uri attributes exist
                    if (!urlAttributeExists && !uriAttributeExists)
                    {
                        tempErrorList.Add(String.Format("Repository element does not contain neccessary 'Url' or equivalent 'Uri' attribute (it must contain one), in file located at path: {0}. Fix this in your file and run again.", FullRepositoryPath));
                        continue;
                    }

                    Uri thisUrl = null;
                    // case: either attribute Uri or Url exists
                    // TODO: do we only allow both to exist, across repositories? (i.e if a file has Uri attribute for one repo and Url attribute for another --> is that invalid?)
                    if (urlAttributeExists)
                    {
                        if (!Uri.TryCreate(repo.Attribute("Url").Value, UriKind.Absolute, out thisUrl))
                        {
                            tempErrorList.Add(String.Format("Unable to read incorrectly formatted Url for repo {0}", repo.Attribute("Name").Value));
                            continue;
                        }
                    }
                    else if (uriAttributeExists)
                    {
                        if (!Uri.TryCreate(repo.Attribute("Uri").Value, UriKind.Absolute, out thisUrl))
                        {
                            tempErrorList.Add(String.Format("Unable to read incorrectly formatted Uri for repo {0}", repo.Attribute("Name").Value));
                            continue;
                        }
                    }

                    PSCredentialInfo thisCredentialInfo;
                    string           credentialInfoErrorMessage = $"Repository {repo.Attribute("Name").Value} has invalid CredentialInfo. {PSCredentialInfo.VaultNameAttribute} and {PSCredentialInfo.SecretNameAttribute} should both be present and non-empty";
                    // both keys are present
                    if (repo.Attribute(PSCredentialInfo.VaultNameAttribute) != null && repo.Attribute(PSCredentialInfo.SecretNameAttribute) != null)
                    {
                        try
                        {
                            // both values are non-empty
                            // = valid credentialInfo
                            thisCredentialInfo = new PSCredentialInfo(repo.Attribute(PSCredentialInfo.VaultNameAttribute).Value, repo.Attribute(PSCredentialInfo.SecretNameAttribute).Value);
                        }
                        catch (Exception)
                        {
                            thisCredentialInfo = null;
                            tempErrorList.Add(credentialInfoErrorMessage);
                            continue;
                        }
                    }
                    // both keys are missing
                    else if (repo.Attribute(PSCredentialInfo.VaultNameAttribute) == null && repo.Attribute(PSCredentialInfo.SecretNameAttribute) == null)
                    {
                        // = valid credentialInfo
                        thisCredentialInfo = null;
                    }
                    // one of the keys is missing
                    else
                    {
                        thisCredentialInfo = null;
                        tempErrorList.Add(credentialInfoErrorMessage);
                        continue;
                    }

                    PSRepositoryInfo currentRepoItem = new PSRepositoryInfo(repo.Attribute("Name").Value,
                                                                            thisUrl,
                                                                            Int32.Parse(repo.Attribute("Priority").Value),
                                                                            Boolean.Parse(repo.Attribute("Trusted").Value),
                                                                            thisCredentialInfo);

                    foundRepos.Add(currentRepoItem);
                }
            }
            else
            {
                foreach (string repo in repoNames)
                {
                    bool            repoMatch           = false;
                    WildcardPattern nameWildCardPattern = new WildcardPattern(repo, WildcardOptions.IgnoreCase);

                    foreach (var node in doc.Descendants("Repository").Where(e => e.Attribute("Name") != null && nameWildCardPattern.IsMatch(e.Attribute("Name").Value)))
                    {
                        if (node.Attribute("Priority") == null)
                        {
                            tempErrorList.Add(String.Format("Repository element does not contain neccessary 'Priority' attribute, in file located at path: {0}. Fix this in your file and run again.", FullRepositoryPath));
                            continue;
                        }

                        if (node.Attribute("Trusted") == null)
                        {
                            tempErrorList.Add(String.Format("Repository element does not contain neccessary 'Trusted' attribute, in file located at path: {0}. Fix this in your file and run again.", FullRepositoryPath));
                            continue;
                        }

                        repoMatch = true;
                        bool urlAttributeExists = node.Attribute("Url") != null;
                        bool uriAttributeExists = node.Attribute("Uri") != null;

                        // case: neither Url nor Uri attributes exist
                        if (!urlAttributeExists && !uriAttributeExists)
                        {
                            tempErrorList.Add(String.Format("Repository element does not contain neccessary 'Url' or equivalent 'Uri' attribute (it must contain one), in file located at path: {0}. Fix this in your file and run again.", FullRepositoryPath));
                            continue;
                        }

                        Uri thisUrl = null;
                        // case: either attribute Uri or Url exists
                        // TODO: do we only allow both to exist, across repositories? (i.e if a file has Uri attribute for one repo and Url attribute for another --> is that invalid?)
                        if (urlAttributeExists)
                        {
                            if (!Uri.TryCreate(node.Attribute("Url").Value, UriKind.Absolute, out thisUrl))
                            {
                                tempErrorList.Add(String.Format("Unable to read incorrectly formatted Url for repo {0}", node.Attribute("Name").Value));
                                continue;
                            }
                        }
                        else if (uriAttributeExists)
                        {
                            if (!Uri.TryCreate(node.Attribute("Uri").Value, UriKind.Absolute, out thisUrl))
                            {
                                tempErrorList.Add(String.Format("Unable to read incorrectly formatted Uri for repo {0}", node.Attribute("Name").Value));
                                continue;
                            }
                        }

                        PSCredentialInfo thisCredentialInfo;
                        string           credentialInfoErrorMessage = $"Repository {node.Attribute("Name").Value} has invalid CredentialInfo. {PSCredentialInfo.VaultNameAttribute} and {PSCredentialInfo.SecretNameAttribute} should both be present and non-empty";
                        // both keys are present
                        if (node.Attribute(PSCredentialInfo.VaultNameAttribute) != null && node.Attribute(PSCredentialInfo.SecretNameAttribute) != null)
                        {
                            try
                            {
                                // both values are non-empty
                                // = valid credentialInfo
                                thisCredentialInfo = new PSCredentialInfo(node.Attribute(PSCredentialInfo.VaultNameAttribute).Value, node.Attribute(PSCredentialInfo.SecretNameAttribute).Value);
                            }
                            catch (Exception)
                            {
                                thisCredentialInfo = null;
                                tempErrorList.Add(credentialInfoErrorMessage);
                                continue;
                            }
                        }
                        // both keys are missing
                        else if (node.Attribute(PSCredentialInfo.VaultNameAttribute) == null && node.Attribute(PSCredentialInfo.SecretNameAttribute) == null)
                        {
                            // = valid credentialInfo
                            thisCredentialInfo = null;
                        }
                        // one of the keys is missing
                        else
                        {
                            thisCredentialInfo = null;
                            tempErrorList.Add(credentialInfoErrorMessage);
                            continue;
                        }

                        PSRepositoryInfo currentRepoItem = new PSRepositoryInfo(node.Attribute("Name").Value,
                                                                                thisUrl,
                                                                                Int32.Parse(node.Attribute("Priority").Value),
                                                                                Boolean.Parse(node.Attribute("Trusted").Value),
                                                                                thisCredentialInfo);

                        foundRepos.Add(currentRepoItem);
                    }

                    if (!repo.Contains("*") && !repoMatch)
                    {
                        tempErrorList.Add(String.Format("Unable to find repository with Name '{0}'.  Use Get-PSResourceRepository to see all available repositories.", repo));
                    }
                }
            }

            errorList = tempErrorList.ToArray();
            // Sort by priority, then by repo name
            var reposToReturn = foundRepos.OrderBy(x => x.Priority).ThenBy(x => x.Name);

            return(reposToReturn.ToList());
        }