public static IOResource From(string value, bool strict = true) { var resource = FileResource.From(value, strict: false) ?? FolderResource.From(value, strict: false) as IOResource; ExpectNot(strict && resource == null, "Value is not an I/O resource"); return(resource); }
public static bool TryFrom(string folder, string name, out FileResource resource, bool extensionOptional = false) { resource = FileName.TryFrom(name, out var parsedName, extensionOptional) ? new FileResource(FolderResource.From(folder), parsedName) : null; return(resource != null); }
private IEnumerable <FolderLink> ReadFolderLinksCore(FolderResource subfolder, bool recursive = false) { var folderPath = Link.Then(subfolder).ToString(); var pattern = "*.*"; var option = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; return(Directory.GetDirectories(folderPath, pattern, option).Select(subdirectory => FolderLink.From(subdirectory))); }
public static FileResource From(FolderResource folder, string name, bool extensionOptional = false) { if (!TryFrom(folder, name, out var resource, extensionOptional)) { throw new FormatException($"Failed to parse file name: {name}"); } return(resource); }
// // Subfolder reads // public Many <IOResource> ReadFolder(FolderResource subfolder, bool recursive = false) { return(ReadLinksCore(subfolder, recursive) .Select(link => { return link is FolderLink ? ((FolderLink)link).RelativeTo(Link) : ((FileLink)link).RelativeTo(Link) as IOResource; }) .ToMany()); }
public void Write(FolderResource folder, bool overwrite = true) { var folderPath = Link.Then(folder).ToString(); if (Directory.Exists(folderPath)) { return; } Expect(overwrite, "Folder exists and overwrite option is not set"); Directory.CreateDirectory(folderPath); }
public static bool TryFrom(string value, out IOResource resource) { if (FileResource.TryFrom(value, out var file)) { resource = file; } else { resource = FolderResource.From(value); } return(resource != null); }
public void Delete(FolderResource folder, bool strict = true) { var folderPath = Link.Then(folder).ToString(); if (Directory.Exists(folderPath)) { Directory.Delete(folderPath, recursive: true); } else { if (strict) { ExpectNot(strict, "Folder not found"); } } }
public static FolderLink FromLocal(string value, bool strict = true) { var parsedFolder = FolderResource.From(value, strict); if (parsedFolder != null && parsedFolder.Path.Segments.Count > 0) { var path = parsedFolder.Path.Segments.Count == 1 ? LinkPath.Root : LinkPath.From(parsedFolder.Path.Segments.Skip(1)); return(new FolderLink(parsedFolder.Path.Segments[0], FolderResource.From(path))); } Expect(strict, "Cannot parse folder link: " + value); return(null); }
public static bool TryFromLocal(string value, out FolderLink link) { link = null; var path = FolderResource.From(value).Path; if (path.Segments.Any()) { var root = path.Segments[0]; var resource = path.Segments.Count == 1 ? LinkPath.Root : LinkPath.From(path.Segments.Skip(1)); link = new FolderLink(root, FolderResource.From(resource)); } return(link != null); }
public static bool TryFromUnc(string value, out FolderLink link) { link = null; if (!String.IsNullOrEmpty(value) && HasUncPrefix(value)) { var path = FolderResource.From(value.Substring(2)).Path; var root = $@"\\{path.Segments[0]}"; var resource = path.Segments.Count == 1 ? LinkPath.Root : LinkPath.From(path.Segments.Skip(1)); link = new FolderLink(root, FolderResource.From(resource), isUnc: true); } return(link != null); }
public static FolderLink FromUnc(string value, bool strict = true) { if (!String.IsNullOrEmpty(value) && value.StartsWith(@"\\")) { var parsedFolder = FolderResource.From(value.Substring(2), strict); if (parsedFolder != null) { var root = @"\\" + parsedFolder.Path.Segments[0].ToString(); var path = parsedFolder.Path.Segments.Count == 1 ? LinkPath.Root : LinkPath.From(parsedFolder.Path.Segments.Skip(1)); return(new FolderLink(root, FolderResource.From(path), isUnc: true)); } } ExpectNot(strict, "Cannot parse UNC link: " + value); return(null); }
public static bool TryFrom(string value, out FileResource resource, bool extensionOptional = false) { resource = null; var parsedFolder = FolderResource.From(value); var file = parsedFolder.Path.Segments.LastOrDefault()?.ToString(); if (file != null) { if (FileName.TryFrom(file, out var parsedFile, extensionOptional)) { if (!parsedFolder.TryUp(out var folderUp)) { folderUp = parsedFolder; } resource = new FileResource(folderUp, parsedFile); } } return(resource != null); }
public new static FileResource From(string value, bool strict = true) { var parsedFolder = FolderResource.From(value, strict); if (parsedFolder != null) { var fileSegment = parsedFolder.Path.Segments.LastOrDefault(); if (fileSegment != null) { var parsedName = FileName.From(fileSegment.ToString(), strict); if (parsedName != null) { return(new FileResource(parsedFolder.Up(strict: false), parsedName)); } } } ExpectNot(strict, "Cannot parse file resource"); return(null); }
public bool FolderExists(FolderResource subfolder) { return(Directory.Exists(Link.Then(subfolder).ToString())); }
public void Move(FolderResource sourceFolder, FolderResource destinationFolder) { Directory.Move(Link.Then(sourceFolder).ToString(), Link.Then(destinationFolder).ToString()); }
public static FileResource From(FolderResource folder, string name, bool strict = true) { var parsedName = FileName.From(name, strict); return(parsedName == null ? null : new FileResource(folder, parsedName)); }
public FolderLink Then(FolderResource folder) => new FolderLink(Root, Resource.Then(folder));
// // Factory // public static FileResource From(FolderResource folder, FileName name) { return(new FileResource(folder, name)); }
public static FileResource From(string folder, string name, bool strict = true) { var parsedFolder = FolderResource.From(folder, strict); return(parsedFolder == null ? null : From(parsedFolder, name, strict)); }
public Many <FolderResource> ReadFolders(FolderResource subfolder, bool recursive = false) { return(ReadFolderLinksCore(subfolder, recursive).Select(folderLink => folderLink.RelativeTo(Link)).ToMany()); }
public static FileResource From(string folder, FileName name) => From(FolderResource.From(folder), name);
public static FileResource From(FolderResource folder, FileName name) => new FileResource(folder, name);
public static HttpResource From(FolderResource folder) => From(folder.ToString(altSlash: true));
public IFolder Then(FolderResource folder) { return(new LocalFolder(Link.Then(folder))); }
FileResource(FolderResource folder, FileName name) { Folder = folder; Name = name; }
public Many <FolderLink> ReadFolderLinks(FolderResource subfolder, bool recursive = false) { return(ReadFolderLinksCore(subfolder, recursive).ToMany()); }
public FileResource RelativeTo(FolderResource folder) => new FileResource(Folder.RelativeTo(folder), Name);
public static bool TryFrom(LinkText root, string resource, out FolderLink link) { link = From(root, FolderResource.From(resource)); return(true); }
public FileResource RelativeTo(FolderResource folder) { return(new FileResource(Folder.RelativeTo(folder), Name)); }