public static Uri GenerateBlobFileSasLink(this string containerName, string blobName, TimeSpan?lifespan = default(TimeSpan?)) { var expiresOn = lifespan.HasValue ? DateTime.UtcNow + lifespan.Value : DateTime.UtcNow.AddMinutes(15);//default SAS token expire after 15 minutes. var blobSasBuilder = new BlobSasBuilder() { BlobContainerName = containerName, BlobName = blobName, ExpiresOn = expiresOn, }; blobSasBuilder.SetPermissions(BlobSasPermissions.Write); var azureDriver = AzureTableDriverDynamic.FromSettings(); var blobClient = azureDriver.BlobClient; var sharedKeyCredential = azureDriver.StorageSharedKeyCredential; var sasToken = blobSasBuilder.ToSasQueryParameters(sharedKeyCredential).ToString(); var sasUrl = blobClient.Uri .AppendToPath(containerName) .AppendToPath(blobName) .SetQuery(sasToken); return(sasUrl); }
public virtual Task <IHttpResponse> InstigatorDelegateGeneric(Type type, IApplication httpApp, IHttpRequest routeData, ParameterInfo parameterInfo, Func <object, Task <IHttpResponse> > onSuccess) { var constructor = typeof(StorageQuery <>) .MakeGenericType(type.GenericTypeArguments) .GetConstructors(BindingFlags.Public | BindingFlags.Instance) .First(); var parameter = AzureTableDriverDynamic.FromSettings(); var sq = constructor.Invoke(parameter.AsArray()); return(onSuccess(sq)); }
public static Func <Task <T> > GetLookupDelegate <T>(MemberInfo memberInfo, string rowKey, string partitionKey, IProvideEntity entityProvider) { var repository = AzureTableDriverDynamic.FromSettings(); var tableName = StorageLookupAttribute.GetMemberTableName(memberInfo); // var tableRef = repository.TableClient.GetTableReference(tableName); Func <Task <T> > lookupDelegate = () => repository.FindByIdAsync <T, T>(rowKey, partitionKey, onFound: (resource, tr) => resource, onNotFound: () => { if (typeof(T).IsArray) { return((T)typeof(T) .GetElementType() .ConstructEmptyArray()); } return(default(T)); }, tableName: tableName, entityProvider: entityProvider); return(lookupDelegate); }
public static IEnumerable <StorageTable> DiscoverStorageResources(Type appType) { var limitedAssemblyQuery = appType .GetAttributesInterface <IApiResources>(inherit: true, multiple: true); Func <Assembly, bool> shouldCheckAssembly = (assembly) => { return(limitedAssemblyQuery .First( (limitedAssembly, next) => { if (limitedAssembly.ShouldCheckAssembly(assembly)) { return true; } return next(); }, () => false)); }; var driver = AzureTableDriverDynamic.FromSettings(); return(AppDomain.CurrentDomain.GetAssemblies() .Where(shouldCheckAssembly) .SelectMany( a => { try { return a.GetTypes(); } catch (Exception) { return new Type[] { }; } }) .SelectMany( (type) => { return type .GetAttributesInterface <IProvideTable>() .Select( tableProvider => { var table = tableProvider.GetTable(type, driver.TableClient); var properties = type .StorageProperties() .Select( propInfoAttribute => { var propInfo = propInfoAttribute.Key; var name = propInfo.GetTablePropertyName(); var memberType = propInfo.GetMemberType(); return new StorageProperty() { name = name, type = memberType, member = propInfo, }; }) .ToArray(); return new StorageTable { name = table.Name, properties = properties, type = type, cloudTable = table, }; }); })); }