Ejemplo n.º 1
0
        // methods
        public async Task <bool> ExecuteAsync(IWriteBinding binding, CancellationToken cancellationToken)
        {
            using (var channelSource = await binding.GetWriteChannelSourceAsync(cancellationToken).ConfigureAwait(false))
            {
                IWriteOperation <bool> operation;
                if (channelSource.ServerDescription.Version >= __serverVersionSupportingUserManagementCommands)
                {
                    operation = new AddUserUsingUserManagementCommandsOperation(_databaseNamespace, _username, _passwordHash, _readOnly, _messageEncoderSettings);
                }
                else
                {
                    operation = new AddUserUsingSystemUsersCollectionOperation(_databaseNamespace, _username, _passwordHash, _readOnly, _messageEncoderSettings);
                }

                return(await operation.ExecuteAsync(channelSource, cancellationToken).ConfigureAwait(false));
            }
        }
Ejemplo n.º 2
0
        // methods
        public bool Execute(IWriteBinding binding, CancellationToken cancellationToken)
        {
            using (var channelSource = binding.GetWriteChannelSource(cancellationToken))
                using (var channel = channelSource.GetChannel(cancellationToken))
                    using (var channelBinding = new ChannelReadWriteBinding(channelSource.Server, channel, binding.Session.Fork()))
                    {
                        IWriteOperation <bool> operation;
                        if (Feature.UserManagementCommands.IsSupported(channel.ConnectionDescription.ServerVersion))
                        {
                            operation = new AddUserUsingUserManagementCommandsOperation(_databaseNamespace, _username, _passwordHash, _readOnly, _messageEncoderSettings);
                        }
                        else
                        {
                            operation = new AddUserUsingSystemUsersCollectionOperation(_databaseNamespace, _username, _passwordHash, _readOnly, _messageEncoderSettings);
                        }

                        return(operation.Execute(channelBinding, cancellationToken));
                    }
        }