using System.Runtime.Serialization; using Vanara.Management; namespace Vanara.IO; /// Provides information about a snapshot within a VHD Set file. [DataContract(Name = "Msvm_VHDSnapshotInformation", Namespace = @"root\virtualization\v2")] public class VirtualDiskSnapshotInformation { /// Initializes a new instance of the class. /// The path of the VHD Set file. /// /// A GUID that uniquely identifies this snapshot within the VHD Set file. /// /// If the supplied Snapshot Id already exists, the existing Snapshot entry will be overwritten with the new entry. Otherwise, the new /// entry will be added to the VHD Set file. /// /// /// The optional resilient change tracking ID associated with this snapshot. public VirtualDiskSnapshotInformation(string vhdsFilePath, Guid snapshotId, string? resilientChangeTrackingId = null) { FilePath = vhdsFilePath; SnapshotId = snapshotId; ResilientChangeTrackingId = resilientChangeTrackingId; } /// Initializes a new instance of the class. public VirtualDiskSnapshotInformation() { } /// Gets or sets the date and time of this snapshot's creation. [IgnoreDataMember] public DateTime? CreationTime { get => ManagementExtensions.CimToDateTime(CreationTimeString); // set => CreationTimeString = value.HasValue ? value.Value.DateTimeToCim() : null; } /// The path of the VHD Set file. public string? FilePath { get; set; } /// /// A list of file paths representing all of the files on which this snapshot depends. This field will be empty unless specifically /// requested. The first entry is the file's immediate parent, with the last entry being the root. /// public string[]? ParentPathsList { get; internal set; } /// Gets or sets the resilient change tracking ID, if any, associated with this snapshot. public string? ResilientChangeTrackingId { get; set; } /// A GUID that uniquely identifies this snapshot within the VHD Set file. [IgnoreDataMember] public Guid? SnapshotId { get => Guid.TryParse(Id, out var id) ? id : null; set => Id = value?.ToString("D"); } /// The path of the file represented by this snapshot. This field may be empty if there is no file associated with this snapshot. public string? SnapshotPath { get; set; } [DataMember(Name = "CreationTime")] internal string? CreationTimeString { get; set; } [DataMember(Name = "SnapshotId")] internal string? Id { get; set; } internal static VirtualDiskSnapshotInformation Parse(string? embeddedInstance) => ManagementExtensions.Parse(embeddedInstance); /// Gets the embedded instance string usable by WMI /// Embedded instance string usable by WMI. internal string GetInstanceText(string serverName = ".") => ManagementExtensions.GetInstanceText(this, serverName); }