/// <summary> /// Initializes a new instance of the TestDataServiceInvokable class /// </summary> /// <param name="dataServiceInstance">Data Service Instance</param> /// <param name="dataServiceOperationContext">Data Service Operation Context</param> /// <param name="serviceAction">Service Action</param> /// <param name="parameters">Parameters to use</param> public TestDataServiceInvokable(object dataServiceInstance, DataServiceOperationContext dataServiceOperationContext, ServiceAction serviceAction, object[] parameters) { this.dataServiceOperationContext = dataServiceOperationContext; this.dataServiceInstance = dataServiceInstance; this.serviceAction = serviceAction; this.parameters = parameters; }
public void GetQueryStringItemAsksHost() { var host = new DataServiceHost2Simulator(); host.SetQueryStringItem("some-key", "test-value"); DataServiceOperationContext context = new DataServiceOperationContext(host); context.GetQueryStringValue("some-key").Should().Be("test-value"); }
/// <summary> /// Creates a new instance of DataServiceODataWriterEntryArgs /// </summary> /// <param name="entry">ODataEntry instance.</param> /// <param name="entityInstance">Entity instance that is getting serialized.</param> /// <param name="operationContext">DataServiceOperationContext instance.</param> public DataServiceODataWriterEntryArgs(ODataEntry entry, object entityInstance, DataServiceOperationContext operationContext) { Debug.Assert(operationContext != null, "operationContext != null"); this.Entry = entry; this.Instance = entityInstance; this.OperationContext = operationContext; }
/// <summary> /// Creates a new instance of DataServiceODataWriterNavigationLinkArgs. /// </summary> /// <param name="navigationLink">Instance of ODataNavigationLink.</param> /// <param name="operationContext">Instance of DataServiceOperationContext.</param> public DataServiceODataWriterNavigationLinkArgs( ODataNavigationLink navigationLink, DataServiceOperationContext operationContext) { WebUtil.CheckArgumentNull(navigationLink, "navigationLink != null"); Debug.Assert(operationContext != null, "navigationLink != null"); this.NavigationLink = navigationLink; this.OperationContext = operationContext; }
public bool TryResolveServiceAction(DataServiceOperationContext operationContext, string serviceActionName, out ServiceAction serviceAction) { if (this.TryResolveServiceActionCallback != null) { return this.TryResolveServiceActionCallback(operationContext, serviceActionName, out serviceAction); } throw new NotImplementedException(); }
/// <summary> /// Creates a new instance of DataServiceODataWriterFeedArgs /// </summary> /// <param name="feed">ODataFeed instance.</param> /// <param name="results">IEnumerable instance that is getting serialized.</param> /// <param name="operationContext">DataServiceOperationContext instance.</param> public DataServiceODataWriterFeedArgs(ODataFeed feed, IEnumerable results, DataServiceOperationContext operationContext) { WebUtil.CheckArgumentNull(feed, "feed"); Debug.Assert(results != null, "results != null"); Debug.Assert(operationContext != null, "operationContext != null"); this.Feed = feed; this.Results = results; this.OperationContext = operationContext; }
/// <summary> /// Builds up an instance oz <see cref="IDataServiceInvokable"/> for the given <paramref name="serviceAction"/> with the provided <paramref name="parameterTokens"/>. /// </summary> /// <param name="operationContext">The data service operation context instance.</param> /// <param name="serviceAction">The service action to invoke.</param> /// <param name="parameterTokens">The parameter tokens required to invoke the service action.</param> /// <returns>An instance of <see cref="IDataServiceInvokable"/> to invoke the action with.</returns> public IDataServiceInvokable CreateInvokable(DataServiceOperationContext operationContext, ServiceAction serviceAction, object[] parameterTokens) { if (DataServiceOverrides.ActionProvider.CreateInvokableFunc != null) { return DataServiceOverrides.ActionProvider.CreateInvokableFunc(operationContext, serviceAction, parameterTokens); } return new TestDataServiceInvokable(this.dataServiceInstance, operationContext, serviceAction, parameterTokens); }
/// <summary> /// Returns all service actions in the provider. /// </summary> /// <param name="operationContext">operation Context</param> /// <returns>An enumeration of all service actions.</returns> public IEnumerable<ServiceAction> GetServiceActions(DataServiceOperationContext operationContext) { if (DataServiceOverrides.ActionProvider.GetServiceActionsFunc != null) { return DataServiceOverrides.ActionProvider.GetServiceActionsFunc(operationContext); } return this.GetServiceActionsInternal(operationContext); }
public IEnumerable<ServiceAction> GetServiceActionsByBindingParameterType(DataServiceOperationContext operationContext, ResourceType bindingParameterType) { if (this.GetByBindingTypeCallback != null) { return this.GetByBindingTypeCallback(operationContext, bindingParameterType); } throw new NotImplementedException(); }
public IEnumerable<ServiceAction> GetServiceActions(DataServiceOperationContext operationContext) { if (this.GetServiceActionsCallback != null) { return this.GetServiceActionsCallback(operationContext); } throw new NotImplementedException(); }
public string ResolveType(string entitySetName, DataServiceOperationContext operationContext) { if (entitySetName == "CustomerBlobs") { return typeof(CustomerBlob).Name; } else { throw new ArgumentException("Unrecognized entity set name", "entitySetName"); } }
/// <summary> /// Tries to find the <see cref="ServiceAction"/> for the given <paramref name="sericeActionName"/>. /// </summary> /// <param name="operationContext">operation Context</param> /// <param name="serviceActionName">The name of the service action to resolve.</param> /// <param name="serviceAction">Returns the service action instance if the resolution is successful; null otherwise.</param> /// <returns>true if the resolution is successful; false otherwise.</returns> public bool TryResolveServiceAction(DataServiceOperationContext operationContext, string serviceActionName, out ServiceAction serviceAction) { if (DataServiceOverrides.ActionProvider.TryResolveServiceActionFunc != null) { DataServiceOverrides.ActionProvider.TryResolveServiceActionFunc(operationContext, serviceActionName); serviceAction = DataServiceOverrides.ActionProvider.OutServiceActionTryResolveServiceActionFunc(); return DataServiceOverrides.ActionProvider.OutReturnTryResolveServiceActionFunc(); } serviceAction = this.GetServiceActionsInternal(operationContext).SingleOrDefault(sa => sa.Name == serviceActionName); return serviceAction != null; }
internal void AssertDebugStateDuringRequestProcessing(DataServiceOperationContext operationContext) { #if DEBUG // If the current request encounters an exception, there is no guarantee that all the // events will be fired, we skip the debug asserts when that happens. if (!this.SkipDebugAssert) { Debug.Assert(!this.HasDisposedProviderInterfaces, "!this.HasDisposedProviderInterfaces"); Debug.Assert(this.OnStartProcessingRequestInvokeCount > 0, "this.OnStartProcessingRequestInvokeCount > 0"); Debug.Assert(this.ProcessingRequestInvokeCount == 1, "this.ProcessingRequestInvokeCount == 1"); Debug.Assert(this.ProcessedRequestInvokeCount == 0, "this.ProcessedRequestInvokeCount == 0"); Debug.Assert( (this.ProcessingChangesetInvokeCount == 0) || (this.ProcessingChangesetInvokeCount == 1 && operationContext.RequestMessage.HttpVerb.IsChange()), "ProcessingChangesetInvokeCount must be 1 during a CUD request."); } #endif }
public bool TryResolveServiceAction(DataServiceOperationContext context, ServiceActionResolverArgs resolverArgs, out ServiceAction serviceAction) { string actionName = resolverArgs.ServiceActionName; IEnumerable<ServiceAction> possibleMatches = this.GetServiceActions(context).Where(a => a.Name == actionName); if (possibleMatches.Count() == 1) { serviceAction = possibleMatches.Single(); } else if (resolverArgs.BindingType == null) { // unbound action serviceAction = possibleMatches.SingleOrDefault(a => a.BindingParameter == null); } else { serviceAction = possibleMatches.SingleOrDefault(a => a.BindingParameter != null && a.BindingParameter.ParameterType.FullName == resolverArgs.BindingType.FullName); } return serviceAction != null; }
public void Initialize() { this.host = new DataServiceHost2Simulator(); var context = new DataServiceOperationContext(this.host); this.dataServiceSimulator = new DataServiceSimulator { OperationContext = context }; var providerSimulator = new DataServiceProviderSimulator(); DataServiceStaticConfiguration staticConfiguration = new DataServiceStaticConfiguration(this.dataServiceSimulator.Instance.GetType(), providerSimulator); IDataServiceProviderBehavior providerBehavior = DataServiceProviderBehavior.CustomDataServiceProviderBehavior; var resourceType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "SelectTestNamespace", "Fake", false) { CanReflectOnInstanceType = false, IsOpenType = true }; resourceType.AddProperty(new ResourceProperty("Id", ResourcePropertyKind.Key | ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int))) { CanReflectOnInstanceTypeProperty = false }); var resourceSet = new ResourceSet("FakeSet", resourceType); resourceSet.SetReadOnly(); providerSimulator.AddResourceSet(resourceSet); var configuration = new DataServiceConfiguration(providerSimulator); configuration.SetEntitySetAccessRule("*", EntitySetRights.All); var provider = new DataServiceProviderWrapper( new DataServiceCacheItem( configuration, staticConfiguration), providerSimulator, providerSimulator, this.dataServiceSimulator, false); this.dataServiceSimulator.ProcessingPipeline = new DataServiceProcessingPipeline(); this.dataServiceSimulator.Provider = provider; provider.ProviderBehavior = providerBehavior; this.dataServiceSimulator.Configuration = new DataServiceConfiguration(providerSimulator); this.dataServiceSimulator.Configuration.DataServiceBehavior.MaxProtocolVersion = ODataProtocolVersion.V4; this.responseMessageSimulator = new ODataResponseMessageSimulator(); }
public MyDSPInvokableAction(DataServiceOperationContext operationContext, Provider.ServiceAction action, object[] parameters) { this.action = action; this.parameters = parameters; }
/// <summary> /// Determines whether a given <paramref name="serviceAction"/> should be advertised as bindable to the given <paramref name="resourceInstance"/>. /// </summary> /// <param name="operationContext">The data service operation context instance.</param> /// <param name="serviceAction">Service action to be advertised.</param> /// <param name="resourceInstance">Instance of the resource to which the service action is bound.</param> /// <param name="resourceInstanceInFeed">true if the resource instance to be serialized is inside a feed; false otherwise. The value true /// suggests that this method might be called many times during serialization since it will get called once for every resource instance inside /// the feed. If it is an expensive operation to determine whether to advertise the service action for the <paramref name="resourceInstance"/>, /// the provider may choose to always advertise in order to optimize for performance.</param> /// <param name="actionToSerialize">The <see cref="ODataAction"/> to be serialized. The server constructs /// the version passed into this call, which may be replaced by an implementation of this interface. /// This should never be set to null unless returning false.</param> /// <returns>true if the service action should be advertised; false otherwise.</returns> public override bool AdvertiseServiceAction(DataServiceOperationContext operationContext, ServiceAction serviceAction, object resourceInstance, bool resourceInstanceInFeed, ref ODataAction actionToSerialize) { if (SubstituteAdvertiseServiceAction != null) { return SubstituteAdvertiseServiceAction(operationContext, serviceAction, resourceInstance, resourceInstanceInFeed, ref actionToSerialize); } return base.AdvertiseServiceAction(operationContext, serviceAction, resourceInstance, resourceInstanceInFeed, ref actionToSerialize); }
/// <summary> /// Forms an instance of DataServiceODataWriterFeedArgs that contains results. /// </summary> /// <param name="feed">ODataFeed instance.</param> /// <param name="operationContext">DataServicesOperationContext instance.</param> /// <returns>DataServiceODataWriterFeedArgs instance</returns> internal DataServiceODataWriterFeedArgs GetDataServiceODataWriterFeedArgs(ODataFeed feed, DataServiceOperationContext operationContext) { return(new DataServiceODataWriterFeedArgs(feed, this.results, operationContext)); }
public string GetStreamETag(object entity, DataServiceOperationContext operationContext) { return null; }
public Uri GetReadStreamUri(object entity, DataServiceOperationContext operationContext) { return DummyReadStreamUri; }
public string GetStreamContentType(object entity, DataServiceOperationContext operationContext) { return DummyContentType; }
public void DeleteStream(object entity, DataServiceOperationContext operationContext) { throw new NotImplementedException(); }
/// <summary> /// Creates a new instance of DataServiceODataWriterEntryArgs /// </summary> /// <param name="entry">ODataResource instance.</param> /// <param name="entityInstance">Entity instance that is getting serialized.</param> /// <param name="operationContext">DataServiceOperationContext instance.</param> public DataServiceODataWriterEntryArgs(ODataResource entry, object entityInstance, DataServiceOperationContext operationContext) { Debug.Assert(operationContext != null, "operationContext != null"); this.Entry = entry; this.Instance = entityInstance; this.OperationContext = operationContext; }
public override Provider.IDataServiceInvokable CreateInvokable(DataServiceOperationContext operationContext, Provider.ServiceAction serviceAction, object[] parameterTokens) { return new MyDSPInvokableAction(operationContext, serviceAction, parameterTokens); }
public bool AdvertiseServiceAction(DataServiceOperationContext operationContext, ServiceAction serviceAction, object resourceInstance, bool resourceInstanceInFeed, ref ODataAction actionToSerialize) { throw new NotImplementedException(); }
public object Execute(Expression requestExpression, DataServiceOperationContext context) { return CUSTOM_EXE_PROVIDER_INVOKE_RETURN; }
/// <summary> /// Constructs a new instance of DataServicePipelineEventArgs object /// </summary> /// <param name="operationContext">Context for the operation which the current event is fired for.</param> internal DataServiceProcessingPipelineEventArgs(DataServiceOperationContext operationContext) { Debug.Assert(operationContext != null, "operationContext != null"); this.operationContext = operationContext; }
private static DataServiceProviderWrapper CreateProvider(out DataServiceConfiguration config, out DataServiceOperationContext operationContext) { var baseUri = new Uri("http://localhost"); var host = new DataServiceHostSimulator() { AbsoluteServiceUri = baseUri, AbsoluteRequestUri = new Uri(baseUri.AbsoluteUri + "/$metadata", UriKind.Absolute), RequestHttpMethod = "GET", RequestAccept = "application/xml+atom", RequestVersion = "4.0", RequestMaxVersion = "4.0", }; operationContext = new DataServiceOperationContext(host); var dataService = new DataServiceSimulator() { OperationContext = operationContext }; operationContext.InitializeAndCacheHeaders(dataService); DataServiceProviderSimulator providerSimulator = new DataServiceProviderSimulator(); providerSimulator.ContainerNamespace = "MyModel"; providerSimulator.ContainerName = "CustomersContainer"; ResourceType customerEntityType = new ResourceType( typeof(object), ResourceTypeKind.EntityType, null, "MyModel", "Customer", false) { CanReflectOnInstanceType = false }; ResourcePropertyKind idPropertyKind = ResourcePropertyKind.Primitive | ResourcePropertyKind.Key; ResourceProperty idProperty = new ResourceProperty( "Id", idPropertyKind, ResourceType.GetPrimitiveResourceType(typeof(int))) { CanReflectOnInstanceTypeProperty = false }; customerEntityType.AddProperty(idProperty); ResourcePropertyKind firstNamePropertyKind = ResourcePropertyKind.Primitive | ResourcePropertyKind.Key; ResourceProperty firstNameProperty = new ResourceProperty( "FirstName", firstNamePropertyKind, ResourceType.GetPrimitiveResourceType(typeof(string))) { CanReflectOnInstanceTypeProperty = false }; customerEntityType.AddProperty(firstNameProperty); customerEntityType.SetReadOnly(); providerSimulator.AddResourceType(customerEntityType); ResourceSet customerSet = new ResourceSet("Customers", customerEntityType); customerSet.SetReadOnly(); providerSimulator.AddResourceSet(customerSet); config = new DataServiceConfiguration(providerSimulator); config.SetEntitySetAccessRule("*", EntitySetRights.All); config.DataServiceBehavior.MaxProtocolVersion = ODataProtocolVersion.V4; IDataServiceProviderBehavior providerBehavior = DataServiceProviderBehavior.CustomDataServiceProviderBehavior; DataServiceStaticConfiguration staticConfig = new DataServiceStaticConfiguration(dataService.Instance.GetType(), providerSimulator); DataServiceProviderWrapper provider = new DataServiceProviderWrapper( new DataServiceCacheItem(config, staticConfig), providerSimulator, providerSimulator, dataService, false); dataService.ProcessingPipeline = new DataServiceProcessingPipeline(); dataService.Provider = provider; provider.ProviderBehavior = providerBehavior; dataService.ActionProvider = DataServiceActionProviderWrapper.Create(dataService); #if DEBUG dataService.ProcessingPipeline.SkipDebugAssert = true; #endif operationContext.RequestMessage.InitializeRequestVersionHeaders(VersionUtil.ToVersion(config.DataServiceBehavior.MaxProtocolVersion)); return provider; }
/// <summary> /// Creates a new instance of DataServiceODataWriterFeedArgs /// </summary> /// <param name="feed">ODataResourceSet instance.</param> /// <param name="results">IEnumerable instance that is getting serialized.</param> /// <param name="operationContext">DataServiceOperationContext instance.</param> public DataServiceODataWriterFeedArgs(ODataResourceSet resourceCollection, IEnumerable results, DataServiceOperationContext operationContext) { WebUtil.CheckArgumentNull(resourceCollection, "feed"); Debug.Assert(results != null, "results != null"); Debug.Assert(operationContext != null, "operationContext != null"); this.Feed = resourceCollection; this.Results = results; this.OperationContext = operationContext; }
public IDataServiceInvokable CreateInvokable(DataServiceOperationContext operationContext, ServiceAction serviceAction, object[] parameterTokens) { throw new NotImplementedException(); }
private void ValidateArguments(object entity, DataServiceOperationContext operationContext) { if (!SkipValidation) { Type projectedWrapperType = typeof(DataService<>).Assembly.GetType("Microsoft.OData.Service.Internal.ProjectedWrapper"); if (projectedWrapperType.IsAssignableFrom(entity.GetType())) { throw new DataServiceException("Expected ResourceType but received ProjectedWrapper"); } Type entityType = entity.GetType(); if (!typeof(Photo).IsAssignableFrom(entityType) && entityType != typeof(NorthwindModel.Customers) && entityType != typeof(NorthwindModel.Orders) && (entityType != typeof(RowEntityTypeWithIDAsKey) || (((RowEntityTypeWithIDAsKey)entity).TypeName != CustomRowBasedContext.CustomerFullName && ((RowEntityTypeWithIDAsKey)entity).TypeName != CustomRowBasedContext.CustomerWithBirthdayFullName)) && (entityType != typeof(RowComplexType) || (((RowComplexType)entity).TypeName != "AstoriaUnitTests.Stubs.Customer" && ((RowComplexType)entity).TypeName != "AstoriaUnitTests.Stubs.CustomerWithBirthday"))) { throw new DataServiceException(String.Format("Unsupported streaming type '{0}'", entity.GetType().FullName)); } // For PUT to $value or POST requests, the content type of the MR should match if (((operationContext.AbsoluteRequestUri.OriginalString.Contains("$value") && operationContext.RequestMethod.Equals("PUT", StringComparison.OrdinalIgnoreCase)) || operationContext.RequestMethod.Equals("POST", StringComparison.OrdinalIgnoreCase)) && operationContext.RequestHeaders[HttpRequestHeader.ContentType] != GetContentType(entity)) { throw new DataServiceException(String.Format("Incorrect Content-Type header value '{0}', expected '{1}'.", operationContext.RequestHeaders["Content-Type"], GetContentType(entity))); } if (!ValidateCustomRequestHeaders(operationContext)) { throw new DataServiceException("Expected custom request headers not found!"); } } }
/// <summary> /// Forms an instance of DataServiceODataWriterFeedArgs that contains results. /// </summary> /// <param name="feed">ODataResourceSet instance.</param> /// <param name="operationContext">DataServicesOperationContext instance.</param> /// <returns>DataServiceODataWriterFeedArgs instance</returns> internal DataServiceODataWriterFeedArgs GetDataServiceODataWriterFeedArgs(ODataResourceSet resourceCollection, DataServiceOperationContext operationContext) { return(new DataServiceODataWriterFeedArgs(resourceCollection, this.results, operationContext)); }
private static bool ValidateCustomRequestHeaders(DataServiceOperationContext operationContext) { string customHeader1 = operationContext.RequestHeaders["CustomRequestHeader1"]; string customHeader2 = operationContext.RequestHeaders["CustomRequestHeader2"]; if (customHeader1 == "CustomRequestHeaderValue1" && customHeader2 == "CustomRequestHeaderValue2") { return true; } return false; }
/// <summary> /// Resolves the entity type for a POST MR operation. /// </summary> /// <param name="entitySetName">named of the entity set for the POST operation</param> /// <param name="operationContext">operation context instance</param> /// <returns>fully qualified entity type name to be created. May be null if the type hierarchy only contains 1 type or does not contain any MLE type</returns> protected override string ResolveTypeInternal(string entitySetName, DataServiceOperationContext operationContext) { string typeName = operationContext.RequestHeaders[ResolveTypeHeaderName]; if (!string.IsNullOrEmpty(typeName)) { return typeName; } ResourceSet resourceSet; if (!DSPServiceDefinition.Current.Metadata.TryResolveResourceSet(entitySetName, out resourceSet)) { throw new InvalidOperationException("Invalid set name: '" + entitySetName + "'"); } ResourceType rootType = resourceSet.ResourceType; List<ResourceType> typeHierarchy = new List<ResourceType>(); typeHierarchy.Add(rootType); typeHierarchy.AddRange(DSPServiceDefinition.Current.Metadata.GetDerivedTypes(rootType)); return typeHierarchy.Single(t => t.IsMediaLinkEntry).FullName; }
private void SetCustomResponseHeaders(DataServiceOperationContext operationContext) { operationContext.ResponseHeaders["CustomResponseHeader1"] = "CustomResponseHeaderValue1"; operationContext.ResponseHeaders["CustomResponseHeader2"] = "CustomResponseHeaderValue2"; bool seenHeader1 = false; bool seenHeader2 = false; foreach (string responseHeader in operationContext.ResponseHeaders.AllKeys) { if (responseHeader == "CustomResponseHeader1") { seenHeader1 = true; if (operationContext.ResponseHeaders[responseHeader] != "CustomResponseHeaderValue1") { throw new DataServiceException("Invalid value for CustomResponseHeader1."); } } else if (responseHeader == "CustomResponseHeader2") { seenHeader2 = true; if (operationContext.ResponseHeaders[responseHeader] != "CustomResponseHeaderValue2") { throw new DataServiceException("Invalid value for CustomResponseHeader2."); } } } if (!seenHeader1 || !seenHeader2) { throw new DataServiceException("CustomResponseHeader1 or CustomResponseHeader2 is not set."); } }
public Stream GetWriteStream(object entity, string etag, bool? checkETagForEquality, DataServiceOperationContext operationContext) { throw new NotImplementedException(); }
/// <summary>Initalizes a new <see cref="ProcessRequestArgs"/> instance.</summary> /// <param name="operationContext">Context about the current operation being processed.</param> internal ProcessRequestArgs(DataServiceOperationContext operationContext) { this.OperationContext = operationContext; }