Skip to content

Commit

Permalink
Merge pull request #25 from viordash/settings
Browse files Browse the repository at this point in the history
skipping errors when entering msdn parameters
  • Loading branch information
viordash authored Oct 1, 2023
2 parents 4cb7924 + c7c5f58 commit 75438fb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ShareClipbrd.Core.Helpers;
using ShareClipbrd.Core.Services;
using ShareClipbrd.Core.Services;

namespace ShareClipbrd.Core.Tests.Services {
public class AddressResolverTests {
Expand All @@ -23,11 +22,11 @@ public void UseAddressDiscoveryService_When_Invalid_Address_Return_False() {
Assert.That(id, Is.Empty);
Assert.That(mandatoryPort, Is.Null);

Assert.IsFalse(AddressResolver.UseAddressDiscoveryService("mdns:", out id, out mandatoryPort));
Assert.IsFalse(AddressResolver.UseAddressDiscoveryService("mdns :", out id, out mandatoryPort));
Assert.That(id, Is.Empty);
Assert.That(mandatoryPort, Is.Null);

Assert.IsFalse(AddressResolver.UseAddressDiscoveryService("mdns: ", out id, out mandatoryPort));
Assert.IsFalse(AddressResolver.UseAddressDiscoveryService("mdns : ", out id, out mandatoryPort));
Assert.That(id, Is.Empty);
Assert.That(mandatoryPort, Is.Null);
}
Expand Down Expand Up @@ -58,7 +57,17 @@ public void UseAddressDiscoveryService_When_Invalid_Ports_Throws_ArgumentExcepti
Assert.Throws<ArgumentException>(() => AddressResolver.UseAddressDiscoveryService("mdns:abcde:-1", out id, out mandatoryPort));
Assert.Throws<ArgumentException>(() => AddressResolver.UseAddressDiscoveryService("mdns:abcde:65536", out id, out mandatoryPort));

Assert.IsFalse(AddressResolver.UseAddressDiscoveryService("mdns::1", out id, out mandatoryPort));
Assert.IsTrue(AddressResolver.UseAddressDiscoveryService("mdns::1", out id, out mandatoryPort));
Assert.That(id, Is.Empty);
Assert.That(mandatoryPort, Is.Null);
}

[Test]
public void UseAddressDiscoveryService_Returns_True_And_Empty_Id_If_Address_Is_Not_Fully_Filled() {
string id;
int? mandatoryPort;

Assert.IsTrue(AddressResolver.UseAddressDiscoveryService("mdns:", out id, out mandatoryPort));
Assert.That(id, Is.Empty);
Assert.That(mandatoryPort, Is.Null);
}
Expand Down
1 change: 0 additions & 1 deletion ShareClipbrd/ShareClipbrd.Core/Services/AddressResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public static bool UseAddressDiscoveryService(string address, out string id, out
if(string.IsNullOrEmpty(s)) {
id = string.Empty;
mandatoryPort = null;
return false;
}
id = s;
return true;
Expand Down
9 changes: 9 additions & 0 deletions ShareClipbrd/ShareClipbrd.Core/Services/DataClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public async Task SendFileDropList(StringCollection fileDropList) {
var cancellationToken = cts.Token;
try {
await Connect(cancellationToken);
if(!IsSocketConnected(client.Client)) {
return;
}
var stream = await Handshake();
var fileTransmitter = new FileTransmitter(progressService, stream);
await fileTransmitter.Send(fileDropList, cancellationToken);
Expand Down Expand Up @@ -125,6 +128,9 @@ public async Task SendData(ClipboardData clipboardData) {
var cancellationToken = cts.Token;
try {
await Connect(cancellationToken);
if(!IsSocketConnected(client.Client)) {
return;
}
await using(progressService.Begin(ProgressMode.Send)) {
var totalLenght = clipboardData.GetTotalLenght();
progressService.SetMaxTick(totalLenght);
Expand Down Expand Up @@ -190,6 +196,9 @@ async Task Connect(CancellationToken cancellationToken) {
if(mandatoryPort.HasValue) {
throw new ArgumentException("mdns port for the partner address is not needed");
}
if(string.IsNullOrEmpty(id)) {
return;
}
ipEndPoint = await addressDiscoveryService.Discover(id);
} else {
ipEndPoint = NetworkHelper.ResolveHostName(systemConfiguration.PartnerAddress);
Expand Down

0 comments on commit 75438fb

Please sign in to comment.