Exemplo n.º 1
0
 protected virtual void NewItem(string path, string itemTypeName, object newItemValue)
 {
     using (PSTransactionManager.GetEngineProtectionScope())
     {
         throw PSTraceSource.NewNotSupportedException("SessionStateStrings", "CmdletProvider_NotSupported", new object[0]);
     }
 }
Exemplo n.º 2
0
 private static void CheckIfSecurityDescriptorInterfaceIsSupported(ISecurityDescriptorCmdletProvider permissionProvider)
 {
     if (permissionProvider == null)
     {
         throw PSTraceSource.NewNotSupportedException("ProviderBaseSecurity", "ISecurityDescriptorCmdletProvider_NotSupported", new object[0]);
     }
 }
Exemplo n.º 3
0
 protected virtual void GetChildItems(string path, bool recurse)
 {
     using (PSTransactionManager.GetEngineProtectionScope())
     {
         throw PSTraceSource.NewNotSupportedException("SessionStateStrings", "CmdletProvider_NotSupported", new object[0]);
     }
 }
Exemplo n.º 4
0
 protected virtual void GetChildNames(string path, ReturnContainers returnContainers)
 {
     using (PSTransactionManager.GetEngineProtectionScope())
     {
         throw PSTraceSource.NewNotSupportedException("SessionStateStrings", "CmdletProvider_NotSupported", new object[0]);
     }
 }
Exemplo n.º 5
0
 protected virtual void InvokeDefaultAction(string path)
 {
     using (PSTransactionManager.GetEngineProtectionScope())
     {
         throw PSTraceSource.NewNotSupportedException("SessionStateStrings", "CmdletProvider_NotSupported", new object[0]);
     }
 }
 protected virtual void MoveItem(string path, string destination)
 {
     using (PSTransactionManager.GetEngineProtectionScope())
     {
         throw PSTraceSource.NewNotSupportedException("SessionStateStrings", "CmdletProvider_NotSupported", new object[0]);
     }
 }
 protected virtual bool IsItemContainer(string path)
 {
     using (PSTransactionManager.GetEngineProtectionScope())
     {
         throw PSTraceSource.NewNotSupportedException("SessionStateStrings", "CmdletProvider_NotSupported", new object[0]);
     }
 }
Exemplo n.º 8
0
 internal PSDriveInfo NewDrive(PSDriveInfo drive, CmdletProviderContext context)
 {
     base.Context = context;
     if (((drive.Credential != null) && (drive.Credential != PSCredential.Empty)) && !CmdletProviderManagementIntrinsics.CheckProviderCapabilities(ProviderCapabilities.Credentials, base.ProviderInfo))
     {
         throw PSTraceSource.NewNotSupportedException("SessionStateStrings", "NewDriveCredentials_NotSupported", new object[0]);
     }
     return(this.NewDrive(drive));
 }
Exemplo n.º 9
0
 /// <summary>
 /// Determines if the item at the specified path has children.
 /// </summary>
 /// <param name="path">
 /// The path to the item to see if it has children.
 /// </param>
 /// <returns>
 /// True if the item has children, false otherwise.
 /// </returns>
 /// <returns>
 /// Nothing is returned, but all objects should be written to the WriteItemObject method.
 /// </returns>
 /// <remarks>
 /// Providers override this method to give the provider infrastructure the ability to determine
 /// if a particular provider object has children without having to retrieve all the child items.
 ///
 /// For implementers of <see cref="ContainerCmdletProvider"/> classes and those derived from it,
 /// if a null or empty path is passed,
 /// the provider should consider any items in the data store to be children
 /// and return true.
 ///
 /// The default implementation of this method throws an <see cref="System.Management.Automation.PSNotSupportedException"/>.
 /// </remarks>
 protected virtual bool HasChildItems(string path)
 {
     using (PSTransactionManager.GetEngineProtectionScope())
     {
         throw
             PSTraceSource.NewNotSupportedException(
                 SessionStateStrings.CmdletProvider_NotSupported);
     }
 }
