Пример #1
0
        public void Run()
        {
            Console.Clear();
            Console.WriteLine("Initializing store");
            Store.InitializeAsync().Wait();
            string input = "";

            do
            {
                Console.WriteLine("1: Increment counter");
                Console.WriteLine("2: Fetch data");
                Console.WriteLine("x: Exit");
                Console.Write("> ");
                input = Console.ReadLine();

                switch (input.ToLowerInvariant())
                {
                case "1":
                    var incrementCounterActionction = new IncrementCounterAction();
                    Dispatcher.Dispatch(incrementCounterActionction);
                    break;

                case "2":
                    var fetchDataAction = new FetchDataAction();
                    Dispatcher.Dispatch(fetchDataAction);
                    break;

                case "x":
                    Console.WriteLine("Program terminated");
                    return;
                }
            } while (true);
        }
Пример #2
0
        public async Task HandleFetchDataAction(FetchDataAction action, IDispatcher dispatcher)
        {
            try
            {
                var thootles = await _dataService.GetThootlesAsync();

                dispatcher.Dispatch(new FetchDataResultAction(thootles));
            }
            catch (Exception e)
            {
                dispatcher.Dispatch(new ErrorAction(e.Message));
            }
        }
Пример #3
0
        public async Task HandleAsync(FetchDataAction action, IDispatcher dispatcher)
        {
            try
            {
                var forecasts = await _httpClient.GetFromJsonAsync <WeatherForecast[]>("WeatherForecast");

                dispatcher.Dispatch(new FetchDataSuccessAction(forecasts));
            }
            catch (Exception ex)
            {
                dispatcher.Dispatch(new FetchDataErrorAction(ex.Message));
            }
        }
Пример #4
0
 public static WeatherState ReduceFetchDataAction(WeatherState state, FetchDataAction action)
 {
     if (state == null)
     {
         throw new ArgumentNullException(nameof(state));
     }
     if (action == null)
     {
         throw new ArgumentNullException(nameof(action));
     }
     return(new WeatherState(
                isLoading: true,
                forecasts: null));
 }
Пример #5
0
        public async Task HandleFetchDataAction(FetchDataAction action, IDispatcher dispatcher)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }
            if (dispatcher == null)
            {
                throw new ArgumentNullException(nameof(dispatcher));
            }
            var forecasts = await _service.GetForecastAsync(DateTime.Now);

            //var forecasts = await _http.GetFromJsonAsync<WeatherForecast[]>("WeatherForecast");
            dispatcher.Dispatch(new FetchDataResultAction(forecasts));
        }
Пример #6
0
        public void Run()
        {
            Console.Clear();
            Console.WriteLine("Initializing store");

            Store.InitializeAsync().Wait();
            SubscribeToResultAction();

            string input = "";

            do
            {
                Console.WriteLine("1: Increment counter");
                Console.WriteLine("2: Fetch data");
                Console.WriteLine("3: Get mutable object from API server");
                Console.WriteLine("x: Exit");
                Console.Write("> ");

                input = Console.ReadLine();

                switch (input.ToLowerInvariant())
                {
                case "1":
                    var action = new IncrementCounterAction();
                    Dispatcher.Dispatch(action);
                    break;

                case "2":
                    var fetchDataAction = new FetchDataAction();
                    Dispatcher.Dispatch(fetchDataAction);
                    break;

                case "3":
                    var getCustomerAction = new GetCustomerForEditAction(42);
                    Dispatcher.Dispatch(getCustomerAction);
                    break;

                case "x":
                    Console.WriteLine("Program terminated");
                    return;
                }
            } while (true);
        }
Пример #7
0
        public async Task HandleFetchDataAction(FetchDataAction action, IDispatcher dispatcher)
        {
            var forecasts = await WeatherForecastService.GetForecastAsync(DateTime.Now);

            dispatcher.Dispatch(new FetchDataResultAction(forecasts));
        }
Пример #8
0
 public static WeatherState ReduceFetchDataAction(WeatherState state, FetchDataAction action) =>
 new WeatherState(
     isLoading: true,
     forecasts: null);
Пример #9
0
        public async Task HandleFetchDataAction(FetchDataAction action, IDispatcher dispatcher)
        {
            var forecasts = await Http.GetFromJsonAsync <WeatherForecast[]>("WeatherForecast");

            dispatcher.Dispatch(new FetchDataResultAction(forecasts));
        }
Пример #10
0
 public static WeatherState ReduceFetchDataAction(WeatherState state, FetchDataAction action) =>
 new WeatherState(true, null);
Пример #11
0
 public static DataState ReduceFetchDataAction(DataState state, FetchDataAction action)
 {
     return(new DataState(state.Thootles, true));
 }
Пример #12
0
 public static FetchDataState ReduceFetchDataAction(FetchDataState state, FetchDataAction action) =>