Skip to content

Commit

Permalink
Migrate Redpoint.CloudFramework to UET mono-repo
Browse files Browse the repository at this point in the history
We're not using this yet in UET.
  • Loading branch information
hach-que committed Jan 5, 2025
1 parent d9bdeac commit bfdc7e0
Show file tree
Hide file tree
Showing 349 changed files with 32,271 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/uet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ jobs:
exit $LastExitCode
}
foreach ($Item in (Get-ChildItem UET -Filter *.Tests)) {
if (Test-Path "$($Item.FullName)/$($Item.Name).csproj") {
if ((Test-Path "$($Item.FullName)/$($Item.Name).csproj") -and ($Item.Name -ne "Redpoint.CloudFramework.Tests")) {
Write-Host "============ STARTING: $($Item.Name) ============"
dotnet test --logger:"console" --logger:"trx;LogFileName=$($Item.Name).test-result.trx" --results-directory "$((Get-Location).Path)\TestResults" "$($Item.FullName)/bin/Release/${{ env.UET_FRAMEWORK_TARGET }}/$($Item.Name).dll"
if ($LastExitCode -ne 0) {
Expand Down
8 changes: 8 additions & 0 deletions UET/Lib/Framework.AspNetCore.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>

<!-- This must remain in sync with Framework.Build.props. -->
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="8.0.0" Condition="'$(TargetFramework)' == 'net8.0'" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

using Microsoft.AspNetCore.Hosting;
using React.Exceptions;

namespace React.AspNet
{
/// <summary>
/// Handles file system functionality, such as reading files. Maps all paths from
/// application-relative (~/...) to full paths using ASP.NET's MapPath method.
/// </summary>
public class AspNetFileSystem : FileSystemBase
{
private readonly IWebHostEnvironment _hostingEnv;

/// <summary>
/// Initializes a new instance of the <see cref="AspNetFileSystem"/> class.
/// </summary>
/// <param name="hostingEnv">The .NET Core hosting environment</param>
public AspNetFileSystem(IWebHostEnvironment hostingEnv)
{
_hostingEnv = hostingEnv;
}

/// <summary>
/// Converts a path from an application relative path (~/...) to a full filesystem path
/// </summary>
/// <param name="relativePath">App-relative path of the file</param>
/// <returns>Full path of the file</returns>
public override string MapPath(string relativePath)
{
if (_hostingEnv.WebRootPath == null)
{
throw new ReactException("WebRootPath was null, has the wwwroot folder been deployed along with your app?");
}

if (relativePath.StartsWith(_hostingEnv.WebRootPath))
{
return relativePath;
}
relativePath = relativePath.TrimStart('~').TrimStart('/').TrimStart('\\');

return Path.GetFullPath(Path.Combine(_hostingEnv.WebRootPath, relativePath));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
using Microsoft.Extensions.Caching.Memory;
using Microsoft.AspNetCore.Hosting;

namespace React.AspNet
{
/// <summary>
/// Memory cache implementation for React.ICache. Uses IMemoryCache from .NET Core.
/// </summary>
public class MemoryFileCacheCore : ICache
{
private readonly IMemoryCache _cache;
private readonly IWebHostEnvironment _hostingEnv;

/// <summary>
/// Initializes a new instance of the <see cref="MemoryFileCacheCore" /> class.
/// </summary>
/// <param name="cache">The cache to use</param>
/// <param name="hostingEnv">The ASP.NET hosting environment.</param>
public MemoryFileCacheCore(IMemoryCache cache, IWebHostEnvironment hostingEnv)
{
_cache = cache;
_hostingEnv = hostingEnv;
}

/// <summary>
/// Get an item from the cache. Returns <paramref name="fallback"/> if the item does
/// not exist.
/// </summary>
/// <typeparam name="T">Type of data</typeparam>
/// <param name="key">The cache key</param>
/// <param name="fallback">Value to return if item is not in the cache</param>
/// <returns>Data from cache, otherwise <paramref name="fallback"/></returns>
public T Get<T>(string key, T fallback = default(T))
{
return (T)(_cache.Get(key) ?? fallback);
}

/// <summary>
/// Sets an item in the cache.
/// </summary>
/// <typeparam name="T">Type of data</typeparam>
/// <param name="key">The cache key</param>
/// <param name="data">Data to cache</param>
/// <param name="slidingExpiration">
/// Sliding expiration, if cache key is not accessed in this time period it will
/// automatically be removed from the cache
/// </param>
/// <param name="cacheDependencyFiles">
/// Filenames this cached item is dependent on. If any of these files change, the cache
/// will be cleared automatically
/// </param>
public void Set<T>(string key, T data, TimeSpan slidingExpiration, IEnumerable<string> cacheDependencyFiles = null)
{
if (data == null)
{
_cache.Remove(key);
return;
}

var options = new MemoryCacheEntryOptions
{
SlidingExpiration = slidingExpiration,
};

if (cacheDependencyFiles != null)
{
foreach (var file in cacheDependencyFiles)
{
var relativePath = file.Replace(_hostingEnv.WebRootPath, string.Empty).TrimStart('\\', '/');
options.AddExpirationToken(_hostingEnv.WebRootFileProvider.Watch(relativePath));
}
}

_cache.Set(key, data, options);
}
}
}
5 changes: 5 additions & 0 deletions UET/Lib/Redpoint.ThirdParty.React.AspNet.Middleware/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Redpoint.ThirdParty.React.AspNet

This is a fork of React.NET (https://github.com/reactjs/react.net) that adds support for React v18.

If you want to use this fork in an ASP.NET Core project, use the `Redpoint.ThirdParty.React.AspNet` package.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace React.AspNet
{
/// <summary>
/// Handles registering ReactJS.NET middleware in an ASP.NET <see cref="IApplicationBuilder"/>.
/// </summary>
public static class ReactBuilderExtensions
{
/// <summary>
/// Initialises ReactJS.NET for this application
/// </summary>
/// <param name="app">ASP.NET application builder</param>
/// <param name="configure">ReactJS.NET configuration</param>
/// <returns>The application builder (for chaining)</returns>
public static IApplicationBuilder UseReact(
this IApplicationBuilder app,
Action<IReactSiteConfiguration> configure
)
{
// Apply configuration.
configure(app.ApplicationServices.GetRequiredService<IReactSiteConfiguration>());

return app;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

using JavaScriptEngineSwitcher.Core;
using Microsoft.Extensions.DependencyInjection;

namespace React.AspNet
{
/// <summary>
/// Handles registering ReactJS.NET services in the ASP.NET <see cref="IServiceCollection"/>.
/// </summary>
public static class ReactServiceCollectionExtensions
{
/// <summary>
/// Registers all services required for ReactJS.NET
/// </summary>
/// <param name="services">ASP.NET services</param>
/// <returns>The service collection (for chaining)</returns>
public static IServiceCollection AddReact(this IServiceCollection services)
{
services.AddSingleton<IReactSiteConfiguration, ReactSiteConfiguration>();
services.AddScoped<IFileCacheHash, FileCacheHash>();
services.AddSingleton<IJsEngineSwitcher>(sp => JsEngineSwitcher.Current);
services.AddSingleton<IJavaScriptEngineFactory, JavaScriptEngineFactory>();
services.AddSingleton<IReactIdGenerator, ReactIdGenerator>();
services.AddScoped<IReactEnvironment, ReactEnvironment>();

services.AddSingleton<IFileSystem, AspNetFileSystem>();
services.AddSingleton<ICache, MemoryFileCacheCore>();

return services;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="$(MSBuildThisFileDirectory)../ThirdPartyCommon.Build.props" />

<PropertyGroup>
<AssemblyName>React.AspNet.Middleware</AssemblyName>
<RootNamespace>React.AspNet.Middleware</RootNamespace>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)../Framework.AspNetCore.Build.props" />

<Import Project="$(MSBuildThisFileDirectory)../LibraryPackaging.Build.props" />
<PropertyGroup>
<Description>A fork of React.NET (https://github.com/reactjs/react.net) that adds support for React v18.</Description>
<PackageId>Redpoint.ThirdParty.React.AspNet.Middleware</PackageId>
<PackageTags>react, react.net</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Authors>June Rhodes, Daniel Lo Nigro</Authors>
<Company></Company>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Redpoint.ThirdParty.React.Core\Redpoint.ThirdParty.React.Core.csproj" />
</ItemGroup>

<PropertyGroup>
<NoWarn>7035</NoWarn>
</PropertyGroup>

</Project>
Loading

0 comments on commit bfdc7e0

Please sign in to comment.