Exemplo n.º 1
0
        private bool VerifyShadowingExistingCommandsAndWriteError(string aliasName)
        {
            CommandSearcher searcher = new CommandSearcher(aliasName, SearchResolutionOptions.None, CommandTypes.All ^ CommandTypes.Alias, this.Context);

            foreach (string expandedCommandName in searcher.ConstructSearchPatternsFromName(aliasName))
            {
                CommandTypes commandTypeOfExistingCommand;
                if (this.ExistingCommands.TryGetValue(expandedCommandName, out commandTypeOfExistingCommand))
                {
                    // Since the alias already exists, write an error.
                    SessionStateException aliasExists =
                        new SessionStateException(
                            aliasName,
                            SessionStateCategory.Alias,
                            "AliasAlreadyExists",
                            SessionStateStrings.AliasWithCommandNameAlreadyExists,
                            ErrorCategory.ResourceExists,
                            commandTypeOfExistingCommand);

                    WriteError(
                        new ErrorRecord(
                            aliasExists.ErrorRecord,
                            aliasExists));
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        private bool IsShadowingExistingCommands(string commandName)
        {
            commandName = ModuleCmdletBase.AddPrefixToCommandName(commandName, this.Prefix);
            CommandSearcher searcher = new CommandSearcher(commandName, SearchResolutionOptions.None, CommandTypes.All, base.Context);

            foreach (string str in searcher.ConstructSearchPatternsFromName(commandName))
            {
                if (this.ExistingCommands.ContainsKey(str))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        private bool VerifyShadowingExistingCommandsAndWriteError(string aliasName)
        {
            CommandSearcher searcher = new CommandSearcher(aliasName, SearchResolutionOptions.None, CommandTypes.Workflow | CommandTypes.Script | CommandTypes.Application | CommandTypes.ExternalScript | CommandTypes.Cmdlet | CommandTypes.Filter | CommandTypes.Function, base.Context);

            foreach (string str in searcher.ConstructSearchPatternsFromName(aliasName))
            {
                CommandTypes types;
                if (this.ExistingCommands.TryGetValue(str, out types))
                {
                    SessionStateException replaceParentContainsErrorRecordException = new SessionStateException(aliasName, SessionStateCategory.Alias, "AliasAlreadyExists", SessionStateStrings.AliasWithCommandNameAlreadyExists, ErrorCategory.ResourceExists, new object[] { types });
                    base.WriteError(new ErrorRecord(replaceParentContainsErrorRecordException.ErrorRecord, replaceParentContainsErrorRecordException));
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 4
0
 private bool VerifyShadowingExistingCommandsAndWriteError(string aliasName)
 {
     CommandSearcher searcher = new CommandSearcher(aliasName, SearchResolutionOptions.None, CommandTypes.Workflow | CommandTypes.Script | CommandTypes.Application | CommandTypes.ExternalScript | CommandTypes.Cmdlet | CommandTypes.Filter | CommandTypes.Function, base.Context);
     foreach (string str in searcher.ConstructSearchPatternsFromName(aliasName))
     {
         CommandTypes types;
         if (this.ExistingCommands.TryGetValue(str, out types))
         {
             SessionStateException replaceParentContainsErrorRecordException = new SessionStateException(aliasName, SessionStateCategory.Alias, "AliasAlreadyExists", SessionStateStrings.AliasWithCommandNameAlreadyExists, ErrorCategory.ResourceExists, new object[] { types });
             base.WriteError(new ErrorRecord(replaceParentContainsErrorRecordException.ErrorRecord, replaceParentContainsErrorRecordException));
             return true;
         }
     }
     return false;
 }
Exemplo n.º 5
0
        private bool VerifyShadowingExistingCommandsAndWriteError(string aliasName)
        {
            CommandSearcher searcher = new CommandSearcher(aliasName, SearchResolutionOptions.None, CommandTypes.All ^ CommandTypes.Alias, this.Context);
            foreach (string expandedCommandName in searcher.ConstructSearchPatternsFromName(aliasName))
            {
                CommandTypes commandTypeOfExistingCommand;
                if (this.ExistingCommands.TryGetValue(expandedCommandName, out commandTypeOfExistingCommand))
                {
                    // Since the alias already exists, write an error.
                    SessionStateException aliasExists =
                        new SessionStateException(
                            aliasName,
                            SessionStateCategory.Alias,
                            "AliasAlreadyExists",
                            SessionStateStrings.AliasWithCommandNameAlreadyExists,
                            ErrorCategory.ResourceExists,
                            commandTypeOfExistingCommand);

                    WriteError(
                        new ErrorRecord(
                            aliasExists.ErrorRecord,
                            aliasExists));
                    return true;
                }
            }

            return false;
        }