Ejemplo n.º 1
0
        public void LazyLoading(IEnumerable <T> views)
        {
            var awaiter = LoadSegmentLazily(views).GetAwaiter();

            awaiter.OnCompleted(() =>
            {
                try
                {
                    awaiter.GetResult();
                    OnLazyLoadingCompleted?.Invoke(this, new AdapterLazyLoadingEventArgs(true, null));
                }

                catch (Exception ex)
                {
                    OnLazyLoadingCompleted?.Invoke(this, new AdapterLazyLoadingEventArgs(false, ex));
                }
            });
        }
Ejemplo n.º 2
0
        public void Load()
        {
            if (_loading)
            {
                return;
            }

            _loading = true;

            var getViewModelsAwaiter = GetViewModels().GetAwaiter();

            getViewModelsAwaiter.OnCompleted(() =>
            {
                try
                {
                    var viewModels = getViewModelsAwaiter.GetResult();
                    Items.Clear();
                    Items.AddRange(viewModels);
                    OnGetDataCompleted();
                    OnAdapterLoaded?.Invoke(this, new AdapterLoadingEventArgs(true, null));
                    Loaded = true;

                    if (LazyLoadingSettings == ELazyLoadingSettings.LoadEverything)
                    {
                        var loadDataLazilyAwaiter = LoadDataLazily().GetAwaiter();
                        loadDataLazilyAwaiter.OnCompleted(() =>
                        {
                            try
                            {
                                loadDataLazilyAwaiter.GetResult();
                                OnLazyLoadingCompleted?.Invoke(this, new AdapterLazyLoadingEventArgs(true, null));
                                _loading = false;
                            }

                            catch (Exception ex)
                            {
                                OnLazyLoadingCompleted?.Invoke(this, new AdapterLazyLoadingEventArgs(false, ex));
                            }
                        });
                    }

                    else if (LazyLoadingSettings == ELazyLoadingSettings.LoadVisibleSegments)
                    {
                        var loadDataLazilyAwaiter = LoadSegmentLazily(Items.Take(50)).GetAwaiter();
                        loadDataLazilyAwaiter.OnCompleted(() =>
                        {
                            try
                            {
                                loadDataLazilyAwaiter.GetResult();
                                OnLazyLoadingCompleted?.Invoke(this, new AdapterLazyLoadingEventArgs(true, null));
                                _loading = false;
                            }

                            catch (Exception ex)
                            {
                                OnLazyLoadingCompleted?.Invoke(this, new AdapterLazyLoadingEventArgs(false, ex));
                            }
                        });
                    }

                    else
                    {
                        _loading = false;
                    }
                }

                catch (Exception ex)
                {
                    OnAdapterLoaded?.Invoke(this, new AdapterLoadingEventArgs(false, ex));
                }
            });
        }