void RemoveInflightData(NSUrlSessionTask task, bool cancel = true)
        {
            lock (inflightRequestsLock) {
                if (inflightRequests.TryGetValue(task, out var data))
                {
                    if (cancel)
                    {
                        data.CancellationTokenSource.Cancel();
                    }
                    data.Dispose();
                    inflightRequests.Remove(task);
                }
#if !MONOMAC && !__WATCHOS__
                // do we need to be notified? If we have not inflightData, we do not
                if (inflightRequests.Count == 0)
                {
                    RemoveNotification();
                }
#endif
            }

            if (cancel)
            {
                task?.Cancel();
            }

            task?.Dispose();
        }
        /// <summary>
        /// Very misleading method name. Gets called if a download is done. Does not necessarily indicate an error
        /// unless the NSError parameter is not null.
        /// </summary>
        public override void DidCompleteWithError(NSUrlSession session, NSUrlSessionTask task, NSError error)
        {
            var downloadInfo = AppDelegate.GetDownloadInfoByTaskId(task.TaskIdentifier);

            // Remember the first completed download. We want to play that when all downloads have finished.
            // If playback is started right here in this method, DidFinishEventsForBackgroundSession() won't be called - no idea why.
            if (this.firstCompletedDownload == null)
            {
                this.firstCompletedDownload = downloadInfo;
            }

            if (error == null)
            {
                return;
            }

            Console.WriteLine("DidCompleteWithError - Task: {0}, Error: {1}", task.TaskIdentifier, error);

            if (downloadInfo != null)
            {
                downloadInfo.Reset(true);
            }

            task.Cancel();
            this.InvokeOnMainThread(() => this.controller.TableView.ReloadData());
        }
            InflightData GetInflightData(NSUrlSessionTask task)
            {
                var inflight = default(InflightData);

                lock (sessionHandler.inflightRequestsLock)
                    if (sessionHandler.inflightRequests.TryGetValue(task, out inflight))
                    {
                        // ensure that we did not cancel the request, if we did, do cancel the task
                        if (inflight.CancellationToken.IsCancellationRequested)
                        {
                            task?.Cancel();
                        }
                        return(inflight);
                    }

                // if we did not manage to get the inflight data, we either got an error or have been canceled, lets cancel the task, that will execute DidCompleteWithError
                task?.Cancel();
                return(null);
            }
		public override void DidCompleteWithError (NSUrlSession session, NSUrlSessionTask task, NSError error)
		{
			if (error == null) {
				return;
			}

			Console.WriteLine ("DidCompleteWithError - Task: {0}, Error: {1}", task.TaskIdentifier, error);

			task.Cancel ();
		}
        public override void DidCompleteWithError(NSUrlSession session, NSUrlSessionTask task, NSError error)
        {
            if (error == null)
            {
                return;
            }

            Console.WriteLine("DidCompleteWithError - Task: {0}, Error: {1}", task.TaskIdentifier, error);

            task.Cancel();
        }
        void RemoveInflightData(NSUrlSessionTask task, bool cancel = true)
        {
            lock (inflightRequestsLock)
                inflightRequests.Remove(task);

            if (cancel)
            {
                task?.Cancel();
            }

            task?.Dispose();
        }
示例#7
0
        /// <summary>
        /// Gets called when a download is done. Does not necessarily indicate an error
        /// unless the NSError parameter is not null.
        /// </summary>
        /// <param name="session">NSUrl Session.</param>
        /// <param name="task">Session Task.</param>
        /// <param name="error">Error received.</param>
        public override void DidCompleteWithError(NSUrlSession session, NSUrlSessionTask task, NSError error)
        {
            if (error == null)
            {
                AppSettings.CurrentSettings.MmpkDownloadDate = DateTime.Now;

                // Save user settings
                Task.Run(() => AppSettings.SaveSettings(Path.Combine(DownloadViewModel.GetDataFolder(), "AppSettings.xml")));
                return;
            }

            // If error indeed occured, cancel the task
            task.Cancel();
        }
示例#8
0
        void RemoveInflightData(NSUrlSessionTask task, bool cancel = true)
        {
            InflightData inflight;

            lock (inflightRequestsLock)
                if (inflightRequests.TryGetValue(task, out inflight))
                {
                    inflightRequests.Remove(task);
                }

            if (cancel)
            {
                task?.Cancel();
            }

            task?.Dispose();
        }
        /// <summary>
        /// Very misleading method name. Gets called if a download is done. Does not necessarily indicate an error
        /// unless the NSError parameter is not null.
        /// </summary>
        public override void DidCompleteWithError(NSUrlSession session, NSUrlSessionTask task, NSError error)
        {
            if (error == null)
            {
                return;
            }

            Console.WriteLine ("DidCompleteWithError - Task: {0}, Error: {1}", task.TaskIdentifier, error);
            var downloadInfo = AppDelegate.GetDownloadInfoByTaskId (task.TaskIdentifier);
            if (downloadInfo != null)
            {
                downloadInfo.Reset ();
            }

            task.Cancel ();
            this.InvokeOnMainThread (() => this.controller.TableView.ReloadData());
        }
        /// <summary>
        /// Very misleading method name. Gets called if a download is done. Does not necessarily indicate an error
        /// unless the NSError parameter is not null.
        /// </summary>
        public override void DidCompleteWithError(NSUrlSession session, NSUrlSessionTask task, NSError error)
        {
            if (error == null)
            {
                return;
            }

            Console.WriteLine("DidCompleteWithError - Task: {0}, Error: {1}", task.TaskIdentifier, error);
            var downloadInfo = AppDelegate.GetDownloadInfoByTaskId(task.TaskIdentifier);

            if (downloadInfo != null)
            {
                downloadInfo.Reset();
            }

            task.Cancel();
            this.InvokeOnMainThread(() => this.controller.TableView.ReloadData());
        }
示例#11
0
        void RemoveInflightData(NSUrlSessionTask task, bool cancel = true)
        {
            lock (inflightRequestsLock) {
                inflightRequests.Remove(task);
#if !MONOMAC && !MONOTOUCH_WATCH
                // do we need to be notified? If we have not inflightData, we do not
                if (inflightRequests.Count == 0)
                {
                    RemoveNotification();
                }
#endif
            }

            if (cancel)
            {
                task?.Cancel();
            }

            task?.Dispose();
        }
        BackgroundDownloadFile Load(NSUrlSessionTask task, bool createIfNotExist = true)
        {
            var id = (long)task.TaskIdentifier;

            if (CanceledItems.Contains(id))
            {
                task.Cancel();
                return(null);
            }
            var file = Files.Values.FirstOrDefault(x => x.TaskId == id);

            if (file != null || !createIfNotExist)
            {
                return(file);
            }

            file                = Newtonsoft.Json.JsonConvert.DeserializeObject <BackgroundDownloadFile>(task.TaskDescription);
            file.TaskId         = id;
            Files[file.TrackId] = file;
            return(file);
        }