示例#1
0
 public override void Delete(FileNode file)
 {
     string folderPath = MapPath(GetFolderPath(file));
     if (Directory.Exists(folderPath))
     {
         Directory.Delete(folderPath, true);
     }
 }
示例#2
0
        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);
        }
示例#3
0
        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);
            }
        }
示例#4
0
        protected virtual string GetFilePath(FileNode file, char separatorChar)
        {
            string folder = GetFolderPath(file, separatorChar);

            return string.Format("{0}" + separatorChar + "{1}", folder, file.Filename);
        }
示例#5
0
 public abstract void Write(FileNode file, Stream input);
示例#6
0
 public abstract Stream Read(FileNode file);
示例#7
0
 public abstract Uri GetUrl(FileNode file);
示例#8
0
 public abstract void Delete(FileNode file);
示例#9
0
        protected override string GetFolderPath(FileNode file, char separatorChar)
        {
            string folder = GetFolderPath(file, separatorChar);

            return string.Format("{0}" + separatorChar + "{1}", "media", folder);
        }
示例#10
0
        public override Stream Read(FileNode file)
        {
            string filePath = MapPath(GetFilePath(file));

            return new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
        }
示例#11
0
 public override Uri GetUrl(FileNode file)
 {
     return new Uri(string.Format("/{0}", GetFilePath(file, '/')), UriKind.Relative);
 }
示例#12
0
 /// <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, '/');
 }