Exemplo n.º 1
0
        public static void RemoveAll()
        {
            try
            {
                Android.App.DownloadManager downloadManager = (Android.App.DownloadManager)Application.Context.GetSystemService("download");

                Android.App.DownloadManager.Query query = new Android.App.DownloadManager.Query();
                //query.SetFilterById(_downloadReference);
                //query.SetFilterByStatus(DownloadStatus.Pending | DownloadStatus.Running | DownloadStatus.Paused | DownloadStatus.Successful);

                ICursor cursor = downloadManager.InvokeQuery(query);

                while (cursor.MoveToNext())
                {
                    long id = cursor.GetLong(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnId));
                    downloadManager.Remove(id);
                }

                MBDownloadManager.fileUriers = 0;
            }
            catch (Exception ex)
            {
                string tag = TAG + " - RemoveAll";
                Log.Error(tag, ex.Message);
            }
        }
Exemplo n.º 2
0
        static void NotifyDownloadListeners()
        {
            lock (requestQueue)
            {
                foreach (var quri in queuedUpdates)
                {
                    var list = pendingRequests[quri];
                    pendingRequests.Remove(quri);

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

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

                        MBDownloadManager.RegisterDownload(quri.ToString(), down.LocalUri);
                    }

                    foreach (var pr in list)
                    {
                        try
                        {
                            pr.DownloadCompleted(quri.AbsoluteUri, ""); // this is the bit that should be on the UiThread
                        }
                        catch (Exception e)
                        {
                            Log.Error("MWC", e.Message);
                        }
                    }
                }

                queuedUpdates.Clear();
            }
        }
Exemplo n.º 3
0
        public static void InstallFinishedMB()
        {
            Android.App.DownloadManager.Query query = new Android.App.DownloadManager.Query();

            query.SetFilterByStatus(DownloadStatus.Successful);

            Android.App.DownloadManager downloadManager = (Android.App.DownloadManager)Context.GetSystemService("download");

            ICursor cursor = downloadManager.InvokeQuery(query);

            while (cursor.MoveToNext())
            {
                string localUri = cursor.GetString(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnLocalUri));
                string uri      = cursor.GetString(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnUri));
                long   id       = cursor.GetLong(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnId));
                string filePath = new Uri(localUri).AbsolutePath;

                if (File.Exists(filePath))
                {
                    MBDownloadManager.InstallMbPackage(uri, localUri);
                    downloadManager.Remove(id);
                    //MBDownloadManager.FinishDownload(new Uri(uri), true);
                }
            }

            cursor.Close();
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
        public void Abort(IDownloadFile i)
        {
            var file = (DownloadFileImplementation)i;

            file.Status = DownloadFileStatus.CANCELED;
            _downloadManager.Remove(file.Id);
            RemoveFile(file);
        }
Exemplo n.º 6
0
        public static void RemoveAll()
        {
            Android.App.DownloadManager downloadManager = (Android.App.DownloadManager)Application.Context.GetSystemService("download");

            Android.App.DownloadManager.Query query = new Android.App.DownloadManager.Query();
            //query.SetFilterById(_downloadReference);
            query.SetFilterByStatus(DownloadStatus.Pending | DownloadStatus.Running | DownloadStatus.Paused);

            ICursor cursor = downloadManager.InvokeQuery(query);

            while (cursor.MoveToNext())
            {
                long id = cursor.GetLong(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnId));
                downloadManager.Remove(id);
            }
        }
Exemplo n.º 7
0
        public static void Remove(long id)
        {
            Android.App.DownloadManager downloadManager = (Android.App.DownloadManager)Application.Context.GetSystemService("download");

            var info = MBDownloadManager2.DownloadInfo(id);

            var uri = new Uri(info.Uri);

            downloadManager.Remove(id);

            if (pendingRequests != null && pendingRequests.ContainsKey(uri))
            {
                pendingRequests.Remove(uri);

                if (queuedUpdates.Contains(uri))
                {
                    queuedUpdates.Remove(uri);
                }
            }
        }
Exemplo n.º 8
0
 public void Abort(DownloadFileImplementation file)
 {
     file.Status = DownloadFileStatus.CANCELED;
     _downloadManager.Remove(file.Id);
     RemoveFile(file);
 }
Exemplo n.º 9
0
        private static void DownloadMonitor(long downId)
        {
            bool downloading = true;

            Android.App.DownloadManager downloadManager = (Android.App.DownloadManager)Application.Context.GetSystemService("download");

            while (downloading)
            {
                DownloadInfo down = MBDownloadManager2.DownloadInfo(downId);

                if (down == null)
                {
                    break;
                }

                Uri uri = new Uri(down.Uri);

                switch (down.Status)
                {
                case DownloadStatus.Running:
                case DownloadStatus.Pending:
                    if (MBDownloadManager2.pendingRequests.ContainsKey(uri))
                    {
                        List <IDownloadUpdated2> list = MBDownloadManager2.pendingRequests[uri];
                        var perc = (int)((down.ByteDownloaded * 100L) / down.ByteTotal);
                        try
                        {
                            foreach (IDownloadUpdated2 current2 in list)
                            {
                                current2.ProgressChanged(perc);
                            }
                        }
                        catch (Exception value)
                        {
                            Console.WriteLine(value);
                        }
                    }
                    break;

                case DownloadStatus.Successful:
                    try
                    {
                        MBDownloadManager2.InstallMbPackage(down.Uri, down.LocalUri);
                        downloadManager.Remove(down.Id);

                        downloading = false;

                        MBDownloadManager2.RegisterDownload(uri.ToString(), down.LocalUri);

                        MBDownloadManager2.FinishDownload(uri, true);
                    }
                    catch (Exception value)
                    {
                        Console.WriteLine(value);
                        MBDownloadManager2.FinishDownload(uri, false);
                    }
                    break;

                default:
                    break;
                }
            }
        }