Skip to content

Commit d9907e8

Browse files
committed
Added netstandard2 as an additional target
2 parents e93198a + 0a5156b commit d9907e8

11 files changed

+236
-160
lines changed

Core/XmppCore.cs

+8-96
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using ARSoft.Tools.Net.Dns;
2-
using XMPPEngineer.Core.Sasl;
1+
using XMPPEngineer.Core.Sasl;
32
using System;
43
using System.Collections.Concurrent;
54
using System.Collections.Generic;
@@ -22,21 +21,6 @@ namespace XMPPEngineer.Core
2221
/// <remarks>For implementation details, refer to RFC 3920.</remarks>
2322
public class XmppCore : IDisposable
2423
{
25-
/// <summary>
26-
/// The DNS SRV name records
27-
/// </summary>
28-
private List<SrvRecord> dnsRecordList;
29-
30-
/// <summary>
31-
/// The current SRV DNS record to use
32-
/// </summary>
33-
private SrvRecord dnsCurrent;
34-
35-
/// <summary>
36-
/// Bool variable indicating whether DNS records are initialised
37-
/// </summary>
38-
private bool dnsIsInit = false;
39-
4024
/// <summary>
4125
/// The TCP connection to the XMPP server.
4226
/// </summary>
@@ -387,18 +371,9 @@ public XmppCore(string hostname, string username, string password, string server
387371
int port = 5222, bool tls = true, RemoteCertificateValidationCallback validate = null)
388372
{
389373
if (String.IsNullOrWhiteSpace(server)) {
390-
moveNextSrvDNS(hostname);
391-
if (dnsCurrent != null)
392-
{
393-
Hostname = dnsCurrent.Target.ToString();
394-
Port = dnsCurrent.Port;
395-
}
396-
else
397-
{
398-
Hostname = hostname;
399-
Server = hostname;
400-
Port = port;
401-
}
374+
Hostname = hostname;
375+
Server = hostname;
376+
Port = port;
402377
}
403378
else {
404379
Server = server;
@@ -454,18 +429,10 @@ public XmppCore(string hostname, string server, int port = 5222, bool tls = true
454429
{
455430
if (String.IsNullOrWhiteSpace(server))
456431
{
457-
moveNextSrvDNS(hostname);
458-
if (dnsCurrent != null)
459-
{
460-
Hostname = dnsCurrent.Target.ToString();
461-
Port = dnsCurrent.Port;
462-
}
463-
else
464-
{
465-
Hostname = hostname;
466-
Server = hostname;
467-
Port = port;
468-
}
432+
433+
Hostname = hostname;
434+
Server = hostname;
435+
Port = port;
469436
}
470437
else {
471438
Server = server;
@@ -477,61 +444,6 @@ public XmppCore(string hostname, string server, int port = 5222, bool tls = true
477444
Validate = validate;
478445
}
479446

480-
/// <summary>
481-
/// Initialises and resolves the DNS Domain, and set to dnsCurrent the next
482-
/// SRV record to use
483-
/// </summary>
484-
/// <param name="domain">XMPP Domain</param>
485-
/// <returns>XMPP server hostname for the Domain</returns>
486-
private SrvRecord moveNextSrvDNS(string domain)
487-
{
488-
domain.ThrowIfNullOrEmpty("domain");
489-
//If already a lookup has being made return
490-
if (dnsIsInit)
491-
{
492-
//If it is already init we remove the current
493-
if (dnsRecordList != null && dnsCurrent != null) dnsRecordList.Remove(dnsCurrent);
494-
dnsCurrent = dnsRecordList.FirstOrDefault();
495-
return dnsCurrent;
496-
};
497-
dnsIsInit = true;
498-
499-
var domainName = ARSoft.Tools.Net.DomainName.Parse(("_xmpp-client._tcp." + domain));
500-
DnsMessage dnsMessage = DnsClient.Default.Resolve(domainName, RecordType.Srv);
501-
if ((dnsMessage == null) || ((dnsMessage.ReturnCode != ReturnCode.NoError) && (dnsMessage.ReturnCode != ReturnCode.NxDomain)))
502-
{
503-
//If DNS SRV records lookup fails then continue with the host name
504-
#if DEBUG
505-
System.Diagnostics.Debug.WriteLine("DNS Lookup Failed");
506-
#endif
507-
return null;
508-
}
509-
else
510-
{
511-
var tempList = new List<SrvRecord>();
512-
513-
foreach (DnsRecordBase dnsRecord in dnsMessage.AnswerRecords)
514-
{
515-
SrvRecord srvRecord = dnsRecord as SrvRecord;
516-
if (srvRecord != null)
517-
{
518-
tempList.Add(srvRecord);
519-
Console.WriteLine(srvRecord.ToString());
520-
Console.WriteLine(" |--- Name " + srvRecord.Name);
521-
Console.WriteLine(" |--- Port: " + srvRecord.Port);
522-
Console.WriteLine(" |--- Priority" + srvRecord.Priority);
523-
Console.WriteLine(" |--- Type " + srvRecord.RecordType);
524-
Console.WriteLine(" |--- Target: " + srvRecord.Target);
525-
Console.WriteLine();
526-
}
527-
}
528-
dnsRecordList = tempList.OrderBy(o => o.Priority).ThenBy(order => order.Weight).ToList();
529-
530-
dnsCurrent = dnsRecordList.FirstOrDefault();
531-
return dnsCurrent;
532-
}
533-
}
534-
535447
/// <summary>
536448
/// Establishes a connection to the XMPP server.
537449
/// </summary>

Extensions/XEP-0045/GroupPresenceEventArgs.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class GroupPresenceEventArgs : EventArgs
1313
/// </summary>
1414
public Occupant Person { get; set; }
1515

16+
public Jid Group { get; }
17+
1618
/// <summary>
1719
///
1820
/// </summary>
@@ -22,10 +24,12 @@ public class GroupPresenceEventArgs : EventArgs
2224
///
2325
/// </summary>
2426
/// <param name="person"></param>
27+
/// <param name="group"></param>
2528
/// <param name="statuses"></param>
26-
public GroupPresenceEventArgs(Occupant person, IEnumerable<MucStatusType> statuses) : base()
29+
public GroupPresenceEventArgs(Occupant person, Jid group, IEnumerable<MucStatusType> statuses) : base()
2730
{
2831
Person = person;
32+
Group = group;
2933
Statuses = statuses;
3034
}
3135
}

Extensions/XEP-0045/MultiUserChat.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public bool Input (Im.Presence stanza)
172172
bool hasNoAvailability = string.IsNullOrWhiteSpace(stanza.Data["show"]?.InnerText);
173173

174174
if (person != null) {
175-
PrescenceChanged.Raise (this, new GroupPresenceEventArgs (person, statusCodeList));
175+
PrescenceChanged.Raise (this, new GroupPresenceEventArgs (person, new Jid(stanza.From.Domain, stanza.From.Node), statusCodeList));
176176
return hasNoAvailability;
177177
}
178178
}

Extensions/vCardAvatars.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using S22.Xmpp.Core;
2-
using S22.Xmpp.Im;
1+
using XMPPEngineer;
2+
using XMPPEngineer.Core;
3+
using XMPPEngineer.Im;
4+
using XMPPEngineer.Extensions;
35
using System;
46
using System.Collections.Generic;
57
using System.IO;
@@ -99,7 +101,7 @@ public void SetAvatar(Stream stream)
99101

100102
if (iq.Type == IqType.Result) {
101103
// Result must contain a 'feature' element.
102-
im.SendPresence(new S22.Xmpp.Im.Presence(null, null, PresenceType.Available, null, null, Xml.Element("x", "vcard-temp:x:update").Child(Xml.Element("photo").Text(hash))));
104+
im.SendPresence(new XMPPEngineer.Im.Presence(null, null, PresenceType.Available, null, null, Xml.Element("x", "vcard-temp:x:update").Child(Xml.Element("photo").Text(hash))));
103105
}
104106

105107
});

Properties/AssemblyInfo.cs

-35
This file was deleted.

XMPPEngineer.csproj

+8-1
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,11 @@
263263
<Target Name="AfterBuild">
264264
</Target>
265265
-->
266-
</Project>
266+
</Project>
267+
<Project Sdk="Microsoft.NET.Sdk">
268+
269+
<PropertyGroup>
270+
<TargetFramework>netcoreapp2.0</TargetFramework>
271+
</PropertyGroup>
272+
273+
</Project>

XMPPEngineer.sln

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
44
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XMPPEngineer", "XMPPEngineer.csproj", "{9EA99E39-8C5C-4F69-9F3F-8E3074C518FA}"
55
EndProject
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XMPPEngineerTest", "..\XMPPEngineerTest\XMPPEngineerTest.csproj", "{170B8AF1-5FA4-4925-8BC1-519CF5D5AB11}"
7+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XMPPEngineer", "XMPPEngineer.csproj", "{C462F45F-CC89-4E71-971D-79E4495B6C2B}"
8+
EndProject
9+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XMPPEngineerTest", "XMPPEngineerTest\XMPPEngineerTest.csproj", "{5FB57B73-A453-4489-8DBA-ED489832D81E}"
710
EndProject
811
Global
912
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -30,4 +33,14 @@ Global
3033
{170B8AF1-5FA4-4925-8BC1-519CF5D5AB11}.Release|x86.ActiveCfg = Release|Any CPU
3134
{170B8AF1-5FA4-4925-8BC1-519CF5D5AB11}.Release|x86.Build.0 = Release|Any CPU
3235
EndGlobalSection
36+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
37+
{C462F45F-CC89-4E71-971D-79E4495B6C2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38+
{C462F45F-CC89-4E71-971D-79E4495B6C2B}.Debug|Any CPU.Build.0 = Debug|Any CPU
39+
{C462F45F-CC89-4E71-971D-79E4495B6C2B}.Release|Any CPU.ActiveCfg = Release|Any CPU
40+
{C462F45F-CC89-4E71-971D-79E4495B6C2B}.Release|Any CPU.Build.0 = Release|Any CPU
41+
{5FB57B73-A453-4489-8DBA-ED489832D81E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42+
{5FB57B73-A453-4489-8DBA-ED489832D81E}.Debug|Any CPU.Build.0 = Debug|Any CPU
43+
{5FB57B73-A453-4489-8DBA-ED489832D81E}.Release|Any CPU.ActiveCfg = Release|Any CPU
44+
{5FB57B73-A453-4489-8DBA-ED489832D81E}.Release|Any CPU.Build.0 = Release|Any CPU
45+
EndGlobalSection
3346
EndGlobal

XMPPEngineer.userprefs

-23
This file was deleted.

XMPPEngineerTest/Program (copy).cs

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
//using System;
2+
3+
//namespace XMPPEngineerTest
4+
//{
5+
// class MainClass
6+
// {
7+
// public static void Main(string[] args)
8+
// {
9+
// /*
10+
// XMPPEngineer.Core.XmppCore client = new XMPPEngineer.Core.XmppCore(
11+
// "alchemy.local",
12+
// "test",
13+
// "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE0OTI2Mzc1NzMsImV4cCI6MTUyNDE3MzU3MywiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoianJvY2tldEBleGFtcGxlLmNvbSIsInVzZXJuYW1lIjoidGVzdCIsIm5ldHdvcmsiOiJhbGNoZW15LmxvY2FsIn0.0IYkS8KH22kai_j6hRcjy5x7Lvwb6TG5XyRY8n9fym0",
14+
// "dev-lite-citym-access.westeurope.cloudapp.azure.com"
15+
// );*/
16+
17+
// XMPPEngineer.Client.XmppClient client = new XMPPEngineer.Client.XmppClient(
18+
// "alchemy.local",
19+
// "steven",
20+
// "test",
21+
// "dev-lite-citym-access.westeurope.cloudapp.azure.com"
22+
// );
23+
24+
// client.Connect("mobile");
25+
26+
// client.Error += (sender, e) => {
27+
// Console.WriteLine(e.ToString());
28+
// };
29+
// client.Message += (sender, e) => {
30+
// Console.WriteLine(e.ToString());
31+
// };
32+
// //client.Iq += (sender, e) => {
33+
// // Console.WriteLine(e.ToString());
34+
// //};
35+
// //client.Presence += (sender, e) =>
36+
// //{
37+
// // Console.WriteLine(e.ToString());
38+
// //};
39+
// ///client.A += (sender, e) =>
40+
// ///{
41+
// ///Console.WriteLine(e.ToString());
42+
// ///};
43+
44+
// //RunBasic(client);
45+
// //RunStreamManagement(client);
46+
// RunStreamManagement2(client);
47+
48+
// Console.ReadKey();
49+
// }
50+
51+
// private static void RunBasic(XMPPEngineer.Core.XmppCore client)
52+
// {
53+
// XMPPEngineer.Im.Message message = new XMPPEngineer.Im.Message(new XMPPEngineer.Jid("admin@alchemy.local"), "ok - " + DateTime.Now.ToLongTimeString());
54+
// client.SendMessage(message);
55+
// }
56+
57+
// private static void RunStreamManagement(XMPPEngineer.Core.XmppCore client)
58+
// {
59+
// client.StreamManagementEnabled += (sdr, evt) =>
60+
// {
61+
// //XMPPEngineer.Im.Message message = new XMPPEngineer.Im.Message(new XMPPEngineer.Jid("admin@alchemy.local"), "ok - " + DateTime.Now.ToLongTimeString());
62+
// //client.SendMessage(message);
63+
64+
// // send a message in a loop
65+
66+
// System.Timers.Timer timer = new System.Timers.Timer(10000);
67+
// timer.Elapsed += (sender, e) => {
68+
// XMPPEngineer.Im.Message messagex = new XMPPEngineer.Im.Message(new XMPPEngineer.Jid("admin@alchemy.local"), "ok - " + DateTime.Now.ToLongTimeString());
69+
// client.SendMessage(messagex);
70+
// };
71+
// timer.Enabled = true;
72+
// timer.Start();
73+
74+
// // // Resumes a stream that was disconnected for some reason - this will only work within the time window allows by the server to stream resumption - which defaults to 20 seconds
75+
// // // We only need to do this if we detect we have lost a connection to the server - probably from no acks.
76+
// // ///client.StreamManagementResumed += (sender, e) => {
77+
// // // continue in here
78+
// // ///};
79+
// // //client.ResumeStream();
80+
81+
// // ///XMPPEngineer.Im.Message message = new XMPPEngineer.Im.Message(new XMPPEngineer.Jid("admin@alchemy.local"), "ok - " + DateTime.Now.ToLongTimeString());
82+
// // ///client.SendMessage(message);
83+
// };
84+
85+
// // enable stream management and recovery mode
86+
// ///client.NumberOfItemsBeforeServerAck = 3;
87+
// ///client.NumberOfSecondsBeforeServerAck = 15;//30;
88+
// client.EnableStreamManagement(true);
89+
// }
90+
91+
// private static void RunStreamManagement2(XMPPEngineer.Client.XmppClient client)
92+
// {
93+
// client.StreamManagementEnabled += (sdr, evt) =>
94+
// {
95+
// // send a message in a loop
96+
97+
// System.Timers.Timer timer = new System.Timers.Timer(10000);
98+
// timer.Elapsed += (sender, e) =>
99+
// {
100+
// XMPPEngineer.Im.Message messagex = new XMPPEngineer.Im.Message(new XMPPEngineer.Jid("admin@alchemy.local"), "ok - " + DateTime.Now.ToLongTimeString());
101+
// client.SendMessage(messagex);
102+
// };
103+
// timer.Enabled = true;
104+
// timer.Start();
105+
// };
106+
107+
// // enable stream management and recovery mode
108+
// client.EnableStreamManagement(true);
109+
// }
110+
// }
111+
//}

0 commit comments

Comments
 (0)