Exemple #1
0
 public static CosmosElement ToCosmosElement(VersionedAndRidCheckedCompositeToken token)
 {
     return(CosmosObject.Create(
                new Dictionary <string, CosmosElement>()
     {
         { PropertyNames.Version, CosmosNumber64.Create((long)token.VersionNumber) },
         { PropertyNames.Rid, CosmosString.Create(token.Rid) },
         { PropertyNames.Continuation, token.ContinuationToken },
     }));
 }
Exemple #2
0
        public static TryCatch <VersionedAndRidCheckedCompositeToken> MonadicCreateFromCosmosElement(CosmosElement cosmosElement)
        {
            if (cosmosElement == null)
            {
                throw new ArgumentNullException(nameof(cosmosElement));
            }

            if (!(cosmosElement is CosmosObject cosmosObject))
            {
                return(TryCatch <VersionedAndRidCheckedCompositeToken> .FromException(
                           new FormatException($"Expected object for {nameof(VersionedAndRidCheckedCompositeToken)}: {cosmosElement}.")));
            }

            if (!cosmosObject.TryGetValue(PropertyNames.Version, out CosmosNumber typeValue))
            {
                return(TryCatch <VersionedAndRidCheckedCompositeToken> .FromException(
                           new FormatException($"expected number {nameof(PropertyNames.Version)} property for {nameof(VersionedAndRidCheckedCompositeToken)}: {cosmosElement}.")));
            }

            if (!cosmosObject.TryGetValue(PropertyNames.Continuation, out CosmosElement continuationValue))
            {
                return(TryCatch <VersionedAndRidCheckedCompositeToken> .FromException(
                           new FormatException($"expected number {nameof(PropertyNames.Continuation)} property for {nameof(VersionedAndRidCheckedCompositeToken)}: {cosmosElement}.")));
            }

            if (!cosmosObject.TryGetValue(PropertyNames.Rid, out CosmosString ridValue))
            {
                return(TryCatch <VersionedAndRidCheckedCompositeToken> .FromException(
                           new FormatException($"expected number {nameof(PropertyNames.Version)} property for {nameof(VersionedAndRidCheckedCompositeToken)}: {cosmosElement}.")));
            }

            VersionedAndRidCheckedCompositeToken token = new VersionedAndRidCheckedCompositeToken(
                (Version)Number64.ToLong(typeValue.Value),
                continuationValue,
                ridValue.Value);

            return(TryCatch <VersionedAndRidCheckedCompositeToken> .FromResult(token));
        }