Skip to content

Commit 7155cd8

Browse files
committed
add remote delegate invocation sample
1 parent 2708fa7 commit 7155cd8

File tree

16 files changed

+698
-0
lines changed

16 files changed

+698
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
<runtime>
7+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
8+
<dependentAssembly>
9+
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
10+
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
11+
</dependentAssembly>
12+
<dependentAssembly>
13+
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
14+
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
15+
</dependentAssembly>
16+
</assemblyBinding>
17+
</runtime>
18+
</configuration>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="Client.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:Client"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace Client
10+
{
11+
/// <summary>
12+
/// App.xaml 的交互逻辑
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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>{1EF9DD09-4380-462D-987F-33ABF5710F05}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace>Client</RootNamespace>
10+
<AssemblyName>Client</AssemblyName>
11+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<WarningLevel>4</WarningLevel>
15+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
16+
<Deterministic>true</Deterministic>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+
<PlatformTarget>AnyCPU</PlatformTarget>
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<PlatformTarget>AnyCPU</PlatformTarget>
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="BeetleX, Version=1.5.0.21, Culture=neutral, PublicKeyToken=b85c46f9bbc85381, processorArchitecture=MSIL">
39+
<HintPath>..\packages\BeetleX.1.5.0.21\lib\netstandard2.0\BeetleX.dll</HintPath>
40+
</Reference>
41+
<Reference Include="BeetleX.XRPC.Clients, Version=1.0.0.2, Culture=neutral, PublicKeyToken=a7fdfd2bcaab0310, processorArchitecture=MSIL">
42+
<HintPath>..\packages\BeetleX.XRPC.Clients.1.0.0.2\lib\netstandard2.0\BeetleX.XRPC.Clients.dll</HintPath>
43+
</Reference>
44+
<Reference Include="MessagePack, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b4a0369545f0a1be, processorArchitecture=MSIL">
45+
<HintPath>..\packages\MessagePack.2.0.323\lib\netstandard2.0\MessagePack.dll</HintPath>
46+
</Reference>
47+
<Reference Include="MessagePack.Annotations, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b4a0369545f0a1be, processorArchitecture=MSIL">
48+
<HintPath>..\packages\MessagePack.Annotations.2.0.323\lib\netstandard2.0\MessagePack.Annotations.dll</HintPath>
49+
</Reference>
50+
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
51+
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
52+
</Reference>
53+
<Reference Include="Northwind.Data, Version=1.2.3.0, Culture=neutral, processorArchitecture=MSIL">
54+
<HintPath>..\packages\Northwind.Data.1.2.3\lib\netstandard2.0\Northwind.Data.dll</HintPath>
55+
</Reference>
56+
<Reference Include="protobuf-net, Version=2.4.0.0, Culture=neutral, PublicKeyToken=257b51d87d2e4d67, processorArchitecture=MSIL">
57+
<HintPath>..\packages\protobuf-net.2.4.0\lib\net40\protobuf-net.dll</HintPath>
58+
</Reference>
59+
<Reference Include="System" />
60+
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
61+
<HintPath>..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
62+
</Reference>
63+
<Reference Include="System.Configuration" />
64+
<Reference Include="System.Data" />
65+
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
66+
<HintPath>..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll</HintPath>
67+
</Reference>
68+
<Reference Include="System.Numerics" />
69+
<Reference Include="System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
70+
<HintPath>..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
71+
</Reference>
72+
<Reference Include="System.Reflection.DispatchProxy, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
73+
<HintPath>..\packages\System.Reflection.DispatchProxy.4.5.1\lib\net461\System.Reflection.DispatchProxy.dll</HintPath>
74+
</Reference>
75+
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
76+
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
77+
</Reference>
78+
<Reference Include="System.Runtime.Serialization" />
79+
<Reference Include="System.Runtime.Serialization.Primitives, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
80+
<HintPath>..\packages\System.Runtime.Serialization.Primitives.4.3.0\lib\net46\System.Runtime.Serialization.Primitives.dll</HintPath>
81+
<Private>True</Private>
82+
<Private>True</Private>
83+
</Reference>
84+
<Reference Include="System.ServiceModel" />
85+
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
86+
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.3\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
87+
</Reference>
88+
<Reference Include="System.Xml" />
89+
<Reference Include="Microsoft.CSharp" />
90+
<Reference Include="System.Core" />
91+
<Reference Include="System.Xml.Linq" />
92+
<Reference Include="System.Data.DataSetExtensions" />
93+
<Reference Include="System.Net.Http" />
94+
<Reference Include="System.Xaml">
95+
<RequiredTargetFramework>4.0</RequiredTargetFramework>
96+
</Reference>
97+
<Reference Include="WindowsBase" />
98+
<Reference Include="PresentationCore" />
99+
<Reference Include="PresentationFramework" />
100+
</ItemGroup>
101+
<ItemGroup>
102+
<ApplicationDefinition Include="App.xaml">
103+
<Generator>MSBuild:Compile</Generator>
104+
<SubType>Designer</SubType>
105+
</ApplicationDefinition>
106+
<Page Include="MainWindow.xaml">
107+
<Generator>MSBuild:Compile</Generator>
108+
<SubType>Designer</SubType>
109+
</Page>
110+
<Compile Include="App.xaml.cs">
111+
<DependentUpon>App.xaml</DependentUpon>
112+
<SubType>Code</SubType>
113+
</Compile>
114+
<Compile Include="DelegateApi.cs" />
115+
<Compile Include="MainWindow.xaml.cs">
116+
<DependentUpon>MainWindow.xaml</DependentUpon>
117+
<SubType>Code</SubType>
118+
</Compile>
119+
</ItemGroup>
120+
<ItemGroup>
121+
<Compile Include="Properties\AssemblyInfo.cs">
122+
<SubType>Code</SubType>
123+
</Compile>
124+
<Compile Include="Properties\Resources.Designer.cs">
125+
<AutoGen>True</AutoGen>
126+
<DesignTime>True</DesignTime>
127+
<DependentUpon>Resources.resx</DependentUpon>
128+
</Compile>
129+
<Compile Include="Properties\Settings.Designer.cs">
130+
<AutoGen>True</AutoGen>
131+
<DependentUpon>Settings.settings</DependentUpon>
132+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
133+
</Compile>
134+
<EmbeddedResource Include="Properties\Resources.resx">
135+
<Generator>ResXFileCodeGenerator</Generator>
136+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
137+
</EmbeddedResource>
138+
<None Include="packages.config" />
139+
<None Include="Properties\Settings.settings">
140+
<Generator>SettingsSingleFileGenerator</Generator>
141+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
142+
</None>
143+
</ItemGroup>
144+
<ItemGroup>
145+
<None Include="App.config" />
146+
</ItemGroup>
147+
<ItemGroup>
148+
<Analyzer Include="..\packages\MessagePackAnalyzer.2.0.323\analyzers\cs\MessagePackAnalyzer.dll" />
149+
</ItemGroup>
150+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
151+
</Project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Northwind.Data;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Client
9+
{
10+
public delegate Task<List<Order>> ListOrders(int employee, string employeeid);
11+
12+
public delegate Task<List<Employee>> ListEmployees();
13+
14+
public delegate Task<List<Customer>> ListCustomers();
15+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Window x:Class="Client.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:Client"
7+
mc:Ignorable="d"
8+
Title="MainWindow" Height="450" Width="800" Loaded="Window_Loaded">
9+
<Grid>
10+
<Grid.RowDefinitions>
11+
<RowDefinition Height="40"/>
12+
<RowDefinition/>
13+
<RowDefinition Height="30"/>
14+
15+
</Grid.RowDefinitions>
16+
<StatusBar Margin="0" Grid.Row="2">
17+
<Label x:Name="txtTime" Content=""/>
18+
</StatusBar>
19+
<DataGrid x:Name="lstOrders" Margin="0" Grid.Row="1"/>
20+
<ComboBox x:Name="comboEmployees" HorizontalAlignment="Left" SelectedValuePath="EmployeeID" DisplayMemberPath="Name" Margin="10,10,0,0" VerticalAlignment="Top" Width="211"/>
21+
<ComboBox x:Name="comboxCustomer" HorizontalAlignment="Left" SelectedValuePath="CustomerID" DisplayMemberPath="CompanyName" Margin="263,10,0,0" VerticalAlignment="Top" Width="222"/>
22+
<Button x:Name="cmdSearch" Content="Search" HorizontalAlignment="Left" Margin="521,10,0,0" VerticalAlignment="Top" Width="75" Click="CmdSearch_Click"/>
23+
24+
</Grid>
25+
</Window>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using BeetleX.XRPC.Clients;
2+
using BeetleX.XRPC.Packets;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Windows;
9+
using System.Windows.Controls;
10+
using System.Windows.Data;
11+
using System.Windows.Documents;
12+
using System.Windows.Input;
13+
using System.Windows.Media;
14+
using System.Windows.Media.Imaging;
15+
using System.Windows.Navigation;
16+
using System.Windows.Shapes;
17+
18+
namespace Client
19+
{
20+
/// <summary>
21+
/// MainWindow.xaml 的交互逻辑
22+
/// </summary>
23+
public partial class MainWindow : Window
24+
{
25+
public MainWindow()
26+
{
27+
InitializeComponent();
28+
}
29+
30+
XRPCClient mClient;
31+
32+
private async void Window_Loaded(object sender, RoutedEventArgs e)
33+
{
34+
mClient = new XRPCClient("localhost", 9090);
35+
mClient.Options.ParameterFormater = new JsonPacket();
36+
mClient.AddDelegate<Action<DateTime>>(SetTime);
37+
comboEmployees.ItemsSource = from a in await mClient.Delegate<ListEmployees>()() select new { a.EmployeeID, Name = $"{a.FirstName} {a.LastName}" };
38+
comboxCustomer.ItemsSource = await mClient.Delegate<ListCustomers>()();
39+
lstOrders.ItemsSource = await mClient.Delegate<ListOrders>()(0, null);
40+
}
41+
42+
private void SetTime(DateTime time)
43+
{
44+
this.Dispatcher.BeginInvoke(new Action<DateTime>(t =>
45+
{
46+
this.txtTime.Content = t.ToString();
47+
}), time);
48+
}
49+
50+
private async void CmdSearch_Click(object sender, RoutedEventArgs e)
51+
{
52+
lstOrders.ItemsSource = await mClient.Delegate<ListOrders>()(
53+
comboEmployees.SelectedValue!=null?(int)comboEmployees.SelectedValue:0,
54+
comboxCustomer.SelectedValue!=null?(string)comboxCustomer.SelectedValue:null
55+
);
56+
}
57+
}
58+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Reflection;
2+
using System.Resources;
3+
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
5+
using System.Windows;
6+
7+
// 有关程序集的一般信息由以下
8+
// 控制。更改这些特性值可修改
9+
// 与程序集关联的信息。
10+
[assembly: AssemblyTitle("Client")]
11+
[assembly: AssemblyDescription("")]
12+
[assembly: AssemblyConfiguration("")]
13+
[assembly: AssemblyCompany("Microsoft")]
14+
[assembly: AssemblyProduct("Client")]
15+
[assembly: AssemblyCopyright("Copyright © Microsoft 2020")]
16+
[assembly: AssemblyTrademark("")]
17+
[assembly: AssemblyCulture("")]
18+
19+
// 将 ComVisible 设置为 false 会使此程序集中的类型
20+
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
21+
//请将此类型的 ComVisible 特性设置为 true。
22+
[assembly: ComVisible(false)]
23+
24+
//若要开始生成可本地化的应用程序,请设置
25+
//.csproj 文件中的 <UICulture>CultureYouAreCodingWith</UICulture>
26+
//例如,如果您在源文件中使用的是美国英语,
27+
//使用的是美国英语,请将 <UICulture> 设置为 en-US。 然后取消
28+
//对以下 NeutralResourceLanguage 特性的注释。 更新
29+
//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
30+
31+
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32+
33+
34+
[assembly: ThemeInfo(
35+
ResourceDictionaryLocation.None, //主题特定资源词典所处位置
36+
//(未在页面中找到资源时使用,
37+
//或应用程序资源字典中找到时使用)
38+
ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
39+
//(未在页面中找到资源时使用,
40+
//、应用程序或任何主题专用资源字典中找到时使用)
41+
)]
42+
43+
44+
// 程序集的版本信息由下列四个值组成:
45+
//
46+
// 主版本
47+
// 次版本
48+
// 生成号
49+
// 修订号
50+
//
51+
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
52+
// 方法是按如下所示使用“*”: :
53+
// [assembly: AssemblyVersion("1.0.*")]
54+
[assembly: AssemblyVersion("1.0.0.0")]
55+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)