}     // CurrentLocation

        /// <summary>
        /// Gets the namespace specific path of the current working directory
        /// for the specified namespace.
        /// </summary>
        ///
        /// <param name="namespaceID">
        /// An identifier that uniquely identifies the namespace to get the
        /// current working directory for.
        /// </param>
        ///
        /// <returns>
        /// The namespace specific path of the current working directory for
        /// the specified namespace.
        /// </returns>
        ///
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="namespaceID"/> is null.
        /// </exception>
        ///
        /// <exception cref="ProviderNotFoundException">
        /// If <paramref name="namespacesID"/> refers to a provider that does not exist.
        /// </exception>
        ///
        /// <exception cref="DriveNotFoundException">
        /// If a current drive cannot be found for the provider <paramref name="namespaceID"/>
        /// </exception>
        ///
        internal PathInfo GetNamespaceCurrentLocation(string namespaceID)
        {
            if (namespaceID == null)
            {
                throw PSTraceSource.NewArgumentNullException("namespaceID");
            }

            // If namespace ID is empty, we will use the current working drive

            PSDriveInfo drive = null;

            if (namespaceID.Length == 0)
            {
                ProvidersCurrentWorkingDrive.TryGetValue(CurrentDrive.Provider, out drive);
            }
            else
            {
                // First check to see if the provider exists

                ProvidersCurrentWorkingDrive.TryGetValue(GetSingleProvider(namespaceID), out drive);
            }

            if (drive == null)
            {
                DriveNotFoundException e =
                    new DriveNotFoundException(
                        namespaceID,
                        "DriveNotFound",
                        SessionStateStrings.DriveNotFound);
                throw e;
            }

            CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);

            context.Drive = drive;

            // Now make the namespace specific path

            string path = null;

            if (drive.Hidden)
            {
                if (LocationGlobber.IsProviderDirectPath(drive.CurrentLocation))
                {
                    path = drive.CurrentLocation;
                }
                else
                {
                    path = LocationGlobber.GetProviderQualifiedPath(drive.CurrentLocation, drive.Provider);
                }
            }
            else
            {
                path = LocationGlobber.GetDriveQualifiedPath(drive.CurrentLocation, drive);
            }
            return(new PathInfo(drive, drive.Provider, path, new SessionState(this)));
        } // GetNamespaceCurrentLocation
