示例#1
0
        public void AddOrUpdateLatestAuthed(string deviceCode, Guid appEntranceId)
        {
            if (string.IsNullOrEmpty(deviceCode))
            {
                throw new ArgumentNullException(nameof(deviceCode));
            }

            if (appEntranceId == Guid.Empty)
            {
                throw new ArgumentOutOfRangeException("must not be empty", nameof(appEntranceId));
            }

            if (Devices.ContainsKey(deviceCode))
            {
                var info = Devices[deviceCode];
                if (info.AppEntranceAuths.ContainsKey(appEntranceId))
                {
                    var auth = info.AppEntranceAuths[appEntranceId];
                    auth.LatestAuthed = DateTimeOffset.UtcNow;
                }
                else
                {
                    info.AppEntranceAuths[appEntranceId] = AppEntranceAuth.Create();
                }
            }
            else
            {
                Devices[deviceCode] = DeviceBindingInfo.Create(appEntranceId);
            }
        }
示例#2
0
        public static UserDeviceBinding Create(Guid userId, string deviceCode, Guid appEntranceId)
        {
            if (userId == Guid.Empty)
            {
                throw new ArgumentOutOfRangeException("must not be empty", nameof(userId));
            }

            if (string.IsNullOrEmpty(deviceCode))
            {
                throw new ArgumentNullException(nameof(deviceCode));
            }

            if (appEntranceId == Guid.Empty)
            {
                throw new ArgumentOutOfRangeException("must not be empty", nameof(appEntranceId));
            }

            return(new UserDeviceBinding
            {
                Id = userId,
                Devices = new Dictionary <string, DeviceBindingInfo>
                {
                    [deviceCode] = DeviceBindingInfo.Create(appEntranceId)
                }
            });
        }