/// <summary>
        /// Gets the path to the parent object for the given object
        /// </summary>
        /// 
        /// <param name="path">
        /// The path to the object to get the parent path from
        /// </param>
        /// 
        /// <param name="root">
        /// The root of the drive.
        /// </param>
        /// 
        /// <returns>
        /// The path to the parent object
        /// </returns>
        /// 
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="path"/> is null.
        /// </exception>
        /// 
        /// <exception cref="NotSupportedException">
        /// If the <paramref name="providerInstance"/> does not support this operation.
        /// </exception>
        /// 
        /// <exception cref="PipelineStoppedException">
        /// If the pipeline is being stopped while executing the command.
        /// </exception>
        /// 
        /// <exception cref="ProviderInvocationException">
        /// If the provider threw an exception.
        /// </exception>
        /// 
        internal string GetParentPath(string path, string root)
        {
            if (path == null)
            {
                throw PSTraceSource.NewArgumentNullException("path");
            }

            CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);

            string result = GetParentPath(path, root, context);

            context.ThrowFirstErrorOrDoNothing();

            return result;
        } //GetParentPath
        /// <summary>
        /// Called by the base class before the streams are open for the path.
        /// This override clears the content from the item. 
        /// </summary>
        /// 
        /// <param name="paths">
        /// The path to the items that will be opened for writing content.
        /// </param>
        /// 
        internal override void BeforeOpenStreams(string[] paths)
        {
            if (paths == null ||
                (paths != null && paths.Length == 0))
            {
                throw PSTraceSource.NewArgumentNullException("paths");
            }

            CmdletProviderContext context = new CmdletProviderContext(GetCurrentContext());

            foreach (string path in paths)
            {
                try
                {
                    InvokeProvider.Content.Clear(path, context);
                    context.ThrowFirstErrorOrDoNothing(true);
                }
                catch (PSNotSupportedException)
                {
                    // If the provider doesn't support clear, that is fine. Continue
                    // on with the setting of the content.
                    continue;
                }
                catch (DriveNotFoundException driveNotFound)
                {
                    WriteError(
                        new ErrorRecord(
                            driveNotFound.ErrorRecord,
                            driveNotFound));
                    continue;
                }
                catch (ProviderNotFoundException providerNotFound)
                {
                    WriteError(
                        new ErrorRecord(
                            providerNotFound.ErrorRecord,
                            providerNotFound));
                    continue;
                }
                catch (ItemNotFoundException)
                {
                    //If the item is not found then there is nothing to clear so ignore this exception.
                    continue;
                }
            }
        } // BeforeOpenStreams
        /// <summary>
        /// Determines if the monad virtual namespace path exists.
        /// </summary>
        /// 
        /// <param name="path">
        /// The path to the object to determine if it exists.
        /// </param>
        /// 
        /// <param name="force">
        /// Passed on to providers to force operations.
        /// </param>
        /// 
        /// <param name="literalPath">
        /// If true, globbing is not done on paths.
        /// </param>
        /// 
        /// <returns>
        /// true if the object specified by path exists, false otherwise.
        /// </returns>
        /// 
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="path"/> is null.
        /// </exception>
        /// 
        /// <exception cref="ProviderNotFoundException">
        /// If the <paramref name="path"/> refers to a provider that could not be found.
        /// </exception>
        /// 
        /// <exception cref="DriveNotFoundException">
        /// If the <paramref name="path"/> refers to a drive that could not be found.
        /// </exception>
        /// 
        /// <exception cref="NotSupportedException">
        /// If the provider that the <paramref name="path"/> refers to does
        /// not support this operation.
        /// </exception>
        /// 
        /// <exception cref="ProviderInvocationException">
        /// If the provider threw an exception.
        /// </exception>
        /// 
        internal bool ItemExists(string path, bool force, bool literalPath)
        {
            if (path == null)
            {
                throw PSTraceSource.NewArgumentNullException("path");
            }

            CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);
            context.Force = force;
            context.SuppressWildcardExpansion = literalPath;

            bool result = ItemExists(path, context);

            context.ThrowFirstErrorOrDoNothing();

            return result;
        } // ItemExists
        /// <summary>
        /// Gets the content reader for the specified item.
        /// </summary>
        /// 
        /// <param name="paths">
        /// The path(s) to the item(s) to get the content reader for.
        /// </param>
        /// 
        /// <param name="force">
        /// Passed on to providers to force operations.
        /// </param>
        /// 
        /// <param name="literalPath">
        /// If true, globbing is not done on paths.
        /// </param>
        /// 
        /// <returns>
        /// The content readers for all items that the path resolves to.
        /// </returns>
        /// 
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="path"/> is null.
        /// </exception>
        /// 
        /// <exception cref="ProviderNotFoundException">
        /// If the <paramref name="path"/> refers to a provider that could not be found.
        /// </exception>
        /// 
        /// <exception cref="DriveNotFoundException">
        /// If the <paramref name="path"/> refers to a drive that could not be found.
        /// </exception>
        /// 
        /// <exception cref="NotSupportedException">
        /// If the provider that the <paramref name="path"/> refers to does
        /// not support this operation.
        /// </exception>
        /// 
        /// <exception cref="ProviderInvocationException">
        /// If the provider threw an exception.
        /// </exception>
        /// 
        internal Collection<IContentReader> GetContentReader(string[] paths, bool force, bool literalPath)
        {
            if (paths == null)
            {
                throw PSTraceSource.NewArgumentNullException("paths");
            }

            CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);
            context.Force = force;
            context.SuppressWildcardExpansion = literalPath;

            Collection<IContentReader> results = GetContentReader(paths, context);

            context.ThrowFirstErrorOrDoNothing();

            return results;
        } // GetContentReader
        /// <summary>
        /// Gets the specified properties from the specified item.
        /// </summary>
        /// 
        /// <param name="paths">
        /// The path(s) to the item(s) to get the properties from.
        /// </param>
        /// 
        /// <param name="providerSpecificPickList">
        /// A list of the properties that the provider should return.
        /// </param>
        /// 
        /// <param name="literalPath">
        /// If true, globbing is not done on paths.
        /// </param>
        /// 
        /// <returns>
        /// A property table container the properties and their values.
        /// </returns>
        /// 
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="path"/> is null.
        /// </exception>
        /// 
        /// <exception cref="ProviderNotFoundException">
        /// If the <paramref name="path"/> refers to a provider that could not be found.
        /// </exception>
        /// 
        /// <exception cref="DriveNotFoundException">
        /// If the <paramref name="path"/> refers to a drive that could not be found.
        /// </exception>
        /// 
        /// <exception cref="NotSupportedException">
        /// If the provider that the <paramref name="path"/> refers to does
        /// not support this operation.
        /// </exception>
        /// 
        /// <exception cref="ProviderInvocationException">
        /// If the provider threw an exception.
        /// </exception>
        /// 
        internal Collection<PSObject> GetProperty(
            string[] paths,
            Collection<string> providerSpecificPickList,
            bool literalPath)
        {
            if (paths == null)
            {
                throw PSTraceSource.NewArgumentNullException("path");
            }

            CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);
            context.SuppressWildcardExpansion = literalPath;

            GetProperty(paths, providerSpecificPickList, context);

            context.ThrowFirstErrorOrDoNothing();

            Collection<PSObject> results = context.GetAccumulatedObjects();

            return results;
        } // GetProperties
Exemple #6
0
        /// <summary>
        /// Gets the specified object
        /// </summary>
        /// 
        /// <param name="paths">
        /// The path(s) to the object(s). They can be either a relative (most common)
        /// or absolute path.
        /// </param>
        /// 
        /// <param name="force">
        /// Passed on to providers to force operations.
        /// </param>
        /// 
        /// <param name="literalPath">
        /// If true, globbing is not done on paths.
        /// </param>
        /// 
        /// <returns>
        /// The item at the specified path.
        /// </returns>
        /// 
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="path"/> is null.
        /// </exception>
        /// 
        /// <exception cref="ProviderNotFoundException">
        /// If the <paramref name="path"/> refers to a provider that could not be found.
        /// </exception>
        /// 
        /// <exception cref="DriveNotFoundException">
        /// If the <paramref name="path"/> refers to a drive that could not be found.
        /// </exception>
        /// 
        /// <exception cref="NotSupportedException">
        /// If the provider that the <paramref name="path"/> refers to does
        /// not support this operation.
        /// </exception>
        /// 
        /// <exception cref="ProviderInvocationException">
        /// If the provider threw an exception.
        /// </exception>
        /// 
        internal Collection<PSObject> GetItem(string[] paths, bool force, bool literalPath)
        {
            if (paths == null)
            {
                throw PSTraceSource.NewArgumentNullException("paths");
            }

            CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);
            context.Force = force;
            context.SuppressWildcardExpansion = literalPath;

            GetItem(paths, context);

            context.ThrowFirstErrorOrDoNothing();

            // Since there was not errors return the accumulated objects

            Collection<PSObject> results = context.GetAccumulatedObjects();

            return results;
        } // GetItem
