예제 #1
0
 internal void AddOperation(OperationWrapper operation)
 {
     if (this.FindOperation(operation.Name) == null)
     {
         this.operations.Add(operation);
     }
 }
예제 #2
0
        public IEnumerable <OperationWrapper> GetVisibleOperations(DataServiceOperationContext operationContext)
        {
            HashSet <string> names = new HashSet <string>(EqualityComparer <string> .Default);
            IEnumerable <ServiceOperation> serviceOperations = this.metadataProvider.ServiceOperations;

            if (serviceOperations != null)
            {
                foreach (ServiceOperation iteratorVariable2 in serviceOperations)
                {
                    AddUniqueNameToSet((iteratorVariable2 != null) ? iteratorVariable2.Name : null, names, System.Data.Services.Strings.DataServiceProviderWrapper_MultipleServiceOperationsWithSameName(iteratorVariable2.Name));
                    OperationWrapper iteratorVariable3 = this.ValidateOperation(iteratorVariable2);
                    if (iteratorVariable3 != null)
                    {
                        yield return(iteratorVariable3);
                    }
                }
            }
            IEnumerator <OperationWrapper>  enumerator = this.dataService.ActionProvider.GetServiceActions(operationContext).GetEnumerator();
            Func <ResourceSetWrapper, bool> predicate  = null;
            OperationWrapper serviceAction;

            while (enumerator.MoveNext())
            {
                serviceAction = enumerator.Current;
                AddUniqueNameToSet(serviceAction.Name, names, System.Data.Services.Strings.DataServiceProviderWrapper_MultipleServiceOperationsWithSameName(serviceAction.Name));
                List <ResourceSetWrapper> source = new List <ResourceSetWrapper>();
                if (serviceAction.BindingParameter != null)
                {
                    ResourceType subType = serviceAction.BindingParameter.ParameterType;
                    if (subType.ResourceTypeKind == ResourceTypeKind.EntityCollection)
                    {
                        subType = ((EntityCollectionResourceType)subType).ItemType;
                    }
                    foreach (ResourceSetWrapper wrapper in this.GetResourceSets())
                    {
                        if (wrapper.ResourceType.IsAssignableFrom(subType))
                        {
                            source.Add(wrapper);
                        }
                    }
                    if (source.Count <ResourceSetWrapper>() == 0)
                    {
                        throw new InvalidOperationException(System.Data.Services.Strings.DataServiceProviderWrapper_ActionHasNoBindableSet(serviceAction.Name, serviceAction.BindingParameter.ParameterType.FullName));
                    }
                }
                if (serviceAction.ResultSetPathExpression != null)
                {
                    if (predicate == null)
                    {
                        predicate = set => serviceAction.ResultSetPathExpression.GetTargetSet(this, set) != null;
                    }
                    if (!source.Any <ResourceSetWrapper>(predicate))
                    {
                        throw new InvalidOperationException(System.Data.Services.Strings.DataServiceProviderWrapper_ActionHasNoVisibleSetReachableFromPathExpression(serviceAction.Name, serviceAction.ResultSetPathExpression.PathExpression));
                    }
                }
                yield return(serviceAction);
            }
        }
        internal MetadataProviderEdmFunctionImport(MetadataProviderEdmModel model, MetadataProviderEdmEntityContainer container, OperationWrapper operation)
        {
            this.container = container;
            this.model     = model;
            this.operation = operation;
            if (operation.Kind == OperationKind.Action)
            {
                this.isSideEffecting = true;
                this.isComposable    = false;
                this.isBindable      = this.operation.BindingParameter != null;
            }
            else
            {
                this.isComposable    = false;
                this.isSideEffecting = true;
                this.isBindable      = false;
            }
            ResourceSetPathExpression resultSetPathExpression = operation.ResultSetPathExpression;

            this.entitySetPath = (resultSetPathExpression == null) ? null : resultSetPathExpression.PathExpression;
            if (operation.Kind == OperationKind.ServiceOperation)
            {
                model.SetHttpMethod(this, operation.Method);
            }
            string mimeType = operation.MimeType;

            if (!string.IsNullOrEmpty(mimeType))
            {
                model.SetMimeType(this, mimeType);
            }
            if (operation.OperationParameterBindingKind == OperationParameterBindingKind.Always)
            {
                model.SetIsAlwaysBindable(this, true);
            }
            ReadOnlyCollection <OperationParameter> parameters = operation.Parameters;

            if ((parameters != null) && (parameters.Count > 0))
            {
                List <IEdmFunctionParameter> list = new List <IEdmFunctionParameter>(parameters.Count);
                foreach (OperationParameter parameter in parameters)
                {
                    IEdmTypeReference typeReference = this.model.EnsureTypeReference(parameter.ParameterType, null);
                    if (!typeReference.IsNullable && (this.model.GetEdmVersion() < DataServiceProtocolVersion.V3.ToVersion()))
                    {
                        typeReference = typeReference.Clone(true);
                    }
                    EdmFunctionParameter item = new EdmFunctionParameter(this, parameter.Name, typeReference, EdmFunctionParameterMode.In);
                    list.Add(item);
                }
                this.parameters = new ReadOnlyCollection <IEdmFunctionParameter>(list);
            }
        }
 internal MetadataProviderEdmFunctionImport(MetadataProviderEdmModel model, MetadataProviderEdmEntityContainer container, OperationWrapper operation)
 {
     this.container = container;
     this.model = model;
     this.operation = operation;
     if (operation.Kind == OperationKind.Action)
     {
         this.isSideEffecting = true;
         this.isComposable = false;
         this.isBindable = this.operation.BindingParameter != null;
     }
     else
     {
         this.isComposable = false;
         this.isSideEffecting = true;
         this.isBindable = false;
     }
     ResourceSetPathExpression resultSetPathExpression = operation.ResultSetPathExpression;
     this.entitySetPath = (resultSetPathExpression == null) ? null : resultSetPathExpression.PathExpression;
     if (operation.Kind == OperationKind.ServiceOperation)
     {
         model.SetHttpMethod(this, operation.Method);
     }
     string mimeType = operation.MimeType;
     if (!string.IsNullOrEmpty(mimeType))
     {
         model.SetMimeType(this, mimeType);
     }
     if (operation.OperationParameterBindingKind == OperationParameterBindingKind.Always)
     {
         model.SetIsAlwaysBindable(this, true);
     }
     ReadOnlyCollection<OperationParameter> parameters = operation.Parameters;
     if ((parameters != null) && (parameters.Count > 0))
     {
         List<IEdmFunctionParameter> list = new List<IEdmFunctionParameter>(parameters.Count);
         foreach (OperationParameter parameter in parameters)
         {
             IEdmTypeReference typeReference = this.model.EnsureTypeReference(parameter.ParameterType, null);
             if (!typeReference.IsNullable && (this.model.GetEdmVersion() < DataServiceProtocolVersion.V3.ToVersion()))
             {
                 typeReference = typeReference.Clone(true);
             }
             EdmFunctionParameter item = new EdmFunctionParameter(this, parameter.Name, typeReference, EdmFunctionParameterMode.In);
             list.Add(item);
         }
         this.parameters = new ReadOnlyCollection<IEdmFunctionParameter>(list);
     }
 }
