Beispiel #1
0
        /// <summary>
        /// Gets the user identifier.
        /// </summary>
        /// <returns>System.String.</returns>
        public string GetUserId()
        {
            lock (_lock)
            {
                if (!string.IsNullOrWhiteSpace(_userId))
                {
                    return(_userId);
                }

                Log.Debug("Calculating user id");

                var cpuId = string.Empty;
                var hddId = string.Empty;
                var macId = string.Empty;

                TaskHelper.RunAndWait(new Action[]
                {
                    // ORCOMP-203: Disable cpu because of performance
                    //() => cpuId = _systemIdentificationService.GetCpuId(),
                    () => hddId = _systemIdentificationService.GetHardDriveId(),
                    () => macId = _systemIdentificationService.GetMacId()
                });

                var uniqueIdPreValue = string.Format("{0}_{1}_{2}", cpuId, hddId, macId);
                var uniqueId         = GetMd5Hash(uniqueIdPreValue);

                Log.Debug("Calculated user id '{0}'", uniqueId);

                _userId = uniqueId;

                return(uniqueId);
            }
        }
        protected override async Task InitializeAsync()
        {
            await base.InitializeAsync();

            IsBusy = true;

            try
            {
                await TaskShim.WhenAll(new[]
                {
                    SetValueAsync(() => _systemIdentificationService.GetCpuId(), x => CpuId                 = x),
                    SetValueAsync(() => _systemIdentificationService.GetGpuId(), x => GpuId                 = x),
                    SetValueAsync(() => _systemIdentificationService.GetHardDriveId(), x => HardDriveId     = x),
                    SetValueAsync(() => _systemIdentificationService.GetMacId(), x => MacId                 = x),
                    SetValueAsync(() => _systemIdentificationService.GetMotherboardId(), x => MotherboardId = x)
                });

                // Note: we calculate the machine id last because we don't want to cause "false timings" in our demo app (the machine id
                // has to wait for all the others to finish so will take much longer then it actually does)
                await TaskHelper.Run(() => SetValueAsync(() => _systemIdentificationService.GetMachineId(), x => MachineId = x), true);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Failed to get system identification");
            }

            IsBusy = false;
        }