/// <summary> /// Calculates the DataServiceVersion for a particular EntityDescriptor /// </summary> /// <param name="entityDescriptorData">Entity Descriptor Data</param> /// <param name="maxProtocolVersion">The client's max protocol version</param> /// <returns>A Data service protocol version</returns> public DataServiceProtocolVersion CalculateDataServiceVersion(EntityDescriptorData entityDescriptorData, DataServiceProtocolVersion maxProtocolVersion) { ExceptionUtilities.CheckArgumentNotNull(entityDescriptorData, "entityDescriptorData"); Type entityType = entityDescriptorData.Entity.GetType(); EntityType testEntityType = this.entityModelSchema.EntityTypes.Single(et => et.FullName == entityType.FullName); // Calculate expected version based on type's feed mappings. DataServiceProtocolVersion expectedVersion = VersionHelper.CalculateEntityPropertyMappingProtocolVersion(testEntityType, VersionCalculationType.Response, MimeTypes.ApplicationAtomXml, maxProtocolVersion, maxProtocolVersion); // Commenting out this code pending a quick versioning discussion with pratikp and ahmed // Cannot check in as with code it breaks BVT's, want to get this in and update pending discussion 12-7-10 // if (testEntityType.AllProperties.Any(p => p.IsStream())) // { // expectedVersion = VersionHelper.IncreaseVersionIfRequired(expectedVersion, DataServiceProtocolVersion.V4); // } // If there are bag properties then its at least v3 if (testEntityType.HasMultiValue(true) || testEntityType.HasSpatialProperties()) { expectedVersion = VersionHelper.IncreaseVersionIfRequired(expectedVersion, DataServiceProtocolVersion.V4); } return(expectedVersion); }
/// <summary> /// Wraps the specified product. If product is a DataServiceContext then registeres it for tracking. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="product">The product.</param> /// <returns>The wrapper for the product instance.</returns> public TResult Wrap <TResult>(object product) where TResult : IWrappedObject { if (product == null) { return(default(TResult)); } Type[] argTypes = new Type[] { typeof(IWrapperScope), typeof(object) }; Type resultType = typeof(TResult); ConstructorInfo ctor = resultType.GetInstanceConstructor(true, argTypes); ExceptionUtilities.CheckObjectNotNull(ctor, "Cannot find constructor: {0}(IWrapperScope, object)", typeof(TResult).Name); DSClient.DataServiceContext context = product as DSClient.DataServiceContext; if (context != null) { DataServiceProtocolVersion maxProtocolVersion = DataServiceProtocolVersion.Unspecified; #if !WINDOWS_PHONE maxProtocolVersion = context.MaxProtocolVersion.ToTestEnum(); #endif var contextData = DataServiceContextData.CreateDataServiceContextDataFromDataServiceContext(context, maxProtocolVersion); this.contextDatas.Add(context, contextData); } return((TResult)ctor.Invoke(new object[] { this, product })); }
private bool TryCalculateODataResponseError(ODataRequest request, DataServiceProtocolVersion dataServiceVersion, DataServiceProtocolVersion maxDataServiceVersion, DataServiceProtocolVersion maxProtocolVersion, out ExpectedErrorMessage expectedErrorMessage) { expectedErrorMessage = null; string preferHeader = request.GetHeaderValueIfExists(HttpHeaders.Prefer); if (preferHeader != null && maxProtocolVersion > DataServiceProtocolVersion.V4 && dataServiceVersion > DataServiceProtocolVersion.V4 && maxDataServiceVersion != DataServiceProtocolVersion.Unspecified && maxDataServiceVersion < DataServiceProtocolVersion.V4 && request.Verb != HttpVerb.Delete) { expectedErrorMessage = new ExpectedErrorMessage(MaxDataServiceVersionTooLow, maxDataServiceVersion.ConvertToHeaderFormat(), DataServiceProtocolVersion.V4.ConvertToIntegerFormat(), "0"); return(true); } // Now do payload processing DataServiceProtocolVersion expectedResponseVersion = this.MinimumVersionRequiredCalculator.CalculateMinResponseVersion(request, maxProtocolVersion); // Now ensure its not greater than than MDSV if (maxDataServiceVersion != DataServiceProtocolVersion.Unspecified && expectedResponseVersion > maxDataServiceVersion) { expectedErrorMessage = new ExpectedErrorMessage(MaxDataServiceVersionTooLow, maxDataServiceVersion.ConvertToHeaderFormat(), expectedResponseVersion.ConvertToIntegerFormat(), "0"); return(true); } return(false); }
internal static DataServiceProtocolVersion CalculateEntitySetUriSegmentRequestVersion(ODataRequest request, EntitySet entitySet, DataServiceProtocolVersion maxProtocolVersion, DataServiceProtocolVersion maxDataServiceVersion, string contentType) { bool processTypeMetadata = false; DataServiceProtocolVersion entitySetSegmentVersion = DataServiceProtocolVersion.V4; IEnumerable <EntityType> entityTypes = VersionHelper.GetEntityTypes(entitySet); if (request.GetEffectiveVerb().IsUpdateVerb() || request.GetEffectiveVerb() == HttpVerb.Post) { // Typically for all posts there is some type of payload so we should analyze the metadata if (request.GetEffectiveVerb() == HttpVerb.Post) { processTypeMetadata = true; } else if (request.PreferHeaderApplies(maxProtocolVersion)) { processTypeMetadata = true; } // Whenever there is an update operation and EPM is involved we need to check the metadata version if (entityTypes.SelectMany(et => et.Annotations.OfType <PropertyMappingAnnotation>()).Where(fma => fma.KeepInContent == false).Any()) { processTypeMetadata = true; } } if (processTypeMetadata) { entitySetSegmentVersion = entitySetSegmentVersion.IncreaseVersionIfRequired(entitySet.CalculateMinEntityPropertyMappingVersion(VersionCalculationType.Request, contentType, maxProtocolVersion, maxDataServiceVersion)); } return(entitySetSegmentVersion); }
private void IncreaseVersionIfTrue(bool test, DataServiceProtocolVersion newVersion) { if (test) { this.IncreaseVersionIfRequired(newVersion); } }
private static void SetExpectedMaxDataServiceVersion(HttpRequestData request, DSClient.DataServiceContext context) { #if !WINDOWS_PHONE DataServiceProtocolVersion maxDataServiceVersion = context.MaxProtocolVersion.ToTestEnum(); SetExpectedMaxDataServiceVersion(request, maxDataServiceVersion); #endif }
public static string GetHeaderValue(this DataServiceProtocolVersion dataServiceProtocolVersion) { string str; switch (dataServiceProtocolVersion) { case DataServiceProtocolVersion.V1: { str = "1.0"; break; } case DataServiceProtocolVersion.V2: { str = "2.0"; break; } case DataServiceProtocolVersion.V3: { str = "3.0"; break; } default: { throw new ArgumentException(string.Format("DataServiceProtocolVersion [{0}] cannot be converted to a header value.", dataServiceProtocolVersion), "dataServiceProtocolVersion"); } } return(str); }
/// <summary> /// Calculates the DataServiceVersion for a particular EntityDescriptor /// </summary> /// <param name="entityDescriptorData">Entity Descriptor Data</param> /// <param name="maxProtocolVersion">The client's max protocol version</param> /// <returns>A Data service protocol version</returns> public DataServiceProtocolVersion CalculateDataServiceVersion(EntityDescriptorData entityDescriptorData, DataServiceProtocolVersion maxProtocolVersion) { ExceptionUtilities.CheckArgumentNotNull(entityDescriptorData, "entityDescriptorData"); Type entityType = entityDescriptorData.Entity.GetType(); EntityType testEntityType = this.entityModelSchema.EntityTypes.Single(et => et.FullName == entityType.FullName); // Calculate expected version based on type's feed mappings. DataServiceProtocolVersion expectedVersion = VersionHelper.CalculateEntityPropertyMappingProtocolVersion(testEntityType, VersionCalculationType.Response, MimeTypes.ApplicationAtomXml, maxProtocolVersion, maxProtocolVersion); // Commenting out this code pending a quick versioning discussion with pratikp and ahmed // Cannot check in as with code it breaks BVT's, want to get this in and update pending discussion 12-7-10 // if (testEntityType.AllProperties.Any(p => p.IsStream())) // { // expectedVersion = VersionHelper.IncreaseVersionIfRequired(expectedVersion, DataServiceProtocolVersion.V4); // } // If there are bag properties then its at least v3 if (testEntityType.HasMultiValue(true) || testEntityType.HasSpatialProperties()) { expectedVersion = VersionHelper.IncreaseVersionIfRequired(expectedVersion, DataServiceProtocolVersion.V4); } return expectedVersion; }
private ExpectedClientRequest CreateEntityInsertRequest(DataServiceContextData contextData, IDictionary <object, IEnumerable <NamedValue> > propertyValuesBeforeSave, EntityDescriptorData entityDescriptorData, SaveChangesOptions options) { ExceptionUtilities.Assert(!entityDescriptorData.IsMediaLinkEntry, "Can only be used for non media-link-entries"); var insertUri = GetEntityInsertUri(contextData, entityDescriptorData); ExpectedClientRequest request = new ExpectedClientRequest() { Verb = HttpVerb.Post, Uri = insertUri }; string preference = contextData.AddAndUpdateResponsePreference.ToHeaderValue(); DataServiceProtocolVersion dsv = GetDataServiceVersion(HttpVerb.Post, preference); dsv = dsv.IncreaseVersionIfRequired(this.VersionCalculator.CalculateDataServiceVersion(entityDescriptorData, contextData.MaxProtocolVersion)); var payload = this.BuildEntityPayload(contextData, propertyValuesBeforeSave, entityDescriptorData, dsv); request.Body = payload; this.AddFoldedLinksToEntityInsertPayload(contextData, entityDescriptorData, payload); request.Headers[HttpHeaders.DataServiceVersion] = ToClientHeaderFormat(dsv); request.Headers[HttpHeaders.IfMatch] = null; request.Headers[HttpHeaders.Prefer] = preference; this.SetDefaultAcceptHeader(request, options); this.SetContentTypeHeaderForEntity(request); string hintString = @"Entity insert\r\n{{\r\n Descriptor = {0}\r\n Options = {1}\r\n}}"; request.DebugHintString = string.Format(CultureInfo.InvariantCulture, hintString, entityDescriptorData, options); return(request); }
public override DataServiceContext ReaderClient(Uri serviceRoot, DataServiceProtocolVersion protocolVersion) { var ctx = base.ReaderClient(serviceRoot, protocolVersion); new JsonLightConfigurator(ctx, AcceptHeader).Configure(); return(ctx); }
/// <summary> /// Checks if the server will process the prefer header for the given request /// </summary> /// <param name="request">the request</param> /// <param name="maxProtocolVersion">The max protocol version of the server</param> /// <returns>true if the server will process the prefer header for the given request</returns> public static bool ResponsePayloadExpected(this ODataRequest request, DataServiceProtocolVersion maxProtocolVersion) { HttpVerb effectiveVerb = request.GetEffectiveVerb(); if (effectiveVerb == HttpVerb.Delete) { return false; } else if (effectiveVerb == HttpVerb.Post) { // TODO: need to deal with Service operations when then come in if (request.Uri.IsEntityReferenceLink() || (request.PreferHeaderApplies(maxProtocolVersion) && request.GetHeaderValueIfExists(HttpHeaders.Prefer) == HttpHeaders.ReturnNoContent)) { return false; } return true; } else if (effectiveVerb.IsUpdateVerb()) { if (request.PreferHeaderApplies(maxProtocolVersion) && request.GetHeaderValueIfExists(HttpHeaders.Prefer) == HttpHeaders.ReturnContent) { return true; } return false; } return true; }
/// <summary> /// Checks if the server will process the prefer header for the given request /// </summary> /// <param name="request">the request</param> /// <param name="maxProtocolVersion">The max protocol version of the server</param> /// <returns>true if the server will process the prefer header for the given request</returns> public static bool ResponsePayloadExpected(this ODataRequest request, DataServiceProtocolVersion maxProtocolVersion) { HttpVerb effectiveVerb = request.GetEffectiveVerb(); if (effectiveVerb == HttpVerb.Delete) { return(false); } else if (effectiveVerb == HttpVerb.Post) { // TODO: need to deal with Service operations when then come in if (request.Uri.IsEntityReferenceLink() || (request.PreferHeaderApplies(maxProtocolVersion) && request.GetHeaderValueIfExists(HttpHeaders.Prefer) == HttpHeaders.ReturnNoContent)) { return(false); } return(true); } else if (effectiveVerb.IsUpdateVerb()) { if (request.PreferHeaderApplies(maxProtocolVersion) && request.GetHeaderValueIfExists(HttpHeaders.Prefer) == HttpHeaders.ReturnContent) { return(true); } return(false); } return(true); }
private MaterializerEntry(ODataEntry entry, DataServiceProtocolVersion maxProtocolVersion) { this.entry = entry; this.entityDescriptor = new System.Data.Services.Client.EntityDescriptor(maxProtocolVersion); SerializationTypeNameAnnotation annotation = entry.GetAnnotation<SerializationTypeNameAnnotation>(); this.entityDescriptor.ServerTypeName = (annotation != null) ? annotation.TypeName : (this.entityDescriptor.ServerTypeName = this.Entry.TypeName); }
private MaterializerEntry(ODataEntry entry, DataServiceProtocolVersion maxProtocolVersion) { this.entry = entry; this.entityDescriptor = new System.Data.Services.Client.EntityDescriptor(maxProtocolVersion); SerializationTypeNameAnnotation annotation = entry.GetAnnotation <SerializationTypeNameAnnotation>(); this.entityDescriptor.ServerTypeName = (annotation != null) ? annotation.TypeName : (this.entityDescriptor.ServerTypeName = this.Entry.TypeName); }
internal ClientTypeAnnotation(IEdmType edmType, Type type, string qualifiedName, DataServiceProtocolVersion maxProtocolVersion) { this.EdmType = edmType; this.ElementTypeName = qualifiedName; this.ElementType = Nullable.GetUnderlyingType(type) ?? type; this.MaxProtocolVersion = maxProtocolVersion; this.epmLazyLoader = new EpmLazyLoader(this); }
internal static string GetEntitySet(object target, string targetEntitySet, DataServiceProtocolVersion maxProtocolVersion) { if (!string.IsNullOrEmpty(targetEntitySet)) { return(targetEntitySet); } return(GetEntitySetAttribute(target.GetType(), maxProtocolVersion)); }
/// <summary> /// Calculates the version based on the ODataUri provided /// </summary> /// <param name="request">Request to calculate from</param> /// <param name="maxProtocolVersion">Max Protocol version of the server</param> /// <returns>Data Service Protocol Version</returns> public DataServiceProtocolVersion CalculateMinRequestVersion(ODataRequest request, DataServiceProtocolVersion maxProtocolVersion) { ExceptionUtilities.CheckArgumentNotNull(request, "request"); ExceptionUtilities.Assert(maxProtocolVersion != DataServiceProtocolVersion.Unspecified, "Max protocol version cannot be unspecified when calculating the MinVersion"); string contentType = request.GetHeaderValueIfExists(HttpHeaders.ContentType); DataServiceProtocolVersion dataServiceVersion = VersionHelper.ConvertToDataServiceProtocolVersion(request.GetHeaderValueIfExists(HttpHeaders.DataServiceVersion)); DataServiceProtocolVersion maxDataServiceVersion = VersionHelper.ConvertToDataServiceProtocolVersion(request.GetHeaderValueIfExists(HttpHeaders.MaxDataServiceVersion)); HttpVerb effectiveVerb = request.GetEffectiveVerb(); if (contentType == null) { contentType = MimeTypes.Any; } // No real request payload for Delete so its automatically version 1 if (request.GetEffectiveVerb() == HttpVerb.Delete) { return DataServiceProtocolVersion.V4; } if (effectiveVerb.IsUpdateVerb() || effectiveVerb == HttpVerb.Post) { EntitySet entitySet = null; if (request.Uri.TryGetExpectedEntitySet(out entitySet)) { // Determine if the operation and Uri combined yields something that we need to look at the metadata to determine the version or not bool processTypeMetadata = false; // Typically for all posts there is some type of payload so we should analyze the metadata if (effectiveVerb == HttpVerb.Post) { processTypeMetadata = true; } else if (dataServiceVersion != DataServiceProtocolVersion.Unspecified && request.PreferHeaderApplies(maxProtocolVersion)) { processTypeMetadata = true; } IEnumerable<EntityType> entityTypes = VersionHelper.GetEntityTypes(entitySet); // Whenever there is an update operation and EPM is involved we need to check the metadata version if (entityTypes.SelectMany(et => et.Annotations.OfType<PropertyMappingAnnotation>()).Where(fma => fma.KeepInContent == false).Any()) { processTypeMetadata = true; } if (processTypeMetadata) { return VersionHelper.GetMaximumVersion(entityTypes.Select(et => et.CalculateEntityPropertyMappingProtocolVersion(VersionCalculationType.Request, contentType, maxProtocolVersion, maxDataServiceVersion)).ToArray()); } } return DataServiceProtocolVersion.V4; } return VersionHelper.CalculateUriMinRequestProtocolVersion(request.Uri, contentType, maxProtocolVersion, maxDataServiceVersion); }
/// <summary> /// Calculates the version based on the ODataUri provided /// </summary> /// <param name="request">Request to calculate from</param> /// <param name="maxProtocolVersion">Max Protocol version of the server</param> /// <returns>Data Service Protocol Version</returns> public DataServiceProtocolVersion CalculateMinRequestVersion(ODataRequest request, DataServiceProtocolVersion maxProtocolVersion) { ExceptionUtilities.CheckArgumentNotNull(request, "request"); ExceptionUtilities.Assert(maxProtocolVersion != DataServiceProtocolVersion.Unspecified, "Max protocol version cannot be unspecified when calculating the MinVersion"); string contentType = request.GetHeaderValueIfExists(HttpHeaders.ContentType); DataServiceProtocolVersion dataServiceVersion = VersionHelper.ConvertToDataServiceProtocolVersion(request.GetHeaderValueIfExists(HttpHeaders.DataServiceVersion)); DataServiceProtocolVersion maxDataServiceVersion = VersionHelper.ConvertToDataServiceProtocolVersion(request.GetHeaderValueIfExists(HttpHeaders.MaxDataServiceVersion)); HttpVerb effectiveVerb = request.GetEffectiveVerb(); if (contentType == null) { contentType = MimeTypes.Any; } // No real request payload for Delete so its automatically version 1 if (request.GetEffectiveVerb() == HttpVerb.Delete) { return(DataServiceProtocolVersion.V4); } if (effectiveVerb.IsUpdateVerb() || effectiveVerb == HttpVerb.Post) { EntitySet entitySet = null; if (request.Uri.TryGetExpectedEntitySet(out entitySet)) { // Determine if the operation and Uri combined yields something that we need to look at the metadata to determine the version or not bool processTypeMetadata = false; // Typically for all posts there is some type of payload so we should analyze the metadata if (effectiveVerb == HttpVerb.Post) { processTypeMetadata = true; } else if (dataServiceVersion != DataServiceProtocolVersion.Unspecified && request.PreferHeaderApplies(maxProtocolVersion)) { processTypeMetadata = true; } IEnumerable <EntityType> entityTypes = VersionHelper.GetEntityTypes(entitySet); // Whenever there is an update operation and EPM is involved we need to check the metadata version if (entityTypes.SelectMany(et => et.Annotations.OfType <PropertyMappingAnnotation>()).Where(fma => fma.KeepInContent == false).Any()) { processTypeMetadata = true; } if (processTypeMetadata) { return(VersionHelper.GetMaximumVersion(entityTypes.Select(et => et.CalculateEntityPropertyMappingProtocolVersion(VersionCalculationType.Request, contentType, maxProtocolVersion, maxDataServiceVersion)).ToArray())); } } return(DataServiceProtocolVersion.V4); } return(VersionHelper.CalculateUriMinRequestProtocolVersion(request.Uri, contentType, maxProtocolVersion, maxDataServiceVersion)); }
internal static DataServiceProtocolVersion CalculateUriResponseMinProtocolVersion(ODataUri requestUri, string contentType, DataServiceProtocolVersion maxProtocolVersion, DataServiceProtocolVersion maxDataServiceVersion) { DataServiceProtocolVersion expectedVersion = DataServiceProtocolVersion.V4; if (requestUri.IncludesInlineCountAllPages()) { expectedVersion = expectedVersion.IncreaseVersionIfRequired(DataServiceProtocolVersion.V4); } if (requestUri.IsCount()) { expectedVersion = expectedVersion.IncreaseVersionIfRequired(DataServiceProtocolVersion.V4); } else if (requestUri.IsProperty()) { var propertySegment = requestUri.LastSegment as PropertySegment; expectedVersion = expectedVersion.IncreaseVersionIfRequired(propertySegment.Property.CalculateProtocolVersion()); } else if (!requestUri.IsNamedStream()) { // Check service operations returning non-entity types if (requestUri.IsServiceOperation()) { var serviceOpSegment = requestUri.Segments.OfType <FunctionSegment>().Single(); DataType returnType = serviceOpSegment.Function.ReturnType; // Service ops returning complex values or bags of complex values, where the complex type has bag properties, are v3 var collectionType = returnType as CollectionDataType; if (collectionType != null) { // for service operations, the fact that a collection is returned does not mean it is a multivalue // so we unwrap the element type before calculating the version returnType = collectionType.ElementDataType; } expectedVersion = expectedVersion.IncreaseVersionIfRequired(returnType.CalculateDataTypeVersion()); } // Check entity types List <DataServiceProtocolVersion> dataServiceProtocolVersions = new List <DataServiceProtocolVersion>(); dataServiceProtocolVersions.Add(expectedVersion); if (!(requestUri.IsEntityReferenceLink() || requestUri.IsPropertyValue())) { foreach (EntitySet entitySet in requestUri.GetAllEntitySetsIncludingExpands()) { DataServiceProtocolVersion entitySetVersion = entitySet.CalculateEntitySetProtocolVersion(contentType, VersionCalculationType.Response, maxProtocolVersion, maxDataServiceVersion); dataServiceProtocolVersions.Add(entitySetVersion); if (entitySetVersion > maxDataServiceVersion) { return(VersionHelper.GetMaximumVersion(dataServiceProtocolVersions.ToArray())); } } } } return(expectedVersion); }
/// <summary> /// Initializes a new instance of the DataServiceVersionVerifier class /// </summary> /// <param name="model">Entity Model Schema</param> /// <param name="maxProtocolVersion">Max Protocol Version</param> public DataServiceVersionVerifier(EntityModelSchema model, DataServiceProtocolVersion maxProtocolVersion) : base() { ExceptionUtilities.CheckArgumentNotNull(model, "model"); ExceptionUtilities.Assert(maxProtocolVersion != DataServiceProtocolVersion.Unspecified, "Max protocol version cannot be unspecified"); this.maxProtocolVersion = maxProtocolVersion; this.model = model; }
internal static Version GetEffectiveMaxResponseVersion(DataServiceProtocolVersion maxProtocolVersion, Version requestMaxVersion) { Version version = maxProtocolVersion.ToVersion(); if (requestMaxVersion >= version) { return(version); } return(requestMaxVersion); }
internal static bool IsDisallowedExpressionForMethodCall(Expression e, DataServiceProtocolVersion maxProtocolVersion) { MemberExpression expression = e as MemberExpression; if ((expression != null) && ClientTypeUtil.TypeIsEntity(expression.Expression.Type, maxProtocolVersion)) { return(false); } return(IsCollectionProducingExpression(e)); }
internal static bool TryCalculateReaderError(ODataPayloadElement payload, DataServiceProtocolVersion dataServiceVersion, IAstoriaStringResourceVerifiers verifiers, out ExpectedErrorMessage expectedErrorMessage) { if (new PayloadReaderVersionErrorCalculator(verifiers).TryCalculateError(payload, dataServiceVersion, out expectedErrorMessage)) { return(true); } expectedErrorMessage = null; return(false); }
internal static bool TryCalculateDataServiceVersionTooHighError(DataServiceProtocolVersion dataServiceVersion, DataServiceProtocolVersion maxProtocolVersion, out ExpectedErrorMessage expectedErrorMessage) { if (dataServiceVersion > maxProtocolVersion) { expectedErrorMessage = new ExpectedErrorMessage(DataServiceRequestVersionMustBeLessThanMPV, dataServiceVersion.ConvertToHeaderFormat(), maxProtocolVersion.ConvertToHeaderFormat()); return(true); } expectedErrorMessage = null; return(false); }
/// <summary> /// Annotates payload with version as appropriate. /// </summary> /// <param name="payloadElement">The root of the payload to annotate.</param> /// <param name="version">The format version to annotate with.</param> /// <param name="requestPayload">true if the payload should represent a request payload, false if it's a response payload.</param> public static void AnnotateVerboseJson(ODataPayloadElement payloadElement, DataServiceProtocolVersion version, bool requestPayload) { PayloadFormatVersionAnnotatingVisitor visitor = new PayloadFormatVersionAnnotatingVisitor(version, requestPayload); visitor.Recurse(payloadElement); // Add the version/response annotation to the root if it's a response. if (!requestPayload && !(payloadElement is ODataErrorPayload)) { payloadElement.SetAnnotation(new PayloadFormatVersionAnnotation() { Version = version, Response = true, ResponseWrapper = true }); } }
internal static DataServiceProtocolVersion CheckEnumerationValue(DataServiceProtocolVersion value, string parameterName) { switch (value) { case DataServiceProtocolVersion.V1: case DataServiceProtocolVersion.V2: case DataServiceProtocolVersion.V3: return(value); } throw Error.ArgumentOutOfRange(parameterName); }
internal EntityDescriptor(string identity, Uri selfLink, Uri editLink, Uri addToUri, object entity, EntityDescriptor parentEntity, string parentProperty, string etag, EntityStates state, DataServiceProtocolVersion maxProtocolVersion) : base(state) { this.identity = identity; this.selfLink = selfLink; this.editLink = editLink; this.addToUri = addToUri; this.parentDescriptor = parentEntity; this.parentProperty = parentProperty; this.MaxProtocolVersion = maxProtocolVersion; this.Entity = entity; this.etag = etag; }
internal static Version ToVersion(this DataServiceProtocolVersion protocolVersion) { switch (protocolVersion) { case DataServiceProtocolVersion.V1: return(DataServiceVersion1); case DataServiceProtocolVersion.V2: return(DataServiceVersion2); } return(DataServiceVersion3); }
internal static Version ToVersion(this DataServiceProtocolVersion protocolVersion) { switch (protocolVersion) { case DataServiceProtocolVersion.V1: return(RequestDescription.Version1Dot0); case DataServiceProtocolVersion.V2: return(RequestDescription.Version2Dot0); } return(RequestDescription.Version3Dot0); }
/// <summary> /// Calculates the Protocol Version based on the payloadElement provided /// </summary> /// <param name="payloadElement">Payload Element</param> /// <param name="contentType">Content Type</param> /// <param name="maxProtocolVersion">The max protocol version</param> /// <param name="maxDataServiceVersion">The max data service version of the request</param> /// <returns>Data Service protocol version</returns> public DataServiceProtocolVersion CalculateProtocolVersion(ODataPayloadElement payloadElement, string contentType, DataServiceProtocolVersion maxProtocolVersion, DataServiceProtocolVersion maxDataServiceVersion) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); ExceptionUtilities.CheckArgumentNotNull(contentType, "contentType"); ExceptionUtilities.Assert(maxProtocolVersion != DataServiceProtocolVersion.Unspecified, "Max protocol version cannot be unspecified"); this.responseContentType = contentType; this.version = DataServiceProtocolVersion.V4; this.currentMaxProtocolVersion = maxProtocolVersion; this.currentMaxDataServiceVersion = maxDataServiceVersion; payloadElement.Accept(this); return this.version; }
/// <summary> /// Initializes a new instance of the ProtocolQueryVerifier class. /// </summary> /// <param name="defaultAcceptType">The mime type to use in the 'accept' header</param> /// <param name="serviceRoot">The root uri of the service</param> /// <param name="maxProtocolVersion">The max protocol version of the service</param> /// <param name="resourceVerifier">The resource string verifier to use for errors</param> protected ProtocolQueryVerifier(string defaultAcceptType, Uri serviceRoot, DataServiceProtocolVersion maxProtocolVersion, IStringResourceVerifier resourceVerifier) { ExceptionUtilities.CheckArgumentNotNull(defaultAcceptType, "defaultAcceptType"); ExceptionUtilities.CheckArgumentNotNull(serviceRoot, "serviceRoot"); ExceptionUtilities.CheckArgumentNotNull(resourceVerifier, "resourceVerifier"); this.DefaultAcceptType = defaultAcceptType; this.ServiceRoot = serviceRoot; this.Logger = Logger.Null; this.MaxProtocolVersion = maxProtocolVersion; this.DataServiceVersion = DataServiceProtocolVersion.Unspecified; this.MaxDataServiceVersion = DataServiceProtocolVersion.Unspecified; this.ResourceVerifier = resourceVerifier; }
public static MaterializerEntry CreateEntry(ODataEntry entry, DataServiceProtocolVersion maxProtocolVersion) { MaterializerEntry annotation = new MaterializerEntry(entry, maxProtocolVersion); entry.SetAnnotation<MaterializerEntry>(annotation); if (entry.Id == null) { throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Deserialize_MissingIdElement); } annotation.EntityDescriptor.Identity = entry.Id; annotation.EntityDescriptor.EditLink = entry.EditLink; annotation.EntityDescriptor.SelfLink = entry.ReadLink; annotation.EntityDescriptor.ETag = entry.ETag; return annotation; }
/// <summary> /// Calculates the Protocol Version based on the payloadElement provided /// </summary> /// <param name="payloadElement">Payload Element</param> /// <param name="contentType">Content Type</param> /// <param name="maxProtocolVersion">The max protocol version</param> /// <param name="maxDataServiceVersion">The max data service version of the request</param> /// <returns>Data Service protocol version</returns> public DataServiceProtocolVersion CalculateProtocolVersion(ODataPayloadElement payloadElement, string contentType, DataServiceProtocolVersion maxProtocolVersion, DataServiceProtocolVersion maxDataServiceVersion) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); ExceptionUtilities.CheckArgumentNotNull(contentType, "contentType"); ExceptionUtilities.Assert(maxProtocolVersion != DataServiceProtocolVersion.Unspecified, "Max protocol version cannot be unspecified"); this.responseContentType = contentType; this.version = DataServiceProtocolVersion.V4; this.currentMaxProtocolVersion = maxProtocolVersion; this.currentMaxDataServiceVersion = maxDataServiceVersion; payloadElement.Accept(this); return(this.version); }
internal static bool IsDataServiceCollection(Type collectionType, DataServiceProtocolVersion maxProtocolVersion) { metadataCacheLock.EnterReadLock(); try { object obj2; if (knownObservableCollectionTypes.TryGetValue(collectionType, out obj2)) { return(obj2 == TrueObject); } } finally { metadataCacheLock.ExitReadLock(); } Type baseType = collectionType; bool flag = false; while (baseType != null) { if (baseType.IsGenericType()) { Type[] genericArguments = baseType.GetGenericArguments(); if (((genericArguments != null) && (genericArguments.Length == 1)) && IsEntityType(genericArguments[0], maxProtocolVersion)) { Type dataServiceCollectionOfT = WebUtil.GetDataServiceCollectionOfT(genericArguments); if ((dataServiceCollectionOfT != null) && dataServiceCollectionOfT.IsAssignableFrom(baseType)) { flag = true; break; } } } baseType = baseType.BaseType; } metadataCacheLock.EnterWriteLock(); try { if (!knownObservableCollectionTypes.ContainsKey(collectionType)) { knownObservableCollectionTypes[collectionType] = flag ? TrueObject : FalseObject; } } finally { metadataCacheLock.ExitWriteLock(); } return(flag); }
public static MaterializerEntry CreateEntry(ODataEntry entry, DataServiceProtocolVersion maxProtocolVersion) { MaterializerEntry annotation = new MaterializerEntry(entry, maxProtocolVersion); entry.SetAnnotation <MaterializerEntry>(annotation); if (entry.Id == null) { throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Deserialize_MissingIdElement); } annotation.EntityDescriptor.Identity = entry.Id; annotation.EntityDescriptor.EditLink = entry.EditLink; annotation.EntityDescriptor.SelfLink = entry.ReadLink; annotation.EntityDescriptor.ETag = entry.ETag; return(annotation); }
/// <summary> /// Checks if the server will process the prefer header for the given request /// </summary> /// <param name="request">the request</param> /// <param name="maxProtocolVersion">The max protocol version of the server</param> /// <returns>true if the server will process the prefer header for the given request</returns> public static bool PreferHeaderApplies(this ODataRequest request, DataServiceProtocolVersion maxProtocolVersion) { // the header should only apply if: // 1) the effective version of the request is >= 3 // 2) the request verb is one of: POST, PUT, PATCH // 3) the uri refers to a single entity for PUT/PATCH, or an entity set for POST var effectiveVersion = VersionHelper.GetEffectiveProtocolVersion(request.Headers, maxProtocolVersion); if (effectiveVersion < DataServiceProtocolVersion.V4 || maxProtocolVersion < DataServiceProtocolVersion.V4) { return false; } return request.PreferHeaderApplies(); }
/// <summary> /// Calculates the protocol version of the EntitySet /// </summary> /// <param name="entitySet">EntitySet to determine the version of</param> /// <param name="contentType">Content Type of the request being made</param> /// <param name="calculationType">Calculation type to use, response, request, or metadata</param> /// <param name="maxProtocolVersion">max Protocol version of the service</param> /// <param name="maxDataServiceVersion">The max data service version of the request</param> /// <returns>Data Service Protocol version of the EntitySet</returns> public static DataServiceProtocolVersion CalculateEntitySetProtocolVersion(this EntitySet entitySet, string contentType, VersionCalculationType calculationType, DataServiceProtocolVersion maxProtocolVersion, DataServiceProtocolVersion maxDataServiceVersion) { ExceptionUtilities.CheckArgumentNotNull(entitySet, "entitySet"); ExceptionUtilities.CheckArgumentNotNull(contentType, "contentType"); DataServiceProtocolVersion expectedVersion = DataServiceProtocolVersion.V4; List <EntityType> entityTypes = entitySet.Container.Model.EntityTypes.Where(et => et.GetRootType() == entitySet.EntityType).ToList(); foreach (EntityType entityType in entityTypes) { expectedVersion = VersionHelper.IncreaseVersionIfRequired(expectedVersion, entityType.CalculateProtocolVersion(contentType, calculationType, maxProtocolVersion, maxDataServiceVersion)); } return(expectedVersion); }
/// <summary> /// Returns the effective protocol version based on the headers and max protocol version /// </summary> /// <param name="dataServiceProtocolVersion">The DataServiceProtocolVersion to convert to a valid header</param> /// <returns>The effective protocol version</returns> public static string ConvertToIntegerFormat(this DataServiceProtocolVersion dataServiceProtocolVersion) { string tempString = dataServiceProtocolVersion.ToString(); if (dataServiceProtocolVersion == DataServiceProtocolVersion.LatestVersionPlusOne) { tempString = "V4"; } else if (dataServiceProtocolVersion == DataServiceProtocolVersion.Unspecified) { return(null); } return(tempString.ToString().Replace("V", string.Empty)); }
internal static ODataVersion ConvertToODataVersion(DataServiceProtocolVersion maxProtocolVersion) { switch (maxProtocolVersion) { case DataServiceProtocolVersion.V1: return ODataVersion.V1; case DataServiceProtocolVersion.V2: return ODataVersion.V2; case DataServiceProtocolVersion.V3: return ODataVersion.V3; } return ~ODataVersion.V1; }
/// <summary> /// Gets the expected options for the given content type and version /// </summary> /// <param name="contentType">The content type of the payload</param> /// <param name="version">The current version</param> /// <param name="payloadUri">The payload URI</param> /// <returns>The payload options for the given content type and version</returns> public ODataPayloadOptions GetExpectedPayloadOptions(string contentType, DataServiceProtocolVersion version, ODataUri payloadUri) { ExceptionUtilities.CheckArgumentNotNull(contentType, "contentType"); ExceptionUtilities.Assert(version != DataServiceProtocolVersion.Unspecified, "Version cannot be unspecified"); var expected = expectedPayloadOptions; if (contentType.StartsWith(MimeTypes.ApplicationJsonODataLightNonStreaming, System.StringComparison.Ordinal) || contentType.StartsWith(MimeTypes.ApplicationJsonODataLightStreaming, System.StringComparison.Ordinal)) { expected = ODataPayloadOptions.IncludeTypeNames | ODataPayloadOptions.IncludeMediaResourceSourceLinks | ODataPayloadOptions.IncludeMediaResourceEditLinks | ODataPayloadOptions.IncludeNamedMediaResourceSourceLinks | ODataPayloadOptions.IncludeNamedMediaResourceEditLinks | ODataPayloadOptions.IncludeEntityIdentifier | ODataPayloadOptions.ConventionallyProducedNamedStreamSelfLink; var selectedPropertyNames = ODataUtilities.GetSelectedPropertyNamesFromUri(payloadUri, this.UriConverter).ToList(); if (selectedPropertyNames.Any()) { EntitySet payloadEntitySet = null; EntityType payloadEntityType = null; if (payloadUri.TryGetExpectedEntitySetAndType(out payloadEntitySet, out payloadEntityType) && !ODataUtilities.ContainsAllIdentityPropertyNames(selectedPropertyNames, payloadEntityType)) { // JSON Light projections without identity do not contain enough metadata to deduce // id and link values. expected = ODataPayloadOptions.IncludeTypeNames; } } } else if (version < DataServiceProtocolVersion.V4) { // Type names for null values are only supported in V1 and V2. expected = expected | ODataPayloadOptions.IncludeTypeNamesForNullValues; } return expected; }
/// <summary> /// Validates the data in the response payload based on the expected query value /// </summary> /// <param name="requestUri">The request uri</param> /// <param name="response">The response</param> /// <param name="expected">The expected query value</param> /// <param name="maxProtocolVersion">The max protocol version of the service</param> public void ValidateResponsePayload(ODataUri requestUri, ODataResponse response, QueryValue expected, DataServiceProtocolVersion maxProtocolVersion) { ExceptionUtilities.CheckObjectNotNull(requestUri, "requestUri"); ExceptionUtilities.CheckObjectNotNull(response, "response"); ExceptionUtilities.CheckObjectNotNull(expected, "expected"); var expectedVersion = response.GetDataServiceVersion(); this.Validator.ExpectedProtocolVersion = expectedVersion; this.Validator.ExpectedPayloadOptions = ODataPayloadOptions.None; string contentType; if (response.Headers.TryGetValue(HttpHeaders.ContentType, out contentType)) { var strategy = this.FormatSelector.GetStrategy(contentType, requestUri); ExceptionUtilities.CheckObjectNotNull(strategy, "Could not get strategy for content type '{0}'", contentType); this.Validator.PrimitiveValueComparer = strategy.GetPrimitiveComparer(); this.Validator.ExpectedPayloadOptions = this.ProtocolImplementationDetails.GetExpectedPayloadOptions(contentType, expectedVersion, requestUri); } this.ValidateAndPrintInfoOnError(requestUri, response.RootElement, expected); }
internal ClientPropertyAnnotation(IEdmProperty edmProperty, PropertyInfo propertyInfo, DataServiceProtocolVersion maxProtocolVersion) { ParameterExpression expression; ParameterExpression expression2; this.EdmProperty = edmProperty; this.PropertyName = propertyInfo.Name; this.NullablePropertyType = propertyInfo.PropertyType; this.PropertyType = Nullable.GetUnderlyingType(this.NullablePropertyType) ?? this.NullablePropertyType; this.DeclaringClrType = propertyInfo.DeclaringType; MethodInfo getMethod = propertyInfo.GetGetMethod(); MethodInfo setMethod = propertyInfo.GetSetMethod(); this.propertyGetter = (getMethod == null) ? null : ((Func<object, object>) Expression.Lambda(Expression.Convert(Expression.Call(Expression.Convert(expression = Expression.Parameter(typeof(object), "instance"), this.DeclaringClrType), getMethod), typeof(object)), new ParameterExpression[] { expression }).Compile()); this.propertySetter = (setMethod == null) ? null : ((Action<object, object>) Expression.Lambda(Expression.Call(Expression.Convert(expression, this.DeclaringClrType), setMethod, new Expression[] { Expression.Convert(expression2 = Expression.Parameter(typeof(object), "value"), this.NullablePropertyType) }), new ParameterExpression[] { expression, expression2 }).Compile()); this.MaxProtocolVersion = maxProtocolVersion; this.IsKnownType = PrimitiveType.IsKnownType(this.PropertyType); if (!this.IsKnownType) { MethodInfo method = ClientTypeUtil.GetMethodForGenericType(this.PropertyType, typeof(IDictionary<,>), "set_Item", out this.DictionaryValueType); if (method != null) { ParameterExpression expression3; this.dictionarySetter = (Action<object, string, object>) Expression.Lambda(Expression.Call(Expression.Convert(expression, typeof(IDictionary<,>).MakeGenericType(new Type[] { typeof(string), this.DictionaryValueType })), method, expression3 = Expression.Parameter(typeof(string), "propertyName"), Expression.Convert(expression2, this.DictionaryValueType)), new ParameterExpression[] { expression, expression3, expression2 }).Compile(); } else { MethodInfo info4 = ClientTypeUtil.GetMethodForGenericType(this.PropertyType, typeof(ICollection<>), "Contains", out this.collectionGenericType); MethodInfo addToCollectionMethod = ClientTypeUtil.GetAddToCollectionMethod(this.PropertyType, out this.collectionGenericType); MethodInfo info6 = ClientTypeUtil.GetMethodForGenericType(this.PropertyType, typeof(ICollection<>), "Remove", out this.collectionGenericType); MethodInfo info7 = ClientTypeUtil.GetMethodForGenericType(this.PropertyType, typeof(ICollection<>), "Clear", out this.collectionGenericType); this.collectionContains = (info4 == null) ? null : ((Func<object, object, bool>) Expression.Lambda(Expression.Call(Expression.Convert(expression, this.PropertyType), info4, new Expression[] { Expression.Convert(expression2, this.collectionGenericType) }), new ParameterExpression[] { expression, expression2 }).Compile()); this.collectionAdd = (addToCollectionMethod == null) ? null : ((Action<object, object>) Expression.Lambda(Expression.Call(Expression.Convert(expression, this.PropertyType), addToCollectionMethod, new Expression[] { Expression.Convert(expression2, this.collectionGenericType) }), new ParameterExpression[] { expression, expression2 }).Compile()); this.collectionRemove = (info6 == null) ? null : ((Func<object, object, bool>) Expression.Lambda(Expression.Call(Expression.Convert(expression, this.PropertyType), info6, new Expression[] { Expression.Convert(expression2, this.collectionGenericType) }), new ParameterExpression[] { expression, expression2 }).Compile()); this.collectionClear = (info7 == null) ? null : ((Action<object>) Expression.Lambda(Expression.Call(Expression.Convert(expression, this.PropertyType), info7), new ParameterExpression[] { expression }).Compile()); } } }
internal static bool IsDisallowedExpressionForMethodCall(Expression e, DataServiceProtocolVersion maxProtocolVersion) { MemberExpression expression = e as MemberExpression; if ((expression != null) && ClientTypeUtil.TypeIsEntity(expression.Expression.Type, maxProtocolVersion)) { return false; } return IsCollectionProducingExpression(e); }
internal static bool IsDataServiceCollection(Type collectionType, DataServiceProtocolVersion maxProtocolVersion) { metadataCacheLock.EnterReadLock(); try { object obj2; if (knownObservableCollectionTypes.TryGetValue(collectionType, out obj2)) { return (obj2 == TrueObject); } } finally { metadataCacheLock.ExitReadLock(); } Type baseType = collectionType; bool flag = false; while (baseType != null) { if (baseType.IsGenericType()) { Type[] genericArguments = baseType.GetGenericArguments(); if (((genericArguments != null) && (genericArguments.Length == 1)) && IsEntityType(genericArguments[0], maxProtocolVersion)) { Type dataServiceCollectionOfT = WebUtil.GetDataServiceCollectionOfT(genericArguments); if ((dataServiceCollectionOfT != null) && dataServiceCollectionOfT.IsAssignableFrom(baseType)) { flag = true; break; } } } baseType = baseType.BaseType; } metadataCacheLock.EnterWriteLock(); try { if (!knownObservableCollectionTypes.ContainsKey(collectionType)) { knownObservableCollectionTypes[collectionType] = flag ? TrueObject : FalseObject; } } finally { metadataCacheLock.ExitWriteLock(); } return flag; }
internal static IList<BindingPropertyInfo> GetObservableProperties(Type entityType, DataServiceProtocolVersion maxProtocolVersion) { return GetBindingEntityInfoFor(entityType, maxProtocolVersion).ObservableProperties; }
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 bool IsEntityType(Type type, DataServiceProtocolVersion maxProtocolVersion) { bool flag; metadataCacheLock.EnterReadLock(); try { if (knownNonEntityTypes.Contains(type)) { return false; } } finally { metadataCacheLock.ExitReadLock(); } try { if (IsDataServiceCollection(type, maxProtocolVersion)) { return false; } flag = ClientTypeUtil.TypeOrElementTypeIsEntity(type); } catch (InvalidOperationException) { flag = false; } if (!flag) { metadataCacheLock.EnterWriteLock(); try { if (!knownNonEntityTypes.Contains(type)) { knownNonEntityTypes.Add(type); } } finally { metadataCacheLock.ExitWriteLock(); } } return flag; }
/// <summary> /// Calculates the version based on the ODataUri provided /// </summary> /// <param name="request">Request to calculate from</param> /// <param name="maxProtocolVersion">Max Protocol version of the server</param> /// <returns>Data Service Protocol Version</returns> public DataServiceProtocolVersion CalculateMinResponseVersion(ODataRequest request, DataServiceProtocolVersion maxProtocolVersion) { ExceptionUtilities.CheckArgumentNotNull(request, "request"); ExceptionUtilities.Assert(maxProtocolVersion != DataServiceProtocolVersion.Unspecified, "Max protocol version cannot be unspecified when calculating the MinVersion"); string contentType = request.GetHeaderValueIfExists(HttpHeaders.Accept); DataServiceProtocolVersion maxDataServiceVersion = VersionHelper.ConvertToDataServiceProtocolVersion(request.GetHeaderValueIfExists(HttpHeaders.MaxDataServiceVersion)); HttpVerb effectiveVerb = request.GetEffectiveVerb(); if (contentType == null) { contentType = MimeTypes.Any; } if (effectiveVerb == HttpVerb.Post || effectiveVerb.IsUpdateVerb()) { DataServiceProtocolVersion version = DataServiceProtocolVersion.V4; string preferHeaderValue = request.GetHeaderValueIfExists(HttpHeaders.Prefer); // Bump to Version 3 if prefer header is specified and its > V3 server if (preferHeaderValue != null && request.PreferHeaderApplies(maxProtocolVersion)) { version = version.IncreaseVersionIfRequired(DataServiceProtocolVersion.V4); } // for insert or update, versioning is specific to the type EntityType expectedEntityType; if (TryGetExpectedType(request, out expectedEntityType)) { version = VersionHelper.IncreaseVersionIfRequired(version, VersionHelper.CalculateProtocolVersion(expectedEntityType, contentType, VersionCalculationType.Response, maxProtocolVersion, maxDataServiceVersion)); } return version; } return VersionHelper.CalculateUriResponseMinProtocolVersion(request.Uri, contentType, maxProtocolVersion, maxDataServiceVersion); }
private static BindingEntityInfoPerType GetBindingEntityInfoFor(Type entityType, DataServiceProtocolVersion maxProtocolVersion) { BindingEntityInfoPerType type; metadataCacheLock.EnterReadLock(); try { if (bindingEntityInfos.TryGetValue(entityType, out type)) { return type; } } finally { metadataCacheLock.ExitReadLock(); } type = new BindingEntityInfoPerType(); EntitySetAttribute attribute = (EntitySetAttribute) entityType.GetCustomAttributes(typeof(EntitySetAttribute), true).SingleOrDefault<object>(); ClientEdmModel model = ClientEdmModel.GetModel(maxProtocolVersion); type.EntitySet = (attribute != null) ? attribute.EntitySet : null; type.ClientType = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(entityType)); foreach (ClientPropertyAnnotation annotation in type.ClientType.Properties()) { BindingPropertyInfo item = null; Type propertyType = annotation.PropertyType; if (!annotation.IsStreamLinkProperty) { if (annotation.IsPrimitiveOrComplexCollection) { item = new BindingPropertyInfo { PropertyKind = BindingPropertyKind.BindingPropertyKindPrimitiveOrComplexCollection }; } else if (annotation.IsEntityCollection) { if (IsDataServiceCollection(propertyType, maxProtocolVersion)) { item = new BindingPropertyInfo { PropertyKind = BindingPropertyKind.BindingPropertyKindDataServiceCollection }; } } else if (IsEntityType(propertyType, maxProtocolVersion)) { item = new BindingPropertyInfo { PropertyKind = BindingPropertyKind.BindingPropertyKindEntity }; } else if (CanBeComplexType(propertyType)) { item = new BindingPropertyInfo { PropertyKind = BindingPropertyKind.BindingPropertyKindComplex }; } if (item != null) { item.PropertyInfo = annotation; if ((type.ClientType.IsEntityType || (item.PropertyKind == BindingPropertyKind.BindingPropertyKindComplex)) || (item.PropertyKind == BindingPropertyKind.BindingPropertyKindPrimitiveOrComplexCollection)) { type.ObservableProperties.Add(item); } } } } metadataCacheLock.EnterWriteLock(); try { if (!bindingEntityInfos.ContainsKey(entityType)) { bindingEntityInfos[entityType] = type; } } finally { metadataCacheLock.ExitWriteLock(); } return type; }
public EntityTracker(DataServiceProtocolVersion maxProtocolVersion) { this.maxProtocolVersion = maxProtocolVersion; }
/// <summary> /// Initializes a new instance of the ActionResponseVerifier class /// </summary> /// <param name="entityModelSchema">Entity Model Schema</param> /// <param name="maxProtocolVersion">Max Protocol Version</param> internal ActionResponseVerifier(EntityModelSchema entityModelSchema, DataServiceProtocolVersion maxProtocolVersion) { this.entityModelSchema = entityModelSchema; this.maxProtocolVersion = maxProtocolVersion; }
public override DataServiceContext ReaderClient(Uri serviceRoot, DataServiceProtocolVersion protocolVersion) { var ctx = base.ReaderClient(serviceRoot, protocolVersion); new JsonLightConfigurator(ctx, AcceptHeader).Configure(); return ctx; }
private static bool ShouldTrackWithContext(object entity, DataServiceProtocolVersion maxProtocolVersion) { return ((entity == null) || ClientTypeUtil.TypeIsEntity(entity.GetType(), maxProtocolVersion)); }
private static string ToClientHeaderFormat(DataServiceProtocolVersion version) { return version.ConvertToHeaderFormat() + ";" + HttpHeaders.NetFx; }
private EntityInstance BuildEntityPayload( DataServiceContextData contextData, IDictionary<object, IEnumerable<NamedValue>> propertyValuesBeforeSave, EntityDescriptorData entityDescriptorData, DataServiceProtocolVersion dsv) { IEnumerable<NamedValue> propertyValues; ExceptionUtilities.Assert(propertyValuesBeforeSave.TryGetValue(entityDescriptorData.Entity, out propertyValues), "Could not find property values for descriptor: {0}", entityDescriptorData); var entityType = this.ModelSchema.EntityTypes.Single(t => t.FullName == entityDescriptorData.EntityClrType.FullName); var entityInstance = this.PayloadBuilder.EntityInstance(entityType, propertyValues); new ExpectedPayloadNormalizer(contextData, dsv).Normalize(entityInstance, entityDescriptorData); return entityInstance; }
/// <summary> /// Initializes a new instance of the ExpectedPayloadNormalizer class /// </summary> /// <param name="contextData">The context data</param> /// <param name="dsv">The data service version</param> public ExpectedPayloadNormalizer(DataServiceContextData contextData, DataServiceProtocolVersion dsv) { ExceptionUtilities.CheckArgumentNotNull(contextData, "contextData"); this.contextData = contextData; this.dsv = dsv; }