public CmdletInfo GetCmdletByTypeName(string cmdletTypeName)
        {
            if (string.IsNullOrEmpty(cmdletTypeName))
            {
                throw PSTraceSource.NewArgumentNullException("cmdletTypeName");
            }
            Exception exception        = null;
            Type      implementingType = LanguagePrimitives.ConvertStringToType(cmdletTypeName, out exception);

            if (exception != null)
            {
                throw exception;
            }
            if (implementingType == null)
            {
                return(null);
            }
            CmdletAttribute attribute = null;

            foreach (object obj2 in implementingType.GetCustomAttributes(true))
            {
                attribute = obj2 as CmdletAttribute;
                if (attribute != null)
                {
                    break;
                }
            }
            if (attribute == null)
            {
                throw PSTraceSource.NewNotSupportedException();
            }
            string nounName = attribute.NounName;

            return(new CmdletInfo(attribute.VerbName + "-" + nounName, implementingType, null, null, this._context));
        }
Beispiel #2
0
 internal void SetRoot(string path)
 {
     if (path == null)
     {
         throw PSTraceSource.NewArgumentNullException("path");
     }
     if (!this.driveBeingCreated)
     {
         throw PSTraceSource.NewNotSupportedException();
     }
     this.root = path;
 }
        /// <summary>
        /// Sets the root of the drive.
        /// </summary>
        /// <param name="path">
        /// The root path to set for the drive.
        /// </param>
        /// <remarks>
        /// This method can only be called during drive
        /// creation. A NotSupportedException if this method
        /// is called outside of drive creation.
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="path"/> is null.
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// If this method gets called any other time except
        /// during drive creation.
        /// </exception>
        internal void SetRoot(string path)
        {
            if (path == null)
            {
                throw PSTraceSource.NewArgumentNullException(nameof(path));
            }

            if (!DriveBeingCreated)
            {
                NotSupportedException e =
                    PSTraceSource.NewNotSupportedException();
                throw e;
            }

            _root = path;
        }
        /// <summary>
        /// Gets an instance of an ISecurityDescriptorCmdletProvider given the provider ID.
        /// </summary>
        /// <param name="providerInstance">
        /// An instance of a CmdletProvider.
        /// </param>
        /// <returns>
        /// An instance of a ISecurityDescriptorCmdletProvider for the specified provider ID.
        /// </returns>
        /// <throws>
        /// ArgumentNullException if providerId is null.
        /// NotSupportedException if the providerId is not for a provider
        /// that is derived from ISecurityDescriptorCmdletProvider.
        /// </throws>
        internal static ISecurityDescriptorCmdletProvider GetPermissionProviderInstance(CmdletProvider providerInstance)
        {
            if (providerInstance == null)
            {
                throw PSTraceSource.NewArgumentNullException(nameof(providerInstance));
            }

            if (!(providerInstance is ISecurityDescriptorCmdletProvider permissionCmdletProvider))
            {
                throw
                    PSTraceSource.NewNotSupportedException(
                        ProviderBaseSecurity.ISecurityDescriptorCmdletProvider_NotSupported);
            }

            return(permissionCmdletProvider);
        }
Beispiel #5
0
        public CommandMetadata(CommandInfo commandInfo, bool shouldGenerateCommonParameters)
        {
            this._commandName             = string.Empty;
            this._defaultParameterSetName = "__AllParameterSets";
            this._positionalBinding       = true;
            this._helpUri            = string.Empty;
            this._remotingCapability = System.Management.Automation.RemotingCapability.PowerShell;
            this._confirmImpact      = System.Management.Automation.ConfirmImpact.Medium;
            this._otherAttributes    = new Collection <Attribute>();
            if (commandInfo == null)
            {
                throw PSTraceSource.NewArgumentNullException("commandInfo");
            }
            while (commandInfo is AliasInfo)
            {
                commandInfo = ((AliasInfo)commandInfo).ResolvedCommand;
                if (commandInfo == null)
                {
                    throw PSTraceSource.NewNotSupportedException();
                }
            }
            CmdletInfo info = commandInfo as CmdletInfo;

            if (info != null)
            {
                this.Init(commandInfo.Name, info.ImplementingType, shouldGenerateCommonParameters);
            }
            else
            {
                ExternalScriptInfo info2 = commandInfo as ExternalScriptInfo;
                if (info2 != null)
                {
                    this.Init(info2.ScriptBlock, info2.Path, shouldGenerateCommonParameters);
                    this._wrappedCommandType = CommandTypes.ExternalScript;
                }
                else
                {
                    FunctionInfo info3 = commandInfo as FunctionInfo;
                    if (info3 == null)
                    {
                        throw PSTraceSource.NewNotSupportedException();
                    }
                    this.Init(info3.ScriptBlock, info3.Name, shouldGenerateCommonParameters);
                    this._wrappedCommandType = commandInfo.CommandType;
                }
            }
        }
        /// <summary>
        /// Get the cmdlet info using the name of the cmdlet's implementing type. This bypasses
        /// session state and retrieves the command directly. Note that the help file and snapin/module
        /// info will both be null on returned object.
        /// </summary>
        /// <param name="cmdletTypeName">The type name of the class implementing this cmdlet.</param>
        /// <returns>CmdletInfo for the cmdlet if found, null otherwise.</returns>
        public CmdletInfo GetCmdletByTypeName(string cmdletTypeName)
        {
            if (string.IsNullOrEmpty(cmdletTypeName))
            {
                throw PSTraceSource.NewArgumentNullException(nameof(cmdletTypeName));
            }

            Exception e          = null;
            Type      cmdletType = TypeResolver.ResolveType(cmdletTypeName, out e);

            if (e != null)
            {
                throw e;
            }

            if (cmdletType == null)
            {
                return(null);
            }

            CmdletAttribute ca = null;

            foreach (var attr in cmdletType.GetCustomAttributes(true))
            {
                ca = attr as CmdletAttribute;
                if (ca != null)
                {
                    break;
                }
            }

            if (ca == null)
            {
                throw PSTraceSource.NewNotSupportedException();
            }

            string noun       = ca.NounName;
            string verb       = ca.VerbName;
            string cmdletName = verb + "-" + noun;

            return(new CmdletInfo(cmdletName, cmdletType, null, null, _context));
        }
