/// <summary> /// Transfers properties from result to current instance /// </summary> /// <param name="parsePathResult"></param> private void TransferParseResult( QuickIOParsePathResult parsePathResult ) { FullNameUnc = parsePathResult.FullNameUnc; FullName = parsePathResult.FullName; ParentFullName = parsePathResult.ParentPath; RootFullName = parsePathResult.RootPath; IsRoot = parsePathResult.IsRoot; PathLocation = parsePathResult.PathLocation; this.PathType = parsePathResult.PathType; if ( PathLocation == QuickIOPathLocation.Local ) { var testRoot = IsRoot ? FullName : RootFullName; if ( !Array.Exists( Environment.GetLogicalDrives( ), delegate( string drve ) { return drve.Equals( testRoot, StringComparison.OrdinalIgnoreCase ); } ) ) { throw new UnsupportedDriveType( testRoot ); } } }
/// <summary> /// Transfers properties from result to current instance /// </summary> /// <param name="parsePathResult"></param> private void TransferParseResult( QuickIOParsePathResult parsePathResult ) { FullNameUnc = parsePathResult.FullNameUnc; FullName = parsePathResult.FullName; ParentFullName = parsePathResult.ParentPath; RootFullName = parsePathResult.RootPath; IsRoot = parsePathResult.IsRoot; PathLocation = parsePathResult.PathLocation; this.PathType = parsePathResult.PathType; }
/// <summary> /// Try to parse path /// </summary> /// <param name="path">Path to parse</param> /// <param name="parsePathResult">Result. See <see cref="QuickIOParsePathResult"/></param> /// <param name="supportRelativePath">true to support relative path</param> /// <returns>True on success. <paramref name="parsePathResult"/> is set.</returns> public static Boolean TryParsePath( String path, out QuickIOParsePathResult parsePathResult, bool supportRelativePath = true ) { if ( QuickIOPath.TryParseLocalRegularPath( path, out parsePathResult ) ) { return true; } if ( QuickIOPath.TryParseLocalUncPath( path, out parsePathResult ) ) { return true; } if ( QuickIOPath.TryParseShareRegularPath( path, out parsePathResult ) ) { return true; } if ( QuickIOPath.TryParseShareUncPath( path, out parsePathResult ) ) { return true; } if ( supportRelativePath && QuickIOPath.TryParseLocalRegularPath( Path.GetFullPath( path ), out parsePathResult ) ) { return true; } return false; }
/// <summary> /// Returns true if specified <paramref name="path"/> is share UNC path and returns result due to <paramref name="parsePathResult"/> /// </summary> /// <param name="path">QuickIOShareInfo UNC path to parse</param> /// <param name="parsePathResult"><see cref="QuickIOParsePathResult"/></param> /// <returns>True if parse succeeded and <paramref name="parsePathResult"/> is filled</returns> public static Boolean TryParseShareUncPath( String path, out QuickIOParsePathResult parsePathResult ) { if ( !IsShareUncPath( path ) ) { parsePathResult = null; return false; } parsePathResult = new QuickIOParsePathResult { PathLocation = QuickIOPathLocation.Share, PathType = QuickIOPathType.UNC }; var cleanedPath = path.TrimEnd( '\\' ); var pathElements = cleanedPath.Substring( QuickIOPath.UncSharePathPrefixLength ).Split( '\\' ); var server = pathElements[ 0 ]; var name = pathElements[ 1 ]; var completeRelativePath = server + @"\" + name; for ( int i = 2 ; i < pathElements.Length ; i++ ) { completeRelativePath += "\\" + pathElements[ i ]; } // set parsePathResult.IsRoot = ( cleanedPath == ( QuickIOPath.UncSharePathPrefix + server + @"\" + name ) ); if ( parsePathResult.IsRoot ) { parsePathResult.ParentPath = null; parsePathResult.RootPath = null; parsePathResult.Name = null; parsePathResult.FullNameUnc = QuickIOPath.UncSharePathPrefix + server + @"\" + name; parsePathResult.FullName = QuickIOPath.RegularSharePathPrefix + server + @"\" + name; } else { parsePathResult.FullName = QuickIOPath.RegularSharePathPrefix + completeRelativePath; parsePathResult.FullNameUnc = QuickIOPath.UncSharePathPrefix + completeRelativePath; parsePathResult.ParentPath = QuickIOPath.RegularSharePathPrefix + completeRelativePath.Substring( 0, completeRelativePath.LastIndexOf( Path.DirectorySeparatorChar ) ); parsePathResult.RootPath = QuickIOPath.RegularSharePathPrefix + server + @"\" + name; parsePathResult.Name = pathElements[ pathElements.Length - 1 ]; } return true; }
/// <summary> /// Returns true if specified <paramref name="path"/> is local UNC path and returns result due to <paramref name="parsePathResult"/> /// </summary> /// <param name="path">Local UNC path to parse</param> /// <param name="parsePathResult"><see cref="QuickIOParsePathResult"/></param> /// <returns>True if parse succeeded and <paramref name="parsePathResult"/> is filled</returns> public static Boolean TryParseLocalUncPath( String path, out QuickIOParsePathResult parsePathResult ) { if ( !IsLocalUncPath( path ) ) { parsePathResult = null; return false; } parsePathResult = new QuickIOParsePathResult { PathLocation = QuickIOPathLocation.Local, PathType = QuickIOPathType.UNC }; if ( path.Length == 7 ) { parsePathResult.IsRoot = true; parsePathResult.ParentPath = null; parsePathResult.RootPath = null; parsePathResult.FullNameUnc = path; parsePathResult.FullName = path.Substring( 4 ); parsePathResult.Name = null; } else { parsePathResult.IsRoot = false; parsePathResult.FullNameUnc = path.TrimEnd( Path.DirectorySeparatorChar ); parsePathResult.FullName = parsePathResult.FullNameUnc.Substring( 4 ); parsePathResult.ParentPath = parsePathResult.FullName.Substring( 0, parsePathResult.FullName.LastIndexOf( Path.DirectorySeparatorChar ) ); parsePathResult.RootPath = path.Substring( 4, 3 ); parsePathResult.Name = parsePathResult.FullName.Substring( parsePathResult.FullName.LastIndexOf( Path.DirectorySeparatorChar ) + 1 ); } return true; }