コード例 #1
0
ファイル: GetItemAsync.cs プロジェクト: Blazored/LocalStorage
        public void ThrowsArgumentNullException_When_KeyIsInvalid(string key)
        {
            // arrange / act
            var action = new Func <Task>(async() => await _sut.GetItemAsync <object>(key));

            // assert
            Assert.ThrowsAsync <ArgumentNullException>(action);
        }
コード例 #2
0
        private async Task LoadAuthors()
        {
            var authors = (await BookStoreService.GetAllAsync("authors"));

            authors = null;
            if (authors == null)
            {
                var accessToken = await LocalStorageService.GetItemAsync <string>("accessToken");

                var refreshToken = await LocalStorageService.GetItemAsync <string>("refreshToken");

                var refreshRequest = new RefreshRequest
                {
                    AccessToken  = accessToken,
                    RefreshToken = refreshToken
                };

                var user = (await UserService.RefreshAccessTokenAsync(refreshRequest)) as UserWithToken;
                if (user != null)
                {
                    await LocalStorageService.SetItemAsync("accessToken", user.AccessToken);

                    authors = (await BookStoreService.GetAllAsync("authors"));
                }
            }

            Authors = authors != null?authors.OrderByDescending(a => a.AuthorId).ToList() : new List <Author>();

            StateHasChanged();
        }
コード例 #3
0
        /// <summary>
        /// Attempts to retrieve a prior user token
        /// </summary>
        public static async Task RetrieveToken(LocalStorageService storage)
        {
            LocalToken tokenObj = await storage.GetItemAsync <LocalToken>("token");

            if (tokenObj != null)
            {
                UserSecretToken = tokenObj.Token;
            }
        }
コード例 #4
0
        protected async Task UnmarkReady()
        {
            await _hubConnection.SendAsync("UnmarkReady", await LocalStorageService.GetItemAsync <int>("currentTable"));

            StateService.CallRequestRefresh();
            await Task.Delay(500);

            StateService.CallRequestRefresh();
        }
コード例 #5
0
 protected async Task Raise()
 {
     if (GameInformation.PlayerRaise > 0 &&
         GameInformation.Players.First(e => e.Username == AuthState.User.Identity.Name).GameMoney >
         GameInformation.PlayerRaise + GameInformation.RaiseAmount)
     {
         await _hubConnection.SendAsync("ActionRaise", await LocalStorageService.GetItemAsync <int>("currentTable"), GameInformation.PlayerRaise);
     }
     GameInformation.PlayerRaise = 0;
 }
コード例 #6
0
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            await base.OnAfterRenderAsync(firstRender);

            if (firstRender)
            {
                if (await LocalStorageService.ContainKeyAsync("PrefferedOsobaId"))
                {
                    this.PrefferedOsobaId = await LocalStorageService.GetItemAsync <int>("PrefferedOsobaId");
                }
            }
        }
コード例 #7
0
        public async Task Should_DeserialiseToCorrectType <T>(T value)
        {
            // Arrange
            var serialisedData = "";

            if (typeof(T) == typeof(string))
            {
                serialisedData = value.ToString();
            }
            else
            {
                serialisedData = JsonSerializer.Serialize(value, _jsonOptions);
            }

            _mockJSRuntime.Setup(x => x.InvokeAsync <string>("localStorage.getItem", new[] { _key }))
            .Returns(() => new ValueTask <string>(serialisedData));

            // Act
            var result = await _sut.GetItemAsync <T>(_key);

            // Assert
            Assert.Equal(value, result);
            _mockJSRuntime.Verify();
        }
コード例 #8
0
        protected async Task MarkReady()
        {
            var formModal = ModalService.Show <JoinTable>("Join table");
            var result    = await formModal.Result;

            if (result.Cancelled)
            {
                return;
            }
            await _hubConnection.SendAsync("MarkReady", await LocalStorageService.GetItemAsync <int>("currentTable"), result.Data);

            StateService.CallRequestRefresh();
            await Task.Delay(500);

            StateService.CallRequestRefresh();
        }
