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();
                }
            }
        }
 private PackageLicenseInfo GeneratePackageLicenseInfo(IPackageSearchMetadata metadata)
 {
     return(new PackageLicenseInfo(
                metadata.Identity.Id,
                PackageLicenseUtilities.GenerateLicenseLinks(metadata),
                metadata.Authors));
 }
示例#3
0
        internal async Task LoadLicenseFileAsync()
        {
            if (Interlocked.CompareExchange(ref _initialized, 1, 0) == 0)
            {
                if (_packagePath != null)
                {
                    string content = await PackageLicenseUtilities.GetEmbeddedLicenseAsync(PackageIdentity, CancellationToken.None);

                    var flowDoc = new FlowDocument();
                    flowDoc.Blocks.AddRange(PackageLicenseUtilities.GenerateParagraphs(content));
                    await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                    LicenseText = flowDoc;
                }
            }
        }
示例#4
0
 internal void LoadLicenseFile()
 {
     if (Interlocked.CompareExchange(ref _initialized, 1, 0) == 0)
     {
         if (_loadFileFromPackage != null)
         {
             NuGetUIThreadHelper.JoinableTaskFactory.RunAsync(async() =>
             {
                 var content = _loadFileFromPackage(_licenseFileLocation);
                 var flowDoc = new FlowDocument();
                 flowDoc.Blocks.AddRange(PackageLicenseUtilities.GenerateParagraphs(content));
                 await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                 LicenseText = flowDoc;
             });
         }
     }
 }