}     // 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
Пример #2
0
        /// <summary>
        /// Retrieves the drives specified by the parameters. If the name is empty, all drives
        /// will be retrieved. If the provider is specified, only drives for that provider
        /// will be retrieved.
        /// </summary>
        protected override void ProcessRecord()
        {
            foreach (string driveName in Name)
            {
                try
                {
                    List<PSDriveInfo> foundDrives = GetMatchingDrives(driveName, PSProvider, Scope);

                    if (foundDrives.Count > 0)
                    {
                        WriteObject(foundDrives, true);
                    }
                    else
                    {
                        // If no drives were found and the user was asking for a specific
                        // drive (no wildcards) then write an error

                        if (!WildcardPattern.ContainsWildcardCharacters(driveName))
                        {
                            DriveNotFoundException driveNotFound =
                                new DriveNotFoundException(
                                    driveName,
                                    "DriveNotFound",
                                    SessionStateStrings.DriveNotFound);

                            WriteError(
                                new ErrorRecord(
                                    driveNotFound,
                                    "GetDriveNoMatchingDrive",
                                    ErrorCategory.ObjectNotFound,
                                    driveName));
                        }
                    }
                }
                catch (DriveNotFoundException driveNotFound)
                {
                    ErrorRecord errorRecord =
                        new ErrorRecord(
                            driveNotFound,
                            "GetLocationNoMatchingDrive",
                            ErrorCategory.ObjectNotFound,
                            driveName);
                    WriteError(errorRecord);
                }
                catch (ProviderNotFoundException providerNotFound)
                {
                    ErrorRecord errorRecord =
                        new ErrorRecord(
                            providerNotFound,
                            "GetLocationNoMatchingDrive",
                            ErrorCategory.ObjectNotFound,
                            PSProvider);
                    WriteError(errorRecord);
                }
                catch (PSArgumentOutOfRangeException outOfRange)
                {
                    WriteError(
                        new ErrorRecord(
                            outOfRange.ErrorRecord,
                            outOfRange));
                }
                catch (PSArgumentException argException)
                {
                    WriteError(
                        new ErrorRecord(
                            argException.ErrorRecord,
                            argException));
                }
            }
        } // ProcessRecord
Пример #3
0
        /// <summary>
        /// Removes the specified drive from the Monad namespace using the name
        /// of the drive.
        /// </summary>
        protected override void ProcessRecord()
        {
            // Get the confirmation strings

            string action = NavigationResources.RemoveDriveConfirmAction;
            string resourceTemplate = NavigationResources.RemoveDriveConfirmResourceTemplate;

            bool verifyMatch = true;
            if (_names == null)
            {
                _names = new string[] { string.Empty };
                verifyMatch = false;
            }

            foreach (string driveName in _names)
            {
                bool foundMatch = false;
                try
                {
                    foreach (PSDriveInfo drive in GetMatchingDrives(driveName, PSProvider, Scope))
                    {
                        string resource =
                            String.Format(
                                System.Globalization.CultureInfo.CurrentCulture,
                                resourceTemplate,
                                drive.Name,
                                drive.Provider,
                                drive.Root);

                        foundMatch = true;
                        if (ShouldProcess(resource, action))
                        {
                            if (!Force && drive == SessionState.Drive.Current)
                            {
                                PSInvalidOperationException invalidOperation =
                                    (PSInvalidOperationException)
                                    PSTraceSource.NewInvalidOperationException(
                                        NavigationResources.RemoveDriveInUse,
                                        drive.Name);

                                WriteError(
                                    new ErrorRecord(
                                        invalidOperation.ErrorRecord,
                                        invalidOperation));
                                continue;
                            }
                            SessionState.Drive.Remove(drive.Name, Force, Scope, CmdletProviderContext);
                        }
                    }
                }
                catch (DriveNotFoundException)
                {
                }
                catch (ProviderNotFoundException)
                {
                }

                // If a name was specified explicitly write an error if the drive wasn't
                // found

                if (verifyMatch && !foundMatch)
                {
                    DriveNotFoundException e = new DriveNotFoundException(
                        driveName,
                        "DriveNotFound",
                        SessionStateStrings.DriveNotFound);
                    WriteError(new ErrorRecord(e.ErrorRecord, e));
                }
            }
        } // ProcessRecord
