public async Task <LoadMoreItemsResult> LoadDataAsync(uint count, CancellationToken cancellationToken)
        {
            uint resultCount = 0;

            BeginLoading?.Invoke();

            IAsyncEnumerable <I> items = null;

            cancellationToken.ThrowIfCancellationRequested();

            try
            {
                items = await _Source.GetPagedItems((int)_Position, (int)_Source.OneTimeLoadCount);
            }
            catch (OperationCanceledException)
            {
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            cancellationToken.ThrowIfCancellationRequested();

            if (items != null)
            {
                // Task.Delay(50)は多重読み込み防止のためのおまじない
                // アイテム追加完了のタイミングで次の追加読み込みの判定が走るっぽいので
                // アイテム追加が完了するまでUIスレッドが止まっている必要があるっぽい、つまり
                //
                // 「非同期処理のことはよくわからない
                //
                //      俺たちは雰囲気で非同期処理をやっているんだ」
                //


                await Task.WhenAll(
                    items.ForEachAsync((item) =>
                {
                    this.Add(item);
                    ++resultCount;
                })
                    , Task.Delay(50)
                    );

                _Position += resultCount;
            }

            if (resultCount == 0)
            {
                _HasMoreItems = false;
            }

            DoneLoading?.Invoke();
            return(new LoadMoreItemsResult()
            {
                Count = resultCount
            });
        }
Esempio n. 2
0
        public async void LoadInBackground(string gcodePathAndFileName, Action <double, string> progressReporter)
        {
            this.FileNameAndPath = gcodePathAndFileName;

            loadedGCode = await GCodeFileLoaded.LoadInBackground(gcodePathAndFileName, progressReporter);

            // backgroundWorker_RunWorkerCompleted
            SetGCodeAfterLoad(loadedGCode);

            DoneLoading?.Invoke(this, null);
        }
Esempio n. 3
0
 private void postLoadInitialization_RunWorkerCompleted()
 {
     DoneLoading?.Invoke(this, null);
 }
Esempio n. 4
0
        public async Task <LoadMoreItemsResult> LoadDataAsync(uint count, CancellationToken cancellationToken)
        {
            try
            {
                await _LoadingLock.WaitAsync();

                BeginLoading?.Invoke();

                uint resultCount           = 0;
                IAsyncEnumerable <I> items = null;
                if (!cancellationToken.IsCancellationRequested)
                {
                    try
                    {
                        items = await _Source.GetPagedItems((int)_Position, (int)_Source.OneTimeLoadCount);
                    }
                    catch (OperationCanceledException)
                    {
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }

                if (items != null && !cancellationToken.IsCancellationRequested)
                {
                    // Task.Delay(50)は多重読み込み防止のためのおまじない
                    // アイテム追加完了のタイミングで次の追加読み込みの判定が走るっぽいので
                    // アイテム追加が完了するまでUIスレッドが止まっている必要があるっぽい、つまり
                    //
                    // 「非同期処理のことはよくわからない
                    //
                    //      俺たちは雰囲気で非同期処理をやっているんだ」
                    //
                    await Task.WhenAll(Task.Delay(50),
                                       items.ForEachAsync(async(item) =>
                    {
                        await _UIDispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { this.Add(item); });
                        ++resultCount;
                    })
                                       );

                    _Position += resultCount;
                }

                if (resultCount == 0)
                {
                    _HasMoreItems = false;
                }



                DoneLoading?.Invoke();

                return(new LoadMoreItemsResult()
                {
                    Count = resultCount
                });
            }
            finally
            {
                _LoadingLock.Release();
            }
        }
        public void Render()
        {
            if (this.ItemTemplate == null || this.ItemsSource == null || HeaderTemplate == null)
            {
                return;
            }

            var coll = this.ItemsSource as ICollection;

            if (coll?.Count <= 0)
            {
                return;
            }

            var mainLayout = new StackLayout {
                Spacing = HeaderSpacing, Orientation = StackOrientation.Vertical, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand
            };

            foreach (var source in this.ItemsSource)
            {
                var stackLayout = new StackLayout {
                    Orientation = StackOrientation.Vertical, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand
                };

                var viewCellHeader = HeaderTemplate.CreateContent() as ViewCell;

                if (viewCellHeader != null)
                {
                    viewCellHeader.View.BindingContext = source;
                    stackLayout.Children.Add(viewCellHeader.View);
                }


                if (source != null)
                {
                    var childitems = new StackLayout()
                    {
                        Spacing = ItemSpacing, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand
                    };


                    foreach (var item in (IEnumerable)source)
                    {
                        var itemsStackLayout = new StackLayout()
                        {
                            HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand
                        };

                        var viewCellItem = ItemTemplate.CreateContent() as Accordion;

                        var headercell = viewCellItem.HeaderTemplate.CreateContent() as HeaderViewCell;

                        if (headercell != null)
                        {
                            headercell.View.BindingContext = item;
                            itemsStackLayout.Children.Add(headercell.View);

                            var acrrodionSection = viewCellItem.ItemTemplate.CreateContent() as AccordionSection;

                            if (acrrodionSection != null)
                            {
                                acrrodionSection.BindingContext = item;
                                headercell.UpdateExpandCommand(acrrodionSection, ExpandCallBack);
                                acrrodionSection.IsVisible = false;
                                itemsStackLayout.Children.Add(acrrodionSection);
                                _headercells.Add(headercell);
                            }
                        }

                        childitems.Children.Add(itemsStackLayout);
                    }

                    stackLayout.Children.Add(childitems);
                }

                mainLayout.Children.Add(stackLayout);
            }

            Content = mainLayout;

            DoneLoading?.Invoke(this, new EventArgs());
        }
Esempio n. 6
0
 public static void OnDoneLoading()
 {
     DoneLoading?.Invoke();
 }
Esempio n. 7
0
        public IAsyncOperation <LoadMoreItemsResult> LoadMoreItemsAsync(uint count)
        {
            var dispatcher = Window.Current.Dispatcher;

            return(Task.Run(async() =>
            {
                try
                {
                    await _LoadingLock.WaitAsync();

                    await dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                              () => BeginLoading?.Invoke()
                                              );

                    uint resultCount = 0;

                    List <I> resultItems = null;
                    try
                    {
                        var items = await _Source.GetPagedItems((int)_Position, (int)_Source.OneTimeLoadCount);
                        resultItems = items?.ToList();
                        Debug.WriteLine("読み込み完了");
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }

                    if (resultItems == null || resultItems.Count == 0)
                    {
                        _HasMoreItems = false;
                    }
                    else
                    {
                        resultCount = (uint)resultItems.Count;

                        _Position += resultCount;

                        await dispatcher.RunAsync(CoreDispatcherPriority.High,
                                                  () =>
                        {
                            foreach (I item in resultItems)
                            {
                                this.Add(item);
                            }
                        });
                    }

                    // 多重読み込み防止のため
                    // リスト表示に反映されるまで
                    // タスクの終了を遅延させる必要があります
                    await Task.Delay(500);

                    await dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                              () => DoneLoading?.Invoke()
                                              );

                    return new LoadMoreItemsResult()
                    {
                        Count = resultCount
                    };
                }
                finally
                {
                    _LoadingLock.Release();
                }
            })
                   .AsAsyncOperation());
        }