예제 #1
0
    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);
    }