public void OpenNewWindow(IMainVM model) { if (model is IMainWindowVM) using (var container = AutofacHelper.Container) { try { var newWindow = new MainView((IMainWindowVM)model); newWindow.ShowDialog(); } catch(UriFormatException) { throw new UriFormatException(); } } if (model is INewDownloadVM) using (var container = AutofacHelper.Container) { var newWindow = new NewDownloadView((INewDownloadVM)model); newWindow.ShowDialog(); } //if (model is IAppSettingsVM) // using (var container = AutofacHelper.Container) // { // var newWindow = new AppSettingsView((IAppSettingsVM)model); // newWindow.ShowDialog(); // } }
/// <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"); }
//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(); }