Exemple #7
0
		internal override void BeforeOpenStreams(string[] paths)
		{
			if (paths == null || paths != null && (int)paths.Length == 0)
			{
				throw PSTraceSource.NewArgumentNullException("paths");
			}
			else
			{
				CmdletProviderContext cmdletProviderContext = new CmdletProviderContext(base.GetCurrentContext());
				string[] strArrays = paths;
				for (int i = 0; i < (int)strArrays.Length; i++)
				{
					string str = strArrays[i];
					try
					{
						base.InvokeProvider.Content.Clear(str, cmdletProviderContext);
						cmdletProviderContext.ThrowFirstErrorOrDoNothing(true);
					}
					catch (PSNotSupportedException pSNotSupportedException)
					{
					}
					catch (DriveNotFoundException driveNotFoundException1)
					{
						DriveNotFoundException driveNotFoundException = driveNotFoundException1;
						base.WriteError(new ErrorRecord(driveNotFoundException.ErrorRecord, driveNotFoundException));
					}
					catch (ProviderNotFoundException providerNotFoundException1)
					{
						ProviderNotFoundException providerNotFoundException = providerNotFoundException1;
						base.WriteError(new ErrorRecord(providerNotFoundException.ErrorRecord, providerNotFoundException));
					}
					catch (ItemNotFoundException itemNotFoundException)
					{
					}
				}
				return;
			}
		}
        } // SetLocation

        /// <summary>
        /// Determines if the specified path is the current working directory
        /// or a parent of the current working directory.
        /// </summary>
        /// <param name="path">
        /// A monad namespace absolute or relative path.
        /// </param>
        /// <param name="context">
        /// The context the provider uses when performing the operation.
        /// </param>
        /// <returns>
        /// true, if the path is the current working directory or a parent of the current
        /// working directory. false, otherwise.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="path"/> is null.
        /// </exception>
        /// <exception cref="ProviderNotFoundException">
        /// If the path is a provider-qualified path for a provider that is
        /// not loaded into the system.
        /// </exception>
        /// <exception cref="DriveNotFoundException">
        /// If the <paramref name="path"/> refers to a drive that could not be found.
        /// </exception>
        /// <exception cref="ProviderInvocationException">
        /// If the provider used to build the path threw an exception.
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// If the provider that the <paramref name="path"/> represents is not a NavigationCmdletProvider
        /// or ContainerCmdletProvider.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// If the <paramref name="path"/> starts with "~" and the home location is not set for
        /// the provider.
        /// </exception>
        /// <exception cref="ProviderInvocationException">
        /// If the provider specified by <paramref name="providerId"/> threw an
        /// exception when its GetParentPath or MakePath was called while
        /// processing the <paramref name="path"/>.
        /// </exception>
        internal bool IsCurrentLocationOrAncestor(string path, CmdletProviderContext context)
        {
            bool result = false;

            if (path == null)
            {
                throw PSTraceSource.NewArgumentNullException("path");
            }

            PSDriveInfo  drive    = null;
            ProviderInfo provider = null;

            string providerSpecificPath =
                Globber.GetProviderPath(
                    path,
                    context,
                    out provider,
                    out drive);

            if (drive != null)
            {
                s_tracer.WriteLine("Tracing drive");
                drive.Trace();
            }

            Dbg.Diagnostics.Assert(
                providerSpecificPath != null,
                "There should always be a way to generate a provider path for a " +
                "given path");

            if (drive != null)
            {
                context.Drive = drive;
            }

            // Check to see if the path that was specified is within the current
            // working drive

            if (drive == CurrentDrive)
            {
                // The path needs to be normalized to get rid of relative path tokens
                // so they don't interfere with our path comparisons below

                CmdletProviderContext normalizePathContext
                    = new CmdletProviderContext(context);

                try
                {
                    providerSpecificPath = NormalizeRelativePath(path, null, normalizePathContext);
                }
                catch (NotSupportedException)
                {
                    // Since the provider does not support normalizing the path, just
                    // use the path we currently have.
                }
                catch (LoopFlowException)
                {
                    throw;
                }
                catch (PipelineStoppedException)
                {
                    throw;
                }
                catch (ActionPreferenceStopException)
                {
                    throw;
                }
                finally
                {
                    normalizePathContext.RemoveStopReferral();
                }

                if (normalizePathContext.HasErrors())
                {
                    normalizePathContext.ThrowFirstErrorOrDoNothing();
                }

                s_tracer.WriteLine("Provider path = {0}", providerSpecificPath);

                // Get the current working directory provider specific path

                PSDriveInfo  currentWorkingDrive  = null;
                ProviderInfo currentDriveProvider = null;

                string currentWorkingPath =
                    Globber.GetProviderPath(
                        ".",
                        context,
                        out currentDriveProvider,
                        out currentWorkingDrive);

                Dbg.Diagnostics.Assert(
                    currentWorkingDrive == CurrentDrive,
                    "The current working drive should be the CurrentDrive.");

                s_tracer.WriteLine(
                    "Current working path = {0}",
                    currentWorkingPath);

                // See if the path is the current working directory or a parent
                // of the current working directory

                s_tracer.WriteLine(
                    "Comparing {0} to {1}",
                    providerSpecificPath,
                    currentWorkingPath);

                if (String.Compare(providerSpecificPath, currentWorkingPath, StringComparison.CurrentCultureIgnoreCase) == 0)
                {
                    // The path is the current working directory so
                    // return true

                    s_tracer.WriteLine("The path is the current working directory");

                    result = true;
                }
                else
                {
                    // Check to see if the specified path is a parent
                    // of the current working directory

                    string lockedDirectory = currentWorkingPath;

                    while (lockedDirectory.Length > 0)
                    {
                        // We need to allow the provider to go as far up the tree
                        // as it can even if that means it has to traverse higher
                        // than the mount point for this drive. That is
                        // why we are passing the empty string as the root here.

                        lockedDirectory =
                            GetParentPath(
                                drive.Provider,
                                lockedDirectory,
                                String.Empty,
                                context);

                        s_tracer.WriteLine(
                            "Comparing {0} to {1}",
                            lockedDirectory,
                            providerSpecificPath);

                        if (String.Compare(lockedDirectory, providerSpecificPath, StringComparison.CurrentCultureIgnoreCase) == 0)
                        {
                            // The path is a parent of the current working
                            // directory

                            s_tracer.WriteLine(
                                "The path is a parent of the current working directory: {0}",
                                lockedDirectory);

                            result = true;
                            break;
                        }
                    }
                }
            }
            else
            {
                s_tracer.WriteLine("Drives are not the same");
            }

            return(result);
        } // IsCurrentLocationOrAncestor
 internal ProviderInfo NewProvider(ProviderInfo provider)
 {
     if (provider == null)
     {
         throw PSTraceSource.NewArgumentNullException("provider");
     }
     ProviderInfo info = this.ProviderExists(provider);
     if (info != null)
     {
         if (info.ImplementingType == provider.ImplementingType)
         {
             return info;
         }
         SessionStateException exception = new SessionStateException(provider.Name, SessionStateCategory.CmdletProvider, "CmdletProviderAlreadyExists", SessionStateStrings.CmdletProviderAlreadyExists, ErrorCategory.ResourceExists, new object[0]);
         throw exception;
     }
     CmdletProvider providerInstance = provider.CreateInstance();
     CmdletProviderContext cmdletProviderContext = new CmdletProviderContext(this.ExecutionContext);
     ProviderInfo providerInfoToSet = null;
     try
     {
         providerInfoToSet = providerInstance.Start(provider, cmdletProviderContext);
         providerInstance.SetProviderInformation(providerInfoToSet);
     }
     catch (LoopFlowException)
     {
         throw;
     }
     catch (PipelineStoppedException)
     {
         throw;
     }
     catch (ActionPreferenceStopException)
     {
         throw;
     }
     catch (InvalidOperationException)
     {
         throw;
     }
     catch (Exception exception2)
     {
         CommandProcessorBase.CheckForSevereException(exception2);
         throw this.NewProviderInvocationException("ProviderStartException", SessionStateStrings.ProviderStartException, provider, null, exception2);
     }
     cmdletProviderContext.ThrowFirstErrorOrDoNothing(true);
     if (providerInfoToSet == null)
     {
         throw PSTraceSource.NewInvalidOperationException("SessionStateStrings", "InvalidProviderInfoNull", new object[0]);
     }
     if (providerInfoToSet != provider)
     {
         if (!string.Equals(providerInfoToSet.Name, provider.Name, StringComparison.OrdinalIgnoreCase))
         {
             throw PSTraceSource.NewInvalidOperationException("SessionStateStrings", "InvalidProviderInfo", new object[0]);
         }
         provider = providerInfoToSet;
     }
     try
     {
         this.NewProviderEntry(provider);
     }
     catch (ArgumentException)
     {
         SessionStateException exception3 = new SessionStateException(provider.Name, SessionStateCategory.CmdletProvider, "CmdletProviderAlreadyExists", SessionStateStrings.CmdletProviderAlreadyExists, ErrorCategory.ResourceExists, new object[0]);
         throw exception3;
     }
     this.ProvidersCurrentWorkingDrive.Add(provider, null);
     bool flag = false;
     try
     {
         this.InitializeProvider(providerInstance, provider, cmdletProviderContext);
         cmdletProviderContext.ThrowFirstErrorOrDoNothing(true);
     }
     catch (LoopFlowException)
     {
         throw;
     }
     catch (PipelineStoppedException)
     {
         flag = true;
         throw;
     }
     catch (ActionPreferenceStopException)
     {
         flag = true;
         throw;
     }
     catch (NotSupportedException)
     {
         flag = false;
     }
     catch (SessionStateException)
     {
         flag = true;
         throw;
     }
     finally
     {
         if (flag)
         {
             this.Providers.Remove(provider.Name.ToString());
             this.ProvidersCurrentWorkingDrive.Remove(provider);
             provider = null;
         }
     }
     return provider;
 }
Exemple #10
0
 internal Collection<PSObject> CopyProperty(string[] sourcePaths, string sourceProperty, string destinationPath, string destinationProperty, bool force, bool literalPath)
 {
     if (sourcePaths == null)
     {
         throw PSTraceSource.NewArgumentNullException("sourcePaths");
     }
     if (sourceProperty == null)
     {
         throw PSTraceSource.NewArgumentNullException("sourceProperty");
     }
     if (destinationPath == null)
     {
         throw PSTraceSource.NewArgumentNullException("destinationPath");
     }
     if (destinationProperty == null)
     {
         throw PSTraceSource.NewArgumentNullException("destinationProperty");
     }
     CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext) {
         Force = force,
         SuppressWildcardExpansion = literalPath
     };
     this.CopyProperty(sourcePaths, sourceProperty, destinationPath, destinationProperty, context);
     context.ThrowFirstErrorOrDoNothing();
     return context.GetAccumulatedObjects();
 }