Exemplo n.º 10
0
 private static void CheckIfSecurityDescriptorInterfaceIsSupported(ISecurityDescriptorCmdletProvider permissionProvider)
 {
     if (permissionProvider is null)
     {
         throw
             PSTraceSource.NewNotSupportedException(
                 ProviderBaseSecurity.ISecurityDescriptorCmdletProvider_NotSupported);
     }
 }
Exemplo n.º 11
0
        internal void ClearProperty(string path, Collection <string> propertyName, CmdletProviderContext cmdletProviderContext)
        {
            this.Context = cmdletProviderContext;
            IPropertyCmdletProvider provider = this as IPropertyCmdletProvider;

            if (provider == null)
            {
                throw PSTraceSource.NewNotSupportedException("SessionStateStrings", "IPropertyCmdletProvider_NotSupported", new object[0]);
            }
            provider.ClearProperty(path, propertyName);
        }
Exemplo n.º 12
0
        internal IContentWriter GetContentWriter(string path, CmdletProviderContext cmdletProviderContext)
        {
            this.Context = cmdletProviderContext;
            IContentCmdletProvider provider = this as IContentCmdletProvider;

            if (provider == null)
            {
                throw PSTraceSource.NewNotSupportedException("SessionStateStrings", "IContentCmdletProvider_NotSupported", new object[0]);
            }
            return(provider.GetContentWriter(path));
        }
Exemplo n.º 13
0
        internal void RenameProperty(string path, string propertyName, string newPropertyName, CmdletProviderContext cmdletProviderContext)
        {
            this.Context = cmdletProviderContext;
            IDynamicPropertyCmdletProvider provider = this as IDynamicPropertyCmdletProvider;

            if (provider == null)
            {
                throw PSTraceSource.NewNotSupportedException("SessionStateStrings", "IDynamicPropertyCmdletProvider_NotSupported", new object[0]);
            }
            provider.RenameProperty(path, propertyName, newPropertyName);
        }
