creating oData client

testing odata interface
This commit is contained in:
2019-03-17 17:32:25 +01:00
parent e52bf0c3a5
commit bbe9f33571
24 changed files with 566 additions and 21 deletions

View File

@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{88DB6691-8EE1-428C-8DA4-50342AEB2C54}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>API.Client</RootNamespace>
<AssemblyName>API.Client</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Data.Edm, Version=5.8.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Data.Edm.5.8.4\lib\net40\Microsoft.Data.Edm.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Data.OData, Version=5.8.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Data.OData.5.8.4\lib\net40\Microsoft.Data.OData.dll</HintPath>
</Reference>
<Reference Include="Microsoft.OData.Core, Version=7.5.3.21218, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.OData.Core.7.5.3\lib\portable-net45+win8+wpa81\Microsoft.OData.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.OData.Edm, Version=7.5.3.21218, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.OData.Edm.7.5.3\lib\portable-net45+win8+wpa81\Microsoft.OData.Edm.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Spatial, Version=7.5.3.21218, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Spatial.7.5.3\lib\portable-net45+win8+wpa81\Microsoft.Spatial.dll</HintPath>
</Reference>
<Reference Include="Simple.OData.Client.Core, Version=5.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Simple.OData.Client.5.6.2\lib\net452\Simple.OData.Client.Core.dll</HintPath>
</Reference>
<Reference Include="Simple.OData.Client.Dynamic, Version=5.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Simple.OData.Client.5.6.2\lib\net452\Simple.OData.Client.Dynamic.dll</HintPath>
</Reference>
<Reference Include="Simple.OData.Client.V3.Adapter, Version=5.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Simple.OData.Client.5.6.2\lib\net452\Simple.OData.Client.V3.Adapter.dll</HintPath>
</Reference>
<Reference Include="Simple.OData.Client.V4.Adapter, Version=5.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Simple.OData.Client.5.6.2\lib\net452\Simple.OData.Client.V4.Adapter.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Spatial, Version=5.8.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\System.Spatial.5.8.4\lib\net40\System.Spatial.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Client.cs" />
<Compile Include="Expresseion.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services\" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Models\API.Models.csproj">
<Project>{8d72ff7d-c085-4c06-9d66-9537b7ac924d}</Project>
<Name>API.Models</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

44
API/API.Client/Client.cs Normal file
View File

@@ -0,0 +1,44 @@

using API.Models;
using Simple.OData.Client;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace API.Client {
public class Client {
public async Task<IEnumerable<Song>> Get() {
var client = new ODataClient("http://localhost/API/odata").For<Song>();
var songs = await client.FindEntriesAsync();
return songs;
}
public async Task<IEnumerable<Song>> Get(Expression<Func<Song, bool>> filterExpression) {
var client = new ODataClient("http://localhost/API/odata").For<Song>();
var songs = await client.Filter(filterExpression).FindEntriesAsync();
return songs;
}
public async Task<Song> Get(long id) {
var client = new ODataClient("http://localhost/API/odata").For<Song>();
var song = await client.Key(id).FindEntryAsync();
return song;
}
public async Task<Song> Post(Song song) {
var client = new ODataClient("http://localhost/API/odata").For<Song>();
var insertedSong = await client.Set(song).InsertEntryAsync();
return insertedSong;
}
public async Task<int> Delete(long id) {
var client = new ODataClient("http://localhost/API/odata").For<Song>();
var count = await client.Key(id).DeleteEntriesAsync();
return count;
}
}
}

View File

@@ -0,0 +1,4 @@
namespace API.Client {
public class Expression {
}
}

View File

@@ -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("API.Client")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("API.Client")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[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("88db6691-8ee1-428c-8da4-50342aeb2c54")]
// 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")]

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Data.Edm" version="5.8.4" targetFramework="net462" />
<package id="Microsoft.Data.OData" version="5.8.4" targetFramework="net462" />
<package id="Microsoft.OData.Core" version="7.5.3" targetFramework="net462" />
<package id="Microsoft.OData.Edm" version="7.5.3" targetFramework="net462" />
<package id="Microsoft.Spatial" version="7.5.3" targetFramework="net462" />
<package id="Simple.OData.Client" version="5.6.2" targetFramework="net462" />
<package id="System.Spatial" version="5.8.4" targetFramework="net462" />
</packages>