Ejemplo n.º 1
0
        /// <summary>
        /// Platform-specific implementation to attempt to obtain a unique network identifier, e.g. based on a MAC address.
        /// </summary>
        /// <param name="identifier">Unique network identifier, if found.</param>
        /// <returns>True if network identifier could be obtained, false otherwise.</returns>
        protected override bool TryGetNetworkIdentifierImpl(out DicomUID identifier)
        {
            var interfaces = NetworkInterface.GetAllNetworkInterfaces();

            for (var i = 0; i < interfaces.Length; i++)
            {
                if (NetworkInterface.LoopbackInterfaceIndex == i ||
                    interfaces[i].OperationalStatus != OperationalStatus.Up)
                {
                    continue;
                }

                var hex = interfaces[i].GetPhysicalAddress().ToString();
                if (string.IsNullOrEmpty(hex))
                {
                    continue;
                }

                try
                {
                    var mac = long.Parse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
                    {
                        identifier = DicomUID.Append(DicomImplementation.ClassUID, mac);
                        return(true);
                    }
                }
                catch
                {
                }
            }

            identifier = null;
            return(false);
        }
        /// <inheritdoc />
        protected override bool TryGetNetworkIdentifierImpl(out DicomUID identifier)
        {
            var profile = NetworkInformation.GetInternetConnectionProfile();

            if (profile != null)
            {
                try
                {
                    var hex = profile.NetworkAdapter.NetworkAdapterId.ToString("N").Substring(0, 12);
                    var dec = long.Parse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
                    {
                        identifier = DicomUID.Append(DicomImplementation.ClassUID, dec);
                        return(true);
                    }
                }
                catch
                {
                }
            }

            identifier = null;
            return(false);
        }