Beispiel #7
0
 protected override string PropertyToString(PSProperty property)
 {
     throw PSTraceSource.NewNotSupportedException();
 }
        internal CmdletInfo AddCmdletToCache(string name, CmdletInfo cmdlet, CommandOrigin origin, System.Management.Automation.ExecutionContext context)
        {
            bool flag = false;

            try
            {
                List <CmdletInfo> list;
                if (!this.GetCmdlets().TryGetValue(name, out list))
                {
                    list = new List <CmdletInfo> {
                        cmdlet
                    };
                    this.GetCmdlets().Add(name, list);
                    if ((cmdlet.Options & ScopedItemOptions.AllScope) != ScopedItemOptions.None)
                    {
                        this.GetAllScopeCmdlets()[name].Insert(0, cmdlet);
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(cmdlet.ModuleName))
                    {
                        foreach (CmdletInfo info in list)
                        {
                            if (string.Equals(cmdlet.FullName, info.FullName, StringComparison.OrdinalIgnoreCase))
                            {
                                if (cmdlet.ImplementingType == info.ImplementingType)
                                {
                                    return(null);
                                }
                                flag = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        foreach (CmdletInfo info2 in list)
                        {
                            if (cmdlet.ImplementingType == info2.ImplementingType)
                            {
                                return(null);
                            }
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        list.Insert(0, cmdlet);
                    }
                }
            }
            catch (ArgumentException)
            {
                flag = true;
            }
            if (flag)
            {
                throw PSTraceSource.NewNotSupportedException("DiscoveryExceptions", "DuplicateCmdletName", new object[] { cmdlet.Name });
            }
            return(this.GetCmdlets()[name][0]);
        }
Beispiel #9
0
 public override Pipeline CreateNestedPipeline(string command, bool addToHistory)
 {
     throw PSTraceSource.NewNotSupportedException("RemotingErrorIdStrings", PSRemotingErrorId.NestedPipelineNotSupported.ToString(), new object[0]);
 }
Beispiel #10
0
 protected override string PropertyType(PSProperty property, bool forDisplay)
 {
     throw PSTraceSource.NewNotSupportedException();
 }
Beispiel #11
0
 public override void SuspendJobAsync(bool force, string reason)
 {
     throw PSTraceSource.NewNotSupportedException("PowerShellStrings", "ProxyChildJobControlNotSupported", new object[0]);
 }
Beispiel #12
0
 protected override void PropertySet(PSProperty property, object setValue, bool convertIfPossible)
 {
     throw PSTraceSource.NewNotSupportedException();
 }
 public override object ConvertTo(object sourceValue, Type destinationType, IFormatProvider formatProvider, bool ignoreCase)
 {
     throw PSTraceSource.NewNotSupportedException();
 }
Beispiel #14
0
 protected override bool PropertyIsSettable(PSProperty property)
 {
     throw PSTraceSource.NewNotSupportedException();
 }
Beispiel #15
0
 protected override object PropertyGet(PSProperty property)
 {
     throw PSTraceSource.NewNotSupportedException();
 }
Beispiel #16
0
 protected override object MethodInvoke(PSMethod method, object[] arguments)
 {
     throw PSTraceSource.NewNotSupportedException();
 }
Beispiel #17
0
 protected override Collection <string> MethodDefinitions(PSMethod method)
 {
     throw PSTraceSource.NewNotSupportedException();
 }
Beispiel #18
0
 public override void UnblockJobAsync()
 {
     throw PSTraceSource.NewNotSupportedException("PowerShellStrings", "ProxyChildJobControlNotSupported", new object[0]);
 }