Exemplo n.º 14
0
        internal void ClearContent(string path, CmdletProviderContext cmdletProviderContext)
        {
            this.Context = cmdletProviderContext;
            IContentCmdletProvider provider = this as IContentCmdletProvider;

            if (provider == null)
            {
                throw PSTraceSource.NewNotSupportedException("SessionStateStrings", "IContentCmdletProvider_NotSupported", new object[0]);
            }
            provider.ClearContent(path);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Removes (deletes) the item at the specified path.
 /// </summary>
 /// <param name="path">
 /// The path to the item to remove.
 /// </param>
 /// <param name="recurse">
 /// True if all children in a subtree should be removed, false if only a single
 /// level of children should be removed. This parameter should only be true for
 /// NavigationCmdletProvider and its derived classes.
 /// </param>
 /// <returns>
 /// Nothing should be returned or written from this method.
 /// </returns>
 /// <remarks>
 /// Providers override this method to allow the user the ability to remove provider objects using
 /// the remove-item cmdlet.
 ///
 /// Providers that declare <see cref="System.Management.Automation.Provider.ProviderCapabilities"/>
 /// of ExpandWildcards, Filter, Include, or Exclude should ensure that the path passed meets those
 /// requirements by accessing the appropriate property from the base class.
 ///
 /// By default overrides of this method should not remove objects that are generally hidden from
 /// the user unless the Force property is set to true. For instance, the FileSystem provider should
 /// not remove a hidden or system file unless the Force property is set to true.
 ///
 /// The provider implementation is responsible for preventing infinite recursion when there are
 /// circular links and the like. An appropriate terminating exception should be thrown if this
 /// situation occurs.
 ///
 /// The default implementation of this method throws an <see cref="System.Management.Automation.PSNotSupportedException"/>.
 /// </remarks>
 protected virtual void RemoveItem(
     string path,
     bool recurse)
 {
     using (PSTransactionManager.GetEngineProtectionScope())
     {
         throw
             PSTraceSource.NewNotSupportedException(
                 SessionStateStrings.CmdletProvider_NotSupported);
     }
 }
Exemplo n.º 16
0
        internal void CopyProperty(string sourcePath, string sourceProperty, string destinationPath, string destinationProperty, CmdletProviderContext cmdletProviderContext)
        {
            this.Context = cmdletProviderContext;
            IDynamicPropertyCmdletProvider provider = this as IDynamicPropertyCmdletProvider;

            if (provider == null)
            {
                throw PSTraceSource.NewNotSupportedException("SessionStateStrings", "IDynamicPropertyCmdletProvider_NotSupported", new object[0]);
            }
            provider.CopyProperty(sourcePath, sourceProperty, destinationPath, destinationProperty);
        }
Exemplo n.º 17
0
        internal void SetProperty(string path, PSObject propertyValue, CmdletProviderContext cmdletProviderContext)
        {
            this.Context = cmdletProviderContext;
            IPropertyCmdletProvider provider = this as IPropertyCmdletProvider;

            if (provider == null)
            {
                throw PSTraceSource.NewNotSupportedException("SessionStateStrings", "IPropertyCmdletProvider_NotSupported", new object[0]);
            }
            provider.SetProperty(path, propertyValue);
        }
        private ReturnType ConvertToReturnType(object inputObject)
        {
            Type o = typeof(ReturnType);

            if (!typeof(PSObject).Equals(o) && !typeof(object).Equals(o))
            {
                throw PSTraceSource.NewNotSupportedException();
            }
            ReturnType result = default(ReturnType);

            LanguagePrimitives.TryConvertTo <ReturnType>(inputObject, out result);
            return(result);
        }
Exemplo n.º 19
0
        private PathInfo ResolvePath(string pathToResolve, bool isLiteralPath, bool allowNonexistingPaths, PSCmdlet cmdlet)
        {
            CmdletProviderContext context = new CmdletProviderContext(cmdlet)
            {
                SuppressWildcardExpansion = isLiteralPath
            };
            Collection <PathInfo> targetObject = new Collection <PathInfo>();

            try
            {
                foreach (PathInfo info in cmdlet.SessionState.Path.GetResolvedPSPathFromPSPath(pathToResolve, context))
                {
                    targetObject.Add(info);
                }
            }
            catch (PSNotSupportedException exception)
            {
                cmdlet.ThrowTerminatingError(new ErrorRecord(exception.ErrorRecord, exception));
            }
            catch (DriveNotFoundException exception2)
            {
                cmdlet.ThrowTerminatingError(new ErrorRecord(exception2.ErrorRecord, exception2));
            }
            catch (ProviderNotFoundException exception3)
            {
                cmdlet.ThrowTerminatingError(new ErrorRecord(exception3.ErrorRecord, exception3));
            }
            catch (ItemNotFoundException exception4)
            {
                if (allowNonexistingPaths)
                {
                    ProviderInfo provider = null;
                    PSDriveInfo  drive    = null;
                    string       path     = cmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(pathToResolve, context, out provider, out drive);
                    PathInfo     item     = new PathInfo(drive, provider, path, cmdlet.SessionState);
                    targetObject.Add(item);
                }
                else
                {
                    cmdlet.ThrowTerminatingError(new ErrorRecord(exception4.ErrorRecord, exception4));
                }
            }
            if (targetObject.Count == 1)
            {
                return(targetObject[0]);
            }
            Exception exception5 = PSTraceSource.NewNotSupportedException();

            cmdlet.ThrowTerminatingError(new ErrorRecord(exception5, "NotSupported", ErrorCategory.NotImplemented, targetObject));
            return(null);
        }
Exemplo n.º 20
0
        private PathInfo ResolvePath(string pathToResolve, bool allowNonexistingPaths, CmdletProviderContext currentCommandContext)
        {
            Collection <PathInfo> targetObject = new Collection <PathInfo>();

            try
            {
                foreach (PathInfo info in base.SessionState.Path.GetResolvedPSPathFromPSPath(pathToResolve, currentCommandContext))
                {
                    targetObject.Add(info);
                }
            }
            catch (PSNotSupportedException exception)
            {
                base.WriteError(new ErrorRecord(exception.ErrorRecord, exception));
            }
            catch (System.Management.Automation.DriveNotFoundException exception2)
            {
                base.WriteError(new ErrorRecord(exception2.ErrorRecord, exception2));
            }
            catch (ProviderNotFoundException exception3)
            {
                base.WriteError(new ErrorRecord(exception3.ErrorRecord, exception3));
            }
            catch (ItemNotFoundException exception4)
            {
                if (allowNonexistingPaths)
                {
                    ProviderInfo provider = null;
                    PSDriveInfo  drive    = null;
                    string       path     = base.SessionState.Path.GetUnresolvedProviderPathFromPSPath(pathToResolve, currentCommandContext, out provider, out drive);
                    PathInfo     item     = new PathInfo(drive, provider, path, base.SessionState);
                    targetObject.Add(item);
                }
                else
                {
                    base.WriteError(new ErrorRecord(exception4.ErrorRecord, exception4));
                }
            }
            if (targetObject.Count == 1)
            {
                return(targetObject[0]);
            }
            if (targetObject.Count > 1)
            {
                Exception exception5 = PSTraceSource.NewNotSupportedException();
                base.WriteError(new ErrorRecord(exception5, "NotSupported", ErrorCategory.NotImplemented, targetObject));
                return(null);
            }
            return(null);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Converts to the return type based on language primitives
        /// </summary>
        /// <param name="inputObject">input object to convert</param>
        /// <returns>input object converted to the specified return type</returns>
        private ReturnType ConvertToReturnType(object inputObject)
        {
            Type resultType = typeof(ReturnType);
            if (typeof(PSObject) == resultType || typeof(object) == resultType)
            {
                ReturnType result;
                LanguagePrimitives.TryConvertTo(inputObject, out result);
                return result;
            }

            System.Management.Automation.Diagnostics.Assert(false,
                "ReturnType should be either object or PSObject only");
            throw PSTraceSource.NewNotSupportedException();
        }
Exemplo n.º 22
0
        private StreamReader OpenFile(out string filePath, bool isLiteralPath)
        {
            StreamReader reader = null;

            filePath = null;
            ProviderInfo        provider = null;
            Collection <string> resolvedProviderPathFromPSPath = null;

            if (isLiteralPath)
            {
                PSDriveInfo info2;
                resolvedProviderPathFromPSPath = new Collection <string> {
                    base.SessionState.Path.GetUnresolvedProviderPathFromPSPath(this.Path, out provider, out info2)
                };
            }
            else
            {
                resolvedProviderPathFromPSPath = base.SessionState.Path.GetResolvedProviderPathFromPSPath(this.Path, out provider);
            }
            if (!provider.NameEquals(base.Context.ProviderNames.FileSystem))
            {
                throw PSTraceSource.NewNotSupportedException("AliasCommandStrings", "ImportAliasFromFileSystemOnly", new object[] { this.Path, provider.FullName });
            }
            if (resolvedProviderPathFromPSPath.Count != 1)
            {
                throw PSTraceSource.NewNotSupportedException("AliasCommandStrings", "ImportAliasPathResolvedToMultiple", new object[] { this.Path });
            }
            filePath = resolvedProviderPathFromPSPath[0];
            try
            {
                FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                reader = new StreamReader(stream);
            }
            catch (IOException exception)
            {
                this.ThrowFileOpenError(exception, filePath);
            }
            catch (SecurityException exception2)
            {
                this.ThrowFileOpenError(exception2, filePath);
            }
            catch (UnauthorizedAccessException exception3)
            {
                this.ThrowFileOpenError(exception3, filePath);
            }
            return(reader);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Internal wrapper for the NewDrive protected method. It is called instead
        /// of the protected method that is overridden by derived classes so that the
        /// context of the command can be set.
        /// </summary>
        /// <param name="drive">
        /// The PSDriveInfo object the represents the drive to be mounted.
        /// </param>
        /// <param name="context">
        /// The context under which this method is being called.
        /// </param>
        /// <returns>
        /// The drive that was returned from the protected NewDrive method.
        /// </returns>
        internal PSDriveInfo NewDrive(PSDriveInfo drive, CmdletProviderContext context)
        {
            Context = context;

            // Make sure the provider supports credentials if they were passed
            // in the drive.

            if (drive.Credential != null &&
                drive.Credential != PSCredential.Empty &&
                !CmdletProviderManagementIntrinsics.CheckProviderCapabilities(ProviderCapabilities.Credentials, ProviderInfo))
            {
                throw PSTraceSource.NewNotSupportedException(
                          SessionStateStrings.NewDriveCredentials_NotSupported);
            }

            return(NewDrive(drive));
        }
Exemplo n.º 24
0
 /// <summary>
 /// Gets the children of the item at the specified path.
 /// </summary>
 /// <param name="path">
 /// The path (or name in a flat namespace) to the item from which to retrieve the children.
 /// </param>
 /// <param name="recurse">
 /// True if all children in a subtree should be retrieved, false if only a single
 /// level of children should be retrieved. This parameter should only be true for
 /// the NavigationCmdletProvider derived class.
 /// </param>
 /// <param name="depth">
 /// Limits the depth of recursion; uint.MaxValue performs full recursion.
 /// </param>
 /// <returns>
 /// Nothing is returned, but all objects should be written to the WriteItemObject method.
 /// </returns>
 /// <remarks>
 /// Providers override this method to give the user access to the provider objects using
 /// the get-childitem cmdlets.
 ///
 /// Providers that declare <see cref="System.Management.Automation.Provider.ProviderCapabilities"/>
 /// of ExpandWildcards, Filter, Include, or Exclude should ensure that the path passed meets those
 /// requirements by accessing the appropriate property from the base class.
 ///
 /// By default overrides of this method should not write objects that are generally hidden from
 /// the user unless the Force property is set to true. For instance, the FileSystem provider should
 /// not call WriteItemObject for hidden or system files unless the Force property is set to true.
 ///
 /// The provider implementation is responsible for preventing infinite recursion when there are
 /// circular links and the like. An appropriate terminating exception should be thrown if this
 /// situation occurs.
 ///
 /// The default implementation of this method throws an <see cref="System.Management.Automation.PSNotSupportedException"/>.
 /// </remarks>
 protected virtual void GetChildItems(
     string path,
     bool recurse,
     uint depth)
 {
     using (PSTransactionManager.GetEngineProtectionScope())
     {
         if (depth == uint.MaxValue)
         {
             this.GetChildItems(path, recurse);
         }
         else
         {
             throw
                 PSTraceSource.NewNotSupportedException(
                     SessionStateStrings.CmdletProvider_NotSupportedRecursionDepth);
         }
     }
 }
        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));
        }