예제 #5
0
        public ConstantExpression InvokeServiceOperation(OperationWrapper serviceOperation, object[] parameters)
        {
            ConstantExpression expression;

            try
            {
                expression = Expression.Constant(this.queryProvider.InvokeServiceOperation(serviceOperation.ServiceOperation, parameters));
            }
            catch (TargetInvocationException exception)
            {
                ErrorHandler.HandleTargetInvocationException(exception);
                throw;
            }
            return(expression);
        }
 internal IEdmFunctionImport EnsureFunctionImport(OperationWrapper serviceOperation)
 {
     List<MetadataProviderEdmFunctionImport> list;
     string name = serviceOperation.Name;
     if (!this.functionImportCache.TryGetValue(name, out list))
     {
         list = new List<MetadataProviderEdmFunctionImport>();
         this.functionImportCache.Add(name, list);
     }
     MetadataProviderEdmFunctionImport item = list.Find(f => f.ServiceOperation == serviceOperation);
     if (item == null)
     {
         item = new MetadataProviderEdmFunctionImport(this.model, this, serviceOperation);
         list.Add(item);
     }
     return item;
 }
예제 #7
0
 public IEnumerable <OperationWrapper> GetServiceActions(DataServiceOperationContext operationContext)
 {
     if (this.TryLoadActionProvider())
     {
         IEnumerable <ServiceAction> serviceActions = this.actionProvider.GetServiceActions(operationContext);
         if (serviceActions != null)
         {
             foreach (ServiceAction iteratorVariable1 in serviceActions)
             {
                 OperationWrapper iteratorVariable2 = this.dataService.Provider.ValidateOperation(iteratorVariable1);
                 if (iteratorVariable2 != null)
                 {
                     yield return(iteratorVariable2);
                 }
             }
         }
     }
 }
