Example #1
0
 private void EndPreviousCommandIfNeeded()
 {
     if (_inProgressCommand == CommandType.Counters)
     {
         _countersOperation.EndPreviousCommandIfNeeded();
     }
     else if (_inProgressCommand == CommandType.TimeSeries)
     {
         TimeSeriesBulkInsert.ThrowAlreadyRunningTimeSeries();
     }
 }
Example #2
0
            public async Task IncrementAsync(string id, string name, long delta)
            {
                using (_operation.ConcurrencyCheck())
                {
                    await _operation.ExecuteBeforeStore().ConfigureAwait(false);

                    if (_operation._inProgressCommand == CommandType.TimeSeries)
                    {
                        TimeSeriesBulkInsert.ThrowAlreadyRunningTimeSeries();
                    }

                    try
                    {
                        var isFirst = _id == null;
                        if (isFirst || _id.Equals(id, StringComparison.OrdinalIgnoreCase) == false)
                        {
                            if (isFirst == false)
                            {
                                //we need to end the command for the previous document id
                                _operation._currentWriter.Write("]}},");
                            }
                            else if (_operation._first == false)
                            {
                                _operation.WriteComma();
                            }

                            _operation._first = false;

                            _id = id;
                            _operation._inProgressCommand = CommandType.Counters;

                            WritePrefixForNewCommand();
                        }

                        if (_countersInBatch >= _maxCountersInBatch)
                        {
                            _operation._currentWriter.Write("]}},");

                            WritePrefixForNewCommand();
                        }

                        _countersInBatch++;

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

                        _first = false;

                        _operation._currentWriter.Write("{\"Type\":\"Increment\",\"CounterName\":\"");
                        _operation.WriteString(name);
                        _operation._currentWriter.Write("\",\"Delta\":");
                        _operation._currentWriter.Write(delta);
                        _operation._currentWriter.Write('}');

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