Ejemplo n.º 1
0
        private void RefreshAsync()
        {
            _appInsightsService.LogEvent("search/sheep", "Searching for Sheeps...");

            Task.Run(() =>
            {
                try
                {
                    var images = _imageSearchAgent.SearchAsync("Sheep").Result
                                 .Take(10).ToList();
                    var result = new ObservableCollection <Sheep>();

                    for (int i = 0; i < 9; i++)
                    {
                        result.Add(new Sheep()
                        {
                            Name    = string.Format("Sheep {0}", (i + 1)),
                            Picture = images[i]
                        });
                    }

                    Execute.OnUIThread(() => this.Items = result);
                }
                catch (Exception ex)
                {
                    _appInsightsService.LogError("search/error", "Unable to search sheeps from Internet", ex);
                }
            });
        }
        public async Task Synchronize()
        {
            var syncEventInsights = _appInsightsService.LogStartEvent("farmers/sync", "Start syncing farmers to/from backend...");

            try
            {
                // First synchronize with the backend service
                await _farmerRepo.SyncWithBackend();

                // Next refresh the UI
                await RefreshAsync();
            }
            catch (Exception ex)
            {
                _appInsightsService.LogError("farmers/sync/error", "Unable to synchronize farmers from backend!", ex);
            }
            finally
            {
                _appInsightsService.LogEndEvent(syncEventInsights);
            }
        }