コード例 #1
1
 private BsonValue ExecuteOperation(EvalOperation operation, IWriteBinding binding, bool async)
 {
     if (async)
     {
         return operation.ExecuteAsync(binding, CancellationToken.None).GetAwaiter().GetResult();
     }
     else
     {
         return operation.Execute(binding, CancellationToken.None);
     }
 }
コード例 #2
0
        public Task <BsonValue> RunScriptAsync(string command, CancellationToken cancellationToken)
        {
            var script       = new BsonJavaScript(command);
            var operation    = new EvalOperation(_database.DatabaseNamespace, script, null);
            var writeBinding = new WritableServerBinding(_client.Cluster);

            return(operation.ExecuteAsync(writeBinding, CancellationToken.None));
        }
コード例 #3
0
        protected async Task <BsonValue> EvalAsync(string javascript)
        {
            var function = new BsonJavaScript(javascript);
            var op       = new EvalOperation(this._database.DatabaseNamespace, function, null);

            using (var writeBinding = new WritableServerBinding(this._client.Cluster, new CoreSessionHandle(NoCoreSession.Instance)))
            {
                return(await op.ExecuteAsync(writeBinding, CancellationToken.None));
            }
        }
コード例 #4
0
        public async Task <BsonValue> ExecuteScriptAsync(string javascript)
        {
            var           function = new BsonJavaScript(javascript);
            EvalOperation op       = new EvalOperation(database.DatabaseNamespace, function, new MessageEncoderSettings {
            });

            using (var writeBinding = new WritableServerBinding(database.Client.Cluster, new CoreSessionHandle(NoCoreSession.Instance)))
            {
                var result = await op.ExecuteAsync(writeBinding, CancellationToken.None);

                return(result);
            }
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public async Task <BsonValue> EvalAsync(string text)
        {
            var client = _database as MongoClient;

            if (client == null)
            {
                throw new ArgumentException("Client is not a MongoClient");
            }

            var function = new BsonJavaScript(text);
            var op       = new EvalOperation(_database.DatabaseNamespace, function, null);

            using (var writeBinding = new WritableServerBinding(client.Cluster, new CoreSessionHandle(NoCoreSession.Instance)))
            {
                return(await op.ExecuteAsync(writeBinding, CancellationToken.None));
            }
        }
コード例 #6
0
        public void ExecuteAsync_should_throw_when_binding_isNull()
        {
            var function = "return 1";
            var subject = new EvalOperation(_databaseNamespace, function, _messageEncoderSettings);

            Action action = () => subject.ExecuteAsync(null, CancellationToken.None).GetAwaiter().GetResult();

            action.ShouldThrow<ArgumentNullException>();
        }
コード例 #7
0
        public async Task ExecuteAsync_should_return_expected_result_when_noLock_is_provided()
        {
            var function = "return 1";
            var subject = new EvalOperation(_databaseNamespace, function, _messageEncoderSettings);
            subject.NoLock = true;

            BsonValue result;
            using (var binding = CoreTestConfiguration.GetReadWriteBinding())
            {
                result = await subject.ExecuteAsync(binding, CancellationToken.None);
            }

            result.Should().Be(1);
        }