Exemple #11
0
        } // SetLocation

        /// <summary>
        /// Changes the current working directory to the path specified
        /// </summary>
        ///
        /// <param name="path">
        /// The path of the new current working directory
        /// </param>
        ///
        /// <param name="context">
        /// The context the provider uses when performing the operation.
        /// </param>
        ///
        /// <returns>
        /// The PathInfo object representing the path of the location
        /// that was set.
        /// </returns>
        ///
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="path"/> is null.
        /// </exception>
        ///
        /// <exception cref="ArgumentException">
        /// If <paramref name="path"/> does not exist, is not a container, or
        /// resolved to multiple containers.
        /// </exception>
        ///
        /// <exception cref="ProviderNotFoundException">
        /// If <paramref name="path"/> refers to a provider that does not exist.
        /// </exception>
        ///
        /// <exception cref="DriveNotFoundException">
        /// If <paramref name="path"/> refers to a drive that does not exist.
        /// </exception>
        ///
        /// <exception cref="ProviderInvocationException">
        /// If the provider associated with <paramref name="path"/> threw an
        /// exception.
        /// </exception>
        ///
        /// <exception cref="ItemNotFoundException">
        /// If the <paramref name="path"/> could not be resolved.
        /// </exception>
        ///
        internal PathInfo SetLocation(string path, CmdletProviderContext context)
        {
            if (path == null)
            {
                throw PSTraceSource.NewArgumentNullException("path");
            }

            string       originalPath = path;
            string       driveName    = null;
            ProviderInfo provider     = null;
            string       providerId   = null;

            PSDriveInfo previousWorkingDrive = CurrentDrive;

            // First check to see if the path is a home path

            if (LocationGlobber.IsHomePath(path))
            {
                path = Globber.GetHomeRelativePath(path);
            }

            if (LocationGlobber.IsProviderDirectPath(path))
            {
                // The path is a provider-direct path so use the current
                // provider and its hidden drive but don't modify the path
                // at all.

                provider     = CurrentLocation.Provider;
                CurrentDrive = provider.HiddenDrive;
            }
            else if (LocationGlobber.IsProviderQualifiedPath(path, out providerId))
            {
                provider     = GetSingleProvider(providerId);
                CurrentDrive = provider.HiddenDrive;
            }
            else
            {
                // See if the path is a relative or absolute
                // path.

                if (Globber.IsAbsolutePath(path, out driveName))
                {
                    // Since the path is an absolute path
                    // we need to change the current working
                    // drive

                    PSDriveInfo newWorkingDrive = GetDrive(driveName);
                    CurrentDrive = newWorkingDrive;

                    // Now that the current working drive is set,
                    // process the rest of the path as a relative path.
                }
            }

            if (context == null)
            {
                context = new CmdletProviderContext(this.ExecutionContext);
            }

            if (CurrentDrive != null)
            {
                context.Drive = CurrentDrive;
            }

            CmdletProvider providerInstance = null;

            Collection <PathInfo> workingPath = null;

            try
            {
                workingPath =
                    Globber.GetGlobbedMonadPathsFromMonadPath(
                        path,
                        false,
                        context,
                        out providerInstance);
            }
            catch (LoopFlowException)
            {
                throw;
            }
            catch (PipelineStoppedException)
            {
                throw;
            }
            catch (ActionPreferenceStopException)
            {
                throw;
            }
            catch (Exception) // Catch-all OK, 3rd party callout
            {
                // Reset the drive to the previous drive and
                // then rethrow the error

                CurrentDrive = previousWorkingDrive;
                throw;
            }

            if (workingPath.Count == 0)
            {
                // Set the current working drive back to the previous
                // one in case it was changed.

                CurrentDrive = previousWorkingDrive;

                throw
                    new ItemNotFoundException(
                        path,
                        "PathNotFound",
                        SessionStateStrings.PathNotFound);
            }

            // We allow globbing the location as long as it only resolves a single container.

            bool foundContainer                     = false;
            bool pathIsContainer                    = false;
            bool pathIsProviderQualifiedPath        = false;
            bool currentPathisProviderQualifiedPath = false;

            for (int index = 0; index < workingPath.Count; ++index)
            {
                CmdletProviderContext normalizePathContext =
                    new CmdletProviderContext(context);

                PathInfo resolvedPath = workingPath[index];
                string   currentPath  = path;
                try
                {
                    string providerName = null;
                    currentPathisProviderQualifiedPath = LocationGlobber.IsProviderQualifiedPath(resolvedPath.Path, out providerName);
                    if (currentPathisProviderQualifiedPath)
                    {
                        // The path should be the provider-qualified path without the provider ID
                        // or ::

                        string providerInternalPath = LocationGlobber.RemoveProviderQualifier(resolvedPath.Path);

                        try
                        {
                            currentPath = NormalizeRelativePath(GetSingleProvider(providerName), providerInternalPath, String.Empty, normalizePathContext);
                        }
                        catch (NotSupportedException)
                        {
                            // Since the provider does not support normalizing the path, just
                            // use the path we currently have.
                        }
                        catch (LoopFlowException)
                        {
                            throw;
                        }
                        catch (PipelineStoppedException)
                        {
                            throw;
                        }
                        catch (ActionPreferenceStopException)
                        {
                            throw;
                        }
                        catch (Exception) // Catch-all OK, 3rd party callout
                        {
                            // Reset the drive to the previous drive and
                            // then rethrow the error

                            CurrentDrive = previousWorkingDrive;
                            throw;
                        }
                    }
                    else
                    {
                        try
                        {
                            currentPath = NormalizeRelativePath(resolvedPath.Path, CurrentDrive.Root, normalizePathContext);
                        }
                        catch (NotSupportedException)
                        {
                            // Since the provider does not support normalizing the path, just
                            // use the path we currently have.
                        }
                        catch (LoopFlowException)
                        {
                            throw;
                        }
                        catch (PipelineStoppedException)
                        {
                            throw;
                        }
                        catch (ActionPreferenceStopException)
                        {
                            throw;
                        }
                        catch (Exception) // Catch-all OK, 3rd party callout
                        {
                            // Reset the drive to the previous drive and
                            // then rethrow the error

                            CurrentDrive = previousWorkingDrive;
                            throw;
                        }
                    }

                    // Now see if there was errors while normalizing the path

                    if (normalizePathContext.HasErrors())
                    {
                        // Set the current working drive back to the previous
                        // one in case it was changed.

                        CurrentDrive = previousWorkingDrive;

                        normalizePathContext.ThrowFirstErrorOrDoNothing();
                    }
                }
                finally
                {
                    normalizePathContext.RemoveStopReferral();
                }

                // Check to see if the path is a container

                bool isContainer = false;

                CmdletProviderContext itemContainerContext =
                    new CmdletProviderContext(context);
                itemContainerContext.SuppressWildcardExpansion = true;

                try
                {
                    isContainer =
                        IsItemContainer(
                            resolvedPath.Path,
                            itemContainerContext);

                    if (itemContainerContext.HasErrors())
                    {
                        // Set the current working drive back to the previous
                        // one in case it was changed.

                        CurrentDrive = previousWorkingDrive;

                        itemContainerContext.ThrowFirstErrorOrDoNothing();
                    }
                }
                catch (NotSupportedException)
                {
                    if (currentPath.Length == 0)
                    {
                        // Treat this as a container because providers that only
                        // support the ContainerCmdletProvider interface are really
                        // containers at their root.

                        isContainer = true;
                    }
                }
                finally
                {
                    itemContainerContext.RemoveStopReferral();
                }

                if (isContainer)
                {
                    if (foundContainer)
                    {
                        // The path resolved to more than one container

                        // Set the current working drive back to the previous
                        // one in case it was changed.

                        CurrentDrive = previousWorkingDrive;

                        throw
                            PSTraceSource.NewArgumentException(
                                "path",
                                SessionStateStrings.PathResolvedToMultiple,
                                originalPath);
                    }
                    else
                    {
                        // Set the path to use
                        path = currentPath;

                        // Mark it as a container
                        pathIsContainer = true;

                        // Mark whether or not it was provider-qualified
                        pathIsProviderQualifiedPath = currentPathisProviderQualifiedPath;

                        // Mark that we have already found one container. Finding additional
                        // should be an error
                        foundContainer = true;
                    }
                }
            }

            if (pathIsContainer)
            {
                // Remove the root slash since it is implied that the
                // current working directory is relative to the root.

                if (!LocationGlobber.IsProviderDirectPath(path) &&
                    path.StartsWith(StringLiterals.DefaultPathSeparatorString, StringComparison.CurrentCulture) &&
                    !pathIsProviderQualifiedPath)
                {
                    path = path.Substring(1);
                }

                s_tracer.WriteLine(
                    "New working path = {0}",
                    path);

                CurrentDrive.CurrentLocation = path;
            }
            else
            {
                // Set the current working drive back to the previous
                // one in case it was changed.

                CurrentDrive = previousWorkingDrive;

                throw
                    new ItemNotFoundException(
                        originalPath,
                        "PathNotFound",
                        SessionStateStrings.PathNotFound);
            }

            // Now make sure the current drive is set in the provider's
            // current working drive hashtable

            ProvidersCurrentWorkingDrive[CurrentDrive.Provider] =
                CurrentDrive;

            // Set the $PWD variable to the new location

            this.SetVariable(SpecialVariables.PWDVarPath, this.CurrentLocation, false, true, CommandOrigin.Internal);
            return(this.CurrentLocation);
        } // SetLocation
Exemple #12
0
 public string GetUnresolvedProviderPathFromPSPath(string path, out ProviderInfo provider, out PSDriveInfo drive)
 {
     CmdletProviderContext context = new CmdletProviderContext(this.sessionState.ExecutionContext);
     string str = this.PathResolver.GetProviderPath(path, context, out provider, out drive);
     context.ThrowFirstErrorOrDoNothing();
     return str;
 }
