private Expression BindSingleResourceCastFunctionCall(SingleResourceFunctionCallNode node) { Contract.Assert(ClrCanonicalFunctions.CastFunctionName == node.Name); Expression[] arguments = BindArguments(node.Parameters); Contract.Assert(arguments.Length == 2); string targetEdmTypeName = (string)((ConstantNode)node.Parameters.Last()).Value; IEdmType targetEdmType = Model.FindType(targetEdmTypeName); Type targetClrType = null; if (targetEdmType != null) { targetClrType = EdmLibHelpers.GetClrType(targetEdmType.ToEdmTypeReference(false), Model); } if (arguments[0].Type == targetClrType) { // We only support to cast Entity type to the same type now. return(arguments[0]); } else if (arguments[0].Type.IsAssignableFrom(targetClrType)) { // To support to cast Entity/Complex type to the sub type now. Expression source = BindCastSourceNode(node.Source); return(Expression.TypeAs(source, targetClrType)); } else { // Cast fails and return null. return(NullConstant); } }
public Object ParseAsync(HttpResponseMessage response) { using (Stream stream = response.Content.ReadAsStreamAsync().Result) { var responseMessage = new ODataResponseMessage(stream); var context = new ODataDeserializerContext() { Model = Model, Request = response.RequestMessage }; using (var messageReader = new ODataMessageReader(responseMessage, _settings, Model)) { ODataResult result = GetODataResult(messageReader); while (result.ODataReader.Read()) { if (result.ODataReader.State == ODataReaderState.EntryEnd) { var entry = (ODataEntry)result.ODataReader.Item; var entityType = (IEdmEntityType)Model.FindType(entry.TypeName); var entityTypeReference = new EdmEntityTypeReference(entityType, false); var navigationLinks = new ODataEntryWithNavigationLinks(entry); result.AddResult(_deserializer.ReadEntry(navigationLinks, entityTypeReference, context)); } } return(result.Result); } } }
public ParserExtModel() { Person = (IEdmEntityType)Model.FindType("TestNS.Person"); Pet = Model.FindType("TestNS.Pet"); Fish = Model.FindType("TestNS.Fish"); People = Model.FindDeclaredEntitySet("People"); PetSet = Model.FindDeclaredEntitySet("PetSet"); }
public SchoolModel() { Student = (IEdmEntityType)Model.FindType("Microsoft.OData.SampleService.Models.School.Student"); Course = (IEdmEntityType)Model.FindType("Microsoft.OData.SampleService.Models.School.Course"); Teacher = (IEdmEntityType)Model.FindType("Microsoft.OData.SampleService.Models.School.Teacher"); StudentSet = Model.FindDeclaredEntitySet("Students"); CourseSet = Model.FindDeclaredEntitySet("Courses"); TeacherSet = Model.FindDeclaredEntitySet("Teachers"); }
static StoreModel() { var builder = new ODataConventionModelBuilder(); builder.Namespace = "Microsoft.Restier.WebApi.Test"; builder.EntitySet <Product>("Products"); builder.Function("GetBestProduct").ReturnsFromEntitySet <Product>("Products"); builder.Action("RemoveWorstProduct").ReturnsFromEntitySet <Product>("Products"); Model = (EdmModel)builder.GetEdmModel(); Product = (IEdmEntityType)Model.FindType("Microsoft.Restier.WebApi.Test.Product"); }
static StoreModel() { var builder = new ODataConventionModelBuilder { Namespace = "Microsoft.Restier.Tests.AspNet" }; builder.EntitySet <Product>("Products"); builder.EntitySet <Customer>("Customers"); builder.EntitySet <Store>("Stores"); builder.Function("GetBestProduct").ReturnsFromEntitySet <Product>("Products"); builder.Action("RemoveWorstProduct").ReturnsFromEntitySet <Product>("Products"); Model = (EdmModel)builder.GetEdmModel(); Product = (IEdmEntityType)Model.FindType("Microsoft.Restier.Tests.AspNet.Product"); }
private Expression BindSingleResourceCastFunctionCall(SingleResourceFunctionCallNode node) { Contract.Assert(ClrCanonicalFunctions.CastFunctionName == node.Name); Expression[] arguments = BindArguments(node.Parameters); Contract.Assert(arguments.Length == 2); string targetEdmTypeName = (string)((ConstantNode)node.Parameters.Last()).Value; IEdmType targetEdmType = Model.FindType(targetEdmTypeName); Type targetClrType = null; if (targetEdmType != null) { targetClrType = Model.GetClrType(targetEdmType.ToEdmTypeReference(false)); } if (arguments[0].Type == targetClrType) { // We only support to cast Entity type to the same type now. return(arguments[0]); } else if (arguments[0].Type.IsAssignableFrom(targetClrType)) { // To support to cast Entity/Complex type to the sub type now. Expression source; if (node.Source != null) { source = BindCastSourceNode(node.Source); } else { // if the cast is on the root i.e $it (~/Products?$filter=NS.PopularProducts/.....), // node.Source would be null. Calling BindCastSourceNode will always return '$it'. // In scenarios where we are casting a navigation property to return an expression that queries against the parent property, // we need to have a memberAccess expression e.g '$it.Category'. We can get this from arguments[0]. source = arguments[0]; } return(Expression.TypeAs(source, targetClrType)); } else { // Cast fails and return null. return(NullConstant); } }
public override void ResolveTypes(CompileContext context, Model.Scope enclosingScope) { _struct = enclosingScope.FindType(typeName); if (_struct == null) { CachedFetchToken = Constant(0); context.ReportError(this, "Could not find type " + typeName); } else if (_struct.size == 0) { throw new InternalError("Struct size must be determined before types are resolved."); } else CachedFetchToken = Constant((ushort)_struct.size); ResultType = "word"; }
public void PostDeleteTypeInReferencingModel() { var entryWrapper = CreateVehicleGPS(true); #region Create and Delete var settings = new ODataMessageWriterSettings(); settings.BaseUri = ServiceBaseUri; var vehicleGPSType = Model.FindType(TestModelNameSpace + ".GPS.VehicleGPSType") as IEdmEntityType; var vehicleGPSSet = Model.FindEntityContainer(TestModelNameSpace + ".GPS.GPSContainer").FindEntitySet("VehicleGPSSetInGPS"); foreach (var mimeType in mimeTypes) { var requestMessage = new HttpWebRequestMessage(new Uri(ServiceBaseUri + "VehicleGPSSetInGPS")); requestMessage.SetHeader("Content-Type", mimeType); requestMessage.SetHeader("Accept", mimeType); requestMessage.Method = "POST"; using (var messageWriter = new ODataMessageWriter(requestMessage, settings, Model)) { var odataWriter = messageWriter.CreateODataResourceWriter(vehicleGPSSet, vehicleGPSType); ODataWriterHelper.WriteResource(odataWriter, entryWrapper); } // send the http request var responseMessage = requestMessage.GetResponse(); // Verify Created Assert.AreEqual(201, responseMessage.StatusCode); ODataResource entry = this.QueryEntityItem("VehicleGPSSetInGPS('000')") as ODataResource; Assert.AreEqual("000", entry.Properties.Single(p => p.Name == "Key").Value); // Delete the entry var deleteRequestMessage = new HttpWebRequestMessage(new Uri(ServiceBaseUri + "VehicleGPSSetInGPS('000')")); deleteRequestMessage.Method = "DELETE"; var deleteResponseMessage = deleteRequestMessage.GetResponse(); // Verift Deleted Assert.AreEqual(204, deleteResponseMessage.StatusCode); ODataResource deletedEntry = this.QueryEntityItem("VehicleGPSSetInGPS('000')", 204) as ODataResource; Assert.IsNull(deletedEntry); } #endregion }
/// <inheritdoc /> public IEdmTypeReference GetEdmType() { if (InstanceType != null) { IEdmStructuredType structuredType = Model.FindType(InstanceType) as IEdmStructuredType; IEdmEntityType entityType = structuredType as IEdmEntityType; if (entityType != null) { return(entityType.ToEdmTypeReference(true)); } return(structuredType.ToEdmTypeReference(true)); } Type elementType = GetElementType(); return(Model.GetTypeMappingCache().GetEdmType(elementType, Model)); }
public override void ResolveTypes(CompileContext context, Model.Scope enclosingScope) { _struct = enclosingScope.FindType(typeName); if (_struct == null) { context.ReportError(this, "Could not find type " + typeName); CachedFetchToken = Constant(0); } else { var memberIndex = _struct.members.FindIndex(m => m.name == memberName); if (memberIndex < 0) { context.ReportError(this, "Member not found : " + memberName); CachedFetchToken = Constant(0); } else CachedFetchToken = Constant((ushort)memberIndex); } ResultType = "word"; }
public TripPinModel() { Person = (IEdmEntityType)Model.FindType("Microsoft.OData.SampleService.Models.TripPin.Person"); Trip = (IEdmEntityType)Model.FindType("Microsoft.OData.SampleService.Models.TripPin.Trip"); PeopleSet = Model.FindDeclaredEntitySet("People"); }
public V4Model() { Product = (IEdmEntityType)Model.FindType("ODataDemo.Product"); Supplier = (IEdmEntityType)Model.FindType("ODataDemo.Supplier"); ProductsSet = Model.FindDeclaredEntitySet("Products"); }
public void PostDeleteTypeInReferencdModel() { #region New Entry ODataEntry newVehicleGPS = new ODataEntry { TypeName = TestModelNameSpace + ".GPS.VehicleGPSType" }; newVehicleGPS.Properties = new[] { new ODataProperty { Name = "Key", Value = "000" }, new ODataProperty { Name = "VehicleSpeed", Value = 999.9 }, new ODataProperty { Name = "StartLocation", Value = new ODataComplexValue { TypeName = TestModelNameSpace + ".Location.GeoLocation", Properties = new[] { new ODataProperty { Name = "Lat", Value = 99.9 }, new ODataProperty { Name = "Long", Value = 88.8 } } } }, new ODataProperty { Name = "EndLocation", Value = new ODataComplexValue { TypeName = TestModelNameSpace + ".Location.GeoLocation", Properties = new[] { new ODataProperty { Name = "Lat", Value = 77.7 }, new ODataProperty { Name = "Long", Value = 88.8 } } } }, new ODataProperty { Name = "CurrentLocation", Value = new ODataComplexValue { TypeName = TestModelNameSpace + ".Location.GeoLocation", Properties = new[] { new ODataProperty { Name = "Lat", Value = 88.8 }, new ODataProperty { Name = "Long", Value = 88.8 } } } }, new ODataProperty { Name = "Map", Value = new ODataComplexValue { TypeName = TestModelNameSpace + ".Map.MapType", Properties = new[] { new ODataProperty { Name = "ProviderName", Value = "ProviderNew" }, new ODataProperty { Name = "Uri", Value = "NewUri" }, new ODataProperty { Name = "MBytesDownloaded", Value = 12.3 } } } }, new ODataProperty { Name = "LostSignalAlarm", Value = new ODataComplexValue { TypeName = TestModelNameSpace + ".GPS.GPSLostSignalAlarmType", Properties = new[] { new ODataProperty { Name = "Severity", Value = 1 }, new ODataProperty { Name = "LastKnownLocation", Value = new ODataComplexValue { TypeName = TestModelNameSpace + ".Location.GeoLocation", Properties = new[] { new ODataProperty { Name = "Lat", Value = 88.8 }, new ODataProperty { Name = "Long", Value = 88.8 } } } }, } } } }; #endregion #region Create and Delete var settings = new ODataMessageWriterSettings(); settings.PayloadBaseUri = ServiceBaseUri; var vehicleGPSType = Model.FindType(TestModelNameSpace + ".GPS.VehicleGPSType") as IEdmEntityType; var vehicleGPSSet = Model.EntityContainer.FindEntitySet("VehicleGPSSet"); foreach (var mimeType in mimeTypes) { var requestMessage = new HttpWebRequestMessage(new Uri(ServiceBaseUri + "VehicleGPSSet")); requestMessage.SetHeader("Content-Type", mimeType); requestMessage.SetHeader("Accept", mimeType); requestMessage.Method = "POST"; using (var messageWriter = new ODataMessageWriter(requestMessage, settings, Model)) { var odataWriter = messageWriter.CreateODataEntryWriter(vehicleGPSSet, vehicleGPSType); odataWriter.WriteStart(newVehicleGPS); odataWriter.WriteEnd(); } // send the http request var responseMessage = requestMessage.GetResponse(); // Verify Created Assert.AreEqual(201, responseMessage.StatusCode); ODataEntry entry = this.QueryEntityItem("VehicleGPSSet('000')") as ODataEntry; Assert.AreEqual("000", entry.Properties.Single(p => p.Name == "Key").Value); // Delete the entry var deleteRequestMessage = new HttpWebRequestMessage(new Uri(ServiceBaseUri + "VehicleGPSSet('000')")); deleteRequestMessage.Method = "DELETE"; var deleteResponseMessage = deleteRequestMessage.GetResponse(); // Verift Deleted Assert.AreEqual(204, deleteResponseMessage.StatusCode); ODataEntry deletedEntry = this.QueryEntityItem("VehicleGPSSet('000')", 204) as ODataEntry; Assert.IsNull(deletedEntry); } #endregion }
public override void ResolveTypes(CompileContext context, Model.Scope enclosingScope) { Child(0).ResolveTypes(context, enclosingScope); _struct = enclosingScope.FindType(Child(0).ResultType); if (_struct == null) { context.ReportError(this, "Result of expression is not a struct"); ResultType = "word"; } else { foreach (var _member in _struct.members) if (_member.name == memberName) member = _member; if (member == null) { context.ReportError(this, "Member " + memberName + " not found on " + _struct.name); ResultType = "word"; } else ResultType = member.typeSpecifier; } }