Skip to content

Commit dda609f

Browse files
committed
no message
0 parents  commit dda609f

File tree

241 files changed

+20238
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

241 files changed

+20238
-0
lines changed

EC.Clients/Client.cs

+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using Beetle.Express;
6+
using EC.Remoting;
7+
8+
namespace EC.Clients
9+
{
10+
11+
public interface IClient
12+
{
13+
bool Send(object message);
14+
15+
Beetle.Express.EventPackageReceive Receive
16+
{
17+
get;
18+
set;
19+
}
20+
21+
Beetle.Express.Clients.TcpClient Connection
22+
{
23+
get;
24+
}
25+
26+
void RegisterRemote(long id, MethodReturnArgs e);
27+
28+
void UnRegisterRemote(long id);
29+
30+
MethodReturnArgs Pop();
31+
32+
void Push(MethodReturnArgs args);
33+
34+
35+
36+
}
37+
38+
public class Client<T> : IClient where T : Beetle.Express.IPackage, new()
39+
{
40+
public Client(string host, int port = 10034)
41+
{
42+
mConnection = new Beetle.Express.Clients.TcpClient(host, port, new T());
43+
mConnection.Package.Receive = OnReceive;
44+
mPool.Push(new MethodReturnArgs());
45+
mPool.Push(new MethodReturnArgs());
46+
mPool.Push(new MethodReturnArgs());
47+
mPool.Push(new MethodReturnArgs());
48+
mPool.Push(new MethodReturnArgs());
49+
}
50+
51+
private Beetle.Express.Clients.TcpClient mConnection;
52+
53+
public bool Send(object message)
54+
{
55+
return mConnection.SendMessage(message);
56+
}
57+
58+
private MethodReturnArgs mMethodReturnArgs = null;
59+
60+
private Dictionary<long, MethodReturnArgs> mRemotingMethods = new Dictionary<long, MethodReturnArgs>(64);
61+
62+
private void OnReceive(object sender, PackageReceiveArgs e)
63+
{
64+
lock (this)
65+
{
66+
if (e.Message is Remoting.RPC.MethodResult)
67+
{
68+
Remoting.RPC.MethodResult result = (Remoting.RPC.MethodResult)e.Message;
69+
if (mRemotingMethods.TryGetValue(result.ID, out mMethodReturnArgs))
70+
{
71+
mMethodReturnArgs.Import(result);
72+
}
73+
}
74+
else
75+
{
76+
if (mMethodReturnArgs == null)
77+
{
78+
if (Receive != null)
79+
Receive(sender, e);
80+
}
81+
else
82+
{
83+
if (mMethodReturnArgs.Status == InvokeStatus.Return)
84+
{
85+
mMethodReturnArgs.SetReturn(e.Message);
86+
}
87+
else if (mMethodReturnArgs.Status == InvokeStatus.Parameter)
88+
{
89+
mMethodReturnArgs.AddParameter(e.Message);
90+
}
91+
}
92+
}
93+
if (mMethodReturnArgs != null && mMethodReturnArgs.Status == InvokeStatus.Completed)
94+
{
95+
mMethodReturnArgs.Completed();
96+
mMethodReturnArgs = null;
97+
}
98+
}
99+
100+
}
101+
102+
private Stack<MethodReturnArgs> mPool = new Stack<MethodReturnArgs>();
103+
104+
public Beetle.Express.EventPackageReceive Receive
105+
{
106+
get;
107+
set;
108+
}
109+
110+
public SERVICE CreateInstance<SERVICE>()
111+
{
112+
SERVICE service = ProxyFactory.CursorFactory.CreateInstance<SERVICE>();
113+
((ICommunicationObject)service).Client = this;
114+
return service;
115+
}
116+
117+
public Beetle.Express.Clients.TcpClient Connection
118+
{
119+
get
120+
{
121+
return mConnection;
122+
}
123+
}
124+
125+
126+
MethodReturnArgs IClient.Pop()
127+
{
128+
MethodReturnArgs result;
129+
lock (mPool)
130+
{
131+
if (mPool.Count > 0)
132+
{
133+
result = mPool.Pop();
134+
result.Reset();
135+
}
136+
result = new MethodReturnArgs();
137+
return result;
138+
}
139+
}
140+
141+
void IClient.Push(MethodReturnArgs args)
142+
{
143+
lock (mPool)
144+
{
145+
mPool.Push(args);
146+
}
147+
}
148+
void IClient.RegisterRemote(long id, MethodReturnArgs e)
149+
{
150+
lock (mRemotingMethods)
151+
{
152+
mRemotingMethods[id] = e;
153+
}
154+
}
155+
156+
void IClient.UnRegisterRemote(long id)
157+
{
158+
lock (mRemotingMethods)
159+
{
160+
mRemotingMethods.Remove(id);
161+
}
162+
}
163+
}
164+
}

