Beispiel #1
0
        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 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);
                    }
                }
            }
        }