Exemple #13
0
 internal static string ResolveFilePath(string filePath, PSCmdlet command, bool isLiteralPath)
 {
     string str = null;
     try
     {
         ProviderInfo provider = null;
         PSDriveInfo drive = null;
         List<string> list = new List<string>();
         if (isLiteralPath)
         {
             list.Add(command.SessionState.Path.GetUnresolvedProviderPathFromPSPath(filePath, out provider, out drive));
         }
         else
         {
             list.AddRange(command.SessionState.Path.GetResolvedProviderPathFromPSPath(filePath, out provider));
         }
         if (!provider.NameEquals(command.Context.ProviderNames.FileSystem))
         {
             ReportWrongProviderType(command, provider.FullName);
         }
         if (list.Count > 1)
         {
             ReportMultipleFilesNotSupported(command);
         }
         if (list.Count == 0)
         {
             ReportWildcardingFailure(command, filePath);
         }
         str = list[0];
     }
     catch (ItemNotFoundException)
     {
         str = null;
     }
     if (string.IsNullOrEmpty(str))
     {
         CmdletProviderContext context = new CmdletProviderContext(command);
         ProviderInfo info3 = null;
         PSDriveInfo info4 = null;
         str = command.SessionState.Path.GetUnresolvedProviderPathFromPSPath(filePath, context, out info3, out info4);
         context.ThrowFirstErrorOrDoNothing();
         if (!info3.NameEquals(command.Context.ProviderNames.FileSystem))
         {
             ReportWrongProviderType(command, info3.FullName);
         }
     }
     return str;
 }
        } // InitializeProvider



        /// <summary>
        /// Creates and adds a provider to the provider container 
        /// </summary>
        /// 
        /// <param name="provider">
        /// The provider to add.
        /// </param>
        /// 
        /// <returns>
        /// The provider that was added or null if the provider failed to be added.
        /// </returns>
        /// 
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="provider"/> is null.
        /// </exception>
        /// 
        /// <exception cref="SessionStateException">
        /// If the provider already exists.
        /// </exception>
        /// 
        /// <exception cref="ProviderInvocationException">
        /// If there was a failure to load the provider or the provider
        /// threw an exception.
        /// </exception>
        /// 
        internal ProviderInfo NewProvider(ProviderInfo provider)
        {
            if (provider == null)
            {
                throw PSTraceSource.NewArgumentNullException("provider");
            }

            // Check to see if the provider already exists.
            // We do the check instead of allowing the hashtable to 
            // throw the exception so that we give a better error
            // message.
            ProviderInfo existingProvider = ProviderExists(provider);
            if (existingProvider != null)
            {
                // If it's an already loaded provider, don't return an error...
                if (existingProvider.ImplementingType == provider.ImplementingType)
                    return existingProvider;

                SessionStateException sessionStateException =
                    new SessionStateException(
                        provider.Name,
                        SessionStateCategory.CmdletProvider,
                        "CmdletProviderAlreadyExists",
                        SessionStateStrings.CmdletProviderAlreadyExists,
                        ErrorCategory.ResourceExists);

                throw sessionStateException;
            }


            // Make sure we are able to create an instance of the provider.
            // Note, this will also set the friendly name if the user didn't
            // specify one.

            Provider.CmdletProvider providerInstance = provider.CreateInstance();

            // Now call start to let the provider initialize itself
            CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);
            ProviderInfo newProviderInfo = null;

            try
            {
                newProviderInfo = providerInstance.Start(provider, context);

                // Set the new provider info in the instance in case the provider
                // derived a new one

                providerInstance.SetProviderInformation(newProviderInfo);
            }
            catch (LoopFlowException)
            {
                throw;
            }
            catch (PipelineStoppedException)
            {
                throw;
            }
            catch (ActionPreferenceStopException)
            {
                throw;
            }
            catch (InvalidOperationException)
            {
                throw;
            }
            catch (Exception e) // Catch-call OK, 3rd party callout
            {
                CommandProcessorBase.CheckForSevereException(e);
                throw
                    NewProviderInvocationException(
                        "ProviderStartException",
                        SessionStateStrings.ProviderStartException,
                        provider,
                        null,
                        e);
            }

            context.ThrowFirstErrorOrDoNothing(true);

            if (newProviderInfo == null)
            {
                throw
                    PSTraceSource.NewInvalidOperationException(
                        SessionStateStrings.InvalidProviderInfoNull);
            }

            if (newProviderInfo != provider)
            {
                // Since the references are not the same, ensure that the provider
                // name is the same.

                if (!string.Equals(newProviderInfo.Name, provider.Name, StringComparison.OrdinalIgnoreCase))
                {
                    throw
                        PSTraceSource.NewInvalidOperationException(
                            SessionStateStrings.InvalidProviderInfo);
                }

                // Use the new provider info instead
                provider = newProviderInfo;
            }

            // Add the newly create provider to the providers container

            try
            {
                NewProviderEntry(provider);
            }
            catch (ArgumentException)
            {
                SessionStateException sessionStateException =
                    new SessionStateException(
                        provider.Name,
                        SessionStateCategory.CmdletProvider,
                        "CmdletProviderAlreadyExists",
                        SessionStateStrings.CmdletProviderAlreadyExists,
                        ErrorCategory.ResourceExists);

                throw sessionStateException;
            }

            // Add the provider to the provider current working 
            // drive hashtable so that we can associate a current working
            // drive with it.

            ProvidersCurrentWorkingDrive.Add(provider, null);

            bool initializeProviderError = false;
            try
            {
                // Initialize the provider and give it a chance to 
                // mount some drives.

                InitializeProvider(providerInstance, provider, context);
                context.ThrowFirstErrorOrDoNothing(true);
            }
            catch (LoopFlowException)
            {
                throw;
            }
            catch (PipelineStoppedException)
            {
                initializeProviderError = true;
                throw;
            }
            catch (ActionPreferenceStopException)
            {
                initializeProviderError = true;
                throw;
            }
            catch (NotSupportedException)
            {
                // We can safely ignore NotSupportedExceptions because
                // it just means that the provider doesn't support
                // drives.

                initializeProviderError = false;
            }
            catch (SessionStateException)
            {
                initializeProviderError = true;
                throw;
            }
            finally
            {
                if (initializeProviderError)
                {
                    // An exception during initialization should remove the provider from 
                    // session state.

                    Providers.Remove(provider.Name.ToString());
                    ProvidersCurrentWorkingDrive.Remove(provider);
                    provider = null;
                }
            }

#if RELATIONSHIP_SUPPORTED
    // 2004/11/24-JeffJon - Relationships have been removed from the Exchange release

            // Make sure the delay-load relationships get updated for the new provider

            relationships.ProcessDelayLoadRelationships (provider.Name);
#endif

            // Now write out the result

            return provider;
        } // NewProvider
Exemple #15
0
 internal void RemoveVariableAtScope(string name, string scopeID, bool force)
 {
     if (string.IsNullOrEmpty(name))
     {
         throw PSTraceSource.NewArgumentException("name");
     }
     VariablePath path = new VariablePath(name);
     SessionStateScope scopeByID = null;
     scopeByID = this.GetScopeByID(scopeID);
     if (path.IsVariable)
     {
         scopeByID.RemoveVariable(path.QualifiedName, force);
     }
     else
     {
         PSDriveInfo drive = scopeByID.GetDrive(path.DriveName);
         if (drive != null)
         {
             CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext) {
                 Drive = drive,
                 Force = force
             };
             this.RemoveItem(new string[] { path.QualifiedName }, false, context);
             context.ThrowFirstErrorOrDoNothing();
         }
     }
 }
Exemple #16
0
 internal Collection<PSObject> RenameItem(string path, string newName, bool force)
 {
     if (path == null)
     {
         throw PSTraceSource.NewArgumentNullException("path");
     }
     CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext) {
         Force = force
     };
     this.RenameItem(path, newName, context);
     context.ThrowFirstErrorOrDoNothing();
     return context.GetAccumulatedObjects();
 }
Exemple #17
0
 private void RemoveProvider(ProviderConfigurationEntry entry)
 {
     try
     {
         CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);
         string providerName = this.GetProviderName(entry);
         this.RemoveProvider(providerName, true, context);
         context.ThrowFirstErrorOrDoNothing();
     }
     catch (LoopFlowException)
     {
         throw;
     }
     catch (PipelineStoppedException)
     {
         throw;
     }
     catch (ActionPreferenceStopException)
     {
         throw;
     }
     catch (Exception exception)
     {
         CommandProcessorBase.CheckForSevereException(exception);
         this.ExecutionContext.ReportEngineStartupError(exception);
     }
 }
Exemple #18
0
 internal void RemoveVariable(string name, bool force)
 {
     if (name == null)
     {
         throw PSTraceSource.NewArgumentNullException("name");
     }
     VariablePath variablePath = new VariablePath(name);
     SessionStateScope scope = null;
     if (variablePath.IsVariable)
     {
         if (this.GetVariableItem(variablePath, out scope) != null)
         {
             scope.RemoveVariable(variablePath.QualifiedName, force);
         }
     }
     else
     {
         CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext) {
             Force = force
         };
         this.RemoveItem(new string[] { variablePath.QualifiedName }, false, context);
         context.ThrowFirstErrorOrDoNothing();
     }
 }
Exemple #19
0
 internal void RemoveItem(string[] paths, bool recurse, bool force, bool literalPath)
 {
     if (paths == null)
     {
         throw PSTraceSource.NewArgumentNullException("paths");
     }
     CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext) {
         Force = force,
         SuppressWildcardExpansion = literalPath
     };
     this.RemoveItem(paths, recurse, context);
     context.ThrowFirstErrorOrDoNothing();
 }
