using System; namespace DSInternals.DataStore { /// /// The AttributeMetadata class is used to contain replication metadata for an Active Directory Domain Services attribute. /// /// Note that AttributeId is held in the parent collection. /// https://msdn.microsoft.com/en-us/library/system.directoryservices.activedirectory.attributemetadata.aspx public class AttributeMetadata { private const int DefaultVersion = 1; public AttributeMetadata(Guid invocationId, DateTime time, long usn) { this.Version = DefaultVersion; this.LastOriginatingChangeTime = time; this.LastOriginatingInvocationId = invocationId; this.OriginatingChangeUsn = usn; this.LocalChangeUsn = usn; } public AttributeMetadata(int version, long timestamp, Guid originatingDSA, long originatingUSN, long localUSN) { this.Version = version; this.LastOriginatingChangeTimestamp = timestamp; this.LastOriginatingInvocationId = originatingDSA; this.OriginatingChangeUsn = originatingUSN; this.LocalChangeUsn = localUSN; } /// /// Gets or sets the version number of this attribute. /// public int Version { get; private set; } /// /// Gets the timestamp at which the last originating change was made to this attribute. /// public long LastOriginatingChangeTimestamp { get; private set; } /// /// Gets or sets the invocation identifier of the server on which the last change was made to this attribute. /// public Guid LastOriginatingInvocationId { get; private set; } /// /// Gets or sets the update sequence number (USN) on the originating server at which the last change to this attribute was made. /// public long OriginatingChangeUsn { get; private set; } /// /// Gets or sets the update sequence number (USN) on the destination server at which the last change to this attribute was applied. /// public long LocalChangeUsn { get; private set; } /// /// Gets or sets the time at which the last originating change was made to this attribute. /// public DateTime LastOriginatingChangeTime { get { DateTime result = DateTime.FromFileTime(this.LastOriginatingChangeTimestamp * ADConstants.GeneralizedTimeCoefficient); return result; } private set { this.LastOriginatingChangeTimestamp = value.ToFileTime() / ADConstants.GeneralizedTimeCoefficient; } } public void Update(Guid invocationId, DateTime time, long usn) { this.LastOriginatingInvocationId = invocationId; this.LocalChangeUsn = usn; this.OriginatingChangeUsn = usn; this.LastOriginatingChangeTime = time; this.Version++; } public override string ToString() { return String.Format("Ver: {0}, USN: {1}, Time: {2}, DSA: {3}", this.Version, this.OriginatingChangeUsn, this.LastOriginatingChangeTime, this.LastOriginatingInvocationId); } } }