Exemple #1
0
 private MaterializeAtom ReadPropertyFromRawData(ClientPropertyAnnotation property)
 {
     MaterializeAtom atom;
     DataServiceContext source = (DataServiceContext) base.Source;
     bool applyingChanges = source.ApplyingChanges;
     try
     {
         source.ApplyingChanges = true;
         string mime = null;
         Encoding encoding = null;
         Type type = property.EntityCollectionItemType ?? property.NullablePropertyType;
         IList results = (IList) Activator.CreateInstance(typeof(List<>).MakeGenericType(new Type[] { type }));
         HttpProcessUtility.ReadContentType(base.ContentType, out mime, out encoding);
         using (Stream stream = base.GetResponseStream())
         {
             if (property.PropertyType == typeof(byte[]))
             {
                 int contentLength = (int) base.ContentLength;
                 byte[] buffer = null;
                 if (contentLength >= 0)
                 {
                     buffer = ReadByteArrayWithContentLength(stream, contentLength);
                 }
                 else
                 {
                     buffer = ReadByteArrayChunked(stream);
                 }
                 results.Add(buffer);
                 property.SetValue(this.entity, buffer, this.propertyName, false);
             }
             else
             {
                 StreamReader reader = new StreamReader(stream, encoding);
                 object obj2 = (property.PropertyType == typeof(string)) ? reader.ReadToEnd() : ClientConvert.ChangeType(reader.ReadToEnd(), property.PropertyType);
                 results.Add(obj2);
                 property.SetValue(this.entity, obj2, this.propertyName, false);
             }
         }
         if (property.MimeTypeProperty != null)
         {
             property.MimeTypeProperty.SetValue(this.entity, mime, null, false);
         }
         atom = MaterializeAtom.CreateWrapper(source, results);
     }
     finally
     {
         source.ApplyingChanges = applyingChanges;
     }
     return atom;
 }
Exemple #2
0
 private MaterializeAtom ReadPropertyFromAtom(EntityDescriptor box, ClientPropertyAnnotation property)
 {
     MaterializeAtom atom2;
     DataServiceContext source = (DataServiceContext) base.Source;
     bool applyingChanges = source.ApplyingChanges;
     try
     {
         source.ApplyingChanges = true;
         bool flag2 = EntityStates.Deleted == box.State;
         bool instanceCreated = false;
         object instance = null;
         if (property.IsEntityCollection)
         {
             instance = this.GetCollectionInstance(property, out instanceCreated);
         }
         Type type = property.IsEntityCollection ? property.EntityCollectionItemType : property.NullablePropertyType;
         IList results = (IList) Activator.CreateInstance(typeof(List<>).MakeGenericType(new Type[] { type }));
         DataServiceQueryContinuation continuation = null;
         using (MaterializeAtom atom = base.GetMaterializer(this.plan))
         {
             bool flag4 = property.EdmProperty.PropertyKind == EdmPropertyKind.Navigation;
             int num = 0;
             foreach (object obj3 in atom)
             {
                 if (property.IsEntityCollection)
                 {
                     property.SetValue(instance, obj3, this.propertyName, true);
                     results.Add(obj3);
                 }
                 else if (property.IsPrimitiveOrComplexCollection)
                 {
                     object obj4 = property.GetValue(this.entity);
                     if (obj4 == null)
                     {
                         obj4 = Activator.CreateInstance(obj3.GetType());
                         property.SetValue(this.entity, obj4, this.propertyName, false);
                     }
                     else
                     {
                         property.ClearBackingICollectionInstance(obj4);
                     }
                     foreach (object obj5 in (IEnumerable) obj3)
                     {
                         property.AddValueToBackingICollectionInstance(obj4, obj5);
                     }
                     results.Add(obj4);
                 }
                 else
                 {
                     property.SetValue(this.entity, obj3, this.propertyName, false);
                     results.Add(obj3);
                 }
                 num++;
                 if (((obj3 != null) && (MergeOption.NoTracking != atom.MergeOptionValue)) && flag4)
                 {
                     if (flag2)
                     {
                         source.DeleteLink(this.entity, this.propertyName, obj3);
                     }
                     else
                     {
                         source.AttachLink(this.entity, this.propertyName, obj3, atom.MergeOptionValue);
                     }
                 }
             }
             continuation = atom.GetContinuation(null);
             Util.SetNextLinkForCollection(property.IsEntityCollection ? instance : this.entity, continuation);
         }
         if (instanceCreated)
         {
             property.SetValue(this.entity, instance, this.propertyName, false);
         }
         atom2 = MaterializeAtom.CreateWrapper(source, results, continuation);
     }
     finally
     {
         source.ApplyingChanges = applyingChanges;
     }
     return atom2;
 }