private AppDownloadItem GetAppDownloadItem(DownloadOperation downloadOperation) { int appId = -1; var appDownloadItem = _downloadsHistory.SingleOrDefault(downloadItem => downloadItem.DownloadGuid == downloadOperation.Guid); if (appDownloadItem == null) { // Unknown download item! var queryStringParts = HttpUtility.ParseQueryString(downloadOperation.RequestedUri.Query); Int32.TryParse(queryStringParts["appid"], out appId); } appDownloadItem = new AppDownloadItem() { AppId = (appDownloadItem != null ? appDownloadItem.AppId : appId), AppName = (appDownloadItem != null ? appDownloadItem.AppName : downloadOperation.Guid.ToString()), StorageFile = downloadOperation.ResultFile, TotalBytesToReceive = downloadOperation.Progress.TotalBytesToReceive, BytesReceived = downloadOperation.Progress.BytesReceived, DownloadGuid = downloadOperation.Guid, Tag = downloadOperation, }; appDownloadItem.SetStatus(downloadOperation.Progress.Status); return(appDownloadItem); }
public async Task StartDownloadAsync(AppDownloadItem appDownloadItem) { await InitializeAsync(); if (FindAppInCurrentDownloads(appDownloadItem.AppGuid) != null) { return; } // Start Download CurrentDownloads.Add(appDownloadItem); appDownloadItem.StorageFile = await CurrentApplication.AppDownloadFolder.CreateFileAsync( $"{appDownloadItem.AppGuid}.pstl", CreationCollisionOption.ReplaceExisting); var downloadOperation = await _downloader.StartDownloadAsync( ServerUri.GetAppDownloadUri(appDownloadItem.AppGuid), appDownloadItem.StorageFile); appDownloadItem.StartDate = DateTime.Now; appDownloadItem.DownloadGuid = downloadOperation.Guid; appDownloadItem.Tag = downloadOperation; // update collections _downloadsHistory.Add(appDownloadItem); await SaveDownloadsHistoryToFileAsync(); }
public async Task InstallAppAsync(AppDownloadItem appDownloadItem) { InstallationQueue.Enqueue(appDownloadItem); if (InstallingPackage) { return; } InstallingPackage = true; while (InstallationQueue.Count() > 0) { PackageInstallationResult result = new PackageInstallationResult() { Success = false }; var item = InstallationQueue.Dequeue(); item.InstallationStatus = InstallationStatus.Installing; for (int i = 0; i < 3 && !result.Success; i++) { result = await DevicePackageManager.InstallAppAsync(item.StorageFile, item.AppGuid); if (!result.Success) { await Task.Delay(2000); } } if (result.Success) { item.InstallationStatus = InstallationStatus.Installed; // Delete App Package try { var storageFile = await CurrentApplication.AppDownloadFolder.GetFileAsync($"{item.AppGuid}.pstl"); await storageFile.DeleteAsync(); } catch { } } else { item.InstallationStatus = InstallationStatus.InstallationFailed; } // Raise Event if (InstallationCompleted != null) { InstallationCompleted(item); } } InstallingPackage = false; }
private static async void appDownloadManager_DownloadCompleted(AppDownloadItem appDownloadItem) { await PackageManager.Instance.InstallAppAsync(appDownloadItem); }
public void CancelDownload(AppDownloadItem appDownloadItem) { var downloadOperation = (DownloadOperation)appDownloadItem.Tag; _downloader.CancelDownload(downloadOperation); }
public void ResumeDownload(AppDownloadItem appDownloadItem) { var downloadOperation = (DownloadOperation)appDownloadItem.Tag; _downloader.ResumeDownload(downloadOperation); }
public void PauseDownload(AppDownloadItem appDownloadItem) { var downloadOperation = (DownloadOperation)appDownloadItem.Tag; _downloader.PauseDownload(downloadOperation); }