Exemplo n.º 26
0
        protected override void BeginProcessing()
        {
            InternalHost host = base.Host as InternalHost;

            if (host != null)
            {
                ConsoleHost externalHost = host.ExternalHost as ConsoleHost;
                if (externalHost != null)
                {
                    if (!externalHost.IsTranscribing)
                    {
                        base.WriteObject(TranscriptStrings.TranscriptionNotInProgress);
                    }
                    try
                    {
                        string str = externalHost.StopTranscribing();
                        base.WriteObject(StringUtil.Format(TranscriptStrings.TranscriptionStopped, str));
                    }
                    catch (Exception exception1)
                    {
                        Exception exception = exception1;
                        ConsoleHost.CheckForSevereException(exception);
                        object[] message = new object[1];
                        message[0] = exception.Message;
                        throw PSTraceSource.NewInvalidOperationException(exception, "TranscriptStrings", "ErrorStoppingTranscript", message);
                    }
                    return;
                }
                else
                {
                    throw PSTraceSource.NewNotSupportedException("TranscriptStrings", "HostDoesNotSupportTranscript", new object[0]);
                }
            }
            else
            {
                throw PSTraceSource.NewNotSupportedException("TranscriptStrings", "HostDoesNotSupportTranscript", new object[0]);
            }
        }
