Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 /// <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;
     }
 }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
        /// <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;
            }
        }
Ejemplo n.º 7
0
 /// <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;
 }
Ejemplo n.º 8
0
        /// <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;
        }
Ejemplo n.º 9
0
        /// <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;
        }
Ejemplo n.º 10
0
 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;
 }
Ejemplo n.º 11
0
        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)));
        }
Ejemplo n.º 12
0
        /// <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
        }
Ejemplo n.º 14
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 15
0
        /// <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);
                    }
                }
            }
        }
Ejemplo n.º 16
0
        /// <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;
            }
        }
Ejemplo n.º 17
0
        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()));
            }
        }
Ejemplo n.º 18
0
 /// <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));
 }
Ejemplo n.º 19
0
 public IQueryable GetQueryRootForResourceSet(ResourceSet container)
 {
     WebUtil.CheckArgumentNull <ResourceSet>(container, "container");
     return(this.GetResourceContainerInstance(container));
 }
Ejemplo n.º 20
0
 public static EntityCollectionResourceType GetEntityCollectionResourceType(ResourceType itemType)
 {
     WebUtil.CheckArgumentNull <ResourceType>(itemType, "itemType");
     return(new EntityCollectionResourceType(itemType));
 }
Ejemplo n.º 21
0
 public void AddProperty(ResourceProperty property)
 {
     WebUtil.CheckArgumentNull <ResourceProperty>(property, "property");
     this.ThrowIfSealed();
     this.AddPropertyInternal(property);
 }
Ejemplo n.º 22
0
 /// <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);
 }
Ejemplo n.º 23
0
 /// <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();
 }
Ejemplo n.º 24
0
 /// <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);
 }
Ejemplo n.º 25
0
 public DataServiceODataWriter(ODataWriter odataWriter)
 {
     WebUtil.CheckArgumentNull(odataWriter, "odataWriter");
     this.innerWriter = odataWriter;
 }
Ejemplo n.º 26
0
        /// <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;
        }
Ejemplo n.º 27
0
 /// <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");
 }
Ejemplo n.º 28
0
 /// <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();
 }
Ejemplo n.º 29
0
 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);
 }
Ejemplo n.º 30
0
 public ResourceType GetResourceType(object resource)
 {
     WebUtil.CheckArgumentNull <object>(resource, "resource");
     return(this.GetNonPrimitiveType(resource.GetType()));
 }