public static async Task <IHttpResponse> QueueUpBackupPartitions(
            [Property(Name = IdPropertyName)] IRef <RepositoryBackup> repositoryBackupRef,
            [Property(Name = StorageSettingCopyFromPropertyName)] string storageSettingCopyFrom,
            [Property(Name = StorageSettingCopyToPropertyName)] string storageSettingCopyTo,
            [Resource] RepositoryBackup repositoryBackup,
            AzureApplication application,
            EastFive.Api.Security security,
            RequestMessage <TableBackup> requestQuery,
            IHttpRequest request,
            EastFive.Analytics.ILogger logger,
            MultipartAsyncResponse <InvocationMessage> onQueued,
            AlreadyExistsResponse onAlreadyExists)
        {
            CloudStorageAccount account = CloudStorageAccount
                                          .Parse(storageSettingCopyFrom);
            CloudTableClient tableClient =
                new CloudTableClient(account.TableEndpoint, account.Credentials);

            return(await repositoryBackup.StorageCreateAsync(
                       (discard) =>
            {
                var includedTables = BackupFunction.DiscoverStorageResources()
                                     .Where(x => x.message.Any())
                                     .Select(x => x.tableName)
                                     .ToArray();

                var resourceInfoToProcess = tableClient.GetTables()
                                            .Where(table => includedTables.Contains(table.Name, StringComparer.OrdinalIgnoreCase))
                                            .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;
                })
                                            .Await(readAhead: 10);
                return onQueued(resourceInfoToProcess);
            },
                       () => onAlreadyExists()));
        }
Exemplo n.º 2
0
        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()));
        }
Exemplo n.º 3
0
 public static async Task <HttpResponseMessage> CreateAsync(
     [Property(Name = IdPropertyName)] IRef <TableBackup> tableBackupRef,
     [Property(Name = WhenPropertyName)] DateTime when,
     [Property(Name = TableNamePropertyName)] string tableName,
     [Property(Name = IdPropertyName)] IRef <RepositoryBackup> repositoryBackupRef,
     [Resource] TableBackup tableBackup,
     RequestMessage <TableBackup> requestQuery,
     HttpRequestMessage request,
     EastFive.Analytics.ILogger logger,
     CreatedBodyResponse <InvocationMessage> onCreated,
     AlreadyExistsResponse onAlreadyExists)
 {
     return(await await tableBackup.StorageCreateAsync(
                async (entity) =>
     {
         var invocationMessage = await requestQuery
                                 .ById(tableBackupRef)
                                 .HttpPatch(default)
        public static async Task <IHttpResponse> QueueUpBackupPartitions(
            [Property(Name = IdPropertyName)] IRef <RepositoryBackup> repositoryBackupRef,
            [Property(Name = WhenPropertyName)] DateTime when,
            RequestMessage <TableBackup> requestQuery,
            IHttpRequest request,
            EastFive.Analytics.ILogger logger,
            MultipartAsyncResponse <InvocationMessage> onQueued,
            NoContentResponse onTooEarly,
            NotFoundResponse onNotFound)
        {
            return(await repositoryBackupRef.StorageUpdateAsync(
                       async (repoBack, saveAsync) =>
            {
                var needsToRun = NCrontab.CrontabSchedule.TryParse(repoBack.frequency,
                                                                   chronSchedule =>
                {
                    var next = chronSchedule.GetNextOccurrence(repoBack.when);
                    if (when > next)
                    {
                        return true;
                    }
                    return false;
                },
                                                                   ex =>
                {
                    return false;
                });
                if (!needsToRun)
                {
                    return onTooEarly();
                }

                var includedTables = BackupFunction.DiscoverStorageResources()
                                     .Where(x => x.message.Any())
                                     .Select(x => x.tableName)
                                     .ToArray();

                CloudStorageAccount account = CloudStorageAccount
                                              .Parse(repoBack.storageSettingCopyFrom);
                CloudTableClient tableClient =
                    new CloudTableClient(account.TableEndpoint, account.Credentials);

                var tables = tableClient.GetTables();
                var resourceInfoToProcess = tables
                                            .Where(table => includedTables.Contains(table.Name, StringComparer.OrdinalIgnoreCase))
                                            .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;
                })
                                            .Await(readAhead: 10);
                repoBack.when = when;
                await saveAsync(repoBack);

                return onQueued(resourceInfoToProcess);
            },
                       () => onNotFound()));
        }