private void ViewLicense_Click(object sender, RoutedEventArgs e)
        {
            if (DataContext is DetailedPackageMetadata metadata)
            {
                var window = new LicenseFileWindow()
                {
                    DataContext = new LicenseFileData
                    {
                        LicenseHeader = string.Format(CultureInfo.CurrentCulture, UI.Resources.WindowTitle_LicenseFileWindow, metadata.Id),
                        LicenseText   = new FlowDocument(new Paragraph(new Run(UI.Resources.LicenseFile_Loading)))
                    }
                };

                NuGetUIThreadHelper.JoinableTaskFactory.RunAsync(async() =>
                {
                    string content = await PackageLicenseUtilities.GetEmbeddedLicenseAsync(new Packaging.Core.PackageIdentity(metadata.Id, metadata.Version), CancellationToken.None);

                    var flowDoc = new FlowDocument();
                    flowDoc.Blocks.AddRange(PackageLicenseUtilities.GenerateParagraphs(content));
                    await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                    (window.DataContext as LicenseFileData).LicenseText = flowDoc;
                }).PostOnFailure(nameof(PackageMetadataControl), nameof(ViewLicense_Click));

                using (NuGetEventTrigger.TriggerEventBeginEnd(
                           NuGetEvent.EmbeddedLicenseWindowBegin,
                           NuGetEvent.EmbeddedLicenseWindowEnd))
                {
                    window.ShowModal();
                }
            }
        }
Example #2
0
        private void ViewLicense_Click(object sender, RoutedEventArgs e)
        {
            if (sender is Hyperlink hyperlink)
            {
                if (hyperlink.DataContext is LicenseFileText licenseFile)
                {
                    var window = new LicenseFileWindow()
                    {
                        DataContext = licenseFile
                    };

                    NuGetUIThreadHelper.JoinableTaskFactory.RunAsync(
                        () => { return(licenseFile.LoadLicenseFileAsync()); }
                        ).PostOnFailure(nameof(LicenseAcceptanceWindow), nameof(ViewLicense_Click));

                    window.ShowModal();
                }
            }
        }
Example #3
0
        private void ViewLicense_Click(object sender, RoutedEventArgs e)
        {
            if (sender is Hyperlink hyperlink)
            {
                if (hyperlink.DataContext is LicenseFileText licenseFile)
                {
                    var window = new LicenseFileWindow()
                    {
                        DataContext = licenseFile
                    };

                    licenseFile.LoadLicenseFile();

                    using (NuGetEventTrigger.TriggerEventBeginEnd(
                               NuGetEvent.EmbeddedLicenseWindowBegin,
                               NuGetEvent.EmbeddedLicenseWindowEnd))
                    {
                        window.ShowModal();
                    }
                }
            }
        }