コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MetadataProviderEdmActionImport"/> class.
 /// </summary>
 /// <param name="model">The model this instance belongs to.</param>
 /// <param name="operation">The resource operation underlying this action import.</param>
 /// <param name="namespaceName">The namespace of the EdmOperation.</param>
 /// <remarks>
 /// This constructor assumes that the entity set for this service operation has already be created.
 /// </remarks>
 internal MetadataProviderEdmAction(
     MetadataProviderEdmModel model, 
     OperationWrapper operation,
     string namespaceName)
     : base(model, operation, namespaceName)
 {
 }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MetadataProviderEdmActionImport"/> class.
 /// </summary>
 /// <param name="model">The model this instance belongs to.</param>
 /// <param name="container">The container this instance belongs to.</param>
 /// <param name="action">The edm action object underlying this function import.</param>
 /// <remarks>
 /// This constructor assumes that the entity set for this service operation has already be created.
 /// </remarks>
 internal MetadataProviderEdmActionImport(
     MetadataProviderEdmModel model, 
     MetadataProviderEdmEntityContainer container, 
     MetadataProviderEdmAction action)
     : base(model, container, action)
 {
     this.Action = action;
 }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MetadataProviderEdmFunctionImport"/> class.
 /// </summary>
 /// <param name="model">The model this instance belongs to.</param>
 /// <param name="container">The container this instance belongs to.</param>
 /// <param name="function">The function that is being imported.</param>
 /// <remarks>
 /// This constructor assumes that the entity set for this service operation has already be created.
 /// </remarks>
 internal MetadataProviderEdmFunctionImport(
     MetadataProviderEdmModel model, 
     MetadataProviderEdmEntityContainer container, 
     MetadataProviderEdmFunction function)
     : base(model, container, function)
 {
     this.Function = function;
 }
コード例 #4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="model">The edm model this instance belongs to.</param>
        /// <param name="entityContainer">Entity container instance that this set belongs to.</param>
        /// <param name="resourceSet">ResourceSet that this entity set represents.</param>
        internal MetadataProviderEdmEntitySet(MetadataProviderEdmModel model, MetadataProviderEdmEntityContainer entityContainer, ResourceSetWrapper resourceSet)
        {
            Debug.Assert(model != null, "model != null");
            Debug.Assert(entityContainer != null, "entityContainer != null");
            Debug.Assert(resourceSet != null, "resourceSet != null");

            this.model = model;
            this.entityContainer = entityContainer;
            this.resourceSet = resourceSet;
        }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MetadataProviderEdmFunctionImport"/> class.
 /// </summary>
 /// <param name="model">The model this instance belongs to.</param>
 /// <param name="operation">The resource operation underlying this function import.</param>
 /// <param name="namespaceName">The namespace of the operation.</param>
 /// <remarks>
 /// This constructor assumes that the entity set for this service operation has already be created.
 /// </remarks>
 internal MetadataProviderEdmFunction(MetadataProviderEdmModel model, OperationWrapper operation, string namespaceName)
     : base(model, operation, namespaceName)
 {
     this.IsComposable = DefaultIsComposable;
     
     // By default everything is composable except functions that return IEnumerable
     if (operation.ReturnInstanceType != null && !(typeof(IEnumerable).IsAssignableFrom(operation.ReturnInstanceType) && !typeof(IQueryable).IsAssignableFrom(operation.ReturnInstanceType)))
     {
         this.IsComposable = true;
     }
 }
コード例 #6
0
        /// <summary>Initializes a new <see cref="RequestExpressionParser"/>.</summary>
        /// <param name="service">Service with data and configuration.</param>
        /// <param name="requestDescription">RequestDescription instance containing information about the current request being parsed.</param>
        internal RequestExpressionParser(IDataService service, RequestDescription requestDescription)
        {
            Debug.Assert(service != null, "service != null");
            Debug.Assert(requestDescription != null, "requestDescription != null");

            this.provider = service.Provider;

            this.model = this.provider.GetMetadataProviderEdmModel();

            this.odataUriParser = RequestUriProcessor.CreateUriParserWithBatchReferenceCallback(service, service.OperationContext.AbsoluteRequestUri);
        }
