Пример #1
0
        private static void FinishDownload(Uri uri, bool result)
        {
            Interlocked.Decrement(ref MBDownloadManager.fileUriers);
            Console.WriteLine("DECREMENT " + MBDownloadManager.fileUriers);

            bool   flag2 = false;
            object obj   = MBDownloadManager.requestQueue;

            lock (obj)
            {
                if (result)
                {
                    MBDownloadManager.queuedUpdates.Add(uri);
                    if (MBDownloadManager.queuedUpdates.Count == 1)
                    {
                        flag2 = true;
                    }
                }
                else
                {
                    MBDownloadManager.pendingRequests.Remove(uri);

                    DownloadInfo down = MBDownloadManager.DownloadInfo(uri.AbsoluteUri);

                    if (down != null)
                    {
                        Android.App.DownloadManager downloadManager = (Android.App.DownloadManager)Application.Context.GetSystemService("download");
                        downloadManager.Remove(down.Id);
                    }
                }

                if (MBDownloadManager.requestQueue.Count > 0)
                {
                    uri = MBDownloadManager.requestQueue.Pop();
                    if (uri == null)
                    {
                        Console.Error.WriteLine("Dropping request {0} because url is null", uri);
                        MBDownloadManager.pendingRequests.Remove(uri);
                        uri = null;
                    }
                }
                else
                {
                    uri = null;
                }
            }

            if (flag2)
            {
                //FileDownloader.nsDispatcher.BeginInvokeOnMainThread(new NSAction(FileDownloader.NotifyDownloadListeners));
                NotifyDownloadListeners();
            }

            if (uri != null)
            {
                Interlocked.Increment(ref MBDownloadManager.fileUriers);
                MBDownloadManager.StartFileDownload(uri);
            }
        }
Пример #2
0
        static void QueueRequest(Uri uri, IDownloadUpdated2 notify)
        {
            if (notify == null)
            {
                throw new ArgumentNullException("notify");
            }
            object obj = MBDownloadManager.requestQueue;

            lock (obj)
            {
                if (MBDownloadManager.pendingRequests.ContainsKey(uri))
                {
                    MBDownloadManager.pendingRequests[uri].Add(notify);
                }
                else
                {
                    List <IDownloadUpdated2> list = new List <IDownloadUpdated2>(4);
                    list.Add(notify);
                    MBDownloadManager.pendingRequests[uri] = list;
                    if (MBDownloadManager.fileUriers >= MaxRequests)
                    {
                        MBDownloadManager.requestQueue.Push(uri);
                    }
                    else
                    {
                        Interlocked.Increment(ref MBDownloadManager.fileUriers);
                        ThreadPool.QueueUserWorkItem(delegate
                        {
                            try
                            {
                                MBDownloadManager.StartFileDownload(uri);
                            }
                            catch (Exception value)
                            {
                                Console.WriteLine(value);
                            }
                        });
                    }
                }
            }
        }