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()));
        }
        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()));
        }