Ejemplo n.º 1
0
        public static DataException ToDataException(this MSDataError error, MSDocumentWrapper msDocumentWrapper = null)
        {
            var exception = new NSErrorException(error);

            return(new DataException(error.LocalizedDescription, exception)
            {
                DocumentMetadata = msDocumentWrapper?.ToDocumentMetadata()
            });
        }
Ejemplo n.º 2
0
 public static DocumentMetadata ToDocumentMetadata(this MSDocumentWrapper documentWrapper)
 {
     return(new DocumentMetadata
     {
         Id = documentWrapper.DocumentId,
         Partition = documentWrapper.Partition,
         ETag = documentWrapper.ETag
     });
 }
Ejemplo n.º 3
0
 public static DocumentWrapper <T> ToDocumentWrapper <T>(this MSDocumentWrapper documentWrapper)
 {
     return(SharedConversionExtensions.ToDocumentWrapper <T>(
                documentWrapper.Partition,
                documentWrapper.ETag,
                documentWrapper.DocumentId,
                documentWrapper.FromDeviceCache,
                documentWrapper.JsonValue,
                p => JsonConvert.DeserializeObject <T>(p),
                documentWrapper.LastUpdatedDate != null ? (DateTime)documentWrapper?.LastUpdatedDate : UnixEpoch));
 }
        public static DocumentWrapper <T> ToDocumentWrapper <T>(this MSDocumentWrapper documentWrapper)
        {
            var jsonValue         = documentWrapper.JsonValue;
            var deserializedValue = jsonValue != null?JsonConvert.DeserializeObject <T>(jsonValue) : default(T);

            return(new DocumentWrapper <T>
            {
                DeserializedValue = deserializedValue,
                JsonValue = jsonValue,
                Partition = documentWrapper.Partition,
                ETag = documentWrapper.ETag,
                Id = documentWrapper.DocumentId,
                LastUpdatedDate = documentWrapper.LastUpdatedDate != null ? (DateTime)documentWrapper?.LastUpdatedDate : UnixEpoch,
                IsFromDeviceCache = documentWrapper.FromDeviceCache
            });
        }
Ejemplo n.º 5
0
 private static void ProcessResult <T>(MSDocumentWrapper resultDoc, TaskCompletionSource <DocumentWrapper <T> > taskCompletionSource)
 {
     if (resultDoc.Error == null)
     {
         try
         {
             taskCompletionSource.SetResult(resultDoc.ToDocumentWrapper <T>());
         }
         catch (JsonException e)
         {
             taskCompletionSource.SetException(new DataException("Failed to process doc: serialization failed", e));
         }
     }
     else
     {
         taskCompletionSource.SetException(resultDoc.Error.ToDataException(resultDoc));
     }
 }