mirror of
https://github.com/cyanfish/naps2.git
synced 2024-09-11 15:26:55 +03:00
Escl: Change device ID to be just the UUID
This commit is contained in:
parent
ad2ba73a64
commit
488429ea8d
@ -13,6 +13,7 @@ public class ClientServerTests
|
|||||||
{
|
{
|
||||||
var job = Substitute.For<IEsclScanJob>();
|
var job = Substitute.For<IEsclScanJob>();
|
||||||
using var server = new EsclServer();
|
using var server = new EsclServer();
|
||||||
|
var uuid = Guid.NewGuid().ToString("D");
|
||||||
var deviceConfig = new EsclDeviceConfig
|
var deviceConfig = new EsclDeviceConfig
|
||||||
{
|
{
|
||||||
Capabilities = new EsclCapabilities
|
Capabilities = new EsclCapabilities
|
||||||
@ -20,7 +21,7 @@ public class ClientServerTests
|
|||||||
Version = "2.0",
|
Version = "2.0",
|
||||||
MakeAndModel = "HP Blah",
|
MakeAndModel = "HP Blah",
|
||||||
SerialNumber = "123abc",
|
SerialNumber = "123abc",
|
||||||
Uuid = Guid.NewGuid().ToString("D")
|
Uuid = uuid
|
||||||
},
|
},
|
||||||
CreateJob = _ => job
|
CreateJob = _ => job
|
||||||
};
|
};
|
||||||
@ -34,7 +35,8 @@ public class ClientServerTests
|
|||||||
RemoteEndpoint = IPAddress.IPv6Loopback,
|
RemoteEndpoint = IPAddress.IPv6Loopback,
|
||||||
Port = deviceConfig.Port,
|
Port = deviceConfig.Port,
|
||||||
RootUrl = "eSCL",
|
RootUrl = "eSCL",
|
||||||
Tls = false
|
Tls = false,
|
||||||
|
Uuid = uuid
|
||||||
});
|
});
|
||||||
var caps = await client.GetCapabilities();
|
var caps = await client.GetCapabilities();
|
||||||
Assert.Equal("2.0", caps.Version);
|
Assert.Equal("2.0", caps.Version);
|
||||||
|
@ -53,7 +53,8 @@ public class EsclUsbContext : IDisposable
|
|||||||
RemoteEndpoint = IPAddress.Loopback,
|
RemoteEndpoint = IPAddress.Loopback,
|
||||||
Port = port,
|
Port = port,
|
||||||
RootUrl = "eSCL",
|
RootUrl = "eSCL",
|
||||||
Tls = false
|
Tls = false,
|
||||||
|
Uuid = Guid.Empty.ToString("D")
|
||||||
});
|
});
|
||||||
Task.Run(ProxyLoop);
|
Task.Run(ProxyLoop);
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ public class EsclService
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A unique identifier for the physical scanner device.
|
/// A unique identifier for the physical scanner device.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? Uuid { get; init; }
|
public required string Uuid { get; init; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The make and model of the scanner.
|
/// The make and model of the scanner.
|
||||||
|
@ -115,9 +115,10 @@ public class EsclServiceLocator : IDisposable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((ipv4 == null && ipv6 == null) || port == -1 || host == null)
|
string? uuid = Get(props, "uuid");
|
||||||
|
if ((ipv4 == null && ipv6 == null) || port == -1 || host == null || uuid == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentException();
|
throw new ArgumentException("Missing host/IP/port/uuid");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new EsclService
|
return new EsclService
|
||||||
@ -128,6 +129,7 @@ public class EsclServiceLocator : IDisposable
|
|||||||
RemoteEndpoint = args.RemoteEndPoint.Address,
|
RemoteEndpoint = args.RemoteEndPoint.Address,
|
||||||
Port = port,
|
Port = port,
|
||||||
Tls = isTls,
|
Tls = isTls,
|
||||||
|
Uuid = uuid,
|
||||||
ScannerName = props["ty"],
|
ScannerName = props["ty"],
|
||||||
RootUrl = props["rs"],
|
RootUrl = props["rs"],
|
||||||
TxtVersion = Get(props, "txtvers"),
|
TxtVersion = Get(props, "txtvers"),
|
||||||
@ -136,7 +138,6 @@ public class EsclServiceLocator : IDisposable
|
|||||||
Thumbnail = Get(props, "representation"),
|
Thumbnail = Get(props, "representation"),
|
||||||
Note = Get(props, "note"),
|
Note = Get(props, "note"),
|
||||||
MimeTypes = Get(props, "pdl")?.Split(','),
|
MimeTypes = Get(props, "pdl")?.Split(','),
|
||||||
Uuid = Get(props, "uuid"),
|
|
||||||
ColorOptions = Get(props, "cs")?.Split(','),
|
ColorOptions = Get(props, "cs")?.Split(','),
|
||||||
SourceOptions = Get(props, "is"),
|
SourceOptions = Get(props, "is"),
|
||||||
DuplexSupported = Get(props, "duplex")?.ToUpperInvariant() == "T"
|
DuplexSupported = Get(props, "duplex")?.ToUpperInvariant() == "T"
|
||||||
|
@ -38,10 +38,8 @@ public class ScanServerIntegrationTests : ContextualTests
|
|||||||
|
|
||||||
// Set up a client ScanController for scanning through EsclScanDriver -> network -> ScanServer
|
// Set up a client ScanController for scanning through EsclScanDriver -> network -> ScanServer
|
||||||
_client = new ScanController(ScanningContext);
|
_client = new ScanController(ScanningContext);
|
||||||
// This device won't match exactly the real device from GetDeviceList but it includes the UUID which is enough
|
|
||||||
// for EsclScanDriver to correctly identify the server for scanning.
|
|
||||||
var uuid = new ScanServerDevice { Device = serverDevice, Name = displayName }.GetUuid(_server.InstanceId);
|
var uuid = new ScanServerDevice { Device = serverDevice, Name = displayName }.GetUuid(_server.InstanceId);
|
||||||
_clientDevice = new ScanDevice(Driver.Escl, $"|{uuid}", displayName);
|
_clientDevice = new ScanDevice(Driver.Escl, uuid, displayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
@ -54,9 +52,9 @@ public class ScanServerIntegrationTests : ContextualTests
|
|||||||
public async Task FindDevice()
|
public async Task FindDevice()
|
||||||
{
|
{
|
||||||
var devices = await _client.GetDeviceList(Driver.Escl);
|
var devices = await _client.GetDeviceList(Driver.Escl);
|
||||||
// The device name is suffixed with the IP so we just check the prefix matches (and vice versa for ID)
|
// The device name is suffixed with the IP so we just check the prefix matches
|
||||||
Assert.Contains(devices,
|
Assert.Contains(devices,
|
||||||
device => device.Name.StartsWith(_clientDevice.Name) && device.ID.EndsWith(_clientDevice.ID));
|
device => device.Name.StartsWith(_clientDevice.Name) && device.ID == _clientDevice.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -21,10 +21,16 @@ internal class EsclScanDriver : IScanDriver
|
|||||||
public static string GetUuid(ScanDevice device)
|
public static string GetUuid(ScanDevice device)
|
||||||
{
|
{
|
||||||
var parts = device.ID.Split('|');
|
var parts = device.ID.Split('|');
|
||||||
|
if (parts.Length == 1)
|
||||||
|
{
|
||||||
|
// Current IDs are just the UUID
|
||||||
|
return parts[0];
|
||||||
|
}
|
||||||
if (parts.Length != 2)
|
if (parts.Length != 2)
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Invalid ESCL device ID");
|
throw new ArgumentException("Invalid ESCL device ID");
|
||||||
}
|
}
|
||||||
|
// Old IDs have both the IP and UUID separated by "|"
|
||||||
return parts[1];
|
return parts[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,14 +46,15 @@ internal class EsclScanDriver : IScanDriver
|
|||||||
var localIPsTask = options.ExcludeLocalIPs ? LocalIPsHelper.Get() : null;
|
var localIPsTask = options.ExcludeLocalIPs ? LocalIPsHelper.Get() : null;
|
||||||
using var locator = new EsclServiceLocator(service =>
|
using var locator = new EsclServiceLocator(service =>
|
||||||
{
|
{
|
||||||
// Store both the IP and UUID so we can preferentially find by the IP, but also fall back to looking for
|
|
||||||
// the UUID in case the IP changed
|
|
||||||
var ip = service.IpV4 ?? service.IpV6!;
|
var ip = service.IpV4 ?? service.IpV6!;
|
||||||
if (options.ExcludeLocalIPs && localIPsTask!.Result.Contains(ip.ToString()))
|
if (options.ExcludeLocalIPs && localIPsTask!.Result.Contains(ip.ToString()))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var id = $"{ip}|{service.Uuid}";
|
// TODO: When we implement scanner capabilities, store all the connection information in there so we can
|
||||||
|
// try and connect directly before querying for a potentially-updated-IP (and then back-propagate the new
|
||||||
|
// connection info).
|
||||||
|
var id = service.Uuid;
|
||||||
var name = string.IsNullOrEmpty(service.ScannerName)
|
var name = string.IsNullOrEmpty(service.ScannerName)
|
||||||
? $"{ip}"
|
? $"{ip}"
|
||||||
: $"{service.ScannerName} ({ip})";
|
: $"{service.ScannerName} ({ip})";
|
||||||
|
Loading…
Reference in New Issue
Block a user