public async Task StartUpload(string tag, string url, string method, HttpContent content) { FileUploadRequest request = new FileUploadRequest() { Identifier = tag, ContentType = content.Headers.ContentType.ToString(), FilePath = System.IO.Path.GetTempFileName(), Method = method, Url = url, ResponseFilePath = System.IO.Path.GetTempFileName() }; List <Header> headerlist = new List <Header>(); foreach (var header in content.Headers) { if (string.Equals(header.Key, "content-type", StringComparison.OrdinalIgnoreCase)) { continue; } headerlist.Add(new Header(header.Key, string.Join(" ", header.Value))); } using (var fs = System.IO.File.OpenWrite(request.FilePath)) { await content.CopyToAsync(fs); } await QueueRequest(request); }
protected override void StartUploadInternal(FileUploadRequest r) { var session = GetSession(r.Identifier); var request = new NSMutableUrlRequest(NSUrl.FromString(r.Url)); request.HttpMethod = r.Method; NSMutableDictionary headers = new NSMutableDictionary(); headers.SetValueForKey(new NSString(r.ContentType), (NSString)"Content-Type"); if (r.Headers != null) { foreach (var h in r.Headers) { headers.SetValueForKey(new NSString(h.Key), new NSString(h.Value)); } } request.Headers = headers; var uploadTask = session.CreateUploadTask(request, NSUrl.FromFilename(r.FilePath)); uploadTask.Resume(); }
internal Task ReportStatus(FileUploadRequest r) { return(Task.Run(async() => { try { //lock (r) //{ // if (r.IsNotifying) // return; // r.IsNotifying = true; //} if (r.ResponseCode == 200) { if (await Receiver.CompletedAsync(r)) { r.Processed = true; } } else { if (await Receiver.FailedAsync(r)) { r.Processed = true; } } if (r.Processed) { // delete file... Storage.Remove(r); if (System.IO.File.Exists(r.FilePath)) { System.IO.File.Delete(r.FilePath); } if (r.ResponseFilePath != null && System.IO.File.Exists(r.ResponseFilePath)) { System.IO.File.Delete(r.ResponseFilePath); } SaveState(); } } catch (Exception ex) { ReportFatalError(ex); } //finally //{ // lock (r) // { // r.IsNotifying = false; // } //} })); }
protected virtual Task QueueRequest(FileUploadRequest request) { Storage.Add(request); StartUploadInternal(request); SaveState(); return(Task.CompletedTask); }
public void Add(FileUploadRequest request) { lock (this) { if (requests.Any(x => x.Identifier == request.Identifier)) { throw new InvalidOperationException(); } requests.Add(request); Save(false); } }
public bool Remove(FileUploadRequest request) { lock (this) { int index = requests.FindIndex(x => x.Identifier == request.Identifier); if (index != -1) { requests.RemoveAt(index); Save(false); return(true); } } return(false); }
protected abstract void OnCancel(FileUploadRequest r);
internal void ReportProgress(FileUploadRequest r) { Receiver.OnProgress(r); SaveState(); }
protected abstract void StartUploadInternal(FileUploadRequest request);
protected override void OnCancel(FileUploadRequest request) { BackgroundUploadService.CancellationTokenSource?.Cancel(false); }
protected override void StartUploadInternal(FileUploadRequest request) { Intent intent = new Intent(Context, typeof(BackgroundUploadService)); Context.StartService(intent); }
protected override void StartUploadInternal(FileUploadRequest request) { throw new NotImplementedException(); }
protected override void OnCancel(FileUploadRequest r) { throw new NotImplementedException(); }
protected override void OnCancel(FileUploadRequest r) { GetSession(r.Identifier).InvalidateAndCancel(); }
public FileUploadRequestArgs(FileUploadRequest request) { this.Request = request; }