Пример #4
0
		protected override void ProcessRecord()
		{
			string[] name = this.Name;
			for (int i = 0; i < (int)name.Length; i++)
			{
				string str = name[i];
				try
				{
					List<PSDriveInfo> matchingDrives = base.GetMatchingDrives(str, this.PSProvider, this.Scope);
					if (matchingDrives.Count <= 0)
					{
						if (!WildcardPattern.ContainsWildcardCharacters(str))
						{
							DriveNotFoundException driveNotFoundException = new DriveNotFoundException(str, "DriveNotFound", SessionStateStrings.DriveNotFound);
							base.WriteError(new ErrorRecord(driveNotFoundException, "GetDriveNoMatchingDrive", ErrorCategory.ObjectNotFound, str));
						}
					}
					else
					{
						base.WriteObject(matchingDrives, true);
					}
				}
				catch (DriveNotFoundException driveNotFoundException2)
				{
					DriveNotFoundException driveNotFoundException1 = driveNotFoundException2;
					ErrorRecord errorRecord = new ErrorRecord(driveNotFoundException1, "GetLocationNoMatchingDrive", ErrorCategory.ObjectNotFound, str);
					base.WriteError(errorRecord);
				}
				catch (ProviderNotFoundException providerNotFoundException1)
				{
					ProviderNotFoundException providerNotFoundException = providerNotFoundException1;
					ErrorRecord errorRecord1 = new ErrorRecord(providerNotFoundException, "GetLocationNoMatchingDrive", ErrorCategory.ObjectNotFound, this.PSProvider);
					base.WriteError(errorRecord1);
				}
				catch (PSArgumentOutOfRangeException pSArgumentOutOfRangeException1)
				{
					PSArgumentOutOfRangeException pSArgumentOutOfRangeException = pSArgumentOutOfRangeException1;
					base.WriteError(new ErrorRecord(pSArgumentOutOfRangeException.ErrorRecord, pSArgumentOutOfRangeException));
				}
				catch (PSArgumentException pSArgumentException1)
				{
					PSArgumentException pSArgumentException = pSArgumentException1;
					base.WriteError(new ErrorRecord(pSArgumentException.ErrorRecord, pSArgumentException));
				}
			}
		}
Пример #5
0
        } // 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
Пример #6
0
		protected override void ProcessRecord()
		{
			string removeDriveConfirmAction = NavigationResources.RemoveDriveConfirmAction;
			string removeDriveConfirmResourceTemplate = NavigationResources.RemoveDriveConfirmResourceTemplate;
			bool flag = true;
			if (this.names == null)
			{
				string[] empty = new string[1];
				empty[0] = string.Empty;
				this.names = empty;
				flag = false;
			}
			string[] strArrays = this.names;
			for (int i = 0; i < (int)strArrays.Length; i++)
			{
				string str = strArrays[i];
				bool flag1 = false;
				try
				{
					foreach (PSDriveInfo matchingDrife in base.GetMatchingDrives(str, this.PSProvider, this.Scope))
					{
						object[] name = new object[3];
						name[0] = matchingDrife.Name;
						name[1] = matchingDrife.Provider;
						name[2] = matchingDrife.Root;
						string str1 = string.Format(Thread.CurrentThread.CurrentCulture, removeDriveConfirmResourceTemplate, name);
						flag1 = true;
						if (!base.ShouldProcess(str1, removeDriveConfirmAction))
						{
							continue;
						}
						if (this.Force || !(matchingDrife == base.SessionState.Drive.Current))
						{
							base.SessionState.Drive.Remove(matchingDrife.Name, this.Force, this.Scope, this.CmdletProviderContext);
						}
						else
						{
							object[] objArray = new object[1];
							objArray[0] = matchingDrife.Name;
							PSInvalidOperationException pSInvalidOperationException = PSTraceSource.NewInvalidOperationException("NavigationResources", "RemoveDriveInUse", objArray);
							base.WriteError(new ErrorRecord(pSInvalidOperationException.ErrorRecord, pSInvalidOperationException));
						}
					}
				}
				catch (DriveNotFoundException driveNotFoundException)
				{
				}
				catch (ProviderNotFoundException providerNotFoundException)
				{
				}
				if (flag && !flag1)
				{
					DriveNotFoundException driveNotFoundException1 = new DriveNotFoundException(str, "DriveNotFound", SessionStateStrings.DriveNotFound);
					base.WriteError(new ErrorRecord(driveNotFoundException1.ErrorRecord, driveNotFoundException1));
				}
			}
		}