public string BuildETagFromPath(ControllerContext context, string absolutePath) { var sb = new StringBuilder("\""); using (var stream = new FileStream(absolutePath, FileMode.Open)) { sb.Append(stream.MD5()); } if (HasGzipFilter(context)) { sb.Append(GzipTag); } else if (HasDeflateFilter(context)) { sb.Append(DeflateTag); } sb.Append("\""); return sb.ToString(); }
// used for getting art from a file. private Art CreateArt(string filePath) { FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); // compute the hash of the file stream Art art = new Art(); art.Md5Hash = fs.MD5(); art.FileSize = fs.Length; art.LastModified = System.IO.File.GetLastWriteTime(fs.Name).ToUnixTime(); art.ArtId = Injection.Kernel.Get<IArtRepository>().ArtIdForMd5(art.Md5Hash); art.FilePath = filePath; if ((object)art.ArtId == null) { art.ArtId = Injection.Kernel.Get<IItemRepository>().GenerateItemId(ItemType.Art); Injection.Kernel.Get<IArtRepository>().InsertArt(art); } // Dispose file stream fs.Close(); return art; }