public override void Delete(FileNode file) { string folderPath = MapPath(GetFolderPath(file)); if (Directory.Exists(folderPath)) { Directory.Delete(folderPath, true); } }
protected virtual string GetFolderPath(FileNode file, char separatorChar) { var hexadecimalId = file.Id.ToString("x16"); // Divide the ID into portions, so each folder has no more than 16^3 files var idParts = _idSplitter.Match(hexadecimalId).Groups.Cast<Group>() .SelectMany(g => g.Captures.Cast<Capture>()).Skip(1) .Select(c => c.Value.TrimStart('0').PadLeft(1, '0')).ToArray(); return string.Join(new string(separatorChar, 1), idParts); }
public override void Write(FileNode file, Stream input) { string folderPath = MapPath(GetFolderPath(file)); Directory.CreateDirectory(folderPath); string filePath = MapPath(GetFilePath(file)); using (FileStream output = File.Create(filePath)) { CopyStream(input, output); } }
protected virtual string GetFilePath(FileNode file, char separatorChar) { string folder = GetFolderPath(file, separatorChar); return string.Format("{0}" + separatorChar + "{1}", folder, file.Filename); }
public abstract void Write(FileNode file, Stream input);
public abstract Stream Read(FileNode file);
public abstract Uri GetUrl(FileNode file);
public abstract void Delete(FileNode file);
protected override string GetFolderPath(FileNode file, char separatorChar) { string folder = GetFolderPath(file, separatorChar); return string.Format("{0}" + separatorChar + "{1}", "media", folder); }
public override Stream Read(FileNode file) { string filePath = MapPath(GetFilePath(file)); return new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); }
public override Uri GetUrl(FileNode file) { return new Uri(string.Format("/{0}", GetFilePath(file, '/')), UriKind.Relative); }
/// <remarks> /// This helper is only relevant as we translate paths using /// HostingEnvironment.MapPath. If we were talking directly to the file /// system Path.DirectorySeparatorChar should be used. /// </remarks> private string GetFolderPath(FileNode file) { return GetFolderPath(file, '/'); }