protected override void WriteEntireEntity(HttpResponseBase response) { try { response.TransmitFile(FileName); } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause { } }
protected override void WriteEntityRange(HttpResponseBase response, long rangeStartIndex, long rangeEndIndex) { int length = Convert.ToInt32(rangeEndIndex - rangeStartIndex) + 1; try { response.TransmitFile(FileName, rangeStartIndex, length); } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause { } }
public virtual bool SendContent(string url, HttpResponseBase response) { var file = GetFileNameFromConfig(url); try { response.TransmitFile(file); RRTracer.Trace("{0} transmitted from disk.", url); return true; } catch (FileNotFoundException) { try { response.TransmitFile(file.Insert(file.LastIndexOf('-'), "-Expired")); RRTracer.Trace("{0} was expired and transmitted from disk.", url); return true; } catch (FileNotFoundException) { return false; } } }
public void Serve(HttpResponseBase response, long offset, long length) { response.TransmitFile(FileName, offset, length); }
public void Serve(HttpResponseBase response) { response.TransmitFile(FileName); }
private bool TryTransmitIfContains(string id, HttpResponseBase response) { if (EnableAutoPurge) { QueueAutoPurge(); } string path = BuildFilePath(id); lock (GetFileLockObject(id)) { if (File.Exists(path)) { response.TransmitFile(path); return true; } else { return false; } } }
/// <summary> /// Writes file to response, adds correct headers based on Request headers and file attributes /// </summary> /// <param name="response"></param> protected virtual void TransmitFile(HttpResponseBase response) { var contentLength = ContentLength(); response.StatusCode = SendRange() ? (int)HttpStatusCode.PartialContent : (int)HttpStatusCode.OK; response.AppendHeader(HttpHeaders.ContentLength, contentLength.ToString(CultureInfo.InvariantCulture)); response.AppendHeader(HttpHeaders.AcceptRanges, "bytes"); response.AppendHeader(HttpHeaders.ContentRange, string.Format("bytes {0}-{1}/{2}", _range.Start, _range.End, _file.Length)); if(!string.IsNullOrWhiteSpace(_downloadFileName)) { response.AddHeader("Content-Disposition", string.Format("attachment;filename=\"{0}\"", _downloadFileName)); } try { response.TransmitFile(FileName, _range.Start, contentLength); } catch (Exception ex) { if(LogException != null) { LogException(ex); } } }
protected override void WriteFile(HttpResponseBase response) { response.TransmitFile(FileName); }
private bool TryTransmitIfContains (string id, HttpResponseBase response, string imgFile) { var tmpFiles = Directory.GetFiles (CachePath, id + "_*" + tmpFileExtension); // check if we have cache files if (tmpFiles.Length > 0) { // TODO: Log warning about duplicate cache entries // we expect to find just one file for each ID var tmpFile = tmpFiles [0]; lock (GetFileLockObject(tmpFile)) { // get tmp short filename without extension var tmpFileName = Path.GetFileNameWithoutExtension (Path.GetFileName (tmpFile)); // extract expire time var expireTime = DateTime.MinValue; var timeIndex = tmpFileName.LastIndexOf ("_") + 1; if (timeIndex > 0) expireTime = DateTime.FromFileTime ( Convert.ToInt64(tmpFileName.Substring (timeIndex))); var hitCache = false; if (imgFile == "") { // check if cache is expired hitCache = expireTime >= DateTime.Now; } else if (timeIndex == 0) { // use original file last write time var imgFileInfo = new FileInfo (imgFile); var tmpFileInfo = new FileInfo (tmpFile); hitCache = tmpFileInfo.LastWriteTime > imgFileInfo.LastWriteTime; } if (hitCache) { response.TransmitFile (tmpFile); return true; } else { File.Delete (tmpFile); return false; } } } return false; }