public async Task SetAppEntranceAuthStateAsync(Guid userId, AppEntranceAuthStateInput input)
        {
            var dictionary = await StateManager.GetOrAddAsync <IReliableDictionary <Guid, UserDeviceBinding> >(DictionaryName_UserDeviceBinding);

            using (var tx = StateManager.CreateTransaction())
            {
                UserDeviceBinding entity;
                var wrap = await dictionary.TryGetValueAsync(tx, userId);

                if (wrap.HasValue)
                {
                    entity = wrap.Value;
                    if (entity.Id == Guid.Empty)
                    {
                        entity.Id = userId;                         //fix existing data for DataMember missing bug #1657
                    }
                    entity.AddOrUpdateLatestAuthed(input.DeviceCode, input.AppEntranceId);
                    await dictionary.SetAsync(tx, userId, entity);
                }
                else
                {
                    entity = UserDeviceBinding.Create(userId, input.DeviceCode, input.AppEntranceId);
                    await dictionary.AddAsync(tx, userId, entity);
                }
                await tx.CommitAsync();
            }
        }
Exemplo n.º 2
0
        public async Task SetAndGetAppEntranceAuthStateAsync()
        {
            var target = new UserSettingAppService(statefulServiceContext, stateManager);
            var userId = Guid.NewGuid();
            var input  = new AppEntranceAuthStateInput
            {
                AppEntranceId = Guid.NewGuid(),
                DeviceCode    = Guid.NewGuid().ToString("N")
            };
            var result = await target.GetAppEntranceAuthStateAsync(userId, input.DeviceCode, input.AppEntranceId);

            result.Should().BeTrue();

            await target.SetAppEntranceAuthStateAsync(userId, input);

            result = await target.GetAppEntranceAuthStateAsync(userId, input.DeviceCode, input.AppEntranceId);

            result.Should().BeFalse();

            await target.SetAppEntranceAuthStateAsync(userId, input);

            await target.SetAppEntranceAuthStateAsync(userId, new AppEntranceAuthStateInput
            {
                AppEntranceId = Guid.NewGuid(),
                DeviceCode    = input.DeviceCode
            });

            result = await target.GetAppEntranceAuthStateAsync(userId, input.DeviceCode, Guid.NewGuid());

            result.Should().BeTrue();

            await target.SetAppEntranceAuthStateAsync(userId, new AppEntranceAuthStateInput
            {
                AppEntranceId = Guid.NewGuid(),
                DeviceCode    = Guid.NewGuid().ToString("N")
            });

            result = await target.GetAppEntranceAuthStateAsync(userId, Guid.NewGuid().ToString("N"), Guid.NewGuid());

            result.Should().BeTrue();
        }