protected override Task <IEnumerable <HttpTransfer> > GetUploads(QueryFilter filter)
 => this.Query(filter, true);
示例#2
0
 public override Task <IEnumerable <HttpTransfer> > GetTransfers(QueryFilter filter = null)
 => this.Session.QueryTransfers(filter);
 protected override Task <IEnumerable <HttpTransfer> > GetDownloads(QueryFilter filter)
 => this.Query(filter, false);
        public override async void OnReceive(Context context, Intent intent)
        {
            if (intent.Action != Native.ActionDownloadComplete)
            {
                return;
            }

            var          id        = intent.GetLongExtra(Native.ExtraDownloadId, -1);
            var          native    = context.GetManager();
            var          tdelegate = ShinyHost.Resolve <IHttpTransferDelegate>();
            HttpTransfer?transfer  = null;

            try
            {
                var query = new QueryFilter().Add(id.ToString()).ToNative();
                using (var cursor = native.InvokeQuery(query))
                {
                    if (cursor.MoveToNext())
                    {
                        transfer = cursor.ToLib();
                        if (transfer.Value.Exception != null)
                        {
                            tdelegate.OnError(transfer.Value, transfer.Value.Exception);
                        }

                        else
                        {
                            var localUri = cursor.GetString(Native.ColumnLocalUri).Replace("file://", String.Empty);
                            var file     = new FileInfo(localUri);
                            Console.WriteLine("Local: " + file.FullName);

                            await Task.Run(() =>
                            {
                                var to = transfer.Value.LocalFilePath;
                                if (File.Exists(to))
                                {
                                    File.Delete(to);
                                }

                                //File.Copy(localPath, to, true);
                                File.Move(file.FullName, to);
                            });

                            tdelegate.OnCompleted(transfer.Value);
                        }
                        HttpEvents.OnNext(transfer.Value);
                    }
                }
            }
            catch (Exception ex)
            {
                if (transfer == null)
                {
                    Log.Write(ex);
                }
                else
                {
                    HttpEvents.OnNext(transfer.Value);
                    tdelegate.OnError(transfer.Value, ex);
                }
            }

            native.Remove(id);
        }