2020-09-02 17:09:19 -07:00
|
|
|
|
using System.Collections.Generic;
|
2023-08-14 13:17:51 -04:00
|
|
|
|
using System.Linq;
|
2020-09-07 22:00:02 -07:00
|
|
|
|
using System.Xml.Serialization;
|
2020-09-02 17:09:19 -07:00
|
|
|
|
using Newtonsoft.Json;
|
2020-09-07 22:00:02 -07:00
|
|
|
|
using Newtonsoft.Json.Converters;
|
2022-11-03 12:22:17 -07:00
|
|
|
|
using SabreTools.Core;
|
2023-08-14 13:17:51 -04:00
|
|
|
|
using SabreTools.Core.Tools;
|
2020-09-02 17:09:19 -07:00
|
|
|
|
|
2021-02-02 10:23:43 -08:00
|
|
|
|
namespace SabreTools.DatItems.Formats
|
2020-09-02 17:09:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Represents a single device on the machine
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonObject("device"), XmlRoot("device")]
|
2020-09-02 17:09:19 -07:00
|
|
|
|
public class Device : DatItem
|
|
|
|
|
|
{
|
|
|
|
|
|
#region Fields
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Device type
|
|
|
|
|
|
/// </summary>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("type")]
|
2020-09-07 22:00:02 -07:00
|
|
|
|
[JsonConverter(typeof(StringEnumConverter))]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public DeviceType DeviceType
|
|
|
|
|
|
{
|
2023-09-04 23:51:37 -04:00
|
|
|
|
get => _internal.ReadString(Models.Metadata.Device.DeviceTypeKey).AsDeviceType();
|
|
|
|
|
|
set => _internal[Models.Metadata.Device.DeviceTypeKey] = value.FromDeviceType();
|
2023-08-14 13:17:51 -04:00
|
|
|
|
}
|
2020-09-02 17:09:19 -07:00
|
|
|
|
|
2020-09-07 22:00:02 -07:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
|
public bool DeviceTypeSpecified { get { return DeviceType != DeviceType.NULL; } }
|
|
|
|
|
|
|
2020-09-02 17:09:19 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Device tag
|
|
|
|
|
|
/// </summary>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("tag", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("tag")]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public string? Tag
|
|
|
|
|
|
{
|
2023-09-04 23:51:37 -04:00
|
|
|
|
get => _internal.ReadString(Models.Metadata.Device.TagKey);
|
|
|
|
|
|
set => _internal[Models.Metadata.Device.TagKey] = value;
|
2023-08-14 13:17:51 -04:00
|
|
|
|
}
|
2020-09-02 17:09:19 -07:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Fixed image format
|
|
|
|
|
|
/// </summary>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("fixed_image", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("fixed_image")]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public string? FixedImage
|
|
|
|
|
|
{
|
2023-09-04 23:51:37 -04:00
|
|
|
|
get => _internal.ReadString(Models.Metadata.Device.FixedImageKey);
|
|
|
|
|
|
set => _internal[Models.Metadata.Device.FixedImageKey] = value;
|
2023-08-14 13:17:51 -04:00
|
|
|
|
}
|
2020-09-02 17:09:19 -07:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Determines if the devices is mandatory
|
|
|
|
|
|
/// </summary>
|
2020-09-04 10:28:25 -07:00
|
|
|
|
/// <remarks>Only value used seems to be 1. Used like bool, but actually int</remarks>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("mandatory", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("mandatory")]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public long? Mandatory
|
|
|
|
|
|
{
|
2023-09-04 23:51:37 -04:00
|
|
|
|
get => _internal.ReadLong(Models.Metadata.Device.MandatoryKey);
|
|
|
|
|
|
set => _internal[Models.Metadata.Device.MandatoryKey] = value;
|
2023-08-14 13:17:51 -04:00
|
|
|
|
}
|
2020-09-02 17:09:19 -07:00
|
|
|
|
|
2020-09-07 22:00:02 -07:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
|
public bool MandatorySpecified { get { return Mandatory != null; } }
|
|
|
|
|
|
|
2020-09-02 17:09:19 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Device interface
|
|
|
|
|
|
/// </summary>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("interface", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("interface")]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public string? Interface
|
|
|
|
|
|
{
|
2023-09-04 23:51:37 -04:00
|
|
|
|
get => _internal.ReadString(Models.Metadata.Device.InterfaceKey);
|
|
|
|
|
|
set => _internal[Models.Metadata.Device.InterfaceKey] = value;
|
2023-08-14 13:17:51 -04:00
|
|
|
|
}
|
2020-09-02 17:09:19 -07:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Device instances
|
|
|
|
|
|
/// </summary>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("instances", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("instances")]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public List<Instance>? Instances
|
|
|
|
|
|
{
|
2023-09-04 23:51:37 -04:00
|
|
|
|
get => _internal.Read<Instance[]>(Models.Metadata.Device.InstanceKey)?.ToList();
|
|
|
|
|
|
set => _internal[Models.Metadata.Device.InstanceKey] = value?.ToArray();
|
2023-08-14 13:17:51 -04:00
|
|
|
|
}
|
2020-09-02 17:09:19 -07:00
|
|
|
|
|
2020-09-07 22:00:02 -07:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
|
public bool InstancesSpecified { get { return Instances != null && Instances.Count > 0; } }
|
|
|
|
|
|
|
2020-09-02 17:09:19 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Device extensions
|
|
|
|
|
|
/// </summary>
|
2022-11-03 12:22:17 -07:00
|
|
|
|
[JsonProperty("extensions", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("extensions")]
|
2023-08-14 13:17:51 -04:00
|
|
|
|
public List<Extension>? Extensions
|
|
|
|
|
|
{
|
2023-09-04 23:51:37 -04:00
|
|
|
|
get => _internal.Read<Extension[]>(Models.Metadata.Device.ExtensionKey)?.ToList();
|
|
|
|
|
|
set => _internal[Models.Metadata.Device.ExtensionKey] = value?.ToArray();
|
2023-08-14 13:17:51 -04:00
|
|
|
|
}
|
2020-09-02 17:09:19 -07:00
|
|
|
|
|
2020-09-07 22:00:02 -07:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
|
public bool ExtensionsSpecified { get { return Extensions != null && Extensions.Count > 0; } }
|
|
|
|
|
|
|
2020-09-02 17:09:19 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Create a default, empty Device object
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Device()
|
|
|
|
|
|
{
|
2023-09-04 23:51:37 -04:00
|
|
|
|
_internal = new Models.Metadata.Device();
|
2023-08-15 01:38:01 -04:00
|
|
|
|
Machine = new Machine();
|
|
|
|
|
|
|
2020-09-02 17:09:19 -07:00
|
|
|
|
ItemType = ItemType.Device;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Cloning Methods
|
|
|
|
|
|
|
2022-11-03 12:22:17 -07:00
|
|
|
|
/// <inheritdoc/>
|
2020-09-02 17:09:19 -07:00
|
|
|
|
public override object Clone()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new Device()
|
|
|
|
|
|
{
|
|
|
|
|
|
ItemType = this.ItemType,
|
|
|
|
|
|
DupeType = this.DupeType,
|
|
|
|
|
|
|
2023-08-15 01:38:01 -04:00
|
|
|
|
Machine = this.Machine.Clone() as Machine ?? new Machine(),
|
2023-08-14 13:17:51 -04:00
|
|
|
|
Source = this.Source?.Clone() as Source,
|
2020-09-02 17:09:19 -07:00
|
|
|
|
Remove = this.Remove,
|
|
|
|
|
|
|
2024-02-28 19:19:50 -05:00
|
|
|
|
_internal = this._internal?.Clone() as Models.Metadata.Device ?? [],
|
2020-09-02 17:09:19 -07:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|