コード例 #1
0
        private void SetSource(ITLTransferable transferable, TLFileLocation location, int fileSize, int phase)
        {
            if (phase >= Phase && location != null)
            {
                //Phase = phase;

                var fileName = string.Format("{0}_{1}_{2}.jpg", location.VolumeId, location.LocalId, location.Secret);
                if (File.Exists(FileUtils.GetTempFileName(fileName)))
                {
                    _bitmapImage.UriSource = FileUtils.GetTempFileUri(fileName);
                }
                else
                {
                    Execute.BeginOnThreadPool(async() =>
                    {
                        var result = await _downloadManager.DownloadFileAsync(location, fileSize).AsTask(transferable?.Download());
                        if (result != null && Phase <= phase)
                        {
                            Phase = phase;

                            Execute.BeginOnUIThread(() =>
                            {
                                if (transferable != null)
                                {
                                    transferable.IsTransferring = false;
                                }

                                _bitmapImage.UriSource = FileUtils.GetTempFileUri(fileName);
                            });
                        }
                    });
                }
            }
        }
コード例 #2
0
        public async void DownloadAsync(IDownloadFileManager manager, Action <TLPhoto> completed)
        {
            var photoSize = Full as TLPhotoSize;

            if (photoSize == null)
            {
                return;
            }

            var location = photoSize.Location as TLFileLocation;

            if (location == null)
            {
                return;
            }

            var fileName = string.Format("{0}_{1}_{2}.jpg", location.VolumeId, location.LocalId, location.Secret);

            if (File.Exists(FileUtils.GetTempFileName(fileName)))
            {
            }
            else
            {
                if (IsTransferring)
                {
                    return;
                }

                var download = await manager.DownloadFileAsync(location, photoSize.Size, Download());

                if (download != null)
                {
                    completed(this);
                }
            }
        }