public virtual async Task <ServerTimeState> UpdateAsync(
                ILiveState <ServerTimeState> liveState, CancellationToken cancellationToken)
            {
                var time = await Time.GetTimeAsync(cancellationToken);

                return(new ServerTimeState()
                {
                    Time = time
                });
            }
Пример #2
0
            public async Task <CounterState> UpdateAsync(
                ILiveState <CounterState> liveState, CancellationToken cancellationToken)
            {
                var counter = await CounterService.GetCounterAsync(cancellationToken);

                return(new CounterState()
                {
                    Counter = counter
                });
            }
            public async Task <WeatherForecastState> UpdateAsync(
                ILiveState <Local, WeatherForecastState> liveState, CancellationToken cancellationToken)
            {
                var local     = liveState.Local;
                var forecasts = await WeatherForecastService.GetForecastAsync(local.StartDate, cancellationToken);

                return(new WeatherForecastState()
                {
                    Forecasts = forecasts
                });
            }
            public virtual async Task <ServerTimeState> UpdateAsync(
                ILiveState <ServerTimeState> liveState, CancellationToken cancellationToken)
            {
                Debug.WriteLine($"{DateTime.Now.ToString("hh:mm:ss.fff")}: @ {GetType().Name}.{nameof(UpdateAsync)}");
                var time = await Time.GetTimeAsync(cancellationToken);

                return(new ServerTimeState()
                {
                    Time = time
                });
            }
Пример #5
0
        public ClientState(AuthStateProvider authStateProvider, IStateFactory stateFactory)
        {
            AuthStateProvider = authStateProvider;
            SessionResolver   = AuthStateProvider.SessionResolver;

            User = stateFactory.NewLive <User>(
                o => o.WithUpdateDelayer(0, 1),
                async(_, cancellationToken) => {
                var authState = await AuthState.UseAsync(cancellationToken).ConfigureAwait(false);
                return(authState.User);
            });
        }
Пример #6
0
        protected virtual async Task <AuthState> ComputeState(ILiveState <AuthState> state, CancellationToken cancellationToken)
        {
            var session = await SessionResolver.GetSession(cancellationToken).ConfigureAwait(false);

            var user = await AuthService.GetUser(session, cancellationToken).ConfigureAwait(false);

            // AuthService.GetUser checks for forced sign-out as well, so
            // we should explicitly query its state for unauthenticated users only
            var isSignOutForced = !user.IsAuthenticated &&
                                  await AuthService.IsSignOutForced(session, cancellationToken).ConfigureAwait(false);

            return(new AuthState(user, isSignOutForced));
        }
Пример #7
0
 public AuthStateProvider(
     Options?options,
     IAuthService authService,
     ISessionResolver sessionResolver,
     IStateFactory stateFactory)
 {
     options ??= new();
     AuthService     = authService;
     SessionResolver = sessionResolver;
     State           = stateFactory.NewLive <AuthState>(o => {
         options.LiveStateOptionsBuilder.Invoke(o);
         o.InitialOutputFactory = _ => new AuthState(new User("none"));
         o.EventConfigurator   += state => state.AddEventHandler(StateEventKind.Updated, OnStateChanged);
     }, ComputeState);
 }
Пример #8
0
        public ClientState(
            IChatService chatService,
            AuthStateProvider authStateProvider,
            IStateFactory stateFactory)
        {
            ChatService       = chatService;
            AuthStateProvider = authStateProvider;
            SessionResolver   = AuthStateProvider.SessionResolver;

            User = stateFactory.NewLive <User>(
                o => o.WithInstantUpdates(),
                async(_, cancellationToken) => {
                var authState = await AuthState.UseAsync(cancellationToken);
                return(authState.User);
            });
            ChatUser = stateFactory.NewLive <ChatUser?>(
                o => {
                o.InitialOutputFactory = _ => null;     // The default factory uses parameterless constructor instead
                o.WithInstantUpdates();
            },
                (_, cancellationToken) => ChatService.GetCurrentUserAsync(Session, cancellationToken));
        }
Пример #9
0
 protected virtual void OnLiveStateUpdated(ILiveState liveState)
 => StateHasChanged();
Пример #10
0
 protected virtual void OnLiveStateUpdated(ILiveState liveState)
 => InvokeAsync(StateHasChanged);
Пример #11
0
 public StateController(ILiveState state)
 {
     _state = state;
 }