public ICentralizedFile GetFile(string path, string fileName) { if (!CentralizedFileStorage.IsValid(this.FileStoreKey, path, fileName)) { throw new ApplicationException("The provided path and/or file name is invalid"); } var file = this.GetAmazonS3FileStorageFileFromCache(path, fileName); if (file == null) { lock (_lockbox.GetObject(this.CreateAmazonS3FileStorageFilePrimaryKey(path, fileName).GetHashCode())) { file = this.GetAmazonS3FileStorageFileFromCache(path, fileName); if (file == null) { ObjectMetaDataResponse response = GetConnection().GetMetadata(this._bucketName, MakeKey(path, fileName), new SortedList()); if (response != null) { file = new AmazonS3FileStorageFile(this.FileStoreKey, path, fileName, (int)response.ContentLength); } if (file != null) { this.PushAmazonS3FileStorageFileToCache(file, path, fileName); } } } } return(file); }
private AmazonS3PathQueryResults QueryPath(string path, PathSearchOption searchOption) { var results = this.GetAmazonS3PathQueryResultsFromCache(path, searchOption); if (results == null) { lock (_lockbox.GetObject(this.CreateAmazonS3PathQueryResultsPrimaryKey(path, searchOption).GetHashCode())) { results = this.GetAmazonS3PathQueryResultsFromCache(path, searchOption); if (results == null) { var files = new List<AmazonS3FileStorageFile>(); var subPaths = new List<string>(); ObjectListResponse response = searchOption != PathSearchOption.AllPaths ? this.GetConnection().ListBucket(this._bucketName, this.MakeKey(path, string.Empty), "", int.MaxValue, "/", new SortedList<string, string>()) : this.GetConnection().ListBucket(this._bucketName, this.MakeKey(path, string.Empty), "", int.MaxValue, new SortedList<string, string>()); foreach (var commonPrefixEntry in response.CommonPrefixEntries) subPaths.Add(this.GetPath(commonPrefixEntry.Prefix, false)); foreach (var entry in response.Entries) { string filePath = GetPath(entry.Key); string fileName = GetFileName(entry.Key); AmazonS3FileStorageFile file = this.GetAmazonS3FileStorageFileFromCache(filePath, fileName); if (file == null) { lock (_lockbox.GetObject(this.CreateAmazonS3FileStorageFilePrimaryKey(filePath, fileName).GetHashCode())) { file = this.GetAmazonS3FileStorageFileFromCache(filePath, fileName); if (file == null) { file = new AmazonS3FileStorageFile(this.FileStoreKey, filePath, fileName, (int)entry.ContentLength); this.PushAmazonS3FileStorageFileToCache(file, filePath, fileName); } } } files.Add(file); } results = new AmazonS3PathQueryResults(subPaths, files); this.PushAmazonS3PathQueryResultsToCache(results, path, searchOption); } } } return results; }
public ICentralizedFile GetFile(string path, string fileName) { if (!CentralizedFileStorage.IsValid(this.FileStoreKey, path, fileName)) throw CreateFilePathInvalidException(path, fileName); var file = this.GetAmazonS3FileStorageFileFromCache(path, fileName); if (file == null) { lock (_lockbox.GetObject(this.CreateAmazonS3FileStorageFilePrimaryKey(path, fileName).GetHashCode())) { file = this.GetAmazonS3FileStorageFileFromCache(path, fileName); if (file == null) { ObjectMetaDataResponse metadata = GetConnection().GetMetadata(this._bucketName, MakeKey(path, fileName), new SortedList<string, string>()); if (metadata != null) file = new AmazonS3FileStorageFile(this.FileStoreKey, path, fileName, (int)metadata.ContentLength); if (file != null) this.PushAmazonS3FileStorageFileToCache(file, path, fileName); } } } return file; }
private void PushAmazonS3FileStorageFileToCache(AmazonS3FileStorageFile file, string path, string fileName) { var key = this.CreateAmazonS3FileStorageFilePrimaryKey(path, fileName); Evolution.Extensibility.Caching.Version1.CacheService.Put(key, file, CacheScope.All); }
private void PushAmazonS3FileStorageFileToCache(AmazonS3FileStorageFile file, string path, string fileName) { CacheService.Put(this.CreateAmazonS3FileStorageFilePrimaryKey(path, fileName), (object)file, CacheScope.All); }