コード例 #7
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="model">The model this instance belongs to.</param>
        /// <param name="containerName">The name of the entity container.</param>
        /// <param name="entityContainerSchemaNamespace">The namespace of the schema this entity container should be made part of during serialization.</param>
        internal MetadataProviderEdmEntityContainer(MetadataProviderEdmModel model, string containerName, string entityContainerSchemaNamespace)
        {
            Debug.Assert(model != null, "model != null");
            Debug.Assert(!string.IsNullOrEmpty(containerName), "!string.IsNullOrEmpty(containerName)");
            Debug.Assert(!string.IsNullOrEmpty(entityContainerSchemaNamespace), "!string.IsNullOrEmpty(entityContainerSchemaNamespace)");

            this.model = model;
            this.containerName = containerName;
            this.containerNamespace = entityContainerSchemaNamespace;

            this.entitySetCache = new Dictionary<string, IEdmEntitySet>(StringComparer.Ordinal);
            this.operationImportCache = new Dictionary<string, List<IEdmOperationImport>>(StringComparer.Ordinal);
        }
コード例 #8
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="model">The model this instance belongs to.</param>
        /// <param name="container">The container this instance belongs to.</param>
        /// <param name="edmOperation">The edm operation underlying this function import.</param>
        /// <remarks>This constructor assumes that the entity set for this service operation has already be created.</remarks>
        protected internal MetadataProviderEdmOperationImport(
            MetadataProviderEdmModel model, 
            MetadataProviderEdmEntityContainer container,
            MetadataProviderEdmOperation edmOperation)
        {
            Debug.Assert(model != null, "model != null");
            Debug.Assert(container != null, "container != null");
            Debug.Assert(edmOperation != null, "edmOperation != null");

            this.container = container;
            this.model = model;
            this.edmOperation = edmOperation;

            // EntitySetPath=<path string>
            ResourceSetPathExpression resultSetPathExpression = edmOperation.ServiceOperation.ResultSetPathExpression;
            this.entitySetPath = resultSetPathExpression == null ? null : resultSetPathExpression.PathExpression;
        }
コード例 #9
0
        private static IEdmEntityType CreateModelAndGetEdmType(ResourceType resourceType)
        {
            var provider = new DataServiceProviderSimulator();
            DataServiceSimulator dataService = new DataServiceSimulator();

            DataServiceStaticConfiguration staticConfiguration = new DataServiceStaticConfiguration(dataService.Instance.GetType(), provider);
            IDataServiceProviderBehavior providerBehavior = DataServiceProviderBehavior.CustomDataServiceProviderBehavior;

            DataServiceProviderWrapper providerWrapper = new DataServiceProviderWrapper(
                    new DataServiceCacheItem(
                        new DataServiceConfiguration(provider),
                        staticConfiguration),
                    provider,
                    provider,
                    dataService,
                    false);

            dataService.Provider = providerWrapper;
            var model = new MetadataProviderEdmModel(providerWrapper, new DataServiceStreamProviderWrapper(dataService), DataServiceActionProviderWrapper.Create(dataService));

            dataService.ProcessingPipeline = new DataServiceProcessingPipeline();
            model.MetadataProvider.ProviderBehavior = providerBehavior;

            var edmType = model.EnsureSchemaType(resourceType) as IEdmEntityType;
            return edmType;
        }
コード例 #10
0
        private static MetadataProviderEdmModel CreateMetadataProviderEdmModel(DataServiceProviderSimulator metadataProvider, IDataServiceActionProvider actionProvider = null)
        {
            var dataServiceSimulator = new DataServiceSimulatorWithGetService { OperationContext = new DataServiceOperationContext(false, new DataServiceHost2Simulator()), ProcessingPipeline = new DataServiceProcessingPipeline() };
            dataServiceSimulator.OperationContext.InitializeAndCacheHeaders(dataServiceSimulator);

            var dataServiceConfiguration = new DataServiceConfiguration(metadataProvider);
            dataServiceConfiguration.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
            dataServiceConfiguration.SetServiceActionAccessRule("*", ServiceActionRights.Invoke);
            dataServiceConfiguration.DataServiceBehavior.MaxProtocolVersion = ODataProtocolVersion.V4;

            if (actionProvider != null)
            {
                dataServiceSimulator.Providers.Add(typeof(IDataServiceActionProvider), actionProvider);
            }

            DataServiceStaticConfiguration staticConfiguration = new DataServiceStaticConfiguration(dataServiceSimulator.Instance.GetType(), metadataProvider);
            IDataServiceProviderBehavior providerBehavior = DataServiceProviderBehavior.CustomDataServiceProviderBehavior;

            DataServiceProviderWrapper providerWrapper = new DataServiceProviderWrapper(
                    new DataServiceCacheItem(
                        dataServiceConfiguration,
                        staticConfiguration),
                    metadataProvider,
                    metadataProvider,
                    dataServiceSimulator,
                    false);

            dataServiceSimulator.Provider = providerWrapper;

            var model = new MetadataProviderEdmModel(providerWrapper, new DataServiceStreamProviderWrapper(dataServiceSimulator),  DataServiceActionProviderWrapper.Create(dataServiceSimulator));

            model.MetadataProvider.ProviderBehavior = providerBehavior;
            return model;
        }
