Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target netstandard2.0 and use the new csproj format. #41

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 16 additions & 180 deletions cSharp/Api-ng-sample-code/Api-ng-sample-code/Api-ng-sample-code.csproj
Original file line number Diff line number Diff line change
@@ -1,184 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6B5844C4-BBF3-43D9-9B58-6AEA1FC6E548}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Api_ng_sample_code</RootNamespace>
<AssemblyName>Api-ng-sample-code</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFramework>netstandard2.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
<VersionPrefix>1.0.1</VersionPrefix>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be a breaking change for some people - should it be at least a minor version revision, if not major?

<LangVersion>6</LangVersion>
<Copyright>Copyright © Betfair 2013</Copyright>
<Product>Api-ng-sample-code</Product>
<Company>Betfair</Company>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<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|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject>Api_ng_sample_code.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\lib\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web.Services" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="IClient.cs" />
<Compile Include="JsonRpcClient.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Json\JsonConvert.cs" />
<Compile Include="Json\JsonRequest.cs" />
<Compile Include="Json\JsonResponse.cs" />
<Compile Include="Json\RescriptRequest.cs" />
<Compile Include="MarketTypeResult.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RescriptClient.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="TO\AccountFundsResponse.cs" />
<Compile Include="TO\APINGException.cs" />
<Compile Include="TO\BetStatus.cs" />
<Compile Include="TO\CancelExecutionReport-Mrt.cs" />
<Compile Include="TO\CancelInstruction.cs" />
<Compile Include="TO\CancelInstructionReport.cs" />
<Compile Include="TO\ClearedOrderSummary.cs" />
<Compile Include="TO\ClearedOrderSummaryReport.cs" />
<Compile Include="TO\Competition.cs" />
<Compile Include="TO\CompetitionResult.cs" />
<Compile Include="TO\CurrentOrderSummary.cs" />
<Compile Include="TO\CurrentOrderSummaryReport.cs" />
<Compile Include="TO\Event.cs" />
<Compile Include="TO\EventResult.cs" />
<Compile Include="TO\EventType.cs" />
<Compile Include="TO\EventTypeResult.cs" />
<Compile Include="TO\ExBestOffersOverrides.cs" />
<Compile Include="TO\Exception.cs" />
<Compile Include="TO\ExchangePrices.cs" />
<Compile Include="TO\ExecutionReportErrorCode.cs" />
<Compile Include="TO\ExecutionReportStatus.cs" />
<Compile Include="TO\GroupBy-Mrt.cs" />
<Compile Include="TO\InstructionReportErrorCode.cs" />
<Compile Include="TO\InstructionReportStatus.cs" />
<Compile Include="TO\ItemDescription.cs" />
<Compile Include="TO\LimitOnCloseOrder.cs" />
<Compile Include="TO\LimitOrder.cs" />
<Compile Include="TO\MarketBettingType.cs" />
<Compile Include="TO\MarketBook.cs" />
<Compile Include="TO\MarketCatalogue.cs" />
<Compile Include="TO\MarketDescription.cs" />
<Compile Include="TO\MarketFilter.cs" />
<Compile Include="TO\MarketOnCloseOrder.cs" />
<Compile Include="TO\MarketProfitAndLoss.cs" />
<Compile Include="TO\MarketProjection.cs" />
<Compile Include="TO\MarketSort.cs" />
<Compile Include="TO\MarketStatus.cs" />
<Compile Include="TO\Match.cs" />
<Compile Include="TO\MatchProjection.cs" />
<Compile Include="TO\Order.cs" />
<Compile Include="TO\OrderBy.cs" />
<Compile Include="TO\OrderProjection.cs" />
<Compile Include="TO\OrderStatus.cs" />
<Compile Include="TO\OrderType.cs" />
<Compile Include="TO\PersistenceType.cs" />
<Compile Include="TO\PlaceExecutionReport.cs" />
<Compile Include="TO\PlaceInstruction.cs" />
<Compile Include="TO\PlaceInstructionReport.cs" />
<Compile Include="TO\PriceData.cs" />
<Compile Include="TO\PriceProjection.cs" />
<Compile Include="TO\PriceSize.cs" />
<Compile Include="TO\ReplaceExecutionReport.cs" />
<Compile Include="TO\ReplaceInstruction.cs" />
<Compile Include="TO\ReplaceInstructionReport.cs" />
<Compile Include="TO\RollUpModel.cs" />
<Compile Include="TO\Runner.cs" />
<Compile Include="TO\RunnerDescription.cs" />
<Compile Include="TO\RunnerId-Mrt.cs" />
<Compile Include="TO\RunnerProfitAndLost.cs" />
<Compile Include="TO\RunnerStatus.cs" />
<Compile Include="TO\Side.cs" />
<Compile Include="TO\SortDir.cs" />
<Compile Include="TO\StartingPrices.cs" />
<Compile Include="TO\TimeRange.cs" />
<Compile Include="TO\UpdateExecutionReport.cs" />
<Compile Include="TO\UpdateInstruction.cs" />
<Compile Include="TO\UpdateInstructionReport.cs" />
<Compile Include="TO\Wallet.cs" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />
</ItemGroup>

