// public System.Diagnostics.Process Process // { // get { return _process; } // } public UiaDriveInfo( PSDriveInfo drive) : base(drive) { Window = null; try{ Window = // 20131109 //AutomationElement.RootElement; UiElement.RootElement; //.SourceElement; } catch (Exception) { //WriteVerbose(e.Message); //WriteVerbose("UiaDriveInfo(PSDriveInfo)"); } }
protected override System.Collections.ObjectModel.Collection <System.Management.Automation.PSDriveInfo> InitializeDefaultDrives() { var driveInfo = new PSDriveInfo( "Triggers", ProviderInfo, "", "Data Source Triggers", null ); var drive = new TriggerDrive(driveInfo); return(new Collection <PSDriveInfo> { drive }); }
/// <summary> /// Initializes the variables drive /// </summary> /// /// <returns> /// An array of a single PSDriveInfo object representing the variables drive. /// </returns> /// protected override Collection <PSDriveInfo> InitializeDefaultDrives() { PSDriveInfo variableDrive = new PSDriveInfo( "Session", ProviderInfo, String.Empty, "Desc", null); Collection <PSDriveInfo> drives = new Collection <PSDriveInfo>(); drives.Add(variableDrive); return(drives); } // InitializeDefaultDrives
protected override PSDriveInfo RemoveDrive(PSDriveInfo drive) { if (drive == null) { WriteError(new ErrorRecord( new ArgumentNullException("drive"), "NullDrive", ErrorCategory.InvalidArgument, drive)); return(null); } NosDBPSDriveInfo noSDrive = drive as NosDBPSDriveInfo; return(noSDrive); }
/// <summary> /// Determines if the specified drive can be created. /// </summary> /// <param name="drive"></param> /// <returns></returns> protected override PSDriveInfo NewDrive(PSDriveInfo drive) { if (drive == null) { throw new ArgumentNullException("drive"); } if (string.IsNullOrWhiteSpace(drive.Root)) { ThrowError(Resources.Resource.NewDriveRootDoesNotExist, ErrorId.NewDriveRootDoesNotExist); return(null); } return(new SHiPSDrive(drive, drive.Root, this)); }
} // constructor #endregion Constructor #region DriveCmdletProvider overrides protected override Collection <PSDriveInfo> InitializeDefaultDrives() { PSDriveInfo variableDrive = new PSDriveInfo( "Cache", ProviderInfo, String.Empty, "Memory cache provider for Universal Dashboard", null); Collection <PSDriveInfo> drives = new Collection <PSDriveInfo>(); drives.Add(variableDrive); return(drives); } // InitializeDefaultDrives
/// <summary> /// Validate each path provided and if valid, add to array of paths to process. /// If path is a literal path it is added to the array to process; we cannot validate them until we /// try to process file contents. /// </summary> /// <param name="path"></param> /// <param name="literalPath"></param> /// <returns></returns> private List <string> ResolvePaths(string[] path, bool literalPath) { List <string> pathsToProcess = new List <string>(); ProviderInfo provider = null; PSDriveInfo drive = null; foreach (string currentPath in path) { List <string> newPaths = new List <string>(); if (literalPath) { newPaths.Add(Context.SessionState.Path.GetUnresolvedProviderPathFromPSPath(currentPath, out provider, out drive)); } else { try { newPaths.AddRange(Context.SessionState.Path.GetResolvedProviderPathFromPSPath(currentPath, out provider)); } catch (ItemNotFoundException e) { if (!WildcardPattern.ContainsWildcardCharacters(currentPath)) { ErrorRecord errorRecord = new ErrorRecord(e, "FileNotFound", ErrorCategory.ObjectNotFound, path); WriteError(errorRecord); continue; } } } if (!provider.Name.Equals("FileSystem", StringComparison.OrdinalIgnoreCase)) { // Write a non-terminating error message indicating that path specified is not supported. string errorMessage = StringUtil.Format(UtilityCommonStrings.FormatHexOnlySupportsFileSystemPaths, currentPath); ErrorRecord errorRecord = new ErrorRecord(new ArgumentException(errorMessage), "FormatHexOnlySupportsFileSystemPaths", ErrorCategory.InvalidArgument, currentPath); WriteError(errorRecord); continue; } pathsToProcess.AddRange(newPaths); } return(pathsToProcess); }
public ObjectManagerPSDriveInfo(NtObject root, PSDriveInfo drive_info) : base(drive_info) { if (root is NtDirectory dir) { DirectoryRoot = new NtDirectoryContainer(dir); } else if (root is NtKey key) { DirectoryRoot = new NtKeyContainer(key); } else { throw new ArgumentException($"Invalid root object. {root.NtTypeName}"); } }
/// <summary> /// Initializes the function drive /// </summary> /// <returns> /// An array of a single PSDriveInfo object representing the functions drive. /// </returns> protected override Collection<PSDriveInfo> InitializeDefaultDrives() { string description = SessionStateStrings.FunctionDriveDescription; PSDriveInfo functionDrive = new PSDriveInfo( DriveNames.FunctionDrive, ProviderInfo, String.Empty, description, null); Collection<PSDriveInfo> drives = new Collection<PSDriveInfo>(); drives.Add(functionDrive); return drives; }
internal Collection <PSDriveInfo> GetDriveFromProviderInfo() { var drives = new Collection <PSDriveInfo>(); string providerName = GetType().GetCustomAttributes(typeof(CmdletProviderAttribute), true) .OfType <CmdletProviderAttribute>() .Select(attribute => attribute.ProviderName) .FirstOrDefault(); if (!String.IsNullOrEmpty(providerName)) { var drive = new PSDriveInfo(ProviderInfo.Name, ProviderInfo, string.Empty, string.Empty, null); drives.Add(drive); } return(drives); }
/// <summary> /// This override removes a drive from the provider. /// </summary> /// <param name="drive">The drive to remove.</param> /// <returns>The drive removed.</returns> protected override PSDriveInfo RemoveDrive(PSDriveInfo drive) { // Check if drive object is null if (drive == null) { WriteError(new ErrorRecord( new ArgumentNullException("drive"), "NullDrive", ErrorCategory.InvalidArgument, drive)); return(null); } return(drive); }
protected override PSDriveInfo NewDrive(PSDriveInfo drive) { // Check if the drive object is null. if (drive == null) { WriteError(new ErrorRecord( new ArgumentNullException("drive"), "NullDrive", ErrorCategory.InvalidArgument, null)); return(null); } // Check if the drive root is not null or empty // and if it is an existing file. if (String.IsNullOrEmpty(drive.Root)) { WriteError(new ErrorRecord( new ArgumentException("drive.Root"), "NoRoot", ErrorCategory.InvalidArgument, drive)); return(null); } // Create a new Consul drive from the default one passed. ConsulPSDriveInfo consulPSDriveInfo; try { consulPSDriveInfo = new ConsulPSDriveInfo(drive); } catch (Exception ex) { WriteError(new ErrorRecord( new ArgumentException("drive.Root"), ex.Message, ErrorCategory.InvalidArgument, drive)); return(null); } return(consulPSDriveInfo); }
/// <summary> /// Internal wrapper for the NewDrive protected method. It is called instead /// of the protected method that is overridden by derived classes so that the /// context of the command can be set. /// </summary> /// <param name="drive"> /// The PSDriveInfo object the represents the drive to be mounted. /// </param> /// <param name="context"> /// The context under which this method is being called. /// </param> /// <returns> /// The drive that was returned from the protected NewDrive method. /// </returns> internal PSDriveInfo NewDrive(PSDriveInfo drive, CmdletProviderContext context) { Context = context; // Make sure the provider supports credentials if they were passed // in the drive. if (drive.Credential != null && drive.Credential != PSCredential.Empty && !CmdletProviderManagementIntrinsics.CheckProviderCapabilities(ProviderCapabilities.Credentials, ProviderInfo)) { throw PSTraceSource.NewNotSupportedException( SessionStateStrings.NewDriveCredentials_NotSupported); } return(NewDrive(drive)); }
/// <summary> /// Initializes the alias drive. /// </summary> /// <returns> /// An array of a single PSDriveInfo object representing the alias drive. /// </returns> protected override Collection <PSDriveInfo> InitializeDefaultDrives() { string description = SessionStateStrings.EnvironmentDriveDescription; PSDriveInfo envDrive = new PSDriveInfo( DriveNames.EnvironmentDrive, ProviderInfo, string.Empty, description, null); Collection <PSDriveInfo> drives = new Collection <PSDriveInfo>(); drives.Add(envDrive); return(drives); }
public Context(IContext context, object dynamicParameters) { Context c = context as Context; if (null == c) { throw new ArgumentException("the context provided is of an incompatible type"); } _provider = c._provider; _drive = c._drive; _path = c._path; _pathProcessor = c._pathProcessor; DynamicParameters = dynamicParameters; _recurse = c.Recurse; PathTopologyVersion = c.PathTopologyVersion; }
protected override PSDriveInfo NewDrive(PSDriveInfo drive) { // Check if the drive object is null. if (drive == null) { WriteError(new ErrorRecord( new ArgumentNullException("drive"), "NullDrive", ErrorCategory.InvalidArgument, null)); return(null); } var d = new PSDriveInfo(name: drive.Name, provider: drive.Provider, root: PathResolver.Root, description: null, credential: null); return(d); }
protected override PSDriveInfo NewDrive(PSDriveInfo drive) { // Check if the drive object is null. if (drive == null) { WriteError(new ErrorRecord( new ArgumentNullException("drive"), "Null Drive", ErrorCategory.InvalidArgument, null)); return(null); } var info = new GithubDriveInfo(drive); return(info); }
protected override PSDriveInfo NewDrive(PSDriveInfo drive) { try { var driveInfo = new System.IO.DriveInfo(System.IO.Path.GetPathRoot(drive.Root)); if (driveInfo.DriveType == System.IO.DriveType.Fixed) { return((ItemExists(drive.Root) && IsItemContainer(drive.Root)) ? drive : null); } return(drive); } catch { } return(null); }
protected override Collection <PSDriveInfo> InitializeDefaultDrives() { Collection <PSDriveInfo> collection = new Collection <PSDriveInfo>(); // TODO: Console.WriteLine("Mono: Before GetDrives"); DriveInfo[] drives = DriveInfo.GetDrives(); // TODO: Console.WriteLine("Mono: After GetDrives"); System.Diagnostics.Debug.WriteLine("Number of drives: " + ((drives == null) ? "Null drives" : drives.Length.ToString())); if (drives != null) { foreach (DriveInfo driveInfo in drives) { System.Diagnostics.Debug.WriteLine(string.Format("drive '{0}' type '{1}' root '{2}'", driveInfo.Name, driveInfo.DriveType.ToString(), driveInfo.RootDirectory)); // Support for Mono names - there are no ':' (colon) in the name string name = driveInfo.Name; if (driveInfo.Name.IndexOf(':') > 0) { name = driveInfo.Name.Substring(0, 1); } string description = string.Empty; string root = driveInfo.Name; if (driveInfo.DriveType == DriveType.Fixed) { try { description = driveInfo.VolumeLabel; root = driveInfo.RootDirectory.FullName; } catch { } } PSDriveInfo info = new PSDriveInfo(name, base.ProviderInfo, root, description, null); info.RemovableDrive = driveInfo.DriveType != DriveType.Fixed; collection.Add(info); } } return(collection); }
/// <summary> /// Create a new drive. Create a connection to the database file and set /// the Connection property in the PSDriveInfo. /// </summary> /// <param name="drive"> /// Information describing the drive to add. /// </param> /// <returns>The added drive.</returns> protected override PSDriveInfo NewDrive(PSDriveInfo drive) { // check if drive object is null if (drive == null) { WriteError(new ErrorRecord( new ArgumentNullException("drive"), "NullDrive", ErrorCategory.InvalidArgument, null) ); return(null); } // check if drive root is not null or empty // and if its an existing file if (String.IsNullOrEmpty(drive.Root) || (File.Exists(drive.Root) == false)) { WriteError(new ErrorRecord( new ArgumentException("drive.Root"), "NoRoot", ErrorCategory.InvalidArgument, drive) ); return(null); } // create a new drive and create an ODBC connection to the new drive AccessDBPSDriveInfo accessDBPSDriveInfo = new AccessDBPSDriveInfo(drive); OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder(); builder.Driver = "Microsoft Access Driver (*.mdb)"; builder.Add("DBQ", drive.Root); OdbcConnection conn = new OdbcConnection(builder.ConnectionString); conn.Open(); accessDBPSDriveInfo.Connection = conn; return(accessDBPSDriveInfo); } // NewDrive
private List <string> ResolvePath(string path, bool isLiteral) { ProviderInfo provider = null; PSDriveInfo drive = null; List <string> resolvedPaths = new(); try { if (isLiteral) { resolvedPaths.Add(Context.SessionState.Path.GetUnresolvedProviderPathFromPSPath(path, out provider, out drive)); } else { resolvedPaths.AddRange(Context.SessionState.Path.GetResolvedProviderPathFromPSPath(path, out provider)); } } catch (ItemNotFoundException infe) { var errorRecord = new ErrorRecord( infe, "FileNotFound", ErrorCategory.ResourceUnavailable, path); WriteError(errorRecord); } if (!provider.Name.Equals("FileSystem", StringComparison.OrdinalIgnoreCase)) { string errorMessage = StringUtil.Format(ConvertMarkdownStrings.FileSystemPathsOnly, path); ErrorRecord errorRecord = new( new ArgumentException(), "OnlyFileSystemPathsSupported", ErrorCategory.InvalidArgument, path); WriteError(errorRecord); return(null); } return(resolvedPaths); }
public DriveInfo(PSDriveInfo driveInfo, DriveParameters driveParameters) : base(driveInfo) { // Validate root. new Uri(this.Root, UriKind.Absolute); if (this.Root.Contains(@"\") || this.Root.EndsWith("/")) { throw new ArgumentException(@"Root must not contain '\' or end with '/'."); } // Store the drive parameters. this.driveParameters = driveParameters; // Store the personal access token as secure string and set the unsecure string to null. if (!string.IsNullOrEmpty(this.driveParameters.PersonalAccessToken)) { this.PersonalAccessToken = SecureStringHelper.ConvertToSecureString(this.driveParameters.PersonalAccessToken); this.driveParameters.PersonalAccessToken = null; } }
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); }
internal NoSDbDetail(string[] pathChunks, PSDriveInfo drive) { if (ConfigurationConnection.ClusterConfiguration != null) { PathChunks = pathChunks; Drive = (NosDBPSDriveInfo)drive; ClusterConfiguration configuration = ConfigurationConnection.ClusterConfiguration; new ConfigClusterInfo(ConfigurationConnection.ConfigCluster); Configuration = configuration; IsContainer = true; IsValid = true; NodeType = PathType.NoSDB; ChilderanName = new List <string>(); ChilderanTable = new PrintableTable(); ChilderanTable.AddHeader("Database Cluster"); ChilderanTable.AddRow(ConfigurationConnection.ClusterConfiguration.DisplayName); ChilderanName.Add(ConfigurationConnection.ClusterConfiguration.DisplayName); } }
private CmdletProvider GetProviderByPath(string path) { // MUST: implement for "dir" if (string.IsNullOrEmpty(path)) { path = CurrentLocation.Path; } string driveName = PathIntrinsics.GetDriveFromPath(path); PSDriveInfo drive = GetDrive(driveName, null); if (drive == null) { return(null); } return(GetProviderInstance(drive.Provider.Name)); }
protected CloudDriveBase(PSDriveInfo driveInfo, RootName rootName, CloudDriveParameters parameters) : base(driveInfo) { if (driveInfo == null) { throw new ArgumentNullException(nameof(driveInfo)); } this.rootName = rootName; DisplayRoot = rootName.Value; if (parameters != null) { apiKey = parameters.ApiKey; encryptionKey = parameters.EncryptionKey; } if (string.IsNullOrEmpty(encryptionKey)) { DisplayRoot = DisplayRoot.Insert(0, "*"); } }
internal string GetDriveQualifiedPath(string providerPath, PSDriveInfo drive) { // expects a provider specific path // NOTE: When a drive is hidden, it means that we usually don't want to see the // drive qualifier. This is for example the case for the default file system drive // on non-Windows systems if (drive == null || String.IsNullOrEmpty(drive.Name) || drive.Hidden) { return(providerPath); } var path = providerPath; var sep = PathIntrinsics.CorrectSlash; if (path.StartsWith(drive.Root)) { path = path.Substring(drive.Root.Length).TrimStart(sep, PathIntrinsics.WrongSlash); } return(drive.Name + ":" + sep + path); }
protected override PSDriveInfo NewDrive(PSDriveInfo drive) { if (drive == null) { WriteError(new ErrorRecord( new ArgumentNullException("drive"), "NullDrive", ErrorCategory.InvalidArgument, null)); return(null); } if (String.IsNullOrWhiteSpace(drive.Root)) { WriteError(new ErrorRecord( new ArgumentException("drive.Root"), "NoRoot", ErrorCategory.InvalidArgument, drive)); return(null); } try { using (NtDirectory dir = NtDirectory.Open(drive.Root)) { ObjectManagerPSDriveInfo objmgr_drive = new ObjectManagerPSDriveInfo(dir.Duplicate(), drive); return(objmgr_drive); } } catch (NtException ex) { WriteError(new ErrorRecord( ex, "NoRoot", ErrorCategory.PermissionDenied, drive)); return(null); } }
internal PathInfo SetLocation(string path, ProviderRuntime providerRuntime) { // TODO: deal with paths starting with ".\" if (path == null) { throw new NullReferenceException("Path can't be null"); } path = PathIntrinsics.NormalizePath(path); ProviderInfo provider = null; string driveName = null; string str = path; string providerId = null; PSDriveInfo currentDrive = CurrentDrive; // If path doesn't start with a drive name if (path.StartsWith(PathIntrinsics.CorrectSlash.ToString())) { provider = CurrentLocation.Provider; } else if (PathIntrinsics.IsAbsolutePath(path, out driveName)) { _currentDrive = GetDrive(driveName, null); path = PathIntrinsics.NormalizePath(PathIntrinsics.RemoveDriveName(path)); } _currentDrive.CurrentLocation = path; _providersCurrentDrive[CurrentDrive.Provider] = CurrentDrive; SetVariable("PWD", CurrentLocation); return(CurrentLocation); PSDriveInfo drive = CurrentDrive; SetLocation(path); }
/// <summary> /// The Windows PowerShell engine calls this method when the New-Drive /// cmdlet is run. This provider creates a connection to the database /// file and sets the Connection property in the PSDriveInfo. /// </summary> /// <param name="drive"> /// Information describing the drive to create. /// </param> /// <returns>An object that describes the new drive.</returns> protected override PSDriveInfo NewDrive(PSDriveInfo drive) { // Check to see if the supplied drive object is null. if (drive == null) { WriteError(new ErrorRecord( new ArgumentNullException("drive"), "NullDrive", ErrorCategory.InvalidArgument, null)); return null; } // Check to see if the drive root is not null or empty // and if it iss an existing file. if (String.IsNullOrEmpty(drive.Root) || (File.Exists(drive.Root) == false)) { WriteError(new ErrorRecord( new ArgumentException("drive.Root"), "NoRoot", ErrorCategory.InvalidArgument, drive)); return null; } // Create the new drive and create an ODBC connection // to the new drive. var accessDBPSDriveInfo = new AccessDBPSDriveInfo(drive); var builder = new OdbcConnectionStringBuilder(); builder.Driver = "Microsoft Access Driver (*.mdb)"; builder.Add("DBQ", drive.Root); var conn = new OdbcConnection(builder.ConnectionString); conn.Open(); accessDBPSDriveInfo.Connection = conn; return accessDBPSDriveInfo; }
protected override PSDriveInfo RemoveDrive(PSDriveInfo drive) { WriteVerbose($"SPOProvider::RemoveDrive (Drive.Name = ’{drive.Name}’)"); var spoDrive = drive as SPODriveInfo; if (spoDrive == null) { return(null); } //Remove proxy aliases if (spoDrive.Provider.Drives.Count < 2) { SPOProxyImplementation.RemoveAlias(SessionState); } spoDrive.ClearState(); return(spoDrive); }
/// <summary> /// Initializes a new instance of the AccessDBPSDriveInfo class. /// </summary> /// <param name="driveInfo">Drive provided by this provider</param> public AccessDBPSDriveInfo(PSDriveInfo driveInfo) : base(driveInfo) { }
// End NewDrive method. /// <summary> /// The Windows PowerShell engine calls this method when the /// Remove-Drive cmdlet is run. This provider removes a drive /// from the Access database. /// </summary> /// <param name="drive">The drive to remove.</param> /// <returns>The drive to be removed.</returns> protected override PSDriveInfo RemoveDrive(PSDriveInfo drive) { // Check to see if the supplied drive object is null. if (drive == null) { WriteError(new ErrorRecord( new ArgumentNullException("drive"), "NullDrive", ErrorCategory.InvalidArgument, drive)); return null; } // Close the ODBC connection to the drive. var accessDBPSDriveInfo = drive as AccessDBPSDriveInfo; if (accessDBPSDriveInfo == null) { return null; } accessDBPSDriveInfo.Connection.Close(); return accessDBPSDriveInfo; }
internal PSDriveInfo NewDrive(PSDriveInfo drive, ProviderRuntime runtime) { ProviderRuntime = runtime; return NewDrive(drive); }
internal PSDriveInfo RemoveDrive(PSDriveInfo drive, ProviderRuntime runtime) { ProviderRuntime = runtime; return RemoveDrive(drive); }
/// <summary> /// /// </summary> /// <param name="cmdlet"></param> /// <param name="path"></param> /// <param name="credential"></param> internal UpdatableHelpSystemDrive(PSCmdlet cmdlet, string path, PSCredential credential) { for (int i = 0; i < 6; i++) { _driveName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()); _cmdlet = cmdlet; // Need to get rid of the trailing \, otherwise New-PSDrive will not work... if (path.EndsWith("\\", StringComparison.OrdinalIgnoreCase) || path.EndsWith("/", StringComparison.OrdinalIgnoreCase)) { path = path.Remove(path.Length - 1); } PSDriveInfo mappedDrive = cmdlet.SessionState.Drive.GetAtScope(_driveName, "local"); if (mappedDrive != null) { if (mappedDrive.Root.Equals(path)) { return; } // Remove the drive after 5 tries if (i < 5) { continue; } cmdlet.SessionState.Drive.Remove(_driveName, true, "local"); } mappedDrive = new PSDriveInfo(_driveName, cmdlet.SessionState.Internal.GetSingleProvider("FileSystem"), path, String.Empty, credential); cmdlet.SessionState.Drive.New(mappedDrive, "local"); break; } }
protected virtual PSDriveInfo NewDrive(PSDriveInfo drive) { return drive; }
protected virtual PSDriveInfo RemoveDrive(PSDriveInfo drive) { throw new NotImplementedException(); }
internal PSDriveInfo DoNewDrive(PSDriveInfo drive) { return NewDrive(drive); }
protected virtual PSDriveInfo RemoveDrive(PSDriveInfo drive) { return drive; //nothing special to do per default }