コード例 #11
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="model">The model this instance belongs to.</param>
        /// <param name="operation">The resource operation underlying this function import.</param>
        /// <param name="namespaceName">The namespace of the operation.</param>
        /// <remarks>This constructor assumes that the entity set for this service operation has already be created.</remarks>
        protected internal MetadataProviderEdmOperation(MetadataProviderEdmModel model, OperationWrapper operation, string namespaceName)
        {
            Debug.Assert(model != null, "model != null");
            Debug.Assert(operation != null, "operation != null");

            this.model = model;
            this.ServiceOperation = operation;
            this.Namespace = namespaceName;

            if (operation.Kind == OperationKind.Action)
            {
                this.isBound = this.ServiceOperation.BindingParameter != null;
            }
            else
            {
                Debug.Assert(operation.Kind == OperationKind.ServiceOperation, "serviceOperation.Kind == OperationKind.ServiceOperation");
                Debug.Assert(operation.OperationParameterBindingKind == OperationParameterBindingKind.Never, "operation.OperationParameterBindingKind == OperationParameterBindingKind.Never");
                this.isBound = DefaultIsBindable;
            }

            // EntitySetPath=<path string>
            ResourceSetPathExpression resultSetPathExpression = operation.ResultSetPathExpression;
            this.entitySetPath = resultSetPathExpression == null ? null : resultSetPathExpression.PathExpression;

#if DEBUG
            ResourceType returnType = operation.ReturnType;
            ResourceSetWrapper resultSet = operation.ResourceSet;

            Debug.Assert(
                returnType == null || returnType.ResourceTypeKind == ResourceTypeKind.EntityCollection || returnType.ResourceTypeKind == ResourceTypeKind.EntityType || (resultSet == null && resultSetPathExpression == null),
                "resultSet and resultSetPathExpression must be both null when the return type is not an entity type or an entity collection type.");
            Debug.Assert(
                (returnType == null || returnType.ResourceTypeKind != ResourceTypeKind.EntityCollection && returnType.ResourceTypeKind != ResourceTypeKind.EntityType) || (resultSet != null || resultSetPathExpression != null),
                "One of resultSet or resultSetPathExpression must be set when the return type is either an entity type or an entity collection type.");
            Debug.Assert(resultSet == null || resultSetPathExpression == null, "resultSet and resultSetPathExpression cannot be both set.");
#endif

            string mimeType = operation.MimeType;
            if (!string.IsNullOrEmpty(mimeType))
            {
                model.SetMimeType(this, mimeType);
            }

            switch (this.ServiceOperation.OperationParameterBindingKind)
            {
                case OperationParameterBindingKind.Always:
                    break;

                default:
                    Debug.Assert(
                        this.ServiceOperation.OperationParameterBindingKind == OperationParameterBindingKind.Sometimes ||
                        this.ServiceOperation.OperationParameterBindingKind == OperationParameterBindingKind.Never,
                        "this.ServiceOperation.OperationParameterBindingKind == OperationParameterBindingKind.Sometimes || this.ServiceOperation.OperationParameterBindingKind == OperationParameterBindingKind.Never");
                    break;
            }

            ReadOnlyCollection<OperationParameter> operationParameters = operation.Parameters;
            if (operationParameters != null && operationParameters.Count > 0)
            {
                List<IEdmOperationParameter> list = new List<IEdmOperationParameter>(operationParameters.Count);
                foreach (OperationParameter parameter in operationParameters)
                {
                    IEdmTypeReference parameterType = this.model.EnsureTypeReference(parameter.ParameterType, /*annotations*/ null);
                    EdmOperationParameter edmParameter = new EdmOperationParameter(this, parameter.Name, parameterType);
                    list.Add(edmParameter);
                }

                this.parameters = new ReadOnlyCollection<IEdmOperationParameter>(list);
            }

            this.ReturnType = this.CreateReturnTypeReference();
        }
