public void RedownloadFailedURLs() { if (BookUpdater.CurrentBook != null && BookUpdater.CurrentBook.FailedURLs != null) { ASINetworkQueue networkQueue = new ASINetworkQueue(); networkQueue.Reset(); networkQueue.ShowAccurateProgress = false; networkQueue.ShouldCancelAllRequestsOnFailure = false; networkQueue.Delegate = this; networkQueue.RequestDidFail = new Selector("requestDidFail:"); networkQueue.RequestDidFinish = new Selector("requestDidFinish:"); networkQueue.QueueDidFinish = new Selector("queueDidFinish:"); ASIHTTPRequest request = null; foreach (String url in BookUpdater.CurrentBook.FailedURLs) { DownloadedFilesCache.RemoveFile(url); request = new ASIHTTPRequest(NSUrl.FromString(url)); request.DownloadDestinationPath = DownloadedFilesCache.BuildCachedFilePath(url); request.Username = Settings.UserID; request.Password = KeychainAccessor.Password; request.Domain = Settings.Domain; networkQueue.AddOperation(request); } // Clear failedUrls before starting to re-download BookUpdater.CurrentBook.FailedURLs.Clear(); networkQueue.Go(); } }
void RequestFinish(NSObject sender) { try { ASIHTTPRequest request = sender as ASIHTTPRequest; if (request != null) { // THIS IS REQUIRED TO SKIP iCLOUD BACKUP SkipBackup2iCloud.SetAttribute(request.DownloadDestinationPath); if (dataSource != null) { dataSource.UpdateImage(request.Url.AbsoluteString); } if (boc != null) { boc.UpdateCover(request.Url.AbsoluteString); } } } catch (Exception ex) { Logger.WriteLineDebugging("LibraryViewController - RequestFinish: {0}", ex.ToString()); } }
public static void RequestDidFinish(NSObject sender) { try { ASIHTTPRequest request = sender as ASIHTTPRequest; if (request != null) { // THIS IS REQUIRED TO SKIP iCLOUD BACKUP SkipBackup2iCloud.SetAttribute(request.DownloadDestinationPath); // Removed from the list if succeeded re-downloading if (CurrentBook.FailedURLs != null) { if (CurrentBook.FailedURLs.Contains(request.Url.AbsoluteString)) { CurrentBook.FailedURLs.Remove(request.Url.AbsoluteString); } } CurrentBook.DownloadCount += 1; DownloadReporter.UpdateProgress(); } } catch (Exception ex) { Logger.WriteLineDebugging("BookUpdater - RequestDidFinish: {0}", ex.ToString()); } }
public static void RequestDidFail(NSObject sender) { try { ASIHTTPRequest request = sender as ASIHTTPRequest; if (request != null && CurrentBook != null) { if (request.Url != null) { if (CurrentBook.FailedURLs == null) { CurrentBook.FailedURLs = new List <String>(); } if (!CurrentBook.FailedURLs.Contains(request.Url.AbsoluteString)) { CurrentBook.FailedURLs.Add(request.Url.AbsoluteString); Logger.WriteLineDebugging("RequestDidFail: {0} pages failed to download so far...", CurrentBook.FailedURLs.Count.ToString()); } } } } catch (Exception ex) { Logger.WriteLineDebugging("BookUpdater - RequestDidFail: {0}", ex.ToString()); } }
private static void DownloadPDFsWork(String bookID, List <String> urlList) { if (urlList.Count > 0) { networkQueue.Reset(); networkQueue.ShowAccurateProgress = false; networkQueue.ShouldCancelAllRequestsOnFailure = false; networkQueue.Delegate = ParentViewController; networkQueue.RequestDidFail = new Selector("requestDidFail:"); networkQueue.RequestDidFinish = new Selector("requestDidFinish:"); networkQueue.QueueDidFinish = new Selector("queueDidFinish:"); ASIHTTPRequest request = null; foreach (String url in urlList) { // Remove page if this is an update if (CurrentBook.Status == Book.BookStatus.UPDATING) { DownloadedFilesCache.RemoveFile(url); } request = new ASIHTTPRequest(NSUrl.FromString(url)); request.DownloadDestinationPath = DownloadedFilesCache.BuildCachedFilePath(url); request.Username = Settings.UserID; request.Password = KeychainAccessor.Password; request.Domain = Settings.Domain; networkQueue.AddOperation(request); } // Clear failedUrls before starting to re-download InitializeFailedURLs(); networkQueue.Go(); } else { // Finished downloading if (DownloadFinishEvent != null) { DownloadFinishEvent(bookID); } } }
public static bool Download(String url, UIViewController controller, bool forceDownload = false) { bool exist = false; if (!String.IsNullOrEmpty(url) && url.Contains("http")) { try { String localPath = DownloadedFilesCache.BuildCachedFilePath(url); if (File.Exists(localPath) && !forceDownload) { exist = true; } else { if (Reachability.IsDefaultNetworkAvailable()) { BackgroundWorker downloadWorker = new BackgroundWorker(); downloadWorker.DoWork += delegate { ASIHTTPRequest request = new ASIHTTPRequest(NSUrl.FromString(url)); request.Username = Settings.UserID; request.Password = KeychainAccessor.Password; request.Domain = Settings.Domain; request.Delegate = controller; request.DidFinishSelector = new Selector("requestFinish:"); request.DownloadDestinationPath = DownloadedFilesCache.BuildCachedFilePath(url); request.StartAsynchronous(); }; downloadWorker.RunWorkerAsync(); } } } catch (Exception ex) { Logger.WriteLineDebugging("FileDownloader - Download: {0}", ex.ToString()); } } return(exist); }