public async Task Execute(IUpdateApplicationCodeFeatureState command, CancellationToken cancellationToken = new CancellationToken()) { CloudTable cloudTable = _tableProvider.GetTable(_settings.ApplicationCodeFeatureStateTableName); var entity = new ApplicationCodeFeatureStateEntity(command.ApplicationId, command.CodeFeatureId, command.Timestamp, command.Enabled, command.CommandId); var current = new ApplicationCodeFeatureStateEntity(command.ApplicationId, command.CodeFeatureId, command.Timestamp, command.Enabled, command.CommandId); current.SetCurrent(); IEnumerable <Task <TableResult> > writeTasks = new[] { entity, current } .Select(x => cloudTable.ExecuteAsync(TableOperation.InsertOrReplace(x), cancellationToken)); await Task.WhenAll(writeTasks); var updateEvent = new ApplicationCodeFeatureStateUpdated(command.ApplicationId, command.CodeFeatureId, command.Enabled, command.Timestamp, command.CommandId); Task <IApplicationCodeFeatureStateUpdated> eventTask = Task.FromResult <IApplicationCodeFeatureStateUpdated>(updateEvent); await Task.WhenAll(_eventHandlers.Select(x => x.Handle(eventTask))); }
public async Task <IEnumerable <ICodeFeatureState> > Execute(IListApplicationCodeFeatures query, CancellationToken cancellationToken = new CancellationToken()) { CloudTable featureStateTable = _tableProvider.GetTable(_settings.ApplicationCodeFeatureStateTableName); TableQuery <ApplicationCodeFeatureStateEntity> featureStateQuery = new TableQuery <ApplicationCodeFeatureStateEntity>() .Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, ApplicationCodeFeatureStateEntity.GetCurrentPartitionKey(query.ApplicationId))); IEnumerable <CodeFeatureState> featureStates = await featureStateTable.ExecuteQueryAsync(featureStateQuery, entity => new CodeFeatureState(new CodeFeatureId(entity.CodeFeatureId), entity.Timestamp.UtcDateTime, entity.Enabled), cancellationToken); CloudTable featureTable = _tableProvider.GetTable(_settings.ApplicationCodeFeatureTableName); TableQuery <ApplicationCodeFeatureEntity> featureQuery = new TableQuery <ApplicationCodeFeatureEntity>() .Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, query.ApplicationId)); IEnumerable <CodeFeatureState> features = await featureTable.ExecuteQueryAsync(featureQuery, entity => new CodeFeatureState(new CodeFeatureId(entity.CodeFeatureId), entity.Timestamp.UtcDateTime, false), cancellationToken); // include the default (not-enabled) feature states for features which have not been initialized return(featureStates.Union(features)); }