Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,5 @@ MigrationBackup/

**/coveragereport/**/**
src/**/coverage.json

src/scripts/nuget/**
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

[![Blazor](https://img.shields.io/badge/blazor-5C2D91.svg?style=for-the-badge&logo=blazor&logoColor=white)](https://dotnet.microsoft.com/en-us/apps/aspnet/web-apps/blazor)
[![C#](https://img.shields.io/badge/c%23-239120.svg?style=for-the-badge&logo=c-sharp&logoColor=white)](https://learn.microsoft.com/en-us/dotnet/csharp/)

<!-- [![VB.NET](https://img.shields.io/badge/VB.NET-512BD4.svg?style=for-the-badge&logo=visualbasic&logoColor=white)](https://learn.microsoft.com/en-us/dotnet/csharp/) -->
<!-- [![F#](https://img.shields.io/badge/F%23-3498DB?style=for-the-badge&logo=f-sharp&logoColor=white)](https://fsharp.org) -->

[![License: MIT](https://img.shields.io/badge/License-MIT-lightgrey.svg?style=for-the-badge)](LICENSE) <!-- https://opensource.org/licenses/MIT -->

[![Build / Test (with Reports)](https://github.com/alex-hedley/BlazorInteractive/actions/workflows/build-test.yml/badge.svg)](https://github.com/alex-hedley/BlazorInteractive/actions/workflows/build-test.yml)
Expand All @@ -14,6 +16,7 @@

[![BlazorInteractive Tests](https://gist.githubusercontent.com/alex-hedley/0f6142396b2a1bb0231906adcd51bdcd/raw/0365da5b9d3b05984b8099051b6f5582eff2878b/blazor_interactive_tests.md_badge.svg "BlazorInteractive Tests")](https://gist.github.com/alex-hedley/0f6142396b2a1bb0231906adcd51bdcd)
[![BlazorInteractive Compilation Tests](https://gist.githubusercontent.com/alex-hedley/1a73c5dd2824cc80bfd2c145308dbcf9/raw/c0c284fcc207940aa665cd816a991d92bf94df26/blazor_interactive_compilation_tests.md_badge.svg "BlazorInteractive Compilation Tests")](https://gist.github.com/alex-hedley/1a73c5dd2824cc80bfd2c145308dbcf9)

<!-- [![BlazorInteractive Dependency Management Tests](https://gist.githubusercontent.com/alex-hedley/###/raw/###/blazor_interactive_compilation_tests.md_badge.svg "BlazorInteractive Dependency Management Tests")](https://gist.github.com/alex-hedley/###) -->

## Demo
Expand All @@ -29,6 +32,7 @@
| BlazorInteractive | BlazorWebAssembly | |
| BlazorInteractive.Compilation | | |
| BlazorInteractive.Compilation.Tests | | |
| BlazorInteractive.ConsoleApp | Microsoft.NET.Sdk | |
| BlazorInteractive.DependencyManagement | | |
| BlazorInteractive.DependencyManagement.Tests | | |
| BlazorInteractive.Tests | | |
Expand Down
12 changes: 11 additions & 1 deletion docs/NUGET.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,14 @@ info : OK https://api.nuget.org/v3-flatcontainer/mono.unix/index.json 166ms
info : GET https://api.nuget.org/v3-flatcontainer/mono.unix/7.1.0-final.1.21458.1/mono.unix.7.1.0-final.1.21458.1.nupkg
info : OK https://api.nuget.org/v3-flatcontainer/dynamiclanguageruntime/1.3.4/dynamiclanguageruntime.1.3.4.nupkg 86ms
info : OK https://api.nuget.org/v3-flatcontainer/mono.unix/7.1.0-final.1.21458.1/mono.unix.7.1.0-final.1.21458.1.nupkg 92ms
```
```

## Testing in Blazor WASM project

[Log] https://api.nuget.org/v3-flatcontainer/ironpython/index.json
[Log] Extracted IronPython.nuspec
[Log] Extracted lib/net6.0/IronPython.dll
[Log] Extracted lib/net6.0/IronPython.Modules.dll
[Log] Extracted lib/net6.0/IronPython.SQLite.dll
[Log] Extracted lib/net6.0/IronPython.Wpf.dll
[Log] Success
2 changes: 1 addition & 1 deletion docs/TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dotnet tool install coverlet.console -g -a arm64

Run this from the `src` directory:

`coverlet BlazorInteractive.Compilation.Tests/bin/Debug/net7.0/BlazorInteractive.Compilation.dll --target "dotnet" --targetargs "test --no-build"`
`coverlet BlazorInteractive.Compilation.Tests/bin/Debug/net8.0/BlazorInteractive.Compilation.dll --target "dotnet" --targetargs "test --no-build"`

## AltCover

Expand Down
23 changes: 23 additions & 0 deletions src/.run/BlazorInteractive.ConsoleApp.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="BlazorInteractive.ConsoleApp" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/BlazorInteractive.ConsoleApp/bin/Debug/net8.0/BlazorInteractive.ConsoleApp" />
<option name="PROGRAM_PARAMETERS" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/BlazorInteractive.ConsoleApp/bin/Debug/net8.0" />
<option name="PASS_PARENT_ENVS" value="1" />
<envs>
<env name="DOTNET_EnableAVX" value="0" />
</envs>
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="PROJECT_PATH" value="$PROJECT_DIR$/BlazorInteractive.ConsoleApp/BlazorInteractive.ConsoleApp.csproj" />
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
<option name="PROJECT_KIND" value="DotNetCore" />
<option name="PROJECT_TFM" value="net8.0" />
<method v="2">
<option name="Build" />
</method>
</configuration>
</component>
17 changes: 17 additions & 0 deletions src/.run/BlazorInteractive_ http.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="BlazorInteractive: http" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BlazorInteractive/BlazorInteractive.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net8.0" />
<option name="LAUNCH_PROFILE_NAME" value="http" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
</component>
17 changes: 17 additions & 0 deletions src/.run/BlazorInteractive_ https.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="BlazorInteractive: https" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/BlazorInteractive/BlazorInteractive.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net8.0" />
<option name="LAUNCH_PROFILE_NAME" value="https" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
</component>
3 changes: 2 additions & 1 deletion src/BlazorInteractive.Compilation/AssemblyLoader.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.Reflection;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Logging;
using BlazorInteractive.Compilation;
using BlazorInteractive.Compilation.Results;
using AssemblyLoaderResult = BlazorInteractive.Compilation.Results.AssemblyLoaderResult;

namespace BlazorInteractive.Compilation;

public class AssemblyLoader : IAssemblyLoader
{
private readonly ILogger _logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\BlazorInteractive.DependencyManagement\BlazorInteractive.DependencyManagement.csproj" />
</ItemGroup>

</Project>
26 changes: 26 additions & 0 deletions src/BlazorInteractive.ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using BlazorInteractive.DependencyManagement;
using Microsoft.Extensions.Logging;
using OneOf.Types;

namespace BlazorInteractive.ConsoleApp;

class Program
{
private static readonly ILogger<NuGetPackageGetter> _logger;

async static Task Main(string[] args)
{
var nugetPackageGetter = new NuGetPackageGetter(_logger);
var package = await nugetPackageGetter.GetPackage("ironpython");
package.Switch(
success =>
{
Console.WriteLine("Success");
},
failure =>
{
Console.WriteLine("Failure");
}
);
}
}
86 changes: 84 additions & 2 deletions src/BlazorInteractive.DependencyManagement/NuGetPackageGetter.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,100 @@
using Microsoft.Extensions.Logging;
using System.IO.Compression;
using System.Text.Json;
using System.Text.Json.Serialization;
using OneOf.Types;

namespace BlazorInteractive.DependencyManagement;

public class NuGetPackageGetter : IPackageGetter
{
private readonly ILogger _logger;

record IndexResource([property:JsonPropertyName("@Id")] string Id, [property:JsonPropertyName("@Type")] string Type, string Comment);
record IndexResponse(string Version, List<IndexResource> Resources);
record PackageVersions(List<string> Versions);

public NuGetPackageGetter(ILogger<NuGetPackageGetter> logger)
{
_logger = logger;
}

public Task<PackageResult> GetPackage(string name)
public async Task<PackageResult> GetPackage(string name)
{
throw new NotImplementedException();
Directory.CreateDirectory("nuget");

var nugetIndexResponse = await GetAndCache<IndexResponse>("https://api.nuget.org/v3/index.json", "nuget/index.json");
var packageVersionsBaseUrl = nugetIndexResponse.Resources.First(resource => resource.Type == "PackageBaseAddress/3.0.0").Id;

var testUrl = $"{packageVersionsBaseUrl}{name}/index.json";
Console.WriteLine(testUrl);
var versionsResponse = await GetAndCache<PackageVersions>($"{packageVersionsBaseUrl}{name}/index.json", $"nuget/{name}versions.json");
var latestVersion = versionsResponse.Versions.Last();

// https://github.com/dotnet/runtime/issues/78991
// DOTNET_EnableAVX=0
var packageUrl = $"{packageVersionsBaseUrl}{name}/{latestVersion}/{name}.{latestVersion}.nupkg";
// var packageUrl = $"{packageVersionsBaseUrl.ToString()}{name.ToString()}/{latestVersion.ToString()}/{name.ToString()}.{latestVersion.ToString()}.nupkg";

if (!File.Exists($"nuget/{name}.{latestVersion}.nupkg"))
{
using (var localFile = File.OpenWrite($"nuget/{name}.{latestVersion}.nupkg"))
{
var packageZip = await client.GetStreamAsync(packageUrl);
await packageZip.CopyToAsync(localFile);
}
}

var extractDir = $"nuget/{name}.{latestVersion}";
if (!Directory.Exists(extractDir))
{
Directory.CreateDirectory(extractDir);
}

using (var zip = ZipFile.OpenRead($"nuget/{name}.{latestVersion}.nupkg"))
{
foreach (var file in zip.Entries)
{
var target = $"{extractDir}/{file.Name}";
if (File.Exists(target))
{
continue;
}

// Check folders

if (file.Name.EndsWith(".dll") && file.FullName.Contains("net6"))
{
file.ExtractToFile(target);
Console.WriteLine($"Extracted {file.FullName}");
// Console.WriteLine($"{Path.GetFullPath(file.Name)}");
}
else if (file.Name.EndsWith("nuspec"))
{
file.ExtractToFile(target);
Console.WriteLine($"Extracted {file.FullName}");
}
}
}

return new PackageResult(new Success());
}

HttpClient client = new();

async Task<T> GetAndCache<T>(string url, string file)
{
string json;
if (!File.Exists(file))
{
json = await client.GetStringAsync(url);
await File.WriteAllTextAsync(file, json);
}
else
{
json = await File.ReadAllTextAsync(file);
}

return JsonSerializer.Deserialize<T>(json, new JsonSerializerOptions {PropertyNameCaseInsensitive = true});
}
}
6 changes: 6 additions & 0 deletions src/BlazorInteractive.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorInteractive.Dependenc
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorInteractive.DependencyManagement.Tests", "BlazorInteractive.DependencyManagement.Tests\BlazorInteractive.DependencyManagement.Tests.csproj", "{D9397485-D136-4BBB-9B47-80D3AE8AAC69}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorInteractive.ConsoleApp", "BlazorInteractive.ConsoleApp\BlazorInteractive.ConsoleApp.csproj", "{5F3F79DB-B425-484E-85F1-5D9F016CF3DC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -43,5 +45,9 @@ Global
{D9397485-D136-4BBB-9B47-80D3AE8AAC69}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9397485-D136-4BBB-9B47-80D3AE8AAC69}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9397485-D136-4BBB-9B47-80D3AE8AAC69}.Release|Any CPU.Build.0 = Release|Any CPU
{5F3F79DB-B425-484E-85F1-5D9F016CF3DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5F3F79DB-B425-484E-85F1-5D9F016CF3DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F3F79DB-B425-484E-85F1-5D9F016CF3DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F3F79DB-B425-484E-85F1-5D9F016CF3DC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions src/BlazorInteractive/BlazorInteractive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

<ItemGroup>
<ProjectReference Include="..\BlazorInteractive.Compilation\BlazorInteractive.Compilation.csproj" />
<ProjectReference Include="..\BlazorInteractive.DependencyManagement\BlazorInteractive.DependencyManagement.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
SelectedValues="@SelectedIds"
DisabledValues="@DisabledIds"
Style="@Style"
/>
/>
<NuGetComponent Data="@(null)"
/>
</div>
<div class="col-md-8">
<StandaloneCodeEditor
Expand Down
53 changes: 53 additions & 0 deletions src/BlazorInteractive/Components/Editor/NuGetComponent.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
@inject IPackageGetter NuGetPackageGetter
@inject IToastService ToastService

<div class="input-group mb-3">
<div class="input-group-prepend">
<img src="https://raw.githubusercontent.com/NuGet/Media/main/Images/MainLogo/Vector/nuget.svg"
alt="NuGet logo" height="25px" />
</div>
<input type="text" class="form-control" placeholder="Search Term" aria-label="Search Term" @bind="SearchTerm" @bind:event="oninput"/>
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" @onclick="GetPackage">Add</button>
</div>
</div>

<div>
@if (Data != null)
{
foreach (var item in Data.Where(i => i is not null))
{
<label class="form-check-label" for="@($"{item}")">
@($"{item}")
</label>
}
}
</div>

@code {
//[Parameter]
string? SearchTerm { get; set; }

[Parameter]
public List<string> Data { get; set; } = new List<string>();

private async void GetPackage()
{
var package = await NuGetPackageGetter.GetPackage(SearchTerm);
package.Switch(
success =>
{
Console.WriteLine("Success");
ToastService.ShowSuccess("Added NuGet Package");
Data.Add(SearchTerm);
},
failure =>
{
Console.WriteLine("Failure");
ToastService.ShowError("Failed to add");
}
);
StateHasChanged();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
img {
margin-right: 10px;
}
2 changes: 2 additions & 0 deletions src/BlazorInteractive/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using BlazorInteractive;
using BlazorInteractive.AssemblyCompilation;
using BlazorInteractive.Compilation;
using BlazorInteractive.DependencyManagement;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
Expand All @@ -16,6 +17,7 @@
builder.Services.AddScoped<IAssemblyInvoker, AssemblyInvoker>();
builder.Services.AddScoped<IAssemblyLoader, AssemblyLoader>();
builder.Services.AddScoped<ICSharpCompiler, CSharpCompiler>();
builder.Services.AddScoped<IPackageGetter, NuGetPackageGetter>();
builder.Services.AddBlazoredToast();

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
Expand Down
Loading