Пример #1
0
        public static DocumentCountersOperation Parse(BlittableJsonReaderObject input)
        {
            if (input.TryGet("DocumentId", out string docId) == false || docId == null)
            {
                ThrowMissingDocumentId();
            }

            if (input.TryGet("Operations", out BlittableJsonReaderArray operations) == false || operations == null)
            {
                ThrowMissingCounterOperations();
            }

            var result = new DocumentCountersOperation
            {
                DocumentId = docId,
                Operations = new List <CounterOperation>()
            };

            foreach (var op in operations)
            {
                if (!(op is BlittableJsonReaderObject bjro))
                {
                    ThrowNotBlittableJsonReaderObjectOperation(op);
                    return(null); //never hit
                }

                result.Operations.Add(CounterOperation.Parse(bjro));
            }

            return(result);
        }
Пример #2
0
        public static CounterOperation Parse(BlittableJsonReaderObject input)
        {
            if (input.TryGet(nameof(CounterName), out string name) == false || name == null)
            {
                ThrowMissingCounterName();
            }

            if (input.TryGet(nameof(Type), out string type) == false || type == null)
            {
                ThrowMissingCounterOperationType(name);
            }

            var counterOperationType = (CounterOperationType)Enum.Parse(typeof(CounterOperationType), type);

            long?delta = null;

            switch (counterOperationType)
            {
            case CounterOperationType.Increment:
            case CounterOperationType.Put:
                if (input.TryGet(nameof(Delta), out delta) == false)
                {
                    ThrowMissingDeltaProperty(name, counterOperationType);
                }
                break;
            }

            var counterOperation = new CounterOperation
            {
                Type        = counterOperationType,
                CounterName = name
            };

            if (delta != null)
            {
                counterOperation.Delta = delta.Value;
            }

            return(counterOperation);
        }