public StartViewModel()
        {
            var canConnect = this.WhenAnyValue(x => x.Url, x => x.JoinCode, x => x.Username, (url, code, name) =>
                                               url != null &&
                                               Uri.IsWellFormedUriString(url, UriKind.Absolute) &&
                                               code != null &&
                                               Regex.IsMatch(code, @"^[a-z]{5}$") &&
                                               name != null &&
                                               Regex.IsMatch(name, @"^[A-Za-z]{3,20}$"));

            _connect = ReactiveCommand.CreateFromTask(async() =>
            {
                var service = await SignalRService.Initialize(Url);
                var player  = await service.JoinGameSession(Username, JoinCode);

                if (player == null)
                {
                    await Error.Handle("The Join Code was invalid");
                    return;
                }

                var vm = new GameViewModel(service, player);
                HostScreen.Router.Navigate.Execute(vm).Subscribe();
            }, canConnect, RxApp.TaskpoolScheduler);

            _isLoading = this.WhenAnyObservable(x => x.Connect.IsExecuting)
                         .StartWith(false)
                         .ToProperty(this, x => x.IsLoading);
        }
Exemple #2
0
 protected override void OnResume()
 {
     _ = SignalRService.Initialize();
 }