예제 #8
0
        private IEnumerable <ResourceType> GetReachableComplexTypesFromOperation(OperationWrapper operation, HashSet <ResourceType> visitedTypes)
        {
            List <ResourceType> iteratorVariable0 = new List <ResourceType>();

            if ((operation.ResultType != null) && (operation.ResultType.ResourceTypeKind == ResourceTypeKind.ComplexType))
            {
                iteratorVariable0.Add(operation.ResultType);
            }
            iteratorVariable0.AddRange(from p in operation.Parameters
                                       where p.ParameterType.ResourceTypeKind == ResourceTypeKind.ComplexType
                                       select p.ParameterType);
            foreach (ResourceType iteratorVariable1 in iteratorVariable0)
            {
                foreach (ResourceType iteratorVariable2 in this.GetResourceTypeAndReachableComplexTypes(iteratorVariable1, visitedTypes))
                {
                    yield return(iteratorVariable2);
                }
            }
        }
        internal IEdmFunctionImport EnsureFunctionImport(OperationWrapper serviceOperation)
        {
            List <MetadataProviderEdmFunctionImport> list;
            string name = serviceOperation.Name;

            if (!this.functionImportCache.TryGetValue(name, out list))
            {
                list = new List <MetadataProviderEdmFunctionImport>();
                this.functionImportCache.Add(name, list);
            }
            MetadataProviderEdmFunctionImport item = list.Find(f => f.ServiceOperation == serviceOperation);

            if (item == null)
            {
                item = new MetadataProviderEdmFunctionImport(this.model, this, serviceOperation);
                list.Add(item);
            }
            return(item);
        }
예제 #10
0
        internal OperationWrapper ValidateOperation(Operation operation)
        {
            OperationWrapper wrapper = null;

            if (operation != null)
            {
                if (this.OperationWrapperCache.TryGetValue(operation.Name, out wrapper))
                {
                    return(wrapper);
                }
                wrapper = new OperationWrapper(operation);
                wrapper.ApplyConfiguration(this.Configuration, this);
                if (!wrapper.IsVisible)
                {
                    wrapper = null;
                }
                this.OperationWrapperCache[operation.Name] = wrapper;
            }
            return(wrapper);
        }
예제 #11
0
 private static object[] ReadOperationParameters(DataServiceHostWrapper host, OperationWrapper operation)
 {
     object[] objArray = new object[operation.Parameters.Count];
     for (int i = 0; i < operation.Parameters.Count; i++)
     {
         Type instanceType = operation.Parameters[i].ParameterType.InstanceType;
         string queryStringItem = host.GetQueryStringItem(operation.Parameters[i].Name);
         Type underlyingType = Nullable.GetUnderlyingType(instanceType);
         if (string.IsNullOrEmpty(queryStringItem))
         {
             WebUtil.CheckSyntaxValid(instanceType.IsClass || (underlyingType != null));
             objArray[i] = null;
         }
         else
         {
             queryStringItem = queryStringItem.Trim();
             Type type = underlyingType ?? instanceType;
             if (WebConvert.IsKeyTypeQuoted(type))
             {
                 WebUtil.CheckSyntaxValid(WebConvert.IsKeyValueQuoted(queryStringItem));
             }
             WebUtil.CheckSyntaxValid(WebConvert.TryKeyStringToPrimitive(queryStringItem, type, out objArray[i]));
         }
     }
     return objArray;
 }
