public static CosmosElement ToCosmosElement(OrderByContinuationToken orderByContinuationToken) { CosmosElement compositeContinuationToken = ParallelContinuationToken.ToCosmosElement(orderByContinuationToken.ParallelContinuationToken); List <CosmosElement> orderByItemsRaw = new List <CosmosElement>(); foreach (OrderByItem orderByItem in orderByContinuationToken.OrderByItems) { orderByItemsRaw.Add(OrderByItem.ToCosmosElement(orderByItem)); } CosmosArray orderByItems = CosmosArray.Create(orderByItemsRaw); CosmosElement filter = orderByContinuationToken.Filter == null?CosmosNull.Create() : (CosmosElement)CosmosString.Create(orderByContinuationToken.Filter); CosmosObject cosmosObject = CosmosObject.Create( new Dictionary <string, CosmosElement>() { { PropertyNames.CompositeToken, compositeContinuationToken }, { PropertyNames.OrderByItems, orderByItems }, { PropertyNames.Rid, CosmosString.Create(orderByContinuationToken.Rid) }, { PropertyNames.SkipCount, CosmosNumber64.Create(orderByContinuationToken.SkipCount) }, { PropertyNames.Filter, filter }, }); return(cosmosObject); }
public static TryCatch <OrderByContinuationToken> TryCreateFromCosmosElement(CosmosElement cosmosElement) { if (!(cosmosElement is CosmosObject cosmosObject)) { return(TryCatch <OrderByContinuationToken> .FromException( new MalformedContinuationTokenException($"{nameof(OrderByContinuationToken)} is not an object: {cosmosElement}"))); } if (!cosmosObject.TryGetValue(PropertyNames.CompositeToken, out CosmosElement compositeContinuationTokenElement)) { return(TryCatch <OrderByContinuationToken> .FromException( new MalformedContinuationTokenException($"{nameof(OrderByContinuationToken)} is missing field: '{PropertyNames.CompositeToken}': {cosmosElement}"))); } TryCatch <ParallelContinuationToken> tryCompositeContinuation = ParallelContinuationToken.TryCreateFromCosmosElement(compositeContinuationTokenElement); if (!tryCompositeContinuation.Succeeded) { return(TryCatch <OrderByContinuationToken> .FromException(tryCompositeContinuation.Exception)); } ParallelContinuationToken compositeContinuationToken = tryCompositeContinuation.Result; if (!cosmosObject.TryGetValue(PropertyNames.OrderByItems, out CosmosArray orderByItemsRaw)) { return(TryCatch <OrderByContinuationToken> .FromException( new MalformedContinuationTokenException($"{nameof(OrderByContinuationToken)} is missing field: '{PropertyNames.OrderByItems}': {cosmosElement}"))); } List <OrderByItem> orderByItems = orderByItemsRaw.Select(x => OrderByItem.FromCosmosElement(x)).ToList(); if (!cosmosObject.TryGetValue(PropertyNames.Rid, out CosmosString ridRaw)) { return(TryCatch <OrderByContinuationToken> .FromException( new MalformedContinuationTokenException($"{nameof(OrderByContinuationToken)} is missing field: '{PropertyNames.Rid}': {cosmosElement}"))); } string rid = ridRaw.Value; if (!cosmosObject.TryGetValue(PropertyNames.SkipCount, out CosmosNumber64 skipCountRaw)) { return(TryCatch <OrderByContinuationToken> .FromException( new MalformedContinuationTokenException($"{nameof(OrderByContinuationToken)} is missing field: '{PropertyNames.SkipCount}': {cosmosElement}"))); } int skipCount = (int)Number64.ToLong(skipCountRaw.GetValue()); if (!cosmosObject.TryGetValue(PropertyNames.Filter, out CosmosElement filterRaw)) { return(TryCatch <OrderByContinuationToken> .FromException( new MalformedContinuationTokenException($"{nameof(OrderByContinuationToken)} is missing field: '{PropertyNames.Filter}': {cosmosElement}"))); } string filter; if (filterRaw is CosmosString filterStringRaw) { filter = filterStringRaw.Value; } else { filter = null; } OrderByContinuationToken orderByContinuationToken = new OrderByContinuationToken( compositeContinuationToken, orderByItems, rid, skipCount, filter); return(TryCatch <OrderByContinuationToken> .FromResult(orderByContinuationToken)); }
public static CosmosElement ToCosmosElement(OrderByItem orderByItem) { return(orderByItem.cosmosObject); }