private static DicomUid ObsoleteGenerateUid()
{
lock (_lock)
{
if (_baseUid == null)
{
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
if (nics.Length == 0)
throw new DicomException("No network cards in system, unable to generate UID");
byte[] addressBytes = nics[0].GetPhysicalAddress().GetAddressBytes();
if (addressBytes.Length > 6)
throw new DicomException("Unexpected length for MAC address, unable to generate a UID");
ulong address = 0;
foreach (byte b in addressBytes)
{
address <<= 8;
address |= b;
}
var sb = new StringBuilder();
// ClearCanvas root from IANA
sb.Append("1.3.6.1.4.1.25403");
// MAC address converted to decimal
sb.AppendFormat(".{0}", address);
// Process Id
sb.AppendFormat(".{0}", (uint) Process.GetCurrentProcess().Id);
_baseUid = sb.ToString();
_lastTimestamp = DateTime.Now.ToString("yyyyMMddhhmmss");
}
var uid = new StringBuilder();
uid.Append(_baseUid);
String time = DateTime.Now.ToString("yyyyMMddhhmmss");
if (time.Equals(_lastTimestamp))
{
if (_count == 9999)
throw new DicomException("Unexpected count reached max value in UID generator!");
_count++;
}
else
{
_count = 1;
_lastTimestamp = time;
}
uid.AppendFormat(".{0}.{1}", time, _count);
return new DicomUid(uid.ToString(), "Instance UID", UidType.SOPInstance);
}
}