/// <summary> /// Method for adding download /// </summary> /// <param name="param">Download param</param> private void AddDownload(object param) { NewDownloadView newDownloadView = new NewDownloadView(); newDownloadView.ShowDialog(); string fileName = string.Empty; if (newDownloadView.Model.Mirror != null) { Uri uri = new Uri(newDownloadView.Model.Mirror.Url); fileName = uri.Segments[uri.Segments.Length - 1]; fileName = HttpUtility.UrlDecode(fileName).Replace("/", "\\"); } else if (newDownloadView.Model.Mirrors.Count != 0) { Uri uri = new Uri(newDownloadView.Model.Mirrors[0].Url); fileName = uri.Segments[uri.Segments.Length - 1]; fileName = HttpUtility.UrlDecode(fileName).Replace("/", "\\"); } Downloader fileToDownload = new Downloader( newDownloadView.Model.Mirror, newDownloadView.Model.Mirrors.ToArray(), newDownloadView.Model.SavePath, fileName); DownloaderManager.Instance.Add(fileToDownload, true); DownloadViewer viewer = new DownloadViewer(); viewer.DataContext = new DownloadViewerVM(fileToDownload); _itemsToDownloaders.Add(fileToDownload, viewer); NotifyPropertyChanged("ItemsToDownloaders"); }
private void AddSavedDownloads() { try { var downloads = DownloadsSerializer.Deserialize(); foreach (var fileToDownload in downloads) { //@ if (fileToDownload.State.State != DownloadState.Ended && fileToDownload.State.State != DownloadState.EndedWithError) { DownloaderManager.Instance.Add(fileToDownload, true); } var viewer = new DownloadViewer(); viewer.DataContext = new DownloadViewerVM(fileToDownload); _itemsToDownloaders.Add(fileToDownload, viewer); } NotifyView(); } catch (FileNotFoundException) { //@ } }
private void AddSavedDownloads() { try { List<Downloader> downloads = DownloadsSerializer.Deserialize(); foreach (var fileToDownload in downloads) { if (fileToDownload.State.GetType() != typeof(DownloadEndedState) && fileToDownload.State.GetType() != typeof(DownloadEndedWithErrorState)) { DownloaderManager.Instance.Add(fileToDownload, true); } DownloadViewer viewer = new DownloadViewer(); viewer.DataContext = new DownloadViewerVM(fileToDownload); _itemsToDownloaders.Add(fileToDownload, viewer); } NotifyPropertyChanged("ItemsToDownloaders"); } catch (FileNotFoundException) { } }
//AutoFac /// <summary> /// Method for adding download /// </summary> /// <param name="param">Download param</param> private void AddDownload(object param) { NewDownloadView newDownloadView = new NewDownloadView(); newDownloadView.ShowDialog(); string fileName = string.Empty; fileName = newDownloadView.Model.Mirror != null ? GetFileName(newDownloadView.Model.Mirror) : GetFileName(newDownloadView.Model.Mirrors.First()); Downloader fileToDownload = new Downloader( newDownloadView.Model.Mirror, newDownloadView.Model.Mirrors.ToArray(), newDownloadView.Model.SavePath, fileName); DownloaderManager.Instance.Add(fileToDownload, true); var viewer = new DownloadViewer(); viewer.DataContext = new DownloadViewerVM(fileToDownload); _itemsToDownloaders.Add(fileToDownload, viewer); NotifyView(); }