Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new <see cref="DataServiceConfiguration"/> with
        /// the specified <paramref name="provider"/>.
        /// </summary>
        /// <param name="provider">Non-null provider for this configuration.</param>
        internal DataServiceConfiguration(IDataServiceMetadataProvider provider)
        {
            WebUtil.CheckArgumentNull(provider, "provider");
            this.provider               = provider;
            this.resourceRights         = new Dictionary <string, EntitySetRights>(EqualityComparer <string> .Default);
            this.serviceOperationRights = new Dictionary <string, ServiceOperationRights>(EqualityComparer <string> .Default);
            this.serviceActionRights    = new Dictionary <string, ServiceActionRights>(EqualityComparer <string> .Default);
            this.pageSizes              = new Dictionary <string, int>(EqualityComparer <string> .Default);
            this.rightsForUnspecifiedResourceContainer = EntitySetRights.None;
            this.rightsForUnspecifiedServiceOperation  = ServiceOperationRights.None;
            this.rightsForUnspecifiedServiceAction     = ServiceActionRights.None;
            this.knownTypes                 = new List <Type>();
            this.maxBatchCount              = Int32.MaxValue;
            this.maxChangeSetCount          = Int32.MaxValue;
            this.maxExpandCount             = Int32.MaxValue;
            this.maxExpandDepth             = Int32.MaxValue;
            this.maxResultsPerCollection    = Int32.MaxValue;
            this.maxObjectCountOnInsert     = Int32.MaxValue;
            this.accessEnabledResourceTypes = new HashSet <string>(EqualityComparer <string> .Default);
            this.dataServiceBehavior        = new DataServiceBehavior();

            // default value is true since in V1, we always did the type conversion
            // and this configuration settings was introduced in V2
            this.typeConversion = true;
        }