Exemple #20
0
 internal void RemoveDrive(PSDriveInfo drive, bool force, string scopeID)
 {
     if (drive == null)
     {
         throw PSTraceSource.NewArgumentNullException("drive");
     }
     CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);
     this.RemoveDrive(drive, force, scopeID, context);
     if (context.HasErrors() && !force)
     {
         context.ThrowFirstErrorOrDoNothing();
     }
 }
Exemple #21
0
 internal string NormalizeRelativePath(string path, string basePath)
 {
     if (path == null)
     {
         throw PSTraceSource.NewArgumentNullException("path");
     }
     CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);
     string str = this.NormalizeRelativePath(path, basePath, context);
     context.ThrowFirstErrorOrDoNothing();
     tracer.WriteLine("result = {0}", new object[] { str });
     return str;
 }
        } // SetLocation

        /// <summary>
        /// Changes the current working directory to the path specified
        /// </summary>
        /// 
        /// <param name="path">
        /// The path of the new current working directory
        /// </param>
        /// 
        /// <param name="context">
        /// The context the provider uses when performing the operation.
        /// </param>
        /// 
        /// <returns>
        /// The PathInfo object representing the path of the location
        /// that was set.
        /// </returns>
        ///
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="path"/> is null.
        /// </exception>
        /// 
        /// <exception cref="ArgumentException">
        /// If <paramref name="path"/> does not exist, is not a container, or
        /// resolved to multiple containers.
        /// </exception>
        /// 
        /// <exception cref="ProviderNotFoundException">
        /// If <paramref name="path"/> refers to a provider that does not exist.
        /// </exception>
        /// 
        /// <exception cref="DriveNotFoundException">
        /// If <paramref name="path"/> refers to a drive that does not exist.
        /// </exception>
        /// 
        /// <exception cref="ProviderInvocationException">
        /// If the provider associated with <paramref name="path"/> threw an
        /// exception.
        /// </exception>
        /// 
        /// <exception cref="ItemNotFoundException">
        /// If the <paramref name="path"/> could not be resolved.
        /// </exception>
        /// 
        internal PathInfo SetLocation(string path, CmdletProviderContext context)
        {
            if (path == null)
            {
                throw PSTraceSource.NewArgumentNullException("path");
            }

            string originalPath = path;
            string driveName = null;
            ProviderInfo provider = null;
            string providerId = null;

            PSDriveInfo previousWorkingDrive = CurrentDrive;

            // First check to see if the path is a home path

            if (LocationGlobber.IsHomePath(path))
            {
                path = Globber.GetHomeRelativePath(path);
            }

            if (LocationGlobber.IsProviderDirectPath(path))
            {
                // The path is a provider-direct path so use the current
                // provider and its hidden drive but don't modify the path
                // at all.

                provider = CurrentLocation.Provider;
                CurrentDrive = provider.HiddenDrive;
            }
            else if (LocationGlobber.IsProviderQualifiedPath(path, out providerId))
            {
                provider = GetSingleProvider(providerId);
                CurrentDrive = provider.HiddenDrive;
            }
            else
            {
                // See if the path is a relative or absolute
                // path.

                if (Globber.IsAbsolutePath(path, out driveName))
                {
                    // Since the path is an absolute path
                    // we need to change the current working
                    // drive

                    PSDriveInfo newWorkingDrive = GetDrive(driveName);
                    CurrentDrive = newWorkingDrive;

                    // Now that the current working drive is set,
                    // process the rest of the path as a relative path.
                }
            }

            if (context == null)
            {
                context = new CmdletProviderContext(this.ExecutionContext);
            }

            if (CurrentDrive != null)
            {
                context.Drive = CurrentDrive;
            }

            CmdletProvider providerInstance = null;

            Collection<PathInfo> workingPath = null;

            try
            {
                workingPath =
                    Globber.GetGlobbedMonadPathsFromMonadPath(
                        path,
                        false,
                        context,
                        out providerInstance);
            }
            catch (LoopFlowException)
            {
                throw;
            }
            catch (PipelineStoppedException)
            {
                throw;
            }
            catch (ActionPreferenceStopException)
            {
                throw;
            }
            catch (Exception e) // Catch-all OK, 3rd party callout
            {
                CommandProcessorBase.CheckForSevereException(e);

                // Reset the drive to the previous drive and
                // then rethrow the error

                CurrentDrive = previousWorkingDrive;
                throw;
            }

            if (workingPath.Count == 0)
            {
                // Set the current working drive back to the previous
                // one in case it was changed.

                CurrentDrive = previousWorkingDrive;

                throw
                    new ItemNotFoundException(
                        path,
                        "PathNotFound",
                        SessionStateStrings.PathNotFound);
            }

            // We allow globbing the location as long as it only resolves a single container.

            bool foundContainer = false;
            bool pathIsContainer = false;
            bool pathIsProviderQualifiedPath = false;
            bool currentPathisProviderQualifiedPath = false;

            for (int index = 0; index < workingPath.Count; ++index)
            {
                CmdletProviderContext normalizePathContext =
                    new CmdletProviderContext(context);

                PathInfo resolvedPath = workingPath[index];
                string currentPath = path;
                try
                {
                    string providerName = null;
                    currentPathisProviderQualifiedPath = LocationGlobber.IsProviderQualifiedPath(resolvedPath.Path, out providerName);
                    if (currentPathisProviderQualifiedPath)
                    {
                        // The path should be the provider-qualified path without the provider ID
                        // or ::

                        string providerInternalPath = LocationGlobber.RemoveProviderQualifier(resolvedPath.Path);

                        try
                        {
                            currentPath = NormalizeRelativePath(GetSingleProvider(providerName), providerInternalPath, String.Empty, normalizePathContext);
                        }
                        catch (NotSupportedException)
                        {
                            // Since the provider does not support normalizing the path, just
                            // use the path we currently have.
                        }
                        catch (LoopFlowException)
                        {
                            throw;
                        }
                        catch (PipelineStoppedException)
                        {
                            throw;
                        }
                        catch (ActionPreferenceStopException)
                        {
                            throw;
                        }
                        catch (Exception e) // Catch-all OK, 3rd party callout
                        {
                            CommandProcessorBase.CheckForSevereException(e);

                            // Reset the drive to the previous drive and
                            // then rethrow the error

                            CurrentDrive = previousWorkingDrive;
                            throw;
                        }
                    }
                    else
                    {
                        try
                        {
                            currentPath = NormalizeRelativePath(resolvedPath.Path, CurrentDrive.Root, normalizePathContext);
                        }
                        catch (NotSupportedException)
                        {
                            // Since the provider does not support normalizing the path, just
                            // use the path we currently have.
                        }
                        catch (LoopFlowException)
                        {
                            throw;
                        }
                        catch (PipelineStoppedException)
                        {
                            throw;
                        }
                        catch (ActionPreferenceStopException)
                        {
                            throw;
                        }
                        catch (Exception e) // Catch-all OK, 3rd party callout
                        {
                            CommandProcessorBase.CheckForSevereException(e);

                            // Reset the drive to the previous drive and
                            // then rethrow the error

                            CurrentDrive = previousWorkingDrive;
                            throw;
                        }
                    }

                    // Now see if there was errors while normalizing the path

                    if (normalizePathContext.HasErrors())
                    {
                        // Set the current working drive back to the previous
                        // one in case it was changed.

                        CurrentDrive = previousWorkingDrive;

                        normalizePathContext.ThrowFirstErrorOrDoNothing();
                    }
                }
                finally
                {
                    normalizePathContext.RemoveStopReferral();
                }

                // Check to see if the path is a container

                bool isContainer = false;

                CmdletProviderContext itemContainerContext =
                    new CmdletProviderContext(context);
                itemContainerContext.SuppressWildcardExpansion = true;

                try
                {
                    isContainer =
                        IsItemContainer(
                            resolvedPath.Path,
                            itemContainerContext);

                    if (itemContainerContext.HasErrors())
                    {
                        // Set the current working drive back to the previous
                        // one in case it was changed.

                        CurrentDrive = previousWorkingDrive;

                        itemContainerContext.ThrowFirstErrorOrDoNothing();
                    }
                }
                catch (NotSupportedException)
                {
                    if (currentPath.Length == 0)
                    {
                        // Treat this as a container because providers that only 
                        // support the ContainerCmdletProvider interface are really
                        // containers at their root.

                        isContainer = true;
                    }
                }
                finally
                {
                    itemContainerContext.RemoveStopReferral();
                }

                if (isContainer)
                {
                    if (foundContainer)
                    {
                        // The path resolved to more than one container

                        // Set the current working drive back to the previous
                        // one in case it was changed.

                        CurrentDrive = previousWorkingDrive;

                        throw
                            PSTraceSource.NewArgumentException(
                                "path",
                                SessionStateStrings.PathResolvedToMultiple,
                                originalPath);
                    }
                    else
                    {
                        // Set the path to use 
                        path = currentPath;

                        // Mark it as a container
                        pathIsContainer = true;

                        // Mark whether or not it was provider-qualified
                        pathIsProviderQualifiedPath = currentPathisProviderQualifiedPath;

                        // Mark that we have already found one container. Finding additional
                        // should be an error
                        foundContainer = true;
                    }
                }
            }

            if (pathIsContainer)
            {
                // Remove the root slash since it is implied that the
                // current working directory is relative to the root.

                if (!LocationGlobber.IsProviderDirectPath(path) &&
                    path.StartsWith(StringLiterals.DefaultPathSeparatorString, StringComparison.CurrentCulture) &&
                    !pathIsProviderQualifiedPath)
                {
                    path = path.Substring(1);
                }

                s_tracer.WriteLine(
                    "New working path = {0}",
                    path);

                CurrentDrive.CurrentLocation = path;
            }
            else
            {
                // Set the current working drive back to the previous
                // one in case it was changed.

                CurrentDrive = previousWorkingDrive;

                throw
                    new ItemNotFoundException(
                        originalPath,
                        "PathNotFound",
                        SessionStateStrings.PathNotFound);
            }

            // Now make sure the current drive is set in the provider's
            // current working drive hashtable

            ProvidersCurrentWorkingDrive[CurrentDrive.Provider] =
                CurrentDrive;

            // Set the $PWD variable to the new location

            this.SetVariable(SpecialVariables.PWDVarPath, this.CurrentLocation, false, true, CommandOrigin.Internal);
            return this.CurrentLocation;
        } // SetLocation
