private async void OnPackageDownloadRequested(object sender, EventArgs e) { PackageInfo packageInfo = _viewModel.SelectedPackage; if (packageInfo != null) { string selectedFilePath; int selectedIndex; string packageName = packageInfo.Id + "." + packageInfo.Version.ToString() + NuGetPe.Constants.PackageExtension; string title = "Save " + packageName; const string filter = "NuGet package file (*.nupkg)|*.nupkg|All files (*.*)|*.*"; bool accepted = UIServices.OpenSaveFileDialog( title, packageName, null, filter, overwritePrompt: true, selectedFilePath: out selectedFilePath, selectedFilterIndex: out selectedIndex); if (accepted) { if (selectedIndex == 1 && !selectedFilePath.EndsWith(NuGetPe.Constants.PackageExtension, StringComparison.OrdinalIgnoreCase)) { selectedFilePath += NuGetPe.Constants.PackageExtension; } await PackageDownloader.Download(selectedFilePath, packageInfo.DownloadUrl, packageInfo.Id, packageInfo.Version); } } }
private async void OnPackageDownloadRequested(object sender, EventArgs e) { var repository = _viewModel.ActiveRepository; var packageInfo = _viewModel.SelectedPackage; if (packageInfo != null) { var packageName = packageInfo.Id + "." + packageInfo.Version + NuGetPe.Constants.PackageExtension; var title = "Save " + packageName; const string filter = "NuGet package file (*.nupkg)|*.nupkg|NuGet Symbols package file (*.snupkg)|*.snupkg|All files (*.*)|*.*"; var accepted = UIServices.OpenSaveFileDialog( title, packageName, null, filter, overwritePrompt: true, selectedFilePath: out var selectedFilePath, selectedFilterIndex: out var selectedIndex); if (accepted) { if (selectedIndex == 1 && !selectedFilePath.EndsWith(NuGetPe.Constants.PackageExtension, StringComparison.OrdinalIgnoreCase)) { selectedFilePath += NuGetPe.Constants.PackageExtension; } await PackageDownloader.Download(selectedFilePath, repository, packageInfo.Identity); } } }
private void DownloadAndOpenDataServicePackage(MruItem item) { if (!NetworkInterface.GetIsNetworkAvailable()) { UIServices.Show( PackageExplorer.Resources.Resources.NoNetworkConnection, MessageLevel.Warning); return; } Uri downloadUrl; if (Uri.TryCreate(item.Path, UriKind.Absolute, out downloadUrl)) { var progressWindow = new DownloadProgressWindow(downloadUrl, item.Id, item.Version) { Owner = this }; var result = progressWindow.ShowDialog(); if (result ?? false) { LoadPackage(progressWindow.DownloadedPackage, item.Path, PackageType.DataServicePackage); } } }
private bool OpenLocalPackageCore(string packagePath) { IPackage package = null; try { string extension = Path.GetExtension(packagePath); if (extension.Equals(Constants.PackageExtension, StringComparison.OrdinalIgnoreCase)) { package = new ZipPackage(packagePath); } else if (extension.Equals(Constants.ManifestExtension, StringComparison.OrdinalIgnoreCase)) { var builder = new PackageBuilder(packagePath); package = builder.Build(); } if (package != null) { LoadPackage(package, packagePath, PackageType.LocalPackage); return(true); } } catch (Exception ex) { UIServices.Show(ex.Message, MessageLevel.Error); return(false); } return(false); }
/// <summary> /// Asks user to save the current file before doing something (e.g. exit, open a new file) /// </summary> /// <returns>true if user cancels the impending action</returns> private bool AskToSaveCurrentFile() { var viewModel = (PackageViewModel)DataContext; if (HasUnsavedChanges || (IsInEditFileMode && viewModel.FileEditorViewModel.HasEdit)) { // if there is unsaved changes, ask user for confirmation bool?result = UIServices.ConfirmWithCancel("You have unsaved changes in the current package.", StringResources.Dialog_SaveQuestion); if (result == null) { return(true); } else if (result == true) { if (IsInEditFileMode) { // force a Save from outside the file editor. // In this case, Content is the FileEditor user control viewModel.FileEditorViewModel.SaveOnExit((IFileEditorService)Content); } ICommand saveCommand = viewModel.SaveCommand; const string parameter = "ForceSave"; saveCommand.Execute(parameter); } } return(false); }
internal async Task DownloadAndOpenDataServicePackage(string packageUrl, string id = null, NuGet.SemanticVersion version = null) { if (!NetworkInterface.GetIsNetworkAvailable()) { UIServices.Show( StringResources.NoNetworkConnection, MessageLevel.Warning); return; } Uri downloadUrl; if (Uri.TryCreate(packageUrl, UriKind.Absolute, out downloadUrl) && downloadUrl.IsRemoteUri()) { IPackage downloadedPackage = await PackageDownloader.Download(downloadUrl, id, version.ToString()); if (downloadedPackage != null) { LoadPackage(downloadedPackage, packageUrl, PackageType.DataServicePackage); } } else { UIServices.Show( String.Format( CultureInfo.CurrentCulture, StringResources.Dialog_InvalidPackageUrl, packageUrl), MessageLevel.Error ); } }
public PackageInfo?SelectPackage(string?searchTerm) { if (_viewModel == null) { _viewModel = ViewModelFactory.CreatePackageChooserViewModel(null); _viewModel.PackageDownloadRequested += OnPackageDownloadRequested; } var dialog = new PackageChooserDialog(SettingsManager, _viewModel) { Owner = Window.Value }; ReCenterPackageChooserDialog(dialog); try { dialog.ShowDialog(searchTerm); } catch (ArgumentException e) { UIServices.Show(e.Message, MessageLevel.Error); } return(_viewModel.SelectedPackage); }
internal async Task DownloadAndOpenDataServicePackage(string packageUrl, string id = null, NuGetVersion version = null) { if (!NetworkInterface.GetIsNetworkAvailable()) { UIServices.Show( StringResources.NoNetworkConnection, MessageLevel.Warning); return; } if (id != null && version != null && Uri.TryCreate(packageUrl, UriKind.Absolute, out var downloadUrl)) { var repository = PackageRepositoryFactory.CreateRepository(packageUrl); var packageIdentity = new NuGet.Packaging.Core.PackageIdentity(id, version); var downloadedPackage = await PackageDownloader.Download(repository, packageIdentity); if (downloadedPackage != null) { LoadPackage(downloadedPackage, packageUrl, PackageType.RemotePackage); } } else { UIServices.Show( string.Format( CultureInfo.CurrentCulture, StringResources.Dialog_InvalidPackageUrl, packageUrl), MessageLevel.Error ); } }
private void SelectDependencyButtonClicked(object sender, System.Windows.RoutedEventArgs e) { if (!NetworkInterface.GetIsNetworkAvailable()) { UIServices.Show( PackageExplorer.Resources.Resources.NoNetworkConnection, MessageLevel.Warning); return; } var dialog = new PackageChooserDialog() { Owner = Window.GetWindow(this), DataContext = PackageViewModelFactory.CreatePackageChooserViewModel() }; var result = dialog.ShowDialog(); if (result ?? false) { var selectedPackage = dialog.SelectedPackage; if (selectedPackage != null) { _newPackageDependency.Id = selectedPackage.Id; _newPackageDependency.VersionSpec = VersionUtility.ParseVersionSpec(selectedPackage.Version.ToString()); } } }
private void OpenPackageFromNuGetFeed() { if (!NetworkInterface.GetIsNetworkAvailable()) { UIServices.Show( PackageExplorer.Resources.Resources.NoNetworkConnection, MessageLevel.Warning); return; } bool canceled = AskToSaveCurrentFile(); if (canceled) { return; } var dialog = new PackageChooserDialog() { Owner = this, DataContext = _packageViewModelFactory.CreatePackageChooserViewModel() }; bool?result = dialog.ShowDialog(); if (result ?? false) { PackageInfo selectedPackage = dialog.SelectedPackage; if (selectedPackage != null) { Version packageVersion = new Version(selectedPackage.Version); IPackage cachePackage = MachineCache.Default.FindPackage(selectedPackage.Id, packageVersion);; if (cachePackage == null || cachePackage.GetHash() != selectedPackage.PackageHash) { // if not in the cache, or if the cache package's hash is different from the feed hash, (re)download it var progressWindow = new DownloadProgressWindow( selectedPackage.DownloadUrl, selectedPackage.Id, packageVersion) { Owner = this }; result = progressWindow.ShowDialog(); if (result ?? false) { cachePackage = progressWindow.DownloadedPackage; } } if (cachePackage != null) { DataServicePackage servicePackage = selectedPackage.AsDataServicePackage(); servicePackage.CorePackage = cachePackage; LoadPackage(servicePackage, selectedPackage.DownloadUrl.ToString(), PackageType.DataServicePackage); } } } }
private bool OpenLocalPackageCore(string packagePath) { IPackage?package = null; string?tempFile = null; try { tempFile = Path.GetTempFileName(); File.Copy(packagePath, tempFile, overwrite: true); var extension = Path.GetExtension(packagePath); if (Constants.PackageExtension.Equals(extension, StringComparison.OrdinalIgnoreCase) || Constants.SymbolPackageExtension.Equals(extension, StringComparison.OrdinalIgnoreCase)) { DiagnosticsClient.TrackPageView("View Existing Package"); #pragma warning disable CA2000 // Dispose objects before losing scope package = new ZipPackage(tempFile); #pragma warning restore CA2000 // Dispose objects before losing scope } else if (Constants.ManifestExtension.Equals(extension, StringComparison.OrdinalIgnoreCase)) { DiagnosticsClient.TrackPageView("View Nuspec"); using var str = ManifestUtility.ReadManifest(tempFile); var builder = new PackageBuilder(str, Path.GetDirectoryName(packagePath)); package = builder.Build(); } if (package != null) { LoadPackage(package, packagePath, packagePath, PackageType.LocalPackage); _tempFile = tempFile; return(true); } } catch (Exception ex) { package?.Dispose(); package = null; UIServices.Show(ex.Message, MessageLevel.Error); return(false); } finally { if (package == null && tempFile != null && File.Exists(tempFile)) { try { File.Delete(tempFile); } catch { /* ignore */ } } } return(false); }
internal void OpenLocalPackage(string packagePath) { if (!File.Exists(packagePath)) { UIServices.Show("File not found at " + packagePath, MessageLevel.Error); return; } PackageSourceItem.SetCurrentValue(ContentControl.ContentProperty, "Loading " + packagePath + "..."); Dispatcher.BeginInvoke(new Action <string>(OpenLocalPackageCore), DispatcherPriority.Loaded, packagePath); }
private bool OpenLocalPackageCore(string packagePath) { IPackage package = null; string tempFile = null; try { tempFile = Path.GetTempFileName(); File.Copy(packagePath, tempFile, overwrite: true); var extension = Path.GetExtension(packagePath); if (extension.Equals(Constants.PackageExtension, StringComparison.OrdinalIgnoreCase) || extension.Equals(Constants.SymbolPackageExtension, StringComparison.OrdinalIgnoreCase)) { package = new ZipPackage(tempFile); } else if (extension.Equals(Constants.ManifestExtension, StringComparison.OrdinalIgnoreCase)) { using (var str = ManifestUtility.ReadManifest(tempFile)) { var builder = new PackageBuilder(str, Path.GetDirectoryName(packagePath)); package = builder.Build(); } } if (package != null) { LoadPackage(package, packagePath, PackageType.LocalPackage); _tempFile = tempFile; return(true); } } catch (Exception ex) { package = null; UIServices.Show(ex.Message, MessageLevel.Error); return(false); } finally { if (package == null && tempFile != null && File.Exists(tempFile)) { try { File.Delete(tempFile); } catch { /* ignore */ } } } return(false); }
private void ViewDownloadCache_Click(object sender, EventArgs args) { string cacheSource = MachineCache.Default.Source; if (Directory.Exists(cacheSource)) { Process.Start(cacheSource); } else { UIServices.Show("The NuGet download cache does not exist.", MessageLevel.Information); } }
private void ClearDownloadCache_Click(object sender, EventArgs args) { bool result = MachineCache.Default.Clear(); if (result) { UIServices.Show("The NuGet download cache has been cleared successfully.", MessageLevel.Information); } else { UIServices.Show("The NuGet download cache does not exist.", MessageLevel.Information); } }
private void ClearDownloadCache_Click(object sender, EventArgs args) { DiagnosticsClient.TrackEvent("MainWindow_ClearDownloadCache"); var result = MachineCache.Default.Clear(); if (result) { UIServices.Show("The NuGet download cache has been cleared successfully.", MessageLevel.Information); } else { UIServices.Show("The NuGet download cache does not exist.", MessageLevel.Information); } }
private async void OnPackageDownloadRequested(object sender, EventArgs e) { DiagnosticsClient.TrackEvent("PackageChooserService_OnPackageDownloadRequested"); var vm = (PackageChooserViewModel)sender; var repository = vm.ActiveRepository; var packageInfo = vm.SelectedPackage; if (packageInfo != null && repository != null) { var packageName = packageInfo.Id + "." + packageInfo.Version + NuGetPe.Constants.PackageExtension; var title = "Save " + packageName; const string filter = "NuGet package file (*.nupkg)|*.nupkg|NuGet Symbols package file (*.snupkg)|*.snupkg|All files (*.*)|*.*"; var accepted = UIServices.OpenSaveFileDialog( title, packageName, null, filter, overwritePrompt: true, selectedFilePath: out var selectedFilePath, selectedFilterIndex: out var selectedIndex); if (accepted) { if (selectedIndex == 1 && !selectedFilePath.EndsWith(NuGetPe.Constants.PackageExtension, StringComparison.OrdinalIgnoreCase)) { selectedFilePath += NuGetPe.Constants.PackageExtension; } else if (selectedIndex == 2 && !selectedFilePath.EndsWith(NuGetPe.Constants.SymbolPackageExtension, StringComparison.OrdinalIgnoreCase)) { selectedFilePath += NuGetPe.Constants.SymbolPackageExtension; } try { await PackageDownloader.Download(selectedFilePath, repository, packageInfo.Identity); } catch (Exception ex) { UIServices.Show(ex.Message, MessageLevel.Error); } } } }
private async void LoadPackage(IPackage package, string packagePath, string packageSource, PackageType packageType) { DisposeViewModel(); if (package != null) { if (!HasLoadedContent <PackageViewer>()) { var packageViewer = new PackageViewer(SettingsManager, UIServices, PackageChooser); var binding = new Binding { Converter = new NullToVisibilityConverter(), FallbackValue = Visibility.Collapsed }; packageViewer.SetBinding(VisibilityProperty, binding); MainContentContainer.Children.Add(packageViewer); #if !HAS_UNO // HACK HACK: set the Export of IPackageMetadataEditor here EditorService = packageViewer.PackageMetadataEditor; #endif } try { var packageViewModel = await PackageViewModelFactory.CreateViewModel(package, packagePath, packageSource); packageViewModel.PropertyChanged += OnPackageViewModelPropertyChanged; DataContext = packageViewModel; if (!string.IsNullOrEmpty(packageSource)) { _mruManager.NotifyFileAdded(package, packageSource, packageType); } } catch (Exception e) { if (!(e is ArgumentException)) { DiagnosticsClient.TrackException(e); } Console.WriteLine(e); UIServices.Show($"Error loading package\n{e.Message}", MessageLevel.Error); } } }
private void OnReportProgress(int percent, string description) { if (_progressDialog != null) { // report progress must be done via UI thread UIServices.BeginInvoke(() => { lock (_progressDialogLock) { if (_progressDialog != null) { _progressDialog.ReportProgress(percent, null, description); } } }); } }
private void ViewDownloadCache_Click(object sender, EventArgs args) { var cacheSource = MachineCache.Default.Source; if (Directory.Exists(cacheSource)) { try { Process.Start(cacheSource); } catch // Possible Win32 exception, nothing we can do { } } else { UIServices.Show("The NuGet download cache does not exist.", MessageLevel.Information); } }
private void OpenPackageFromLocal() { bool canceled = AskToSaveCurrentFile(); if (canceled) { return; } string selectedFile; bool result = UIServices.OpenFileDialog( "Select File", StringResources.Dialog_OpenFileFilter, out selectedFile); if (result) { OpenLocalPackage(selectedFile); } }
internal async Task OpenLocalPackage(string packagePath) { if (!File.Exists(packagePath)) { UIServices.Show("File not found at " + packagePath, MessageLevel.Error); return; } object oldContent = PackageSourceItem.Content; PackageSourceItem.SetCurrentValue(ContentProperty, "Loading " + packagePath + "..."); bool succeeded = await Dispatcher.InvokeAsync( () => OpenLocalPackageCore(packagePath), DispatcherPriority.Loaded); if (!succeeded) { // restore old content PackageSourceItem.SetCurrentValue(ContentProperty, oldContent); } }
/// <summary> /// Asks user to save the current file before doing something (e.g. exit, open a new file) /// </summary> /// <returns>true if user cancels the impending action</returns> private bool AskToSaveCurrentFile() { if (HasUnsavedChanges) { // if there is unsaved changes, ask user for confirmation var result = UIServices.ConfirmWithCancel(StringResources.Dialog_SaveQuestion); if (result == null) { return(true); } if (result == true) { var saveCommand = SaveMenuItem.Command; const string parameter = "ForceSave"; saveCommand.Execute(parameter); } } return(false); }
private Task OpenPackageFromLocal() { var canceled = AskToSaveCurrentFile(); if (canceled) { return(Task.FromResult(0)); } var result = UIServices.OpenFileDialog( "Select File", StringResources.Dialog_OpenFileFilter, out var selectedFile); if (result) { return(OpenLocalPackage(selectedFile)); } return(Task.FromResult(0)); }
private async void LoadPackage(IPackage package, string packagePath, PackageType packageType) { DisposeViewModel(); if (package != null) { if (!HasLoadedContent <PackageViewer>()) { var packageViewer = new PackageViewer(UIServices, PackageChooser); var binding = new Binding { Converter = new NullToVisibilityConverter(), FallbackValue = Visibility.Collapsed }; packageViewer.SetBinding(VisibilityProperty, binding); MainContentContainer.Children.Add(packageViewer); // HACK HACK: set the Export of IPackageMetadataEditor here EditorService = packageViewer.PackageMetadataEditor; } try { PackageViewModel packageViewModel = await PackageViewModelFactory.CreateViewModel(package, packagePath); packageViewModel.PropertyChanged += OnPackageViewModelPropertyChanged; DataContext = packageViewModel; if (!String.IsNullOrEmpty(packagePath)) { _mruManager.NotifyFileAdded(package, packagePath, packageType); } } catch (Exception e) { UIServices.Show($"Error loading package\n{e.Message}", MessageLevel.Error); } } }
internal async Task OpenLocalPackage(string packagePath) { DiagnosticsClient.TrackEvent("MainWindow_OpenLocalPackage"); if (!File.Exists(packagePath)) { UIServices.Show("File not found at " + packagePath, MessageLevel.Error); return; } //var oldContent = PackageSourceItem.Content; //PackageSourceItem.SetCurrentValue(ContentProperty, "Loading " + packagePath + "..."); await Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => OpenLocalPackageCore(packagePath)); //if (!succeeded) //{ // // restore old content // PackageSourceItem.SetCurrentValue(ContentProperty, oldContent); //} }
private void OnError(Exception error) { UIServices.Show((error.InnerException ?? error).Message, MessageLevel.Error); }