internal void RemoveUpload(FileUpload upload, bool deleteFile)
		{
			Debug.Assert (this.session != null, "Session is required!");
			Debug.Assert (upload.State == FileUpload.STATE.Stopped, "Only stopped uploads can be removed!");

			var activeUpload = this.GetUploadByUniqueId (upload.UniqueId);
			Debug.Assert (activeUpload != null, "Requested upload not found in active uploads!");

			this.ActiveUploads.Remove (activeUpload);

			if (deleteFile)
			{
				try
				{
					File.Delete(upload.LocalFilePath);
				}
				catch(Exception ex)
				{
					Console.WriteLine ($"Failed to delete local file at '{upload.LocalFilePath}: {ex}");
				}
			}

		}
		internal void StopUpload(FileUpload upload)
		{
			Debug.Assert (this.session != null, "Session is required!");
			Debug.Assert (upload.State == FileUpload.STATE.Started, "Only started uploads can be stopped!");

			upload.State = FileUpload.STATE.Stopping;
			Debug.Assert (upload.IsStateValid (), "Invalid state after trying to stop upload!");
			upload.UploadTask.Cancel ();
		}
		public FileUpload CreateFileUpload(NSUrlRequest request, string localFilename)
		{
			Debug.Assert (this.session != null, "Session is required to create upload task!");
			Debug.Assert(request != null, "Cannot create upload without request!");
			Debug.Assert(!string.IsNullOrWhiteSpace(localFilename), "Cannot upload non-existing file!");

			Console.WriteLine ($"Creating upload task for file '{localFilename}'.");

			var upload = new FileUpload(
				request: request,
				uniqueId: System.Guid.NewGuid().ToString(),
				localFilePath: localFilename,
				creationDate: DateTime.Now,
				manager: this);
			
			Debug.Assert (upload.State == FileUpload.STATE.Stopped || upload.State == FileUpload.STATE.Failed, "Invalid state of file upload object!");

			Console.WriteLine ($"Adding active upload with ID '{upload.UniqueId}'.");
			this.ActiveUploads.Add (upload);

			return upload;
		}
		internal void StartUpload(FileUpload upload)
		{
			upload.UploadTask = this.session.CreateUploadTask (upload.Request, NSUrl.FromFilename(upload.LocalFilePath));
			upload.Error = null;
			upload.State = FileUpload.STATE.Started;

			Debug.Assert (upload.IsStateValid(), "Invalid state of upload/upload task!");

			upload.UploadTask.Resume ();
		}
		/// <summary>
		/// Helper to add an upload to the list of pending uploads.
		/// </summary>
		/// <param name="upload">Upload to add.</param>
		void AddUpload(FileUpload upload)
		{
			if(upload == null)
			{
				return;
			}
			Debug.Assert(!string.IsNullOrWhiteSpace(upload.UniqueId), "Added upload must have a unique ID!");
			this.ActiveUploads.Add(upload);
		}