Exemplo n.º 1
0
 internal void RemoveDrive(string driveName, bool force, string scopeID, CmdletProviderContext context)
 {
     if (driveName == null)
     {
         throw PSTraceSource.NewArgumentNullException("driveName");
     }
     PSDriveInfo drive = this.GetDrive(driveName, scopeID);
     if (drive == null)
     {
         System.Management.Automation.DriveNotFoundException replaceParentContainsErrorRecordException = new System.Management.Automation.DriveNotFoundException(driveName, "DriveNotFound", SessionStateStrings.DriveNotFound);
         context.WriteError(new ErrorRecord(replaceParentContainsErrorRecordException.ErrorRecord, replaceParentContainsErrorRecordException));
     }
     else
     {
         this.RemoveDrive(drive, force, scopeID, context);
     }
 }
Exemplo n.º 2
0
 internal PathInfo GetNamespaceCurrentLocation(string namespaceID)
 {
     if (namespaceID == null)
     {
         throw PSTraceSource.NewArgumentNullException("namespaceID");
     }
     PSDriveInfo info = null;
     if (namespaceID.Length == 0)
     {
         this.ProvidersCurrentWorkingDrive.TryGetValue(this.CurrentDrive.Provider, out info);
     }
     else
     {
         this.ProvidersCurrentWorkingDrive.TryGetValue(this.GetSingleProvider(namespaceID), out info);
     }
     if (info == null)
     {
         System.Management.Automation.DriveNotFoundException exception = new System.Management.Automation.DriveNotFoundException(namespaceID, "DriveNotFound", SessionStateStrings.DriveNotFound);
         throw exception;
     }
     CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext) {
         Drive = info
     };
     string path = null;
     if (info.Hidden)
     {
         if (LocationGlobber.IsProviderDirectPath(info.CurrentLocation))
         {
             path = info.CurrentLocation;
         }
         else
         {
             path = LocationGlobber.GetProviderQualifiedPath(info.CurrentLocation, info.Provider);
         }
     }
     else
     {
         path = LocationGlobber.GetDriveQualifiedPath(info.CurrentLocation, info);
     }
     PathInfo info2 = new PathInfo(info, info.Provider, path, new SessionState(this));
     tracer.WriteLine("result = {0}", new object[] { info2 });
     return info2;
 }
Exemplo n.º 3
0
 internal void RemoveDrive(string driveName, bool force, string scopeID)
 {
     if (driveName == null)
     {
         throw PSTraceSource.NewArgumentNullException("driveName");
     }
     PSDriveInfo drive = this.GetDrive(driveName, scopeID);
     if (drive == null)
     {
         System.Management.Automation.DriveNotFoundException exception = new System.Management.Automation.DriveNotFoundException(driveName, "DriveNotFound", SessionStateStrings.DriveNotFound);
         throw exception;
     }
     this.RemoveDrive(drive, force, scopeID);
 }
Exemplo n.º 4
0
 private PSDriveInfo GetDrive(string name, bool automount)
 {
     if (name == null)
     {
         throw PSTraceSource.NewArgumentNullException("name");
     }
     PSDriveInfo drive = null;
     SessionStateScopeEnumerator enumerator = new SessionStateScopeEnumerator(this.CurrentScope);
     int num = 0;
     foreach (SessionStateScope scope in (IEnumerable<SessionStateScope>) enumerator)
     {
         drive = scope.GetDrive(name);
         if (drive != null)
         {
             if (drive.IsAutoMounted)
             {
                 if (drive.IsAutoMountedManuallyRemoved)
                 {
                     System.Management.Automation.DriveNotFoundException exception = new System.Management.Automation.DriveNotFoundException(name, "DriveNotFound", SessionStateStrings.DriveNotFound);
                     throw exception;
                 }
                 if (!this.ValidateOrRemoveAutoMountedDrive(drive, scope))
                 {
                     drive = null;
                 }
             }
             if (drive != null)
             {
                 tracer.WriteLine("Drive found in scope {0}", new object[] { num });
                 break;
             }
         }
         num++;
     }
     if ((drive == null) && automount)
     {
         drive = this.AutomountBuiltInDrive(name);
     }
     if ((drive == null) && (this == this._context.TopLevelSessionState))
     {
         drive = this.AutomountFileSystemDrive(name);
     }
     if (drive == null)
     {
         System.Management.Automation.DriveNotFoundException exception2 = new System.Management.Automation.DriveNotFoundException(name, "DriveNotFound", SessionStateStrings.DriveNotFound);
         throw exception2;
     }
     return drive;
 }