コード例 #9
0
        public override async Task <Unit> Handle(RestoreStatesAction action, CancellationToken aCancellationToken)
        {
            try
            {
                await Mediator.Send(await LocalStorageService.GetItemAsync <ApplicationState.SetState>("ApplicationState") ?? new ApplicationState.SetState());

                await Mediator.Send(await LocalStorageService.GetItemAsync <SessionState.SetState>("SessionState") ?? new SessionState.SetState());

                await Mediator.Send(await LocalStorageService.GetItemAsync <WalletState.SetState>("WalletState") ?? new WalletState.SetState());
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            Console.WriteLine("State Restored");
            return(Unit.Value);
        }
コード例 #10
0
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            await base.OnAfterRenderAsync(firstRender);

            if (firstRender)
            {
                DateTime lastVisit = DateTime.Today.AddDays(-14);
                if (await LocalStorageService.ContainKeyAsync("LastVisit"))                 // JS Interop - musíme až do AfterRender
                {
                    lastVisit = await LocalStorageService.GetItemAsync <DateTime>("LastVisit");
                }

                if ((await NastenkaWebApiClient.GetVzkazyAsync()).Vzkazy.Any(vzkaz => vzkaz.DatumVlozeni > lastVisit))
                {
                    ShowNastenkaLink = true;
                    StateHasChanged();
                }

                await LocalStorageService.SetItemAsync("LastVisit", DateTime.Now);

                await JSRuntime.InvokeVoidAsync("setTitle", "Volejbal - Přihlašování");
            }
        }
コード例 #11
0
        protected override async Task OnInitializedAsync()
        {
            AuthState = await AuthenticationStateProvider.GetAuthenticationStateAsync();

            _hubConnection = new HubConnectionBuilder()
                             .WithUrl(NavigationManager.ToAbsoluteUri("/gameHub"))
                             .Build();

            _hubConnection.On("ReceiveMessage", (object message) =>
            {
                var newMessage = JsonConvert.DeserializeObject <GetMessageResult>(message.ToString());
                ChatMessages.Add(newMessage);
                StateHasChanged();
            });

            _hubConnection.On("ReceiveStartingHand", (object hand) =>
            {
                var newHand = JsonConvert.DeserializeObject <List <Card> >(hand.ToString());
                GameInformation.Hand.AddRange(newHand);
                StateHasChanged();
            });

            _hubConnection.On("ReceiveTurnPlayer", (string currentPlayer) =>
            {
                GameInformation.CurrentPlayer = currentPlayer;
                StateHasChanged();
            });

            _hubConnection.On("ReceiveFlop", (object flopjson) =>
            {
                var flop = JsonConvert.DeserializeObject <List <Card> >(flopjson.ToString());
                GameInformation.TableCards.AddRange(flop);
                StateHasChanged();
            });

            _hubConnection.On("ReceiveTurnOrRiver", (object card) =>
            {
                var turnOrRiverCard = JsonConvert.DeserializeObject <List <Card> >(card.ToString());
                GameInformation.TableCards.AddRange(turnOrRiverCard);
                StateHasChanged();
            });


            _hubConnection.On("ReceiveWinner", (string winner) =>
            {
                GameInformation.Winner = winner;
                StateHasChanged();
            });


            _hubConnection.On("ReceiveStateRefresh", (object playerState) =>
            {
                var playerStateModel = JsonConvert.DeserializeObject <PlayerStateModel>(playerState.ToString());

                GameInformation.Players        = playerStateModel.Players;
                GameInformation.TableCards     = playerStateModel.CommunityCards ?? new List <Card>();
                GameInformation.Hand           = playerStateModel.HandCards ?? new List <Card>();
                GameInformation.GameInProgress = playerStateModel.GameInProgress;
                GameInformation.RaiseAmount    = playerStateModel.RaiseAmount;
                GameInformation.Pots           = playerStateModel.Pots ?? new List <Pot>();
                if (GameInformation.GameInProgress == false)
                {
                    foreach (var gameInformationPlayer in GameInformation.Players)
                    {
                        gameInformationPlayer.IsPlaying = false;
                    }
                }

                GameInformation.Winner = null;

                StateHasChanged();
            });

            _hubConnection.On("ReceiveKick", async() =>
            {
                await LocalStorageService.RemoveItemAsync("currentTable");
                NavigationManager.NavigateTo("/");
            });

            await _hubConnection.StartAsync();

            await _hubConnection.SendAsync("AddToUsers", await LocalStorageService.GetItemAsync <int>("currentTable"));

            GameInformation.PlayersNotes = (await PlayerNoteService.GetList()).PlayerNotes;

            await base.OnInitializedAsync();
        }
コード例 #12
0
ファイル: IndexBase.cs プロジェクト: AugustinasMK/Poker
        protected override async Task OnInitializedAsync()
        {
            await base.OnInitializedAsync();

            CurrentTable = await LocalStorageService.GetItemAsync <int>("currentTable");
        }
コード例 #13
0
        protected override async Task OnInitializedAsync()
        {
            Result = await LocalStorageService.GetItemAsync <string>("Result");

            await Task.Delay(TimeSpan.FromSeconds(3));
        }
コード例 #14
0
 protected async Task AllIn()
 {
     await _hubConnection.SendAsync("ActionAllIn", await LocalStorageService.GetItemAsync <int>("currentTable"));
 }