public async Task <Variable> CreateAsync( string name, string @namespace, bool isSecret, string?defaultValue, CancellationToken cancellationToken) { Variable variable = new(Guid.NewGuid(), VariableState.Active, name, isSecret, @namespace); await _variableStore.CreateAsync(variable, cancellationToken); if (defaultValue != null) { CreateVariableChange log = new(variable.Id, variable.Version, variable); using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { await _changeLogService.CreateAsync(log, cancellationToken); await SaveVariableValueAsync( variable, defaultValue, cancellationToken : cancellationToken); transaction.Complete(); } } return(variable); }
public async Task <Component> CreateAsync( string name, string?schemaSdl, IDictionary <string, object?>?values, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("Value cannot be null or empty.", nameof(name)); } string?serializedValues = null; if (schemaSdl is not null) { ISchema schema = _schemaService.CreateSchema(schemaSdl); if (values is not null) { serializedValues = _schemaService.CreateValuesForSchema(schema, values); } } Component component = new(Guid.NewGuid(), name, schemaSdl, serializedValues, ComponentState.Active); CreateComponentChange log = new(component.Id, component.Version, component); using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { await _changeLogService.CreateAsync(log, cancellationToken); await _componentStore.AddAsync(component, cancellationToken); transaction.Complete(); } return(component); }