Esempio n. 1
0
        void ReinitializeFile(ICursor cursor)
        {
            var downloadFile = new DownloadFileImplementation(cursor);

            AddFile(downloadFile);
            UpdateFileProperties(cursor, downloadFile);
        }
Esempio n. 2
0
        public DownloadManagerImplementation()
        {
            _queue = new List <IDownloadFile>();

            // Enumerate outstanding downloads.
            BackgroundDownloader.GetCurrentDownloadsAsync().AsTask().ContinueWith((downloadOperationsTask) => {
                foreach (var downloadOperation in downloadOperationsTask.Result)
                {
                    var downloadFile = new DownloadFileImplementation(downloadOperation);
                    _queue.Add(downloadFile);
                }
            });
        }
Esempio n. 3
0
        /**
         * Move the downloaded file to it's destination
         */
        public bool MoveDownloadedFile(DownloadFileImplementation file, NSUrl location, string destinationPathName)
        {
            var fileManager = NSFileManager.DefaultManager;

            var     destinationUrl = new NSUrl(destinationPathName, false);
            NSError removeCopy;
            NSError errorCopy;

            fileManager.Remove(destinationUrl, out removeCopy);
            var success = fileManager.Copy(location, destinationUrl, out errorCopy);

            if (!success)
            {
                file.StatusDetails = errorCopy.LocalizedDescription;
                file.Status        = DownloadFileStatus.FAILED;
            }

            return(success);
        }
Esempio n. 4
0
        /**
         * Update the properties for a file by it's cursor.
         * This method should be called in an interval and on reinitialization.
         */
        public void UpdateFileProperties(ICursor cursor, DownloadFileImplementation downloadFile)
        {
            downloadFile.TotalBytesWritten  = cursor.GetInt(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnBytesDownloadedSoFar));
            downloadFile.TotalBytesExpected = cursor.GetInt(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnTotalSizeBytes));

            switch ((DownloadStatus)cursor.GetInt(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnStatus)))
            {
            case DownloadStatus.Successful:
                downloadFile.StatusDetails = default(string);
                downloadFile.Status        = DownloadFileStatus.COMPLETED;
                RemoveFile(downloadFile);
                break;

            case DownloadStatus.Failed:
                downloadFile.Status = DownloadFileStatus.FAILED;
                RemoveFile(downloadFile);

                var reasonFailed = cursor.GetInt(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnReason));
                if (reasonFailed < 600)
                {
                    downloadFile.StatusDetails = "Error.HttpCode: " + reasonFailed;
                }
                else
                {
                    switch ((DownloadError)reasonFailed)
                    {
                    case DownloadError.CannotResume:
                        downloadFile.StatusDetails = "Error.CannotResume";
                        break;

                    case DownloadError.DeviceNotFound:
                        downloadFile.StatusDetails = "Error.DeviceNotFound";
                        break;

                    case DownloadError.FileAlreadyExists:
                        downloadFile.StatusDetails = "Error.FileAlreadyExists";
                        break;

                    case DownloadError.FileError:
                        downloadFile.StatusDetails = "Error.FileError";
                        break;

                    case DownloadError.HttpDataError:
                        downloadFile.StatusDetails = "Error.HttpDataError";
                        break;

                    case DownloadError.InsufficientSpace:
                        downloadFile.StatusDetails = "Error.InsufficientSpace";
                        break;

                    case DownloadError.TooManyRedirects:
                        downloadFile.StatusDetails = "Error.TooManyRedirects";
                        break;

                    case DownloadError.UnhandledHttpCode:
                        downloadFile.StatusDetails = "Error.UnhandledHttpCode";
                        break;

                    case DownloadError.Unknown:
                        downloadFile.StatusDetails = "Error.Unknown";
                        break;

                    default:
                        downloadFile.StatusDetails = "Error.Unregistered: " + reasonFailed;
                        break;
                    }
                }
                break;

            case DownloadStatus.Paused:
                downloadFile.Status = DownloadFileStatus.PAUSED;

                var reasonPaused = cursor.GetInt(cursor.GetColumnIndex(Android.App.DownloadManager.ColumnReason));
                switch ((DownloadPausedReason)reasonPaused)
                {
                case DownloadPausedReason.QueuedForWifi:
                    downloadFile.StatusDetails = "Paused.QueuedForWifi";
                    break;

                case DownloadPausedReason.WaitingToRetry:
                    downloadFile.StatusDetails = "Paused.WaitingToRetry";
                    break;

                case DownloadPausedReason.WaitingForNetwork:
                    downloadFile.StatusDetails = "Paused.WaitingForNetwork";
                    break;

                case DownloadPausedReason.Unknown:
                    downloadFile.StatusDetails = "Paused.Unknown";
                    break;

                default:
                    downloadFile.StatusDetails = "Paused.Unregistered: " + reasonPaused;
                    break;
                }
                break;

            case DownloadStatus.Pending:
                downloadFile.StatusDetails = default(string);
                downloadFile.Status        = DownloadFileStatus.PENDING;
                break;

            case DownloadStatus.Running:
                downloadFile.StatusDetails = default(string);
                downloadFile.Status        = DownloadFileStatus.RUNNING;
                break;
            }
        }