This repository has been archived by the owner on Jul 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 196
/
EasyClient.cs
57 lines (45 loc) · 1.53 KB
/
EasyClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using SuperSocket.ProtoBase;
namespace SuperSocket.ClientEngine
{
public class EasyClient : EasyClientBase
{
private Action<IPackageInfo> m_Handler;
public void Initialize<TPackageInfo>(IReceiveFilter<TPackageInfo> receiveFilter, Action<TPackageInfo> handler)
where TPackageInfo : IPackageInfo
{
PipeLineProcessor = new DefaultPipelineProcessor<TPackageInfo>(receiveFilter);
m_Handler = (p) => handler((TPackageInfo)p);
}
protected override void HandlePackage(IPackageInfo package)
{
var handler = m_Handler;
if (handler == null)
return;
handler(package);
}
}
public class EasyClient<TPackageInfo> : EasyClientBase
where TPackageInfo : IPackageInfo
{
public event EventHandler<PackageEventArgs<TPackageInfo>> NewPackageReceived;
public EasyClient()
{
}
public virtual void Initialize(IReceiveFilter<TPackageInfo> receiveFilter)
{
PipeLineProcessor = new DefaultPipelineProcessor<TPackageInfo>(receiveFilter);
}
protected override void HandlePackage(IPackageInfo package)
{
var handler = NewPackageReceived;
if (handler == null)
return;
handler(this, new PackageEventArgs<TPackageInfo>((TPackageInfo)package));
}
}
}