Ejemplo n.º 2
0
        public override object TypeIs(object value, DSP.ResourceType type)
        {
            // not clear how we can make this tolerant without it blowing up
            APICallLog.Current.Push();
            try
            {
                if (value == null)
                {
                    return(false);
                }

                DSP.ResourceType instanceType = QueryProvider.GetResourceType(value);
                if (instanceType != null)
                {
                    IDataServiceMetadataProvider metadataProvider = QueryProvider as IDataServiceMetadataProvider;
                    if (metadataProvider != null && metadataProvider.HasDerivedTypes(type))
                    {
                        if (metadataProvider.GetDerivedTypes(type).Contains(instanceType))
                        {
                            return(true);
                        }
                    }
                    return(type == instanceType);
                }

                return(type.InstanceType.IsAssignableFrom(value.GetType()));
            }
            finally
            {
                APICallLog.Current.Pop();
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructors the static configuration object which can be cached for the whole AppDomain lifecycle.
 /// </summary>
 /// <param name="dataServiceType">Service type.</param>
 /// <param name="provider">Metadata provider instance.</param>
 internal DataServiceStaticConfiguration(Type dataServiceType, IDataServiceMetadataProvider provider)
 {
     this.provider = provider;
     this.readAuthorizationMethods  = new Dictionary <string, List <MethodInfo> >(EqualityComparer <string> .Default);
     this.writeAuthorizationMethods = new Dictionary <string, List <MethodInfo> >(EqualityComparer <string> .Default);
     this.RegisterCallbacks(dataServiceType);
     this.LoadConfigurationSettings();
 }
 /// <summary>
 /// Constructors the static configuration object which can be cached for the whole AppDomain lifecycle.
 /// </summary>
 /// <param name="dataServiceType">Service type.</param>
 /// <param name="provider">Metadata provider instance.</param>
 internal DataServiceStaticConfiguration(Type dataServiceType, IDataServiceMetadataProvider provider)
 {
     this.provider = provider;
     this.readAuthorizationMethods = new Dictionary<string, List<MethodInfo>>(EqualityComparer<string>.Default);
     this.writeAuthorizationMethods = new Dictionary<string, List<MethodInfo>>(EqualityComparer<string>.Default);
     this.RegisterCallbacks(dataServiceType);
     this.LoadConfigurationSettings();
 }
Ejemplo n.º 5
0
 private IDataServiceQueryProvider GetQueryProvider(IDataServiceMetadataProvider metadata)
 {
     if (this.queryProvider == null)
     {
         ReportingSchema reportingSchema = ReportingService.GetReportingSchema();
         this.queryProvider = new ReportingQueryProvider(metadata, reportingSchema);
     }
     return(this.queryProvider);
 }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="metadataProvider">The IDataServiceMetadataProvider instance to wrap.</param>
        internal DataServiceMetadataProviderWrapper(IDataServiceMetadataProvider metadataProvider)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(metadataProvider != null, "metadataProvider != null");

            this.metadataProvider      = metadataProvider;
            this.resourceTypeCache     = new Dictionary <string, ResourceType>(EqualityComparer <string> .Default);
            this.resourceSetCache      = new Dictionary <string, ResourceSetWrapper>(EqualityComparer <string> .Default);
            this.serviceOperationCache = new Dictionary <string, ServiceOperationWrapper>(EqualityComparer <string> .Default);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="metadataProvider">The IDataServiceMetadataProvider instance to wrap.</param>
        public DataServiceMetadataProviderWrapper(IDataServiceMetadataProvider metadataProvider)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(metadataProvider != null, "metadataProvider != null");

            this.metadataProvider = metadataProvider;
            this.resourceTypeCache = new Dictionary<string, ResourceType>(EqualityComparer<string>.Default);
            this.resourceSetCache = new Dictionary<string, ResourceSetWrapper>(EqualityComparer<string>.Default);
            this.serviceOperationCache = new Dictionary<string, ServiceOperationWrapper>(EqualityComparer<string>.Default);
        }
        /// <summary>
        /// Wrapper methods around metadata provider to get the ResourceType
        /// </summary>
        /// <param name="metadataProvider">metadata provider</param>
        /// <param name="typeName">type name</param>
        /// <returns>a resource type or throws</returns>
        protected ResourceType GetResourceType(IDataServiceMetadataProvider metadataProvider, string typeName)
        {
            ResourceType resourceType = null;

            ProviderImplementationSettings.Override(
                s => s.EnforceMetadataCaching = false,
                () => ExceptionUtilities.Assert(metadataProvider.TryResolveResourceType(typeName, out resourceType), "Cannot find a resource type '{0}' in the metadata provider", typeName));

            return(resourceType);
        }
        /// <summary>
        /// Wrapper methods around metadata provider to get the ResourceSet
        /// </summary>
        /// <param name="metadataProvider">metadata provider</param>
        /// <param name="setName">set name</param>
        /// <returns>a resource set or throws</returns>
        protected ResourceSet GetResourceSet(IDataServiceMetadataProvider metadataProvider, string setName)
        {
            ResourceSet resourceSet = null;

            ProviderImplementationSettings.Override(
                s => s.EnforceMetadataCaching = false,
                () => ExceptionUtilities.Assert(metadataProvider.TryResolveResourceSet(setName, out resourceSet), "Cannot find a resource set '{0}' in the metadata provider", setName));

            return(resourceSet);
        }
Ejemplo n.º 10
0
 internal void DisposeDataSource()
 {
     WebUtil.Dispose(this.metadataProvider);
     if (this.metadataProvider != this.queryProvider)
     {
         WebUtil.Dispose(this.queryProvider);
     }
     this.metadataProvider = null;
     this.queryProvider    = null;
     this.dataService      = null;
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Initializes all service actions in the provider.
        /// </summary>
        /// <param name="operationContext">The operation context instance of the request.</param>
        private void InitializeServiceActions(DataServiceOperationContext operationContext)
        {
            if (operationContext == null)
            {
                throw new DataServiceException("operationContext must not be null!");
            }

            var actionInfos = Interlocked.Exchange(ref this.serviceActionInfos, new Dictionary <string, DSPServiceActionInfo>());

            if (actionInfos.Count > 0)
            {
                IDataServiceMetadataProvider metadataProvider = (IDataServiceMetadataProvider)operationContext.GetService(typeof(IDataServiceMetadataProvider));
                if (metadataProvider == null)
                {
                    throw new DataServiceException("DataServiceOperationContext.GetService(typeof(IDataServiceMetadataProvider)) must return a valid instance of the IDataServiceMetadataProvider.");
                }

                foreach (var entry in actionInfos)
                {
                    DSPServiceActionInfo actionInfo       = entry.Value;
                    DSPActionAttribute   actionAttribute  = actionInfo.ActionAttribute;
                    MethodInfo           actionMethodInfo = actionInfo.Method;

                    ResourceType returnType = DSPActionProvider.GetResourceTypeFromType(metadataProvider, actionInfo.Method.ReturnType, actionAttribute.ReturnElementTypeName);
                    var          parameters = DSPActionProvider.GetServiceActionParameters(metadataProvider, actionAttribute, actionMethodInfo);

                    ServiceAction action;
                    if (!string.IsNullOrEmpty(actionAttribute.ReturnSetPath))
                    {
                        if (actionAttribute.OperationParameterBindingKind != OperationParameterBindingKind.Always && actionAttribute.OperationParameterBindingKind != OperationParameterBindingKind.Sometimes)
                        {
                            throw new DataServiceException("DSPActionAttribute.IsBindable must be true when DSPActionAttribute.ReturnSetPath is not null.");
                        }

                        ResourceSetPathExpression pathExpression = new ResourceSetPathExpression(actionAttribute.ReturnSetPath);
                        action = new ServiceAction(actionMethodInfo.Name, returnType, OperationParameterBindingKind.Sometimes, parameters, pathExpression);
                    }
                    else
                    {
                        ResourceSet returnSet = null;
                        if (!string.IsNullOrEmpty(actionAttribute.ReturnSet))
                        {
                            metadataProvider.TryResolveResourceSet(actionAttribute.ReturnSet, out returnSet);
                        }

                        action = new ServiceAction(actionMethodInfo.Name, returnType, returnSet, actionAttribute.OperationParameterBindingKind, parameters);
                    }

                    action.CustomState = actionInfo;
                    action.SetReadOnly();
                    this.serviceActions.Add(actionMethodInfo.Name, action);
                }
            }
        }
Ejemplo n.º 12
0
 internal DataServiceProviderWrapper(DataServiceCacheItem cacheItem, IDataServiceMetadataProvider metadataProvider, IDataServiceQueryProvider queryProvider, IDataService dataService)
 {
     this.metadata                  = cacheItem;
     this.metadataProvider          = metadataProvider;
     this.queryProvider             = queryProvider;
     this.dataService               = dataService;
     this.operationWrapperCache     = new Dictionary <string, OperationWrapper>(EqualityComparer <string> .Default);
     this.metadataProviderEdmModels = new Dictionary <DataServiceOperationContext, MetadataProviderEdmModel>(EqualityComparer <DataServiceOperationContext> .Default);
     this.models                  = new Dictionary <DataServiceOperationContext, IEdmModel>(EqualityComparer <DataServiceOperationContext> .Default);
     this.edmSchemaVersion        = MetadataEdmSchemaVersion.Version1Dot0;
     this.containerNameCache      = null;
     this.containerNamespaceCache = null;
 }
Ejemplo n.º 13
0
        public override IQueryable <EntityType> GetEntitySet <EntityType>(string entitySetName)
        {
            IDataServiceMetadataProvider idsmp = this.CurrentDataSource;
            ResourceSet set;

            if (!idsmp.TryResolveResourceSet(entitySetName, out set))
            {
                throw new DataServiceException("Could not find resource set with name '" + entitySetName + "'");
            }

            IDataServiceQueryProvider idsqp = this.CurrentDataSource;

            return(idsqp.GetQueryRootForResourceSet(set).OfType <EntityType>());
        }
            public bool TryResolveServiceAction(DataServiceOperationContext operationContext, string serviceActionName, out ServiceAction serviceAction)
            {
                if (serviceActionName == "Action")
                {
                    IDataServiceMetadataProvider metadataProvider = (IDataServiceMetadataProvider)operationContext.GetService(typeof(IDataServiceMetadataProvider));
                    ResourceType resourceType;
                    metadataProvider.TryResolveResourceType(EntityTypeNameWithStringKey, out resourceType);
                    Assert.IsNotNull(resourceType);
                    serviceAction = new ServiceAction("Action", ResourceType.GetPrimitiveResourceType(typeof(string)), OperationParameterBindingKind.Always, new[] { new ServiceActionParameter("param1", ResourceType.GetEntityCollectionResourceType(resourceType)) }, null);
                    serviceAction.SetReadOnly();
                    return(true);
                }

                serviceAction = null;
                return(false);
            }
Ejemplo n.º 15
0
        private List <ServiceAction> GetActions(DataServiceOperationContext context)
        {
            if (_cache.ContainsKey(_instanceType))
            {
                return(_cache[_instanceType]);
            }

            IDataServiceMetadataProvider metadata = context.GetService(typeof(IDataServiceMetadataProvider)) as IDataServiceMetadataProvider;
            ActionFactory factory = new ActionFactory(metadata);

            var actions = factory.GetActions(_instanceType).ToList();

            _cache[_instanceType] = actions;

            return(actions);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Get the resource type for the given clr type.
        /// </summary>
        /// <param name="metadataProvider">An instance of the IDataServiceMetadataProvider.</param>
        /// <param name="type">Clr type in question.</param>
        /// <param name="elementTypeName">Name of the element type if <paramref name="type"/> is a
        /// <see cref="DSPResource"/> type or a collection type of <see cref="DSPResource"/>.</param>
        /// <returns>The resource type for the given clr type.</returns>
        private static ResourceType GetResourceTypeFromType(IDataServiceMetadataProvider metadataProvider, Type type, string elementTypeName)
        {
            Debug.Assert(metadataProvider != null, "metadataProvider != null");
            if (type == typeof(void))
            {
                return(null);
            }

            ResourceType resourceType;
            Type         elementType = type;

            if (!type.IsPrimitive && type.IsGenericType && typeof(IEnumerable).IsAssignableFrom(type))
            {
                elementType = type.GetGenericArguments()[0];
            }

            if (elementType == typeof(DSPResource))
            {
                metadataProvider.TryResolveResourceType(elementTypeName, out resourceType);
            }
            else
            {
                resourceType = ResourceType.GetPrimitiveResourceType(elementType);
                if (resourceType == null && !metadataProvider.TryResolveResourceType(elementType.FullName, out resourceType))
                {
                    throw new DataServiceException(string.Format("The type '{0}' is unknown to the metadata provider.", elementType.FullName));
                }
            }

            if (type != elementType)
            {
                if (resourceType.ResourceTypeKind == ResourceTypeKind.EntityType)
                {
                    resourceType = ResourceType.GetEntityCollectionResourceType(resourceType);
                }
                else
                {
                    resourceType = ResourceType.GetCollectionResourceType(resourceType);
                }
            }

            return(resourceType);
        }
Ejemplo n.º 17
0
 internal DataServiceConfiguration(IDataServiceMetadataProvider provider)
 {
     this.provider               = provider;
     this.resourceRights         = new Dictionary <string, EntitySetRights>(EqualityComparer <string> .Default);
     this.serviceOperationRights = new Dictionary <string, ServiceOperationRights>(EqualityComparer <string> .Default);
     this.serviceActionRights    = new Dictionary <string, ServiceActionRights>(EqualityComparer <string> .Default);
     this.pageSizes              = new Dictionary <string, int>(EqualityComparer <string> .Default);
     this.rightsForUnspecifiedResourceContainer = EntitySetRights.None;
     this.rightsForUnspecifiedServiceOperation  = ServiceOperationRights.None;
     this.rightsForUnspecifiedServiceAction     = ServiceActionRights.None;
     this.knownTypes                 = new List <Type>();
     this.maxBatchCount              = 0x7fffffff;
     this.maxChangeSetCount          = 0x7fffffff;
     this.maxExpandCount             = 0x7fffffff;
     this.maxExpandDepth             = 0x7fffffff;
     this.maxResultsPerCollection    = 0x7fffffff;
     this.maxObjectCountOnInsert     = 0x7fffffff;
     this.readAuthorizationMethods   = new Dictionary <string, List <MethodInfo> >(EqualityComparer <string> .Default);
     this.writeAuthorizationMethods  = new Dictionary <string, List <MethodInfo> >(EqualityComparer <string> .Default);
     this.accessEnabledResourceTypes = new HashSet <string>(EqualityComparer <string> .Default);
     this.dataServiceBehavior        = new System.Data.Services.DataServiceBehavior();
     this.typeConversion             = true;
 }
Ejemplo n.º 18
0
 internal DataServiceConfiguration(IDataServiceMetadataProvider provider)
 {
     this.provider = provider;
     this.resourceRights = new Dictionary<string, EntitySetRights>(EqualityComparer<string>.Default);
     this.serviceOperationRights = new Dictionary<string, ServiceOperationRights>(EqualityComparer<string>.Default);
     this.serviceActionRights = new Dictionary<string, ServiceActionRights>(EqualityComparer<string>.Default);
     this.pageSizes = new Dictionary<string, int>(EqualityComparer<string>.Default);
     this.rightsForUnspecifiedResourceContainer = EntitySetRights.None;
     this.rightsForUnspecifiedServiceOperation = ServiceOperationRights.None;
     this.rightsForUnspecifiedServiceAction = ServiceActionRights.None;
     this.knownTypes = new List<Type>();
     this.maxBatchCount = 0x7fffffff;
     this.maxChangeSetCount = 0x7fffffff;
     this.maxExpandCount = 0x7fffffff;
     this.maxExpandDepth = 0x7fffffff;
     this.maxResultsPerCollection = 0x7fffffff;
     this.maxObjectCountOnInsert = 0x7fffffff;
     this.readAuthorizationMethods = new Dictionary<string, List<MethodInfo>>(EqualityComparer<string>.Default);
     this.writeAuthorizationMethods = new Dictionary<string, List<MethodInfo>>(EqualityComparer<string>.Default);
     this.accessEnabledResourceTypes = new HashSet<string>(EqualityComparer<string>.Default);
     this.dataServiceBehavior = new System.Data.Services.DataServiceBehavior();
     this.typeConversion = true;
 }
Ejemplo n.º 19
0
        public CustomRowBasedContext()
        {
            if (preserveChanges == false || customers == null)
            {
                provider = null;
                queryProvider = null;
                Debug.Assert((customers == null && orders == null) ||
                             (customers != null && orders != null), "Either the data must be populated or not");

                customers = new List<RowEntityTypeWithIDAsKey>();
                orders = new List<RowEntityTypeWithIDAsKey>();
                products = new List<RowEntityTypeWithIDAsKey>();
                regions = new List<RowEntityTypeWithIDAsKey>();
                orderDetails = new List<RowEntityType>();

                memberCustomers = new List<RowEntityTypeWithIDAsKey>();
                memberOrders = new List<RowEntityTypeWithIDAsKey>();
                memberProducts = new List<RowEntityTypeWithIDAsKey>();
                memberRegions = new List<RowEntityTypeWithIDAsKey>();
                memberOrderDetails = new List<RowEntityType>();

                // initialize data and metadata
                PopulateData();
                if (CustomizeCustomers != null)
                {
                    CustomizeCustomers(customers);
                }
                if (CustomizeOrders != null)
                {
                    CustomizeOrders(orders);
                }

                provider = PopulateMetadata(this);
                queryProvider = (IDataServiceQueryProvider)provider;
            }
        }
 /// <summary>
 /// Loads action providers service actions
 /// </summary>
 /// <param name="dataServiceMetadataProvider">Data Service Metadata Provider</param>
 /// <returns>Enumerable of Service Actions</returns>
 protected abstract IEnumerable <ServiceAction> LoadServiceActions(IDataServiceMetadataProvider dataServiceMetadataProvider);
Ejemplo n.º 21
0
        protected override IEnumerable <ServiceAction> LoadServiceActions(IDataServiceMetadataProvider dataServiceMetadataProvider)
        {
            ResourceType productType;

            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.Product", out productType);

            ResourceType orderLineType;

            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.OrderLine", out orderLineType);

            ResourceType personType;

            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.Person", out personType);

            ResourceType employeeType;

            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.Employee", out employeeType);

            ResourceType specialEmployeeType;

            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.SpecialEmployee", out specialEmployeeType);

            ResourceType contractorType;

            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.Contractor", out contractorType);

            //
            // actions with the same name and non-related binding types
            //
            var RetrieveProductActionProduct = new ServiceAction(
                "RetrieveProduct",
                ResourceType.GetPrimitiveResourceType(typeof(int)),
                null,
                OperationParameterBindingKind.Sometimes,
                new[]
            {
                new ServiceActionParameter("product", productType),
            });

            RetrieveProductActionProduct.SetReadOnly();
            yield return(RetrieveProductActionProduct);

            var RetrieveProductActionOrderLine = new ServiceAction(
                "RetrieveProduct",
                ResourceType.GetPrimitiveResourceType(typeof(int)),
                null,
                OperationParameterBindingKind.Sometimes,
                new[]
            {
                new ServiceActionParameter("orderLine", orderLineType),
            });

            RetrieveProductActionOrderLine.SetReadOnly();
            yield return(RetrieveProductActionOrderLine);

            //
            // Collection bound actions with the same name
            //
            var increaseSalariesActionEmployee = new ServiceAction(
                "IncreaseSalaries",
                null,
                null,
                OperationParameterBindingKind.Sometimes,
                new[]
            {
                new ServiceActionParameter("employees", ResourceType.GetEntityCollectionResourceType(employeeType)),
                new ServiceActionParameter("n", ResourceType.GetPrimitiveResourceType(typeof(int))),
            });

            increaseSalariesActionEmployee.SetReadOnly();
            yield return(increaseSalariesActionEmployee);

            var increaseSalariesActionSpecialEmployee = new ServiceAction(
                "IncreaseSalaries",
                null,
                null,
                OperationParameterBindingKind.Sometimes,
                new[]
            {
                new ServiceActionParameter("specialEmployees", ResourceType.GetEntityCollectionResourceType(specialEmployeeType)),
                new ServiceActionParameter("n", ResourceType.GetPrimitiveResourceType(typeof(int))),
            });

            increaseSalariesActionSpecialEmployee.SetReadOnly();
            yield return(increaseSalariesActionSpecialEmployee);

            //
            // Actions with the same name and base/derived type binding parameters
            //
            var updatePersonInfoAction = new ServiceAction(
                "UpdatePersonInfo",
                null,
                null,
                OperationParameterBindingKind.Never,
                null);

            updatePersonInfoAction.SetReadOnly();
            yield return(updatePersonInfoAction);

            var updatePersonInfoActionPerson = new ServiceAction(
                "UpdatePersonInfo",
                null,
                null,
                OperationParameterBindingKind.Sometimes,
                new[]
            {
                new ServiceActionParameter("person", personType),
            });

            updatePersonInfoActionPerson.SetReadOnly();
            yield return(updatePersonInfoActionPerson);

            var updatePersonInfoActionEmployee = new ServiceAction(
                "UpdatePersonInfo",
                null,
                null,
                OperationParameterBindingKind.Sometimes,
                new[]
            {
                new ServiceActionParameter("employee", employeeType),
            });

            updatePersonInfoActionEmployee.SetReadOnly();
            yield return(updatePersonInfoActionEmployee);

            var updatePersonInfoActionSpecialEmployee = new ServiceAction(
                "UpdatePersonInfo",
                null,
                null,
                OperationParameterBindingKind.Sometimes,
                new[]
            {
                new ServiceActionParameter("specialEmployee", specialEmployeeType),
            });

            updatePersonInfoActionSpecialEmployee.SetReadOnly();
            yield return(updatePersonInfoActionSpecialEmployee);

            var updatePersonInfoActionContractor = new ServiceAction(
                "UpdatePersonInfo",
                null,
                null,
                OperationParameterBindingKind.Always,
                new[]
            {
                new ServiceActionParameter("contractor", contractorType),
            });

            updatePersonInfoActionContractor.SetReadOnly();
            yield return(updatePersonInfoActionContractor);

            //
            // Actions with the same name, base/derived type binding parameters, different non-binding parameters
            //
            var increaseEmployeeSalaryActionEmployee = new ServiceAction(
                "IncreaseEmployeeSalary",
                ResourceType.GetPrimitiveResourceType(typeof(bool)),
                null,
                OperationParameterBindingKind.Sometimes,
                new[]
            {
                new ServiceActionParameter("employee", employeeType),
                new ServiceActionParameter("n", ResourceType.GetPrimitiveResourceType(typeof(int))),
            });

            increaseEmployeeSalaryActionEmployee.SetReadOnly();
            yield return(increaseEmployeeSalaryActionEmployee);

            var increaseEmployeeSalaryActionSpecialEmployee = new ServiceAction(
                "IncreaseEmployeeSalary",
                ResourceType.GetPrimitiveResourceType(typeof(int)),
                null,
                OperationParameterBindingKind.Sometimes,
                new[]
            {
                new ServiceActionParameter("specialEmployee", specialEmployeeType),
            });

            increaseEmployeeSalaryActionSpecialEmployee.SetReadOnly();
            yield return(increaseEmployeeSalaryActionSpecialEmployee);
        }
Ejemplo n.º 22
0
 public ODataServiceUpdateProvider(IDataServiceMetadataProvider metadata, ODataServiceQueryProvider <T> query)
 {
     _metadata = metadata;
     _query    = query;
     _actions  = new List <Action>();
 }
Ejemplo n.º 23
0
 /// <summary>Seals this configuration instance and prevents further changes.</summary>
 /// <remarks>
 /// This method should be called after the configuration has been set up and before it's placed on the
 /// metadata cache for sharing.
 /// </remarks>
 internal void Seal()
 {
     Debug.Assert(!this.configurationSealed, "!configurationSealed - otherwise .Seal is invoked multiple times");
     this.configurationSealed = true;
     this.provider            = null;
 }
        /// <summary>
        /// Wrapper methods around metadata provider to get the ResourceSet
        /// </summary>
        /// <param name="metadataProvider">metadata provider</param>
        /// <param name="setName">set name</param>
        /// <returns>a resource set or throws</returns>
        protected ResourceSet GetResourceSet(IDataServiceMetadataProvider metadataProvider, string setName)
        {
            ResourceSet resourceSet = null;

            ProviderImplementationSettings.Override(
               s => s.EnforceMetadataCaching = false,
               () => ExceptionUtilities.Assert(metadataProvider.TryResolveResourceSet(setName, out resourceSet), "Cannot find a resource set '{0}' in the metadata provider", setName));

            return resourceSet;
        }
Ejemplo n.º 25
0
 public ODataServiceQueryProvider(IDataServiceMetadataProvider metadata)
 {
     _metadata = metadata;
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Creates a new ODataMessageWriter for the given request message and writer settings.
        /// </summary>
        /// <param name="requestMessage">The request message for which to create the writer.</param>
        /// <param name="settings">The writer settings to use for writing the message payload.</param>
        /// <param name="metadataProvider">The metadata provider to use.</param>
        public ODataMessageWriter(IODataRequestMessage requestMessage, ODataWriterSettings settings, IDataServiceMetadataProvider metadataProvider)
        {
            ExceptionUtils.CheckArgumentNotNull(requestMessage, "requestMessage");
            ExceptionUtils.CheckArgumentNotNull(settings, "settings");

            ODataVersionChecker.CheckVersionSupported(settings.Version);

            this.writingResponse = false;
            this.message = new ODataRequestMessage(requestMessage);
            this.settings = settings;
            if (metadataProvider != null)
            {
                this.metadataProvider = new DataServiceMetadataProviderWrapper(metadataProvider);
            }
        }
 /// <summary>
 /// Parses the <paramref name="queryUri"/> and binds the query to the metadata provided
 /// then returns a new instance of <see cref="QueryDescriptorQueryNode"/>
 /// describing the query specified by the uri.
 /// </summary>
 /// <param name="queryUri">The absolute URI which holds the query to parse. This must be a path relative to the <paramref name="serviceBaseUri"/>.</param>
 /// <param name="serviceBaseUri">The base URI of the service.</param>
 /// <param name="metadataProvider">The metadata provider to use for binding.</param>
 /// <returns>A new instance of <see cref="QueryDescriptorQueryNode"/> which represents the query specified in the <paramref name="queryUri"/>.</returns>
 public static QueryDescriptorQueryNode ParseUri(Uri queryUri, Uri serviceBaseUri, IDataServiceMetadataProvider metadataProvider)
 {
     return ParseUri(queryUri, serviceBaseUri, metadataProvider, DefaultMaxDepth);
 }
        /// <summary>
        /// Wrapper methods around metadata provider to get the ResourceType
        /// </summary>
        /// <param name="metadataProvider">metadata provider</param>
        /// <param name="typeName">type name</param>
        /// <returns>a resource type or throws</returns>
        protected ResourceType GetResourceType(IDataServiceMetadataProvider metadataProvider, string typeName)
        {
            ResourceType resourceType = null;

            ProviderImplementationSettings.Override(
                s => s.EnforceMetadataCaching = false,
                () => ExceptionUtilities.Assert(metadataProvider.TryResolveResourceType(typeName, out resourceType), "Cannot find a resource type '{0}' in the metadata provider", typeName));

            return resourceType;
        }
Ejemplo n.º 29
0
 public static void ClearData()
 {
     CustomRowBasedContext.PreserveChanges = false;
     provider = null;
     queryProvider = null;
     customers = null;
     orders = null;
     regions = null;
 }
Ejemplo n.º 30
0
 public JsonToAtomUtil(IDataServiceMetadataProvider metadataProvider)
 {
     this.metadataProvider = metadataProvider;
 }
        protected override IEnumerable<ServiceAction> LoadServiceActions(IDataServiceMetadataProvider dataServiceMetadataProvider)
        {
            ResourceType productType;
            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.Product", out productType);

            ResourceType orderLineType;
            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.OrderLine", out orderLineType);

            ResourceType personType;
            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.Person", out personType);

            ResourceType employeeType;
            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.Employee", out employeeType);

            ResourceType specialEmployeeType;
            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.SpecialEmployee", out specialEmployeeType);

            ResourceType contractorType;
            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.Contractor", out contractorType);

            //
            // actions with the same name and non-related binding types
            //
            var RetrieveProductActionProduct = new ServiceAction(
                "RetrieveProduct",
                ResourceType.GetPrimitiveResourceType(typeof(int)),
                null,
                OperationParameterBindingKind.Sometimes,
                new[]
                {
                    new ServiceActionParameter("product", productType), 
                });
            RetrieveProductActionProduct.SetReadOnly();
            yield return RetrieveProductActionProduct;

            var RetrieveProductActionOrderLine = new ServiceAction(
                "RetrieveProduct",
                ResourceType.GetPrimitiveResourceType(typeof(int)),
                null,
                OperationParameterBindingKind.Sometimes,
                new[]
                {
                    new ServiceActionParameter("orderLine", orderLineType), 
                });
            RetrieveProductActionOrderLine.SetReadOnly();
            yield return RetrieveProductActionOrderLine;

            //
            // Collection bound actions with the same name
            //
            var increaseSalariesActionEmployee = new ServiceAction(
                "IncreaseSalaries",
                null,
                null,
                OperationParameterBindingKind.Sometimes,
                new[]
                {
                    new ServiceActionParameter("employees", ResourceType.GetEntityCollectionResourceType(employeeType)),
                    new ServiceActionParameter("n", ResourceType.GetPrimitiveResourceType(typeof(int))),
                });
            increaseSalariesActionEmployee.SetReadOnly();
            yield return increaseSalariesActionEmployee;

            var increaseSalariesActionSpecialEmployee = new ServiceAction(
                "IncreaseSalaries",
                null,
                null,
                OperationParameterBindingKind.Sometimes,
                new[]
                {
                    new ServiceActionParameter("specialEmployees", ResourceType.GetEntityCollectionResourceType(specialEmployeeType)),
                    new ServiceActionParameter("n", ResourceType.GetPrimitiveResourceType(typeof(int))),
                });
            increaseSalariesActionSpecialEmployee.SetReadOnly();
            yield return increaseSalariesActionSpecialEmployee;

            //
            // Actions with the same name and base/derived type binding parameters
            //
            var updatePersonInfoAction = new ServiceAction(
                "UpdatePersonInfo",
                null,
                null,
                OperationParameterBindingKind.Never,
                null);
            updatePersonInfoAction.SetReadOnly();
            yield return updatePersonInfoAction;

            var updatePersonInfoActionPerson = new ServiceAction(
                "UpdatePersonInfo",
                null,
                null,
                OperationParameterBindingKind.Sometimes,
                new[]
                {
                    new ServiceActionParameter("person", personType), 
                });
            updatePersonInfoActionPerson.SetReadOnly();
            yield return updatePersonInfoActionPerson;

            var updatePersonInfoActionEmployee = new ServiceAction(
                "UpdatePersonInfo",
                null,
                null,
                OperationParameterBindingKind.Sometimes,
                new[]
                {
                    new ServiceActionParameter("employee", employeeType), 
                });
            updatePersonInfoActionEmployee.SetReadOnly();
            yield return updatePersonInfoActionEmployee;

            var updatePersonInfoActionSpecialEmployee = new ServiceAction(
                "UpdatePersonInfo",
                null,
                null,
                OperationParameterBindingKind.Sometimes,
                new[]
                {
                    new ServiceActionParameter("specialEmployee", specialEmployeeType), 
                });
            updatePersonInfoActionSpecialEmployee.SetReadOnly();
            yield return updatePersonInfoActionSpecialEmployee;

            var updatePersonInfoActionContractor = new ServiceAction(
                "UpdatePersonInfo",
                null,
                null,
                OperationParameterBindingKind.Always,
                new[]
                {
                    new ServiceActionParameter("contractor", contractorType), 
                });
            updatePersonInfoActionContractor.SetReadOnly();
            yield return updatePersonInfoActionContractor;

            //
            // Actions with the same name, base/derived type binding parameters, different non-binding parameters
            //
            var increaseEmployeeSalaryActionEmployee = new ServiceAction(
                "IncreaseEmployeeSalary",
                ResourceType.GetPrimitiveResourceType(typeof(bool)),
                null,
                OperationParameterBindingKind.Sometimes,
                new[]
                {
                    new ServiceActionParameter("employee", employeeType),
                    new ServiceActionParameter("n", ResourceType.GetPrimitiveResourceType(typeof(int))),
                });
            increaseEmployeeSalaryActionEmployee.SetReadOnly();
            yield return increaseEmployeeSalaryActionEmployee;

            var increaseEmployeeSalaryActionSpecialEmployee = new ServiceAction(
                "IncreaseEmployeeSalary",
                ResourceType.GetPrimitiveResourceType(typeof(int)),
                null,
                OperationParameterBindingKind.Sometimes,
                new[]
                {
                    new ServiceActionParameter("specialEmployee", specialEmployeeType),
                });
            increaseEmployeeSalaryActionSpecialEmployee.SetReadOnly();
            yield return increaseEmployeeSalaryActionSpecialEmployee;
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Initializes a new <see cref="DataServiceConfiguration"/> with
        /// the specified <paramref name="provider"/>.
        /// </summary>
        /// <param name="provider">Non-null provider for this configuration.</param>
        internal DataServiceConfiguration(IDataServiceMetadataProvider provider)
        {
            WebUtil.CheckArgumentNull(provider, "provider");
            this.provider = provider;
            this.resourceRights = new Dictionary<string, EntitySetRights>(EqualityComparer<string>.Default);
            this.serviceOperationRights = new Dictionary<string, ServiceOperationRights>(EqualityComparer<string>.Default);
            this.serviceActionRights = new Dictionary<string, ServiceActionRights>(EqualityComparer<string>.Default);
            this.pageSizes = new Dictionary<string, int>(EqualityComparer<string>.Default);
            this.rightsForUnspecifiedResourceContainer = EntitySetRights.None;
            this.rightsForUnspecifiedServiceOperation = ServiceOperationRights.None;
            this.rightsForUnspecifiedServiceAction = ServiceActionRights.None;
            this.knownTypes = new List<Type>();
            this.maxBatchCount = Int32.MaxValue;
            this.maxChangeSetCount = Int32.MaxValue;
            this.maxExpandCount = Int32.MaxValue;
            this.maxExpandDepth = Int32.MaxValue;
            this.maxResultsPerCollection = Int32.MaxValue;
            this.maxObjectCountOnInsert = Int32.MaxValue;
            this.accessEnabledResourceTypes = new HashSet<string>(EqualityComparer<string>.Default);
            this.dataServiceBehavior = new DataServiceBehavior();

            // default value is true since in V1, we always did the type conversion
            // and this configuration settings was introduced in V2
            this.typeConversion = true;
        }
        protected override IEnumerable <ServiceAction> LoadServiceActions(IDataServiceMetadataProvider dataServiceMetadataProvider)
        {
            ResourceType employeeType;

            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.Employee", out employeeType);
            ResourceType computerDetailType;

            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.ComputerDetail", out computerDetailType);
            ResourceType computerType;

            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.Computer", out computerType);
            ResourceType customerType;

            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer", out customerType);
            ResourceType auditInfoType;

            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.AuditInfo", out auditInfoType);
            ResourceSet computerSet;

            dataServiceMetadataProvider.TryResolveResourceSet("Computer", out computerSet);
            var increaseSalaryAction = new ServiceAction(
                "IncreaseSalaries",
                null,
                null,
                OperationParameterBindingKind.Always,
                new[]
            {
                new ServiceActionParameter("employees", ResourceType.GetEntityCollectionResourceType(employeeType)),
                new ServiceActionParameter("n", ResourceType.GetPrimitiveResourceType(typeof(int))),
            });

            increaseSalaryAction.SetReadOnly();

            yield return(increaseSalaryAction);

            var sackEmployeeAction = new ServiceAction(
                "Sack",
                null,
                null,
                OperationParameterBindingKind.Always,
                new[]
            {
                new ServiceActionParameter("employee", employeeType),
            });

            sackEmployeeAction.SetReadOnly();

            yield return(sackEmployeeAction);

            var getComputerAction = new ServiceAction(
                "GetComputer",
                computerType,
                OperationParameterBindingKind.Always,
                new[]
            {
                new ServiceActionParameter("computer", computerType)
            },
                new ResourceSetPathExpression("computer"));

            getComputerAction.SetReadOnly();

            yield return(getComputerAction);

            var changeCustomerAuditInfoAction = new ServiceAction(
                "ChangeCustomerAuditInfo",
                null,
                null,
                OperationParameterBindingKind.Always,
                new[]
            {
                new ServiceActionParameter("customer", customerType),
                new ServiceActionParameter("auditInfo", auditInfoType),
            });

            changeCustomerAuditInfoAction.SetReadOnly();

            yield return(changeCustomerAuditInfoAction);

            var resetComputerDetailsSpecificationsAction = new ServiceAction(
                "ResetComputerDetailsSpecifications",
                null,
                null,
                OperationParameterBindingKind.Always,
                new[]
            {
                new ServiceActionParameter("computerDetail", computerDetailType),
                new ServiceActionParameter("specifications", ResourceType.GetCollectionResourceType(ResourceType.GetPrimitiveResourceType(typeof(string)))),
                new ServiceActionParameter("purchaseTime", ResourceType.GetPrimitiveResourceType(typeof(DateTimeOffset)))
            });

            resetComputerDetailsSpecificationsAction.SetReadOnly();

            yield return(resetComputerDetailsSpecificationsAction);
        }
Ejemplo n.º 34
0
 public ActionFactory(IDataServiceMetadataProvider metadata)
 {
     _metadata = metadata;
 }
Ejemplo n.º 35
0
 internal void Seal()
 {
     this.configurationSealed = true;
     this.provider = null;
 }
Ejemplo n.º 36
0
 public JsonToAtomUtil(IDataServiceMetadataProvider metadataProvider)
 {
     this.metadataProvider = metadataProvider;
 }
Ejemplo n.º 37
0
 public ReportingQueryProvider(IDataServiceMetadataProvider metadataProvider, ReportingSchema schema)
 {
     this.metadataProvider = metadataProvider;
     this.schema           = schema;
     this.dataSource       = DependencyFactory.CreateReportingDataSource(RbacPrincipal.Current);
 }
Ejemplo n.º 38
0
 internal void Seal()
 {
     this.configurationSealed = true;
     this.provider            = null;
 }
Ejemplo n.º 39
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="metadataProvider">The metadata provider to use for binding.</param>
        public MetadataBinder(IDataServiceMetadataProvider metadataProvider)
        {
            ExceptionUtils.CheckArgumentNotNull(metadataProvider, "metadataProvider");

            this.metadataProvider = new DataServiceMetadataProviderWrapper(metadataProvider);
        }
Ejemplo n.º 40
0
        /// <summary>
        /// Creates the service action parameters for the given action method info.
        /// </summary>
        /// <param name="metadataProvider">An instance of the IDataServiceMetadataProvider.</param>
        /// <param name="actionAttribute">DSPActionAttribute instance for the action.</param>
        /// <param name="actionMethodInfo">MethodInfo for the action.</param>
        /// <returns></returns>
        private static IEnumerable <ServiceActionParameter> GetServiceActionParameters(IDataServiceMetadataProvider metadataProvider, DSPActionAttribute actionAttribute, MethodInfo actionMethodInfo)
        {
            ParameterInfo[] parameterInfos = actionMethodInfo.GetParameters();
            if (actionAttribute.ParameterTypeNames.Length != parameterInfos.Length)
            {
                throw new InvalidOperationException(string.Format("Mismatch parameter count between the DSPActionAttribute and the MethodInfo for the Action '{0}'.", actionMethodInfo.Name));
            }

            for (int idx = 0; idx < parameterInfos.Length; idx++)
            {
                ParameterInfo parameterInfo         = parameterInfos[idx];
                ResourceType  parameterResourceType = DSPActionProvider.GetResourceTypeFromType(metadataProvider, parameterInfo.ParameterType, actionAttribute.ParameterTypeNames[idx]);
                yield return(new ServiceActionParameter(parameterInfo.Name, parameterResourceType));
            }
        }
        /// <summary>
        /// Parses the <paramref name="queryUri"/> and binds the query to the metadata provided
        /// then returns a new instance of <see cref="QueryDescriptorQueryNode"/>
        /// describing the query specified by the uri.
        /// </summary>
        /// <param name="queryUri">The absolute URI which holds the query to parse. This must be a path relative to the <paramref name="serviceBaseUri"/>.</param>
        /// <param name="serviceBaseUri">The base URI of the service.</param>
        /// <param name="metadataProvider">The metadata provider to use for binding.</param>
        /// <param name="maxDepth">The maximum depth of any single query part. Security setting to guard against DoS attacks causing stack overflows and such.</param>
        /// <returns>A new instance of <see cref="QueryDescriptorQueryNode"/> which represents the query specified in the <paramref name="queryUri"/>.</returns>
        public static QueryDescriptorQueryNode ParseUri(Uri queryUri, Uri serviceBaseUri, IDataServiceMetadataProvider metadataProvider, int maxDepth)
        {
            ExceptionUtils.CheckArgumentNotNull(metadataProvider, "metadataProvider");

            QueryDescriptorQueryToken queryDescriptorQueryToken = QueryDescriptorQueryToken.ParseUri(queryUri, serviceBaseUri, maxDepth);
            MetadataBinder metadataBinder = new MetadataBinder(metadataProvider);
            return metadataBinder.BindQuery(queryDescriptorQueryToken);
        }
 /// <summary>
 /// Loads action providers service actions
 /// </summary>
 /// <param name="dataServiceMetadataProvider">Data Service Metadata Provider</param>
 /// <returns>Enumerable of Service Actions</returns>
 protected abstract IEnumerable<ServiceAction> LoadServiceActions(IDataServiceMetadataProvider dataServiceMetadataProvider);
Ejemplo n.º 43
0
 /// <summary>Seals this configuration instance and prevents further changes.</summary>
 /// <remarks>
 /// This method should be called after the configuration has been set up and before it's placed on the
 /// metadata cache for sharing.
 /// </remarks>
 internal void Seal()
 {
     Debug.Assert(!this.configurationSealed, "!configurationSealed - otherwise .Seal is invoked multiple times");
     this.configurationSealed = true;
     this.provider = null;
 }
Ejemplo n.º 44
0
 /// <summary>
 /// Parses the <paramref name="queryUri"/> and binds the query to the metadata provided
 /// then returns a new instance of <see cref="QueryDescriptorQueryNode"/>
 /// describing the query specified by the uri.
 /// </summary>
 /// <param name="queryUri">The absolute URI which holds the query to parse. This must be a path relative to the <paramref name="serviceBaseUri"/>.</param>
 /// <param name="serviceBaseUri">The base URI of the service.</param>
 /// <param name="metadataProvider">The metadata provider to use for binding.</param>
 /// <returns>A new instance of <see cref="QueryDescriptorQueryNode"/> which represents the query specified in the <paramref name="queryUri"/>.</returns>
 public static QueryDescriptorQueryNode ParseUri(Uri queryUri, Uri serviceBaseUri, IDataServiceMetadataProvider metadataProvider)
 {
     return(ParseUri(queryUri, serviceBaseUri, metadataProvider, DefaultMaxDepth));
 }
        protected override IEnumerable<ServiceAction> LoadServiceActions(IDataServiceMetadataProvider dataServiceMetadataProvider)
        {
            ResourceType employeeType;
            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.Employee", out employeeType);
            ResourceType computerDetailType;
            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.ComputerDetail", out computerDetailType);
            ResourceType computerType;          
            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.Computer", out computerType);
            ResourceType customerType;
            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer", out customerType);
            ResourceType auditInfoType;
            dataServiceMetadataProvider.TryResolveResourceType("Microsoft.Test.OData.Services.AstoriaDefaultService.AuditInfo", out auditInfoType);            
            ResourceSet computerSet;
            dataServiceMetadataProvider.TryResolveResourceSet("Computer", out computerSet);
            var increaseSalaryAction = new ServiceAction(
                 "IncreaseSalaries",
                 null,
                 null,
                 OperationParameterBindingKind.Always,
                 new[]
                {
                    new ServiceActionParameter("employees", ResourceType.GetEntityCollectionResourceType(employeeType)),
                    new ServiceActionParameter("n", ResourceType.GetPrimitiveResourceType(typeof(int))),
                });

            increaseSalaryAction.SetReadOnly();

            yield return increaseSalaryAction;

            var sackEmployeeAction = new ServiceAction(
                "Sack",
                null,
                null,
                OperationParameterBindingKind.Always,
                new[]
                {
                    new ServiceActionParameter("employee", employeeType), 
                });

            sackEmployeeAction.SetReadOnly();

            yield return sackEmployeeAction;

            var getComputerAction = new ServiceAction(
                "GetComputer",
                computerType,
                OperationParameterBindingKind.Always,
                new[]
                {
                    new ServiceActionParameter("computer", computerType)
                },
                new ResourceSetPathExpression("computer"));

            getComputerAction.SetReadOnly();

            yield return getComputerAction;
             
            var changeCustomerAuditInfoAction = new ServiceAction(
               "ChangeCustomerAuditInfo",
               null,
               null,
               OperationParameterBindingKind.Always,
               new[]
                {
                
                    new ServiceActionParameter("customer", customerType), 
                    new ServiceActionParameter("auditInfo", auditInfoType),
                });

            changeCustomerAuditInfoAction.SetReadOnly();

            yield return changeCustomerAuditInfoAction;

             var resetComputerDetailsSpecificationsAction = new ServiceAction(
                "ResetComputerDetailsSpecifications",
                null,
                null,
                OperationParameterBindingKind.Always,
                new[]
                {
                    new ServiceActionParameter("computerDetail", computerDetailType), 
                    new ServiceActionParameter("specifications", ResourceType.GetCollectionResourceType(ResourceType.GetPrimitiveResourceType(typeof(string)))),
                    new ServiceActionParameter("purchaseTime", ResourceType.GetPrimitiveResourceType(typeof(DateTimeOffset)))
                });

            resetComputerDetailsSpecificationsAction.SetReadOnly();

            yield return resetComputerDetailsSpecificationsAction;
        }
Ejemplo n.º 46
0
        /// <summary>
        /// Parses the <paramref name="queryUri"/> and binds the query to the metadata provided
        /// then returns a new instance of <see cref="QueryDescriptorQueryNode"/>
        /// describing the query specified by the uri.
        /// </summary>
        /// <param name="queryUri">The absolute URI which holds the query to parse. This must be a path relative to the <paramref name="serviceBaseUri"/>.</param>
        /// <param name="serviceBaseUri">The base URI of the service.</param>
        /// <param name="metadataProvider">The metadata provider to use for binding.</param>
        /// <param name="maxDepth">The maximum depth of any single query part. Security setting to guard against DoS attacks causing stack overflows and such.</param>
        /// <returns>A new instance of <see cref="QueryDescriptorQueryNode"/> which represents the query specified in the <paramref name="queryUri"/>.</returns>
        public static QueryDescriptorQueryNode ParseUri(Uri queryUri, Uri serviceBaseUri, IDataServiceMetadataProvider metadataProvider, int maxDepth)
        {
            ExceptionUtils.CheckArgumentNotNull(metadataProvider, "metadataProvider");

            QueryDescriptorQueryToken queryDescriptorQueryToken = QueryDescriptorQueryToken.ParseUri(queryUri, serviceBaseUri, maxDepth);
            MetadataBinder            metadataBinder            = new MetadataBinder(metadataProvider);

            return(metadataBinder.BindQuery(queryDescriptorQueryToken));
        }