forked from DmitryChabanin/xmpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.cs
More file actions
124 lines (96 loc) · 3.98 KB
/
Client.cs
File metadata and controls
124 lines (96 loc) · 3.98 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Client.cs
//
//Copyright © 2006 - 2012 Dieter Lunn
//Modified 2012 Paul Freund ( freund.paul@lvl3.org )
//
//This library is free software; you can redistribute it and/or modify it under
//the terms of the GNU Lesser General Public License as published by the Free
//Software Foundation; either version 3 of the License, or (at your option)
//any later version.
//
//This library is distributed in the hope that it will be useful, but WITHOUT
//ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
//FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
//
//You should have received a copy of the GNU Lesser General Public License along
//with this library; if not, write to the Free Software Foundation, Inc., 59
//Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using XMPP.common;
using XMPP.tags;
namespace XMPP
{
public enum Transport
{
Socket,
BoSH
}
public class Client : IDisposable
{
private readonly Manager Manager;
public Client() : this(Transport.Socket)
{
}
public Client(Transport transport)
{
Transport = transport;
Manager = new Manager(transport);
}
public void Dispose() { Dispose(true); }
virtual protected void Dispose(bool managed)
{
Manager.Dispose();
}
public Transport Transport { get; private set; }
#region properties
public readonly string Version = typeof(Client).GetTypeInfo().Assembly.GetName().Version.ToString();
public Settings Settings { get { return Manager.Settings; } }
public bool Connected { get { return Manager.IsConnected; } }
public ManualResetEvent ProcessComplete { get { return Manager.ProcessComplete; } }
#endregion
#region events
public event Events.ExternalError OnError { add { Manager.Events.OnError += value; } remove { Manager.Events.OnError -= value; } }
public event Events.ExternalNewTag OnNewTag { add { Manager.Events.OnNewTag += value; } remove { Manager.Events.OnNewTag -= value; } }
public event Events.ExternalLogMessage OnLogMessage { add { Manager.Events.OnLogMessage += value; } remove { Manager.Events.OnLogMessage -= value; } }
public event Events.ExternalReady OnReady { add { Manager.Events.OnReady += value; } remove { Manager.Events.OnReady -= value; } }
public event Events.ExternalResourceBound OnResourceBound { add { Manager.Events.OnResourceBound += value; } remove { Manager.Events.OnResourceBound -= value; } }
public event Events.ExternalConnected OnConnected { add { Manager.Events.OnConnected += value; } remove { Manager.Events.OnConnected -= value; } }
public event Events.ExternalDisconnected OnDisconnected { add { Manager.Events.OnDisconnected += value; } remove { Manager.Events.OnDisconnected -= value; } }
public event Events.ExternalReceive OnReceive { add { Manager.Events.OnReceive += value; } remove { Manager.Events.OnReceive -= value; } }
public event Events.ExternalChunk OnChunk { add { Manager.Events.OnChunk += value; } remove { Manager.Events.OnChunk -= value; } }
#endregion
#region actions
public void Connect()
{
Manager.Events.Connect(null, default(EventArgs));
}
public Task ConnectAsync()
{
return Task.Run(() => Connect());
}
public void Disconnect()
{
Manager.Events.Disconnect(null, default(EventArgs));
}
public Task DisconnectAsync()
{
return Task.Run(() => Disconnect());
}
public void Send(Tag tag)
{
Send(new TagEventArgs(tag));
}
public Task SendAsync(Tag tag)
{
return Task.Run(() => Send(tag));
}
public void Send(TagEventArgs e)
{
Manager.Events.Send(null, e);
}
#endregion
}
}