コード例 #12
0
        /// <summary>
        /// Parses the path part of the request URI using the ODL uri parser.
        /// </summary>
        /// <param name="metadataProviderEdmModel">The metadata provider edm model.</param>
        /// <param name="absoluteRequestUri">The absolute request URI.</param>
        /// <param name="service">The data service.</param>
        /// <returns>
        /// The parsed path.
        /// </returns>
        private static ODataPath ParsePath(MetadataProviderEdmModel metadataProviderEdmModel, Uri absoluteRequestUri, IDataService service)
        {
            Debug.Assert(absoluteRequestUri != null, "absoluteRequestUri != null");
            Debug.Assert(service != null, "service != null");

            var parser = CreateUriParserWithBatchReferenceCallback(service, absoluteRequestUri);

            // parse the path in the ODataUriParser constructor, and convert any parsing exceptions into DataServiceExceptions.
            try
            {
                Debug.Assert(metadataProviderEdmModel.Mode == MetadataProviderEdmModelMode.Serialization, "Model expected to be in serialization mode by default");
                metadataProviderEdmModel.Mode = MetadataProviderEdmModelMode.UriPathParsing;
                return parser.ParsePath();
            }
            catch (ODataUnrecognizedPathException exception)
            {
                // For now, don't include the original exception because it causes the stack trace to be written, breaking a lot of tests.
                throw DataServiceException.ResourceNotFoundError(exception.Message);
            }
            catch (ODataException exception)
            {
                if (exception.InnerException != null)
                {
                    // For now, don't include the original exception because it causes the stack trace to be written, breaking a lot of tests.
                    throw DataServiceException.CreateSyntaxError(exception.InnerException.Message);
                }

                throw DataServiceException.CreateSyntaxError(exception.Message);
            }
            finally
            {
                metadataProviderEdmModel.Mode = MetadataProviderEdmModelMode.Serialization;
            }
        }
コード例 #13
0
ファイル: SelectBinder.cs プロジェクト: AlineGuan/odata.net
 /// <summary>
 /// Creates a new instance of <see cref="ContainerQualifiedWildcardSelectItem"/>.
 /// </summary>
 /// <param name="metadataProviderEdmModel">The metadata provider-based edm model.</param>
 /// <returns>A new instance of <see cref="ContainerQualifiedWildcardSelectItem"/>.</returns>
 private static ContainerQualifiedWildcardSelectItem CreateContainerQualifiedWildcardSelection(MetadataProviderEdmModel metadataProviderEdmModel)
 {
     return new ContainerQualifiedWildcardSelectItem(metadataProviderEdmModel.EnsureDefaultEntityContainer());
 }
コード例 #14
0
ファイル: SelectBinder.cs プロジェクト: AlineGuan/odata.net
 /// <summary>
 /// Creates an instance of <see cref="SelectItem"/> to represent the selection of an set of operations.
 /// </summary>
 /// <param name="metadataProviderEdmModel">The metadata provider-based edm model.</param>
 /// <param name="selectedServiceActions">The operations being selected.</param>
 /// <param name="typeSegments">Type segments seen in the path so far.</param>
 /// <returns>A new <see cref="SelectItem"/> to represent the selection of the operations.</returns>
 private static SelectItem CreateOperationSelection(MetadataProviderEdmModel metadataProviderEdmModel, IEnumerable<OperationWrapper> selectedServiceActions, ICollection<TypeSegment> typeSegments)
 {
     return new PathSelectItem(CreatePath(typeSegments, new OperationSegment(selectedServiceActions.Select(a => metadataProviderEdmModel.EnsureDefaultEntityContainer().EnsureFunctionImport(a)).ToList())));
 }
コード例 #15
0
ファイル: SelectBinder.cs プロジェクト: AlineGuan/odata.net
        /// <summary>
        /// Creates an instance of <see cref="SelectItem"/> to represent the selection of the given property.
        /// </summary>
        /// <param name="metadataProviderEdmModel">The metadata provider-based edm model.</param>
        /// <param name="targetResourceType">The resource type the property is being selected for.</param>
        /// <param name="property">The property being selected.</param>
        /// <param name="typeSegments">Type segments seen in the path so far.</param>
        /// <returns>A new <see cref="SelectItem"/> to represent the selection of the given property.</returns>
        private static SelectItem CreatePropertySelection(MetadataProviderEdmModel metadataProviderEdmModel, ResourceType targetResourceType, ResourceProperty property, ICollection<TypeSegment> typeSegments)
        {
            var structuredType = (IEdmStructuredType)metadataProviderEdmModel.EnsureSchemaType(targetResourceType);
            IEdmProperty edmProperty = structuredType.FindProperty(property.Name);
            var edmStructuralProperty = edmProperty as IEdmStructuralProperty;

            Segment lastSegment;
            if (edmStructuralProperty != null)
            {
                lastSegment = new PropertySegment(edmStructuralProperty);
            }
            else
            {
                lastSegment = new NavigationPropertySegment((IEdmNavigationProperty)edmProperty);
            }

            var path = CreatePath(typeSegments, lastSegment);
            return new PathSelectItem(path);
        }