private void CheckMediaLinkEntry() { Func<ClientPropertyAnnotation, bool> predicate = null; this.isMediaLinkEntry = false; MediaEntryAttribute mediaEntryAttribute = (MediaEntryAttribute) this.ElementType.GetCustomAttributes(typeof(MediaEntryAttribute), true).SingleOrDefault<object>(); if (mediaEntryAttribute != null) { this.isMediaLinkEntry = true; if (predicate == null) { predicate = p => p.PropertyName == mediaEntryAttribute.MediaMemberName; } ClientPropertyAnnotation annotation = this.Properties().SingleOrDefault<ClientPropertyAnnotation>(predicate); if (annotation == null) { throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.ClientType_MissingMediaEntryProperty(this.ElementTypeName, mediaEntryAttribute.MediaMemberName)); } this.mediaDataMember = annotation; } if (this.ElementType.GetCustomAttributes(typeof(HasStreamAttribute), true).Any<object>()) { this.isMediaLinkEntry = true; } if (this.isMediaLinkEntry.HasValue && this.isMediaLinkEntry.Value) { this.SetMediaLinkEntryAnnotation(); } }
/// <summary> /// Computes the metadata version of the property. /// </summary> /// <param name="propertyCollection">List of properties for which metadata version needs to be computed.</param> /// <param name="visitedComplexTypes">List of complex type already visited.</param> /// <returns>the metadata version of the property collection.</returns> private Version ComputeVersionForPropertyCollection(IEnumerable <IEdmProperty> propertyCollection, HashSet <IEdmType> visitedComplexTypes) { Version propertyMetadataVersion = Util.DataServiceVersion1; foreach (IEdmProperty property in propertyCollection) { ClientPropertyAnnotation propertyAnnotation = this.model.GetClientPropertyAnnotation(property); // Raise the property version to 3.0 if the property is of type // collection, Geography or Geometry type. if (propertyAnnotation.IsPrimitiveOrComplexCollection || propertyAnnotation.IsSpatialType) { WebUtil.RaiseVersion(ref propertyMetadataVersion, Util.DataServiceVersion3); } else if (property.Type.TypeKind() == EdmTypeKind.Complex && !propertyAnnotation.IsDictionary) { if (visitedComplexTypes == null) { visitedComplexTypes = new HashSet <IEdmType>(EqualityComparer <IEdmType> .Default); } else if (visitedComplexTypes.Contains(property.Type.Definition)) { continue; } visitedComplexTypes.Add(property.Type.Definition); WebUtil.RaiseVersion(ref propertyMetadataVersion, this.ComputeVersionForPropertyCollection(this.model.GetClientTypeAnnotation(property).EdmProperties(), visitedComplexTypes)); } } return(propertyMetadataVersion); }
private Version ComputeVersionForPropertyCollection(IEnumerable <IEdmProperty> propertyCollection, HashSet <IEdmType> visitedComplexTypes, ClientEdmModel model) { Version version = Util.DataServiceVersion1; foreach (IEdmProperty property in propertyCollection) { ClientPropertyAnnotation clientPropertyAnnotation = model.GetClientPropertyAnnotation(property); if (clientPropertyAnnotation.IsPrimitiveOrComplexCollection || clientPropertyAnnotation.IsSpatialType) { WebUtil.RaiseVersion(ref version, Util.DataServiceVersion3); } else { if ((property.Type.TypeKind() == EdmTypeKind.Complex) && !clientPropertyAnnotation.IsDictionary) { if (visitedComplexTypes == null) { visitedComplexTypes = new HashSet <IEdmType>(EqualityComparer <IEdmType> .Default); } else if (visitedComplexTypes.Contains(property.Type.Definition)) { goto Label_00A6; } visitedComplexTypes.Add(property.Type.Definition); WebUtil.RaiseVersion(ref version, this.ComputeVersionForPropertyCollection(model.GetClientTypeAnnotation(property).EdmProperties(), visitedComplexTypes, model)); } Label_00A6 :; } } return(version); }
/// <summary> /// Check if this type represents an ATOM-style media link entry and /// if so mark the ClientType as such /// </summary> private void CheckMediaLinkEntry() { this.isMediaLinkEntry = false; // MediaEntryAttribute does not allow multiples, so there can be at most 1 instance on the type. MediaEntryAttribute mediaEntryAttribute = (MediaEntryAttribute)this.ElementType.GetCustomAttributes(typeof(MediaEntryAttribute), true).SingleOrDefault(); if (mediaEntryAttribute != null) { this.isMediaLinkEntry = true; ClientPropertyAnnotation mediaProperty = this.Properties().SingleOrDefault(p => p.PropertyName == mediaEntryAttribute.MediaMemberName); if (mediaProperty == null) { throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.ClientType_MissingMediaEntryProperty( this.ElementTypeName, mediaEntryAttribute.MediaMemberName)); } this.mediaDataMember = mediaProperty; } // HasStreamAttribute does not allow multiples, so there can be at most 1 instance on the type. bool hasStreamAttribute = this.ElementType.GetCustomAttributes(typeof(HasStreamAttribute), true).Any(); if (hasStreamAttribute) { this.isMediaLinkEntry = true; } if (this.isMediaLinkEntry.HasValue && this.isMediaLinkEntry.Value) { this.SetMediaLinkEntryAnnotation(); } }
private void CheckMediaLinkEntry() { Func <ClientPropertyAnnotation, bool> predicate = null; this.isMediaLinkEntry = false; MediaEntryAttribute mediaEntryAttribute = (MediaEntryAttribute)this.ElementType.GetCustomAttributes(typeof(MediaEntryAttribute), true).SingleOrDefault <object>(); if (mediaEntryAttribute != null) { this.isMediaLinkEntry = true; if (predicate == null) { predicate = p => p.PropertyName == mediaEntryAttribute.MediaMemberName; } ClientPropertyAnnotation annotation = this.Properties().SingleOrDefault <ClientPropertyAnnotation>(predicate); if (annotation == null) { throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.ClientType_MissingMediaEntryProperty(this.ElementTypeName, mediaEntryAttribute.MediaMemberName)); } this.mediaDataMember = annotation; } if (this.ElementType.GetCustomAttributes(typeof(HasStreamAttribute), true).Any <object>()) { this.isMediaLinkEntry = true; } if (this.isMediaLinkEntry.HasValue && this.isMediaLinkEntry.Value) { this.SetMediaLinkEntryAnnotation(); } }
/// <summary> /// Determines whether a given property should be serialized into an insert or update payload. /// </summary> /// <param name="type">The declaring type of the property.</param> /// <param name="property">The property.</param> /// <returns>Whether or not the property should be serialized.</returns> private static bool ShouldSerializeProperty(ClientTypeAnnotation type, ClientPropertyAnnotation property) { // don't write property if it is a dictionary // don't write mime data member or the mime type member for it // link properties need to be ignored return(!property.IsDictionary && property != type.MediaDataMember && !property.IsStreamLinkProperty && (type.MediaDataMember == null || type.MediaDataMember.MimeTypeProperty != property) && !property.IsEntityCollection); }
private object GetCollectionInstance(ClientPropertyAnnotation property, out bool instanceCreated) { instanceCreated = false; object obj2 = property.GetValue(this.entity); if (obj2 != null) { return obj2; } instanceCreated = true; Type propertyType = property.PropertyType; if (BindingEntityInfo.IsDataServiceCollection(propertyType, base.RequestInfo.MaxProtocolVersion)) { object[] args = new object[2]; args[1] = TrackingMode.None; return Activator.CreateInstance(WebUtil.GetDataServiceCollectionOfT(new Type[] { property.EntityCollectionItemType }), args); } Type c = typeof(List<>).MakeGenericType(new Type[] { property.EntityCollectionItemType }); if (!propertyType.IsAssignableFrom(c)) { c = propertyType; } return Activator.CreateInstance(c); }
internal static bool TryGetPropertyValue(object source, string sourceProperty, DataServiceProtocolVersion maxProtocolVersion, out BindingPropertyInfo bindingPropertyInfo, out ClientPropertyAnnotation clientProperty, out object propertyValue) { Type entityType = source.GetType(); bindingPropertyInfo = GetObservableProperties(entityType, maxProtocolVersion).SingleOrDefault<BindingPropertyInfo>(x => x.PropertyInfo.PropertyName == sourceProperty); bool flag = bindingPropertyInfo != null; if (!flag) { clientProperty = GetClientType(entityType, maxProtocolVersion).GetProperty(sourceProperty, true); flag = clientProperty != null; if (!flag) { propertyValue = null; return flag; } propertyValue = clientProperty.GetValue(source); return flag; } clientProperty = null; propertyValue = bindingPropertyInfo.PropertyInfo.GetValue(source); return flag; }
internal static void SetClientPropertyAnnotation(this IEdmProperty edmProperty, ClientPropertyAnnotation annotation) { ClientEdmModel.GetModel(annotation.MaxProtocolVersion).SetAnnotationValue <ClientPropertyAnnotation>(edmProperty, annotation); }
private ODataComplexValue CreateODataComplexPropertyValue(ClientPropertyAnnotation property, object propertyValue, List<object> visitedComplexTypeObjects) { Type complexType = property.IsPrimitiveOrComplexCollection ? property.PrimitiveOrComplexCollectionItemType : property.PropertyType; return this.CreateODataComplexValue(complexType, propertyValue, property.PropertyName, property.IsPrimitiveOrComplexCollection, visitedComplexTypeObjects); }
private ODataCollectionValue CreateODataCollectionPropertyValue(ClientPropertyAnnotation property, object propertyValue, List<object> visitedComplexTypeObjects) { return this.CreateODataCollection(property.PrimitiveOrComplexCollectionItemType, property.PropertyName, propertyValue, visitedComplexTypeObjects); }
/// <summary> /// Sets the given instance of <paramref name="annotation"/> to the given instance of <paramref name="edmProperty"/>. /// </summary> /// <param name="edmProperty">IEdmProperty instance to set the annotation.</param> /// <param name="annotation">Annotation instance to set.</param> internal static void SetClientPropertyAnnotation(this IEdmProperty edmProperty, ClientPropertyAnnotation annotation) { Debug.Assert(edmProperty != null, "edmProperty != null"); Debug.Assert(annotation != null, "annotation != null"); annotation.Model.SetAnnotationValue <ClientPropertyAnnotation>(edmProperty, annotation); }
internal static void SetClientPropertyAnnotation(this IEdmProperty edmProperty, ClientPropertyAnnotation annotation) { ClientEdmModel.GetModel(annotation.MaxProtocolVersion).SetAnnotationValue<ClientPropertyAnnotation>(edmProperty, annotation); }
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; }
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; }
internal Uri GetNavigationLink(UriResolver baseUriResolver, ClientPropertyAnnotation property) { LinkInfo linkInfo = null; Uri navigationLink = null; if (this.TryGetLinkInfo(property.PropertyName, out linkInfo)) { navigationLink = linkInfo.NavigationLink; } if (navigationLink == null) { Uri requestUri = Util.CreateUri(property.PropertyName + (property.IsEntityCollection ? "()" : string.Empty), UriKind.Relative); navigationLink = Util.CreateUri(this.GetResourceUri(baseUriResolver, true), requestUri); } return navigationLink; }