From 8505d3f01d3b741835fba529e6e95b25ae5edfc9 Mon Sep 17 00:00:00 2001 From: Rob Ward Date: Thu, 2 Nov 2017 11:19:34 -0700 Subject: [PATCH] This change adds nuget package testing. This intention is to provide a small test project that can ingest the latest NuPkg's from the build, restore them, build the project which results in a testable Dll. These tests are very limited in scope, i.e. they only test the Dlls ability to load and perform basic functions; the functional tests will test the full functionality. --- .gitignore | 4 + .../App.config | 6 + .../ClientLibTest.cs | 35 + .../Microsoft.OData.Tests.Nuget.Client.csproj | 110 + .../Properties/AssemblyInfo.cs | 36 + .../TrippinService.cs | 2905 ++++++++++ .../TrippinService.tt | 75 + .../TrippinService.ttinclude | 5074 +++++++++++++++++ .../packages.config | 14 + .../App.config | 6 + .../CoreLibTest.cs | 73 + .../HttpWebRequestMessage.cs | 125 + .../HttpWebResponseMessage.cs | 93 + .../Microsoft.OData.Tests.Nuget.Core.csproj | 114 + .../Properties/AssemblyInfo.cs | 36 + .../packages.config | 45 + .../App.config | 6 + .../EdmLibTest.cs | 34 + .../Microsoft.OData.Tests.Nuget.Edm.csproj | 105 + .../Properties/AssemblyInfo.cs | 36 + .../Schema.xml | 143 + .../packages.config | 43 + .../App.config | 6 + ...Microsoft.OData.Tests.Nuget.Spatial.csproj | 104 + .../Properties/AssemblyInfo.cs | 36 + .../SpatialLibTest.cs | 26 + .../packages.config | 43 + test/PackageTests/NugetPackageTesting.sln | 40 + 28 files changed, 9373 insertions(+) create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Client/App.config create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Client/ClientLibTest.cs create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Client/Microsoft.OData.Tests.Nuget.Client.csproj create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Client/Properties/AssemblyInfo.cs create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Client/TrippinService.cs create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Client/TrippinService.tt create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Client/TrippinService.ttinclude create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Client/packages.config create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Core/App.config create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Core/CoreLibTest.cs create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Core/HttpWebRequestMessage.cs create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Core/HttpWebResponseMessage.cs create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Core/Microsoft.OData.Tests.Nuget.Core.csproj create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Core/Properties/AssemblyInfo.cs create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Core/packages.config create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/App.config create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/EdmLibTest.cs create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/Microsoft.OData.Tests.Nuget.Edm.csproj create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/Properties/AssemblyInfo.cs create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/Schema.xml create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/packages.config create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Spatial/App.config create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Spatial/Microsoft.OData.Tests.Nuget.Spatial.csproj create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Spatial/Properties/AssemblyInfo.cs create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Spatial/SpatialLibTest.cs create mode 100644 test/PackageTests/Microsoft.OData.Tests.Nuget.Spatial/packages.config create mode 100644 test/PackageTests/NugetPackageTesting.sln diff --git a/.gitignore b/.gitignore index b2c7f8ece0..4a136ffc71 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,10 @@ test/FunctionalTests/Framework/AstoriaTestFramework.xml # Downloaded Nuget packages sln/packages/ +test/PackageTests/packages/ + +# Packages under tests +test/PackageTests/TestPackages # Test artifacts test/FunctionalTests/Tests/Data/Northwind/Northwind.csdl1.csdl diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/App.config b/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/App.config new file mode 100644 index 0000000000..3c88dd4d84 --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/ClientLibTest.cs b/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/ClientLibTest.cs new file mode 100644 index 0000000000..94727a9e60 --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/ClientLibTest.cs @@ -0,0 +1,35 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- +namespace Microsoft.OData.Tests.Nuget.Client +{ + using System; + using System.Linq; + using Microsoft.OData.SampleService.Models.TripPin; + using OData.Client; + using Xunit; + + public class ClientLibTest + { + [Fact] + public void BasicTest() + { + var dsc = new DefaultContainer(new Uri("http://services.odata.org/V4/(S(ply0t0sqxoh4wooviq211x55))/TripPinServiceRW/")); + var people = dsc.People; + people.BeginExecute(ReadingPeople, people); + + } + + private void ReadingPeople(IAsyncResult ar) + { + var peopleQuery = ar.AsyncState as DataServiceQuery; + if (peopleQuery != null) + { + var people = peopleQuery.EndExecute(ar); + Console.WriteLine(people.Count()); + } + } + } +} diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/Microsoft.OData.Tests.Nuget.Client.csproj b/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/Microsoft.OData.Tests.Nuget.Client.csproj new file mode 100644 index 0000000000..0943e6c4bd --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/Microsoft.OData.Tests.Nuget.Client.csproj @@ -0,0 +1,110 @@ + + + + + + Debug + AnyCPU + {82A1482B-3B8D-4DE0-B4F9-B2CDA4496AD3} + Library + Properties + Microsoft.OData.Tests.Nuget.Client + Microsoft.OData.Tests.Nuget.Client + v4.5.2 + 512 + + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.OData.Client.7.4.0\lib\net45\Microsoft.OData.Client.dll + True + + + ..\packages\Microsoft.OData.Core.7.4.0\lib\portable-net45+win8+wpa81\Microsoft.OData.Core.dll + True + + + ..\packages\Microsoft.OData.Edm.7.4.0\lib\portable-net45+win8+wpa81\Microsoft.OData.Edm.dll + True + + + ..\packages\Microsoft.Spatial.7.4.0\lib\portable-net45+win8+wpa81\Microsoft.Spatial.dll + True + + + + + + + + + + ..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll + True + + + ..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll + True + + + ..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll + True + + + ..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll + True + + + + + + + True + True + TrippinService.tt + + + + + + + + + + TextTemplatingFileGenerator + TrippinService.cs + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + \ No newline at end of file diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/Properties/AssemblyInfo.cs b/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..e4b8ccc3a9 --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ClientLibPackageTest")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ClientLibPackageTest")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("499c3089-cba3-4932-9888-ff89efac70c1")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/TrippinService.cs b/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/TrippinService.cs new file mode 100644 index 0000000000..5c6dd08466 --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/TrippinService.cs @@ -0,0 +1,2905 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +// Generation date: 1/25/2016 11:49:33 AM +namespace Microsoft.OData.SampleService.Models.TripPin +{ + /// + /// There are no comments for DefaultContainer in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("DefaultContainer")] + public partial class DefaultContainer : global::Microsoft.OData.Client.DataServiceContext + { + /// + /// Initialize a new DefaultContainer object. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public DefaultContainer(global::System.Uri serviceRoot) : + base(serviceRoot, global::Microsoft.OData.Client.ODataProtocolVersion.V4) + { + this.ResolveName = new global::System.Func(this.ResolveNameFromType); + this.ResolveType = new global::System.Func(this.ResolveTypeFromName); + this.OnContextCreated(); + this.Format.LoadServiceModel = GeneratedEdmModel.GetInstance; + this.Format.UseJson(); + } + partial void OnContextCreated(); + /// + /// Since the namespace configured for this service reference + /// in Visual Studio is different from the one indicated in the + /// server schema, use type-mappers to map between the two. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected global::System.Type ResolveTypeFromName(string typeName) + { + global::System.Type resolvedType = this.DefaultResolveType(typeName, "Microsoft.OData.SampleService.Models.TripPin", "Microsoft.OData.SampleService.Models.TripPin"); + if ((resolvedType != null)) + { + return resolvedType; + } + return null; + } + /// + /// Since the namespace configured for this service reference + /// in Visual Studio is different from the one indicated in the + /// server schema, use type-mappers to map between the two. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected string ResolveNameFromType(global::System.Type clientType) + { + global::Microsoft.OData.Client.OriginalNameAttribute originalNameAttribute = (global::Microsoft.OData.Client.OriginalNameAttribute)global::System.Linq.Enumerable.SingleOrDefault(global::Microsoft.OData.Client.Utility.GetCustomAttributes(clientType, typeof(global::Microsoft.OData.Client.OriginalNameAttribute), true)); + if (clientType.Namespace.Equals("Microsoft.OData.SampleService.Models.TripPin", global::System.StringComparison.Ordinal)) + { + if (originalNameAttribute != null) + { + return string.Concat("Microsoft.OData.SampleService.Models.TripPin.", originalNameAttribute.OriginalName); + } + return string.Concat("Microsoft.OData.SampleService.Models.TripPin.", clientType.Name); + } + if (originalNameAttribute != null) + { + return clientType.Namespace + "." + originalNameAttribute.OriginalName; + } + return clientType.FullName; + } + /// + /// There are no comments for Photos in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Photos")] + public global::Microsoft.OData.Client.DataServiceQuery Photos + { + get + { + if ((this._Photos == null)) + { + this._Photos = base.CreateQuery("Photos"); + } + return this._Photos; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Photos; + /// + /// There are no comments for People in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("People")] + public global::Microsoft.OData.Client.DataServiceQuery People + { + get + { + if ((this._People == null)) + { + this._People = base.CreateQuery("People"); + } + return this._People; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _People; + /// + /// There are no comments for Airlines in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Airlines")] + public global::Microsoft.OData.Client.DataServiceQuery Airlines + { + get + { + if ((this._Airlines == null)) + { + this._Airlines = base.CreateQuery("Airlines"); + } + return this._Airlines; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Airlines; + /// + /// There are no comments for Airports in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Airports")] + public global::Microsoft.OData.Client.DataServiceQuery Airports + { + get + { + if ((this._Airports == null)) + { + this._Airports = base.CreateQuery("Airports"); + } + return this._Airports; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Airports; + /// + /// There are no comments for Photos in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public void AddToPhotos(Photo photo) + { + base.AddObject("Photos", photo); + } + /// + /// There are no comments for People in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public void AddToPeople(Person person) + { + base.AddObject("People", person); + } + /// + /// There are no comments for Airlines in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public void AddToAirlines(Airline airline) + { + base.AddObject("Airlines", airline); + } + /// + /// There are no comments for Airports in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public void AddToAirports(Airport airport) + { + base.AddObject("Airports", airport); + } + /// + /// There are no comments for Me in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Me")] + public PersonSingle Me + { + get + { + if ((this._Me == null)) + { + this._Me = new PersonSingle(this, "Me"); + } + return this._Me; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private PersonSingle _Me; + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private abstract class GeneratedEdmModel + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private static global::Microsoft.OData.Edm.IEdmModel ParsedModel = LoadModelFromString(); + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private const string Edmx = @" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Org.OData.Core.V1.Permission/Read + + + + + + image/jpeg + + + + + + + + + + Org.OData.Core.V1.Permission/Read + + + + + + + + + + + + + + + + + + + + + Org.OData.Core.V1.Permission/Read + + + + + + + + + + + Org.OData.Core.V1.Permission/Read + + + + + + + + + + + + + + + Org.OData.Core.V1.Permission/Read + + + + + + + + + + + + + + + + + + + + + + + + + + + Org.OData.Core.V1.Permission/Read + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Org.OData.Capabilities.V1.SearchExpressions/none + + + + + + + + + + + + + + + + + + + + + + Concurrency + + + + + + + Org.OData.Capabilities.V1.NavigationType/None + + + + + + + Org.OData.Capabilities.V1.NavigationType/Recursive + + + + + + + + + + + Org.OData.Capabilities.V1.SearchExpressions/none + + + + + + + + + Trips + Friends + + + + + + + + + + + + Org.OData.Capabilities.V1.SearchExpressions/none + + + + + + + + + + + + + + + + + + + Org.OData.Capabilities.V1.SearchExpressions/none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Org.OData.Capabilities.V1.ConformanceLevelType/Advanced + + + + application/json;odata.metadata=full;IEEE754Compatible=false;odata.streaming=true + application/json;odata.metadata=minimal;IEEE754Compatible=false;odata.streaming=true + application/json;odata.metadata=none;IEEE754Compatible=false;odata.streaming=true + + + + + + + contains + endswith + startswith + length + indexof + substring + tolower + toupper + trim + concat + year + month + day + hour + minute + second + round + floor + ceiling + cast + isof + + + + + +"; + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static global::Microsoft.OData.Edm.IEdmModel GetInstance() + { + return ParsedModel; + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private static global::Microsoft.OData.Edm.IEdmModel LoadModelFromString() + { + global::System.Xml.XmlReader reader = CreateXmlReader(Edmx); + try + { + return global::Microsoft.OData.Edm.Csdl.CsdlReader.Parse(reader); + } + finally + { + ((global::System.IDisposable)(reader)).Dispose(); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private static global::System.Xml.XmlReader CreateXmlReader(string edmxToParse) + { + return global::System.Xml.XmlReader.Create(new global::System.IO.StringReader(edmxToParse)); + } + } + /// + /// There are no comments for GetNearestAirport in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("GetNearestAirport")] + public global::Microsoft.OData.SampleService.Models.TripPin.AirportSingle GetNearestAirport(double lat, double lon) + { + return new global::Microsoft.OData.SampleService.Models.TripPin.AirportSingle(this.CreateFunctionQuerySingle("", "GetNearestAirport", true, new global::Microsoft.OData.Client.UriOperationParameter("lat", lat), + new global::Microsoft.OData.Client.UriOperationParameter("lon", lon))); + } + /// + /// There are no comments for ResetDataSource in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("ResetDataSource")] + public global::Microsoft.OData.Client.DataServiceActionQuery ResetDataSource() + { + return new global::Microsoft.OData.Client.DataServiceActionQuery(this, this.BaseUri.OriginalString.Trim('/') + "/ResetDataSource"); + } + } + /// + /// There are no comments for City in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("City")] + public partial class City : global::System.ComponentModel.INotifyPropertyChanged + { + /// + /// Create a new City object. + /// + /// Initial value of CountryRegion. + /// Initial value of Name. + /// Initial value of Region. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static City CreateCity(string countryRegion, string name, string region) + { + City city = new City(); + city.CountryRegion = countryRegion; + city.Name = name; + city.Region = region; + return city; + } + /// + /// There are no comments for Property CountryRegion in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("CountryRegion")] + public string CountryRegion + { + get + { + return this._CountryRegion; + } + set + { + this.OnCountryRegionChanging(value); + this._CountryRegion = value; + this.OnCountryRegionChanged(); + this.OnPropertyChanged("CountryRegion"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _CountryRegion; + partial void OnCountryRegionChanging(string value); + partial void OnCountryRegionChanged(); + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Name")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + this.OnPropertyChanged("Name"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + /// + /// There are no comments for Property Region in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Region")] + public string Region + { + get + { + return this._Region; + } + set + { + this.OnRegionChanging(value); + this._Region = value; + this.OnRegionChanged(); + this.OnPropertyChanged("Region"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Region; + partial void OnRegionChanging(string value); + partial void OnRegionChanged(); + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } + } + /// + /// There are no comments for Location in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("Location")] + public partial class Location : global::System.ComponentModel.INotifyPropertyChanged + { + /// + /// Create a new Location object. + /// + /// Initial value of Address. + /// Initial value of City. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Location CreateLocation(string address, global::Microsoft.OData.SampleService.Models.TripPin.City city) + { + Location location = new Location(); + location.Address = address; + if ((city == null)) + { + throw new global::System.ArgumentNullException("city"); + } + location.City = city; + return location; + } + /// + /// There are no comments for Property Address in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Address")] + public string Address + { + get + { + return this._Address; + } + set + { + this.OnAddressChanging(value); + this._Address = value; + this.OnAddressChanged(); + this.OnPropertyChanged("Address"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Address; + partial void OnAddressChanging(string value); + partial void OnAddressChanged(); + /// + /// There are no comments for Property City in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("City")] + public global::Microsoft.OData.SampleService.Models.TripPin.City City + { + get + { + return this._City; + } + set + { + this.OnCityChanging(value); + this._City = value; + this.OnCityChanged(); + this.OnPropertyChanged("City"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.SampleService.Models.TripPin.City _City; + partial void OnCityChanging(global::Microsoft.OData.SampleService.Models.TripPin.City value); + partial void OnCityChanged(); + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } + } + /// + /// There are no comments for EventLocation in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("EventLocation")] + public partial class EventLocation : Location + { + /// + /// Create a new EventLocation object. + /// + /// Initial value of Address. + /// Initial value of City. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static EventLocation CreateEventLocation(string address, global::Microsoft.OData.SampleService.Models.TripPin.City city) + { + EventLocation eventLocation = new EventLocation(); + eventLocation.Address = address; + if ((city == null)) + { + throw new global::System.ArgumentNullException("city"); + } + eventLocation.City = city; + return eventLocation; + } + /// + /// There are no comments for Property BuildingInfo in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("BuildingInfo")] + public string BuildingInfo + { + get + { + return this._BuildingInfo; + } + set + { + this.OnBuildingInfoChanging(value); + this._BuildingInfo = value; + this.OnBuildingInfoChanged(); + this.OnPropertyChanged("BuildingInfo"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _BuildingInfo; + partial void OnBuildingInfoChanging(string value); + partial void OnBuildingInfoChanged(); + } + /// + /// There are no comments for AirportLocation in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("AirportLocation")] + public partial class AirportLocation : Location + { + /// + /// Create a new AirportLocation object. + /// + /// Initial value of Address. + /// Initial value of City. + /// Initial value of Loc. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static AirportLocation CreateAirportLocation(string address, global::Microsoft.OData.SampleService.Models.TripPin.City city, global::Microsoft.Spatial.GeographyPoint loc) + { + AirportLocation airportLocation = new AirportLocation(); + airportLocation.Address = address; + if ((city == null)) + { + throw new global::System.ArgumentNullException("city"); + } + airportLocation.City = city; + airportLocation.Loc = loc; + return airportLocation; + } + /// + /// There are no comments for Property Loc in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Loc")] + public global::Microsoft.Spatial.GeographyPoint Loc + { + get + { + return this._Loc; + } + set + { + this.OnLocChanging(value); + this._Loc = value; + this.OnLocChanged(); + this.OnPropertyChanged("Loc"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.Spatial.GeographyPoint _Loc; + partial void OnLocChanging(global::Microsoft.Spatial.GeographyPoint value); + partial void OnLocChanged(); + } + /// + /// There are no comments for PhotoSingle in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("PhotoSingle")] + public partial class PhotoSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new PhotoSingle object. + /// + public PhotoSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new PhotoSingle object. + /// + public PhotoSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new PhotoSingle object. + /// + public PhotoSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + } + /// + /// There are no comments for Photo in the schema. + /// + /// + /// Id + /// + [global::Microsoft.OData.Client.Key("Id")] + [global::Microsoft.OData.Client.EntitySet("Photos")] + [global::Microsoft.OData.Client.HasStream()] + [global::Microsoft.OData.Client.OriginalNameAttribute("Photo")] + public partial class Photo : global::Microsoft.OData.Client.BaseEntityType, global::System.ComponentModel.INotifyPropertyChanged + { + /// + /// Create a new Photo object. + /// + /// Initial value of Id. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Photo CreatePhoto(long ID) + { + Photo photo = new Photo(); + photo.Id = ID; + return photo; + } + /// + /// There are no comments for Property Id in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Id")] + public long Id + { + get + { + return this._Id; + } + set + { + this.OnIdChanging(value); + this._Id = value; + this.OnIdChanged(); + this.OnPropertyChanged("Id"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private long _Id; + partial void OnIdChanging(long value); + partial void OnIdChanged(); + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Name")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + this.OnPropertyChanged("Name"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } + } + /// + /// There are no comments for PersonSingle in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("PersonSingle")] + public partial class PersonSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new PersonSingle object. + /// + public PersonSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new PersonSingle object. + /// + public PersonSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new PersonSingle object. + /// + public PersonSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + /// + /// There are no comments for Friends in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Friends")] + public global::Microsoft.OData.Client.DataServiceQuery Friends + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Friends == null)) + { + this._Friends = Context.CreateQuery(GetPath("Friends")); + } + return this._Friends; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Friends; + /// + /// There are no comments for Trips in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Trips")] + public global::Microsoft.OData.Client.DataServiceQuery Trips + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Trips == null)) + { + this._Trips = Context.CreateQuery(GetPath("Trips")); + } + return this._Trips; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Trips; + /// + /// There are no comments for Photo in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Photo")] + public global::Microsoft.OData.SampleService.Models.TripPin.PhotoSingle Photo + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Photo == null)) + { + this._Photo = new global::Microsoft.OData.SampleService.Models.TripPin.PhotoSingle(this.Context, GetPath("Photo")); + } + return this._Photo; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.SampleService.Models.TripPin.PhotoSingle _Photo; + } + /// + /// There are no comments for Person in the schema. + /// + /// + /// UserName + /// + [global::Microsoft.OData.Client.Key("UserName")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Person")] + public partial class Person : global::Microsoft.OData.Client.BaseEntityType, global::System.ComponentModel.INotifyPropertyChanged + { + /// + /// Create a new Person object. + /// + /// Initial value of UserName. + /// Initial value of FirstName. + /// Initial value of LastName. + /// Initial value of Concurrency. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Person CreatePerson(string userName, string firstName, string lastName, long concurrency) + { + Person person = new Person(); + person.UserName = userName; + person.FirstName = firstName; + person.LastName = lastName; + person.Concurrency = concurrency; + return person; + } + /// + /// There are no comments for Property UserName in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("UserName")] + public string UserName + { + get + { + return this._UserName; + } + set + { + this.OnUserNameChanging(value); + this._UserName = value; + this.OnUserNameChanged(); + this.OnPropertyChanged("UserName"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _UserName; + partial void OnUserNameChanging(string value); + partial void OnUserNameChanged(); + /// + /// There are no comments for Property FirstName in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("FirstName")] + public string FirstName + { + get + { + return this._FirstName; + } + set + { + this.OnFirstNameChanging(value); + this._FirstName = value; + this.OnFirstNameChanged(); + this.OnPropertyChanged("FirstName"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _FirstName; + partial void OnFirstNameChanging(string value); + partial void OnFirstNameChanged(); + /// + /// There are no comments for Property LastName in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("LastName")] + public string LastName + { + get + { + return this._LastName; + } + set + { + this.OnLastNameChanging(value); + this._LastName = value; + this.OnLastNameChanged(); + this.OnPropertyChanged("LastName"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _LastName; + partial void OnLastNameChanging(string value); + partial void OnLastNameChanged(); + /// + /// There are no comments for Property Emails in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Emails")] + public global::System.Collections.ObjectModel.ObservableCollection Emails + { + get + { + return this._Emails; + } + set + { + this.OnEmailsChanging(value); + this._Emails = value; + this.OnEmailsChanged(); + this.OnPropertyChanged("Emails"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.Collections.ObjectModel.ObservableCollection _Emails = new global::System.Collections.ObjectModel.ObservableCollection(); + partial void OnEmailsChanging(global::System.Collections.ObjectModel.ObservableCollection value); + partial void OnEmailsChanged(); + /// + /// There are no comments for Property AddressInfo in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("AddressInfo")] + public global::System.Collections.ObjectModel.ObservableCollection AddressInfo + { + get + { + return this._AddressInfo; + } + set + { + this.OnAddressInfoChanging(value); + this._AddressInfo = value; + this.OnAddressInfoChanged(); + this.OnPropertyChanged("AddressInfo"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.Collections.ObjectModel.ObservableCollection _AddressInfo = new global::System.Collections.ObjectModel.ObservableCollection(); + partial void OnAddressInfoChanging(global::System.Collections.ObjectModel.ObservableCollection value); + partial void OnAddressInfoChanged(); + /// + /// There are no comments for Property Gender in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Gender")] + public global::System.Nullable Gender + { + get + { + return this._Gender; + } + set + { + this.OnGenderChanging(value); + this._Gender = value; + this.OnGenderChanged(); + this.OnPropertyChanged("Gender"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.Nullable _Gender; + partial void OnGenderChanging(global::System.Nullable value); + partial void OnGenderChanged(); + /// + /// There are no comments for Property Concurrency in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Concurrency")] + public long Concurrency + { + get + { + return this._Concurrency; + } + set + { + this.OnConcurrencyChanging(value); + this._Concurrency = value; + this.OnConcurrencyChanged(); + this.OnPropertyChanged("Concurrency"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private long _Concurrency; + partial void OnConcurrencyChanging(long value); + partial void OnConcurrencyChanged(); + /// + /// There are no comments for Property Friends in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Friends")] + public global::Microsoft.OData.Client.DataServiceCollection Friends + { + get + { + return this._Friends; + } + set + { + this.OnFriendsChanging(value); + this._Friends = value; + this.OnFriendsChanged(); + this.OnPropertyChanged("Friends"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceCollection _Friends = new global::Microsoft.OData.Client.DataServiceCollection(null, global::Microsoft.OData.Client.TrackingMode.None); + partial void OnFriendsChanging(global::Microsoft.OData.Client.DataServiceCollection value); + partial void OnFriendsChanged(); + /// + /// There are no comments for Property Trips in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Trips")] + public global::Microsoft.OData.Client.DataServiceCollection Trips + { + get + { + return this._Trips; + } + set + { + this.OnTripsChanging(value); + this._Trips = value; + this.OnTripsChanged(); + this.OnPropertyChanged("Trips"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceCollection _Trips = new global::Microsoft.OData.Client.DataServiceCollection(null, global::Microsoft.OData.Client.TrackingMode.None); + partial void OnTripsChanging(global::Microsoft.OData.Client.DataServiceCollection value); + partial void OnTripsChanged(); + /// + /// There are no comments for Property Photo in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Photo")] + public global::Microsoft.OData.SampleService.Models.TripPin.Photo Photo + { + get + { + return this._Photo; + } + set + { + this.OnPhotoChanging(value); + this._Photo = value; + this.OnPhotoChanged(); + this.OnPropertyChanged("Photo"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.SampleService.Models.TripPin.Photo _Photo; + partial void OnPhotoChanging(global::Microsoft.OData.SampleService.Models.TripPin.Photo value); + partial void OnPhotoChanged(); + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } + /// + /// There are no comments for GetFavoriteAirline in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("GetFavoriteAirline")] + public global::Microsoft.OData.SampleService.Models.TripPin.AirlineSingle GetFavoriteAirline() + { + global::System.Uri requestUri; + Context.TryGetUri(this, out requestUri); + + return new global::Microsoft.OData.SampleService.Models.TripPin.AirlineSingle(this.Context.CreateFunctionQuerySingle(string.Join("/", global::System.Linq.Enumerable.Select(global::System.Linq.Enumerable.Skip(requestUri.Segments, this.Context.BaseUri.Segments.Length), s => s.Trim('/'))), "Microsoft.OData.SampleService.Models.TripPin.GetFavoriteAirline", true)); + } + /// + /// There are no comments for GetFriendsTrips in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("GetFriendsTrips")] + public global::Microsoft.OData.Client.DataServiceQuery GetFriendsTrips(string userName) + { + global::System.Uri requestUri; + Context.TryGetUri(this, out requestUri); + return this.Context.CreateFunctionQuery(string.Join("/", global::System.Linq.Enumerable.Select(global::System.Linq.Enumerable.Skip(requestUri.Segments, this.Context.BaseUri.Segments.Length), s => s.Trim('/'))), "Microsoft.OData.SampleService.Models.TripPin.GetFriendsTrips", true, new global::Microsoft.OData.Client.UriOperationParameter("userName", userName)); + } + /// + /// There are no comments for ShareTrip in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("ShareTrip")] + public global::Microsoft.OData.Client.DataServiceActionQuery ShareTrip(string userName, int tripId) + { + global::Microsoft.OData.Client.EntityDescriptor resource = Context.EntityTracker.TryGetEntityDescriptor(this); + if (resource == null) + { + throw new global::System.Exception("cannot find entity"); + } + + return new global::Microsoft.OData.Client.DataServiceActionQuery(this.Context, resource.EditLink.OriginalString.Trim('/') + "/Microsoft.OData.SampleService.Models.TripPin.ShareTrip", new global::Microsoft.OData.Client.BodyOperationParameter("userName", userName), + new global::Microsoft.OData.Client.BodyOperationParameter("tripId", tripId)); + } + } + /// + /// There are no comments for AirlineSingle in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("AirlineSingle")] + public partial class AirlineSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new AirlineSingle object. + /// + public AirlineSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new AirlineSingle object. + /// + public AirlineSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new AirlineSingle object. + /// + public AirlineSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + } + /// + /// There are no comments for Airline in the schema. + /// + /// + /// AirlineCode + /// + [global::Microsoft.OData.Client.Key("AirlineCode")] + [global::Microsoft.OData.Client.EntitySet("Airlines")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Airline")] + public partial class Airline : global::Microsoft.OData.Client.BaseEntityType, global::System.ComponentModel.INotifyPropertyChanged + { + /// + /// Create a new Airline object. + /// + /// Initial value of AirlineCode. + /// Initial value of Name. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Airline CreateAirline(string airlineCode, string name) + { + Airline airline = new Airline(); + airline.AirlineCode = airlineCode; + airline.Name = name; + return airline; + } + /// + /// There are no comments for Property AirlineCode in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("AirlineCode")] + public string AirlineCode + { + get + { + return this._AirlineCode; + } + set + { + this.OnAirlineCodeChanging(value); + this._AirlineCode = value; + this.OnAirlineCodeChanged(); + this.OnPropertyChanged("AirlineCode"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _AirlineCode; + partial void OnAirlineCodeChanging(string value); + partial void OnAirlineCodeChanged(); + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Name")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + this.OnPropertyChanged("Name"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } + } + /// + /// There are no comments for AirportSingle in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("AirportSingle")] + public partial class AirportSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new AirportSingle object. + /// + public AirportSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new AirportSingle object. + /// + public AirportSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new AirportSingle object. + /// + public AirportSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + } + /// + /// There are no comments for Airport in the schema. + /// + /// + /// IcaoCode + /// + [global::Microsoft.OData.Client.Key("IcaoCode")] + [global::Microsoft.OData.Client.EntitySet("Airports")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Airport")] + public partial class Airport : global::Microsoft.OData.Client.BaseEntityType, global::System.ComponentModel.INotifyPropertyChanged + { + /// + /// Create a new Airport object. + /// + /// Initial value of IcaoCode. + /// Initial value of Name. + /// Initial value of IataCode. + /// Initial value of Location. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Airport CreateAirport(string icaoCode, string name, string iataCode, global::Microsoft.OData.SampleService.Models.TripPin.AirportLocation location) + { + Airport airport = new Airport(); + airport.IcaoCode = icaoCode; + airport.Name = name; + airport.IataCode = iataCode; + if ((location == null)) + { + throw new global::System.ArgumentNullException("location"); + } + airport.Location = location; + return airport; + } + /// + /// There are no comments for Property IcaoCode in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("IcaoCode")] + public string IcaoCode + { + get + { + return this._IcaoCode; + } + set + { + this.OnIcaoCodeChanging(value); + this._IcaoCode = value; + this.OnIcaoCodeChanged(); + this.OnPropertyChanged("IcaoCode"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _IcaoCode; + partial void OnIcaoCodeChanging(string value); + partial void OnIcaoCodeChanged(); + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Name")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + this.OnPropertyChanged("Name"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + /// + /// There are no comments for Property IataCode in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("IataCode")] + public string IataCode + { + get + { + return this._IataCode; + } + set + { + this.OnIataCodeChanging(value); + this._IataCode = value; + this.OnIataCodeChanged(); + this.OnPropertyChanged("IataCode"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _IataCode; + partial void OnIataCodeChanging(string value); + partial void OnIataCodeChanged(); + /// + /// There are no comments for Property Location in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Location")] + public global::Microsoft.OData.SampleService.Models.TripPin.AirportLocation Location + { + get + { + return this._Location; + } + set + { + this.OnLocationChanging(value); + this._Location = value; + this.OnLocationChanged(); + this.OnPropertyChanged("Location"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.SampleService.Models.TripPin.AirportLocation _Location; + partial void OnLocationChanging(global::Microsoft.OData.SampleService.Models.TripPin.AirportLocation value); + partial void OnLocationChanged(); + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } + } + /// + /// There are no comments for PlanItemSingle in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("PlanItemSingle")] + public partial class PlanItemSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new PlanItemSingle object. + /// + public PlanItemSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new PlanItemSingle object. + /// + public PlanItemSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new PlanItemSingle object. + /// + public PlanItemSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + } + /// + /// There are no comments for PlanItem in the schema. + /// + /// + /// PlanItemId + /// + [global::Microsoft.OData.Client.Key("PlanItemId")] + [global::Microsoft.OData.Client.OriginalNameAttribute("PlanItem")] + public partial class PlanItem : global::Microsoft.OData.Client.BaseEntityType, global::System.ComponentModel.INotifyPropertyChanged + { + /// + /// Create a new PlanItem object. + /// + /// Initial value of PlanItemId. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static PlanItem CreatePlanItem(int planItemId) + { + PlanItem planItem = new PlanItem(); + planItem.PlanItemId = planItemId; + return planItem; + } + /// + /// There are no comments for Property PlanItemId in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("PlanItemId")] + public int PlanItemId + { + get + { + return this._PlanItemId; + } + set + { + this.OnPlanItemIdChanging(value); + this._PlanItemId = value; + this.OnPlanItemIdChanged(); + this.OnPropertyChanged("PlanItemId"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private int _PlanItemId; + partial void OnPlanItemIdChanging(int value); + partial void OnPlanItemIdChanged(); + /// + /// There are no comments for Property ConfirmationCode in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("ConfirmationCode")] + public string ConfirmationCode + { + get + { + return this._ConfirmationCode; + } + set + { + this.OnConfirmationCodeChanging(value); + this._ConfirmationCode = value; + this.OnConfirmationCodeChanged(); + this.OnPropertyChanged("ConfirmationCode"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _ConfirmationCode; + partial void OnConfirmationCodeChanging(string value); + partial void OnConfirmationCodeChanged(); + /// + /// There are no comments for Property StartsAt in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("StartsAt")] + public global::System.Nullable StartsAt + { + get + { + return this._StartsAt; + } + set + { + this.OnStartsAtChanging(value); + this._StartsAt = value; + this.OnStartsAtChanged(); + this.OnPropertyChanged("StartsAt"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.Nullable _StartsAt; + partial void OnStartsAtChanging(global::System.Nullable value); + partial void OnStartsAtChanged(); + /// + /// There are no comments for Property EndsAt in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("EndsAt")] + public global::System.Nullable EndsAt + { + get + { + return this._EndsAt; + } + set + { + this.OnEndsAtChanging(value); + this._EndsAt = value; + this.OnEndsAtChanged(); + this.OnPropertyChanged("EndsAt"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.Nullable _EndsAt; + partial void OnEndsAtChanging(global::System.Nullable value); + partial void OnEndsAtChanged(); + /// + /// There are no comments for Property Duration in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Duration")] + public global::System.Nullable Duration + { + get + { + return this._Duration; + } + set + { + this.OnDurationChanging(value); + this._Duration = value; + this.OnDurationChanged(); + this.OnPropertyChanged("Duration"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.Nullable _Duration; + partial void OnDurationChanging(global::System.Nullable value); + partial void OnDurationChanged(); + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } + } + /// + /// There are no comments for PublicTransportationSingle in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("PublicTransportationSingle")] + public partial class PublicTransportationSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new PublicTransportationSingle object. + /// + public PublicTransportationSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new PublicTransportationSingle object. + /// + public PublicTransportationSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new PublicTransportationSingle object. + /// + public PublicTransportationSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + } + /// + /// There are no comments for PublicTransportation in the schema. + /// + /// + /// PlanItemId + /// + [global::Microsoft.OData.Client.Key("PlanItemId")] + [global::Microsoft.OData.Client.OriginalNameAttribute("PublicTransportation")] + public partial class PublicTransportation : PlanItem + { + /// + /// Create a new PublicTransportation object. + /// + /// Initial value of PlanItemId. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static PublicTransportation CreatePublicTransportation(int planItemId) + { + PublicTransportation publicTransportation = new PublicTransportation(); + publicTransportation.PlanItemId = planItemId; + return publicTransportation; + } + /// + /// There are no comments for Property SeatNumber in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("SeatNumber")] + public string SeatNumber + { + get + { + return this._SeatNumber; + } + set + { + this.OnSeatNumberChanging(value); + this._SeatNumber = value; + this.OnSeatNumberChanged(); + this.OnPropertyChanged("SeatNumber"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _SeatNumber; + partial void OnSeatNumberChanging(string value); + partial void OnSeatNumberChanged(); + } + /// + /// There are no comments for FlightSingle in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("FlightSingle")] + public partial class FlightSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new FlightSingle object. + /// + public FlightSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new FlightSingle object. + /// + public FlightSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new FlightSingle object. + /// + public FlightSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + /// + /// There are no comments for From in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("From")] + public global::Microsoft.OData.SampleService.Models.TripPin.AirportSingle From + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._From == null)) + { + this._From = new global::Microsoft.OData.SampleService.Models.TripPin.AirportSingle(this.Context, GetPath("From")); + } + return this._From; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.SampleService.Models.TripPin.AirportSingle _From; + /// + /// There are no comments for To in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("To")] + public global::Microsoft.OData.SampleService.Models.TripPin.AirportSingle To + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._To == null)) + { + this._To = new global::Microsoft.OData.SampleService.Models.TripPin.AirportSingle(this.Context, GetPath("To")); + } + return this._To; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.SampleService.Models.TripPin.AirportSingle _To; + /// + /// There are no comments for Airline in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Airline")] + public global::Microsoft.OData.SampleService.Models.TripPin.AirlineSingle Airline + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Airline == null)) + { + this._Airline = new global::Microsoft.OData.SampleService.Models.TripPin.AirlineSingle(this.Context, GetPath("Airline")); + } + return this._Airline; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.SampleService.Models.TripPin.AirlineSingle _Airline; + } + /// + /// There are no comments for Flight in the schema. + /// + /// + /// PlanItemId + /// + [global::Microsoft.OData.Client.Key("PlanItemId")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Flight")] + public partial class Flight : PublicTransportation + { + /// + /// Create a new Flight object. + /// + /// Initial value of PlanItemId. + /// Initial value of FlightNumber. + /// Initial value of From. + /// Initial value of To. + /// Initial value of Airline. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Flight CreateFlight(int planItemId, string flightNumber, global::Microsoft.OData.SampleService.Models.TripPin.Airport from, global::Microsoft.OData.SampleService.Models.TripPin.Airport to, global::Microsoft.OData.SampleService.Models.TripPin.Airline airline) + { + Flight flight = new Flight(); + flight.PlanItemId = planItemId; + flight.FlightNumber = flightNumber; + if ((from == null)) + { + throw new global::System.ArgumentNullException("from"); + } + flight.From = from; + if ((to == null)) + { + throw new global::System.ArgumentNullException("to"); + } + flight.To = to; + if ((airline == null)) + { + throw new global::System.ArgumentNullException("airline"); + } + flight.Airline = airline; + return flight; + } + /// + /// There are no comments for Property FlightNumber in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("FlightNumber")] + public string FlightNumber + { + get + { + return this._FlightNumber; + } + set + { + this.OnFlightNumberChanging(value); + this._FlightNumber = value; + this.OnFlightNumberChanged(); + this.OnPropertyChanged("FlightNumber"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _FlightNumber; + partial void OnFlightNumberChanging(string value); + partial void OnFlightNumberChanged(); + /// + /// There are no comments for Property From in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("From")] + public global::Microsoft.OData.SampleService.Models.TripPin.Airport From + { + get + { + return this._From; + } + set + { + this.OnFromChanging(value); + this._From = value; + this.OnFromChanged(); + this.OnPropertyChanged("From"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.SampleService.Models.TripPin.Airport _From; + partial void OnFromChanging(global::Microsoft.OData.SampleService.Models.TripPin.Airport value); + partial void OnFromChanged(); + /// + /// There are no comments for Property To in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("To")] + public global::Microsoft.OData.SampleService.Models.TripPin.Airport To + { + get + { + return this._To; + } + set + { + this.OnToChanging(value); + this._To = value; + this.OnToChanged(); + this.OnPropertyChanged("To"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.SampleService.Models.TripPin.Airport _To; + partial void OnToChanging(global::Microsoft.OData.SampleService.Models.TripPin.Airport value); + partial void OnToChanged(); + /// + /// There are no comments for Property Airline in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Airline")] + public global::Microsoft.OData.SampleService.Models.TripPin.Airline Airline + { + get + { + return this._Airline; + } + set + { + this.OnAirlineChanging(value); + this._Airline = value; + this.OnAirlineChanged(); + this.OnPropertyChanged("Airline"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.SampleService.Models.TripPin.Airline _Airline; + partial void OnAirlineChanging(global::Microsoft.OData.SampleService.Models.TripPin.Airline value); + partial void OnAirlineChanged(); + } + /// + /// There are no comments for EventSingle in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("EventSingle")] + public partial class EventSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new EventSingle object. + /// + public EventSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new EventSingle object. + /// + public EventSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new EventSingle object. + /// + public EventSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + } + /// + /// There are no comments for Event in the schema. + /// + /// + /// PlanItemId + /// + [global::Microsoft.OData.Client.Key("PlanItemId")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Event")] + public partial class Event : PlanItem + { + /// + /// Create a new Event object. + /// + /// Initial value of PlanItemId. + /// Initial value of OccursAt. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Event CreateEvent(int planItemId, global::Microsoft.OData.SampleService.Models.TripPin.EventLocation occursAt) + { + Event @event = new Event(); + @event.PlanItemId = planItemId; + if ((occursAt == null)) + { + throw new global::System.ArgumentNullException("occursAt"); + } + @event.OccursAt = occursAt; + return @event; + } + /// + /// There are no comments for Property Description in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Description")] + public string Description + { + get + { + return this._Description; + } + set + { + this.OnDescriptionChanging(value); + this._Description = value; + this.OnDescriptionChanged(); + this.OnPropertyChanged("Description"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Description; + partial void OnDescriptionChanging(string value); + partial void OnDescriptionChanged(); + /// + /// There are no comments for Property OccursAt in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("OccursAt")] + public global::Microsoft.OData.SampleService.Models.TripPin.EventLocation OccursAt + { + get + { + return this._OccursAt; + } + set + { + this.OnOccursAtChanging(value); + this._OccursAt = value; + this.OnOccursAtChanged(); + this.OnPropertyChanged("OccursAt"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.SampleService.Models.TripPin.EventLocation _OccursAt; + partial void OnOccursAtChanging(global::Microsoft.OData.SampleService.Models.TripPin.EventLocation value); + partial void OnOccursAtChanged(); + } + /// + /// There are no comments for TripSingle in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("TripSingle")] + public partial class TripSingle : global::Microsoft.OData.Client.DataServiceQuerySingle + { + /// + /// Initialize a new TripSingle object. + /// + public TripSingle(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) { } + + /// + /// Initialize a new TripSingle object. + /// + public TripSingle(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) { } + + /// + /// Initialize a new TripSingle object. + /// + public TripSingle(global::Microsoft.OData.Client.DataServiceQuerySingle query) + : base(query) { } + + /// + /// There are no comments for Photos in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Photos")] + public global::Microsoft.OData.Client.DataServiceQuery Photos + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._Photos == null)) + { + this._Photos = Context.CreateQuery(GetPath("Photos")); + } + return this._Photos; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _Photos; + /// + /// There are no comments for PlanItems in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("PlanItems")] + public global::Microsoft.OData.Client.DataServiceQuery PlanItems + { + get + { + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + if ((this._PlanItems == null)) + { + this._PlanItems = Context.CreateQuery(GetPath("PlanItems")); + } + return this._PlanItems; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceQuery _PlanItems; + } + /// + /// There are no comments for Trip in the schema. + /// + /// + /// TripId + /// + [global::Microsoft.OData.Client.Key("TripId")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Trip")] + public partial class Trip : global::Microsoft.OData.Client.BaseEntityType, global::System.ComponentModel.INotifyPropertyChanged + { + /// + /// Create a new Trip object. + /// + /// Initial value of TripId. + /// Initial value of Name. + /// Initial value of Budget. + /// Initial value of StartsAt. + /// Initial value of EndsAt. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public static Trip CreateTrip(int tripId, string name, float budget, global::System.DateTimeOffset startsAt, global::System.DateTimeOffset endsAt) + { + Trip trip = new Trip(); + trip.TripId = tripId; + trip.Name = name; + trip.Budget = budget; + trip.StartsAt = startsAt; + trip.EndsAt = endsAt; + return trip; + } + /// + /// There are no comments for Property TripId in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("TripId")] + public int TripId + { + get + { + return this._TripId; + } + set + { + this.OnTripIdChanging(value); + this._TripId = value; + this.OnTripIdChanged(); + this.OnPropertyChanged("TripId"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private int _TripId; + partial void OnTripIdChanging(int value); + partial void OnTripIdChanged(); + /// + /// There are no comments for Property ShareId in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("ShareId")] + public global::System.Nullable ShareId + { + get + { + return this._ShareId; + } + set + { + this.OnShareIdChanging(value); + this._ShareId = value; + this.OnShareIdChanged(); + this.OnPropertyChanged("ShareId"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.Nullable _ShareId; + partial void OnShareIdChanging(global::System.Nullable value); + partial void OnShareIdChanged(); + /// + /// There are no comments for Property Description in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Description")] + public string Description + { + get + { + return this._Description; + } + set + { + this.OnDescriptionChanging(value); + this._Description = value; + this.OnDescriptionChanged(); + this.OnPropertyChanged("Description"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Description; + partial void OnDescriptionChanging(string value); + partial void OnDescriptionChanged(); + /// + /// There are no comments for Property Name in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Name")] + public string Name + { + get + { + return this._Name; + } + set + { + this.OnNameChanging(value); + this._Name = value; + this.OnNameChanged(); + this.OnPropertyChanged("Name"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private string _Name; + partial void OnNameChanging(string value); + partial void OnNameChanged(); + /// + /// There are no comments for Property Budget in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Budget")] + public float Budget + { + get + { + return this._Budget; + } + set + { + this.OnBudgetChanging(value); + this._Budget = value; + this.OnBudgetChanged(); + this.OnPropertyChanged("Budget"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private float _Budget; + partial void OnBudgetChanging(float value); + partial void OnBudgetChanged(); + /// + /// There are no comments for Property StartsAt in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("StartsAt")] + public global::System.DateTimeOffset StartsAt + { + get + { + return this._StartsAt; + } + set + { + this.OnStartsAtChanging(value); + this._StartsAt = value; + this.OnStartsAtChanged(); + this.OnPropertyChanged("StartsAt"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.DateTimeOffset _StartsAt; + partial void OnStartsAtChanging(global::System.DateTimeOffset value); + partial void OnStartsAtChanged(); + /// + /// There are no comments for Property EndsAt in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("EndsAt")] + public global::System.DateTimeOffset EndsAt + { + get + { + return this._EndsAt; + } + set + { + this.OnEndsAtChanging(value); + this._EndsAt = value; + this.OnEndsAtChanged(); + this.OnPropertyChanged("EndsAt"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.DateTimeOffset _EndsAt; + partial void OnEndsAtChanging(global::System.DateTimeOffset value); + partial void OnEndsAtChanged(); + /// + /// There are no comments for Property Tags in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Tags")] + public global::System.Collections.ObjectModel.ObservableCollection Tags + { + get + { + return this._Tags; + } + set + { + this.OnTagsChanging(value); + this._Tags = value; + this.OnTagsChanged(); + this.OnPropertyChanged("Tags"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::System.Collections.ObjectModel.ObservableCollection _Tags = new global::System.Collections.ObjectModel.ObservableCollection(); + partial void OnTagsChanging(global::System.Collections.ObjectModel.ObservableCollection value); + partial void OnTagsChanged(); + /// + /// There are no comments for Property Photos in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("Photos")] + public global::Microsoft.OData.Client.DataServiceCollection Photos + { + get + { + return this._Photos; + } + set + { + this.OnPhotosChanging(value); + this._Photos = value; + this.OnPhotosChanged(); + this.OnPropertyChanged("Photos"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceCollection _Photos = new global::Microsoft.OData.Client.DataServiceCollection(null, global::Microsoft.OData.Client.TrackingMode.None); + partial void OnPhotosChanging(global::Microsoft.OData.Client.DataServiceCollection value); + partial void OnPhotosChanged(); + /// + /// There are no comments for Property PlanItems in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + [global::Microsoft.OData.Client.OriginalNameAttribute("PlanItems")] + public global::Microsoft.OData.Client.DataServiceCollection PlanItems + { + get + { + return this._PlanItems; + } + set + { + this.OnPlanItemsChanging(value); + this._PlanItems = value; + this.OnPlanItemsChanged(); + this.OnPropertyChanged("PlanItems"); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + private global::Microsoft.OData.Client.DataServiceCollection _PlanItems = new global::Microsoft.OData.Client.DataServiceCollection(null, global::Microsoft.OData.Client.TrackingMode.None); + partial void OnPlanItemsChanging(global::Microsoft.OData.Client.DataServiceCollection value); + partial void OnPlanItemsChanged(); + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.4.0")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } + /// + /// There are no comments for GetInvolvedPeople in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("GetInvolvedPeople")] + public global::Microsoft.OData.Client.DataServiceQuery GetInvolvedPeople() + { + global::System.Uri requestUri; + Context.TryGetUri(this, out requestUri); + return this.Context.CreateFunctionQuery(string.Join("/", global::System.Linq.Enumerable.Select(global::System.Linq.Enumerable.Skip(requestUri.Segments, this.Context.BaseUri.Segments.Length), s => s.Trim('/'))), "Microsoft.OData.SampleService.Models.TripPin.GetInvolvedPeople", true); + } + } + /// + /// There are no comments for PersonGender in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("PersonGender")] + public enum PersonGender + { + [global::Microsoft.OData.Client.OriginalNameAttribute("Male")] + Male = 0, + [global::Microsoft.OData.Client.OriginalNameAttribute("Female")] + Female = 1, + [global::Microsoft.OData.Client.OriginalNameAttribute("Unknown")] + Unknown = 2 + } + /// + /// Class containing all extension methods + /// + public static class ExtensionMethods + { + /// + /// Get an entity of type global::Microsoft.OData.SampleService.Models.TripPin.Photo as global::Microsoft.OData.SampleService.Models.TripPin.PhotoSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.SampleService.Models.TripPin.PhotoSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.SampleService.Models.TripPin.PhotoSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.SampleService.Models.TripPin.Photo as global::Microsoft.OData.SampleService.Models.TripPin.PhotoSingle specified by key from an entity set + /// + /// source entity set + /// The value of id + public static global::Microsoft.OData.SampleService.Models.TripPin.PhotoSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + long id) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "Id", id } + }; + return new global::Microsoft.OData.SampleService.Models.TripPin.PhotoSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.SampleService.Models.TripPin.Person as global::Microsoft.OData.SampleService.Models.TripPin.PersonSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.SampleService.Models.TripPin.PersonSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.SampleService.Models.TripPin.PersonSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.SampleService.Models.TripPin.Person as global::Microsoft.OData.SampleService.Models.TripPin.PersonSingle specified by key from an entity set + /// + /// source entity set + /// The value of userName + public static global::Microsoft.OData.SampleService.Models.TripPin.PersonSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + string userName) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "UserName", userName } + }; + return new global::Microsoft.OData.SampleService.Models.TripPin.PersonSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.SampleService.Models.TripPin.Airline as global::Microsoft.OData.SampleService.Models.TripPin.AirlineSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.SampleService.Models.TripPin.AirlineSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.SampleService.Models.TripPin.AirlineSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.SampleService.Models.TripPin.Airline as global::Microsoft.OData.SampleService.Models.TripPin.AirlineSingle specified by key from an entity set + /// + /// source entity set + /// The value of airlineCode + public static global::Microsoft.OData.SampleService.Models.TripPin.AirlineSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + string airlineCode) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "AirlineCode", airlineCode } + }; + return new global::Microsoft.OData.SampleService.Models.TripPin.AirlineSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.SampleService.Models.TripPin.Airport as global::Microsoft.OData.SampleService.Models.TripPin.AirportSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.SampleService.Models.TripPin.AirportSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.SampleService.Models.TripPin.AirportSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.SampleService.Models.TripPin.Airport as global::Microsoft.OData.SampleService.Models.TripPin.AirportSingle specified by key from an entity set + /// + /// source entity set + /// The value of icaoCode + public static global::Microsoft.OData.SampleService.Models.TripPin.AirportSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + string icaoCode) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "IcaoCode", icaoCode } + }; + return new global::Microsoft.OData.SampleService.Models.TripPin.AirportSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.SampleService.Models.TripPin.PlanItem as global::Microsoft.OData.SampleService.Models.TripPin.PlanItemSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.SampleService.Models.TripPin.PlanItemSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.SampleService.Models.TripPin.PlanItemSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.SampleService.Models.TripPin.PlanItem as global::Microsoft.OData.SampleService.Models.TripPin.PlanItemSingle specified by key from an entity set + /// + /// source entity set + /// The value of planItemId + public static global::Microsoft.OData.SampleService.Models.TripPin.PlanItemSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + int planItemId) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "PlanItemId", planItemId } + }; + return new global::Microsoft.OData.SampleService.Models.TripPin.PlanItemSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.SampleService.Models.TripPin.PublicTransportation as global::Microsoft.OData.SampleService.Models.TripPin.PublicTransportationSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.SampleService.Models.TripPin.PublicTransportationSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.SampleService.Models.TripPin.PublicTransportationSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.SampleService.Models.TripPin.PublicTransportation as global::Microsoft.OData.SampleService.Models.TripPin.PublicTransportationSingle specified by key from an entity set + /// + /// source entity set + /// The value of planItemId + public static global::Microsoft.OData.SampleService.Models.TripPin.PublicTransportationSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + int planItemId) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "PlanItemId", planItemId } + }; + return new global::Microsoft.OData.SampleService.Models.TripPin.PublicTransportationSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Cast an entity of type global::Microsoft.OData.SampleService.Models.TripPin.PlanItem to its derived type global::Microsoft.OData.SampleService.Models.TripPin.PublicTransportation + /// + /// source entity + public static global::Microsoft.OData.SampleService.Models.TripPin.PublicTransportationSingle CastToPublicTransportation(this global::Microsoft.OData.Client.DataServiceQuerySingle source) + { + global::Microsoft.OData.Client.DataServiceQuerySingle query = source.CastTo(); + return new global::Microsoft.OData.SampleService.Models.TripPin.PublicTransportationSingle(source.Context, query.GetPath(null)); + } + /// + /// Get an entity of type global::Microsoft.OData.SampleService.Models.TripPin.Flight as global::Microsoft.OData.SampleService.Models.TripPin.FlightSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.SampleService.Models.TripPin.FlightSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.SampleService.Models.TripPin.FlightSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.SampleService.Models.TripPin.Flight as global::Microsoft.OData.SampleService.Models.TripPin.FlightSingle specified by key from an entity set + /// + /// source entity set + /// The value of planItemId + public static global::Microsoft.OData.SampleService.Models.TripPin.FlightSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + int planItemId) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "PlanItemId", planItemId } + }; + return new global::Microsoft.OData.SampleService.Models.TripPin.FlightSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Cast an entity of type global::Microsoft.OData.SampleService.Models.TripPin.PublicTransportation to its derived type global::Microsoft.OData.SampleService.Models.TripPin.Flight + /// + /// source entity + public static global::Microsoft.OData.SampleService.Models.TripPin.FlightSingle CastToFlight(this global::Microsoft.OData.Client.DataServiceQuerySingle source) + { + global::Microsoft.OData.Client.DataServiceQuerySingle query = source.CastTo(); + return new global::Microsoft.OData.SampleService.Models.TripPin.FlightSingle(source.Context, query.GetPath(null)); + } + /// + /// Cast an entity of type global::Microsoft.OData.SampleService.Models.TripPin.PlanItem to its derived type global::Microsoft.OData.SampleService.Models.TripPin.Flight + /// + /// source entity + public static global::Microsoft.OData.SampleService.Models.TripPin.FlightSingle CastToFlight(this global::Microsoft.OData.Client.DataServiceQuerySingle source) + { + global::Microsoft.OData.Client.DataServiceQuerySingle query = source.CastTo(); + return new global::Microsoft.OData.SampleService.Models.TripPin.FlightSingle(source.Context, query.GetPath(null)); + } + /// + /// Get an entity of type global::Microsoft.OData.SampleService.Models.TripPin.Event as global::Microsoft.OData.SampleService.Models.TripPin.EventSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.SampleService.Models.TripPin.EventSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.SampleService.Models.TripPin.EventSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.SampleService.Models.TripPin.Event as global::Microsoft.OData.SampleService.Models.TripPin.EventSingle specified by key from an entity set + /// + /// source entity set + /// The value of planItemId + public static global::Microsoft.OData.SampleService.Models.TripPin.EventSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + int planItemId) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "PlanItemId", planItemId } + }; + return new global::Microsoft.OData.SampleService.Models.TripPin.EventSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Cast an entity of type global::Microsoft.OData.SampleService.Models.TripPin.PlanItem to its derived type global::Microsoft.OData.SampleService.Models.TripPin.Event + /// + /// source entity + public static global::Microsoft.OData.SampleService.Models.TripPin.EventSingle CastToEvent(this global::Microsoft.OData.Client.DataServiceQuerySingle source) + { + global::Microsoft.OData.Client.DataServiceQuerySingle query = source.CastTo(); + return new global::Microsoft.OData.SampleService.Models.TripPin.EventSingle(source.Context, query.GetPath(null)); + } + /// + /// Get an entity of type global::Microsoft.OData.SampleService.Models.TripPin.Trip as global::Microsoft.OData.SampleService.Models.TripPin.TripSingle specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static global::Microsoft.OData.SampleService.Models.TripPin.TripSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, global::System.Collections.Generic.Dictionary keys) + { + return new global::Microsoft.OData.SampleService.Models.TripPin.TripSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type global::Microsoft.OData.SampleService.Models.TripPin.Trip as global::Microsoft.OData.SampleService.Models.TripPin.TripSingle specified by key from an entity set + /// + /// source entity set + /// The value of tripId + public static global::Microsoft.OData.SampleService.Models.TripPin.TripSingle ByKey(this global::Microsoft.OData.Client.DataServiceQuery source, + int tripId) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + { "TripId", tripId } + }; + return new global::Microsoft.OData.SampleService.Models.TripPin.TripSingle(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// There are no comments for GetFavoriteAirline in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("GetFavoriteAirline")] + public static global::Microsoft.OData.SampleService.Models.TripPin.AirlineSingle GetFavoriteAirline(this global::Microsoft.OData.Client.DataServiceQuerySingle source) + { + if (!source.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + + return new global::Microsoft.OData.SampleService.Models.TripPin.AirlineSingle(source.CreateFunctionQuerySingle("Microsoft.OData.SampleService.Models.TripPin.GetFavoriteAirline", true)); + } + /// + /// There are no comments for GetInvolvedPeople in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("GetInvolvedPeople")] + public static global::Microsoft.OData.Client.DataServiceQuery GetInvolvedPeople(this global::Microsoft.OData.Client.DataServiceQuerySingle source) + { + if (!source.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + + return source.CreateFunctionQuery("Microsoft.OData.SampleService.Models.TripPin.GetInvolvedPeople", true); + } + /// + /// There are no comments for GetFriendsTrips in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("GetFriendsTrips")] + public static global::Microsoft.OData.Client.DataServiceQuery GetFriendsTrips(this global::Microsoft.OData.Client.DataServiceQuerySingle source, string userName) + { + if (!source.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + + return source.CreateFunctionQuery("Microsoft.OData.SampleService.Models.TripPin.GetFriendsTrips", true, new global::Microsoft.OData.Client.UriOperationParameter("userName", userName)); + } + /// + /// There are no comments for ShareTrip in the schema. + /// + [global::Microsoft.OData.Client.OriginalNameAttribute("ShareTrip")] + public static global::Microsoft.OData.Client.DataServiceActionQuery ShareTrip(this global::Microsoft.OData.Client.DataServiceQuerySingle source, string userName, int tripId) + { + if (!source.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + + return new global::Microsoft.OData.Client.DataServiceActionQuery(source.Context, source.AppendRequestUri("Microsoft.OData.SampleService.Models.TripPin.ShareTrip"), new global::Microsoft.OData.Client.BodyOperationParameter("userName", userName), + new global::Microsoft.OData.Client.BodyOperationParameter("tripId", tripId)); + } + } +} diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/TrippinService.tt b/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/TrippinService.tt new file mode 100644 index 0000000000..dbdc2f0de3 --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/TrippinService.tt @@ -0,0 +1,75 @@ +<#@ include file="TrippinService.ttinclude" #> +<#+ +public static class Configuration +{ + // The URI of the metadata document. The value must be set to a valid service document URI or a local file path + // eg : "http://services.odata.org/V4/OData/OData.svc/", "File:///C:/Odata.edmx", or @"C:\Odata.edmx" + // ### Notice ### If the OData service requires authentication for accessing the metadata document, the value of + // MetadataDocumentUri has to be set to a local file path, or the client code generation process will fail. + public const string MetadataDocumentUri = "http://services.odata.org/V4/(S(ply0t0sqxoh4wooviq211x55))/TripPinServiceRW/$metadata"; + + // The use of DataServiceCollection enables entity and property tracking. The value must be set to true or false. + public const bool UseDataServiceCollection = true; + + // The namespace of the client code generated. It replaces the original namespace in the metadata document, + // unless the model has several namespaces. + public const string NamespacePrefix = ""; + + // The target language of the generated client code. The value must be set to "CSharp" or "VB". + public const string TargetLanguage = "CSharp"; + + // This flag indicates whether to enable naming alias. The value must be set to true or false. + public const bool EnableNamingAlias = true; + + // This flag indicates whether to ignore unexpected elements and attributes in the metadata document and generate + // the client code if any. The value must be set to true or false. + public const bool IgnoreUnexpectedElementsAndAttributes = true; +} + +public static class Customization +{ + /// + /// Changes the text to use upper camel case, which upper case for the first character. + /// + /// Text to convert. + /// The converted text in upper camel case + internal static string CustomizeNaming(string text) + { + if (string.IsNullOrEmpty(text)) + { + return text; + } + + if (text.Length == 1) + { + return Char.ToUpperInvariant(text[0]).ToString(CultureInfo.InvariantCulture); + } + + return Char.ToUpperInvariant(text[0]) + text.Substring(1); + } + + /// + /// Changes the namespace to use upper camel case, which upper case for the first character of all segments. + /// + /// Namespace to convert. + /// The converted namespace in upper camel case + internal static string CustomizeNamespace(string fullNamespace) + { + if (string.IsNullOrEmpty(fullNamespace)) + { + return fullNamespace; + } + + string[] segs = fullNamespace.Split('.'); + string upperNamespace = string.Empty; + int n = segs.Length; + for (int i = 0; i < n; ++i) + { + upperNamespace += Customization.CustomizeNaming(segs[i]); + upperNamespace += (i == n - 1 ? string.Empty : "."); + } + + return upperNamespace; + } +} +#> diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/TrippinService.ttinclude b/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/TrippinService.ttinclude new file mode 100644 index 0000000000..294f97e640 --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/TrippinService.ttinclude @@ -0,0 +1,5074 @@ +<# +/* +OData Client T4 Template ver. 2.4.0 +Copyright (c) Microsoft Corporation +All rights reserved. +MIT License +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +#> +<#@ template debug="true" hostSpecific="true" visibility="internal" linePragmas="false"#> +<#@ output extension=".cs" #> +<#@ Assembly Name="System.Core.dll" #> +<#@ Assembly Name="System.Xml.dll" #> +<#@ Assembly Name="System.Xml.Linq.dll" #> +<#@ Assembly Name="System.Windows.Forms.dll" #> +<#@ Assembly Name="Microsoft.OData.Client.dll" #> +<#@ Assembly Name="Microsoft.OData.Core.dll" #> +<#@ Assembly Name="Microsoft.OData.Edm.dll" #> +<#@ Assembly Name="Microsoft.Spatial.dll" #> +<#@ Import Namespace="System" #> +<#@ Import Namespace="System.IO" #> +<#@ Import Namespace="System.Diagnostics" #> +<#@ Import Namespace="System.Globalization" #> +<#@ Import Namespace="System.Linq" #> +<#@ Import Namespace="System.Xml"#> +<#@ Import Namespace="System.Xml.Linq" #> +<#@ Import Namespace="System.Collections.Generic" #> +<#@ Import Namespace="Microsoft.OData.Edm.Csdl" #> +<#@ Import Namespace="Microsoft.OData.Edm" #> +<#@ Import Namespace="Microsoft.OData.Edm.Annotations" #> +<#@ Import Namespace="Microsoft.OData.Edm.Expressions" #> +<#@ Import Namespace="Microsoft.OData.Edm.Library" #> +<#@ Import Namespace="Microsoft.OData.Edm.Values" #> +<#@ Import Namespace="Microsoft.OData.Edm.Vocabularies.V1" #> +<#@ Import Namespace="Microsoft.OData.Edm.Vocabularies.Community.V1" #> +<#@ Import Namespace="System.Text"#> +<#@ Import Namespace="System.Net"#> +<# + CodeGenerationContext context; + if (!string.IsNullOrWhiteSpace(this.Edmx)) + { + context = new CodeGenerationContext(this.Edmx, this.NamespacePrefix) + { + UseDataServiceCollection = this.UseDataServiceCollection, + TargetLanguage = this.TargetLanguage, + EnableNamingAlias = this.EnableNamingAlias, + IgnoreUnexpectedElementsAndAttributes = this.IgnoreUnexpectedElementsAndAttributes + }; + } + else + { + this.ApplyParametersFromCommandLine(); + if (string.IsNullOrEmpty(metadataDocumentUri)) + { + this.ApplyParametersFromConfigurationClass(); + } + + context = new CodeGenerationContext(new Uri(this.MetadataDocumentUri, UriKind.Absolute), this.NamespacePrefix) + { + UseDataServiceCollection = this.UseDataServiceCollection, + TargetLanguage = this.TargetLanguage, + EnableNamingAlias = this.EnableNamingAlias, + IgnoreUnexpectedElementsAndAttributes = this.IgnoreUnexpectedElementsAndAttributes + }; + } + + if(this.GetReferencedModelReaderFunc != null) + { + context.GetReferencedModelReaderFunc = this.GetReferencedModelReaderFunc; + } + + ODataClientTemplate template; + switch(this.TargetLanguage) + { + case LanguageOption.CSharp: + template = new ODataClientCSharpTemplate(context); + break; + case LanguageOption.VB: + template = new ODataClientVBTemplate(context); + break; + + default: + throw new NotSupportedException(string.Format("Code gen for the target language '{0}' is not supported.", this.TargetLanguage.ToString())); + } + +#><#=template.TransformText()#><# + foreach (string warning in context.Warnings) + { + this.Warning(warning); + } +#><#+ +/// +/// The string for the edmx content. +/// +public string Edmx +{ + get; + set; +} + +/// +/// The Uri string to the metadata document. +/// +public string MetadataDocumentUri +{ + get + { + return this.metadataDocumentUri; + } + + set + { + value = Uri.UnescapeDataString(value); + Uri uri; + if (!Uri.TryCreate(value, UriKind.Absolute, out uri)) + { + // ******************************************************************************************************** + // To fix this error, if the current text transformation is run by the TextTemplatingFileGenerator + // custom tool inside Visual Studio, update the .odata.config file in the project with a valid parameter + // value then hit Ctrl-S to save the .tt file to refresh the code generation. + // ******************************************************************************************************** + throw new ArgumentException(string.Format("The value \"{0}\" is not a valid MetadataDocumentUri because is it not a valid absolute Uri. The MetadataDocumentUri must be set to an absolute Uri referencing the $metadata endpoint of an OData service.", value)); + } + + if (uri.Scheme == "http" || uri.Scheme == "https") + { + value = uri.Scheme + "://" + uri.Authority + uri.AbsolutePath; + value = value.TrimEnd('/'); + if (!value.EndsWith("$metadata")) + { + value += "/$metadata"; + } + } + + this.metadataDocumentUri = value; + } +} + +private string metadataDocumentUri; + +/// +/// The Func to get referenced model's XmlReader. Must have value when the this.Edmx xml or this.metadataDocumentUri's model has referneced model. +/// +public Func GetReferencedModelReaderFunc +{ + get; + set; +} + +/// +/// The NamespacePrefix is used as the only namespace for types in the same namespace as the default container, +/// and as a prefix for the namespace from the model for everything else. If this argument is null, the +/// namespaces from the model are used for all types. +/// +public string NamespacePrefix +{ + get + { + return this.namespacePrefix; + } + + set + { + if (string.IsNullOrWhiteSpace(value)) + { + this.namespacePrefix = null; + } + else + { + this.namespacePrefix = value; + } + } +} + +private string namespacePrefix; + +/// +/// true to use DataServiceCollection in the generated code, false otherwise. +/// +public bool UseDataServiceCollection +{ + get; + set; +} + +/// +/// Specifies which specific .Net Framework language the generated code will target. +/// +public LanguageOption TargetLanguage +{ + get; + set; +} + +/// +/// true to use Upper camel case for all class and property names, false otherwise. +/// +public bool EnableNamingAlias +{ + get; + set; +} + +/// +/// true to ignore unknown elements or attributes in metadata, false otherwise. +/// +public bool IgnoreUnexpectedElementsAndAttributes +{ + get; + set; +} + +/// +/// Generate code targeting a specific .Net Framework language. +/// +public enum LanguageOption +{ + /// Generate code for C# language. + CSharp = 0, + + /// Generate code for Visual Basic language. + VB = 1, +} + +/// +/// Set the UseDataServiceCollection property with the given value. +/// +/// The value to set. +public void ValidateAndSetUseDataServiceCollectionFromString(string stringValue) +{ + bool boolValue; + if (!bool.TryParse(stringValue, out boolValue)) + { + // ******************************************************************************************************** + // To fix this error, if the current text transformation is run by the TextTemplatingFileGenerator + // custom tool inside Visual Studio, update the .odata.config file in the project with a valid parameter + // value then hit Ctrl-S to save the .tt file to refresh the code generation. + // ******************************************************************************************************** + throw new ArgumentException(string.Format("The value \"{0}\" cannot be assigned to the UseDataServiceCollection parameter because it is not a valid boolean value.", stringValue)); + } + + this.UseDataServiceCollection = boolValue; +} + +/// +/// Tries to set the TargetLanguage property with the given value. +/// +/// The value to set. +public void ValidateAndSetTargetLanguageFromString(string stringValue) +{ + LanguageOption option; + if (!Enum.TryParse(stringValue, true, out option)) + { + // ******************************************************************************************************** + // To fix this error, if the current text transformation is run by the TextTemplatingFileGenerator + // custom tool inside Visual Studio, update the .odata.config file in the project with a valid parameter + // value then hit Ctrl-S to save the .tt file to refresh the code generation. + // ******************************************************************************************************** + throw new ArgumentException(string.Format("The value \"{0}\" cannot be assigned to the TargetLanguage parameter because it is not a valid LanguageOption. The supported LanguageOptions are \"CSharp\" and \"VB\".", stringValue)); + } + + this.TargetLanguage = option; +} + +/// +/// Set the EnableNamingAlias property with the given value. +/// +/// The value to set. +public void ValidateAndSetEnableNamingAliasFromString(string stringValue) +{ + bool boolValue; + if (!bool.TryParse(stringValue, out boolValue)) + { + // ******************************************************************************************************** + // To fix this error, if the current text transformation is run by the TextTemplatingFileGenerator + // custom tool inside Visual Studio, update the .odata.config file in the project with a valid parameter + // value then hit Ctrl-S to save the .tt file to refresh the code generation. + // ******************************************************************************************************** + throw new ArgumentException(string.Format("The value \"{0}\" cannot be assigned to the EnableNamingAlias parameter because it is not a valid boolean value.", stringValue)); + } + + this.EnableNamingAlias = boolValue; +} + +/// +/// Set the IgnoreUnexpectedElementsAndAttributes property with the given value. +/// +/// The value to set. +public void ValidateAndSetIgnoreUnexpectedElementsAndAttributesFromString(string stringValue) +{ + bool boolValue; + if (!bool.TryParse(stringValue, out boolValue)) + { + // ******************************************************************************************************** + // To fix this error, if the current text transformation is run by the TextTemplatingFileGenerator + // custom tool inside Visual Studio, update the .odata.config file in the project with a valid parameter + // value then hit Ctrl-S to save the .tt file to refresh the code generation. + // ******************************************************************************************************** + throw new ArgumentException(string.Format("The value \"{0}\" cannot be assigned to the IgnoreUnexpectedElementsAndAttributes parameter because it is not a valid boolean value.", stringValue)); + } + + this.IgnoreUnexpectedElementsAndAttributes = boolValue; +} + +/// +/// Reads the parameter values from the Configuration class and applies them. +/// +private void ApplyParametersFromConfigurationClass() +{ + this.MetadataDocumentUri = Configuration.MetadataDocumentUri; + this.NamespacePrefix = Configuration.NamespacePrefix; + this.UseDataServiceCollection = Configuration.UseDataServiceCollection; + this.ValidateAndSetTargetLanguageFromString(Configuration.TargetLanguage); + this.EnableNamingAlias = Configuration.EnableNamingAlias; + this.IgnoreUnexpectedElementsAndAttributes = Configuration.IgnoreUnexpectedElementsAndAttributes; +} + +/// +/// Reads the parameter values from the command line (TextTransform.exe) and applies them. +/// +private void ApplyParametersFromCommandLine() +{ + if (this.Host == null) + { + return; + } + + string metadataDocumentUri = this.Host.ResolveParameterValue("notempty", "notempty", "MetadataDocumentUri"); + if (!string.IsNullOrEmpty(metadataDocumentUri)) + { + this.MetadataDocumentUri = metadataDocumentUri; + } + + string namespacePrefix = this.Host.ResolveParameterValue("notempty", "notempty", "NamespacePrefix"); + if (!string.IsNullOrEmpty(namespacePrefix)) + { + this.NamespacePrefix = namespacePrefix; + } + + string useDataServiceCollection = this.Host.ResolveParameterValue("notempty", "notempty", "UseDataServiceCollection"); + if (!string.IsNullOrEmpty(useDataServiceCollection)) + { + this.ValidateAndSetUseDataServiceCollectionFromString(useDataServiceCollection); + } + + string targetLanguage = this.Host.ResolveParameterValue("notempty", "notempty", "TargetLanguage"); + if (!string.IsNullOrEmpty(targetLanguage)) + { + this.ValidateAndSetTargetLanguageFromString(targetLanguage); + } + + string enableNamingAlias = this.Host.ResolveParameterValue("notempty", "notempty", "EnableNamingAlias"); + if (!string.IsNullOrEmpty(enableNamingAlias)) + { + this.ValidateAndSetEnableNamingAliasFromString(enableNamingAlias); + } + + string ignoreUnexpectedElementsAndAttributes = this.Host.ResolveParameterValue("notempty", "notempty", "IgnoreUnexpectedElementsAndAttributes"); + if (!string.IsNullOrEmpty(ignoreUnexpectedElementsAndAttributes)) + { + this.ValidateAndSetIgnoreUnexpectedElementsAndAttributesFromString(ignoreUnexpectedElementsAndAttributes); + } +} + +/// +/// Context object to provide the model and configuration info to the code generator. +/// +public class CodeGenerationContext +{ + /// + /// The namespace of the term to use when building value annotations for indicating the conventions used. + /// + private const string ConventionTermNamespace = "Com.Microsoft.OData.Service.Conventions.V1"; + + /// + /// The name of the term to use when building value annotations for indicating the conventions used. + /// + private const string ConventionTermName = "UrlConventions"; + + /// + /// The string value for indicating that the key-as-segment convention is being used in annotations and headers. + /// + private const string KeyAsSegmentConventionName = "KeyAsSegment"; + + /// + /// The XElement for the edmx + /// + private readonly XElement edmx; + + /// + /// The namespacePrefix is used as the only namespace in generated code when there's only one schema in edm model, + /// and as a prefix for the namespace from the model with multiple schemas. If this argument is null, the + /// namespaces from the model are used for all types. + /// + private readonly string namespacePrefix; + + /// + /// The EdmModel to generate code for. + /// + private IEdmModel edmModel; + + /// + /// The array of namespaces in the current edm model. + /// + private string[] namespacesInModel; + + /// + /// The array of warnings occured when parsing edm model. + /// + private string[] warnings; + + /// + /// true if the model contains any structural type with inheritance, false otherwise. + /// + private bool? modelHasInheritance; + + /// + /// If the namespacePrefix is not null, this contains the mapping of namespaces in the model to the corresponding prefixed namespaces. + /// Otherwise this is an empty dictionary. + /// + private Dictionary namespaceMap; + + /// + /// Maps the element type of a navigation source to the navigation source. + /// + private Dictionary> elementTypeToNavigationSourceMap; + + /// + /// HashSet contains the pair of Names and Namespaces of EntityContainers using KeyAsSegment url convention + /// + private HashSet keyAsSegmentContainers; + + /// + /// Constructs an instance of . + /// + /// The Uri to the metadata document. The supported scheme are File, http and https. + public CodeGenerationContext(Uri metadataUri, string namespacePrefix) + : this(GetEdmxStringFromMetadataPath(metadataUri), namespacePrefix) + { + } + + /// + /// Constructs an instance of . + /// + /// The string for the edmx. + /// The namespacePrefix is used as the only namespace in generated code + /// when there's only one schema in edm model, and as a prefix for the namespace from the model with multiple + /// schemas. If this argument is null, the namespaces from the model are used for all types. + public CodeGenerationContext(string edmx, string namespacePrefix) + { + this.edmx = XElement.Parse(edmx); + this.namespacePrefix = namespacePrefix; + } + + /// + /// The EdmModel to generate code for. + /// + public XElement Edmx + { + get { return this.edmx; } + } + + /// + /// The EdmModel to generate code for. + /// + public IEdmModel EdmModel + { + get + { + if (this.edmModel == null) + { + Debug.Assert(this.edmx != null, "this.edmx != null"); + + IEnumerable errors; + EdmxReaderSettings edmxReaderSettings = new EdmxReaderSettings() + { + GetReferencedModelReaderFunc = this.GetReferencedModelReaderFuncWrapper, + IgnoreUnexpectedAttributesAndElements = this.IgnoreUnexpectedElementsAndAttributes + }; + if (!EdmxReader.TryParse(this.edmx.CreateReader(ReaderOptions.None), Enumerable.Empty(), edmxReaderSettings, out this.edmModel, out errors)) + { + Debug.Assert(errors != null, "errors != null"); + throw new InvalidOperationException(errors.FirstOrDefault().ErrorMessage); + } + else if (this.IgnoreUnexpectedElementsAndAttributes) + { + if (errors != null && errors.Any()) + { + this.warnings = errors.Select(e => e.ErrorMessage).ToArray(); + } + } + } + + return this.edmModel; + } + } + + /// + /// The func for user code to overwrite and provide referenced model's XmlReader. + /// + public Func GetReferencedModelReaderFunc + { + get { return getReferencedModelReaderFunc; } + set { this.getReferencedModelReaderFunc = value; } + } + + /// + /// Basic setting for XmlReader. + /// + private static readonly XmlReaderSettings settings = new XmlReaderSettings() { IgnoreWhitespace = true }; + + /// + /// The func for user code to overwrite and provide referenced model's XmlReader. + /// + private Func getReferencedModelReaderFunc = uri => XmlReader.Create(GetEdmxStreamFromUri(uri), settings); + + /// + /// The Wrapper func for user code to overwrite and provide referenced model's stream. + /// + public Func GetReferencedModelReaderFuncWrapper + { + get + { + return (uri) => + { + using (XmlReader reader = GetReferencedModelReaderFunc(uri)) + { + if (reader == null) + { + return null; + } + + XElement element = XElement.Load(reader); + if (this.ReferencesMap == null) + { + this.ReferencesMap = new Dictionary(); + } + + this.ReferencesMap.Add(uri, element); + return element.CreateReader(ReaderOptions.None); + } + }; + } + } + + /// + /// Dictionary that stores uri and referenced xml mapping. + /// + public Dictionary ReferencesMap + { + get; + set; + } + + /// + /// The array of namespaces in the current edm model. + /// + public string[] NamespacesInModel + { + get + { + if (this.namespacesInModel == null) + { + Debug.Assert(this.EdmModel != null, "this.EdmModel != null"); + this.namespacesInModel = GetElementsFromModelTree(this.EdmModel, (m) => m.SchemaElements.Select(e => e.Namespace)).Distinct().ToArray(); + } + + return this.namespacesInModel; + } + } + + /// + /// The array of warnings occured when parsing edm model. + /// + public string[] Warnings + { + get { return this.warnings ?? (this.warnings = new string[] {}); } + } + + /// + /// true if the model contains any structural type with inheritance, false otherwise. + /// + public bool ModelHasInheritance + { + get + { + if (!this.modelHasInheritance.HasValue) + { + Debug.Assert(this.EdmModel != null, "this.EdmModel != null"); + this.modelHasInheritance = this.EdmModel.SchemaElementsAcrossModels().OfType().Any(t => t.BaseType != null); + } + + return this.modelHasInheritance.Value; + } + } + + /// + /// true if we need to generate the ResolveNameFromType method, false otherwise. + /// + public bool NeedResolveNameFromType + { + get { return this.ModelHasInheritance || this.NamespaceMap.Count > 0 || this.EnableNamingAlias; } + } + + /// + /// true if we need to generate the ResolveTypeFromName method, false otherwise. + /// + public bool NeedResolveTypeFromName + { + get { return this.NamespaceMap.Count > 0 || this.EnableNamingAlias; } + } + + /// + /// If the namespacePrefix is not null, this contains the mapping of namespaces in the model to the corresponding prefixed namespaces. + /// Otherwise this is an empty dictionary. + /// + public Dictionary NamespaceMap + { + get + { + if (this.namespaceMap == null) + { + if (!string.IsNullOrEmpty(this.namespacePrefix)) + { + if (this.NamespacesInModel.Count() == 1) + { + IEdmEntityContainer container = this.EdmModel.EntityContainer; + string containerNamespace = container == null ? null : container.Namespace; + this.namespaceMap = this.NamespacesInModel + .Distinct() + .ToDictionary( + ns => ns, + ns => ns == containerNamespace ? + this.namespacePrefix : + this.namespacePrefix + "." + (this.EnableNamingAlias ? Customization.CustomizeNamespace(ns) : ns)); + } + else + { + this.namespaceMap = this.NamespacesInModel + .Distinct() + .ToDictionary( + ns => ns, + ns => this.namespacePrefix + "." + (this.EnableNamingAlias ? Customization.CustomizeNamespace(ns) : ns)); + } + } + else if (this.EnableNamingAlias) + { + this.namespaceMap = this.NamespacesInModel + .Distinct() + .ToDictionary( + ns => ns, + ns => Customization.CustomizeNamespace(ns)); + } + else + { + this.namespaceMap = new Dictionary(); + } + } + + return this.namespaceMap; + } + } + + /// + /// true to use DataServiceCollection in the generated code, false otherwise. + /// + public bool UseDataServiceCollection + { + get; + set; + } + + /// + /// Specifies which specific .Net Framework language the generated code will target. + /// + public LanguageOption TargetLanguage + { + get; + set; + } + + /// + /// true to use Upper camel case for all class and property names, false otherwise. + /// + public bool EnableNamingAlias + { + get; + set; + } + + /// + /// true to ignore unknown elements or attributes in metadata, false otherwise. + /// + public bool IgnoreUnexpectedElementsAndAttributes + { + get; + set; + } + + /// + /// Maps the element type of an entity set to the entity set. + /// + public Dictionary> ElementTypeToNavigationSourceMap + { + get + { + return this.elementTypeToNavigationSourceMap ?? (this.elementTypeToNavigationSourceMap = new Dictionary>(EqualityComparer.Default)); + } + } + + /// + /// true if this EntityContainer need to set the UrlConvention to KeyAsSegment, false otherwise. + /// + public bool UseKeyAsSegmentUrlConvention(IEdmEntityContainer currentContainer) + { + if (this.keyAsSegmentContainers == null) + { + this.keyAsSegmentContainers = new HashSet(); + Debug.Assert(this.EdmModel != null, "this.EdmModel != null"); + IEnumerable annotations = this.EdmModel.VocabularyAnnotations; + foreach(IEdmValueAnnotation valueAnnotation in annotations.OfType()) + { + IEdmEntityContainer container = valueAnnotation.Target as IEdmEntityContainer; + IEdmValueTerm valueTerm = valueAnnotation.Term as IEdmValueTerm; + IEdmStringConstantExpression expression = valueAnnotation.Value as IEdmStringConstantExpression; + if (container != null && valueTerm != null && expression != null) + { + if (valueTerm.Namespace == ConventionTermNamespace && + valueTerm.Name == ConventionTermName && + expression.Value == KeyAsSegmentConventionName) + { + this.keyAsSegmentContainers.Add(container.FullName()); + } + } + } + } + + return this.keyAsSegmentContainers.Contains(currentContainer.FullName()); + } + + /// + /// Gets the enumeration of schema elements with the given namespace. + /// + /// The namespace of the schema elements to get. + /// The enumeration of schema elements with the given namespace. + public IEnumerable GetSchemaElements(string ns) + { + Debug.Assert(ns != null, "ns != null"); + Debug.Assert(this.EdmModel != null, "this.EdmModel != null"); + return GetElementsFromModelTree(this.EdmModel, m => m.SchemaElements.Where(e => e.Namespace == ns)); + } + + /// + /// Gets the namespace qualified name for the given with the namespace prefix applied if this.NamespacePrefix is specified. + /// + /// The schema element to get the full name for. + /// The fixed name of this schemaElement. + /// The current code generate template. + /// The namespace qualified name for the given with the namespace prefix applied if this.NamespacePrefix is specified. + public string GetPrefixedFullName(IEdmSchemaElement schemaElement, string schemaElementFixedName, ODataClientTemplate template, bool needGlobalPrefix = true) + { + if (schemaElement == null) + { + return null; + } + + return this.GetPrefixedNamespace(schemaElement.Namespace, template, true, needGlobalPrefix) + "." + schemaElementFixedName; + } + + /// + /// Gets the prefixed namespace for the given . + /// + /// The namespace without the prefix. + /// The current code generate template. + /// The flag indicates whether the namespace need to be fixed now. + /// The flag indicates whether the namespace need to be added by gloabal prefix. + /// The prefixed namespace for the given . + public string GetPrefixedNamespace(string ns, ODataClientTemplate template, bool needFix, bool needGlobalPrefix) + { + if (ns == null) + { + return null; + } + + string prefixedNamespace; + if (!this.NamespaceMap.TryGetValue(ns, out prefixedNamespace)) + { + prefixedNamespace = ns; + } + + if (needFix) + { + string[] segments = prefixedNamespace.Split('.'); + prefixedNamespace = string.Empty; + int n = segments.Length; + for (int i = 0; i < n; ++i) + { + if (template.LanguageKeywords.Contains(segments[i])) + { + prefixedNamespace += string.Format(template.FixPattern, segments[i]); + } + else + { + prefixedNamespace += segments[i]; + } + + prefixedNamespace += (i == n - 1 ? string.Empty : "."); + } + } + + if (needGlobalPrefix) + { + prefixedNamespace = template.GlobalPrefix + prefixedNamespace; + } + + return prefixedNamespace; + } + + /// + /// Reads the edmx string from a file path or a http/https path. + /// + /// The Uri to the metadata document. The supported scheme are File, http and https. + private static string GetEdmxStringFromMetadataPath(Uri metadataUri) + { + string content = null; + using (StreamReader streamReader = new StreamReader(GetEdmxStreamFromUri(metadataUri))) + { + content = streamReader.ReadToEnd(); + } + + return content; + } + + /// + /// Get the metadata stream from a file path or a http/https path. + /// + /// The Uri to the stream. The supported scheme are File, http and https. + private static Stream GetEdmxStreamFromUri(Uri metadataUri) + { + Debug.Assert(metadataUri != null, "metadataUri != null"); + Stream metadataStream = null; + if (metadataUri.Scheme == "file") + { + metadataStream = new FileStream(Uri.UnescapeDataString(metadataUri.AbsolutePath), FileMode.Open, FileAccess.Read); + } + else if (metadataUri.Scheme == "http" || metadataUri.Scheme == "https") + { + try + { + HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(metadataUri); + WebResponse webResponse = webRequest.GetResponse(); + metadataStream = webResponse.GetResponseStream(); + } + catch (WebException e) + { + HttpWebResponse webResponse = e.Response as HttpWebResponse; + if (webResponse != null && webResponse.StatusCode == HttpStatusCode.Unauthorized) + { + throw new WebException("Failed to access the metadata document. The OData service requires authentication for accessing it. Please download the metadata, store it into a local file, and set the value of “MetadataDocumentUri” in the .odata.config file to the file path. After that, run custom tool again to generate the OData Client code."); + } + else + { + throw e; + } + } + } + else + { + throw new ArgumentException("Only file, http, https schemes are supported for paths to metadata source locations."); + } + + return metadataStream; + } + + private static IEnumerable GetElementsFromModelTree(IEdmModel mainModel, Func> getElementFromOneModelFunc) + { + List ret = new List(); + if(mainModel is EdmCoreModel || mainModel.FindDeclaredValueTerm(CoreVocabularyConstants.OptimisticConcurrencyControl) != null) + { + return ret; + } + + ret.AddRange(getElementFromOneModelFunc(mainModel)); + foreach (var tmp in mainModel.ReferencedModels) + { + if (tmp is EdmCoreModel || + tmp.FindDeclaredValueTerm(CoreVocabularyConstants.OptimisticConcurrencyControl) != null || + tmp.FindDeclaredValueTerm(CapabilitiesVocabularyConstants.ChangeTracking) != null || + tmp.FindDeclaredValueTerm(AlternateKeysVocabularyConstants.AlternateKeys) != null) + { + continue; + } + + ret.AddRange(getElementFromOneModelFunc(tmp)); + } + + return ret; + } +} + +/// +/// The template class to generate the OData client code. +/// +public abstract class ODataClientTemplate : TemplateBase +{ + protected readonly string singleSuffix = "Single"; + protected const string T4Version = "2.4.0"; + + /// + /// The code generation context. + /// + protected readonly CodeGenerationContext context; + + /// + /// The Dictionary to store identifier mappings when there are duplicate names between properties and Entity/Complex types + /// + protected Dictionary IdentifierMappings = new Dictionary(StringComparer.Ordinal); + + /// + /// Creates an instance of the ODataClientTemplate. + /// + /// The code generation context. + public ODataClientTemplate(CodeGenerationContext context) + { + this.context = context; + } + + #region Get Language specific keyword names. + internal abstract string GlobalPrefix { get; } + internal abstract string SystemTypeTypeName { get; } + internal abstract string AbstractModifier { get; } + internal abstract string DataServiceActionQueryTypeName { get; } + internal abstract string DataServiceActionQuerySingleOfTStructureTemplate { get; } + internal abstract string DataServiceActionQueryOfTStructureTemplate { get; } + internal abstract string NotifyPropertyChangedModifier { get; } + internal abstract string ClassInheritMarker { get; } + internal abstract string ParameterSeparator { get; } + internal abstract string KeyParameterSeparator { get; } + internal abstract string KeyDictionaryItemSeparator { get; } + internal abstract string SystemNullableStructureTemplate { get; } + internal abstract string ICollectionOfTStructureTemplate { get; } + internal abstract string DataServiceCollectionStructureTemplate { get; } + internal abstract string DataServiceQueryStructureTemplate { get; } + internal abstract string DataServiceQuerySingleStructureTemplate { get; } + internal abstract string ObservableCollectionStructureTemplate { get; } + internal abstract string ObjectModelCollectionStructureTemplate { get; } + internal abstract string DataServiceCollectionConstructorParameters { get; } + internal abstract string NewModifier { get; } + internal abstract string GeoTypeInitializePattern { get; } + internal abstract string Int32TypeName { get; } + internal abstract string StringTypeName { get; } + internal abstract string BinaryTypeName { get; } + internal abstract string DecimalTypeName { get; } + internal abstract string Int16TypeName { get; } + internal abstract string SingleTypeName { get; } + internal abstract string BooleanTypeName { get; } + internal abstract string DoubleTypeName { get; } + internal abstract string GuidTypeName { get; } + internal abstract string ByteTypeName { get; } + internal abstract string Int64TypeName { get; } + internal abstract string SByteTypeName { get; } + internal abstract string DataServiceStreamLinkTypeName { get; } + internal abstract string GeographyTypeName { get; } + internal abstract string GeographyPointTypeName { get; } + internal abstract string GeographyLineStringTypeName { get; } + internal abstract string GeographyPolygonTypeName { get; } + internal abstract string GeographyCollectionTypeName { get; } + internal abstract string GeographyMultiPolygonTypeName { get; } + internal abstract string GeographyMultiLineStringTypeName { get; } + internal abstract string GeographyMultiPointTypeName { get; } + internal abstract string GeometryTypeName { get; } + internal abstract string GeometryPointTypeName { get; } + internal abstract string GeometryLineStringTypeName { get; } + internal abstract string GeometryPolygonTypeName { get; } + internal abstract string GeometryCollectionTypeName { get; } + internal abstract string GeometryMultiPolygonTypeName { get; } + internal abstract string GeometryMultiLineStringTypeName { get; } + internal abstract string GeometryMultiPointTypeName { get; } + internal abstract string DateTypeName { get; } + internal abstract string DateTimeOffsetTypeName { get; } + internal abstract string DurationTypeName { get; } + internal abstract string TimeOfDayTypeName { get; } + internal abstract string XmlConvertClassName { get; } + internal abstract string EnumTypeName { get; } + internal abstract HashSet LanguageKeywords { get; } + internal abstract string FixPattern { get; } + internal abstract string EnumUnderlyingTypeMarker { get; } + internal abstract string ConstantExpressionConstructorWithType { get; } + internal abstract string TypeofFormatter { get; } + internal abstract string UriOperationParameterConstructor { get; } + internal abstract string UriEntityOperationParameterConstructor { get; } + internal abstract string BodyOperationParameterConstructor { get; } + internal abstract string BaseEntityType { get; } + internal abstract string OverloadsModifier { get; } + internal abstract string ODataVersion { get; } + internal abstract string ParameterDeclarationTemplate { get; } + internal abstract string DictionaryItemConstructor { get; } + #endregion Get Language specific keyword names. + + #region Language specific write methods. + internal abstract void WriteFileHeader(); + internal abstract void WriteNamespaceStart(string fullNamespace); + internal abstract void WriteClassStartForEntityContainer(string originalContainerName, string containerName, string fixedContainerName); + internal abstract void WriteMethodStartForEntityContainerConstructor(string containerName, string fixedContainerName); + internal abstract void WriteKeyAsSegmentUrlConvention(); + internal abstract void WriteInitializeResolveName(); + internal abstract void WriteInitializeResolveType(); + internal abstract void WriteClassEndForEntityContainerConstructor(); + internal abstract void WriteMethodStartForResolveTypeFromName(); + internal abstract void WriteResolveNamespace(string typeName, string fullNamespace, string languageDependentNamespace); + internal abstract void WriteMethodEndForResolveTypeFromName(); + internal abstract void WriteMethodStartForResolveNameFromType(string containerName, string fullNamespace); + internal abstract void WriteResolveType(string fullNamespace, string languageDependentNamespace); + internal abstract void WriteMethodEndForResolveNameFromType(bool modelHasInheritance); + internal abstract void WriteContextEntitySetProperty(string entitySetName, string entitySetFixedName, string originalEntitySetName, string entitySetElementTypeName, bool inContext = true); + internal abstract void WriteContextSingletonProperty(string singletonName, string singletonFixedName, string originalSingletonName, string singletonElementTypeName, bool inContext = true); + internal abstract void WriteContextAddToEntitySetMethod(string entitySetName, string originalEntitySetName, string typeName, string parameterName); + internal abstract void WriteGeneratedEdmModel(string escapedEdmxString); + internal abstract void WriteClassEndForEntityContainer(); + internal abstract void WriteSummaryCommentForStructuredType(string typeName); + internal abstract void WriteKeyPropertiesCommentAndAttribute(IEnumerable keyProperties, string keyString); + internal abstract void WriteEntityTypeAttribute(); + internal abstract void WriteEntitySetAttribute(string entitySetName); + internal abstract void WriteEntityHasStreamAttribute(); + internal abstract void WriteClassStartForStructuredType(string abstractModifier, string typeName, string originalTypeName, string baseTypeName); + internal abstract void WriteSummaryCommentForStaticCreateMethod(string typeName); + internal abstract void WriteParameterCommentForStaticCreateMethod(string parameterName, string propertyName); + internal abstract void WriteDeclarationStartForStaticCreateMethod(string typeName,string fixedTypeName ); + internal abstract void WriteParameterForStaticCreateMethod(string parameterTypeName, string parameterName, string parameterSeparater); + internal abstract void WriteDeclarationEndForStaticCreateMethod(string typeName, string instanceName); + internal abstract void WriteParameterNullCheckForStaticCreateMethod(string parameterName); + internal abstract void WritePropertyValueAssignmentForStaticCreateMethod(string instanceName, string propertyName, string parameterName); + internal abstract void WriteMethodEndForStaticCreateMethod(string instanceName); + internal abstract void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged); + internal abstract void WriteINotifyPropertyChangedImplementation(); + internal abstract void WriteClassEndForStructuredType(); + internal abstract void WriteNamespaceEnd(); + internal abstract void WriteEnumFlags(); + internal abstract void WriteSummaryCommentForEnumType(string enumName); + internal abstract void WriteEnumDeclaration(string enumName, string originalEnumName, string underlyingType); + internal abstract void WriteMemberForEnumType(string member, string originalMemberName, bool last); + internal abstract void WriteEnumEnd(); + internal abstract void WritePropertyRootNamespace(string containerName, string fullNamespace); + internal abstract void WriteFunctionImportReturnCollectionResult(string functionName, string originalFunctionName, string returnTypeName, string parameters, string parameterValues, bool isComposable, bool useEntityReference); + internal abstract void WriteFunctionImportReturnSingleResult(string functionName, string originalFunctionName, string returnTypeName, string parameters, string parameterValues, bool isComposable, bool isReturnEntity, bool useEntityReference); + internal abstract void WriteBoundFunctionInEntityTypeReturnCollectionResult(bool hideBaseMethod, string functionName, string originalFunctionName, string returnTypeName, string parameters, string fullNamespace, string parameterValues, bool isComposable, bool useEntityReference); + internal abstract void WriteBoundFunctionInEntityTypeReturnSingleResult(bool hideBaseMethod, string functionName, string originalFunctionName, string returnTypeName, string parameters, string fullNamespace, string parameterValues, bool isComposable, bool isReturnEntity, bool useEntityReference); + internal abstract void WriteActionImport(string actionName, string originalActionName, string returnTypeName, string parameters, string parameterValues); + internal abstract void WriteBoundActionInEntityType(bool hideBaseMethod, string actionName, string originalActionName, string returnTypeName, string parameters, string fullNamespace, string parameterValues); + internal abstract void WriteConstructorForSingleType(string singleTypeName, string baseTypeName); + internal abstract void WriteExtensionMethodsStart(); + internal abstract void WriteExtensionMethodsEnd(); + internal abstract void WriteByKeyMethods(string entityTypeName, string returnTypeName, IEnumerable keys, string keyParameters, string keyDictionaryItems); + internal abstract void WriteCastToMethods(string baseTypeName, string derivedTypeName, string derivedTypeFullName, string returnTypeName); + internal abstract void WriteBoundFunctionReturnSingleResultAsExtension(string functionName, string originalFunctionName, string boundTypeName, string returnTypeName, string parameters, string fullNamespace, string parameterValues, bool isComposable, bool isReturnEntity, bool useEntityReference); + internal abstract void WriteBoundFunctionReturnCollectionResultAsExtension(string functionName, string originalFunctionName, string boundTypeName, string returnTypeName, string parameters, string fullNamespace, string parameterValues, bool isComposable, bool useEntityReference); + internal abstract void WriteBoundActionAsExtension(string actionName, string originalActionName, string boundSourceType, string returnTypeName, string parameters, string fullNamespace, string parameterValues); + #endregion Language specific write methods. + + internal HashSet ClrReferenceTypes { get { + if (clrReferenceTypes == null) + { + clrReferenceTypes = new HashSet() + { + EdmPrimitiveTypeKind.String, EdmPrimitiveTypeKind.Binary, EdmPrimitiveTypeKind.Geography, EdmPrimitiveTypeKind.Stream, + EdmPrimitiveTypeKind.GeographyPoint, EdmPrimitiveTypeKind.GeographyLineString, EdmPrimitiveTypeKind.GeographyPolygon, + EdmPrimitiveTypeKind.GeographyCollection, EdmPrimitiveTypeKind.GeographyMultiPolygon, EdmPrimitiveTypeKind.GeographyMultiLineString, + EdmPrimitiveTypeKind.GeographyMultiPoint, EdmPrimitiveTypeKind.Geometry, EdmPrimitiveTypeKind.GeometryPoint, + EdmPrimitiveTypeKind.GeometryLineString, EdmPrimitiveTypeKind.GeometryPolygon, EdmPrimitiveTypeKind.GeometryCollection, + EdmPrimitiveTypeKind.GeometryMultiPolygon, EdmPrimitiveTypeKind.GeometryMultiLineString, EdmPrimitiveTypeKind.GeometryMultiPoint + }; + } + return clrReferenceTypes; + } } + private HashSet clrReferenceTypes; + + /// + /// Generates code for the OData client. + /// + /// The generated code for the OData client. + public override string TransformText() + { + this.WriteFileHeader(); + this.WriteNamespaces(); + return this.GenerationEnvironment.ToString(); + } + + internal void WriteNamespaces() + { + foreach(string fullNamespace in context.NamespacesInModel) + { + this.WriteNamespace(fullNamespace); + } + } + + internal void WriteNamespace(string fullNamespace) + { + this.WriteNamespaceStart(this.context.GetPrefixedNamespace(fullNamespace, this, true, false)); + + IEdmSchemaElement[] schemaElements = this.context.GetSchemaElements(fullNamespace).ToArray(); + if (schemaElements.OfType().Any()) { + IEdmEntityContainer container = schemaElements.OfType().Single(); + this.WriteEntityContainer(container, fullNamespace); + } + + Dictionary> boundOperationsMap = new Dictionary>(); + foreach (IEdmOperation operation in schemaElements.OfType()) + { + if (operation.IsBound) + { + IEdmType edmType = operation.Parameters.First().Type.Definition; + IEdmStructuredType edmStructuredType = edmType as IEdmStructuredType; + if (edmStructuredType != null) + { + List operationList; + if (!boundOperationsMap.TryGetValue(edmStructuredType, out operationList)) + { + operationList = new List(); + } + + operationList.Add(operation); + boundOperationsMap[edmStructuredType] = operationList; + } + } + } + + Dictionary> structuredBaseTypeMap = new Dictionary>(); + foreach(IEdmSchemaType type in schemaElements.OfType()) + { + IEdmEnumType enumType = type as IEdmEnumType; + if (enumType != null) + { + this.WriteEnumType(enumType); + } + else + { + IEdmComplexType complexType = type as IEdmComplexType; + if (complexType != null) + { + this.WriteComplexType(complexType, boundOperationsMap); + } + else + { + IEdmEntityType entityType = type as IEdmEntityType; + this.WriteEntityType(entityType, boundOperationsMap); + } + + IEdmStructuredType structuredType = type as IEdmStructuredType; + if (structuredType.BaseType != null) + { + List derivedTypes; + if (!structuredBaseTypeMap.TryGetValue(structuredType.BaseType, out derivedTypes)) + { + structuredBaseTypeMap[structuredType.BaseType] = new List(); + } + + structuredBaseTypeMap[structuredType.BaseType].Add(structuredType); + } + } + } + + if (schemaElements.OfType().Any() || + schemaElements.OfType().Any(o => o.IsBound)) + { + this.WriteExtensionMethodsStart(); + foreach (IEdmEntityType type in schemaElements.OfType()) + { + string entityTypeName = type.Name; + entityTypeName = context.EnableNamingAlias ? Customization.CustomizeNaming(entityTypeName) : entityTypeName; + string entityTypeFullName = context.GetPrefixedFullName(type, GetFixedName(entityTypeName), this); + string returnTypeName = context.GetPrefixedFullName(type, GetFixedName(entityTypeName + this.singleSuffix), this); + + var keyProperties = type.Key(); + if(keyProperties != null && keyProperties.Any()) + { + List keyParameters = new List(); + List keyDictionaryItems = new List(); + List keyNames = new List(); + foreach (IEdmProperty key in keyProperties) + { + string typeName = Utils.GetClrTypeName(key.Type, this.context.UseDataServiceCollection, this, this.context); + string keyName = Utils.CamelCase(key.Name); + keyNames.Add(keyName); + keyParameters.Add(string.Format(this.ParameterDeclarationTemplate, typeName, this.GetFixedName(keyName))); + keyDictionaryItems.Add(string.Format(this.DictionaryItemConstructor, "\"" + key.Name + "\"", this.GetFixedName(keyName))); + } + + string keyParametersString = string.Join(this.KeyParameterSeparator, keyParameters); + string keyDictionaryItemsString = string.Join(this.KeyDictionaryItemSeparator, keyDictionaryItems); + this.WriteByKeyMethods(entityTypeFullName, returnTypeName, keyNames, keyParametersString, keyDictionaryItemsString); + } + + IEdmEntityType current = (IEdmEntityType)type.BaseType; + while (current != null) + { + string baseTypeName = current.Name; + baseTypeName = context.EnableNamingAlias ? Customization.CustomizeNaming(baseTypeName) : baseTypeName; + baseTypeName = context.GetPrefixedFullName(current, GetFixedName(baseTypeName), this); + this.WriteCastToMethods(baseTypeName, entityTypeName, entityTypeFullName, returnTypeName); + current = (IEdmEntityType)current.BaseType; + } + } + + HashSet boundOperations = new HashSet(StringComparer.Ordinal); + foreach (IEdmFunction function in schemaElements.OfType()) + { + if (function.IsBound) + { + IEdmTypeReference edmTypeReference = function.Parameters.First().Type; + string functionName = this.context.EnableNamingAlias ? Customization.CustomizeNaming(function.Name) : function.Name; + string parameterString, parameterExpressionString, parameterTypes, parameterValues; + bool useEntityReference; + this.GetParameterStrings(function.IsBound, false, function.Parameters.ToArray(), out parameterString, out parameterTypes, out parameterExpressionString, out parameterValues, out useEntityReference); + string sourceTypeName = GetSourceOrReturnTypeName(edmTypeReference); + sourceTypeName = string.Format(edmTypeReference.IsCollection() ? this.DataServiceQueryStructureTemplate : this.DataServiceQuerySingleStructureTemplate, sourceTypeName); + string returnTypeName = GetSourceOrReturnTypeName(function.ReturnType); + string fixedFunctionName = GetFixedName(functionName); + string func = string.Format("{0}({1},{2})", fixedFunctionName, sourceTypeName, parameterTypes ); + + if (!boundOperations.Contains(func)) + { + boundOperations.Add(func); + + if (function.ReturnType.IsCollection()) + { + this.WriteBoundFunctionReturnCollectionResultAsExtension(fixedFunctionName, function.Name, sourceTypeName, returnTypeName, parameterString, function.Namespace, parameterValues, function.IsComposable, useEntityReference); + } + else + { + this.WriteBoundFunctionReturnSingleResultAsExtension(fixedFunctionName, function.Name, sourceTypeName, returnTypeName, parameterString, function.Namespace, parameterValues, function.IsComposable, function.ReturnType.IsEntity(), useEntityReference); + } + } + + IEdmStructuredType structuredType; + if (edmTypeReference.IsCollection()) + { + IEdmCollectionType collectionType = edmTypeReference.Definition as IEdmCollectionType; + structuredType = (IEdmStructuredType)collectionType.ElementType.Definition; + } + else + { + structuredType = (IEdmStructuredType)edmTypeReference.Definition; + } + + List derivedTypes; + if (structuredBaseTypeMap.TryGetValue(structuredType, out derivedTypes)) + { + foreach (IEdmStructuredType type in derivedTypes) + { + IEdmTypeReference derivedTypeReference = new EdmEntityTypeReference((IEdmEntityType)type, true); + List currentParameters = function.Parameters.Select(p => p.Type).ToList(); + currentParameters[0] = derivedTypeReference; + + sourceTypeName = string.Format(edmTypeReference.IsCollection() ? this.DataServiceQueryStructureTemplate : this.DataServiceQuerySingleStructureTemplate, GetSourceOrReturnTypeName(derivedTypeReference)); + string currentFunc = string.Format("{0}({1},{2})", fixedFunctionName, sourceTypeName, parameterTypes ); + if (!boundOperations.Contains(currentFunc)) + { + boundOperations.Add(currentFunc); + + if (function.ReturnType.IsCollection()) + { + this.WriteBoundFunctionReturnCollectionResultAsExtension(fixedFunctionName, function.Name, sourceTypeName, returnTypeName, parameterString, function.Namespace, parameterValues, function.IsComposable, useEntityReference); + } + else + { + this.WriteBoundFunctionReturnSingleResultAsExtension(fixedFunctionName, function.Name, sourceTypeName, returnTypeName, parameterString, function.Namespace, parameterValues, function.IsComposable, function.ReturnType.IsEntity(), useEntityReference); + } + } + } + } + } + } + + foreach (IEdmAction action in schemaElements.OfType()) + { + if (action.IsBound) + { + IEdmTypeReference edmTypeReference = action.Parameters.First().Type; + string actionName = this.context.EnableNamingAlias ? Customization.CustomizeNaming(action.Name) : action.Name; + string parameterString, parameterExpressionString, parameterTypes, parameterValues; + bool useEntityReference; + this.GetParameterStrings(action.IsBound, true, action.Parameters.ToArray(), out parameterString, out parameterTypes, out parameterExpressionString, out parameterValues, out useEntityReference); + string sourceTypeName = GetSourceOrReturnTypeName(edmTypeReference); + sourceTypeName = string.Format(edmTypeReference.IsCollection() ? this.DataServiceQueryStructureTemplate : this.DataServiceQuerySingleStructureTemplate, sourceTypeName); + string returnTypeName; + if (action.ReturnType != null) + { + returnTypeName = GetSourceOrReturnTypeName(action.ReturnType); + if (action.ReturnType.IsCollection()) + { + returnTypeName = string.Format(this.DataServiceActionQueryOfTStructureTemplate, returnTypeName); + } + else + { + returnTypeName = string.Format(this.DataServiceActionQuerySingleOfTStructureTemplate, returnTypeName); + } + } + else + { + returnTypeName = this.DataServiceActionQueryTypeName; + } + + string fixedActionName = GetFixedName(actionName); + string ac = string.Format("{0}({1},{2})", fixedActionName, sourceTypeName, parameterTypes ); + if (!boundOperations.Contains(ac)) + { + boundOperations.Add(ac); + this.WriteBoundActionAsExtension(fixedActionName, action.Name, sourceTypeName, returnTypeName, parameterString, action.Namespace, parameterValues); + } + + IEdmStructuredType structuredType; + if (edmTypeReference.IsCollection()) + { + IEdmCollectionType collectionType = edmTypeReference.Definition as IEdmCollectionType; + structuredType = (IEdmStructuredType)collectionType.ElementType.Definition; + } + else + { + structuredType = (IEdmStructuredType)edmTypeReference.Definition; + } + + List derivedTypes; + if (structuredBaseTypeMap.TryGetValue(structuredType, out derivedTypes)) + { + foreach (IEdmStructuredType type in derivedTypes) + { + IEdmTypeReference derivedTypeReference = new EdmEntityTypeReference((IEdmEntityType)type, true); + List currentParameters = action.Parameters.Select(p => p.Type).ToList(); + currentParameters[0] = derivedTypeReference; + + sourceTypeName = string.Format(edmTypeReference.IsCollection() ? this.DataServiceQueryStructureTemplate : this.DataServiceQuerySingleStructureTemplate, GetSourceOrReturnTypeName(derivedTypeReference)); + string currentAc = string.Format("{0}({1},{2})", fixedActionName, sourceTypeName, parameterTypes ); + if (!boundOperations.Contains(currentAc)) + { + boundOperations.Add(currentAc); + this.WriteBoundActionAsExtension(fixedActionName, action.Name, sourceTypeName, returnTypeName, parameterString, action.Namespace, parameterValues); + } + } + } + } + } + + this.WriteExtensionMethodsEnd(); + } + + this.WriteNamespaceEnd(); + } + + internal bool HasBoundOperations(IEnumerable operations) + { + foreach (IEdmOperation opeartion in operations) + { + if (opeartion.IsBound) + { + return true; + } + } + + return false; + } + + internal void WriteEntityContainer(IEdmEntityContainer container, string fullNamespace) + { + string camelCaseContainerName = container.Name; + if (this.context.EnableNamingAlias) + { + camelCaseContainerName = Customization.CustomizeNaming(camelCaseContainerName); + } + + this.WriteClassStartForEntityContainer(container.Name, camelCaseContainerName, GetFixedName(camelCaseContainerName)); + this.WriteEntityContainerConstructor(container); + + if (this.context.NeedResolveNameFromType) + { + this.WritePropertyRootNamespace(GetFixedName(camelCaseContainerName), this.context.GetPrefixedNamespace(fullNamespace, this, false, false)); + } + + this.WriteResolveTypeFromName(); + this.WriteResolveNameFromType(camelCaseContainerName, fullNamespace); + + foreach (IEdmEntitySet entitySet in container.EntitySets()) + { + IEdmEntityType entitySetElementType = entitySet.EntityType(); + string entitySetElementTypeName = GetElementTypeName(entitySetElementType, container); + + string camelCaseEntitySetName = entitySet.Name; + if (this.context.EnableNamingAlias) + { + camelCaseEntitySetName = Customization.CustomizeNaming(camelCaseEntitySetName); + } + + this.WriteContextEntitySetProperty(camelCaseEntitySetName, GetFixedName(camelCaseEntitySetName), entitySet.Name, GetFixedName(entitySetElementTypeName)); + List edmNavigationSourceList = null; + if (!this.context.ElementTypeToNavigationSourceMap.TryGetValue(entitySet.EntityType(), out edmNavigationSourceList)) + { + edmNavigationSourceList = new List(); + this.context.ElementTypeToNavigationSourceMap.Add(entitySet.EntityType(), edmNavigationSourceList); + } + + edmNavigationSourceList.Add(entitySet); + } + + foreach (IEdmEntitySet entitySet in container.EntitySets()) + { + IEdmEntityType entitySetElementType = entitySet.EntityType(); + + string entitySetElementTypeName = GetElementTypeName(entitySetElementType, container); + + UniqueIdentifierService uniqueIdentifierService = new UniqueIdentifierService(/*IsLanguageCaseSensitive*/true); + string parameterName = GetFixedName(uniqueIdentifierService.GetUniqueParameterName(entitySetElementType.Name)); + + string camelCaseEntitySetName = entitySet.Name; + if (this.context.EnableNamingAlias) + { + camelCaseEntitySetName = Customization.CustomizeNaming(camelCaseEntitySetName); + } + + this.WriteContextAddToEntitySetMethod(camelCaseEntitySetName, entitySet.Name, GetFixedName(entitySetElementTypeName), parameterName); + } + + foreach (IEdmSingleton singleton in container.Singletons()) + { + IEdmEntityType singletonElementType = singleton.EntityType(); + string singletonElementTypeName = GetElementTypeName(singletonElementType, container); + string camelCaseSingletonName = singleton.Name; + if (this.context.EnableNamingAlias) + { + camelCaseSingletonName = Customization.CustomizeNaming(camelCaseSingletonName); + } + + this.WriteContextSingletonProperty(camelCaseSingletonName, GetFixedName(camelCaseSingletonName), singleton.Name, singletonElementTypeName + "Single"); + + List edmNavigationSourceList = null; + if (this.context.ElementTypeToNavigationSourceMap.TryGetValue(singleton.EntityType(), out edmNavigationSourceList)) + { + edmNavigationSourceList.Add(singleton); + } + } + + this.WriteGeneratedEdmModel(Utils.SerializeToString(this.context.Edmx).Replace("\"", "\"\"")); + + bool hasOperationImport = container.OperationImports().OfType().Any(); + foreach (IEdmFunctionImport functionImport in container.OperationImports().OfType()) + { + string parameterString, parameterTypes, parameterExpressionString, parameterValues; + bool useEntityReference; + this.GetParameterStrings(false, false, functionImport.Function.Parameters.ToArray(), out parameterString, out parameterTypes, out parameterExpressionString, out parameterValues, out useEntityReference); + string returnTypeName = GetSourceOrReturnTypeName(functionImport.Function.ReturnType); + string fixedContainerName = this.GetFixedName(functionImport.Container.Name); + bool isCollectionResult = functionImport.Function.ReturnType.IsCollection(); + string functionImportName = functionImport.Name; + if (this.context.EnableNamingAlias) + { + functionImportName = Customization.CustomizeNaming(functionImportName); + fixedContainerName = Customization.CustomizeNaming(fixedContainerName); + } + + if (functionImport.Function.ReturnType.IsCollection()) + { + this.WriteFunctionImportReturnCollectionResult(this.GetFixedName(functionImportName), functionImport.Name, returnTypeName, parameterString, parameterValues, functionImport.Function.IsComposable, useEntityReference); + } + else + { + this.WriteFunctionImportReturnSingleResult(this.GetFixedName(functionImportName), functionImport.Name, returnTypeName, parameterString, parameterValues, functionImport.Function.IsComposable, functionImport.Function.ReturnType.IsEntity(), useEntityReference); + } + } + + foreach (IEdmActionImport actionImport in container.OperationImports().OfType()) + { + string parameterString, parameterTypes, parameterExpressionString, parameterValues; + bool useEntityReference; + this.GetParameterStrings(false, true, actionImport.Action.Parameters.ToArray(), out parameterString, out parameterTypes, out parameterExpressionString, out parameterValues, out useEntityReference); + string returnTypeName = null; + string fixedContainerName = this.GetFixedName(actionImport.Container.Name); + + if (actionImport.Action.ReturnType != null) + { + returnTypeName = GetSourceOrReturnTypeName(actionImport.Action.ReturnType); + if (actionImport.Action.ReturnType.IsCollection()) + { + returnTypeName = string.Format(this.DataServiceActionQueryOfTStructureTemplate, returnTypeName); + } + else + { + returnTypeName = string.Format(this.DataServiceActionQuerySingleOfTStructureTemplate, returnTypeName); + } + } + else + { + returnTypeName = this.DataServiceActionQueryTypeName; + } + + string actionImportName = actionImport.Name; + if (this.context.EnableNamingAlias) + { + actionImportName = Customization.CustomizeNaming(actionImportName); + fixedContainerName = Customization.CustomizeNaming(fixedContainerName); + } + + this.WriteActionImport(this.GetFixedName(actionImportName), actionImport.Name, returnTypeName, parameterString, parameterValues); + } + + this.WriteClassEndForEntityContainer(); + } + + internal void WriteEntityContainerConstructor(IEdmEntityContainer container) + { + string camelCaseContainerName = container.Name; + if (this.context.EnableNamingAlias) + { + camelCaseContainerName = Customization.CustomizeNaming(camelCaseContainerName); + } + + this.WriteMethodStartForEntityContainerConstructor(camelCaseContainerName, GetFixedName(camelCaseContainerName)); + + if (this.context.UseKeyAsSegmentUrlConvention(container)) + { + this.WriteKeyAsSegmentUrlConvention(); + } + + if (this.context.NeedResolveNameFromType) + { + this.WriteInitializeResolveName(); + } + + if (this.context.NeedResolveTypeFromName) + { + this.WriteInitializeResolveType(); + } + + this.WriteClassEndForEntityContainerConstructor(); + } + + internal void WriteResolveTypeFromName() + { + if (!this.context.NeedResolveTypeFromName) + { + return; + } + + this.WriteMethodStartForResolveTypeFromName(); + + // NOTE: since multiple namespaces can have the same prefix and match the namespace + // prefix condition, it's important that the prefix check is done is prefix-length + // order, starting with the longest prefix. + IEnumerable> namespaceToPrefixedNamespacePairs = this.context.NamespaceMap.OrderByDescending(p => p.Key.Length).ThenBy(p => p.Key); + + string typeName = this.SystemTypeTypeName + " "; + foreach(KeyValuePair namespaceToPrefixedNamespacePair in namespaceToPrefixedNamespacePairs) + { + this.WriteResolveNamespace(typeName, namespaceToPrefixedNamespacePair.Key, namespaceToPrefixedNamespacePair.Value); + typeName = string.Empty; + } + + this.WriteMethodEndForResolveTypeFromName(); + } + + internal void WriteResolveNameFromType(string containerName, string fullNamespace) + { + if (!this.context.NeedResolveNameFromType) + { + return; + } + + this.WriteMethodStartForResolveNameFromType(GetFixedName(containerName), fullNamespace); + + // NOTE: in this case order also matters, but the length of the CLR + // namespace is what needs to be considered. + IEnumerable> namespaceToPrefixedNamespacePairs = this.context.NamespaceMap.OrderByDescending(p => p.Value.Length).ThenBy(p => p.Key); + + foreach(KeyValuePair namespaceToPrefixedNamespacePair in namespaceToPrefixedNamespacePairs) + { + this.WriteResolveType(namespaceToPrefixedNamespacePair.Key, namespaceToPrefixedNamespacePair.Value); + } + + this.WriteMethodEndForResolveNameFromType(this.context.ModelHasInheritance); + } + + internal void WritePropertiesForSingleType(IEnumerable properties) + { + foreach (IEdmProperty property in properties.Where(i => i.PropertyKind == EdmPropertyKind.Navigation)) + { + string propertyType; + string propertyName = this.context.EnableNamingAlias ? Customization.CustomizeNaming(property.Name) : property.Name; + if (property.Type is Microsoft.OData.Edm.Library.EdmCollectionTypeReference) + { + propertyType = GetSourceOrReturnTypeName(property.Type); + WriteContextEntitySetProperty(propertyName, GetFixedName(propertyName), property.Name, propertyType, false); + } + else + { + propertyType = Utils.GetClrTypeName(property.Type, true, this, this.context, true); + WriteContextSingletonProperty(propertyName, GetFixedName(propertyName), property.Name, propertyType + "Single", false); + } + } + } + + internal void WriteEntityType(IEdmEntityType entityType, Dictionary> boundOperationsMap) + { + string entityTypeName = ((IEdmSchemaElement)entityType).Name; + entityTypeName = this.context.EnableNamingAlias ? Customization.CustomizeNaming(entityTypeName) : entityTypeName; + this.WriteSummaryCommentForStructuredType(entityTypeName + this.singleSuffix); + this.WriteStructurdTypeDeclaration(entityType, + this.ClassInheritMarker + string.Format(this.DataServiceQuerySingleStructureTemplate, GetFixedName(entityTypeName)), + this.singleSuffix); + string singleTypeName = (this.context.EnableNamingAlias ? + Customization.CustomizeNaming(((IEdmSchemaElement)entityType).Name) : ((IEdmSchemaElement)entityType).Name) + this.singleSuffix; + this.WriteConstructorForSingleType(GetFixedName(singleTypeName), string.Format(this.DataServiceQuerySingleStructureTemplate, GetFixedName(entityTypeName))); + IEdmEntityType current = entityType; + while (current != null) + { + this.WritePropertiesForSingleType(current.DeclaredProperties); + current = (IEdmEntityType)current.BaseType; + } + + this.WriteClassEndForStructuredType(); + + this.WriteSummaryCommentForStructuredType(this.context.EnableNamingAlias ? Customization.CustomizeNaming(entityType.Name) : entityType.Name); + + if (entityType.Key().Any()) + { + IEnumerable keyProperties = entityType.Key().Select(k => k.Name); + this.WriteKeyPropertiesCommentAndAttribute( + this.context.EnableNamingAlias ? keyProperties.Select(k => Customization.CustomizeNaming(k)) : keyProperties, + string.Join("\", \"", keyProperties)); + } + else + { + this.WriteEntityTypeAttribute(); + } + + if (this.context.UseDataServiceCollection) + { + List navigationSourceList; + if (this.context.ElementTypeToNavigationSourceMap.TryGetValue(entityType, out navigationSourceList)) + { + if(navigationSourceList.Count == 1) + { + this.WriteEntitySetAttribute(navigationSourceList[0].Name); + } + } + } + + if (entityType.HasStream) + { + this.WriteEntityHasStreamAttribute(); + } + + this.WriteStructurdTypeDeclaration(entityType, this.BaseEntityType); + this.SetPropertyIdentifierMappingsIfNameConflicts(entityType.Name, entityType); + this.WriteTypeStaticCreateMethod(entityType.Name, entityType); + this.WritePropertiesForStructuredType(entityType.DeclaredProperties); + + if (entityType.BaseType == null && this.context.UseDataServiceCollection) + { + this.WriteINotifyPropertyChangedImplementation(); + } + + this.WriteBoundOperations(entityType, boundOperationsMap); + + this.WriteClassEndForStructuredType(); + } + + internal void WriteComplexType(IEdmComplexType complexType, Dictionary> boundOperationsMap) + { + this.WriteSummaryCommentForStructuredType(this.context.EnableNamingAlias ? Customization.CustomizeNaming(complexType.Name) : complexType.Name); + this.WriteStructurdTypeDeclaration(complexType, string.Empty); + this.SetPropertyIdentifierMappingsIfNameConflicts(complexType.Name, complexType); + this.WriteTypeStaticCreateMethod(complexType.Name, complexType); + this.WritePropertiesForStructuredType(complexType.DeclaredProperties); + + if (complexType.BaseType == null && this.context.UseDataServiceCollection) + { + this.WriteINotifyPropertyChangedImplementation(); + } + + this.WriteClassEndForStructuredType(); + } + + internal void WriteBoundOperations(IEdmStructuredType structuredType, Dictionary> boundOperationsMap) + { + List operations; + if (boundOperationsMap.TryGetValue(structuredType, out operations)) + { + foreach (IEdmFunction function in operations.OfType()) + { + string parameterString, parameterExpressionString, parameterTypes, parameterValues; + bool useEntityReference; + bool hideBaseMethod = this.CheckMethodsInBaseClass(structuredType.BaseType, function, boundOperationsMap); + this.GetParameterStrings(function.IsBound, false, function.Parameters.ToArray(), out parameterString, out parameterTypes, out parameterExpressionString, out parameterValues, out useEntityReference); + string returnTypeName = GetSourceOrReturnTypeName(function.ReturnType); + string functionName = function.Name; + if (this.context.EnableNamingAlias) + { + functionName = Customization.CustomizeNaming(functionName); + } + + if (function.ReturnType.IsCollection()) + { + this.WriteBoundFunctionInEntityTypeReturnCollectionResult(hideBaseMethod, GetFixedName(functionName), function.Name, returnTypeName, parameterString, function.Namespace, parameterValues, function.IsComposable, useEntityReference); + } + else + { + this.WriteBoundFunctionInEntityTypeReturnSingleResult(hideBaseMethod, GetFixedName(functionName), function.Name, returnTypeName, parameterString, function.Namespace, parameterValues, function.IsComposable, function.ReturnType.IsEntity(), useEntityReference); + } + } + + foreach (IEdmAction action in operations.OfType()) + { + string parameterString, parameterExpressionString, parameterTypes, parameterValues; + bool useEntityReference; + bool hideBaseMethod = this.CheckMethodsInBaseClass(structuredType.BaseType, action, boundOperationsMap); + this.GetParameterStrings(action.IsBound, true, action.Parameters.ToArray(), out parameterString, out parameterTypes, out parameterExpressionString, out parameterValues, out useEntityReference); + string returnTypeName; + if (action.ReturnType != null) + { + returnTypeName = GetSourceOrReturnTypeName(action.ReturnType); + if (action.ReturnType.IsCollection()) + { + returnTypeName = string.Format(this.DataServiceActionQueryOfTStructureTemplate, returnTypeName); + } + else + { + returnTypeName = string.Format(this.DataServiceActionQuerySingleOfTStructureTemplate, returnTypeName); + } + } + else + { + returnTypeName = this.DataServiceActionQueryTypeName; + } + + string actionName = action.Name; + if (this.context.EnableNamingAlias) + { + actionName = Customization.CustomizeNaming(actionName); + } + + this.WriteBoundActionInEntityType(hideBaseMethod, GetFixedName(actionName), action.Name, returnTypeName, parameterString, action.Namespace, parameterValues); + } + } + } + + internal bool CheckMethodsInBaseClass(IEdmStructuredType structuredType, IEdmOperation operation, Dictionary> boundOperationsMap) + { + if (structuredType != null) + { + List operations; + if (boundOperationsMap.TryGetValue(structuredType, out operations)) + { + foreach (IEdmOperation op in operations) + { + if (this.context.TargetLanguage == LanguageOption.VB) + { + if (operation.Name == op.Name) + { + return true; + } + } + + List targetParameter = operation.Parameters.ToList(); + List checkParameter = op.Parameters.ToList(); + if (operation.Name == op.Name && targetParameter.Count == checkParameter.Count) + { + bool areSame = true; + for (int i = 1; i < targetParameter.Count; ++i) + { + var targetParameterType = targetParameter[i].Type; + var checkParameterType = checkParameter[i].Type; + if (!targetParameterType.Definition.Equals(checkParameterType.Definition) + || targetParameterType.IsNullable != checkParameterType.IsNullable) + { + areSame = false; + break; + } + } + + if (areSame) + { + return true; + } + } + } + } + + return CheckMethodsInBaseClass(structuredType.BaseType, operation, boundOperationsMap); + } + + return false; + } + + internal void WriteEnumType(IEdmEnumType enumType) + { + this.WriteSummaryCommentForEnumType(this.context.EnableNamingAlias ? Customization.CustomizeNaming(enumType.Name) : enumType.Name); + if (enumType.IsFlags) + { + this.WriteEnumFlags(); + } + + string underlyingType = string.Empty; + if (enumType.UnderlyingType != null && enumType.UnderlyingType.PrimitiveKind != EdmPrimitiveTypeKind.Int32) + { + underlyingType = Utils.GetClrTypeName(enumType.UnderlyingType, this); + underlyingType = this.EnumUnderlyingTypeMarker + underlyingType; + } + + this.WriteEnumDeclaration(this.context.EnableNamingAlias ? GetFixedName(Customization.CustomizeNaming(enumType.Name)) : GetFixedName(enumType.Name), enumType.Name, underlyingType); + this.WriteMembersForEnumType(enumType.Members); + this.WriteEnumEnd(); + } + + internal void WriteStructurdTypeDeclaration(IEdmStructuredType structuredType, string baseEntityType, string typeNameSuffix = null) + { + string abstractModifier = structuredType.IsAbstract && typeNameSuffix == null ? this.AbstractModifier : string.Empty; + string baseTypeName = baseEntityType; + + if (typeNameSuffix == null) + { + if (structuredType.BaseType == null) + { + if (this.context.UseDataServiceCollection) + { + if (this.context.TargetLanguage == LanguageOption.CSharp) + { + baseTypeName += string.IsNullOrEmpty(baseTypeName) ? this.ClassInheritMarker : ", "; + } + + baseTypeName += this.NotifyPropertyChangedModifier; + } + } + else + { + IEdmSchemaElement baseType = (IEdmSchemaElement)structuredType.BaseType; + string baseTypeFixedName = this.context.EnableNamingAlias ? GetFixedName(Customization.CustomizeNaming(baseType.Name)) : GetFixedName(baseType.Name); + baseTypeName = ((IEdmSchemaElement)structuredType).Namespace == baseType.Namespace ? baseTypeFixedName : this.context.GetPrefixedFullName(baseType, baseTypeFixedName, this); + baseTypeName = this.ClassInheritMarker + baseTypeName; + } + } + + string structuredTypeName = this.context.EnableNamingAlias ? + Customization.CustomizeNaming(((IEdmSchemaElement)structuredType).Name) : ((IEdmSchemaElement)structuredType).Name; + this.WriteClassStartForStructuredType(abstractModifier, GetFixedName(structuredTypeName + typeNameSuffix), ((IEdmSchemaElement)structuredType).Name + typeNameSuffix, baseTypeName); + } + + internal string GetSourceOrReturnTypeName(IEdmTypeReference typeReference) + { + IEdmCollectionType edmCollectionType = typeReference.Definition as IEdmCollectionType; + bool addNullableTemplate = true; + if (edmCollectionType != null) + { + typeReference = edmCollectionType.ElementType; + addNullableTemplate = false; + } + + return Utils.GetClrTypeName(typeReference, this.context.UseDataServiceCollection, this, this.context, addNullableTemplate); + } + + internal void GetParameterStrings(bool isBound, bool isAction, IEdmOperationParameter[] parameters, out string parameterString, out string parameterTypes, out string parameterExpressionString, out string parameterValues, out bool useEntityReference) + { + parameterString = string.Empty; + parameterExpressionString = string.Empty; + parameterTypes = string.Empty; + parameterValues = string.Empty; + useEntityReference = false; + + int n = parameters.Count(); + for (int i = isBound ? 1 : 0; i < n; ++i) + { + IEdmOperationParameter param = parameters[i]; + if (i == (isBound ? 1 : 0)) + { + if (this.context.TargetLanguage == LanguageOption.CSharp) + { + parameterExpressionString += "\r\n "; + } + else + { + parameterExpressionString += "\r\n "; + } + } + + string typeName = Utils.GetClrTypeName(param.Type, this.context.UseDataServiceCollection, this, this.context, true, true, true); + if (this.context.TargetLanguage == LanguageOption.CSharp) + { + parameterString += typeName; + parameterString += (" " + GetFixedName(param.Name)); + } + else if (this.context.TargetLanguage == LanguageOption.VB) + { + parameterString += GetFixedName(param.Name); + parameterString += (this.EnumUnderlyingTypeMarker + typeName); + } + + parameterString += i == n - 1 ? string.Empty : ", "; + parameterTypes += string.Format(this.TypeofFormatter, typeName) + ", "; + parameterExpressionString += this.GetParameterExpressionString(param, typeName) + ", "; + + if (i != (isBound ? 1 : 0)) + { + parameterValues += ",\r\n "; + } + + if (isAction) + { + parameterValues += string.Format(this.BodyOperationParameterConstructor, param.Name, GetFixedName(param.Name)); + } + else if (param.Type.IsEntity() || (param.Type.IsCollection() && param.Type.AsCollection().ElementType().IsEntity())) + { + useEntityReference = true; + parameterValues += string.Format(this.UriEntityOperationParameterConstructor, param.Name, GetFixedName(param.Name),"useEntityReference"); + } + else + { + parameterValues += string.Format(this.UriOperationParameterConstructor, param.Name, GetFixedName(param.Name)); + } + } + } + + internal string GetParameterExpressionString(IEdmOperationParameter param, string typeName) + { + string clrTypeName; + IEdmType edmType = param.Type.Definition; + IEdmPrimitiveType edmPrimitiveType = edmType as IEdmPrimitiveType; + if (edmPrimitiveType != null) + { + clrTypeName = Utils.GetClrTypeName(edmPrimitiveType, this); + if (param.Type.IsNullable && !this.ClrReferenceTypes.Contains(edmPrimitiveType.PrimitiveKind)) + { + clrTypeName += "?"; + } + + return string.Format(this.ConstantExpressionConstructorWithType, GetFixedName(param.Name), clrTypeName); + } + + return string.Format(this.ConstantExpressionConstructorWithType, GetFixedName(param.Name), typeName); + } + + // This is to solve duplicate names between property and type + internal void SetPropertyIdentifierMappingsIfNameConflicts(string typeName, IEdmStructuredType structuredType) + { + if (this.context.EnableNamingAlias) + { + typeName = Customization.CustomizeNaming(typeName); + } + + // PropertyName in VB is case-insensitive. + bool isLanguageCaseSensitive = this.context.TargetLanguage == LanguageOption.CSharp; + + // In VB, it is allowed that a type has a property whose name is same with the type's name + bool allowPropertyNameSameWithTypeName = this.context.TargetLanguage == LanguageOption.VB; + + Func customizePropertyName = (name) => { return this.context.EnableNamingAlias ? Customization.CustomizeNaming(name) : name; }; + + var propertyGroups = structuredType.Properties() + .GroupBy(p => isLanguageCaseSensitive ? customizePropertyName(p.Name) : customizePropertyName(p.Name).ToUpperInvariant()); + + // If the group contains more than one property, or the property in the group has the same name with the type (only for C#), we need to rename the property + var propertyToBeRenamedGroups = propertyGroups.Where(g => g.Count() > 1 || !allowPropertyNameSameWithTypeName && g.Key == typeName); + + var knownIdentifiers = propertyGroups.Select(g => customizePropertyName(g.First().Name)).ToList(); + if(!allowPropertyNameSameWithTypeName && !knownIdentifiers.Contains(typeName)) + { + knownIdentifiers.Add(typeName); + } + UniqueIdentifierService uniqueIdentifierService = + new UniqueIdentifierService(knownIdentifiers, isLanguageCaseSensitive); + + IdentifierMappings.Clear(); + foreach (IGrouping g in propertyToBeRenamedGroups) + { + bool hasPropertyNameSameWithCustomizedPropertyName = false; + int itemCount = g.Count(); + for (int i = 0; i < itemCount; i++) + { + var property = g.ElementAt(i); + var customizedPropertyName = customizePropertyName(property.Name); + + if(this.context.EnableNamingAlias && customizedPropertyName == property.Name) + { + hasPropertyNameSameWithCustomizedPropertyName = true; + } + + if(isLanguageCaseSensitive) + { + // If a property name is same as its customized property name, then we don't rename it. + // Or we don't rename the last property in the group + if(customizedPropertyName != typeName + && (customizedPropertyName == property.Name + || (!hasPropertyNameSameWithCustomizedPropertyName && i == itemCount-1))) + { + continue; + } + } + else + { + // When EnableNamingAlias = true, If a property name is same as its customized property name, then we don't rename it. + // Or we don't rename the last property in the group. + if((this.context.EnableNamingAlias && customizedPropertyName == property.Name) + || (!hasPropertyNameSameWithCustomizedPropertyName && i == itemCount-1)) + { + continue; + } + } + var renamedPropertyName = uniqueIdentifierService.GetUniqueIdentifier(customizedPropertyName); + IdentifierMappings.Add(property.Name, renamedPropertyName); + } + } + } + + internal void WriteTypeStaticCreateMethod(string typeName, IEdmStructuredType structuredType) + { + Debug.Assert(structuredType != null, "structuredType != null"); + if (structuredType.IsAbstract) + { + return; + } + + Func hasDefault = p => p.PropertyKind == EdmPropertyKind.Structural && ((IEdmStructuralProperty)p).DefaultValueString != null; + + if (this.context.EnableNamingAlias) + { + typeName = Customization.CustomizeNaming(typeName); + } + + IEnumerable parameters = structuredType.Properties() + .Where(p => !p.Type.IsNullable && !p.Type.IsCollection() && !hasDefault(p)); + if (!parameters.Any()) + { + return; + } + + this.WriteSummaryCommentForStaticCreateMethod(typeName); + + UniqueIdentifierService uniqueIdentifierService = new UniqueIdentifierService( /*IsLanguageCaseSensitive*/true); + string instanceName = GetFixedName(uniqueIdentifierService.GetUniqueParameterName(typeName)); + KeyValuePair[] propertyToParameterNamePairs = parameters + .Select(p => + new KeyValuePair(p, + uniqueIdentifierService.GetUniqueParameterName( + IdentifierMappings.ContainsKey(p.Name) ? IdentifierMappings[p.Name] : p.Name))) + .ToArray(); + + foreach (var propertyToParameterNamePair in propertyToParameterNamePairs) + { + string propertyName = propertyToParameterNamePair.Key.Name; + propertyName = IdentifierMappings.ContainsKey(propertyName) ? + IdentifierMappings[propertyName] : (this.context.EnableNamingAlias ? Customization.CustomizeNaming(propertyName) : propertyName); + this.WriteParameterCommentForStaticCreateMethod(propertyToParameterNamePair.Value, propertyName); + } + + propertyToParameterNamePairs = propertyToParameterNamePairs + .Select(p => p = new KeyValuePair(p.Key, GetFixedName(p.Value))) + .ToArray(); + + this.WriteDeclarationStartForStaticCreateMethod(typeName, GetFixedName(typeName)); + this.WriteStaticCreateMethodParameters(propertyToParameterNamePairs); + this.WriteDeclarationEndForStaticCreateMethod(GetFixedName(typeName), instanceName); + + foreach (var propertyToParameterNamePair in propertyToParameterNamePairs) + { + IEdmProperty property = propertyToParameterNamePair.Key; + string parameterName = propertyToParameterNamePair.Value; + + Debug.Assert(!property.Type.IsCollection(), "!property.Type.IsCollection()"); + Debug.Assert(!property.Type.IsNullable, "!property.Type.IsNullable"); + + // The static create method only sets non-nullable properties. We should add the null check if the type of the property is not a clr ValueType. + // For now we add the null check if the property type is non-primitive. We should add the null check for non-ValueType primitives in the future. + if (!property.Type.IsPrimitive() && !property.Type.IsEnum()) + { + this.WriteParameterNullCheckForStaticCreateMethod(parameterName); + } + + var uniqIdentifier = IdentifierMappings.ContainsKey(property.Name) ? + IdentifierMappings[property.Name] : (this.context.EnableNamingAlias ? Customization.CustomizeNaming(property.Name) : property.Name); + this.WritePropertyValueAssignmentForStaticCreateMethod(instanceName, + GetFixedName(uniqIdentifier), + parameterName); + } + + this.WriteMethodEndForStaticCreateMethod(instanceName); + } + + internal void WriteStaticCreateMethodParameters(KeyValuePair[] propertyToParameterPairs) + { + if (propertyToParameterPairs.Length == 0) + { + return; + } + + // If the number of parameters are greater than 5, we put them in separate lines. + string parameterSeparator = propertyToParameterPairs.Length > 5 ? this.ParameterSeparator : ", "; + for (int idx = 0; idx < propertyToParameterPairs.Length; idx++) + { + KeyValuePair propertyToParameterPair = propertyToParameterPairs[idx]; + + string parameterType = Utils.GetClrTypeName(propertyToParameterPair.Key.Type, this.context.UseDataServiceCollection, this, this.context); + string parameterName = propertyToParameterPair.Value; + if (idx == propertyToParameterPairs.Length - 1) + { + // No separator after the last parameter. + parameterSeparator = string.Empty; + } + + this.WriteParameterForStaticCreateMethod(parameterType, GetFixedName(parameterName), parameterSeparator); + } + } + + internal void WritePropertiesForStructuredType(IEnumerable properties) + { + bool useDataServiceCollection = this.context.UseDataServiceCollection; + + var propertyInfos = properties.Select(property => + { + string propertyName = IdentifierMappings.ContainsKey(property.Name) ? + IdentifierMappings[property.Name] : (this.context.EnableNamingAlias ? Customization.CustomizeNaming(property.Name) : property.Name); + + return new + { + PropertyType = Utils.GetClrTypeName(property.Type, useDataServiceCollection, this, this.context), + PropertyVanillaName = property.Name, + PropertyName = propertyName, + FixedPropertyName = GetFixedName(propertyName), + PrivatePropertyName = "_" + propertyName, + PropertyInitializationValue = Utils.GetPropertyInitializationValue(property, useDataServiceCollection, this, this.context) + }; + }).ToList(); + + // Private name should not confict with field name + UniqueIdentifierService uniqueIdentifierService = new UniqueIdentifierService(propertyInfos.Select(_ => _.FixedPropertyName), + this.context.TargetLanguage == LanguageOption.CSharp); + + foreach (var propertyInfo in propertyInfos) + { + string privatePropertyName = uniqueIdentifierService.GetUniqueIdentifier("_" + propertyInfo.PropertyName); + + this.WritePropertyForStructuredType( + propertyInfo.PropertyType, + propertyInfo.PropertyVanillaName, + propertyInfo.PropertyName, + propertyInfo.FixedPropertyName, + privatePropertyName, + propertyInfo.PropertyInitializationValue, + useDataServiceCollection); + } + } + + internal void WriteMembersForEnumType(IEnumerable members) + { + int n = members.Count(); + for (int idx = 0; idx < n; ++idx) + { + IEdmEnumMember member = members.ElementAt(idx); + string value = string.Empty; + if (member.Value != null) + { + IEdmIntegerValue integerValue = member.Value as IEdmIntegerValue; + if (integerValue != null) + { + value = " = " + integerValue.Value.ToString(CultureInfo.InvariantCulture); + } + } + + string memberName = this.context.EnableNamingAlias ? Customization.CustomizeNaming(member.Name) : member.Name; + this.WriteMemberForEnumType(GetFixedName(memberName) + value, member.Name, idx == n - 1); + } + } + + internal string GetFixedName(string originalName) + { + string fixedName = originalName; + + if (this.LanguageKeywords.Contains(fixedName)) + { + fixedName = string.Format(this.FixPattern, fixedName); + } + + return fixedName; + } + + internal string GetElementTypeName(IEdmEntityType elementType, IEdmEntityContainer container) + { + string elementTypeName = elementType.Name; + + if (this.context.EnableNamingAlias) + { + elementTypeName = Customization.CustomizeNaming(elementTypeName); + } + + if (elementType.Namespace != container.Namespace) + { + elementTypeName = this.context.GetPrefixedFullName(elementType, GetFixedName(elementTypeName), this); + } + + return elementTypeName; + } +} + +/// +/// Base class for text transformation +/// +[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "11.0.0.0")] +public abstract class TemplateBase +{ + #region Fields + private global::System.Text.StringBuilder generationEnvironmentField; + private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField; + private global::System.Collections.Generic.List indentLengthsField; + private string currentIndentField = ""; + private bool endsWithNewline; + private global::System.Collections.Generic.IDictionary sessionField; + #endregion + #region Properties + /// + /// The string builder that generation-time code is using to assemble generated output + /// + protected System.Text.StringBuilder GenerationEnvironment + { + get + { + if ((this.generationEnvironmentField == null)) + { + this.generationEnvironmentField = new global::System.Text.StringBuilder(); + } + return this.generationEnvironmentField; + } + set + { + this.generationEnvironmentField = value; + } + } + /// + /// The error collection for the generation process + /// + public System.CodeDom.Compiler.CompilerErrorCollection Errors + { + get + { + if ((this.errorsField == null)) + { + this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection(); + } + return this.errorsField; + } + } + /// + /// A list of the lengths of each indent that was added with PushIndent + /// + private System.Collections.Generic.List indentLengths + { + get + { + if ((this.indentLengthsField == null)) + { + this.indentLengthsField = new global::System.Collections.Generic.List(); + } + return this.indentLengthsField; + } + } + /// + /// Gets the current indent we use when adding lines to the output + /// + public string CurrentIndent + { + get + { + return this.currentIndentField; + } + } + /// + /// Current transformation session + /// + public virtual global::System.Collections.Generic.IDictionary Session + { + get + { + return this.sessionField; + } + set + { + this.sessionField = value; + } + } + #endregion + + /// + /// Create the template output + /// + public abstract string TransformText(); + + #region Transform-time helpers + /// + /// Write text directly into the generated output + /// + public void Write(string textToAppend) + { + if (string.IsNullOrEmpty(textToAppend)) + { + return; + } + // If we're starting off, or if the previous text ended with a newline, + // we have to append the current indent first. + if (((this.GenerationEnvironment.Length == 0) + || this.endsWithNewline)) + { + this.GenerationEnvironment.Append(this.currentIndentField); + this.endsWithNewline = false; + } + // Check if the current text ends with a newline + if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture)) + { + this.endsWithNewline = true; + } + // This is an optimization. If the current indent is "", then we don't have to do any + // of the more complex stuff further down. + if ((this.currentIndentField.Length == 0)) + { + this.GenerationEnvironment.Append(textToAppend); + return; + } + // Everywhere there is a newline in the text, add an indent after it + textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField)); + // If the text ends with a newline, then we should strip off the indent added at the very end + // because the appropriate indent will be added when the next time Write() is called + if (this.endsWithNewline) + { + this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length)); + } + else + { + this.GenerationEnvironment.Append(textToAppend); + } + } + /// + /// Write text directly into the generated output + /// + public void WriteLine(string textToAppend) + { + this.Write(textToAppend); + this.GenerationEnvironment.AppendLine(); + this.endsWithNewline = true; + } + /// + /// Write formatted text directly into the generated output + /// + public void Write(string format, params object[] args) + { + this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); + } + /// + /// Write formatted text directly into the generated output + /// + public void WriteLine(string format, params object[] args) + { + this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args)); + } + /// + /// Raise an error + /// + public void Error(string message) + { + System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); + error.ErrorText = message; + this.Errors.Add(error); + } + /// + /// Raise a warning + /// + public void Warning(string message) + { + System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError(); + error.ErrorText = message; + error.IsWarning = true; + this.Errors.Add(error); + } + /// + /// Increase the indent + /// + public void PushIndent(string indent) + { + if ((indent == null)) + { + throw new global::System.ArgumentNullException("indent"); + } + this.currentIndentField = (this.currentIndentField + indent); + this.indentLengths.Add(indent.Length); + } + /// + /// Remove the last indent that was added with PushIndent + /// + public string PopIndent() + { + string returnValue = ""; + if ((this.indentLengths.Count > 0)) + { + int indentLength = this.indentLengths[(this.indentLengths.Count - 1)]; + this.indentLengths.RemoveAt((this.indentLengths.Count - 1)); + if ((indentLength > 0)) + { + returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength)); + this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength)); + } + } + return returnValue; + } + /// + /// Remove any indentation + /// + public void ClearIndent() + { + this.indentLengths.Clear(); + this.currentIndentField = ""; + } + #endregion + #region ToString Helpers + /// + /// Utility class to produce culture-oriented representation of an object as a string. + /// + public class ToStringInstanceHelper + { + private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture; + /// + /// Gets or sets format provider to be used by ToStringWithCulture method. + /// + public System.IFormatProvider FormatProvider + { + get + { + return this.formatProviderField ; + } + set + { + if ((value != null)) + { + this.formatProviderField = value; + } + } + } + /// + /// This is called from the compile/run appdomain to convert objects within an expression block to a string + /// + public string ToStringWithCulture(object objectToConvert) + { + if ((objectToConvert == null)) + { + throw new global::System.ArgumentNullException("objectToConvert"); + } + System.Type t = objectToConvert.GetType(); + System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] { + typeof(System.IFormatProvider)}); + if ((method == null)) + { + return objectToConvert.ToString(); + } + else + { + return ((string)(method.Invoke(objectToConvert, new object[] { + this.formatProviderField }))); + } + } + } + private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper(); + /// + /// Helper to produce culture-oriented representation of an object as a string + /// + public ToStringInstanceHelper ToStringHelper + { + get + { + return this.toStringHelperField; + } + } + #endregion +} + +/// +/// Service making names within a scope unique. Initialize a new instance for every scope. +/// +internal sealed class UniqueIdentifierService +{ + // This is the list of keywords we check against when creating parameter names from propert. + // If a name matches this keyword we prefix it. + private static readonly string[] Keywords = new string[] {"class", "event"}; + + /// + /// Hash set to detect identifier collision. + /// + private readonly HashSet knownIdentifiers; + + /// + /// Constructs a . + /// + /// true if the language we are generating the code for is case sensitive, false otherwise. + internal UniqueIdentifierService(bool caseSensitive) + { + this.knownIdentifiers = new HashSet(caseSensitive ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase); + } + + /// + /// Constructs a . + /// + /// identifiers used to detect collision. + /// true if the language we are generating the code for is case sensitive, false otherwise. + internal UniqueIdentifierService(IEnumerable identifiers, bool caseSensitive) + { + this.knownIdentifiers = new HashSet(identifiers ?? Enumerable.Empty(), caseSensitive ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase); + } + + /// + /// Given an identifier, makes it unique within the scope by adding + /// a suffix (1, 2, 3, ...), and returns the adjusted identifier. + /// + /// Identifier. Must not be null or empty. + /// Identifier adjusted to be unique within the scope. + internal string GetUniqueIdentifier(string identifier) + { + Debug.Assert(!string.IsNullOrEmpty(identifier), "identifier is null or empty"); + + // find a unique name by adding suffix as necessary + int numberOfConflicts = 0; + string uniqueIdentifier = identifier; + while (this.knownIdentifiers.Contains(uniqueIdentifier)) + { + ++numberOfConflicts; + uniqueIdentifier = identifier + numberOfConflicts.ToString(CultureInfo.InvariantCulture); + } + + // remember the identifier in this scope + Debug.Assert(!this.knownIdentifiers.Contains(uniqueIdentifier), "we just made it unique"); + this.knownIdentifiers.Add(uniqueIdentifier); + + return uniqueIdentifier; + } + + /// + /// Fix up the given parameter name and make it unique. + /// + /// Parameter name. + /// Fixed parameter name. + internal string GetUniqueParameterName(string name) + { + name = Utils.CamelCase(name); + + // FxCop consider 'iD' as violation, we will change any property that is 'id'(case insensitive) to 'ID' + if (StringComparer.OrdinalIgnoreCase.Equals(name, "id")) + { + name = "ID"; + } + + return this.GetUniqueIdentifier(name); + } +} + +/// +/// Utility class. +/// +internal static class Utils +{ + /// + /// Serializes the xml element to a string. + /// + /// The xml element to serialize. + /// The string representation of the xml. + internal static string SerializeToString(XElement xml) + { + // because comment nodes can contain special characters that are hard to embed in VisualBasic, remove them here + xml.DescendantNodes().OfType().Remove(); + + var stringBuilder = new StringBuilder(); + using (var writer = XmlWriter.Create( + stringBuilder, + new XmlWriterSettings + { + OmitXmlDeclaration = true, + NewLineHandling = NewLineHandling.Replace, + Indent = true, + })) + { + xml.WriteTo(writer); + } + + return stringBuilder.ToString(); + } + + /// + /// Changes the text to use camel case, which lower case for the first character. + /// + /// Text to convert. + /// The converted text in camel case + internal static string CamelCase(string text) + { + if (string.IsNullOrEmpty(text)) + { + return text; + } + + if (text.Length == 1) + { + return text[0].ToString(CultureInfo.InvariantCulture).ToLowerInvariant(); + } + + return text[0].ToString(CultureInfo.InvariantCulture).ToLowerInvariant() + text.Substring(1); + } + + /// + /// Changes the text to use pascal case, which upper case for the first character. + /// + /// Text to convert. + /// The converted text in pascal case + internal static string PascalCase(string text) + { + if (string.IsNullOrEmpty(text)) + { + return text; + } + + if (text.Length == 1) + { + return text[0].ToString(CultureInfo.InvariantCulture).ToUpperInvariant(); + } + + return text[0].ToString(CultureInfo.InvariantCulture).ToUpperInvariant() + text.Substring(1); + } + + /// + /// Gets the clr type name from the give type reference. + /// + /// The type reference in question. + /// true to use the DataServicCollection type for entity collections and the ObservableCollection type for non-entity collections, + /// false to use Collection for collections. + /// ODataClientTemplate instance that call this method. + /// CodeGenerationContext instance in the clientTemplate. + /// This flag indicates whether to return the type name in nullable format + /// The flag indicates whether the namespace need to be added by global prefix + /// This flag indicates whether the edmTypeReference is for an operation parameter + /// The clr type name of the type reference. + internal static string GetClrTypeName(IEdmTypeReference edmTypeReference, bool useDataServiceCollection, ODataClientTemplate clientTemplate, CodeGenerationContext context, bool addNullableTemplate = true, bool needGlobalPrefix = true, bool isOperationParameter = false) + { + string clrTypeName; + IEdmType edmType = edmTypeReference.Definition; + IEdmPrimitiveType edmPrimitiveType = edmType as IEdmPrimitiveType; + if (edmPrimitiveType != null) + { + clrTypeName = Utils.GetClrTypeName(edmPrimitiveType, clientTemplate); + if (edmTypeReference.IsNullable && !clientTemplate.ClrReferenceTypes.Contains(edmPrimitiveType.PrimitiveKind) && addNullableTemplate) + { + clrTypeName = string.Format(clientTemplate.SystemNullableStructureTemplate, clrTypeName); + } + } + else + { + IEdmComplexType edmComplexType = edmType as IEdmComplexType; + if (edmComplexType != null) + { + clrTypeName = context.GetPrefixedFullName(edmComplexType, + context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(edmComplexType.Name)) : clientTemplate.GetFixedName(edmComplexType.Name), clientTemplate); + } + else + { + IEdmEnumType edmEnumType = edmType as IEdmEnumType; + if (edmEnumType != null) + { + clrTypeName = context.GetPrefixedFullName(edmEnumType, + context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(edmEnumType.Name)) : clientTemplate.GetFixedName(edmEnumType.Name), clientTemplate, needGlobalPrefix); + if (edmTypeReference.IsNullable && addNullableTemplate) + { + clrTypeName = string.Format(clientTemplate.SystemNullableStructureTemplate, clrTypeName); + } + } + else + { + IEdmEntityType edmEntityType = edmType as IEdmEntityType; + if (edmEntityType != null) + { + clrTypeName = context.GetPrefixedFullName(edmEntityType, + context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(edmEntityType.Name)) : clientTemplate.GetFixedName(edmEntityType.Name), clientTemplate); + } + else + { + IEdmCollectionType edmCollectionType = (IEdmCollectionType)edmType; + IEdmTypeReference elementTypeReference = edmCollectionType.ElementType; + IEdmPrimitiveType primitiveElementType = elementTypeReference.Definition as IEdmPrimitiveType; + if (primitiveElementType != null) + { + clrTypeName = Utils.GetClrTypeName(primitiveElementType, clientTemplate); + } + else + { + IEdmSchemaElement schemaElement = (IEdmSchemaElement)elementTypeReference.Definition; + clrTypeName = context.GetPrefixedFullName(schemaElement, + context.EnableNamingAlias ? clientTemplate.GetFixedName(Customization.CustomizeNaming(schemaElement.Name)) : clientTemplate.GetFixedName(schemaElement.Name), clientTemplate); + } + + string collectionTypeName = isOperationParameter + ? clientTemplate.ICollectionOfTStructureTemplate + : (useDataServiceCollection + ? (elementTypeReference.TypeKind() == EdmTypeKind.Entity + ? clientTemplate.DataServiceCollectionStructureTemplate + : clientTemplate.ObservableCollectionStructureTemplate) + : clientTemplate.ObjectModelCollectionStructureTemplate); + + clrTypeName = string.Format(collectionTypeName, clrTypeName); + } + } + } + } + + return clrTypeName; + } + + /// + /// Gets the value expression to initualize the property with. + /// + /// The property in question. + /// true to use the DataServicCollection type for entity collections and the ObservableCollection type for non-entity collections, + /// false to use Collection for collections. + /// ODataClientTemplate instance that call this method. + /// CodeGenerationContext instance in the clientTemplate. + /// The value expression to initualize the property with. + internal static string GetPropertyInitializationValue(IEdmProperty property, bool useDataServiceCollection, ODataClientTemplate clientTemplate, CodeGenerationContext context) + { + IEdmTypeReference edmTypeReference = property.Type; + IEdmCollectionTypeReference edmCollectionTypeReference = edmTypeReference as IEdmCollectionTypeReference; + if (edmCollectionTypeReference == null) + { + IEdmStructuralProperty structuredProperty = property as IEdmStructuralProperty; + if (structuredProperty != null) + { + if (!string.IsNullOrEmpty(structuredProperty.DefaultValueString)) + { + string valueClrType = GetClrTypeName(edmTypeReference, useDataServiceCollection, clientTemplate, context); + string defaultValue = structuredProperty.DefaultValueString; + bool isCSharpTemplate = clientTemplate is ODataClientCSharpTemplate; + if (edmTypeReference.Definition.TypeKind == EdmTypeKind.Enum) + { + var enumValues = defaultValue.Split(','); + string fullenumTypeName = GetClrTypeName(edmTypeReference, useDataServiceCollection, clientTemplate, context); + string enumTypeName = GetClrTypeName(edmTypeReference, useDataServiceCollection, clientTemplate, context, false, false); + List customizedEnumValues = new List(); + foreach(var enumValue in enumValues) + { + string currentEnumValue = enumValue.Trim(); + int indexFirst = currentEnumValue.IndexOf('\'') + 1; + int indexLast = currentEnumValue.LastIndexOf('\''); + if (indexFirst > 0 && indexLast > indexFirst) + { + currentEnumValue = currentEnumValue.Substring(indexFirst, indexLast - indexFirst); + } + + var customizedEnumValue = context.EnableNamingAlias ? Customization.CustomizeNaming(currentEnumValue) : currentEnumValue; + if (isCSharpTemplate) + { + currentEnumValue = "(" + fullenumTypeName + ")" + clientTemplate.EnumTypeName + ".Parse(" + clientTemplate.SystemTypeTypeName + ".GetType(\"" + enumTypeName + "\"), \"" + customizedEnumValue + "\")"; + } + else + { + currentEnumValue = clientTemplate.EnumTypeName + ".Parse(" + clientTemplate.SystemTypeTypeName + ".GetType(\"" + enumTypeName + "\"), \"" + currentEnumValue + "\")"; + } + customizedEnumValues.Add(currentEnumValue); + } + if (isCSharpTemplate) + { + return string.Join(" | ", customizedEnumValues); + } + else + { + return string.Join(" Or ", customizedEnumValues); + } + } + + if (valueClrType.Equals(clientTemplate.StringTypeName)) + { + defaultValue = "\"" + defaultValue + "\""; + } + else if (valueClrType.Equals(clientTemplate.BinaryTypeName)) + { + defaultValue = "System.Text.Encoding.UTF8.GetBytes(\"" + defaultValue + "\")"; + } + else if (valueClrType.Equals(clientTemplate.SingleTypeName)) + { + if (isCSharpTemplate) + { + defaultValue = defaultValue.EndsWith("f", StringComparison.OrdinalIgnoreCase) ? defaultValue : defaultValue + "f"; + } + else + { + defaultValue = defaultValue.EndsWith("f", StringComparison.OrdinalIgnoreCase) ? defaultValue : defaultValue + "F"; + } + } + else if (valueClrType.Equals(clientTemplate.DecimalTypeName)) + { + if (isCSharpTemplate) + { + // decimal in C# must be initialized with 'm' at the end, like Decimal dec = 3.00m + defaultValue = defaultValue.EndsWith("m", StringComparison.OrdinalIgnoreCase) ? defaultValue : defaultValue + "m"; + } + else + { + // decimal in VB must be initialized with 'D' at the end, like Decimal dec = 3.00D + defaultValue = defaultValue.ToLower().Replace("m", "D"); + defaultValue = defaultValue.EndsWith("D", StringComparison.OrdinalIgnoreCase) ? defaultValue : defaultValue + "D"; + } + } + else if (valueClrType.Equals(clientTemplate.GuidTypeName) + | valueClrType.Equals(clientTemplate.DateTimeOffsetTypeName) + | valueClrType.Equals(clientTemplate.DateTypeName) + | valueClrType.Equals(clientTemplate.TimeOfDayTypeName)) + { + defaultValue = valueClrType + ".Parse(\"" + defaultValue + "\")"; + } + else if (valueClrType.Equals(clientTemplate.DurationTypeName)) + { + defaultValue = clientTemplate.XmlConvertClassName + ".ToTimeSpan(\"" + defaultValue + "\")"; + } + else if (valueClrType.Contains("Microsoft.Spatial")) + { + defaultValue = string.Format(clientTemplate.GeoTypeInitializePattern, valueClrType, defaultValue); + } + + return defaultValue; + } + else + { + // doesn't have a default value + return null; + } + } + else + { + // only structured property has default value + return null; + } + } + else + { + string constructorParameters; + if (edmCollectionTypeReference.ElementType().IsEntity() && useDataServiceCollection) + { + constructorParameters = clientTemplate.DataServiceCollectionConstructorParameters; + } + else + { + constructorParameters = "()"; + } + + string clrTypeName = GetClrTypeName(edmTypeReference, useDataServiceCollection, clientTemplate, context); + return clientTemplate.NewModifier + clrTypeName + constructorParameters; + } + } + + /// + /// Gets the clr type name from the give Edm primitive type. + /// + /// The Edm primitive type in question. + /// ODataClientTemplate instance that call this method. + /// The clr type name of the Edm primitive type. + internal static string GetClrTypeName(IEdmPrimitiveType edmPrimitiveType, ODataClientTemplate clientTemplate) + { + EdmPrimitiveTypeKind kind = edmPrimitiveType.PrimitiveKind; + + string type="UNKNOWN"; + if (kind==EdmPrimitiveTypeKind.Int32) + { + type= clientTemplate.Int32TypeName; + } + else if (kind== EdmPrimitiveTypeKind.String) + { + type= clientTemplate.StringTypeName; + } + else if (kind==EdmPrimitiveTypeKind.Binary) + { + type= clientTemplate.BinaryTypeName; + } + else if (kind==EdmPrimitiveTypeKind.Decimal) + { + type= clientTemplate.DecimalTypeName; + } + else if (kind==EdmPrimitiveTypeKind.Int16) + { + type= clientTemplate.Int16TypeName; + } + else if(kind==EdmPrimitiveTypeKind.Single) + { + type= clientTemplate.SingleTypeName; + } + else if (kind==EdmPrimitiveTypeKind.Boolean) + { + type= clientTemplate.BooleanTypeName; + } + else if (kind== EdmPrimitiveTypeKind.Double) + { + type= clientTemplate.DoubleTypeName; + } + else if (kind== EdmPrimitiveTypeKind.Guid) + { + type= clientTemplate.GuidTypeName; + } + else if (kind== EdmPrimitiveTypeKind.Byte) + { + type= clientTemplate.ByteTypeName; + } + else if (kind== EdmPrimitiveTypeKind.Int64) + { + type= clientTemplate.Int64TypeName; + } + else if (kind== EdmPrimitiveTypeKind.SByte) + { + type= clientTemplate.SByteTypeName; + } + else if (kind == EdmPrimitiveTypeKind.Stream) + { + type= clientTemplate.DataServiceStreamLinkTypeName; + } + else if (kind== EdmPrimitiveTypeKind.Geography) + { + type= clientTemplate.GeographyTypeName; + } + else if (kind== EdmPrimitiveTypeKind.GeographyPoint) + { + type= clientTemplate.GeographyPointTypeName; + } + else if (kind== EdmPrimitiveTypeKind.GeographyLineString) + { + type= clientTemplate.GeographyLineStringTypeName; + } + else if (kind== EdmPrimitiveTypeKind.GeographyPolygon) + { + type= clientTemplate.GeographyPolygonTypeName; + } + else if (kind== EdmPrimitiveTypeKind.GeographyCollection) + { + type= clientTemplate.GeographyCollectionTypeName; + } + else if (kind== EdmPrimitiveTypeKind.GeographyMultiPolygon) + { + type= clientTemplate.GeographyMultiPolygonTypeName; + } + else if (kind== EdmPrimitiveTypeKind.GeographyMultiLineString) + { + type= clientTemplate.GeographyMultiLineStringTypeName; + } + else if (kind== EdmPrimitiveTypeKind.GeographyMultiPoint) + { + type= clientTemplate.GeographyMultiPointTypeName; + } + else if (kind== EdmPrimitiveTypeKind.Geometry) + { + type= clientTemplate.GeometryTypeName; + } + else if (kind== EdmPrimitiveTypeKind.GeometryPoint) + { + type= clientTemplate.GeometryPointTypeName; + } + else if (kind== EdmPrimitiveTypeKind.GeometryLineString) + { + type= clientTemplate.GeometryLineStringTypeName; + } + else if (kind== EdmPrimitiveTypeKind.GeometryPolygon) + { + type= clientTemplate.GeometryPolygonTypeName; + } + else if (kind== EdmPrimitiveTypeKind.GeometryCollection) + { + type= clientTemplate.GeometryCollectionTypeName; + } + else if (kind== EdmPrimitiveTypeKind.GeometryMultiPolygon) + { + type= clientTemplate.GeometryMultiPolygonTypeName; + } + else if (kind== EdmPrimitiveTypeKind.GeometryMultiLineString) + { + type= clientTemplate.GeometryMultiLineStringTypeName; + } + else if (kind== EdmPrimitiveTypeKind.GeometryMultiPoint) + { + type= clientTemplate.GeometryMultiPointTypeName; + } + else if (kind== EdmPrimitiveTypeKind.DateTimeOffset) + { + type= clientTemplate.DateTimeOffsetTypeName; + } + else if (kind== EdmPrimitiveTypeKind.Duration) + { + type= clientTemplate.DurationTypeName; + } + else if (kind== EdmPrimitiveTypeKind.Date) + { + type= clientTemplate.DateTypeName; + } + else if (kind== EdmPrimitiveTypeKind.TimeOfDay) + { + type= clientTemplate.TimeOfDayTypeName; + } + else + { + throw new Exception("Type "+kind.ToString()+" is unrecognized"); + } + + return type; + } +} + +public sealed class ODataClientCSharpTemplate : ODataClientTemplate +{ + /// + /// Creates an instance of the ODataClientTemplate. + /// + /// The code generation context. + public ODataClientCSharpTemplate(CodeGenerationContext context) + : base(context) + { + } + + internal override string GlobalPrefix { get {return "global::"; } } + internal override string SystemTypeTypeName { get { return "global::System.Type"; } } + internal override string AbstractModifier { get { return " abstract"; } } + internal override string DataServiceActionQueryTypeName { get { return "global::Microsoft.OData.Client.DataServiceActionQuery"; } } + internal override string DataServiceActionQuerySingleOfTStructureTemplate { get { return "global::Microsoft.OData.Client.DataServiceActionQuerySingle<{0}>"; } } + internal override string DataServiceActionQueryOfTStructureTemplate { get { return "global::Microsoft.OData.Client.DataServiceActionQuery<{0}>"; } } + internal override string NotifyPropertyChangedModifier { get { return "global::System.ComponentModel.INotifyPropertyChanged"; } } + internal override string ClassInheritMarker { get { return " : "; } } + internal override string ParameterSeparator { get { return ", \r\n "; } } + internal override string KeyParameterSeparator { get { return ", \r\n "; } } + internal override string KeyDictionaryItemSeparator { get { return ", \r\n "; } } + internal override string SystemNullableStructureTemplate { get { return "global::System.Nullable<{0}>"; } } + internal override string ICollectionOfTStructureTemplate { get { return "global::System.Collections.Generic.ICollection<{0}>"; } } + internal override string DataServiceCollectionStructureTemplate { get { return "global::Microsoft.OData.Client.DataServiceCollection<{0}>"; } } + internal override string DataServiceQueryStructureTemplate { get { return "global::Microsoft.OData.Client.DataServiceQuery<{0}>"; } } + internal override string DataServiceQuerySingleStructureTemplate { get { return "global::Microsoft.OData.Client.DataServiceQuerySingle<{0}>"; } } + internal override string ObservableCollectionStructureTemplate { get { return "global::System.Collections.ObjectModel.ObservableCollection<{0}>"; } } + internal override string ObjectModelCollectionStructureTemplate { get { return "global::System.Collections.ObjectModel.Collection<{0}>"; } } + internal override string DataServiceCollectionConstructorParameters { get { return "(null, global::Microsoft.OData.Client.TrackingMode.None)"; } } + internal override string NewModifier { get { return "new "; } } + internal override string GeoTypeInitializePattern { get { return "global::Microsoft.Spatial.SpatialImplementation.CurrentImplementation.CreateWellKnownTextSqlFormatter(false).Read<{0}>(new global::System.IO.StringReader(\"{1}\"))"; } } + internal override string Int32TypeName { get { return "int"; } } + internal override string StringTypeName { get { return "string"; } } + internal override string BinaryTypeName { get { return "byte[]"; } } + internal override string DecimalTypeName { get { return "decimal"; } } + internal override string Int16TypeName { get { return "short"; } } + internal override string SingleTypeName { get { return "float"; } } + internal override string BooleanTypeName { get { return "bool"; } } + internal override string DoubleTypeName { get { return "double"; } } + internal override string GuidTypeName { get { return "global::System.Guid"; } } + internal override string ByteTypeName { get { return "byte"; } } + internal override string Int64TypeName { get { return "long"; } } + internal override string SByteTypeName { get { return "sbyte"; } } + internal override string DataServiceStreamLinkTypeName { get { return "global::Microsoft.OData.Client.DataServiceStreamLink"; } } + internal override string GeographyTypeName { get { return "global::Microsoft.Spatial.Geography"; } } + internal override string GeographyPointTypeName { get { return "global::Microsoft.Spatial.GeographyPoint"; } } + internal override string GeographyLineStringTypeName { get { return "global::Microsoft.Spatial.GeographyLineString"; } } + internal override string GeographyPolygonTypeName { get { return "global::Microsoft.Spatial.GeographyPolygon"; } } + internal override string GeographyCollectionTypeName { get { return "global::Microsoft.Spatial.GeographyCollection"; } } + internal override string GeographyMultiPolygonTypeName { get { return "global::Microsoft.Spatial.GeographyMultiPolygon"; } } + internal override string GeographyMultiLineStringTypeName { get { return "global::Microsoft.Spatial.GeographyMultiLineString"; } } + internal override string GeographyMultiPointTypeName { get { return "global::Microsoft.Spatial.GeographyMultiPoint"; } } + internal override string GeometryTypeName { get { return "global::Microsoft.Spatial.Geometry"; } } + internal override string GeometryPointTypeName { get { return "global::Microsoft.Spatial.GeometryPoint"; } } + internal override string GeometryLineStringTypeName { get { return "global::Microsoft.Spatial.GeometryLineString"; } } + internal override string GeometryPolygonTypeName { get { return "global::Microsoft.Spatial.GeometryPolygon"; } } + internal override string GeometryCollectionTypeName { get { return "global::Microsoft.Spatial.GeometryCollection"; } } + internal override string GeometryMultiPolygonTypeName { get { return "global::Microsoft.Spatial.GeometryMultiPolygon"; } } + internal override string GeometryMultiLineStringTypeName { get { return "global::Microsoft.Spatial.GeometryMultiLineString"; } } + internal override string GeometryMultiPointTypeName { get { return "global::Microsoft.Spatial.GeometryMultiPoint"; } } + internal override string DateTypeName { get { return "global::Microsoft.OData.Edm.Library.Date"; } } + internal override string DateTimeOffsetTypeName { get { return "global::System.DateTimeOffset"; } } + internal override string DurationTypeName { get { return "global::System.TimeSpan"; } } + internal override string TimeOfDayTypeName { get { return "global::Microsoft.OData.Edm.Library.TimeOfDay"; } } + internal override string XmlConvertClassName { get { return "global::System.Xml.XmlConvert"; } } + internal override string EnumTypeName { get { return "global::System.Enum"; } } + internal override string FixPattern { get { return "@{0}"; } } + internal override string EnumUnderlyingTypeMarker { get { return " : "; } } + internal override string ConstantExpressionConstructorWithType { get { return "global::System.Linq.Expressions.Expression.Constant({0}, typeof({1}))"; } } + internal override string TypeofFormatter { get { return "typeof({0})"; } } + internal override string UriOperationParameterConstructor { get { return "new global::Microsoft.OData.Client.UriOperationParameter(\"{0}\", {1})"; } } + internal override string UriEntityOperationParameterConstructor { get { return "new global::Microsoft.OData.Client.UriEntityOperationParameter(\"{0}\", {1}, {2})"; } } + internal override string BodyOperationParameterConstructor { get { return "new global::Microsoft.OData.Client.BodyOperationParameter(\"{0}\", {1})"; } } + internal override string BaseEntityType { get { return " : global::Microsoft.OData.Client.BaseEntityType"; } } + internal override string OverloadsModifier { get { return "new "; } } + internal override string ODataVersion { get { return "global::Microsoft.OData.Core.ODataVersion.V4"; } } + internal override string ParameterDeclarationTemplate { get { return "{0} {1}"; } } + internal override string DictionaryItemConstructor { get { return "{{ {0}, {1} }}"; } } + internal override HashSet LanguageKeywords { get { + if (CSharpKeywords == null) + { + CSharpKeywords = new HashSet(StringComparer.Ordinal) + { + "abstract", "as", "base", "byte", "bool", "break", "case", "catch", "char", "checked", "class", "const", "continue", + "decimal", "default", "delegate", "do", "double", "else", "enum", "event", "explicit", "extern", "false", "for", + "foreach", "finally", "fixed", "float", "goto", "if", "implicit", "in", "int", "interface", "internal", "is", "lock", + "long", "namespace", "new", "null", "object", "operator", "out", "override", "params", "private", "protected", "public", + "readonly", "ref", "return", "sbyte", "sealed", "string", "short", "sizeof", "stackalloc", "static", "struct", "switch", + "this", "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "virtual", "volatile", + "void", "while" + }; + } + return CSharpKeywords; + } } + private HashSet CSharpKeywords; + + internal override void WriteFileHeader() + { +#>//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:<#= Environment.Version #> +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +// Generation date: <#= DateTime.Now.ToString(global::System.Globalization.CultureInfo.CurrentCulture) #> +<#+ + } + + internal override void WriteNamespaceStart(string fullNamespace) + { +#> +namespace <#= fullNamespace #> +{ +<#+ + } + + internal override void WriteClassStartForEntityContainer(string originalContainerName, string containerName, string fixedContainerName) + { +#> + /// + /// There are no comments for <#= containerName #> in the schema. + /// +<#+ + if (this.context.EnableNamingAlias) + { +#> + [global::Microsoft.OData.Client.OriginalNameAttribute("<#= originalContainerName #>")] +<#+ + } +#> + public partial class <#= fixedContainerName #> : global::Microsoft.OData.Client.DataServiceContext + { +<#+ + } + + internal override void WriteMethodStartForEntityContainerConstructor(string containerName, string fixedContainerName) + { +#> + /// + /// Initialize a new <#= containerName #> object. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] + public <#= fixedContainerName #>(global::System.Uri serviceRoot) : + base(serviceRoot, global::Microsoft.OData.Client.ODataProtocolVersion.V4) + { +<#+ + } + + internal override void WriteKeyAsSegmentUrlConvention() + { +#> + this.UrlConventions = global::Microsoft.OData.Client.DataServiceUrlConventions.KeyAsSegment; +<#+ + } + + internal override void WriteInitializeResolveName() + { +#> + this.ResolveName = new global::System.Func(this.ResolveNameFromType); +<#+ + } + + internal override void WriteInitializeResolveType() + { +#> + this.ResolveType = new global::System.Func(this.ResolveTypeFromName); +<#+ + } + + internal override void WriteClassEndForEntityContainerConstructor() + { +#> + this.OnContextCreated(); + this.Format.LoadServiceModel = GeneratedEdmModel.GetInstance; + this.Format.UseJson(); + } + partial void OnContextCreated(); +<#+ + } + + internal override void WriteMethodStartForResolveTypeFromName() + { +#> + /// + /// Since the namespace configured for this service reference + /// in Visual Studio is different from the one indicated in the + /// server schema, use type-mappers to map between the two. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] + protected global::System.Type ResolveTypeFromName(string typeName) + { +<#+ + } + + internal override void WriteResolveNamespace(string typeName, string fullNamespace, string languageDependentNamespace) + { +#> + <#= typeName #>resolvedType = this.DefaultResolveType(typeName, "<#= fullNamespace #>", "<#= languageDependentNamespace #>"); + if ((resolvedType != null)) + { + return resolvedType; + } +<#+ + } + + internal override void WriteMethodEndForResolveTypeFromName() + { +#> + return null; + } +<#+ + } + + internal override void WritePropertyRootNamespace(string containerName, string fullNamespace) + { + + } + + internal override void WriteMethodStartForResolveNameFromType(string containerName, string fullNamespace) + { +#> + /// + /// Since the namespace configured for this service reference + /// in Visual Studio is different from the one indicated in the + /// server schema, use type-mappers to map between the two. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] + protected string ResolveNameFromType(global::System.Type clientType) + { +<#+ + if (this.context.EnableNamingAlias) + { +#> + global::Microsoft.OData.Client.OriginalNameAttribute originalNameAttribute = (global::Microsoft.OData.Client.OriginalNameAttribute)global::System.Linq.Enumerable.SingleOrDefault(global::Microsoft.OData.Client.Utility.GetCustomAttributes(clientType, typeof(global::Microsoft.OData.Client.OriginalNameAttribute), true)); +<#+ + } + } + + internal override void WriteResolveType(string fullNamespace, string languageDependentNamespace) + { +#> + if (clientType.Namespace.Equals("<#= languageDependentNamespace #>", global::System.StringComparison.Ordinal)) + { +<#+ + if (this.context.EnableNamingAlias) + { +#> + if (originalNameAttribute != null) + { + return string.Concat("<#= fullNamespace #>.", originalNameAttribute.OriginalName); + } +<#+ + } +#> + return string.Concat("<#= fullNamespace #>.", clientType.Name); + } +<#+ + } + + internal override void WriteMethodEndForResolveNameFromType(bool modelHasInheritance) + { + if (this.context.EnableNamingAlias && modelHasInheritance) + { +#> + if (originalNameAttribute != null) + { + return clientType.Namespace + "." + originalNameAttribute.OriginalName; + } +<#+ + } +#> + return <#= modelHasInheritance ? "clientType.FullName" : "null" #>; + } +<#+ + } + + internal override void WriteConstructorForSingleType(string singleTypeName, string baseTypeName) + { +#> + /// + /// Initialize a new <#= singleTypeName #> object. + /// + public <#= singleTypeName #>(global::Microsoft.OData.Client.DataServiceContext context, string path) + : base(context, path) {} + + /// + /// Initialize a new <#= singleTypeName #> object. + /// + public <#= singleTypeName #>(global::Microsoft.OData.Client.DataServiceContext context, string path, bool isComposable) + : base(context, path, isComposable) {} + + /// + /// Initialize a new <#= singleTypeName #> object. + /// + public <#= singleTypeName #>(<#= baseTypeName #> query) + : base(query) {} + +<#+ + } + + internal override void WriteContextEntitySetProperty(string entitySetName, string entitySetFixedName, string originalEntitySetName, string entitySetElementTypeName, bool inContext) + { +#> + /// + /// There are no comments for <#= entitySetName #> in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] +<#+ + if (this.context.EnableNamingAlias) + { +#> + [global::Microsoft.OData.Client.OriginalNameAttribute("<#= originalEntitySetName #>")] +<#+ + } +#> + public global::Microsoft.OData.Client.DataServiceQuery<<#= entitySetElementTypeName #>> <#= entitySetFixedName #> + { + get + { +<#+ + if (!inContext) + { +#> + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } +<#+ + } +#> + if ((this._<#= entitySetName #> == null)) + { + this._<#= entitySetName #> = <#= inContext ? "base" : "Context" #>.CreateQuery<<#= entitySetElementTypeName #>>(<#= inContext ? "\"" + originalEntitySetName + "\"" : "GetPath(\"" + originalEntitySetName + "\")" #>); + } + return this._<#= entitySetName #>; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] + private global::Microsoft.OData.Client.DataServiceQuery<<#= entitySetElementTypeName #>> _<#= entitySetName #>; +<#+ + } + + internal override void WriteContextSingletonProperty(string singletonName, string singletonFixedName, string originalSingletonName, string singletonElementTypeName, bool inContext) + { +#> + /// + /// There are no comments for <#= singletonName #> in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] +<#+ + if (this.context.EnableNamingAlias) + { +#> + [global::Microsoft.OData.Client.OriginalNameAttribute("<#= originalSingletonName #>")] +<#+ + } +#> + public <#= singletonElementTypeName #> <#= singletonFixedName #> + { + get + { +<#+ + if (!inContext) + { +#> + if (!this.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } +<#+ + } +#> + if ((this._<#= singletonName #> == null)) + { + this._<#= singletonName #> = new <#= singletonElementTypeName #>(<#= inContext ? "this" : "this.Context" #>, <#= inContext ? "\"" + originalSingletonName + "\"" : "GetPath(\"" + originalSingletonName + "\")" #>); + } + return this._<#= singletonName #>; + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] + private <#= singletonElementTypeName #> _<#= singletonName #>; +<#+ + } + + internal override void WriteContextAddToEntitySetMethod(string entitySetName, string originalEntitySetName, string typeName, string parameterName) + { +#> + /// + /// There are no comments for <#= entitySetName #> in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] + public void AddTo<#= entitySetName #>(<#= typeName #> <#= parameterName #>) + { + base.AddObject("<#= originalEntitySetName #>", <#= parameterName #>); + } +<#+ + } + + internal override void WriteGeneratedEdmModel(string escapedEdmxString) + { +#> + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] + private abstract class GeneratedEdmModel + { +<#+ + if (this.context.ReferencesMap != null) + { +#> + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] + private static global::System.Collections.Generic.Dictionary ReferencesMap = new global::System.Collections.Generic.Dictionary() + { +<#+ + foreach(var reference in this.context.ReferencesMap) + { +#> + {@"<#= reference.Key.OriginalString.Replace("\"", "\"\"") #>", @"<#= Utils.SerializeToString(reference.Value).Replace("\"", "\"\"") #>"}, +<#+ + } +#> + }; +<#+ + } +#> + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] + private static global::Microsoft.OData.Edm.IEdmModel ParsedModel = LoadModelFromString(); + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] + private const string Edmx = @"<#= escapedEdmxString #>"; + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] + public static global::Microsoft.OData.Edm.IEdmModel GetInstance() + { + return ParsedModel; + } +<#+ + if (this.context.ReferencesMap != null) + { +#> + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] + private static global::System.Xml.XmlReader getReferencedModelFromMap(global::System.Uri uri) + { + string referencedEdmx; + if (ReferencesMap.TryGetValue(uri.OriginalString, out referencedEdmx)) + { + return CreateXmlReader(referencedEdmx); + } + + return null; + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] + private static global::Microsoft.OData.Edm.IEdmModel LoadModelFromString() + { + global::System.Xml.XmlReader reader = CreateXmlReader(Edmx); + try + { + return global::Microsoft.OData.Edm.Csdl.EdmxReader.Parse(reader, getReferencedModelFromMap); + } + finally + { + ((global::System.IDisposable)(reader)).Dispose(); + } + } +<#+ + } + else + { +#> + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] + private static global::Microsoft.OData.Edm.IEdmModel LoadModelFromString() + { + global::System.Xml.XmlReader reader = CreateXmlReader(Edmx); + try + { + return global::Microsoft.OData.Edm.Csdl.EdmxReader.Parse(reader); + } + finally + { + ((global::System.IDisposable)(reader)).Dispose(); + } + } +<#+ + } +#> + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] + private static global::System.Xml.XmlReader CreateXmlReader(string edmxToParse) + { + return global::System.Xml.XmlReader.Create(new global::System.IO.StringReader(edmxToParse)); + } + } +<#+ + } + + internal override void WriteClassEndForEntityContainer() + { +#> + } +<#+ + } + + internal override void WriteSummaryCommentForStructuredType(string typeName) + { +#> + /// + /// There are no comments for <#= typeName #> in the schema. + /// +<#+ + } + + internal override void WriteKeyPropertiesCommentAndAttribute(IEnumerable keyProperties, string keyString) + { +#> + /// +<#+ + foreach (string key in keyProperties) + { +#> + /// <#= key #> +<#+ + } +#> + /// + [global::Microsoft.OData.Client.Key("<#= keyString #>")] +<#+ + } + + internal override void WriteEntityTypeAttribute() + { +#> + [global::Microsoft.OData.Client.EntityType()] +<#+ + } + + internal override void WriteEntitySetAttribute(string entitySetName) + { +#> + [global::Microsoft.OData.Client.EntitySet("<#= entitySetName #>")] +<#+ + } + + internal override void WriteEntityHasStreamAttribute() + { +#> + [global::Microsoft.OData.Client.HasStream()] +<#+ + } + + internal override void WriteClassStartForStructuredType(string abstractModifier, string typeName, string originalTypeName, string baseTypeName) + { + if (this.context.EnableNamingAlias) + { +#> + [global::Microsoft.OData.Client.OriginalNameAttribute("<#= originalTypeName #>")] +<#+ + } +#> + public<#= abstractModifier #> partial class <#= typeName #><#= baseTypeName #> + { +<#+ + } + + internal override void WriteSummaryCommentForStaticCreateMethod(string typeName) + { +#> + /// + /// Create a new <#= typeName #> object. + /// +<#+ + } + + internal override void WriteParameterCommentForStaticCreateMethod(string parameterName, string propertyName) + { +#> + /// Initial value of <#= propertyName #>. +<#+ + } + + internal override void WriteDeclarationStartForStaticCreateMethod(string typeName, string fixedTypeName) + { +#> + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] + public static <#= fixedTypeName #> Create<#= typeName #>(<#+ + } + + internal override void WriteParameterForStaticCreateMethod(string parameterTypeName, string parameterName, string parameterSeparater) + { +#><#= parameterTypeName #> <#= parameterName #><#= parameterSeparater #><#+ + } + + internal override void WriteDeclarationEndForStaticCreateMethod(string typeName, string instanceName) + { + #>) + { + <#= typeName #> <#= instanceName #> = new <#= typeName #>(); +<#+ + } + + internal override void WriteParameterNullCheckForStaticCreateMethod(string parameterName) + { +#> + if ((<#= parameterName #> == null)) + { + throw new global::System.ArgumentNullException("<#= parameterName #>"); + } +<#+ + } + + internal override void WritePropertyValueAssignmentForStaticCreateMethod(string instanceName, string propertyName, string parameterName) + { +#> + <#= instanceName #>.<#= propertyName #> = <#= parameterName #>; +<#+ + } + + internal override void WriteMethodEndForStaticCreateMethod(string instanceName) + { +#> + return <#= instanceName #>; + } +<#+ + } + + internal override void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged) + { +#> + /// + /// There are no comments for Property <#= propertyName #> in the schema. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] +<#+ + if (this.context.EnableNamingAlias || IdentifierMappings.ContainsKey(originalPropertyName)) + { +#> + [global::Microsoft.OData.Client.OriginalNameAttribute("<#= originalPropertyName #>")] +<#+ + } +#> + public <#= propertyType #> <#= fixedPropertyName #> + { + get + { + return this.<#= privatePropertyName #>; + } + set + { + this.On<#= propertyName #>Changing(value); + this.<#= privatePropertyName #> = value; + this.On<#= propertyName #>Changed(); +<#+ + if (writeOnPropertyChanged) + { +#> + this.OnPropertyChanged("<#= originalPropertyName #>"); +<#+ + } +#> + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] + private <#= propertyType #> <#= privatePropertyName #><#= propertyInitializationValue != null ? " = " + propertyInitializationValue : string.Empty #>; + partial void On<#= propertyName #>Changing(<#= propertyType #> value); + partial void On<#= propertyName #>Changed(); +<#+ + } + + internal override void WriteINotifyPropertyChangedImplementation() + { +#> + /// + /// This event is raised when the value of the property is changed + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] + public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + /// + /// The value of the property is changed + /// + /// property name + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "<#=T4Version#>")] + protected virtual void OnPropertyChanged(string property) + { + if ((this.PropertyChanged != null)) + { + this.PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(property)); + } + } +<#+ + } + + internal override void WriteClassEndForStructuredType() + { +#> + } +<#+ + } + + internal override void WriteEnumFlags() + { +#> + [global::System.Flags] +<#+ + } + + internal override void WriteSummaryCommentForEnumType(string enumName) + { +#> + /// + /// There are no comments for <#= enumName #> in the schema. + /// +<#+ + } + + internal override void WriteEnumDeclaration(string enumName, string originalEnumName, string underlyingType) + { + if (this.context.EnableNamingAlias) + { +#> + [global::Microsoft.OData.Client.OriginalNameAttribute("<#= originalEnumName #>")] +<#+ + } +#> + public enum <#= enumName #><#= underlyingType #> + { +<#+ + } + + internal override void WriteMemberForEnumType(string member, string originalMemberName, bool last) + { + if (this.context.EnableNamingAlias) + { +#> + [global::Microsoft.OData.Client.OriginalNameAttribute("<#= originalMemberName #>")] +<#+ + } +#> + <#= member #><#= last ? string.Empty : "," #> +<#+ + } + + internal override void WriteEnumEnd() + { +#> + } +<#+ + } + + internal override void WriteFunctionImportReturnCollectionResult(string functionName, string originalFunctionName, string returnTypeName, string parameters, string parameterValues, bool isComposable, bool useEntityReference) + { +#> + /// + /// There are no comments for <#= functionName #> in the schema. + /// +<#+ + if (this.context.EnableNamingAlias) + { +#> + [global::Microsoft.OData.Client.OriginalNameAttribute("<#= originalFunctionName #>")] +<#+ + } +#> + public global::Microsoft.OData.Client.DataServiceQuery<<#= returnTypeName #>> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) + { + return this.CreateFunctionQuery<<#= returnTypeName #>>("", "<#= originalFunctionName #>", <#= isComposable.ToString().ToLower() #><#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>); + } +<#+ + } + + internal override void WriteFunctionImportReturnSingleResult(string functionName, string originalFunctionName, string returnTypeName, string parameters, string parameterValues, bool isComposable, bool isReturnEntity, bool useEntityReference) + { +#> + /// + /// There are no comments for <#= functionName #> in the schema. + /// +<#+ + if (this.context.EnableNamingAlias) + { +#> + [global::Microsoft.OData.Client.OriginalNameAttribute("<#= originalFunctionName #>")] +<#+ + } +#> + public <#= isReturnEntity ? returnTypeName + this.singleSuffix : string.Format(this.DataServiceQuerySingleStructureTemplate, returnTypeName) #> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) + { + return <#= isReturnEntity ? "new " + returnTypeName + this.singleSuffix + "(" : string.Empty #>this.CreateFunctionQuerySingle<<#= returnTypeName #>>("", "<#= originalFunctionName #>", <#= isComposable.ToString().ToLower() #><#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>)<#= isReturnEntity ? ")" : string.Empty #>; + } +<#+ + } + + internal override void WriteBoundFunctionInEntityTypeReturnCollectionResult(bool hideBaseMethod, string functionName, string originalFunctionName, string returnTypeName, string parameters, string fullNamespace, string parameterValues, bool isComposable, bool useEntityReference) + { +#> + /// + /// There are no comments for <#= functionName #> in the schema. + /// +<#+ + if (this.context.EnableNamingAlias) + { +#> + [global::Microsoft.OData.Client.OriginalNameAttribute("<#= originalFunctionName #>")] +<#+ + } +#> + public <#= hideBaseMethod ? this.OverloadsModifier : string.Empty #>global::Microsoft.OData.Client.DataServiceQuery<<#= returnTypeName #>> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) + { + global::System.Uri requestUri; + Context.TryGetUri(this, out requestUri); + return this.Context.CreateFunctionQuery<<#= returnTypeName #>>(string.Join("/", global::System.Linq.Enumerable.Select(global::System.Linq.Enumerable.Skip(requestUri.Segments, this.Context.BaseUri.Segments.Length), s => s.Trim('/'))), "<#= fullNamespace #>.<#= originalFunctionName #>", <#= isComposable.ToString().ToLower() #><#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>); + } +<#+ + } + + internal override void WriteBoundFunctionInEntityTypeReturnSingleResult(bool hideBaseMethod, string functionName, string originalFunctionName, string returnTypeName, string parameters, string fullNamespace, string parameterValues, bool isComposable, bool isReturnEntity, bool useEntityReference) + { +#> + /// + /// There are no comments for <#= functionName #> in the schema. + /// +<#+ + if (this.context.EnableNamingAlias) + { +#> + [global::Microsoft.OData.Client.OriginalNameAttribute("<#= originalFunctionName #>")] +<#+ + } +#> + public <#= hideBaseMethod ? this.OverloadsModifier : string.Empty #> <#= isReturnEntity ? returnTypeName + this.singleSuffix : string.Format(this.DataServiceQuerySingleStructureTemplate, returnTypeName) #> <#= functionName #>(<#= parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) + { + global::System.Uri requestUri; + Context.TryGetUri(this, out requestUri); + + return <#= isReturnEntity ? "new " + returnTypeName + this.singleSuffix + "(" : string.Empty #>this.Context.CreateFunctionQuerySingle<<#= returnTypeName #>>(string.Join("/", global::System.Linq.Enumerable.Select(global::System.Linq.Enumerable.Skip(requestUri.Segments, this.Context.BaseUri.Segments.Length), s => s.Trim('/'))), "<#= fullNamespace #>.<#= originalFunctionName #>", <#= isComposable.ToString().ToLower() #><#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>)<#= isReturnEntity ? ")" : string.Empty #>; + } +<#+ + } + + internal override void WriteActionImport(string actionName, string originalActionName, string returnTypeName, string parameters, string parameterValues) + { +#> + /// + /// There are no comments for <#= actionName #> in the schema. + /// +<#+ + if (this.context.EnableNamingAlias) + { +#> + [global::Microsoft.OData.Client.OriginalNameAttribute("<#= originalActionName #>")] +<#+ + } +#> + public <#= returnTypeName #> <#= actionName #>(<#= parameters #>) + { + return new <#= returnTypeName #>(this, this.BaseUri.OriginalString.Trim('/') + "/<#= originalActionName #>"<#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>); + } +<#+ + } + + internal override void WriteBoundActionInEntityType(bool hideBaseMethod, string actionName, string originalActionName, string returnTypeName, string parameters, string fullNamespace, string parameterValues) + { +#> + /// + /// There are no comments for <#= actionName #> in the schema. + /// +<#+ + if (this.context.EnableNamingAlias) + { +#> + [global::Microsoft.OData.Client.OriginalNameAttribute("<#= originalActionName #>")] +<#+ + } +#> + public <#= hideBaseMethod ? this.OverloadsModifier : string.Empty #><#= returnTypeName #> <#= actionName #>(<#= parameters #>) + { + global::Microsoft.OData.Client.EntityDescriptor resource = Context.EntityTracker.TryGetEntityDescriptor(this); + if (resource == null) + { + throw new global::System.Exception("cannot find entity"); + } + + return new <#= returnTypeName #>(this.Context, resource.EditLink.OriginalString.Trim('/') + "/<#= fullNamespace #>.<#= originalActionName #>"<#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>); + } +<#+ + } + + internal override void WriteExtensionMethodsStart() + { +#> + /// + /// Class containing all extension methods + /// + public static class ExtensionMethods + { +<#+ + } + + internal override void WriteExtensionMethodsEnd() + { +#> + } +<#+ + } + + internal override void WriteByKeyMethods(string entityTypeName, string returnTypeName, IEnumerable keys, string keyParameters, string keyDictionaryItems) + { +#> + /// + /// Get an entity of type <#= entityTypeName #> as <#= entityTypeName + this.singleSuffix #> specified by key from an entity set + /// + /// source entity set + /// dictionary with the names and values of keys + public static <#= returnTypeName #> ByKey(this global::Microsoft.OData.Client.DataServiceQuery<<#= entityTypeName #>> source, global::System.Collections.Generic.Dictionary keys) + { + return new <#= returnTypeName #>(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } + /// + /// Get an entity of type <#= entityTypeName #> as <#= entityTypeName + this.singleSuffix #> specified by key from an entity set + /// + /// source entity set +<#+ + foreach (var key in keys) + { +#> + /// The value of <#= key #> +<#+ + } +#> + public static <#= returnTypeName #> ByKey(this global::Microsoft.OData.Client.DataServiceQuery<<#= entityTypeName #>> source, + <#= keyParameters #>) + { + global::System.Collections.Generic.Dictionary keys = new global::System.Collections.Generic.Dictionary + { + <#= keyDictionaryItems #> + }; + return new <#= returnTypeName #>(source.Context, source.GetKeyPath(global::Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))); + } +<#+ + } + + internal override void WriteCastToMethods(string baseTypeName, string derivedTypeName, string derivedTypeFullName, string returnTypeName) + { +#> + /// + /// Cast an entity of type <#= baseTypeName #> to its derived type <#= derivedTypeFullName #> + /// + /// source entity + public static <#= returnTypeName #> CastTo<#= derivedTypeName #>(this global::Microsoft.OData.Client.DataServiceQuerySingle<<#= baseTypeName #>> source) + { + global::Microsoft.OData.Client.DataServiceQuerySingle<<#= derivedTypeFullName #>> query = source.CastTo<<#= derivedTypeFullName #>>(); + return new <#= returnTypeName #>(source.Context, query.GetPath(null)); + } +<#+ + } + + internal override void WriteBoundFunctionReturnSingleResultAsExtension(string functionName, string originalFunctionName, string boundTypeName, string returnTypeName, string parameters, string fullNamespace, string parameterValues, bool isComposable, bool isReturnEntity, bool useEntityReference) + { +#> + /// + /// There are no comments for <#= functionName #> in the schema. + /// +<#+ + if (this.context.EnableNamingAlias) + { +#> + [global::Microsoft.OData.Client.OriginalNameAttribute("<#= originalFunctionName #>")] +<#+ + } +#> + public static <#= isReturnEntity ? returnTypeName + this.singleSuffix : string.Format(this.DataServiceQuerySingleStructureTemplate, returnTypeName) #> <#= functionName #>(this <#= boundTypeName #> source<#= string.IsNullOrEmpty(parameters) ? string.Empty : ", " + parameters #><#= useEntityReference ? ", bool useEntityReference = false" : string.Empty #>) + { + if (!source.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + + return <#= isReturnEntity ? "new " + returnTypeName + this.singleSuffix + "(" : string.Empty #>source.CreateFunctionQuerySingle<<#= returnTypeName #>>("<#= fullNamespace #>.<#= originalFunctionName #>", <#= isComposable.ToString().ToLower() #><#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>)<#= isReturnEntity ? ")" : string.Empty #>; + } +<#+ + } + + internal override void WriteBoundFunctionReturnCollectionResultAsExtension(string functionName, string originalFunctionName, string boundTypeName, string returnTypeName, string parameters, string fullNamespace, string parameterValues, bool isComposable, bool useEntityReference) + { +#> + /// + /// There are no comments for <#= functionName #> in the schema. + /// +<#+ + if (this.context.EnableNamingAlias) + { +#> + [global::Microsoft.OData.Client.OriginalNameAttribute("<#= originalFunctionName #>")] +<#+ + } +#> + public static global::Microsoft.OData.Client.DataServiceQuery<<#= returnTypeName #>> <#= functionName #>(this <#= boundTypeName #> source<#= string.IsNullOrEmpty(parameters) ? string.Empty : ", " + parameters #><#= useEntityReference ? ", bool useEntityReference = true" : string.Empty #>) + { + if (!source.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + + return source.CreateFunctionQuery<<#= returnTypeName #>>("<#= fullNamespace #>.<#= originalFunctionName #>", <#= isComposable.ToString().ToLower() #><#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>); + } +<#+ + } + + internal override void WriteBoundActionAsExtension(string actionName, string originalActionName, string boundSourceType, string returnTypeName, string parameters, string fullNamespace, string parameterValues) + { +#> + /// + /// There are no comments for <#= actionName #> in the schema. + /// +<#+ + if (this.context.EnableNamingAlias) + { +#> + [global::Microsoft.OData.Client.OriginalNameAttribute("<#= originalActionName #>")] +<#+ + } +#> + public static <#= returnTypeName #> <#= actionName #>(this <#= boundSourceType #> source<#= string.IsNullOrEmpty(parameters) ? string.Empty : ", " + parameters #>) + { + if (!source.IsComposable) + { + throw new global::System.NotSupportedException("The previous function is not composable."); + } + + return new <#= returnTypeName #>(source.Context, source.AppendRequestUri("<#= fullNamespace #>.<#= originalActionName #>")<#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>); + } +<#+ + } + + internal override void WriteNamespaceEnd() + { +#> +} +<#+ + } +} + +public sealed class ODataClientVBTemplate : ODataClientTemplate +{ + /// + /// Creates an instance of the ODataClientTemplate. + /// + /// The cotion context. + public ODataClientVBTemplate(CodeGenerationContext context) + : base(context) + { + } + + internal override string GlobalPrefix { get { return string.Empty; } } + internal override string SystemTypeTypeName { get { return "Global.System.Type"; } } + internal override string AbstractModifier { get { return " MustInherit"; } } + internal override string DataServiceActionQueryTypeName { get { return "Global.Microsoft.OData.Client.DataServiceActionQuery"; } } + internal override string DataServiceActionQuerySingleOfTStructureTemplate { get { return "Global.Microsoft.OData.Client.DataServiceActionQuerySingle(Of {0})"; } } + internal override string DataServiceActionQueryOfTStructureTemplate { get { return "Global.Microsoft.OData.Client.DataServiceActionQuery(Of {0})"; } } + internal override string NotifyPropertyChangedModifier { get { return "\r\n Implements Global.System.ComponentModel.INotifyPropertyChanged"; } } + internal override string ClassInheritMarker { get { return "\r\n Inherits "; } } + internal override string ParameterSeparator { get { return ", _\r\n "; } } + internal override string KeyParameterSeparator { get { return ", _\r\n "; } } + internal override string KeyDictionaryItemSeparator { get { return ", _\r\n "; } } + internal override string SystemNullableStructureTemplate { get { return "Global.System.Nullable(Of {0})"; } } + internal override string ICollectionOfTStructureTemplate { get { return "Global.System.Collections.Generic.ICollection(Of {0})"; } } + internal override string DataServiceCollectionStructureTemplate { get { return "Global.Microsoft.OData.Client.DataServiceCollection(Of {0})"; } } + internal override string DataServiceQueryStructureTemplate { get { return "Global.Microsoft.OData.Client.DataServiceQuery(Of {0})"; } } + internal override string DataServiceQuerySingleStructureTemplate { get { return "Global.Microsoft.OData.Client.DataServiceQuerySingle(Of {0})"; } } + internal override string ObservableCollectionStructureTemplate { get { return "Global.System.Collections.ObjectModel.ObservableCollection(Of {0})"; } } + internal override string ObjectModelCollectionStructureTemplate { get { return "Global.System.Collections.ObjectModel.Collection(Of {0})"; } } + internal override string DataServiceCollectionConstructorParameters { get { return "(Nothing, Global.Microsoft.OData.Client.TrackingMode.None)"; } } + internal override string NewModifier { get { return "New "; } } + internal override string GeoTypeInitializePattern { get { return "Global.Microsoft.Spatial.SpatialImplementation.CurrentImplementation.CreateWellKnownTextSqlFormatter(False).Read(Of {0})(New Global.System.IO.StringReader(\"{1}\"))"; } } + internal override string Int32TypeName { get { return "Integer"; } } + internal override string StringTypeName { get { return "String"; } } + internal override string BinaryTypeName { get { return "Byte()"; } } + internal override string DecimalTypeName { get { return "Decimal"; } } + internal override string Int16TypeName { get { return "Short"; } } + internal override string SingleTypeName { get { return "Single"; } } + internal override string BooleanTypeName { get { return "Boolean"; } } + internal override string DoubleTypeName { get { return "Double"; } } + internal override string GuidTypeName { get { return "Global.System.Guid"; } } + internal override string ByteTypeName { get { return "Byte"; } } + internal override string Int64TypeName { get { return "Long"; } } + internal override string SByteTypeName { get { return "SByte"; } } + internal override string DataServiceStreamLinkTypeName { get { return "Global.Microsoft.OData.Client.DataServiceStreamLink"; } } + internal override string GeographyTypeName { get { return "Global.Microsoft.Spatial.Geography"; } } + internal override string GeographyPointTypeName { get { return "Global.Microsoft.Spatial.GeographyPoint"; } } + internal override string GeographyLineStringTypeName { get { return "Global.Microsoft.Spatial.GeographyLineString"; } } + internal override string GeographyPolygonTypeName { get { return "Global.Microsoft.Spatial.GeographyPolygon"; } } + internal override string GeographyCollectionTypeName { get { return "Global.Microsoft.Spatial.GeographyCollection"; } } + internal override string GeographyMultiPolygonTypeName { get { return "Global.Microsoft.Spatial.GeographyMultiPolygon"; } } + internal override string GeographyMultiLineStringTypeName { get { return "Global.Microsoft.Spatial.GeographyMultiLineString"; } } + internal override string GeographyMultiPointTypeName { get { return "Global.Microsoft.Spatial.GeographyMultiPoint"; } } + internal override string GeometryTypeName { get { return "Global.Microsoft.Spatial.Geometry"; } } + internal override string GeometryPointTypeName { get { return "Global.Microsoft.Spatial.GeometryPoint"; } } + internal override string GeometryLineStringTypeName { get { return "Global.Microsoft.Spatial.GeometryLineString"; } } + internal override string GeometryPolygonTypeName { get { return "Global.Microsoft.Spatial.GeometryPolygon"; } } + internal override string GeometryCollectionTypeName { get { return "Global.Microsoft.Spatial.GeometryCollection"; } } + internal override string GeometryMultiPolygonTypeName { get { return "Global.Microsoft.Spatial.GeometryMultiPolygon"; } } + internal override string GeometryMultiLineStringTypeName { get { return "Global.Microsoft.Spatial.GeometryMultiLineString"; } } + internal override string GeometryMultiPointTypeName { get { return "Global.Microsoft.Spatial.GeometryMultiPoint"; } } + internal override string DateTypeName { get { return "Global.Microsoft.OData.Edm.Library.Date"; } } + internal override string DateTimeOffsetTypeName { get { return "Global.System.DateTimeOffset"; } } + internal override string DurationTypeName { get { return "Global.System.TimeSpan"; } } + internal override string TimeOfDayTypeName { get { return "Global.Microsoft.OData.Edm.Library.TimeOfDay"; } } + internal override string XmlConvertClassName { get { return "Global.System.Xml.XmlConvert"; } } + internal override string EnumTypeName { get { return "Global.System.Enum"; } } + internal override string FixPattern { get { return "[{0}]"; } } + internal override string EnumUnderlyingTypeMarker { get { return " As "; } } + internal override string ConstantExpressionConstructorWithType { get { return "Global.System.Linq.Expressions.Expression.Constant({0}, GetType({1}))"; } } + internal override string TypeofFormatter { get { return "GetType({0})"; } } + internal override string UriOperationParameterConstructor { get { return "New Global.Microsoft.OData.Client.UriOperationParameter(\"{0}\", {1})"; } } + internal override string UriEntityOperationParameterConstructor { get { return "New Global.Microsoft.OData.Client.UriEntityOperationParameter(\"{0}\", {1}, {2})"; } } + internal override string BodyOperationParameterConstructor { get { return "New Global.Microsoft.OData.Client.BodyOperationParameter(\"{0}\", {1})"; } } + internal override string BaseEntityType { get { return "\r\n Inherits Global.Microsoft.OData.Client.BaseEntityType"; } } + internal override string OverloadsModifier { get { return "Overloads "; } } + internal override string ODataVersion { get { return "Global.Microsoft.OData.Core.ODataVersion.V4"; } } + internal override string ParameterDeclarationTemplate { get { return "{1} As {0}"; } } + internal override string DictionaryItemConstructor { get { return "{{ {0}, {1} }}"; } } + internal override HashSet LanguageKeywords { get { + if (VBKeywords == null) + { + VBKeywords = new HashSet(StringComparer.OrdinalIgnoreCase) + { + "AddHandler", "AddressOf", "Alias", "And", "AndAlso", "As", "Boolean", "ByRef", "Byte", "ByVal", + "Call", "Case", "Catch", "CBool", "", "CByte", "CChar", "CDate", "CDbl", "CDec", "Char", + "CInt", "Class", "CLng", "CObj", "Const", "Continue", "CSByte", "CShort", "CSng", "CStr", + "CType", "CUInt", "CULng", "CUShort", "Date", "Decimal", "Declare", "Default", "Delegate", "Dim", + "DirectCast", "Do", "Double", "Each", "Else", "ElseIf", "End", "EndIf", "Enum", "Erase", + "Error", "Event", "Exit", "False", "Finally", "For", "Friend", "Function", "Get", "GetType", + "GetXMLNamespace", "Global", "GoSub", "GoTo", "Handles", "If", "Implements", "Imports", "In", "Inherits", + "Integer", "Interface", "Is", "IsNot", "Let", "Lib", "Like", "Long", "Loop", "Me", + "Mod", "Module", "MustInherit", "MustOverride", "MyBase", "MyClass", "Namespace", "Narrowing", "New", "Next", + "Not", "Nothing", "NotInheritable", "NotOverridable", "Object", "Of", "On", "Operator", "Option", "Optional", + "Or", "OrElse", "Out", "Overloads", "Overridable", "Overrides", "ParamArray", "Partial", "Private", "Property", + "Protected", "Public", "RaiseEvent", "ReadOnly", "ReDim", "REM", "RemoveHandler", "Resume", "Return", "SByte", + "Select", "Set", "Shadows", "Shared", "Short", "Single", "Static", "Step", "Stop", "String", + "Structure", "Sub", "SyncLock", "Then", "Throw", "To", "True", "Try", "TryCast", "TypeOf", + "UInteger", "ULong", "UShort", "Using", "Variant", "Wend", "When", "While", "Widening", "With", + "WithEvents", "WriteOnly", "Xor" + }; + } + return VBKeywords; + } } + private HashSet VBKeywords; + + internal override void WriteFileHeader() + { +#>'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:<#= Environment.Version #> +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict Off +Option Explicit On + + +'Generation date: <#= DateTime.Now.ToString(System.Globalization.CultureInfo.CurrentCulture) #> +<#+ + } + + internal override void WriteNamespaceStart(string fullNamespace) + { +#> +Namespace <#= fullNamespace #> +<#+ + } + + internal override void WriteClassStartForEntityContainer(string originalContainerName, string containerName, string fixedContainerName) + { +#> + ''' + '''There are no comments for <#= containerName #> in the schema. + ''' +<#+ + if (this.context.EnableNamingAlias) + { +#> + ")> _ +<#+ + } +#> + Partial Public Class <#= fixedContainerName #> + Inherits Global.Microsoft.OData.Client.DataServiceContext +<#+ + } + + internal override void WriteMethodStartForEntityContainerConstructor(string containerName, string fixedContainerName) + { +#> + ''' + '''Initialize a new <#= containerName #> object. + ''' + ")> _ + Public Sub New(ByVal serviceRoot As Global.System.Uri) + MyBase.New(serviceRoot, Global.Microsoft.OData.Client.ODataProtocolVersion.V4) +<#+ + } + + internal override void WriteKeyAsSegmentUrlConvention() + { +#> + Me.UrlConventions = Global.Microsoft.OData.Client.DataServiceUrlConventions.KeyAsSegment +<#+ + } + + internal override void WriteInitializeResolveName() + { +#> + Me.ResolveName = AddressOf Me.ResolveNameFromType +<#+ + } + + internal override void WriteInitializeResolveType() + { +#> + Me.ResolveType = AddressOf Me.ResolveTypeFromName +<#+ + } + + internal override void WriteClassEndForEntityContainerConstructor() + { +#> + Me.OnContextCreated + Me.Format.LoadServiceModel = AddressOf GeneratedEdmModel.GetInstance + Me.Format.UseJson() + End Sub + Partial Private Sub OnContextCreated() + End Sub +<#+ + } + + internal override void WriteMethodStartForResolveTypeFromName() + { +#> + ''' + '''Since the namespace configured for this service reference + '''in Visual Studio is different from the one indicated in the + '''server schema, use type-mappers to map between the two. + ''' + ")> _ + Protected Function ResolveTypeFromName(ByVal typeName As String) As Global.System.Type +<#+ + } + + internal override void WriteResolveNamespace(string typeName, string fullNamespace, string languageDependentNamespace) + { + if (!string.IsNullOrEmpty(typeName)) + { +#> + Dim resolvedType As <#= typeName #>= Me.DefaultResolveType(typeName, "<#= fullNamespace #>", String.Concat(ROOTNAMESPACE, "<#= languageDependentNamespace #>")) +<#+ + } + else + { +#> + resolvedType = Me.DefaultResolveType(typeName, "<#= fullNamespace #>", String.Concat(ROOTNAMESPACE, "<#= languageDependentNamespace #>")) +<#+ + } +#> + If (Not (resolvedType) Is Nothing) Then + Return resolvedType + End If +<#+ + } + + internal override void WriteMethodEndForResolveTypeFromName() + { +#> + Return Nothing + End Function +<#+ + } + + internal override void WritePropertyRootNamespace(string containerName, string fullNamespace) + { +#> + ")> _ + Private Shared ROOTNAMESPACE As String = GetType(<#= containerName #>).Namespace.Remove(GetType(<#= containerName #>).Namespace.LastIndexOf("<#= fullNamespace #>")) +<#+ + } + + internal override void WriteMethodStartForResolveNameFromType(string containerName, string fullNamespace) + { +#> + ''' + '''Since the namespace configured for this service reference + '''in Visual Studio is different from the one indicated in the + '''server schema, use type-mappers to map between the two. + ''' + ")> _ + Protected Function ResolveNameFromType(ByVal clientType As Global.System.Type) As String +<#+ + if (this.context.EnableNamingAlias) + { +#> + Dim originalNameAttribute As Global.Microsoft.OData.Client.OriginalNameAttribute = + CType(Global.System.Linq.Enumerable.SingleOrDefault(Global.Microsoft.OData.Client.Utility.GetCustomAttributes(clientType, GetType(Global.Microsoft.OData.Client.OriginalNameAttribute), true)), Global.Microsoft.OData.Client.OriginalNameAttribute) +<#+ + } + } + + internal override void WriteResolveType(string fullNamespace, string languageDependentNamespace) + { +#> + If clientType.Namespace.Equals(String.Concat(ROOTNAMESPACE, "<#= languageDependentNamespace #>"), Global.System.StringComparison.OrdinalIgnoreCase) Then +<#+ + if (this.context.EnableNamingAlias) + { +#> + If (Not (originalNameAttribute) Is Nothing) Then + Return String.Concat("<#= fullNamespace #>.", originalNameAttribute.OriginalName) + End If +<#+ + } +#> + Return String.Concat("<#= fullNamespace #>.", clientType.Name) + End If +<#+ + } + + internal override void WriteMethodEndForResolveNameFromType(bool modelHasInheritance) + { + if (this.context.EnableNamingAlias && modelHasInheritance) + { +#> + If (Not (originalNameAttribute) Is Nothing) Then + Dim fullName As String = clientType.FullName.Substring(ROOTNAMESPACE.Length) + Return fullName.Remove(fullName.LastIndexOf(clientType.Name)) + originalNameAttribute.OriginalName + End If +<#+ + } +#> + Return <#= modelHasInheritance ? "clientType.FullName.Substring(ROOTNAMESPACE.Length)" : "Nothing" #> + End Function +<#+ + } + + internal override void WriteConstructorForSingleType(string singleTypeName, string baseTypeName) + { +#> + ''' + ''' Initialize a new <#= singleTypeName #> object. + ''' + Public Sub New(ByVal context As Global.Microsoft.OData.Client.DataServiceContext, ByVal path As String) + MyBase.New(context, path) + End Sub + + ''' + ''' Initialize a new <#= singleTypeName #> object. + ''' + Public Sub New(ByVal context As Global.Microsoft.OData.Client.DataServiceContext, ByVal path As String, ByVal isComposable As Boolean) + MyBase.New(context, path, isComposable) + End Sub + + ''' + ''' Initialize a new <#= singleTypeName #> object. + ''' + Public Sub New(ByVal query As <#= baseTypeName #>) + MyBase.New(query) + End Sub +<#+ + } + + internal override void WriteContextEntitySetProperty(string entitySetName, string entitySetFixedName, string originalEntitySetName, string entitySetElementTypeName, bool inContext) + { +#> + ''' + '''There are no comments for <#= entitySetName #> in the schema. + ''' + ")> _ +<#+ + if (this.context.EnableNamingAlias) + { +#> + ")> _ +<#+ + } +#> + Public ReadOnly Property <#= entitySetFixedName #>() As Global.Microsoft.OData.Client.DataServiceQuery(Of <#= entitySetElementTypeName #>) + Get +<#+ + if (!inContext) + { +#> + If Not Me.IsComposable Then + Throw New Global.System.NotSupportedException("The previous function is not composable.") + End If +<#+ + } +#> + If (Me._<#= entitySetName #> Is Nothing) Then + Me._<#= entitySetName #> = <#= inContext ? "MyBase" : "Context"#>.CreateQuery(Of <#= entitySetElementTypeName #>)(<#= inContext ? "\"" + originalEntitySetName + "\"" : "GetPath(\"" + originalEntitySetName + "\")" #>) + End If + Return Me._<#= entitySetName #> + End Get + End Property + ")> _ + Private _<#= entitySetName #> As Global.Microsoft.OData.Client.DataServiceQuery(Of <#= entitySetElementTypeName #>) +<#+ + } + + internal override void WriteContextSingletonProperty(string singletonName, string singletonFixedName, string originalSingletonName, string singletonElementTypeName, bool inContext) + { +#> + ''' + '''There are no comments for <#= singletonName #> in the schema. + ''' + ")> _ +<#+ + if (this.context.EnableNamingAlias) + { +#> + ")> _ +<#+ + } +#> + Public ReadOnly Property <#= singletonFixedName #>() As <#= singletonElementTypeName #> + Get +<#+ + if (!inContext) + { +#> + If Not Me.IsComposable Then + Throw New Global.System.NotSupportedException("The previous function is not composable.") + End If +<#+ + } +#> + If (Me._<#= singletonName #> Is Nothing) Then + Me._<#= singletonName #> = New <#= singletonElementTypeName #>(<#= inContext ? "Me" : "Me.Context" #>, <#= inContext ? "\"" + originalSingletonName + "\"" : "GetPath(\"" + originalSingletonName + "\")" #>) + End If + Return Me._<#= singletonName #> + End Get + End Property + ")> _ + Private _<#= singletonName #> As <#= singletonElementTypeName #> +<#+ + } + + internal override void WriteContextAddToEntitySetMethod(string entitySetName, string originalEntitySetName, string typeName, string parameterName) + { +#> + ''' + '''There are no comments for <#= entitySetName #> in the schema. + ''' + ")> _ + Public Sub AddTo<#= entitySetName #>(ByVal <#= parameterName #> As <#= typeName #>) + MyBase.AddObject("<#= originalEntitySetName #>", <#= parameterName #>) + End Sub +<#+ + } + + internal override void WriteGeneratedEdmModel(string escapedEdmxString) + { + escapedEdmxString = escapedEdmxString.Replace("\r\n", "\" & _\r\n \""); +#> + ")> _ + Private MustInherit Class GeneratedEdmModel +<#+ + if (this.context.ReferencesMap != null) + { +#> + ")> _ + Private Shared ReferencesMap As Global.System.Collections.Generic.Dictionary(Of String, String) = New Global.System.Collections.Generic.Dictionary(Of String, String) From + { +<#+ + int count = this.context.ReferencesMap.Count(); + foreach(var reference in this.context.ReferencesMap) + { +#> + {"<#= reference.Key.OriginalString.Replace("\"", "\"\"") #>", "<#= Utils.SerializeToString(reference.Value).Replace("\"", "\"\"").Replace("\r\n", "\" & _\r\n \"") #>"}<#= (--count>0?",":"")#> +<#+ + } +#> + } +<#+ + } +#> + ")> _ + Private Shared ParsedModel As Global.Microsoft.OData.Edm.IEdmModel = LoadModelFromString + ")> _ + Private Const Edmx As String = "<#= escapedEdmxString #>" + ")> _ + Public Shared Function GetInstance() As Global.Microsoft.OData.Edm.IEdmModel + Return ParsedModel + End Function +<#+ + if (this.context.ReferencesMap != null) + { +#> + ")> _ + Private Shared Function getReferencedModelFromMap(ByVal uri As Global.System.Uri) As Global.System.Xml.XmlReader + Dim referencedEdmx As String = Nothing + If (ReferencesMap.TryGetValue(uri.OriginalString, referencedEdmx)) Then + Return CreateXmlReader(referencedEdmx) + End If + Return Nothing + End Function + ")> _ + Private Shared Function LoadModelFromString() As Global.Microsoft.OData.Edm.IEdmModel + Dim reader As Global.System.Xml.XmlReader = CreateXmlReader(Edmx) + Try + Return Global.Microsoft.OData.Edm.Csdl.EdmxReader.Parse(reader, AddressOf getReferencedModelFromMap) + Finally + CType(reader,Global.System.IDisposable).Dispose + End Try + End Function +<#+ + } + else + { +#> + ")> _ + Private Shared Function LoadModelFromString() As Global.Microsoft.OData.Edm.IEdmModel + Dim reader As Global.System.Xml.XmlReader = CreateXmlReader(Edmx) + Try + Return Global.Microsoft.OData.Edm.Csdl.EdmxReader.Parse(reader) + Finally + CType(reader,Global.System.IDisposable).Dispose + End Try + End Function +<#+ + } +#> + ")> _ + Private Shared Function CreateXmlReader(ByVal edmxToParse As String) As Global.System.Xml.XmlReader + Return Global.System.Xml.XmlReader.Create(New Global.System.IO.StringReader(edmxToParse)) + End Function + End Class +<#+ + } + + internal override void WriteClassEndForEntityContainer() + { +#> + End Class +<#+ + } + + internal override void WriteSummaryCommentForStructuredType(string typeName) + { +#> + ''' + '''There are no comments for <#= typeName #> in the schema. + ''' +<#+ + } + + internal override void WriteKeyPropertiesCommentAndAttribute(IEnumerable keyProperties, string keyString) + { +#> + ''' +<#+ + foreach (string key in keyProperties) + { +#> + '''<#= key #> +<#+ + } +#> + ''' + ")> _ +<#+ + } + + internal override void WriteEntityTypeAttribute() + { +#> + _ +<#+ + } + + internal override void WriteEntitySetAttribute(string entitySetName) + { +#> + ")> _ +<#+ + } + + internal override void WriteEntityHasStreamAttribute() + { +#> + _ +<#+ + } + + internal override void WriteClassStartForStructuredType(string abstractModifier, string typeName, string originalTypeName, string baseTypeName) + { + if (this.context.EnableNamingAlias) + { +#> + ")> _ +<#+ + } +#> + Partial Public<#= abstractModifier #> Class <#= typeName #><#= baseTypeName #> +<#+ + } + + internal override void WriteSummaryCommentForStaticCreateMethod(string typeName) + { +#> + ''' + '''Create a new <#= typeName #> object. + ''' +<#+ + } + + internal override void WriteParameterCommentForStaticCreateMethod(string parameterName, string propertyName) + { +#> + '''Initial value of <#= propertyName #>. +<#+ + } + + internal override void WriteDeclarationStartForStaticCreateMethod(string typeName, string fixedTypeName) + { +#> + ")> _ + Public Shared Function Create<#= typeName #>(<#+ + + } + + internal override void WriteParameterForStaticCreateMethod(string parameterTypeName, string parameterName, string parameterSeparater) + { +#>ByVal <#= parameterName #> As <#= parameterTypeName #><#= parameterSeparater #><#+ + } + + internal override void WriteDeclarationEndForStaticCreateMethod(string typeName, string instanceName) + { + #>) As <#= typeName #> + Dim <#= instanceName #> As <#= typeName #> = New <#= typeName #>() +<#+ + } + + internal override void WriteParameterNullCheckForStaticCreateMethod(string parameterName) + { +#> + If (<#= parameterName #> Is Nothing) Then + Throw New Global.System.ArgumentNullException("<#= parameterName #>") + End If +<#+ + } + + internal override void WritePropertyValueAssignmentForStaticCreateMethod(string instanceName, string propertyName, string parameterName) + { +#> + <#= instanceName #>.<#= propertyName #> = <#= parameterName #> +<#+ + } + + internal override void WriteMethodEndForStaticCreateMethod(string instanceName) + { +#> + Return <#= instanceName #> + End Function +<#+ + } + + internal override void WritePropertyForStructuredType(string propertyType, string originalPropertyName, string propertyName, string fixedPropertyName, string privatePropertyName, string propertyInitializationValue, bool writeOnPropertyChanged) + { +#> + ''' + '''There are no comments for Property <#= propertyName #> in the schema. + ''' + ")> _ +<#+ + if (this.context.EnableNamingAlias || IdentifierMappings.ContainsKey(originalPropertyName)) + { +#> + ")> _ +<#+ + } +#> + Public Property <#= fixedPropertyName #>() As <#= propertyType #> + Get + Return Me.<#= privatePropertyName #> + End Get + Set + Me.On<#= propertyName #>Changing(value) + Me.<#= privatePropertyName #> = value + Me.On<#= propertyName #>Changed +<#+ + if (writeOnPropertyChanged) + { +#> + Me.OnPropertyChanged("<#= originalPropertyName #>") +<#+ + } +#> + End Set + End Property + ")> _ +<#+ + string constructorString = string.Empty; + if (!string.IsNullOrEmpty(propertyInitializationValue)) + { + constructorString = " = " + propertyInitializationValue; + } +#> + Private <#= privatePropertyName #> As <#= propertyType #><#= constructorString #> + Partial Private Sub On<#= propertyName #>Changing(ByVal value As <#= propertyType #>) + End Sub + Partial Private Sub On<#= propertyName #>Changed() + End Sub +<#+ + } + + internal override void WriteINotifyPropertyChangedImplementation() + { +#> + ''' + ''' This event is raised when the value of the property is changed + ''' + ")> _ + Public Event PropertyChanged As Global.System.ComponentModel.PropertyChangedEventHandler Implements Global.System.ComponentModel.INotifyPropertyChanged.PropertyChanged + ''' + ''' The value of the property is changed + ''' + ''' property name + ")> _ + Protected Overridable Sub OnPropertyChanged(ByVal [property] As String) + If (Not (Me.PropertyChangedEvent) Is Nothing) Then + RaiseEvent PropertyChanged(Me, New Global.System.ComponentModel.PropertyChangedEventArgs([property])) + End If + End Sub +<#+ + } + + internal override void WriteClassEndForStructuredType() + { +#> + End Class +<#+ + } + + internal override void WriteEnumFlags() + { +#> + +<#+ + } + + internal override void WriteSummaryCommentForEnumType(string enumName) + { +#> + ''' + '''There are no comments for <#= enumName #> in the schema. + ''' +<#+ + } + + internal override void WriteEnumDeclaration(string enumName, string originalEnumName, string underlyingType) + { + if (this.context.EnableNamingAlias) + { +#> + ")> _ +<#+ + } +#> + Public Enum <#= enumName #><#= underlyingType #> +<#+ + } + + internal override void WriteMemberForEnumType(string member, string originalMemberName, bool last) + { + if (this.context.EnableNamingAlias) + { +#> + ")> _ +<#+ + } +#> + <#= member #> +<#+ + } + + internal override void WriteEnumEnd() + { +#> + End Enum +<#+ + } + + internal override void WriteFunctionImportReturnCollectionResult(string functionName, string originalFunctionName, string returnTypeName, string parameters, string parameterValues, bool isComposable, bool useEntityReference) + { +#> + ''' + ''' There are no comments for <#= functionName #> in the schema. + ''' +<#+ + if (this.context.EnableNamingAlias) + { +#> + ")> _ +<#+ + } +#> + Public Function <#= functionName #>(<#= parameters #><#= useEntityReference ? ", Optional ByVal useEntityReference As Boolean = False" : string.Empty #>) As Global.Microsoft.OData.Client.DataServiceQuery(Of <#= returnTypeName #>) + Return Me.CreateFunctionQuery(Of <#= returnTypeName #>)("", "/<#= originalFunctionName #>", <#= isComposable #> <#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>) + End Function +<#+ + } + + internal override void WriteFunctionImportReturnSingleResult(string functionName, string originalFunctionName, string returnTypeName, string parameters, string parameterValues, bool isComposable, bool isReturnEntity, bool useEntityReference) + { +#> + ''' + ''' There are no comments for <#= functionName #> in the schema. + ''' +<#+ + if (this.context.EnableNamingAlias) + { +#> + ")> _ +<#+ + } +#> + Public Function <#= functionName #>(<#= parameters #><#= useEntityReference ? ", Optional ByVal useEntityReference As Boolean = False" : string.Empty #>) As <#= isReturnEntity ? returnTypeName + this.singleSuffix : string.Format(this.DataServiceQuerySingleStructureTemplate, returnTypeName) #> + Return <#= isReturnEntity ? "New " + returnTypeName + this.singleSuffix + "(" : string.Empty #>Me.CreateFunctionQuerySingle(<#= "Of " + returnTypeName #>)("", "/<#= originalFunctionName #>", <#= isComposable #><#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>)<#= isReturnEntity ? ")" : string.Empty #> + End Function +<#+ + } + + internal override void WriteBoundFunctionInEntityTypeReturnCollectionResult(bool hideBaseMethod, string functionName, string originalFunctionName, string returnTypeName, string parameters, string fullNamespace, string parameterValues, bool isComposable, bool useEntityReference) + { +#> + ''' + ''' There are no comments for <#= functionName #> in the schema. + ''' +<#+ + if (this.context.EnableNamingAlias) + { +#> + ")> _ +<#+ + } +#> + Public <#= hideBaseMethod ? this.OverloadsModifier : string.Empty #>Function <#= functionName #>(<#= parameters #><#= useEntityReference ? ", Optional ByVal useEntityReference As Boolean = False" : string.Empty #>) As Global.Microsoft.OData.Client.DataServiceQuery(Of <#= returnTypeName #>) + Dim requestUri As Global.System.Uri = Nothing + Context.TryGetUri(Me, requestUri) + Return Me.Context.CreateFunctionQuery(Of <#= returnTypeName #>)("", String.Join("/", Global.System.Linq.Enumerable.Select(Global.System.Linq.Enumerable.Skip(requestUri.Segments, Me.Context.BaseUri.Segments.Length), Function(s) s.Trim("/"C))) + "/<#= fullNamespace #>.<#= originalFunctionName #>", <#= isComposable #><#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>) + End Function +<#+ + } + + internal override void WriteBoundFunctionInEntityTypeReturnSingleResult(bool hideBaseMethod, string functionName, string originalFunctionName, string returnTypeName, string parameters, string fullNamespace, string parameterValues, bool isComposable, bool isReturnEntity, bool useEntityReference) + { +#> + ''' + ''' There are no comments for <#= functionName #> in the schema. + ''' +<#+ + if (this.context.EnableNamingAlias) + { +#> + ")> _ +<#+ + } +#> + Public <#= hideBaseMethod ? this.OverloadsModifier : string.Empty #>Function <#= functionName #>(<#= parameters #><#= useEntityReference ? ", Optional ByVal useEntityReference As Boolean = False" : string.Empty #>) As <#= isReturnEntity ? returnTypeName + this.singleSuffix : string.Format(this.DataServiceQuerySingleStructureTemplate, returnTypeName) #> + Dim requestUri As Global.System.Uri = Nothing + Context.TryGetUri(Me, requestUri) + Return <#= isReturnEntity ? "New " + returnTypeName + this.singleSuffix + "(" : string.Empty #>Me.Context.CreateFunctionQuerySingle(<#= "Of " + returnTypeName #>)(String.Join("/", Global.System.Linq.Enumerable.Select(Global.System.Linq.Enumerable.Skip(requestUri.Segments, Me.Context.BaseUri.Segments.Length), Function(s) s.Trim("/"C))), "/<#= fullNamespace #>.<#= originalFunctionName #>", <#= isComposable #><#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>)<#= isReturnEntity ? ")" : string.Empty #> + End Function +<#+ + } + + internal override void WriteActionImport(string actionName, string originalActionName, string returnTypeName, string parameters, string parameterValues) + { +#> + ''' + ''' There are no comments for <#= actionName #> in the schema. + ''' +<#+ + if (this.context.EnableNamingAlias) + { +#> + ")> _ +<#+ + } +#> + Public Function <#= actionName #>(<#= parameters #>) As <#= returnTypeName #> + Return New <#= returnTypeName #>(Me, Me.BaseUri.OriginalString.Trim("/"C) + "/<#= originalActionName #>"<#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>) + End Function +<#+ + } + + internal override void WriteBoundActionInEntityType(bool hideBaseMethod, string actionName, string originalActionName, string returnTypeName, string parameters, string fullNamespace, string parameterValues) + { +#> + ''' + ''' There are no comments for <#= actionName #> in the schema. + ''' +<#+ + if (this.context.EnableNamingAlias) + { +#> + ")> _ +<#+ + } +#> + Public <#= hideBaseMethod ? this.OverloadsModifier : string.Empty #>Function <#= actionName #>(<#= parameters #>) As <#= returnTypeName #> + Dim resource As Global.Microsoft.OData.Client.EntityDescriptor = Context.EntityTracker.TryGetEntityDescriptor(Me) + If resource Is Nothing Then + Throw New Global.System.Exception("cannot find entity") + End If + + Return New <#= returnTypeName #>(Me.Context, resource.EditLink.OriginalString.Trim("/"C) + "/<#= fullNamespace #>.<#= originalActionName #>"<#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>) + End Function +<#+ + } + + internal override void WriteExtensionMethodsStart() + { +#> + ''' + ''' Class containing all extension methods + ''' + Public Module ExtensionMethods +<#+ + } + + internal override void WriteExtensionMethodsEnd() + { +#> + End Module +<#+ + } + + internal override void WriteByKeyMethods(string entityTypeName, string returnTypeName, IEnumerable keys, string keyParameters, string keyDictionaryItems) + { +#> + ''' + ''' Get an entity of type <#= entityTypeName #> as <#= entityTypeName + this.singleSuffix #> specified by key from an entity set + ''' + ''' source entity set + ''' dictionary with the names and values of keys + + Public Function ByKey(ByVal source As Global.Microsoft.OData.Client.DataServiceQuery(Of <#= entityTypeName #>), ByVal keys As Global.System.Collections.Generic.Dictionary(Of String, Object)) As <#= returnTypeName #> + Return New <#= returnTypeName #>(source.Context, source.GetKeyPath(Global.Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))) + End Function + ''' + ''' Get an entity of type <#= entityTypeName #> as <#= entityTypeName + this.singleSuffix #> specified by key from an entity set + ''' + ''' source entity set +<#+ + foreach (var key in keys) + { +#> + ''' The value of <#= key #> +<#+ + } +#> + + Public Function ByKey(ByVal source As Global.Microsoft.OData.Client.DataServiceQuery(Of <#= entityTypeName #>), + <#= keyParameters #>) As <#= returnTypeName #> + Dim keys As Global.System.Collections.Generic.Dictionary(Of String, Object) = New Global.System.Collections.Generic.Dictionary(Of String, Object)() From + { + <#= keyDictionaryItems #> + } + Return New <#= returnTypeName #>(source.Context, source.GetKeyPath(Global.Microsoft.OData.Client.Serializer.GetKeyString(source.Context, keys))) + End Function +<#+ + } + + internal override void WriteCastToMethods(string baseTypeName, string derivedTypeName, string derivedTypeFullName, string returnTypeName) + { +#> + ''' + ''' Cast an entity of type <#= baseTypeName #> to its derived type <#= derivedTypeFullName #> + ''' + ''' source entity + + Public Function CastTo<#= derivedTypeName #>(ByVal source As Global.Microsoft.OData.Client.DataServiceQuerySingle(Of <#= baseTypeName #>)) As <#= returnTypeName #> + Dim query As Global.Microsoft.OData.Client.DataServiceQuerySingle(Of <#= derivedTypeFullName #>) = source.CastTo(Of <#= derivedTypeFullName #>)() + Return New <#= returnTypeName #>(source.Context, query.GetPath(Nothing)) + End Function +<#+ + } + + internal override void WriteBoundFunctionReturnSingleResultAsExtension(string functionName, string originalFunctionName, string boundTypeName, string returnTypeName, string parameters, string fullNamespace, string parameterValues, bool isComposable, bool isReturnEntity, bool useEntityReference) + { +#> + ''' + ''' There are no comments for <#= functionName #> in the schema. + ''' + +<#+ + if (this.context.EnableNamingAlias) + { +#> + ")> _ +<#+ + } +#> + Public Function <#= functionName #>(ByVal source As <#= boundTypeName #><#= string.IsNullOrEmpty(parameters) ? string.Empty : ", " + parameters #><#= useEntityReference ? ", Optional ByVal useEntityReference As Boolean = False" : string.Empty #>) As <#= isReturnEntity ? returnTypeName + this.singleSuffix : string.Format(this.DataServiceQuerySingleStructureTemplate, returnTypeName) #> + If Not source.IsComposable Then + Throw New Global.System.NotSupportedException("The previous function is not composable.") + End If + + Return <#= isReturnEntity ? "New " + returnTypeName + this.singleSuffix + "(" : string.Empty #>source.CreateFunctionQuerySingle(<#= "Of " + returnTypeName #>)("<#= fullNamespace #>.<#= originalFunctionName #>", <#= isComposable #><#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>)<#= isReturnEntity ? ")" : string.Empty #> + End Function +<#+ + } + + internal override void WriteBoundFunctionReturnCollectionResultAsExtension(string functionName, string originalFunctionName, string boundTypeName, string returnTypeName, string parameters, string fullNamespace, string parameterValues, bool isComposable, bool useEntityReference) + { +#> + ''' + ''' There are no comments for <#= functionName #> in the schema. + ''' + +<#+ + if (this.context.EnableNamingAlias) + { +#> + ")> _ +<#+ + } +#> + Public Function <#= functionName #>(ByVal source As <#= boundTypeName #><#= string.IsNullOrEmpty(parameters) ? string.Empty : ", " + parameters #><#= useEntityReference ? ", Optional ByVal useEntityReference As Boolean = False" : string.Empty #>) As Global.Microsoft.OData.Client.DataServiceQuery(Of <#= returnTypeName #>) + If Not source.IsComposable Then + Throw New Global.System.NotSupportedException("The previous function is not composable.") + End If + + Return source.CreateFunctionQuery(Of <#= returnTypeName #>)("<#= fullNamespace #>.<#= originalFunctionName #>", <#= isComposable #><#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>) + End Function +<#+ + } + + internal override void WriteBoundActionAsExtension(string actionName, string originalActionName, string boundSourceType, string returnTypeName, string parameters, string fullNamespace, string parameterValues) + { +#> + ''' + ''' There are no comments for <#= actionName #> in the schema. + ''' + +<#+ + if (this.context.EnableNamingAlias) + { +#> + ")> _ +<#+ + } +#> + Public Function <#= actionName #>(ByVal source As <#= boundSourceType #><#= string.IsNullOrEmpty(parameters) ? string.Empty : ", " + parameters #>) As <#= returnTypeName #> + If Not source.IsComposable Then + Throw New Global.System.NotSupportedException("The previous function is not composable.") + End If + Return New <#= returnTypeName #>(source.Context, source.AppendRequestUri("<#= fullNamespace #>.<#= originalActionName #>")<#= string.IsNullOrEmpty(parameterValues) ? string.Empty : ", " + parameterValues #>) + End Function +<#+ + } + + internal override void WriteNamespaceEnd() + { +#> +End Namespace +<#+ + } +} +#> diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/packages.config b/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/packages.config new file mode 100644 index 0000000000..55215f5c15 --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Client/packages.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/App.config b/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/App.config new file mode 100644 index 0000000000..3c88dd4d84 --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/CoreLibTest.cs b/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/CoreLibTest.cs new file mode 100644 index 0000000000..f1bd2ae429 --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/CoreLibTest.cs @@ -0,0 +1,73 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- +namespace Microsoft.OData.Tests.Nuget.Core +{ + using System; + using System.Xml; + using Microsoft.OData; + using Microsoft.OData.Edm; + using Xunit; + + public class CoreLibTest + { + static Uri baseUri = new Uri("http://services.odata.org/V4/(S(f1yueljyzoy0bfv5deqdqkdq))/TrippinServiceRW/"); + static string nameSpace = "Microsoft.OData.SampleService.Models.TripPin"; + static IEdmModel Model { get; set; } + + [Fact] + public void BasicTest() + { + Model = GetModel(); + + // create entry and insert + var personEntry = new ODataResource() { TypeName = nameSpace + ".Person" }; + var userName = new ODataProperty { Name = "UserName", Value = "Test" }; + var firstName = new ODataProperty { Name = "FirstName", Value = "Test" }; + var lastName = new ODataProperty { Name = "LastName", Value = "1" }; + var emails = new ODataProperty { Name = "Emails", Value = new ODataCollectionValue() }; + + personEntry.Properties = new[] { userName, firstName, lastName, emails }; + + var settings = new ODataMessageWriterSettings(); + settings.BaseUri = baseUri; + + var orderType = Model.FindDeclaredType(nameSpace + ".Person") as IEdmEntityType; + var orderSet = Model.EntityContainer.FindEntitySet("People"); + + var requestMessage = new HttpWebRequestMessage(new Uri(settings.BaseUri + "People")); + requestMessage.SetHeader("Content-Type", "application/json"); + requestMessage.SetHeader("Accept", "application/json"); + requestMessage.Method = "POST"; + using (var messageWriter = new ODataMessageWriter(requestMessage, settings)) + { + var odataWriter = messageWriter.CreateODataResourceWriter(orderSet, orderType); + odataWriter.WriteStart(personEntry); + odataWriter.WriteEnd(); + } + + var responseMessage = requestMessage.GetResponse(); + + int expectedStatus = 201; + Assert.True(expectedStatus.Equals(responseMessage.StatusCode)); + } + + public IEdmModel GetModel() + { + HttpWebRequestMessage message = new HttpWebRequestMessage(new Uri(baseUri.AbsoluteUri + "$metadata", UriKind.Absolute)); + message.SetHeader("Accept", "application/xml"); + + using (var messageReader = new ODataMessageReader(message.GetResponse())) + { + Func getReferencedSchemaFunc = uri => + { + HttpWebRequestMessage msg = new HttpWebRequestMessage(new Uri(uri.AbsoluteUri, UriKind.Absolute)); + return XmlReader.Create(msg.GetResponse().GetStream()); + }; + return messageReader.ReadMetadataDocument(getReferencedSchemaFunc); + } + } + } +} diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/HttpWebRequestMessage.cs b/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/HttpWebRequestMessage.cs new file mode 100644 index 0000000000..f754a972db --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/HttpWebRequestMessage.cs @@ -0,0 +1,125 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- +namespace Microsoft.OData.Tests.Nuget.Core +{ + using System; + using System.Collections.Generic; + using System.IO; + using System.Net; + using System.Threading.Tasks; + using Microsoft.OData; + + /// An implementation of IODataRequestMessageAsync that uses an HttpWebRequest under the covers. + /// In ODataLibrary, a message is an abstraction which consists of stream and header interfaces that hides the details of stream-reading/writing. + public class HttpWebRequestMessage : IODataRequestMessageAsync + { + private readonly HttpWebRequest request; + private bool lockedHeaders = false; + + public HttpWebRequestMessage(Uri uri) + { + request = (HttpWebRequest)WebRequest.Create(uri); + } + + public string GetHeader(string headerName) + { + return request.Headers.Get(headerName); + } + + public Task GetStreamAsync() + { + lockedHeaders = true; + + TaskCompletionSource completionSource = new TaskCompletionSource(); + completionSource.SetResult(request.GetRequestStream()); + return completionSource.Task; + } + + public IEnumerable> Headers + { + get + { + foreach (string headerName in this.request.Headers.Keys) + { + yield return new KeyValuePair(headerName, this.request.Headers[headerName]); + } + } + } + + public void SetHeader(string headerName, string headerValue) + { + if (lockedHeaders) + { + throw new InvalidOperationException("Cannot set headers they have already been written to the stream"); + } + + if (headerName == "Content-Type") + { + request.ContentType = headerValue; + } + else if (headerName == "Accept") + { + request.Accept = headerValue; + } + else + { + request.Headers.Add(headerName, headerValue); + } + } + + public IODataResponseMessage GetResponse() + { + WebResponse response; + try + { + response = request.GetResponse(); + } + catch (WebException webException) + { + if (webException.Response == null) + { + throw; + } + + response = webException.Response; + } + + return new HttpWebResponseMessage((HttpWebResponse)response); + } + + public Stream GetStream() + { + return request.GetRequestStream(); + } + + public Uri Url + { + get + { + return request.RequestUri; + } + + set + { + throw new InvalidOperationException("Request Uri cannot be changed"); + } + } + + public string Method + { + get + { + return request.Method; + } + + set + { + request.Method = value; + } + } + } +} + diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/HttpWebResponseMessage.cs b/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/HttpWebResponseMessage.cs new file mode 100644 index 0000000000..f36728928f --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/HttpWebResponseMessage.cs @@ -0,0 +1,93 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- +namespace Microsoft.OData.Tests.Nuget.Core +{ + using System; + using System.Collections.Generic; + using System.IO; + using System.Net; + using System.Threading.Tasks; + using Microsoft.OData; + + /// + /// An implementation of IODataResponseMessageAsync that uses an HttpWebResponse under the covers. + /// In ODataLibrary, a message is an abstraction which consists of stream and header interfaces that hides the details of stream-reading/writing. + /// + public class HttpWebResponseMessage : IODataResponseMessageAsync + { + private HttpWebResponse response; + private bool lockedHeaders = false; + + public HttpWebResponseMessage(HttpWebResponse response) + { + this.response = response; + } + + public string GetHeader(string headerName) + { + return response.Headers[headerName]; + } + + public Task GetStreamAsync() + { + lockedHeaders = true; + TaskCompletionSource completionSource = new TaskCompletionSource(); + completionSource.SetResult(response.GetResponseStream()); + return completionSource.Task; + } + + public IEnumerable> Headers + { + get + { + foreach (string headerName in this.response.Headers.Keys) + { + yield return new KeyValuePair(headerName, this.response.Headers[headerName]); + } + } + } + + public void SetHeader(string headerName, string headerValue) + { + if (lockedHeaders) + { + throw new InvalidOperationException("Cannot set headers they have already been written to the stream"); + } + + this.response.Headers[headerName] = headerValue; + } + + public int StatusCode + { + get + { + return (int)response.StatusCode; + } + set + { + throw new NotImplementedException(); + } + } + + public string StatusDescription + { + get + { + return response.StatusDescription; + } + set + { + throw new NotImplementedException(); + } + } + + public Stream GetStream() + { + return response.GetResponseStream(); + } + } +} + diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/Microsoft.OData.Tests.Nuget.Core.csproj b/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/Microsoft.OData.Tests.Nuget.Core.csproj new file mode 100644 index 0000000000..f0beaa85b8 --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/Microsoft.OData.Tests.Nuget.Core.csproj @@ -0,0 +1,114 @@ + + + + + + + + Debug + AnyCPU + {706928E9-34E7-40D6-AA00-86A539D0F096} + Library + Properties + Microsoft.OData.Tests.Nuget.Core + Microsoft.OData.Tests.Nuget.Core + v4.5.2 + 512 + + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + ..\packages\Microsoft.OData.Core.7.0.0\lib\portable-net45+win8+wpa81\Microsoft.OData.Core.dll + True + + + ..\packages\Microsoft.OData.Edm.7.0.0\lib\portable-net45+win8+wpa81\Microsoft.OData.Edm.dll + True + + + ..\packages\Microsoft.Spatial.7.0.0\lib\portable-net45+win8+wpa81\Microsoft.Spatial.dll + True + + + + + + + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + True + + + + + + + + ..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll + True + + + ..\packages\xunit.assert.2.3.1\lib\netstandard1.1\xunit.assert.dll + True + + + ..\packages\xunit.extensibility.core.2.3.1\lib\netstandard1.1\xunit.core.dll + True + + + ..\packages\xunit.extensibility.execution.2.3.1\lib\net452\xunit.execution.desktop.dll + True + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + \ No newline at end of file diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/Properties/AssemblyInfo.cs b/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..799057adf8 --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("TestODataLib")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TestODataLib")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("cbe458d5-db39-4a4f-8055-a0442025342f")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/packages.config b/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/packages.config new file mode 100644 index 0000000000..43f51664e1 --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Core/packages.config @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/App.config b/test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/App.config new file mode 100644 index 0000000000..3c88dd4d84 --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/EdmLibTest.cs b/test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/EdmLibTest.cs new file mode 100644 index 0000000000..7c55ecb03d --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/EdmLibTest.cs @@ -0,0 +1,34 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- +namespace Microsoft.OData.Tests.Nuget.Edm +{ + using System; + using System.Reflection; + using System.Xml; + using Microsoft.OData.Edm; + using Microsoft.OData.Edm.Csdl; + using System.IO; + using Xunit; + + public class EdmLibTest + { + [Fact] + public void BasicTest() + { + Assembly assembly = Assembly.GetExecutingAssembly(); + string resourceName = "Microsoft.OData.Tests.Nuget.Edm.Schema.xml"; + + using (Stream stream = assembly.GetManifestResourceStream(resourceName)) + { + using (StreamReader reader = new StreamReader(stream)) + { + IEdmModel model = CsdlReader.Parse(XmlTextReader.Create(stream)); + Assert.NotEmpty(model.EntityContainer.Name); + } + } + } + } +} diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/Microsoft.OData.Tests.Nuget.Edm.csproj b/test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/Microsoft.OData.Tests.Nuget.Edm.csproj new file mode 100644 index 0000000000..61e3964db8 --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/Microsoft.OData.Tests.Nuget.Edm.csproj @@ -0,0 +1,105 @@ + + + + + + + + Debug + AnyCPU + {4F678D48-57B6-4810-A67F-7C7F2794414F} + Library + Properties + Microsoft.OData.Tests.Nuget.Edm + Microsoft.OData.Tests.Nuget.Edm + v4.5.2 + 512 + + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + ..\packages\Microsoft.OData.Edm.7.0.0\lib\portable-net45+win8+wpa81\Microsoft.OData.Edm.dll + True + + + + + + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + True + + + + + ..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll + True + + + ..\packages\xunit.assert.2.3.1\lib\netstandard1.1\xunit.assert.dll + True + + + ..\packages\xunit.extensibility.core.2.3.1\lib\netstandard1.1\xunit.core.dll + True + + + ..\packages\xunit.extensibility.execution.2.3.1\lib\net452\xunit.execution.desktop.dll + True + + + + + + + + + + + + + Always + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + \ No newline at end of file diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/Properties/AssemblyInfo.cs b/test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..7205671ba6 --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("TestEdmLib")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TestEdmLib")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("87a4135f-c846-4fa5-b1de-75e8def230ec")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/Schema.xml b/test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/Schema.xml new file mode 100644 index 0000000000..0a75b6af33 --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/Schema.xml @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/packages.config b/test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/packages.config new file mode 100644 index 0000000000..461704dfa7 --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Edm/packages.config @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Spatial/App.config b/test/PackageTests/Microsoft.OData.Tests.Nuget.Spatial/App.config new file mode 100644 index 0000000000..3c88dd4d84 --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Spatial/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Spatial/Microsoft.OData.Tests.Nuget.Spatial.csproj b/test/PackageTests/Microsoft.OData.Tests.Nuget.Spatial/Microsoft.OData.Tests.Nuget.Spatial.csproj new file mode 100644 index 0000000000..8b6fdafa1a --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Spatial/Microsoft.OData.Tests.Nuget.Spatial.csproj @@ -0,0 +1,104 @@ + + + + + + + + Debug + AnyCPU + {F600FB5D-C80C-486E-B2A5-501A5D9FD96B} + Library + Properties + Microsoft.OData.Tests.Nuget.Spatial + Microsoft.OData.Tests.Nuget.Spatial + v4.5.2 + 512 + + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + ..\packages\Microsoft.Spatial.7.0.0\lib\portable-net45+win8+wpa81\Microsoft.Spatial.dll + True + + + + + + + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + True + + + + + + + + ..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll + True + + + ..\packages\xunit.assert.2.3.1\lib\netstandard1.1\xunit.assert.dll + True + + + ..\packages\xunit.extensibility.core.2.3.1\lib\netstandard1.1\xunit.core.dll + True + + + ..\packages\xunit.extensibility.execution.2.3.1\lib\net452\xunit.execution.desktop.dll + True + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + \ No newline at end of file diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Spatial/Properties/AssemblyInfo.cs b/test/PackageTests/Microsoft.OData.Tests.Nuget.Spatial/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..43eeca5cfc --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Spatial/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("TestSpatial")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TestSpatial")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("13fa76e1-c9da-476e-8ff3-53cf682f2f7d")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Spatial/SpatialLibTest.cs b/test/PackageTests/Microsoft.OData.Tests.Nuget.Spatial/SpatialLibTest.cs new file mode 100644 index 0000000000..a9963edce8 --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Spatial/SpatialLibTest.cs @@ -0,0 +1,26 @@ +//--------------------------------------------------------------------- +// +// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. +// +//--------------------------------------------------------------------- +namespace Microsoft.OData.Tests.Nuget.Spatial +{ + using System; + using System.Diagnostics; + using Microsoft.Spatial; + using Xunit; + + public class SpatialLibTest + { + [Fact] + public void BasicTest() + { + GeometryPoint point1 = GeometryPoint.Create(1, 1); + + double expectedValue = 1.0; + Assert.True(expectedValue.Equals(point1.X)); + Assert.True(expectedValue.Equals(point1.Y)); + Console.WriteLine(point1.CoordinateSystem); + } + } +} diff --git a/test/PackageTests/Microsoft.OData.Tests.Nuget.Spatial/packages.config b/test/PackageTests/Microsoft.OData.Tests.Nuget.Spatial/packages.config new file mode 100644 index 0000000000..856eee1e70 --- /dev/null +++ b/test/PackageTests/Microsoft.OData.Tests.Nuget.Spatial/packages.config @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/PackageTests/NugetPackageTesting.sln b/test/PackageTests/NugetPackageTesting.sln new file mode 100644 index 0000000000..d7d5035924 --- /dev/null +++ b/test/PackageTests/NugetPackageTesting.sln @@ -0,0 +1,40 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.OData.Tests.Nuget.Client", "Microsoft.OData.Tests.Nuget.Client\Microsoft.OData.Tests.Nuget.Client.csproj", "{82A1482B-3B8D-4DE0-B4F9-B2CDA4496AD3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.OData.Tests.Nuget.Core", "Microsoft.OData.Tests.Nuget.Core\Microsoft.OData.Tests.Nuget.Core.csproj", "{706928E9-34E7-40D6-AA00-86A539D0F096}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.OData.Tests.Nuget.Edm", "Microsoft.OData.Tests.Nuget.Edm\Microsoft.OData.Tests.Nuget.Edm.csproj", "{4F678D48-57B6-4810-A67F-7C7F2794414F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.OData.Tests.Nuget.Spatial", "Microsoft.OData.Tests.Nuget.Spatial\Microsoft.OData.Tests.Nuget.Spatial.csproj", "{F600FB5D-C80C-486E-B2A5-501A5D9FD96B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {82A1482B-3B8D-4DE0-B4F9-B2CDA4496AD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {82A1482B-3B8D-4DE0-B4F9-B2CDA4496AD3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {82A1482B-3B8D-4DE0-B4F9-B2CDA4496AD3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {82A1482B-3B8D-4DE0-B4F9-B2CDA4496AD3}.Release|Any CPU.Build.0 = Release|Any CPU + {706928E9-34E7-40D6-AA00-86A539D0F096}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {706928E9-34E7-40D6-AA00-86A539D0F096}.Debug|Any CPU.Build.0 = Debug|Any CPU + {706928E9-34E7-40D6-AA00-86A539D0F096}.Release|Any CPU.ActiveCfg = Release|Any CPU + {706928E9-34E7-40D6-AA00-86A539D0F096}.Release|Any CPU.Build.0 = Release|Any CPU + {4F678D48-57B6-4810-A67F-7C7F2794414F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F678D48-57B6-4810-A67F-7C7F2794414F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F678D48-57B6-4810-A67F-7C7F2794414F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F678D48-57B6-4810-A67F-7C7F2794414F}.Release|Any CPU.Build.0 = Release|Any CPU + {F600FB5D-C80C-486E-B2A5-501A5D9FD96B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F600FB5D-C80C-486E-B2A5-501A5D9FD96B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F600FB5D-C80C-486E-B2A5-501A5D9FD96B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F600FB5D-C80C-486E-B2A5-501A5D9FD96B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal