Example #1
0
        private async void OnDownloadProgressChanged(object sender, TransferItem e)
        {
            await _dispatcherWrapper.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (DownloadsState == ContentState.Loading)
                {
                    return;
                }

                DownloadsState = ContentState.Normal;
                var item       = Downloads.FirstOrDefault(d => d.OperationGuid == e.OperationGuid);
                if (item == null)
                {
                    if (e.Status != BackgroundTransferStatus.Completed &&
                        e.Status != BackgroundTransferStatus.Canceled)
                    {
                        return;
                    }

                    Downloads.Add(new TransferItemViewModel(e, _locService));
                    item = Downloads.FirstOrDefault(d => d.OperationGuid == e.OperationGuid);
                    if (item == null)
                    {
                        return;
                    }
                }
                else
                {
                    item.Operation = e;
                }

                if (item.Status == BackgroundTransferStatus.Completed ||
                    item.Status == BackgroundTransferStatus.Canceled)
                {
                    Downloads.Remove(item);
                }

                if (Downloads.Count == 0)
                {
                    DownloadsState = ContentState.NoData;
                }
                else
                {
                    Downloads.OrderBy(d => d.Status, new TransferStatusComparer());
                }

                CancelAllDownloadsCommand.RaiseCanExecuteChanged();
            });
        }