예제 #12
0
 private static System.Data.Services.SegmentInfo CreateSegmentForServiceAction(System.Data.Services.SegmentInfo previousSegment, OperationWrapper serviceAction, IDataService service, string identifier, string queryPortion)
 {
     System.Data.Services.SegmentInfo info = new System.Data.Services.SegmentInfo {
         Identifier = identifier,
         Operation = serviceAction
     };
     if ((previousSegment != null) && (previousSegment.TargetKind == RequestTargetKind.Link))
     {
         throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestUriProcessor_LinkSegmentMustBeFollowedByEntitySegment(identifier, "$links"));
     }
     if ((previousSegment != null) && Deserializer.IsCrossReferencedSegment(previousSegment, service))
     {
         throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestUriProcessor_BatchedActionOnEntityCreatedInSameChangeset(identifier));
     }
     info.TargetSource = RequestTargetSource.ServiceOperation;
     if (service.OperationContext.RequestMethod != serviceAction.Method)
     {
         throw DataServiceException.CreateMethodNotAllowed(System.Data.Services.Strings.RequestUriProcessor_MethodNotAllowed, serviceAction.Method);
     }
     if ((queryPortion != null) && !string.IsNullOrEmpty(RemoveFilterParens(queryPortion)))
     {
         throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestUriProcessor_SegmentDoesNotSupportKeyPredicates(identifier));
     }
     if (serviceAction.ResultKind != ServiceOperationResultKind.Void)
     {
         info.TargetContainer = serviceAction.GetResultSet(service.Provider, (previousSegment == null) ? null : previousSegment.TargetContainer);
         info.TargetResourceType = serviceAction.ReturnType;
         info.TargetKind = TargetKindFromType(info.TargetResourceType);
         if ((info.TargetKind == RequestTargetKind.Resource) && (info.TargetContainer == null))
         {
             throw DataServiceException.CreateForbidden();
         }
         info.SingleResult = serviceAction.ResultKind == ServiceOperationResultKind.DirectValue;
     }
     else
     {
         info.TargetContainer = null;
         info.TargetResourceType = null;
         info.TargetKind = RequestTargetKind.VoidOperation;
     }
     RequestQueryProcessor.CheckEmptyQueryArguments(service, false);
     return info;
 }
예제 #13
0
 internal static void CheckServiceOperationRights(OperationWrapper operation, ServiceOperationRights requiredRights)
 {
     ServiceOperationRights serviceOperationRights = operation.ServiceOperationRights;
     if ((requiredRights & serviceOperationRights) == ServiceOperationRights.None)
     {
         throw DataServiceException.CreateForbidden();
     }
 }
예제 #14
0
 internal static void CheckServiceOperationRights(OperationWrapper operation, bool singleResult)
 {
     if (operation.ResultKind != ServiceOperationResultKind.Void)
     {
         ServiceOperationRights requiredRights = singleResult ? ServiceOperationRights.ReadSingle : ServiceOperationRights.ReadMultiple;
         CheckServiceOperationRights(operation, requiredRights);
     }
 }
 public Expression CreateInvokable(DataServiceOperationContext operationContext, OperationWrapper serviceAction, Expression[] parameterTokens)
 {
     return Expression.Call(DataServiceExecutionProviderMethods.CreateServiceActionInvokableMethodInfo, Expression.Constant(operationContext, typeof(DataServiceOperationContext)), Expression.Constant(this.ActionProvider, typeof(IDataServiceActionProvider)), Expression.Constant(serviceAction.ServiceAction, typeof(ServiceAction)), Expression.NewArrayInit(typeof(object), parameterTokens));
 }
 public bool AdvertiseServiceAction(DataServiceOperationContext operationContext, OperationWrapper serviceAction, object resourceInstance, bool resourceInstanceInFeed, ref ODataAction actionToSerialize)
 {
     return this.ActionProvider.AdvertiseServiceAction(operationContext, serviceAction.ServiceAction, resourceInstance, resourceInstanceInFeed, ref actionToSerialize);
 }
 protected IEdmFunctionImport GetFunctionImport(OperationWrapper serviceOperation)
 {
     return base.Service.Provider.GetMetadataProviderEdmModel(base.Service.OperationContext).EnsureDefaultEntityContainer().EnsureFunctionImport(serviceOperation);
 }
예제 #18
0
 public Expression CreateInvokable(DataServiceOperationContext operationContext, OperationWrapper serviceAction, Expression[] parameterTokens)
 {
     return(Expression.Call(DataServiceExecutionProviderMethods.CreateServiceActionInvokableMethodInfo, Expression.Constant(operationContext, typeof(DataServiceOperationContext)), Expression.Constant(this.ActionProvider, typeof(IDataServiceActionProvider)), Expression.Constant(serviceAction.ServiceAction, typeof(ServiceAction)), Expression.NewArrayInit(typeof(object), parameterTokens)));
 }
예제 #19
0
 public bool AdvertiseServiceAction(DataServiceOperationContext operationContext, OperationWrapper serviceAction, object resourceInstance, bool resourceInstanceInFeed, ref ODataAction actionToSerialize)
 {
     return(this.ActionProvider.AdvertiseServiceAction(operationContext, serviceAction.ServiceAction, resourceInstance, resourceInstanceInFeed, ref actionToSerialize));
 }