2024-12-15 17:06:14 +01:00
|
|
|
// <copyright file="HeartbeatModel.cs" company="alveus.dev">
|
|
|
|
// Copyright (c) alveus.dev. All rights reserved. Licensed under the MIT License.
|
|
|
|
// </copyright>
|
|
|
|
|
|
|
|
using System.Text.Json.Serialization;
|
2024-12-15 21:20:27 +01:00
|
|
|
using Astral.Services.Dtos;
|
2024-12-15 17:06:14 +01:00
|
|
|
|
|
|
|
namespace Astral.ApiServer.Models;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Heartbeat contents.
|
|
|
|
/// </summary>
|
|
|
|
public class HeartbeatModel
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// True if connected.
|
|
|
|
/// </summary>
|
|
|
|
[JsonPropertyName("connected")]
|
2024-12-15 21:20:27 +01:00
|
|
|
public bool? Connected { get; set; }
|
2024-12-15 17:06:14 +01:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Path.
|
|
|
|
/// </summary>
|
|
|
|
[JsonPropertyName("path")]
|
|
|
|
public string Path { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Domain id.
|
|
|
|
/// </summary>
|
|
|
|
[JsonPropertyName("domain_id")]
|
2024-12-15 21:20:27 +01:00
|
|
|
public string DomainId { get; set; }
|
2024-12-15 17:06:14 +01:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Place id.
|
|
|
|
/// </summary>
|
|
|
|
[JsonPropertyName("place_id")]
|
2024-12-15 21:20:27 +01:00
|
|
|
public string PlaceId { get; set; }
|
2024-12-15 17:06:14 +01:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Network address.
|
|
|
|
/// </summary>
|
|
|
|
[JsonPropertyName("network_address")]
|
|
|
|
public string NetworkAddress { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Network port.
|
|
|
|
/// </summary>
|
|
|
|
[JsonPropertyName("network_port")]
|
2024-12-15 21:20:27 +01:00
|
|
|
public int? NetworkPort { get; set; }
|
2024-12-15 17:06:14 +01:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Node id.
|
|
|
|
/// </summary>
|
|
|
|
[JsonPropertyName("node_id")]
|
2024-12-15 21:20:27 +01:00
|
|
|
public string NodeId { get; set; }
|
2024-12-15 17:06:14 +01:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Availability.
|
|
|
|
/// </summary>
|
|
|
|
[JsonPropertyName("availability")]
|
|
|
|
public string Availability { get; set; }
|
2024-12-15 21:20:27 +01:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Convert this model to <see cref="UserLocationHeartbeatDto"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>Instance of <see cref="UserLocationHeartbeatDto"/>.</returns>
|
|
|
|
public UserLocationHeartbeatDto ToUserLocationHeartbeat()
|
|
|
|
{
|
|
|
|
var result = new UserLocationHeartbeatDto()
|
|
|
|
{
|
|
|
|
Connected = Connected,
|
|
|
|
Path = Path,
|
|
|
|
NetworkAddress = NetworkAddress,
|
|
|
|
NetworkPort = NetworkPort,
|
|
|
|
Availability = Availability
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(DomainId))
|
|
|
|
{
|
|
|
|
if (Guid.TryParse(DomainId, out var guid))
|
|
|
|
{
|
|
|
|
result.DomainId = guid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.DomainId = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(PlaceId))
|
|
|
|
{
|
|
|
|
if (Guid.TryParse(PlaceId, out var guid))
|
|
|
|
{
|
|
|
|
result.PlaceId = guid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PlaceId = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(NodeId))
|
|
|
|
{
|
|
|
|
if (Guid.TryParse(NodeId, out var guid))
|
|
|
|
{
|
|
|
|
result.NodeId = guid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.NodeId = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2024-12-15 17:06:14 +01:00
|
|
|
}
|