internal static AzureTableDriverDynamic GetRepository(string connectionString) { if (!repositories.TryGetValue(connectionString, out AzureTableDriverDynamic repository)) { repository = AzureTableDriverDynamic.FromStorageString(connectionString); if (!repositories.TryAdd(connectionString, repository)) { repositories.TryGetValue(connectionString, out repository); } } return(repository); }
public static async Task <HttpResponseMessage> QueueUpBackupPartitions( [Property(Name = IdPropertyName)] IRef <RepositoryBackup> repositoryBackupRef, [Property(Name = StorageSettingCopyFromPropertyName)] string storageSettingCopyFrom, [Property(Name = StorageSettingCopyToPropertyName)] string storageSettingCopyTo, [Resource] RepositoryBackup repositoryBackup, AzureApplication application, RequestMessage <TableBackup> requestQuery, HttpRequestMessage request, EastFive.Analytics.ILogger logger, MultipartResponseAsync <InvocationMessage> onQueued, AlreadyExistsResponse onAlreadyExists) { logger.Trace($"Cleaning backup results"); var repo = AzureTableDriverDynamic.FromStorageString(storageSettingCopyTo); await DeleteAllAsync(GetRepository(storageSettingCopyTo)); CloudStorageAccount account = CloudStorageAccount .Parse(storageSettingCopyFrom); CloudTableClient tableClient = new CloudTableClient(account.TableEndpoint, account.Credentials); return(await await repositoryBackup.StorageCreateAsync( (discard) => { var resourceInfoToProcess = tableClient .ListTables() .Distinct() .Select( async cloudTable => { var tableBackup = new TableBackup() { tableBackupRef = Ref <TableBackup> .NewRef(), backup = repositoryBackupRef, tableName = cloudTable.Name, when = DateTime.UtcNow, }; var invocationMessage = await requestQuery .HttpPost(tableBackup) .CompileRequest(request) .FunctionAsync(); logger.Trace($"Invocation[{invocationMessage.id}] will backup table `{tableBackup.tableName}`."); return invocationMessage; }) .AsyncEnumerable(); return onQueued(resourceInfoToProcess); }, () => onAlreadyExists().AsTask())); }
public static Task <TResult> LoadSpaFile <TResult>( Func <Stream, TResult> onFound, Func <TResult> onNotFound) { return(EastFive.Azure.AppSettings.SPA.SpaStorage.ConfigurationString( async connectionString => { try { var blobClient = AzureTableDriverDynamic.FromStorageString(connectionString).BlobClient; var containerName = Persistence.AppSettings.SpaContainer.ConfigurationString(name => name); var container = blobClient.GetBlobContainerClient(containerName); var blobRef = container.GetBlobClient("spa.zip"); var blobStream = await blobRef.OpenReadAsync(); return onFound(blobStream); } catch { return onNotFound(); } }, why => onNotFound().AsTask())); }
private void ExtractSpaFiles(AzureApplication application) { bool setup = EastFive.Azure.Persistence.AppSettings.SpaStorage.ConfigurationString( connectionString => { ZipArchive zipArchive = null; try { var blobClient = AzureTableDriverDynamic.FromStorageString(connectionString).BlobClient; var containerName = EastFive.Azure.Persistence.AppSettings.SpaContainer.ConfigurationString(name => name); var container = blobClient.GetContainerReference(containerName); var blobRef = container.GetBlockBlobReference("spa.zip"); var blobStream = blobRef.OpenRead(); zipArchive = new ZipArchive(blobStream); } catch { indexHTML = System.Text.Encoding.UTF8.GetBytes("SPA Not Installed"); return(false); } using (zipArchive) { indexHTML = zipArchive.Entries .First(item => string.Compare(item.FullName, IndexHTMLFileName, true) == 0) .Open() .ToBytes(); lookupSpaFile = ConfigurationContext.Instance.GetSettingValue(EastFive.Azure.AppSettings.SpaSiteLocation, (siteLocation) => { application.Telemetry.TrackEvent($"SpaHandlerModule - ExtractSpaFiles siteLocation: {siteLocation}"); return(zipArchive.Entries .Where(item => string.Compare(item.FullName, IndexHTMLFileName, true) != 0) .Select( entity => { if (!entity.FullName.EndsWith(".js")) { return entity.FullName.PairWithValue(entity.Open().ToBytes()); } var fileBytes = entity.Open() .ToBytes() .GetString() .Replace("8FCC3D6A-9C25-4802-8837-16C51BE9FDBE.example.com", siteLocation) .GetBytes(); return entity.FullName.PairWithValue(fileBytes); }) .ToDictionary()); }, () => { application.Telemetry.TrackException(new ArgumentNullException("Could not find SpaSiteLocation - is this key set in app settings?")); return(new Dictionary <string, byte[]>()); }); } return(true); }, why => false); }