Exemplo n.º 27
0
 internal virtual Hashtable CreateHashtableFromSingleType(object val)
 {
     // NOTE: must override for the default type(s) entry
     // this entry will have to expand the object into a hash table
     throw PSTraceSource.NewNotSupportedException();
 }
Exemplo n.º 28
0
        /// <summary>
        /// Resolves the specified path to PathInfo objects
        /// </summary>
        ///
        /// <param name="pathToResolve">
        /// The path 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="currentCommandContext">
        /// The context under which the command is running.
        /// </param>
        ///
        /// <returns>
        /// A string representing the resolved path.
        /// </returns>
        ///
        private PathInfo ResolvePath(
            string pathToResolve,
            bool allowNonexistingPaths,
            CmdletProviderContext currentCommandContext)
        {
            Collection <PathInfo> results = new Collection <PathInfo>();

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

                foreach (PathInfo pathInfo in pathInfos)
                {
                    results.Add(pathInfo);
                }
            }
            catch (PSNotSupportedException notSupported)
            {
                WriteError(
                    new ErrorRecord(
                        notSupported.ErrorRecord,
                        notSupported));
            }
            catch (System.Management.Automation.DriveNotFoundException driveNotFound)
            {
                WriteError(
                    new ErrorRecord(
                        driveNotFound.ErrorRecord,
                        driveNotFound));
            }
            catch (ProviderNotFoundException providerNotFound)
            {
                WriteError(
                    new ErrorRecord(
                        providerNotFound.ErrorRecord,
                        providerNotFound));
            }
            catch (ItemNotFoundException pathNotFound)
            {
                if (allowNonexistingPaths)
                {
                    ProviderInfo provider = null;
                    System.Management.Automation.PSDriveInfo drive = null;
                    string unresolvedPath =
                        SessionState.Path.GetUnresolvedProviderPathFromPSPath(
                            pathToResolve,
                            currentCommandContext,
                            out provider,
                            out drive);

                    PathInfo pathInfo =
                        new PathInfo(
                            drive,
                            provider,
                            unresolvedPath,
                            SessionState);
                    results.Add(pathInfo);
                }
                else
                {
                    WriteError(
                        new ErrorRecord(
                            pathNotFound.ErrorRecord,
                            pathNotFound));
                }
            }

            if (results.Count == 1)
            {
                return(results[0]);
            }
            else if (results.Count > 1)
            {
                Exception e = PSTraceSource.NewNotSupportedException();
                WriteError(
                    new ErrorRecord(e,
                                    "NotSupported",
                                    ErrorCategory.NotImplemented,
                                    results));
                return(null);
            }
            else
            {
                return(null);
            }
        } // ResolvePath
Exemplo n.º 29
0
 /// <summary>
 /// Connects asynchronously to a running command on a remote server.
 /// </summary>
 public override void ConnectAsync()
 {
     // Connect semantics not supported on local (non-remoting) pipelines.
     throw PSTraceSource.NewNotSupportedException(PipelineStrings.ConnectNotSupported);
 }
Exemplo n.º 30
0
 /// <summary>
 /// Connects synchronously to a running command on a remote server.
 /// The pipeline object must be in the disconnected state.
 /// </summary>
 /// <returns>A collection of result objects.</returns>
 public override Collection <PSObject> Connect()
 {
     // Connect semantics not supported on local (non-remoting) pipelines.
     throw PSTraceSource.NewNotSupportedException(PipelineStrings.ConnectNotSupported);
 }