public static Boolean AreSame( VirtualDirectoryPath vpath1, VirtualDirectoryPath vpath2, Boolean verbose ) { DirectoryInfo directory1 = new DirectoryInfo( vpath1.Path ); DirectoryInfo directory2 = new DirectoryInfo( vpath2.Path ); return AreSame( directory1, directory2, verbose ); }
/// <summary> /// Converts a string to a VirtualFilepath instance /// </summary> /// <param name="path"> /// Can be a local path (in which case the local machine is the host) or "MACHINENAME,c:\local\path" /// </param> /// <param name="throwOnInvalidPath"> /// throw exception if the path is not syntactically valid /// </param> /// <param name="throwIfNotDirectoryPath">throw exception is path is to a file</param> /// <param name="throwOnNotExists">throw exception if the directory or file does not exist</param> /// <returns>A VirtualDirectoryPath object</returns> public static VirtualDirectoryPath Parse ( string path, Boolean throwOnInvalidPath = false, Boolean throwIfNotDirectoryPath = false, Boolean throwOnNotExists = false) { string hostName = System.Environment.MachineName; string localPath = null; #region Validate if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentNullException(nameof(path)); } else if (path.StartsWith(@"\\")) { throw new fr.ScarabException("UNC paths are not supported"); } if (path.Contains(",")) { var split = path.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); hostName = split[0]; localPath = System.IO.Path.GetFullPath(split[1]); } else { localPath = System.IO.Path.GetFullPath(path); } if (!CommonRegex.LocalFsoPathRegex.IsMatch(localPath)) { if (throwOnInvalidPath) { throw new ScarabException("Failed to parse path '{0}'", path); } else { return(null); } } #endregion VirtualDirectoryPath ret = new VirtualDirectoryPath ( hostName, localPath, throwIfNotDirectoryPath: throwIfNotDirectoryPath, throwOnNotExists: throwOnNotExists ); Debug.Assert(ret != null); return(ret); }
public static async Task CopyDirectoryTreeAsync ( VirtualDirectoryPath sourceDirectory, VirtualDirectoryPath targetDirectory, CollisionRemediation cr, Boolean deleteSourceDirectory = false) { await CopyDirectoryTreeAsync ( sourceDirectory.Path, targetDirectory.Path, cr, deleteSourceDirectory ); }
public static void CopyDirectoryTree2 ( VirtualDirectoryPath sourceDirectory, VirtualDirectoryPath targetDirectory, CollisionRemediation cr, Boolean deleteSourceDirectory = false) { CopyDirectoryTree2 ( sourceDirectory.Path, targetDirectory.Path, cr, deleteSourceDirectory ); }
public override Boolean Equals(object obj) { // If parameter is null return false if (obj == null) { return(false); } VirtualDirectoryPath other = obj as VirtualDirectoryPath; if ((System.Object)other == null) { return(false); } // Return true if the fields match (may be referenced by derived classes) return(this.GetHashCode() == other.GetHashCode()); }
public override object ConvertFrom ( ITypeDescriptorContext ctx, CultureInfo ci, object data) { VirtualDirectoryPath vfp = VirtualDirectoryPath.Parse ( data.ToString(), true, // Just 'throwOnInvalidPath' can be true, since file paths or false, // nonexistent paths could legitimately be in config files false ); Debug.Assert(vfp != null); return(vfp); }
/// <summary> /// This code performs the actual conversion from a VirtualDirectoryPath to an InstanceDescriptor. /// </summary> public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) { ConstructorInfo ci = typeof(VirtualDirectoryPath).GetConstructor ( new Type[] { typeof(string), typeof(string), typeof(Boolean) } ); VirtualDirectoryPath t = ( VirtualDirectoryPath )value; return(new InstanceDescriptor(ci, new object[] { t.HostName, t.LocalPath, false })); } // Always call base, even if you can't convert. return(base.ConvertTo(context, culture, value, destinationType)); }