示例#1
0
            public TimeSeriesBulkInsert(BulkInsertOperation operation, string id, string name)
            {
                operation.EndPreviousCommandIfNeeded();

                _operation = operation;
                _id        = id;
                _name      = name;

                _operation._inProgressCommand = CommandType.TimeSeries;
            }
示例#2
0
            public async Task StoreAsync(string id, string name, Stream stream, string contentType = null, CancellationToken token = default)
            {
                PutAttachmentCommandHelper.ValidateStream(stream);

                using var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(token, _token);
                using (_operation.ConcurrencyCheck())
                {
                    _operation.EndPreviousCommandIfNeeded();

                    await _operation.ExecuteBeforeStore().ConfigureAwait(false);

                    try
                    {
                        if (_operation._first == false)
                        {
                            _operation.WriteComma();
                        }

                        _operation._currentWriter.Write("{\"Id\":\"");
                        _operation.WriteString(id);
                        _operation._currentWriter.Write("\",\"Type\":\"AttachmentPUT\",\"Name\":\"");
                        _operation.WriteString(name);

                        if (contentType != null)
                        {
                            _operation._currentWriter.Write("\",\"ContentType\":\"");
                            _operation.WriteString(contentType);
                        }

                        _operation._currentWriter.Write("\",\"ContentLength\":");
                        _operation._currentWriter.Write(stream.Length);
                        _operation._currentWriter.Write('}');
                        await _operation.FlushIfNeeded().ConfigureAwait(false);

                        PutAttachmentCommandHelper.PrepareStream(stream);
                        // pass the default value for bufferSize to make it compile on netstandard2.0
                        await stream.CopyToAsync(_operation._currentWriter.BaseStream, bufferSize : 16 * 1024, cancellationToken : linkedCts.Token).ConfigureAwait(false);

                        await _operation.FlushIfNeeded().ConfigureAwait(false);
                    }
                    catch (Exception e)
                    {
                        await _operation.HandleErrors(id, e).ConfigureAwait(false);
                    }
                }
            }