Exemple #23
0
 internal PSDriveInfo NewDrive(PSDriveInfo drive, string scopeID)
 {
     if (drive == null)
     {
         throw PSTraceSource.NewArgumentNullException("drive");
     }
     PSDriveInfo baseObject = null;
     CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);
     this.NewDrive(drive, scopeID, context);
     context.ThrowFirstErrorOrDoNothing();
     Collection<PSObject> accumulatedObjects = context.GetAccumulatedObjects();
     if (((accumulatedObjects != null) && (accumulatedObjects.Count > 0)) && !accumulatedObjects[0].immediateBaseObjectIsEmpty)
     {
         baseObject = (PSDriveInfo) accumulatedObjects[0].BaseObject;
     }
     return baseObject;
 }
        } // SetLocation

        /// <summary>
        /// Determines if the specified path is the current working directory
        /// or a parent of the current working directory.
        /// </summary>
        /// 
        /// <param name="path">
        /// A monad namespace absolute or relative path.
        /// </param>
        /// 
        /// <param name="context">
        /// The context the provider uses when performing the operation.
        /// </param>
        /// 
        /// <returns>
        /// true, if the path is the current working directory or a parent of the current
        /// working directory. false, otherwise.
        /// </returns>
        /// 
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="path"/> is null.
        /// </exception>
        /// 
        /// <exception cref="ProviderNotFoundException">
        /// If the path is a provider-qualified path for a provider that is
        /// not loaded into the system.
        /// </exception>
        /// 
        /// <exception cref="DriveNotFoundException">
        /// If the <paramref name="path"/> refers to a drive that could not be found.
        /// </exception>
        /// 
        /// <exception cref="ProviderInvocationException">
        /// If the provider used to build the path threw an exception.
        /// </exception>
        /// 
        /// <exception cref="NotSupportedException">
        /// If the provider that the <paramref name="path"/> represents is not a NavigationCmdletProvider
        /// or ContainerCmdletProvider.
        /// </exception>
        /// 
        /// <exception cref="InvalidOperationException">
        /// If the <paramref name="path"/> starts with "~" and the home location is not set for 
        /// the provider.
        /// </exception>
        /// 
        /// <exception cref="ProviderInvocationException">
        /// If the provider specified by <paramref name="providerId"/> threw an
        /// exception when its GetParentPath or MakePath was called while
        /// processing the <paramref name="path"/>.
        /// </exception>
        /// 
        internal bool IsCurrentLocationOrAncestor(string path, CmdletProviderContext context)
        {
            bool result = false;

            if (path == null)
            {
                throw PSTraceSource.NewArgumentNullException("path");
            }

            PSDriveInfo drive = null;
            ProviderInfo provider = null;

            string providerSpecificPath =
                Globber.GetProviderPath(
                    path,
                    context,
                    out provider,
                    out drive);

            if (drive != null)
            {
                s_tracer.WriteLine("Tracing drive");
                drive.Trace();
            }

            Dbg.Diagnostics.Assert(
                providerSpecificPath != null,
                "There should always be a way to generate a provider path for a " +
                "given path");

            if (drive != null)
            {
                context.Drive = drive;
            }

            // Check to see if the path that was specified is within the current
            // working drive

            if (drive == CurrentDrive)
            {
                // The path needs to be normalized to get rid of relative path tokens
                // so they don't interfere with our path comparisons below

                CmdletProviderContext normalizePathContext
                    = new CmdletProviderContext(context);

                try
                {
                    providerSpecificPath = NormalizeRelativePath(path, null, normalizePathContext);
                }
                catch (NotSupportedException)
                {
                    // Since the provider does not support normalizing the path, just
                    // use the path we currently have.
                }
                catch (LoopFlowException)
                {
                    throw;
                }
                catch (PipelineStoppedException)
                {
                    throw;
                }
                catch (ActionPreferenceStopException)
                {
                    throw;
                }
                finally
                {
                    normalizePathContext.RemoveStopReferral();
                }

                if (normalizePathContext.HasErrors())
                {
                    normalizePathContext.ThrowFirstErrorOrDoNothing();
                }

                s_tracer.WriteLine("Provider path = {0}", providerSpecificPath);

                // Get the current working directory provider specific path

                PSDriveInfo currentWorkingDrive = null;
                ProviderInfo currentDriveProvider = null;

                string currentWorkingPath =
                    Globber.GetProviderPath(
                        ".",
                        context,
                        out currentDriveProvider,
                        out currentWorkingDrive);

                Dbg.Diagnostics.Assert(
                    currentWorkingDrive == CurrentDrive,
                    "The current working drive should be the CurrentDrive.");

                s_tracer.WriteLine(
                    "Current working path = {0}",
                    currentWorkingPath);

                // See if the path is the current working directory or a parent
                // of the current working directory

                s_tracer.WriteLine(
                    "Comparing {0} to {1}",
                    providerSpecificPath,
                    currentWorkingPath);

                if (String.Compare(providerSpecificPath, currentWorkingPath, StringComparison.CurrentCultureIgnoreCase) == 0)
                {
                    // The path is the current working directory so
                    // return true

                    s_tracer.WriteLine("The path is the current working directory");

                    result = true;
                }
                else
                {
                    // Check to see if the specified path is a parent
                    // of the current working directory

                    string lockedDirectory = currentWorkingPath;

                    while (lockedDirectory.Length > 0)
                    {
                        // We need to allow the provider to go as far up the tree
                        // as it can even if that means it has to traverse higher
                        // than the mount point for this drive. That is
                        // why we are passing the empty string as the root here.

                        lockedDirectory =
                            GetParentPath(
                                drive.Provider,
                                lockedDirectory,
                                String.Empty,
                                context);

                        s_tracer.WriteLine(
                            "Comparing {0} to {1}",
                            lockedDirectory,
                            providerSpecificPath);

                        if (String.Compare(lockedDirectory, providerSpecificPath, StringComparison.CurrentCultureIgnoreCase) == 0)
                        {
                            // The path is a parent of the current working
                            // directory

                            s_tracer.WriteLine(
                                "The path is a parent of the current working directory: {0}",
                                lockedDirectory);

                            result = true;
                            break;
                        }
                    }
                }
            }
            else
            {
                s_tracer.WriteLine("Drives are not the same");
            }

            return result;
        } // IsCurrentLocationOrAncestor
