Skip to content

Commit d3c2c47

Browse files
committed
Simple winforms example
1 parent 1d9ef07 commit d3c2c47

11 files changed

+657
-0
lines changed

ExchangeSharp.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt
2020
EndProject
2121
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExchangeSharpTests", "ExchangeSharpTests\ExchangeSharpTests.csproj", "{85BBD19C-5702-4394-BD7C-CE08309F6F49}"
2222
EndProject
23+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExchangeSharpWinForms", "ExchangeSharpWinForms\ExchangeSharpWinForms.csproj", "{571623F9-1652-4669-8E17-A6FAD1426181}"
24+
EndProject
2325
Global
2426
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2527
Debug|Any CPU = Debug|Any CPU
@@ -38,6 +40,10 @@ Global
3840
{85BBD19C-5702-4394-BD7C-CE08309F6F49}.Debug|Any CPU.Build.0 = Debug|Any CPU
3941
{85BBD19C-5702-4394-BD7C-CE08309F6F49}.Release|Any CPU.ActiveCfg = Release|Any CPU
4042
{85BBD19C-5702-4394-BD7C-CE08309F6F49}.Release|Any CPU.Build.0 = Release|Any CPU
43+
{571623F9-1652-4669-8E17-A6FAD1426181}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
44+
{571623F9-1652-4669-8E17-A6FAD1426181}.Debug|Any CPU.Build.0 = Debug|Any CPU
45+
{571623F9-1652-4669-8E17-A6FAD1426181}.Release|Any CPU.ActiveCfg = Release|Any CPU
46+
{571623F9-1652-4669-8E17-A6FAD1426181}.Release|Any CPU.Build.0 = Release|Any CPU
4147
EndGlobalSection
4248
GlobalSection(SolutionProperties) = preSolution
4349
HideSolutionNode = FALSE

ExchangeSharpWinForms/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{571623F9-1652-4669-8E17-A6FAD1426181}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace>ExchangeSharpWinForms</RootNamespace>
10+
<AssemblyName>ExchangeSharpWinForms</AssemblyName>
11+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="System" />
37+
<Reference Include="System.Core" />
38+
<Reference Include="System.Xml.Linq" />
39+
<Reference Include="System.Data.DataSetExtensions" />
40+
<Reference Include="Microsoft.CSharp" />
41+
<Reference Include="System.Data" />
42+
<Reference Include="System.Deployment" />
43+
<Reference Include="System.Drawing" />
44+
<Reference Include="System.Net.Http" />
45+
<Reference Include="System.Windows.Forms" />
46+
<Reference Include="System.Xml" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<Compile Include="MainForm.cs">
50+
<SubType>Form</SubType>
51+
</Compile>
52+
<Compile Include="MainForm.Designer.cs">
53+
<DependentUpon>MainForm.cs</DependentUpon>
54+
</Compile>
55+
<Compile Include="Properties\AssemblyInfo.cs" />
56+
<EmbeddedResource Include="MainForm.resx">
57+
<DependentUpon>MainForm.cs</DependentUpon>
58+
</EmbeddedResource>
59+
<EmbeddedResource Include="Properties\Resources.resx">
60+
<Generator>ResXFileCodeGenerator</Generator>
61+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
62+
<SubType>Designer</SubType>
63+
</EmbeddedResource>
64+
<Compile Include="Properties\Resources.Designer.cs">
65+
<AutoGen>True</AutoGen>
66+
<DependentUpon>Resources.resx</DependentUpon>
67+
</Compile>
68+
<None Include="Properties\Settings.settings">
69+
<Generator>SettingsSingleFileGenerator</Generator>
70+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
71+
</None>
72+
<Compile Include="Properties\Settings.Designer.cs">
73+
<AutoGen>True</AutoGen>
74+
<DependentUpon>Settings.settings</DependentUpon>
75+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
76+
</Compile>
77+
</ItemGroup>
78+
<ItemGroup>
79+
<None Include="App.config" />
80+
</ItemGroup>
81+
<ItemGroup>
82+
<ProjectReference Include="..\ExchangeSharp\ExchangeSharp.csproj">
83+
<Project>{b4addaef-95bf-4fda-8b2f-8b899eda3f45}</Project>
84+
<Name>ExchangeSharp</Name>
85+
</ProjectReference>
86+
</ItemGroup>
87+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
88+
</Project>

ExchangeSharpWinForms/MainForm.Designer.cs

Lines changed: 93 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ExchangeSharpWinForms/MainForm.cs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows.Forms;
10+
11+
using ExchangeSharp;
12+
13+
namespace ExchangeSharpWinForms
14+
{
15+
public partial class MainForm : Form
16+
{
17+
/// <summary>
18+
/// The main entry point for the application.
19+
/// </summary>
20+
[STAThread]
21+
static void Main()
22+
{
23+
Application.EnableVisualStyles();
24+
Application.SetCompatibleTextRenderingDefault(false);
25+
Application.Run(new MainForm());
26+
}
27+
28+
private async void FetchTickers()
29+
{
30+
if (!Created || string.IsNullOrWhiteSpace(cmbExchange.SelectedItem as string))
31+
{
32+
return;
33+
}
34+
35+
this.UseWaitCursor = true;
36+
try
37+
{
38+
var api = ExchangeAPI.GetExchangeAPI(cmbExchange.SelectedItem as string);
39+
var tickers = await api.GetTickersAsync();
40+
StringBuilder b = new StringBuilder();
41+
foreach (var ticker in tickers)
42+
{
43+
b.AppendFormat("{0,-12}{1}\r\n", ticker.Key, ticker.Value);
44+
}
45+
textTickersResult.Text = b.ToString();
46+
}
47+
catch (Exception ex)
48+
{
49+
textTickersResult.Text = ex.ToString();
50+
}
51+
finally
52+
{
53+
Invoke(new Action(() => this.UseWaitCursor = false));
54+
}
55+
}
56+
57+
public MainForm()
58+
{
59+
InitializeComponent();
60+
foreach (var exchange in ExchangeAPI.GetExchangeAPIs())
61+
{
62+
cmbExchange.Items.Add(exchange.Name);
63+
}
64+
cmbExchange.SelectedIndex = 0;
65+
}
66+
67+
protected override void OnShown(EventArgs e)
68+
{
69+
base.OnShown(e);
70+
FetchTickers();
71+
}
72+
73+
private void Button1_Click(object sender, EventArgs e)
74+
{
75+
FetchTickers();
76+
}
77+
78+
private void cmbExchange_SelectedIndexChanged(object sender, EventArgs e)
79+
{
80+
FetchTickers();
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)