/// <summary> /// Returns the date and time the specified file or directory was last written to. /// </summary> /// <param name="path">Path to file.</param> public override DateTime GetLastWriteTime(string path) { if (!this.Exists(path)) { throw GetFileNotFoundException(path); } IS3ObjectInfo info = S3ObjectFactory.GetInfo(path); if (Provider.ObjectExists(info)) { return(S3ObjectInfoProvider.GetStringDateTime(info.GetMetadata(S3ObjectInfoProvider.LAST_WRITE_TIME))); } return(System.IO.File.GetLastAccessTime(path)); }
protected void Page_Load(object sender, EventArgs e) { string hash = QueryHelper.GetString("hash", string.Empty); string path = QueryHelper.GetString("path", string.Empty); // Validate hash if (ValidationHelper.ValidateHash("?path=" + URLHelper.EscapeSpecialCharacters(path), hash, false)) { if (path.StartsWithCSafe("~")) { path = Server.MapPath(path); } // Get file content from Amazon S3 IS3ObjectInfo obj = S3ObjectFactory.GetInfo(path); // Check if blob exists if (Provider.ObjectExists(obj)) { // Clear response. CookieHelper.ClearResponseCookies(); Response.Clear(); // Set the revalidation SetRevalidation(); DateTime lastModified = S3ObjectInfoProvider.GetStringDateTime(obj.GetMetadata(S3ObjectInfoProvider.LAST_WRITE_TIME)); string etag = "\"" + lastModified.ToString() + "\""; // Set correct response content type SetResponseContentType(path); // Client caching - only on the live site if (AllowCache && AllowClientCache && ETagsMatch(etag, lastModified)) { // Set the file time stamps to allow client caching SetTimeStamps(lastModified); RespondNotModified(etag, true); return; } Stream stream = Provider.GetObjectContent(obj); SetDisposition(Path.GetFileName(path), Path.GetExtension(path)); // Setup Etag property ETag = etag; if (AllowCache) { // Set the file time stamps to allow client caching SetTimeStamps(lastModified); Response.Cache.SetETag(etag); } else { SetCacheability(); } // Send headers Response.Flush(); Byte[] buffer = new Byte[StorageHelper.BUFFER_SIZE]; int bytesRead = stream.Read(buffer, 0, StorageHelper.BUFFER_SIZE); // Copy data from blob stream to cache while (bytesRead > 0) { // Write the data to the current output stream Response.OutputStream.Write(buffer, 0, bytesRead); // Flush the data to the output Response.Flush(); // Read next part of data bytesRead = stream.Read(buffer, 0, StorageHelper.BUFFER_SIZE); } stream.Close(); CompleteRequest(); } else { NotFound(); } } else { URLHelper.Redirect(ResolveUrl("~/CMSMessages/Error.aspx?title=" + ResHelper.GetString("general.badhashtitle") + "&text=" + ResHelper.GetString("general.badhashtext"))); } }