EC.Clients/EC.Clients.csproj

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" 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>{D1FD3CCC-2196-4A35-BF7E-3EE294BD4047}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>EC.Clients</RootNamespace>
11+
<AssemblyName>EC.Clients</AssemblyName>
12+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="Beetle.Express">
34+
<HintPath>..\Lib\4.0\Beetle.Express.dll</HintPath>
35+
</Reference>
36+
<Reference Include="MsgPack">
37+
<HintPath>..\Lib\4.0\MsgPack.dll</HintPath>
38+
</Reference>
39+
<Reference Include="protobuf-net">
40+
<HintPath>..\Lib\4.0\protobuf-net.dll</HintPath>
41+
</Reference>
42+
<Reference Include="System" />
43+
<Reference Include="System.configuration" />
44+
<Reference Include="System.Core" />
45+
<Reference Include="System.Xml.Linq" />
46+
<Reference Include="System.Data.DataSetExtensions" />
47+
<Reference Include="Microsoft.CSharp" />
48+
<Reference Include="System.Data" />
49+
<Reference Include="System.Xml" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<Compile Include="..\EC\Message.cs">
53+
<Link>Message.cs</Link>
54+
</Compile>
55+
<Compile Include="..\EC\MessageAttribute.cs">
56+
<Link>MessageAttribute.cs</Link>
57+
</Compile>
58+
<Compile Include="..\EC\TypeMapping.cs">
59+
<Link>TypeMapping.cs</Link>
60+
</Compile>
61+
<Compile Include="Remoting\MethodReturnArgs.cs" />
62+
<Compile Include="Client.cs" />
63+
<Compile Include="ICallBackMessage.cs" />
64+
<Compile Include="IkendeCore.cs" />
65+
<Compile Include="MsgPackPacket.cs" />
66+
<Compile Include="Packet.cs" />
67+
<Compile Include="Properties\AssemblyInfo.cs" />
68+
<Compile Include="ProtobufPacket.cs" />
69+
<Compile Include="Remoting\ECProxyHandler.cs" />
70+
<Compile Include="Remoting\HandleParameter.cs" />
71+
<Compile Include="Remoting\ICommunicationObject.cs" />
72+
<Compile Include="Remoting\IProxyHandler.cs" />
73+
<Compile Include="Remoting\MethodHandler.cs" />
74+
<Compile Include="Remoting\ProxyBuilder.cs" />
75+
<Compile Include="Remoting\ProxyException.cs" />
76+
<Compile Include="Remoting\ProxyFactory.cs" />
77+
<Compile Include="Remoting\RemoteInvokeArgs.cs" />
78+
<Compile Include="Remoting\Result.cs" />
79+
<Compile Include="Remoting\ResultStatus.cs" />
80+
<Compile Include="Remoting\RPC\Header.cs" />
81+
<Compile Include="Remoting\RPC\MethodCall.cs" />
82+
<Compile Include="Remoting\RPC\MethodResult.cs" />
83+
<Compile Include="Remoting\Script\AssemblyLoad.cs" />
84+
<Compile Include="Remoting\Script\Script.cs" />
85+
<Compile Include="SyncClient.cs" />
86+
<Compile Include="TypeMapper.cs" />
87+
<Compile Include="Utils.cs" />
88+
</ItemGroup>
89+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
90+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
91+
Other similar extension points exist, see Microsoft.Common.targets.
92+
<Target Name="BeforeBuild">
93+
</Target>
94+
<Target Name="AfterBuild">
95+
</Target>
96+
-->
97+
</Project>

EC.Clients/EC.Clients.csproj.user

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ProjectView>ProjectFiles</ProjectView>
5+
</PropertyGroup>
6+
</Project>

EC.Clients/ICallBackMessage.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace EC.Clients
7+
{
8+
public interface ICallBackMessage
9+
{
10+
long CallBackID { get; set; }
11+
}
12+
}

0 commit comments

Comments
 (0)