Exemple #25
0
        internal PathInfo SetLocation (string path, CmdletProviderContext context)
		{
			if (string.IsNullOrEmpty (path) && OSHelper.IsUnix)
				path = "/";
			else if (path == null) {
				throw PSTraceSource.NewArgumentNullException ("path");
			}
			string str = path;
			string driveName = null;
			ProviderInfo provider = null;
			string providerId = null;
			PSDriveInfo currentDrive = this.CurrentDrive;
			if (LocationGlobber.IsHomePath (path)) {
				path = this.Globber.GetHomeRelativePath (path);
			}

			if (LocationGlobber.IsProviderDirectPath (path)) {
				provider = this.CurrentLocation.Provider;
				PSDriveInfo drive = null;
				if (PathIntrinsics.FinDriveFromPath (path, provider, out drive))
				{
					this.CurrentDrive = drive;
				}
				else if (LocationGlobber.IsProviderQualifiedPath (path, out providerId)) {
					provider = this.GetSingleProvider (providerId);
					if (PathIntrinsics.FinDriveFromPath (path, provider, out drive))
					{
						this.CurrentDrive = drive;
					}
					else if (this.Globber.IsAbsolutePath(path, out driveName))
					{
						drive = this.GetDrive(driveName);
						this.CurrentDrive = drive;
					}
				}
			} else if (LocationGlobber.IsProviderQualifiedPath (path, out providerId)) {
				provider = this.GetSingleProvider (providerId);
				PSDriveInfo drive = null;
				if (PathIntrinsics.FinDriveFromPath (path, provider, out drive))
				{
					this.CurrentDrive = drive;
				}
				else if (this.Globber.IsAbsolutePath(path, out driveName))
				{
					drive = this.GetDrive(driveName);
					this.CurrentDrive = drive;
				}
			} 
			else if (this.Globber.IsAbsolutePath(path, out driveName))
			{
				PSDriveInfo drive = this.GetDrive(driveName);
				this.CurrentDrive = drive;
			}
            if (context == null)
            {
                context = new CmdletProviderContext(this.ExecutionContext);
            }
            if (this.CurrentDrive != null)
            {
                context.Drive = this.CurrentDrive;
            }
            CmdletProvider providerInstance = null;
            Collection<PathInfo> collection = null;
            try
            {
                collection = this.Globber.GetGlobbedMonadPathsFromMonadPath(path, false, context, out providerInstance);

			}
            catch (LoopFlowException)
            {
                throw;
            }
            catch (PipelineStoppedException)
            {
                throw;
            }
            catch (ActionPreferenceStopException)
            {
                throw;
            }
            catch (Exception exception)
            {
                CommandProcessorBase.CheckForSevereException(exception);
                this.CurrentDrive = currentDrive;
                throw;
            }
            if (collection.Count == 0)
            {
                this.CurrentDrive = currentDrive;
                throw new ItemNotFoundException(path, "PathNotFound", SessionStateStrings.PathNotFound);
            }
            bool flag = false;
            bool flag2 = false;
            bool flag3 = false;
            bool flag4 = false;
            for (int i = 0; i < collection.Count; i++)
            {
                CmdletProviderContext context2 = new CmdletProviderContext(context);
                PathInfo info4 = collection[i];
                string str4 = path;
                try
                {
                    string str5 = null;
                    flag4 = LocationGlobber.IsProviderQualifiedPath(info4.Path, out str5);
                    if (flag4)
                    {
                        string str6 = LocationGlobber.RemoveProviderQualifier(info4.Path);
                        try
                        {
                            str4 = this.NormalizeRelativePath(this.GetSingleProvider(str5), str6, string.Empty, context2);
                            goto Label_01DF;
                        }
                        catch (NotSupportedException)
                        {
                            goto Label_01DF;
                        }
                        catch (LoopFlowException)
                        {
                            throw;
                        }
                        catch (PipelineStoppedException)
                        {
                            throw;
                        }
                        catch (ActionPreferenceStopException)
                        {
                            throw;
                        }
                        catch (Exception exception2)
                        {
                            CommandProcessorBase.CheckForSevereException(exception2);
                            this.CurrentDrive = currentDrive;
                            throw;
                        }
                    }
                    try
                    {
                    	str4 = this.NormalizeRelativePath(info4.Path, this.CurrentDrive.Root, context2);
                    }
                    catch (NotSupportedException)
                    {
                    }
                    catch (LoopFlowException)
                    {
                        throw;
                    }
                    catch (PipelineStoppedException)
                    {
                        throw;
                    }
                    catch (ActionPreferenceStopException)
                    {
                        throw;
                    }
                    catch (Exception exception3)
                    {
                        CommandProcessorBase.CheckForSevereException(exception3);
                        this.CurrentDrive = currentDrive;
                        throw;
                    }
                Label_01DF:
                    if (context2.HasErrors())
                    {
                        this.CurrentDrive = currentDrive;
                        context2.ThrowFirstErrorOrDoNothing();
                    }
                }
                finally
                {
                    context2.RemoveStopReferral();
                }
                bool flag5 = false;
                CmdletProviderContext context3 = new CmdletProviderContext(context) {
                    SuppressWildcardExpansion = true
                };
                try
                {
                    flag5 = this.IsItemContainer(info4.Path, context3);
                    if (context3.HasErrors())
                    {
                        this.CurrentDrive = currentDrive;
                        context3.ThrowFirstErrorOrDoNothing();
                    }
                }
                catch (NotSupportedException)
                {
                    if (str4.Length == 0)
                    {
                        flag5 = true;
                    }
                }
                finally
                {
                    context3.RemoveStopReferral();
                }
                if (flag5)
                {
                    if (flag)
                    {
                        this.CurrentDrive = currentDrive;
                        throw PSTraceSource.NewArgumentException("path", "SessionStateStrings", "PathResolvedToMultiple", new object[] { str });
                    }
                    path = str4;
                    flag2 = true;
                    flag3 = flag4;
                    flag = true;
                }
            }
            if (flag2)
            {
				if (!OSHelper.IsUnix)
				{
	                if (!LocationGlobber.IsProviderDirectPath(path))
	                {
	                    char ch = '\\';
	                    if (path.StartsWith(ch.ToString(), StringComparison.CurrentCulture) && !flag3)
	                    {
	                        path = path.Substring(1);
	                    }
	                }
				}
				tracer.WriteLine("New working path = {0}", new object[] { path });
				this.CurrentDrive.CurrentLocation = path;
            }
            else
            {
                this.CurrentDrive = currentDrive;
                throw new ItemNotFoundException(str, "PathNotFound", SessionStateStrings.PathNotFound);
            }
            this.ProvidersCurrentWorkingDrive[this.CurrentDrive.Provider] = this.CurrentDrive;
            this.SetVariable(SpecialVariables.PWDVarPath, this.CurrentLocation, false, true, CommandOrigin.Internal);
            return this.CurrentLocation;
        }
Exemple #26
0
        /// <summary>
        /// Changes the current working directory to the path specified.
        /// </summary>
        /// <param name="path">
        /// The path of the new current working directory.
        /// </param>
        /// <param name="context">
        /// The context the provider uses when performing the operation.
        /// </param>
        /// <param name="literalPath">
        /// Indicate if the path is a literal path.
        /// </param>
        /// <returns>
        /// The PathInfo object representing the path of the location
        /// that was set.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="path"/> is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// If <paramref name="path"/> does not exist, is not a container, or
        /// resolved to multiple containers.
        /// </exception>
        /// <exception cref="ProviderNotFoundException">
        /// If <paramref name="path"/> refers to a provider that does not exist.
        /// </exception>
        /// <exception cref="DriveNotFoundException">
        /// If <paramref name="path"/> refers to a drive that does not exist.
        /// </exception>
        /// <exception cref="ProviderInvocationException">
        /// If the provider associated with <paramref name="path"/> threw an
        /// exception.
        /// </exception>
        /// <exception cref="ItemNotFoundException">
        /// If the <paramref name="path"/> could not be resolved.
        /// </exception>
        internal PathInfo SetLocation(string path, CmdletProviderContext context, bool literalPath)
        {
            if (path == null)
            {
                throw PSTraceSource.NewArgumentNullException("path");
            }

            PathInfo     current      = CurrentLocation;
            string       originalPath = path;
            string       driveName    = null;
            ProviderInfo provider     = null;
            string       providerId   = null;

            switch (originalPath)
            {
            case string originalPathSwitch when !literalPath && originalPathSwitch.Equals("-", StringComparison.Ordinal):
                if (_setLocationHistory.UndoCount <= 0)
                {
                    throw new InvalidOperationException(SessionStateStrings.LocationUndoStackIsEmpty);
                }

                path = _setLocationHistory.Undo(this.CurrentLocation).Path;
                break;

            case string originalPathSwitch when !literalPath && originalPathSwitch.Equals("+", StringComparison.Ordinal):
                if (_setLocationHistory.RedoCount <= 0)
                {
                    throw new InvalidOperationException(SessionStateStrings.LocationRedoStackIsEmpty);
                }

                path = _setLocationHistory.Redo(this.CurrentLocation).Path;
                break;

            default:
                var pushPathInfo = GetNewPushPathInfo();
                _setLocationHistory.Push(pushPathInfo);
                break;
            }

            PSDriveInfo previousWorkingDrive = CurrentDrive;

            // First check to see if the path is a home path
            if (LocationGlobber.IsHomePath(path))
            {
                path = Globber.GetHomeRelativePath(path);
            }

            if (LocationGlobber.IsProviderDirectPath(path))
            {
                // The path is a provider-direct path so use the current
                // provider and its hidden drive but don't modify the path
                // at all.
                provider     = CurrentLocation.Provider;
                CurrentDrive = provider.HiddenDrive;
            }
            else if (LocationGlobber.IsProviderQualifiedPath(path, out providerId))
            {
                provider     = GetSingleProvider(providerId);
                CurrentDrive = provider.HiddenDrive;
            }
            else
            {
                // See if the path is a relative or absolute
                // path.
                if (Globber.IsAbsolutePath(path, out driveName))
                {
                    // Since the path is an absolute path
                    // we need to change the current working
                    // drive
                    PSDriveInfo newWorkingDrive = GetDrive(driveName);
                    CurrentDrive = newWorkingDrive;

                    // If the path is simply a colon-terminated drive,
                    // not a slash-terminated path to the root of a drive,
                    // set the path to the current working directory of that drive.
                    string colonTerminatedVolume = CurrentDrive.Name + ':';
                    if (CurrentDrive.VolumeSeparatedByColon && (path.Length == colonTerminatedVolume.Length))
                    {
                        path = Path.Combine(colonTerminatedVolume + Path.DirectorySeparatorChar, CurrentDrive.CurrentLocation);
                    }

                    // Now that the current working drive is set,
                    // process the rest of the path as a relative path.
                }
            }

            if (context == null)
            {
                context = new CmdletProviderContext(this.ExecutionContext);
            }

            if (CurrentDrive != null)
            {
                context.Drive = CurrentDrive;
            }

            CmdletProvider providerInstance = null;

            Collection <PathInfo> workingPath = null;

            try
            {
                workingPath =
                    Globber.GetGlobbedMonadPathsFromMonadPath(
                        path,
                        false,
                        context,
                        out providerInstance);
            }
            catch (LoopFlowException)
            {
                throw;
            }
            catch (PipelineStoppedException)
            {
                throw;
            }
            catch (ActionPreferenceStopException)
            {
                throw;
            }
            catch (Exception)
            {
                // Reset the drive to the previous drive and
                // then rethrow the error
                CurrentDrive = previousWorkingDrive;
                throw;
            }

            if (workingPath.Count == 0)
            {
                // Set the current working drive back to the previous
                // one in case it was changed.
                CurrentDrive = previousWorkingDrive;

                throw
                    new ItemNotFoundException(
                        path,
                        "PathNotFound",
                        SessionStateStrings.PathNotFound);
            }

            // We allow globbing the location as long as it only resolves a single container.
            bool foundContainer                     = false;
            bool pathIsContainer                    = false;
            bool pathIsProviderQualifiedPath        = false;
            bool currentPathisProviderQualifiedPath = false;

            for (int index = 0; index < workingPath.Count; ++index)
            {
                CmdletProviderContext normalizePathContext =
                    new CmdletProviderContext(context);

                PathInfo resolvedPath = workingPath[index];
                string   currentPath  = path;
                try
                {
                    string providerName = null;
                    currentPathisProviderQualifiedPath = LocationGlobber.IsProviderQualifiedPath(resolvedPath.Path, out providerName);
                    if (currentPathisProviderQualifiedPath)
                    {
                        // The path should be the provider-qualified path without the provider ID
                        // or ::
                        string providerInternalPath = LocationGlobber.RemoveProviderQualifier(resolvedPath.Path);

                        try
                        {
                            currentPath = NormalizeRelativePath(GetSingleProvider(providerName), providerInternalPath, string.Empty, normalizePathContext);
                        }
                        catch (NotSupportedException)
                        {
                            // Since the provider does not support normalizing the path, just
                            // use the path we currently have.
                        }
                        catch (LoopFlowException)
                        {
                            throw;
                        }
                        catch (PipelineStoppedException)
                        {
                            throw;
                        }
                        catch (ActionPreferenceStopException)
                        {
                            throw;
                        }
                        catch (Exception)
                        {
                            // Reset the drive to the previous drive and
                            // then rethrow the error
                            CurrentDrive = previousWorkingDrive;
                            throw;
                        }
                    }
                    else
                    {
                        try
                        {
                            currentPath = NormalizeRelativePath(resolvedPath.Path, CurrentDrive.Root, normalizePathContext);
                        }
                        catch (NotSupportedException)
                        {
                            // Since the provider does not support normalizing the path, just
                            // use the path we currently have.
                        }
                        catch (LoopFlowException)
                        {
                            throw;
                        }
                        catch (PipelineStoppedException)
                        {
                            throw;
                        }
                        catch (ActionPreferenceStopException)
                        {
                            throw;
                        }
                        catch (Exception)
                        {
                            // Reset the drive to the previous drive and
                            // then rethrow the error
                            CurrentDrive = previousWorkingDrive;
                            throw;
                        }
                    }

                    // Now see if there was errors while normalizing the path
                    if (normalizePathContext.HasErrors())
                    {
                        // Set the current working drive back to the previous
                        // one in case it was changed.
                        CurrentDrive = previousWorkingDrive;

                        normalizePathContext.ThrowFirstErrorOrDoNothing();
                    }
                }
                finally
                {
                    normalizePathContext.RemoveStopReferral();
                }

                bool isContainer = false;

                CmdletProviderContext itemContainerContext =
                    new CmdletProviderContext(context);
                itemContainerContext.SuppressWildcardExpansion = true;

                try
                {
                    isContainer =
                        IsItemContainer(
                            resolvedPath.Path,
                            itemContainerContext);

                    if (itemContainerContext.HasErrors())
                    {
                        // Set the current working drive back to the previous
                        // one in case it was changed.
                        CurrentDrive = previousWorkingDrive;

                        itemContainerContext.ThrowFirstErrorOrDoNothing();
                    }
                }
                catch (NotSupportedException)
                {
                    if (currentPath.Length == 0)
                    {
                        // Treat this as a container because providers that only
                        // support the ContainerCmdletProvider interface are really
                        // containers at their root.
                        isContainer = true;
                    }
                }
                finally
                {
                    itemContainerContext.RemoveStopReferral();
                }

                if (isContainer)
                {
                    if (foundContainer)
                    {
                        // The path resolved to more than one container
                        // Set the current working drive back to the previous
                        // one in case it was changed.
                        CurrentDrive = previousWorkingDrive;

                        throw
                            PSTraceSource.NewArgumentException(
                                "path",
                                SessionStateStrings.PathResolvedToMultiple,
                                originalPath);
                    }
                    else
                    {
                        // Set the path to use
                        path = currentPath;

                        // Mark it as a container
                        pathIsContainer = true;

                        // Mark whether or not it was provider-qualified
                        pathIsProviderQualifiedPath = currentPathisProviderQualifiedPath;

                        // Mark that we have already found one container. Finding additional
                        // should be an error
                        foundContainer = true;
                    }
                }
            }

            if (pathIsContainer)
            {
                // Remove the root slash since it is implied that the
                // current working directory is relative to the root.
                if (!LocationGlobber.IsProviderDirectPath(path) &&
                    path.StartsWith(StringLiterals.DefaultPathSeparatorString, StringComparison.Ordinal) &&
                    !pathIsProviderQualifiedPath)
                {
                    path = path.Substring(1);
                }

                s_tracer.WriteLine(
                    "New working path = {0}",
                    path);

                CurrentDrive.CurrentLocation = path;
            }
            else
            {
                // Set the current working drive back to the previous
                // one in case it was changed.
                CurrentDrive = previousWorkingDrive;

                throw
                    new ItemNotFoundException(
                        originalPath,
                        "PathNotFound",
                        SessionStateStrings.PathNotFound);
            }

            // Now make sure the current drive is set in the provider's
            // current working drive hashtable
            ProvidersCurrentWorkingDrive[CurrentDrive.Provider] =
                CurrentDrive;

            // Set the $PWD variable to the new location
            this.SetVariable(SpecialVariables.PWDVarPath, this.CurrentLocation, false, true, CommandOrigin.Internal);

            // If an action has been defined for location changes, invoke it now.
            if (PublicSessionState.InvokeCommand.LocationChangedAction != null)
            {
                var eventArgs = new LocationChangedEventArgs(PublicSessionState, current, CurrentLocation);
                PublicSessionState.InvokeCommand.LocationChangedAction.Invoke(ExecutionContext.CurrentRunspace, eventArgs);
                s_tracer.WriteLine("Invoked LocationChangedAction");
            }

            return(this.CurrentLocation);
        } // SetLocation
