public CachedFileResult(VirtualFile file, DateTime?lastModifiedUtc = null, string contentType = null) { Guard.NotNull(file, nameof(file)); try { var fi = GetFileInfo(file.VirtualPath); if (fi.Exists) { ContentType = contentType.NullEmpty() ?? MimeTypes.MapNameToMimeType(fi.Name); FileLength = fi.Length; LastModifiedUtc = fi.LastWriteTimeUtc; } } finally { if (lastModifiedUtc == null) { throw new ArgumentNullException(nameof(lastModifiedUtc), "A modification date must be provided if the VirtualFile cannot be mapped to a physical path."); } if (FileLength == null) { ContentType = contentType.NullEmpty() ?? MimeTypes.MapNameToMimeType(file.Name); using (var stream = file.Open()) { FileLength = stream.Length; } } } Transmitter = new FileStreamTransmitter(file.Open); LastModifiedUtc = lastModifiedUtc.Value; }
public CachedFileResult(string contentType, DateTime lastModifiedUtc, Func <Stream> factory, long?fileLength = null) { Guard.NotNull(factory, nameof(factory)); Guard.NotEmpty(contentType, nameof(contentType)); Transmitter = new FileStreamTransmitter(factory); ContentType = contentType; FileLength = fileLength; LastModifiedUtc = lastModifiedUtc; }
public CachedFileResult(IFile file, string contentType = null) { Guard.NotNull(file, nameof(file)); if (!file.Exists) { throw new FileNotFoundException(file.Path); } Transmitter = new FileStreamTransmitter(file.OpenRead); ContentType = contentType.NullEmpty() ?? MimeTypes.MapNameToMimeType(file.Name); FileLength = file.Size; LastModifiedUtc = file.LastUpdated; }