public object GetPropertyValue(object target, ResourceProperty resourceProperty) { object obj2; WebUtil.CheckArgumentNull <object>(target, "target"); WebUtil.CheckArgumentNull <ResourceProperty>(resourceProperty, "resourceProperty"); try { obj2 = this.GetResourceType(target).GetPropertyInfo(resourceProperty).GetGetMethod().Invoke(target, null); } catch (TargetInvocationException exception) { ErrorHandler.HandleTargetInvocationException(exception); throw; } return(obj2); }
internal ResourceType GetPrimitive(Type type) { WebUtil.CheckArgumentNull <Type>(type, "type"); ResourceType type2 = this.primitiveResourceTypes.FirstOrDefault <ResourceType>(rt => rt.InstanceType == type); if (type2 == null) { foreach (ResourceType type3 in this.inheritablePrimitiveResourceTypes) { if (type3.InstanceType.IsAssignableFrom(type) && ((type2 == null) || type2.InstanceType.IsAssignableFrom(type3.InstanceType))) { type2 = type3; } } } return(type2); }
/// <summary> /// Get the value of the strongly typed property. /// </summary> /// <param name="target">instance of the type declaring the property.</param> /// <param name="resourceProperty">resource property describing the property.</param> /// <returns>value for the property.</returns> public virtual object GetPropertyValue(object target, ResourceProperty resourceProperty) { WebUtil.CheckArgumentNull(target, "target"); WebUtil.CheckArgumentNull(resourceProperty, "resourceProperty"); try { var resourceTypeCacheItem = this.ResolveNonPrimitiveTypeCacheItem(target.GetType()); PropertyInfo propertyInfo = this.GetResourcePropertyCacheItem(resourceTypeCacheItem, resourceProperty).PropertyInfo; Debug.Assert(propertyInfo != null, "propertyInfo != null"); return(propertyInfo.GetGetMethod().Invoke(target, null)); } catch (TargetInvocationException exception) { ErrorHandler.HandleTargetInvocationException(exception); throw; } }
public object GetProjectedPropertyValue(string propertyName) { WebUtil.CheckArgumentNull <string>(propertyName, "propertyName"); if (this.propertyNames == null) { throw new InvalidOperationException(System.Data.Services.Strings.BasicExpandProvider_ProjectedPropertiesNotInitialized); } int propertyIndex = -1; for (int i = 0; i < this.propertyNames.Length; i++) { if (this.propertyNames[i] == propertyName) { propertyIndex = i; break; } } return(this.InternalGetProjectedPropertyValue(propertyIndex)); }
public ResourceType(Type instanceType, System.Data.Services.Providers.ResourceTypeKind resourceTypeKind, ResourceType baseType, string namespaceName, string name, bool isAbstract) : this(instanceType, baseType, namespaceName, name, isAbstract) { WebUtil.CheckArgumentNull <Type>(instanceType, "instanceType"); WebUtil.CheckStringArgumentNullOrEmpty(name, "name"); WebUtil.CheckResourceTypeKind(resourceTypeKind, "resourceTypeKind"); if (((resourceTypeKind == System.Data.Services.Providers.ResourceTypeKind.Primitive) || (resourceTypeKind == System.Data.Services.Providers.ResourceTypeKind.Collection)) || (resourceTypeKind == System.Data.Services.Providers.ResourceTypeKind.EntityCollection)) { throw new ArgumentException(System.Data.Services.Strings.ResourceType_InvalidValueForResourceTypeKind("resourceTypeKind"), "resourceTypeKind"); } if ((baseType != null) && (baseType.ResourceTypeKind != resourceTypeKind)) { throw new ArgumentException(System.Data.Services.Strings.ResourceType_InvalidResourceTypeKindInheritance(resourceTypeKind.ToString(), baseType.ResourceTypeKind.ToString()), "resourceTypeKind"); } if (instanceType.IsValueType) { throw new ArgumentException(System.Data.Services.Strings.ResourceType_TypeCannotBeValueType, "instanceType"); } this.resourceTypeKind = resourceTypeKind; }
/// <summary> /// Invoke the given service operation instance. /// </summary> /// <param name="serviceOperation">metadata for the service operation to invoke.</param> /// <param name="parameters">list of parameters to pass to the service operation.</param> /// <returns>returns the result by the service operation instance.</returns> public virtual object InvokeServiceOperation(ServiceOperation serviceOperation, object[] parameters) { WebUtil.CheckArgumentNull(serviceOperation, "serviceOperation"); try { return(((MethodInfo)serviceOperation.CustomState).Invoke( this.dataServiceInstance, BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy, null, parameters, CultureInfo.InvariantCulture)); } catch (TargetInvocationException exception) { ErrorHandler.HandleTargetInvocationException(exception); throw; } }
/// <summary>Initializes a new <see cref="ExpandSegment"/> instance.</summary> /// <param name="name">Segment name.</param> /// <param name="filter">Filter expression for segment, possibly null.</param> /// <param name="maxResultsExpected"> /// Expand providers may choose to return at most MaxResultsExpected + 1 elements to allow the /// data service to detect a failure to meet this constraint. /// </param> /// <param name="container">Container to which the segment belongs; possibly null.</param> /// <param name="targetResourceType">Target resource type on which the expansion needs to happen.</param> /// <param name="expandedProperty">Property expanded by this expand segment</param> /// <param name="orderingInfo">Collection of ordering information for this segment, used for paging</param> internal ExpandSegment( string name, Expression filter, int maxResultsExpected, ResourceSetWrapper container, ResourceType targetResourceType, ResourceProperty expandedProperty, OrderingInfo orderingInfo) { WebUtil.CheckArgumentNull(name, "name"); CheckFilterType(filter); this.name = name; this.filter = filter; this.container = container; this.maxResultsExpected = maxResultsExpected; this.expandedProperty = expandedProperty; this.orderingInfo = orderingInfo; this.targetResourceType = targetResourceType; }
/// <summary> /// Creates an instance of <see cref="DataServiceProviderArgs"/>. /// </summary> /// <param name="dataServiceInstance">Required instance of data service object.</param> /// <param name="dataSourceInstance">Required instance of data source object.</param> /// <param name="knownTypes">Optional collection of known types.</param> /// <param name="useMetadataKeyOrder">Whether metadata key order is to be used instead of default service defined key order.</param> public DataServiceProviderArgs(object dataServiceInstance, object dataSourceInstance, IEnumerable <Type> knownTypes, bool useMetadataKeyOrder) { WebUtil.CheckArgumentNull(dataServiceInstance, "dataServiceInstance"); WebUtil.CheckArgumentNull(dataSourceInstance, "dataSourceInstance"); this.DataServiceInstance = dataServiceInstance; this.DataSourceInstance = dataSourceInstance; if (knownTypes != null) { this.KnownTypes = new ReadOnlyCollection <Type>(new List <Type>(knownTypes)); } else { this.KnownTypes = Enumerable.Empty <Type>(); } this.UseMetadataKeyOrder = useMetadataKeyOrder; this.SkipServiceOperationMetadata = false; }
/// <summary>Initializes a new instance of the <see cref="T:Microsoft.OData.Service.Providers.ResourceAssociationSet" /> class.</summary> /// <param name="name">Name of the association set.</param> /// <param name="end1"><see cref="T:Microsoft.OData.Service.Providers.ResourceAssociationSetEnd" /> that is at the source end of the association set.</param> /// <param name="end2"><see cref="T:Microsoft.OData.Service.Providers.ResourceAssociationSetEnd" /> that is at the target end of the association set.</param> public ResourceAssociationSet(string name, ResourceAssociationSetEnd end1, ResourceAssociationSetEnd end2) { WebUtil.CheckStringArgumentNullOrEmpty(name, "name"); WebUtil.CheckArgumentNull(end1, "end1"); WebUtil.CheckArgumentNull(end2, "end2"); if (end1.ResourceProperty == null && end2.ResourceProperty == null) { throw new ArgumentException(Strings.ResourceAssociationSet_ResourcePropertyCannotBeBothNull); } ////if (end1.ResourceType == end2.ResourceType && end1.ResourceProperty == end2.ResourceProperty) ////{ //// throw new ArgumentException(Strings.ResourceAssociationSet_SelfReferencingAssociationCannotBeBiDirectional); ////} this.name = name; this.end1 = end1; this.end2 = end2; }
public ResourceAssociationSetEnd(System.Data.Services.Providers.ResourceSet resourceSet, System.Data.Services.Providers.ResourceType resourceType, System.Data.Services.Providers.ResourceProperty resourceProperty) { WebUtil.CheckArgumentNull <System.Data.Services.Providers.ResourceSet>(resourceSet, "resourceSet"); WebUtil.CheckArgumentNull <System.Data.Services.Providers.ResourceType>(resourceType, "resourceType"); if ((resourceProperty != null) && ((resourceType.TryResolvePropertyName(resourceProperty.Name) == null) || (resourceProperty.TypeKind != ResourceTypeKind.EntityType))) { throw new ArgumentException(Strings.ResourceAssociationSetEnd_ResourcePropertyMustBeNavigationPropertyOnResourceType); } if (!resourceSet.ResourceType.IsAssignableFrom(resourceType) && !resourceType.IsAssignableFrom(resourceSet.ResourceType)) { throw new ArgumentException(Strings.ResourceAssociationSetEnd_ResourceTypeMustBeAssignableToResourceSet); } if ((resourceProperty != null) && (DataServiceProviderWrapper.GetDeclaringTypeForProperty(resourceType, resourceProperty, null) != resourceType)) { throw new ArgumentException(Strings.ResourceAssociationSetEnd_ResourceTypeMustBeTheDeclaringType(resourceType.FullName, resourceProperty.Name)); } this.resourceSet = resourceSet; this.resourceType = resourceType; this.resourceProperty = resourceProperty; }
public override ResourceAssociationSet GetResourceAssociationSet(ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty) { ResourceSet set; ResourceType type; string str; WebUtil.CheckArgumentNull <ResourceSet>(resourceSet, "resourceSet"); WebUtil.CheckArgumentNull <ResourceType>(resourceType, "resourceType"); WebUtil.CheckArgumentNull <ResourceProperty>(resourceProperty, "resourceProperty"); if (!base.TryResolveResourceSet(resourceSet.Name, out set) || (set != resourceSet)) { throw new InvalidOperationException(System.Data.Services.Strings.BadProvider_UnknownResourceSet(resourceSet.Name)); } if (!base.TryResolveResourceType(resourceType.FullName, out type) || (type != resourceType)) { throw new InvalidOperationException(System.Data.Services.Strings.BadProvider_UnknownResourceType(resourceType.FullName)); } if (resourceType != DataServiceProviderWrapper.GetDeclaringTypeForProperty(resourceType, resourceProperty, null)) { throw new InvalidOperationException(System.Data.Services.Strings.BadProvider_ResourceTypeMustBeDeclaringTypeForProperty(resourceType.FullName, resourceProperty.Name)); } ResourceType type2 = resourceProperty.ResourceType; if (type2.ResourceTypeKind != ResourceTypeKind.EntityType) { throw new InvalidOperationException(System.Data.Services.Strings.BadProvider_PropertyMustBeNavigationPropertyOnType(resourceProperty.Name, resourceType.FullName)); } ResourceSet containerForResourceType = InternalGetContainerForResourceType(type2.InstanceType, base.EntitySets.Values); if (base.Types.Count <ResourceType>(rt => (rt.Name == resourceType.Name)) > 1) { str = resourceType.FullName.Replace('.', '_') + '_' + resourceProperty.Name; } else { str = resourceType.Name + '_' + resourceProperty.Name; } ResourceAssociationSetEnd end = new ResourceAssociationSetEnd(resourceSet, resourceType, resourceProperty); return(new ResourceAssociationSet(str, end, new ResourceAssociationSetEnd(containerForResourceType, type2, null))); }
/// <summary> /// Constructs a ResourceAssociationEnd instance. /// </summary> /// <param name="resourceSet">Resource set of the association end.</param> /// <param name="resourceType">Resource type of the association end.</param> /// <param name="resourceProperty">Resource property of the association end.</param> public ResourceAssociationSetEnd(ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty) { WebUtil.CheckArgumentNull(resourceSet, "resourceSet"); WebUtil.CheckArgumentNull(resourceType, "resourceType"); if (resourceProperty != null && (resourceType.TryResolvePropertyName(resourceProperty.Name) == null || resourceProperty.TypeKind != ResourceTypeKind.EntityType)) { throw new ArgumentException(Strings.ResourceAssociationSetEnd_ResourcePropertyMustBeNavigationPropertyOnResourceType); } if (!resourceSet.ResourceType.IsAssignableFrom(resourceType) && !resourceType.IsAssignableFrom(resourceSet.ResourceType)) { throw new ArgumentException(Strings.ResourceAssociationSetEnd_ResourceTypeMustBeAssignableToResourceSet); } this.resourceSet = resourceSet; this.resourceType = resourceType; // Note that for the TargetEnd, resourceProperty can be null. this.resourceProperty = resourceProperty; }
internal void AddContentToTarget(SyndicationItem target) #endif { #if ASTORIA_CLIENT Util.CheckArgumentNull(target, "target"); #else WebUtil.CheckArgumentNull(target, "target"); #endif this.XmlContentWriter.Close(); this.XmlContentWriter = null; this.XmlContentStream.Seek(0, SeekOrigin.Begin); XmlReaderSettings customContentReaderSettings = new XmlReaderSettings(); customContentReaderSettings.ConformanceLevel = ConformanceLevel.Fragment; XmlReader reader = XmlReader.Create(this.XmlContentStream, customContentReaderSettings); this.XmlContentStream = null; #if ASTORIA_CLIENT target.WriteNode(reader, false); #else target.ElementExtensions.Add(reader); #endif }
public IEnumerable <ResourceType> GetDerivedTypes(ResourceType resourceType) { WebUtil.CheckArgumentNull <ResourceType>(resourceType, "resourceType"); if (!this.ChildTypesCache.ContainsKey(resourceType)) { throw new InvalidOperationException(System.Data.Services.Strings.BaseServiceProvider_UnknownResourceTypeInstance(resourceType.FullName)); } List <ResourceType> iteratorVariable0 = this.ChildTypesCache[resourceType]; if (iteratorVariable0 != null) { foreach (ResourceType iteratorVariable1 in iteratorVariable0) { yield return(iteratorVariable1); foreach (ResourceType iteratorVariable2 in this.GetDerivedTypes(iteratorVariable1)) { yield return(iteratorVariable2); } } } }
/// <summary> /// The method must return a collection of all the types derived from <paramref name="resourceType"/>. /// The collection returned should NOT include the type passed in as a parameter. /// An implementer of the interface should return null if the type does not have any derived types (ie. null == no derived types). /// </summary> /// <param name="resourceType">Resource to get derived resource types from.</param> /// <returns> /// A collection of resource types (<see cref="ResourceType"/>) derived from the specified <paramref name="resourceType"/> /// or null if there no types derived from the specified <paramref name="resourceType"/> exist. /// </returns> public virtual IEnumerable <ResourceType> GetDerivedTypes(ResourceType resourceType) { WebUtil.CheckArgumentNull(resourceType, "resourceType"); if (!this.ChildTypesCache.ContainsKey(resourceType)) { throw new InvalidOperationException(Strings.BaseServiceProvider_UnknownResourceTypeInstance(resourceType.FullName)); } List <ResourceType> childTypes = this.ChildTypesCache[resourceType]; if (childTypes != null) { foreach (ResourceType childType in childTypes) { yield return(childType); foreach (ResourceType descendantType in this.GetDerivedTypes(childType)) { yield return(descendantType); } } } }
/// <summary>Sets the maximum page size for an entity set resource.</summary> /// <param name="name">The name of entity set resource for which to set the page size.</param> /// <param name="size">The page size for the entity set resource that is specified in <paramref name="name" />.</param> public void SetEntitySetPageSize(String name, int size) { WebUtil.CheckArgumentNull(name, "name"); if (size < 0) { throw new ArgumentOutOfRangeException("size", size, Strings.DataService_SDP_PageSizeMustbeNonNegative(size, name)); } // Treat a page size of Int32.MaxValue to be the same as not setting the page size. if (size == Int32.MaxValue) { size = 0; } if (this.MaxResultsPerCollection != Int32.MaxValue) { throw new InvalidOperationException(Strings.DataService_SDP_PageSizeWithMaxResultsPerCollection); } this.CheckNotSealed(); if (name == "*") { this.defaultPageSize = size; } else { ResourceSet container; if (!this.provider.TryResolveResourceSet(name, out container) || container == null) { throw new ArgumentException(Strings.DataServiceConfiguration_ResourceSetNameNotFound(name), "name"); } this.pageSizes[container.Name] = size; } }
internal const int RetryWaitMilliseconds = 100; //The base retry time between retry attempts public static ulong GetServerTickCountFromDatabase(SqlConnection connection, SqlTransaction transaction) { WebUtil.CheckArgumentNull(connection, "connection"); SqlEdition edition = GetEdition(connection, transaction); string commandText = string.Empty; switch (edition) { case SqlEdition.SqlAzure: commandText = "SELECT CAST(get_new_rowversion() AS BIGINT)"; break; default: commandText = "SELECT CAST(@@DBTS AS BIGINT)"; break; } using (var command = new SqlCommand(commandText, connection, transaction)) { return(Convert.ToUInt64(command.ExecuteScalar())); } }
/// <summary>A Boolean value that indicates whether any segments in the specified <paramref name="path"/> have a filter.</summary> /// <returns>True if any of the segments in the path has a filter; false otherwise.</returns> /// <param name="path">The enumeration of segments to check for filters.</param> public static bool PathHasFilter(IEnumerable <ExpandSegment> path) { WebUtil.CheckArgumentNull(path, "path"); return(System.Linq.Enumerable.Any(path, segment => segment.HasFilter)); }
public IQueryable GetQueryRootForResourceSet(ResourceSet container) { WebUtil.CheckArgumentNull <ResourceSet>(container, "container"); return(this.GetResourceContainerInstance(container)); }
public static EntityCollectionResourceType GetEntityCollectionResourceType(ResourceType itemType) { WebUtil.CheckArgumentNull <ResourceType>(itemType, "itemType"); return(new EntityCollectionResourceType(itemType)); }
public void AddProperty(ResourceProperty property) { WebUtil.CheckArgumentNull <ResourceProperty>(property, "property"); this.ThrowIfSealed(); this.AddPropertyInternal(property); }
/// <summary> /// Start writing a navigation link. /// </summary> /// <param name="args">DataServiceODataWriterNavigationLinkArgs which contains the ODataNavigationLink to serialize.</param> public virtual void WriteStart(DataServiceODataWriterNavigationLinkArgs args) { WebUtil.CheckArgumentNull(args, "args"); this.innerWriter.WriteStart(args.NavigationLink); }
/// <summary> /// Finish writing an entry. /// </summary> /// <param name="args">DataServiceODataWriterEntryArgs which contains the ODataEntry and the entry instance that is being serialized.</param> /// <remarks> /// This method calls WriteEnd() and it's used to track when WriteEnd is called for Entry. /// </remarks> public virtual void WriteEnd(DataServiceODataWriterEntryArgs args) { WebUtil.CheckArgumentNull(args, "args"); this.WriteEnd(); }
/// <summary> /// Start writing an entry. /// </summary> /// <param name="args">DataServiceODataWriterEntryArgs which contains the ODataEntry and the entry instance to serialize.</param> public virtual void WriteStart(DataServiceODataWriterEntryArgs args) { WebUtil.CheckArgumentNull(args, "args"); this.innerWriter.WriteStart(args.Entry); }
public DataServiceODataWriter(ODataWriter odataWriter) { WebUtil.CheckArgumentNull(odataWriter, "odataWriter"); this.innerWriter = odataWriter; }
/// <summary> /// Initializes a new instance of the <see cref="MessageWriterSettingsArgs"/> class. /// </summary> /// <param name="settings">The settings.</param> public MessageWriterSettingsArgs(ODataMessageWriterSettings settings) { WebUtil.CheckArgumentNull(settings, "settings"); this.Settings = settings; }
/// <summary>Initializes a new instance of the <see cref="T:Microsoft.OData.Service.QueryInterceptorAttribute" /> class for the entity set specified by the <paramref name="entitySetName" /> parameter.</summary> /// <param name="entitySetName">The name of the entity set that contains the entity to which the interceptor applies.</param> public QueryInterceptorAttribute(string entitySetName) { this.entitySetName = WebUtil.CheckArgumentNull(entitySetName, "entitySetName"); }
/// <summary> /// Finish writing a navigation link. /// </summary> /// <param name="args">DataServiceODataWriterNestedResourceInfoArgs which contains the ODataNestedResourceInfo that is being serialized.</param> /// <remarks> /// This method calls WriteEnd() and it's used to track when WriteEnd is called for Link. /// </remarks> public virtual void WriteEnd(DataServiceODataWriterNestedResourceInfoArgs args) { WebUtil.CheckArgumentNull(args, "args"); this.WriteEnd(); }
public static IQueryable <TElement> SetContinuationToken <TElement>(IDataServicePagingProvider pagingProvider, IQueryable <TElement> query, ResourceType resourceType, object[] continuationToken) { WebUtil.CheckArgumentNull(pagingProvider, "pagingProvider"); pagingProvider.SetContinuationToken(query, resourceType, continuationToken); return(query); }
public ResourceType GetResourceType(object resource) { WebUtil.CheckArgumentNull <object>(resource, "resource"); return(this.GetNonPrimitiveType(resource.GetType())); }