public ClaimStorageController() : base(new DefaultStorageProvider()) { this.claimsDbContext = new ClaimsDbContext(); this.containerNameResolver = new DefaultContainerNameResolver(); }
/// <inheritdoc /> public async override Task <IEnumerable <MobileServiceFile> > GetRecordFilesAsync(string tableName, string recordId, IContainerNameResolver containerNameResolver) { if (tableName == null) { throw new ArgumentException(nameof(tableName)); } if (recordId == null) { throw new ArgumentException(nameof(recordId)); } if (containerNameResolver == null) { throw new ArgumentNullException(nameof(containerNameResolver)); } IEnumerable <string> containerNames = await containerNameResolver.GetRecordContainerNames(tableName, recordId); var files = new List <MobileServiceFile>(); foreach (var containerName in containerNames) { IEnumerable <CloudBlockBlob> blobs = await GetContainerFilesAsync(containerName); files.AddRange(blobs.Select(b => MobileServiceFile.FromBlobItem(b, tableName, recordId))); } return(files); }
/// <inheritdoc /> public async override Task DeleteFileAsync(string tableName, string recordId, string fileName, IContainerNameResolver containerNameResolver) { if (tableName == null) { throw new ArgumentException(nameof(tableName)); } if (recordId == null) { throw new ArgumentException(nameof(recordId)); } if (fileName == null) { throw new ArgumentException(nameof(fileName)); } if (containerNameResolver == null) { throw new ArgumentNullException(nameof(containerNameResolver)); } string containerName = await containerNameResolver.GetFileContainerNameAsync(tableName, recordId, fileName); CloudBlobContainer container = GetContainer(containerName); CloudBlockBlob blob = container.GetBlockBlobReference(fileName); await blob.DeleteIfExistsAsync(); }
/// <summary> /// Gets a storage token for the given entity ID and <see cref="StorageTokenRequest"/>, using the provided <see cref="IContainerNameResolver"/>. /// </summary> /// <param name="id">The entity id.</param> /// <param name="value">The request provided by the client.</param> /// <param name="containerNameResolver">The instance of an <see cref="IContainerNameResolver"/> used to resolve the storage container name.</param> /// <returns></returns> public virtual async Task <StorageToken> GetStorageTokenAsync(string id, StorageTokenRequest value, IContainerNameResolver containerNameResolver) { StorageTokenScope scope = GetStorageScopeForRequest(id, value); StorageToken token = await this.storageProvider.GetAccessTokenAsync(value, scope, containerNameResolver); return(token); }
/// <inheritdoc /> public async override Task <StorageToken> GetAccessTokenAsync(StorageTokenRequest request, StorageTokenScope scope, IContainerNameResolver containerNameResolver) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (containerNameResolver == null) { throw new ArgumentNullException(nameof(containerNameResolver)); } string containerName = await containerNameResolver.GetFileContainerNameAsync(request.TargetFile.TableName, request.TargetFile.ParentId, request.TargetFile.Name); CloudBlobContainer container = GetContainer(containerName); var constraints = new SharedAccessBlobPolicy(); constraints.SharedAccessExpiryTime = DateTime.UtcNow.AddHours(1); constraints.Permissions = GetBlobAccessPermissions(request.Permissions); string sas = null; Uri resourceUri = null; if (scope == StorageTokenScope.File) { CloudBlockBlob blob = container.GetBlockBlobReference(request.TargetFile.Name); resourceUri = blob.Uri; sas = blob.GetSharedAccessSignature(constraints); } else if (scope == StorageTokenScope.Record) { resourceUri = container.Uri; sas = container.GetSharedAccessSignature(constraints); } var storageToken = new StorageToken(resourceUri, request.TargetFile.ParentId, request.Permissions, scope, sas); return(storageToken); }
/// <summary> /// Deletes a file. /// </summary> /// <param name="id">The id of the entity that owns the file.</param> /// <param name="name">The name of the file to be deleted.</param> /// <param name="containerNameResolver">The instance of an <see cref="IContainerNameResolver"/> used to resolve the storage container name.</param> /// <returns>A <see cref="Task"/> that completes when the delete operation finishes.</returns> public async Task DeleteFileAsync(string id, string name, IContainerNameResolver containerNameResolver) { await this.storageProvider.DeleteFileAsync(GetTableName(), id, name, containerNameResolver); }
/// <summary> /// Gets the list of files for the provided entity ID /// </summary> /// <param name="id">The entity id.</param> /// <param name="containerNameResolver">The instance of an <see cref="IContainerNameResolver"/> used to resolve the storage container name.</param> /// <returns>A <see cref="Task"/> that completes when the list of <see cref="MobileServiceFile"/> is available.</returns> public async Task <IEnumerable <MobileServiceFile> > GetRecordFilesAsync(string id, IContainerNameResolver containerNameResolver) { return(await this.storageProvider.GetRecordFilesAsync(GetTableName(), id, containerNameResolver)); }
/// <summary> /// Retrieves an access token for a given request. /// </summary> /// <param name="request">The request the requested access </param> /// <param name="scope"></param> /// <param name="containerNameResolver">The instance of an <see cref="IContainerNameResolver"/> used to resolve the storage container name.</param> /// <returns>A <see cref="Task{StorageToken}"/> that completes when the storage token is generated.</returns> abstract public Task <StorageToken> GetAccessTokenAsync(StorageTokenRequest request, StorageTokenScope scope, IContainerNameResolver containerNameResolver);
/// <summary> /// Deletes a file. /// </summary> /// <param name="tableName">The table (entity) name.</param> /// <param name="recordId">The entity id.</param> /// <param name="fileName">The name of the file to be deleted.</param> /// <param name="containerNameResolver">The instance of an <see cref="IContainerNameResolver"/> used to resolve the storage container name.</param> /// <returns>A <see cref="Task"/> that completes when the delete operation is finished.</returns> abstract public Task DeleteFileAsync(string tableName, string recordId, string fileName, IContainerNameResolver containerNameResolver);
/// <summary> /// Gets the files associated with a record. /// </summary> /// <param name="tableName">The table (entity) name.</param> /// <param name="recordId">The entity id.</param> /// <param name="containerNameResolver">The instance of an <see cref="IContainerNameResolver"/> used to resolve the storage container name.</param> /// <returns>A <see cref="Task{TResult}"/> that completes when the list of files is retrieved.</returns> abstract public Task <IEnumerable <MobileServiceFile> > GetRecordFilesAsync(string tableName, string recordId, IContainerNameResolver containerNameResolver);