void _loadDataBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            LoadDataResult resultWrapper = e.Argument as LoadDataResult;

            if (resultWrapper != null)
            {
                resultWrapper.Result = this.LoadData();
            }
        }
        public bool LoadData_BkgndWithModalLoop()
        {
            LoadDataResult resultFromBackgroundWorker = new LoadDataResult()
            {
                Result = false
            };

            DispatcherFrame modalLoopFrame = new DispatcherFrame();

            _loadDataBackgroundWorker                            = new BackgroundWorker();
            _loadDataBackgroundWorker.DoWork                    += new DoWorkEventHandler(_loadDataBackgroundWorker_DoWork);
            _loadDataBackgroundWorker.RunWorkerCompleted        += (sender, e) => modalLoopFrame.Continue = false;
            _loadDataBackgroundWorker.WorkerSupportsCancellation = true;
            _loadDataBackgroundWorker.RunWorkerAsync(resultFromBackgroundWorker);

            Dispatcher.PushFrame(modalLoopFrame);

            return(resultFromBackgroundWorker.Result);
        }
Esempio n. 3
0
    private async void LoadData()
    {
        try
        {
            LoadDataResult loadResult = await m_saveManager.LoadData();

            if (loadResult.Status == GameSaveErrorStatus.Ok)
            {
                m_gameData = loadResult.Data;
                LogLine(String.Format("Loaded data : {0}", m_gameData));
            }
            else
            {
                LogLine(String.Format("LoadData failed: {0}", loadResult.Status));
            }
        }
        catch (Exception ex)
        {
            LogLine("LoadData failed: " + ex.Message);
        }

        LogLine("");
    }
Esempio n. 4
0
        private async Task <LoadDataResult <T> > LoadFromHttpAsync <T>(string url)
        {
            var http = new HttpClient();
            HttpResponseMessage response;

            try
            {
                response = await http.GetAsync(url);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(new LoadDataResult <T>
                {
                    Message = "Unexpected exception see log for details"
                });
            }

            var result = new LoadDataResult <T>
            {
                Success = response.IsSuccessStatusCode,
                Message = response.ReasonPhrase
            };

            if (response.IsSuccessStatusCode)
            {
                var serializeOptions = new JsonSerializerOptions
                {
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
                };
                using var responseStream = await response.Content.ReadAsStreamAsync();

                result.Data = await JsonSerializer.DeserializeAsync <T>(responseStream, serializeOptions);
            }
            return(result);
        }
Esempio n. 5
0
 public override Task Invoke(LoadDataResult action)
 {
     return(action.Payload.Count > 0
 ? App.ShowMessge($"Loaded {action.Payload.Count} items")
 : App.ShowMessge("Loading failed", true));
 }