<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4 Client Profile %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Web.Services.Description" Version="6.0.0" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

</Project>
9 changes: 7 additions & 2 deletions cSharp/Api-ng-sample-code/Api-ng-sample-code/IClient.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Api_ng_sample_code.TO;

namespace Api_ng_sample_code
{
public interface IClient
{
event EventHandler<APINGException> OnAPINGException;

void KeepAlive();
AccountFundsResponse getAccountFunds(Wallet wallet);
IList<EventResult> listEvents(MarketFilter mf, string locale = null);
IList<MarketBook> listRunnerBook(string marketId, string selectionId, double handicap, PriceProjection priceProjection, MatchProjection matchProjection, bool includeOverallPosition, bool partitionMatchedByStrategyRef, ISet<string> customerStrategyRefs, string currencyCode, string locale, DateTime matchedSince, ISet<string> betIds);

/**
* calls api-ng to get a list of events
*
Expand Down
77 changes: 55 additions & 22 deletions cSharp/Api-ng-sample-code/Api-ng-sample-code/JsonRpcClient.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,48 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using Api_ng_sample_code.TO;
using System.Web.Services.Protocols;
using System.Net;
using System.IO;
using Api_ng_sample_code.Json;
using Api_ng_sample_code.TO;
using System.Linq;

namespace Api_ng_sample_code
{
public class JsonRpcClient : HttpWebClientProtocol, IClient
public class JsonRpcClient : HttpWebClientProtocol, IClient
{
public string EndPoint { get; private set; }
public void KeepAlive()
{
WebRequest rq = WebRequest.Create(new Uri(EndPointKeepAlive));
rq.Method = "GET";
rq.Headers.Add(CustomHeaders);
((HttpWebRequest)rq).Accept = "application/json";
using (WebResponse response = GetWebResponse(rq))
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
string s = reader.ReadToEnd();
}
}

private static readonly string LIST_EVENTS_METHOD = "SportsAPING/v1.0/listEvents";
public IList<EventResult> listEvents(MarketFilter marketFilter, string locale = null)
{
var args = new Dictionary<string, object>();
args[FILTER] = marketFilter;
args[LOCALE] = locale;
return Invoke<List<EventResult>>(LIST_EVENTS_METHOD, args);
}

public IList<MarketBook> listRunnerBook(string marketId, string selectionId, double handicap, PriceProjection priceProjection, MatchProjection matchProjection, bool includeOverallPosition, bool partitionMatchedByStrategyRef, ISet<string> customerStrategyRefs, string currencyCode, string locale, DateTime matchedSince, ISet<string> betIds)
{
throw new NotImplementedException();
}

public string EndPointBetting { get; private set; }
public string EndPointAccount { get; private set; }
public string EndPointKeepAlive { get; private set; }
private static readonly IDictionary<string, Type> operationReturnTypeMap = new Dictionary<string, Type>();
public const string APPKEY_HEADER = "X-Application";
public const string SESSION_TOKEN_HEADER = "X-Authentication";
Expand Down Expand Up @@ -63,9 +91,13 @@ public class JsonRpcClient : HttpWebClientProtocol, IClient
private static readonly string GROUP_BY = "groupBy";
private static readonly string INCLUDE_ITEM_DESCRIPTION = "includeItemDescription";

public JsonRpcClient(string endPoint, string appKey, string sessionToken)
{
this.EndPoint = endPoint + "/json-rpc/v1";
private static readonly string[] _AccountApiMethods = { GET_ACCOUNT_FUNDS_METHOD };

public JsonRpcClient(string endPointBetting, string endPointAccount, string endPointKeepAlive, string appKey, string sessionToken)
{
EndPointBetting = endPointBetting + "/json-rpc/v1";
EndPointAccount = endPointAccount + "/json-rpc/v1";
EndPointKeepAlive = endPointKeepAlive;
CustomHeaders = new NameValueCollection();
if (appKey != null)
{
Expand All @@ -75,7 +107,7 @@ public JsonRpcClient(string endPoint, string appKey, string sessionToken)
{
CustomHeaders[SESSION_TOKEN_HEADER] = sessionToken;
}
}
}


public IList<EventTypeResult> listEventTypes(MarketFilter marketFilter, string locale = null)
Expand All @@ -84,7 +116,7 @@ public IList<EventTypeResult> listEventTypes(MarketFilter marketFilter, string l
args[FILTER] = marketFilter;
args[LOCALE] = locale;
return Invoke<List<EventTypeResult>>(LIST_EVENT_TYPES_METHOD, args);

}

public IList<MarketCatalogue> listMarketCatalogue(MarketFilter marketFilter, ISet<MarketProjection> marketProjections, MarketSort marketSort, string maxResult = "1", string locale = null)
Expand All @@ -109,7 +141,7 @@ public IList<MarketTypeResult> listMarketTypes(MarketFilter marketFilter, string
public IList<MarketBook> listMarketBook(IList<string> marketIds, PriceProjection priceProjection, OrderProjection? orderProjection = null, MatchProjection? matchProjection = null, string currencyCode = null, string locale = null)
{
var args = new Dictionary<string, object>();
args[MARKET_IDS]= marketIds;
args[MARKET_IDS] = marketIds;
args[PRICE_PROJECTION] = priceProjection;
args[ORDER_PROJECTION] = orderProjection;
args[MATCH_PROJECTION] = matchProjection;
Expand All @@ -121,11 +153,11 @@ public IList<MarketBook> listMarketBook(IList<string> marketIds, PriceProjection
public PlaceExecutionReport placeOrders(string marketId, string customerRef, IList<PlaceInstruction> placeInstructions, string locale = null)
{
var args = new Dictionary<string, object>();
args[MARKET_ID] = marketId;

args[MARKET_ID] = marketId;
args[INSTRUCTIONS] = placeInstructions;
args[CUSTOMER_REFERENCE] = customerRef;
args[LOCALE] = locale;
args[LOCALE] = locale;

return Invoke<PlaceExecutionReport>(PLACE_ORDERS_METHOD, args);
}
Expand All @@ -134,7 +166,7 @@ public PlaceExecutionReport placeOrders(string marketId, string customerRef, ILi

protected WebRequest CreateWebRequest(Uri uri)
{
WebRequest request = WebRequest.Create(new Uri(EndPoint));
WebRequest request = WebRequest.Create(uri);
request.Method = "POST";
request.ContentType = "application/json-rpc";
request.Headers.Add(HttpRequestHeader.AcceptCharset, "ISO-8859-1,utf-8");
Expand All @@ -143,7 +175,7 @@ protected WebRequest CreateWebRequest(Uri uri)
return request;
}


public event EventHandler<APINGException> OnAPINGException;

public T Invoke<T>(string method, IDictionary<string, object> args = null)
{
Expand All @@ -152,25 +184,27 @@ public T Invoke<T>(string method, IDictionary<string, object> args = null)
if (method.Length == 0)
throw new ArgumentException(null, "method");

var request = CreateWebRequest(new Uri(EndPoint));
var request = _AccountApiMethods.Contains(method) ? CreateWebRequest(new Uri(EndPointAccount)) : CreateWebRequest(new Uri(EndPointBetting));

using (Stream stream = request.GetRequestStream())
using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
{
var call = new JsonRequest { Method = method, Id = 1, Params = args };
JsonConvert.Export(call, writer);
}
Console.WriteLine("\nCalling: " + method + " With args: " + JsonConvert.Serialize<IDictionary<string, object>>(args));
Console.WriteLine("\nCalling: " + method + " With args: " + JsonConvert.Serialize<IDictionary<string, object>>(args));

using (WebResponse response = GetWebResponse(request))
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
var jsonResponse = JsonConvert.Import<T>(reader);
// Console.WriteLine("\nGot Response: " + JsonConvert.Serialize<JsonResponse<T>>(jsonResponse));
// Console.WriteLine("\nGot Response: " + JsonConvert.Serialize<JsonResponse<T>>(jsonResponse));
if (jsonResponse.HasError)
{
throw ReconstituteException(jsonResponse.Error);
APINGException e = ReconstituteException(jsonResponse.Error);
OnAPINGException(this, e);
throw e;
}
else
{
Expand All @@ -179,8 +213,7 @@ public T Invoke<T>(string method, IDictionary<string, object> args = null)
}
}


private static System.Exception ReconstituteException(Api_ng_sample_code.TO.Exception ex)
private static APINGException ReconstituteException(Api_ng_sample_code.TO.Exception ex)
{
var data = ex.Data;

Expand Down
Loading