Skip to content

Commit

Permalink
Realign property name casing in DeviceClientDto. Move update check af…
Browse files Browse the repository at this point in the history
…ter reconnection, so these can be properly cased later.
  • Loading branch information
bitbound committed Jun 24, 2023
1 parent 097e6a4 commit f1e83df
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
6 changes: 3 additions & 3 deletions Agent/Services/AgentHubConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public async Task Connect()

_logger.LogInformation("Connected to server.");

// TODO: Move CPU sampler to background service.
var device = await _deviceInfoService.CreateDevice(_connectionInfo.DeviceID, _connectionInfo.OrganizationID);

var result = await _hubConnection.InvokeAsync<bool>("DeviceCameOnline", device);
Expand Down Expand Up @@ -199,6 +198,8 @@ private async void HeartbeatTimer_Elapsed(object sender, ElapsedEventArgs e)
private async Task HubConnection_Reconnected(string arg)
{
_logger.LogInformation("Reconnected to server.");
await _updater.CheckForUpdates();

var device = await _deviceInfoService.CreateDevice(_connectionInfo.DeviceID, _connectionInfo.OrganizationID);

if (!await _hubConnection.InvokeAsync<bool>("DeviceCameOnline", device))
Expand All @@ -212,9 +213,8 @@ private async Task HubConnection_Reconnected(string arg)
await Connect();
return;
}

await _updater.CheckForUpdates();
}

private void RegisterMessageHandlers()
{

Expand Down
8 changes: 4 additions & 4 deletions Agent/Services/DeviceInfoGeneratorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ protected DeviceClientDto GetDeviceBase(string deviceID, string orgID)

return new DeviceClientDto()
{
Id = deviceID,
ID = deviceID,
DeviceName = Environment.MachineName,
Platform = EnvironmentHelper.Platform.ToString(),
ProcessorCount = Environment.ProcessorCount,
OsArchitecture = RuntimeInformation.OSArchitecture,
OsDescription = RuntimeInformation.OSDescription,
OSArchitecture = RuntimeInformation.OSArchitecture,
OSDescription = RuntimeInformation.OSDescription,
Is64Bit = Environment.Is64BitOperatingSystem,
IsOnline = true,
MacAddresses = GetMacAddresses().ToArray(),
OrganizationId = orgID,
OrganizationID = orgID,
AgentVersion = AppVersionHelper.GetAppVersion()
};
}
Expand Down
4 changes: 2 additions & 2 deletions Server/Hubs/AgentHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public async Task<bool> DeviceCameOnline(DeviceClientDto device)
{
try
{
if (CheckForDeviceBan(device.Id, device.DeviceName))
if (CheckForDeviceBan(device.ID, device.DeviceName))
{
return false;
}
Expand Down Expand Up @@ -147,7 +147,7 @@ public async Task<bool> DeviceCameOnline(DeviceClientDto device)

public async Task DeviceHeartbeat(DeviceClientDto device)
{
if (CheckForDeviceBan(device.Id, device.DeviceName))
if (CheckForDeviceBan(device.ID, device.DeviceName))
{
return;
}
Expand Down
10 changes: 5 additions & 5 deletions Server/Services/DataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,14 @@ public async Task<Result<Device>> AddOrUpdateDevice(DeviceClientDto deviceDto)
{
using var dbContext = _appDbFactory.GetContext();

var device = await dbContext.Devices.FindAsync(deviceDto.Id);
var device = await dbContext.Devices.FindAsync(deviceDto.ID);

if (device is null)
{
device = new Device
{
OrganizationID = deviceDto.OrganizationId,
ID = deviceDto.Id,
OrganizationID = deviceDto.OrganizationID,
ID = deviceDto.ID,
};
await dbContext.Devices.AddAsync(device);
}
Expand All @@ -380,8 +380,8 @@ public async Task<Result<Device>> AddOrUpdateDevice(DeviceClientDto deviceDto)
device.UsedStorage = deviceDto.UsedStorage;
device.Is64Bit = deviceDto.Is64Bit;
device.IsOnline = true;
device.OSArchitecture = deviceDto.OsArchitecture;
device.OSDescription = deviceDto.OsDescription;
device.OSArchitecture = deviceDto.OSArchitecture;
device.OSDescription = deviceDto.OSDescription;
device.Platform = deviceDto.Platform;
device.ProcessorCount = deviceDto.ProcessorCount;
device.PublicIP = deviceDto.PublicIP;
Expand Down
8 changes: 4 additions & 4 deletions Shared/Dtos/DeviceClientDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class DeviceClientDto
public List<Drive> Drives { get; set; } = new();

[DataMember]
public string Id { get; set; } = string.Empty;
public string ID { get; set; } = string.Empty;

[DataMember]
public bool Is64Bit { get; set; }
Expand All @@ -41,13 +41,13 @@ public class DeviceClientDto
public string[] MacAddresses { get; set; } = Array.Empty<string>();

[DataMember]
public string OrganizationId { get; set; } = string.Empty;
public string OrganizationID { get; set; } = string.Empty;

[DataMember]
public Architecture OsArchitecture { get; set; }
public Architecture OSArchitecture { get; set; }

[DataMember]
public string OsDescription { get; set; } = string.Empty;
public string OSDescription { get; set; } = string.Empty;

[DataMember]
public string Platform { get; set; } = string.Empty;
Expand Down
2 changes: 1 addition & 1 deletion Tests/LoadTester/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private static async Task StartAgent(int i)
{
try
{
var currentInfo = await _deviceInfo.CreateDevice(device.Id, _organizationId);
var currentInfo = await _deviceInfo.CreateDevice(device.ID, _organizationId);
currentInfo.DeviceName = device.DeviceName;
await hubConnection.SendAsync("DeviceHeartbeat", currentInfo);
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Server.Tests/DataServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public async Task AddOrUpdateDevice()

var newDevice = new DeviceClientDto()
{
Id = _newDeviceID,
OrganizationId = _testData.Org1Id,
ID = _newDeviceID,
OrganizationID = _testData.Org1Id,
DeviceName = Environment.MachineName,
Is64Bit = Environment.Is64BitOperatingSystem
};
Expand Down
16 changes: 8 additions & 8 deletions Tests/Server.Tests/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ public async Task Init()

var device1 = new DeviceClientDto()
{
Id = "Org1Device1",
ID = "Org1Device1",
DeviceName = "Org1Device1Name",
OrganizationId = Org1Id
OrganizationID = Org1Id
};
var device2 = new DeviceClientDto()
{
Id = "Org1Device2",
ID = "Org1Device2",
DeviceName = "Org1Device2Name",
OrganizationId = Org1Id
OrganizationID = Org1Id
};
Org1Device1 = (await dataService.AddOrUpdateDevice(device1)).Value;
Org1Device2 = (await dataService.AddOrUpdateDevice(device2)).Value;
Expand All @@ -150,15 +150,15 @@ public async Task Init()

var device3 = new DeviceClientDto()
{
Id = "Org2Device1",
ID = "Org2Device1",
DeviceName = "Org2Device1Name",
OrganizationId = Org2Id
OrganizationID = Org2Id
};
var device4 = new DeviceClientDto()
{
Id = "Org2Device2",
ID = "Org2Device2",
DeviceName = "Org2Device2Name",
OrganizationId = Org2Id
OrganizationID = Org2Id
};
Org2Device1 = (await dataService.AddOrUpdateDevice(device3)).Value;
Org2Device2 = (await dataService.AddOrUpdateDevice(device4)).Value;
Expand Down

0 comments on commit f1e83df

Please sign in to comment.