public async void Completed(NSUrlSessionTask downloadTask, NSUrl location) { NSFileManager fileManager = NSFileManager.DefaultManager; NSError errorCopy = null; var file = Load(downloadTask); LogManager.Shared.Log("Download Complete", file); file.IsCompleted = true; file.Status = BackgroundDownloadFile.FileStatus.Temporary; file.Percent = 1; //if (!AutoProcess) //{ // var sharedFolder = fileManager.GetContainerUrl(SharedContainerIdentifier); // fileManager.CreateDirectory(sharedFolder, true, null, out errorCopy); // var fileName = Path.GetFileName(file.Destination); // var newTemp = Path.Combine(sharedFolder.RelativePath, fileName); // var success1 = fileManager.Copy(location, NSUrl.FromFilename(newTemp), out errorCopy); // Console.WriteLine("Success: {0} {1}", success1, errorCopy); // file.TempLocation = newTemp; // return; //} var originalURL = downloadTask.OriginalRequest.Url; var dest = Path.Combine(Locations.BaseDir, file.Destination); NSUrl destinationURL = NSUrl.FromFilename(dest); NSError removeCopy; fileManager.Remove(destinationURL, out removeCopy); LogManager.Shared.Log("Copying Downloaded File", value: "Destination", key: dest); var success = fileManager.Copy(location, destinationURL, out errorCopy); if (success) { file.Status = BackgroundDownloadFile.FileStatus.Completed; } else { LogManager.Shared.Log("Error copying file", key: "Error", value: errorCopy?.LocalizedDescription ?? ""); } Console.WriteLine("Success: {0} {1}", success, errorCopy); file.Status = BackgroundDownloadFile.FileStatus.Completed; file.Destination = dest; await ProcessFile(file); FileCompleted?.InvokeOnMainThread(downloadTask, new CompletedArgs { File = file }); LogManager.Shared.Log("Download Completed", key: "Data", value: downloadTask.TaskDescription); }
protected virtual void OnFileCompleted(FileInfo fileInfo) { FileCompleted?.Invoke(this, fileInfo); }
protected virtual void OnFileCompleted(string filename) { FileCompleted?.Invoke(this, new FileEventArgs(filename)); }