Ejemplo n.º 2
0
        public override string ToString()
        {
            string path = this.path;

            if ((this.drive == null) || this.drive.Hidden)
            {
                return(LocationGlobber.GetProviderQualifiedPath(path, this.provider));
            }
            path = LocationGlobber.GetDriveQualifiedPath(path, this.drive);
            return(path);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets a string representing the MSH path.
        /// </summary>
        /// <returns>
        /// A string representing the MSH path.
        /// </returns>
        public override string ToString()
        {
            string result = _path;

            if (_drive == null ||
                _drive.Hidden)
            {
                // For hidden drives just return the current location
                result =
                    LocationGlobber.GetProviderQualifiedPath(
                        _path,
                        _provider);
            }
            else
            {
                result = LocationGlobber.GetDriveQualifiedPath(_path, _drive);
            }

            return(result);
        }
Ejemplo n.º 4
0
 public override string ToString()
 {
     using (PathInfo.tracer.TraceMethod(this.path, new object[0]))
     {
         string path = this.path;
         string str  = this.drive == (PSDriveInfo)null || this.drive.Hidden ? LocationGlobber.GetProviderQualifiedPath(this.path, this.provider) : LocationGlobber.GetDriveQualifiedPath(this.path, this.drive);
         PathInfo.tracer.WriteLine("result = {0}", (object)str);
         return(str);
     }
 }
Ejemplo n.º 5
0
        protected override void ProcessRecord()
        {
            PathInfo           pathInfo;
            List <PSDriveInfo> matchingDrives;
            string             parameterSetName = base.ParameterSetName;
            string             str = parameterSetName;

            if (parameterSetName != null)
            {
                if (str == "Location")
                {
                    pathInfo = null;
                    if (this.PSDrive == null || (int)this.PSDrive.Length <= 0)
                    {
                        if ((this.PSDrive == null || (int)this.PSDrive.Length == 0) && this.PSProvider != null && (int)this.PSProvider.Length > 0)
                        {
                            string[] pSProvider = this.PSProvider;
                            for (int i = 0; i < (int)pSProvider.Length; i++)
                            {
                                string str1 = pSProvider[i];
                                bool   flag = WildcardPattern.ContainsWildcardCharacters(str1);
                                if (!flag)
                                {
                                    try
                                    {
                                        base.SessionState.Provider.GetOne(str1);
                                    }
                                    catch (ProviderNotFoundException providerNotFoundException1)
                                    {
                                        ProviderNotFoundException providerNotFoundException = providerNotFoundException1;
                                        ErrorRecord errorRecord = new ErrorRecord(providerNotFoundException, "GetLocationNoMatchingProvider", ErrorCategory.ObjectNotFound, str1);
                                        base.WriteError(errorRecord);
                                        goto Label0;
                                    }
                                }
                                foreach (ProviderInfo all in base.SessionState.Provider.GetAll())
                                {
                                    if (!all.IsMatch(str1))
                                    {
                                        continue;
                                    }
                                    try
                                    {
                                        base.WriteObject(base.SessionState.Path.CurrentProviderLocation(all.FullName));
                                    }
                                    catch (ProviderNotFoundException providerNotFoundException3)
                                    {
                                        ProviderNotFoundException providerNotFoundException2 = providerNotFoundException3;
                                        base.WriteError(new ErrorRecord(providerNotFoundException2.ErrorRecord, providerNotFoundException2));
                                    }
                                    catch (DriveNotFoundException driveNotFoundException1)
                                    {
                                        DriveNotFoundException driveNotFoundException = driveNotFoundException1;
                                        if (!flag)
                                        {
                                            base.WriteError(new ErrorRecord(driveNotFoundException.ErrorRecord, driveNotFoundException));
                                        }
                                    }
                                }
Label0:
                                continue;
                            }
                            return;
                        }
                        else
                        {
                            base.WriteObject(base.SessionState.Path.CurrentLocation);
                            return;
                        }
                    }
                    else
                    {
                        string[] pSDrive = this.PSDrive;
                        for (int j = 0; j < (int)pSDrive.Length; j++)
                        {
                            string str2 = pSDrive[j];
                            matchingDrives = null;
                            try
                            {
                                matchingDrives = base.GetMatchingDrives(str2, this.PSProvider, null);
                                goto Label1;
                            }
                            catch (DriveNotFoundException driveNotFoundException3)
                            {
                                DriveNotFoundException driveNotFoundException2 = driveNotFoundException3;
                                ErrorRecord            errorRecord1            = new ErrorRecord(driveNotFoundException2, "GetLocationNoMatchingDrive", ErrorCategory.ObjectNotFound, str2);
                                base.WriteError(errorRecord1);
                            }
                            catch (ProviderNotFoundException providerNotFoundException5)
                            {
                                ProviderNotFoundException providerNotFoundException4 = providerNotFoundException5;
                                ErrorRecord errorRecord2 = new ErrorRecord(providerNotFoundException4, "GetLocationNoMatchingProvider", ErrorCategory.ObjectNotFound, this.PSProvider);
                                base.WriteError(errorRecord2);
                            }
                            catch (ArgumentException argumentException1)
                            {
                                ArgumentException argumentException = argumentException1;
                                ErrorRecord       errorRecord3      = new ErrorRecord(argumentException, "GetLocationNoMatchingDrive", ErrorCategory.ObjectNotFound, str2);
                                base.WriteError(errorRecord3);
                            }
                        }
                        return;
                    }
                }
                else
                {
                    if (str == "Stack")
                    {
                        if (this.stackNames == null)
                        {
                            try
                            {
                                base.WriteObject(base.SessionState.Path.LocationStack(null), false);
                            }
                            catch (PSArgumentException pSArgumentException1)
                            {
                                PSArgumentException pSArgumentException = pSArgumentException1;
                                base.WriteError(new ErrorRecord(pSArgumentException.ErrorRecord, pSArgumentException));
                            }
                        }
                        else
                        {
                            string[] strArrays = this.stackNames;
                            for (int k = 0; k < (int)strArrays.Length; k++)
                            {
                                string str3 = strArrays[k];
                                try
                                {
                                    base.WriteObject(base.SessionState.Path.LocationStack(str3), false);
                                }
                                catch (PSArgumentException pSArgumentException3)
                                {
                                    PSArgumentException pSArgumentException2 = pSArgumentException3;
                                    base.WriteError(new ErrorRecord(pSArgumentException2.ErrorRecord, pSArgumentException2));
                                }
                            }
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }
            return;

Label1:
            List <PSDriveInfo> .Enumerator enumerator = matchingDrives.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    PSDriveInfo current = enumerator.Current;
                    try
                    {
                        string driveQualifiedPath = LocationGlobber.GetDriveQualifiedPath(current.CurrentLocation, current);
                        pathInfo = new PathInfo(current, current.Provider, driveQualifiedPath, base.SessionState);
                        base.WriteObject(pathInfo);
                    }
                    catch (ProviderNotFoundException providerNotFoundException7)
                    {
                        ProviderNotFoundException providerNotFoundException6 = providerNotFoundException7;
                        base.WriteError(new ErrorRecord(providerNotFoundException6.ErrorRecord, providerNotFoundException6));
                    }
                }
                return;
            }
            finally
            {
                enumerator.Dispose();
            }
        }