Exemple #27
0
 internal Collection<PSObject> SetProperty(string[] paths, PSObject property, bool force, bool literalPath)
 {
     if (paths == null)
     {
         throw PSTraceSource.NewArgumentNullException("paths");
     }
     if (property == null)
     {
         throw PSTraceSource.NewArgumentNullException("properties");
     }
     CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext) {
         Force = force,
         SuppressWildcardExpansion = literalPath
     };
     this.SetProperty(paths, property, context);
     context.ThrowFirstErrorOrDoNothing();
     return context.GetAccumulatedObjects();
 }
        private void RemoveProvider(ProviderConfigurationEntry entry)
        {
            try
            {
                CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);

                string providerName = GetProviderName(entry);
                RemoveProvider(providerName, true, context);

                context.ThrowFirstErrorOrDoNothing();
            }
            catch (LoopFlowException)
            {
                throw;
            }
            catch (PipelineStoppedException)
            {
                throw;
            }
            catch (ActionPreferenceStopException)
            {
                throw;
            }
            catch (Exception e) // Catch-all OK, 3rd party callout
            {
                CommandProcessorBase.CheckForSevereException(e);

                // NTRAID#Windows OS Bugs-1009281-2004/02/11-JeffJon
                this.ExecutionContext.ReportEngineStartupError(e);
            }
        }
Exemple #29
0
 internal Collection<PSObject> SetSecurityDescriptor(string path, ObjectSecurity securityDescriptor)
 {
     if (path == null)
     {
         throw PSTraceSource.NewArgumentNullException("path");
     }
     if (securityDescriptor == null)
     {
         throw PSTraceSource.NewArgumentNullException("securityDescriptor");
     }
     CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);
     this.SetSecurityDescriptor(path, securityDescriptor, context);
     context.ThrowFirstErrorOrDoNothing();
     Collection<PSObject> accumulatedObjects = context.GetAccumulatedObjects();
     if (accumulatedObjects == null)
     {
         accumulatedObjects = new Collection<PSObject>();
     }
     return accumulatedObjects;
 }
		private string ResolveFilePath(string filePath, bool isLiteralPath)
		{
			string item = null;
			try
			{
				if (!isLiteralPath)
				{
					ProviderInfo providerInfo = null;
					Collection<string> resolvedProviderPathFromPSPath = base.SessionState.Path.GetResolvedProviderPathFromPSPath(filePath, out providerInfo);
					if (!providerInfo.NameEquals(base.Context.ProviderNames.FileSystem))
					{
						this.ReportWrongProviderType(providerInfo.FullName);
					}
					if (resolvedProviderPathFromPSPath.Count > 1)
					{
						this.ReportMultipleFilesNotSupported();
					}
					item = resolvedProviderPathFromPSPath[0];
				}
				else
				{
					item = base.SessionState.Path.GetUnresolvedProviderPathFromPSPath(filePath);
				}
			}
			catch (ItemNotFoundException itemNotFoundException)
			{
				item = null;
			}
			if (string.IsNullOrEmpty(item))
			{
				CmdletProviderContext cmdletProviderContext = new CmdletProviderContext(this);
				ProviderInfo providerInfo1 = null;
				PSDriveInfo pSDriveInfo = null;
				item = base.SessionState.Path.GetUnresolvedProviderPathFromPSPath(filePath, cmdletProviderContext, out providerInfo1, out pSDriveInfo);
				cmdletProviderContext.ThrowFirstErrorOrDoNothing();
				if (!providerInfo1.NameEquals(base.Context.ProviderNames.FileSystem))
				{
					this.ReportWrongProviderType(providerInfo1.FullName);
				}
			}
			return item;
		}
Exemple #31
0
 internal Collection<PSObject> CopyItem(string[] paths, string copyPath, bool recurse, CopyContainers copyContainers, bool force, bool literalPath)
 {
     if (paths == null)
     {
         throw PSTraceSource.NewArgumentNullException("paths");
     }
     if (copyPath == null)
     {
         copyPath = string.Empty;
     }
     CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext) {
         Force = force,
         SuppressWildcardExpansion = literalPath
     };
     this.CopyItem(paths, copyPath, recurse, copyContainers, context);
     context.ThrowFirstErrorOrDoNothing();
     return context.GetAccumulatedObjects();
 }
Exemple #32
0
 internal void ClearProperty(string[] paths, Collection<string> propertyToClear, bool force, bool literalPath)
 {
     if (paths == null)
     {
         throw PSTraceSource.NewArgumentNullException("paths");
     }
     if (propertyToClear == null)
     {
         throw PSTraceSource.NewArgumentNullException("propertyToClear");
     }
     CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext) {
         Force = force,
         SuppressWildcardExpansion = literalPath
     };
     this.ClearProperty(paths, propertyToClear, context);
     context.ThrowFirstErrorOrDoNothing();
 }
Exemple #33
0
 internal Collection<PSObject> NewItem(string[] paths, string name, string type, object content, bool force)
 {
     if (paths == null)
     {
         throw PSTraceSource.NewArgumentNullException("paths");
     }
     CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext) {
         Force = force
     };
     this.NewItem(paths, name, type, content, context);
     context.ThrowFirstErrorOrDoNothing();
     return context.GetAccumulatedObjects();
 }