Skip to content

Commit

Permalink
Version 1
Browse files Browse the repository at this point in the history
  • Loading branch information
rockfordlhotka committed Sep 9, 2024
0 parents commit a16af43
Show file tree
Hide file tree
Showing 11 changed files with 501 additions and 0 deletions.
183 changes: 183 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
[Bb]in/
[Oo]bj/

# mstest test results
TestResults

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates
project.lock.json
.vs

# Build results
[Dd]ebug/
[Rr]elease/
x64/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.log
*.vspscc
*.vssscc
.builds

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*

# NCrunch
*.ncrunch*
.*crunch*.local.xml

# Installshield output folder
[Ee]xpress

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish

# Publish Web Output
*.Publish.xml

# NuGet Packages Directory
packages

# Windows Azure Build Output
csx
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
[Bb]in
[Oo]bj
sql
TestResults
[Tt]est[Rr]esult*
*.Cache
ClientBin
[Ss]tyle[Cc]op.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML

Desktop.ini
/Source/Csla.Silverlight.test/UnitTest/CslaLight.Testing/Generated_Code
/Support/TemplateInstaller/CslaTemplates/Thumbs.db
/Source/Csla.Help/Help

/Source/CslaDoc/csladoc.shfbproj_Rockford

/Source/CslaDoc/Help
/Source/.nuget

Thumbs.db
/Source/Csla.Universal/Resources
/Source/Csla.WinRT.Phone/Resources/ar/*.resw
/Source/Csla.WinRT.Phone/Resources/bs/*.resw
/Source/Csla.WinRT.Phone/Resources/ca-ES/*.resw
/Source/Csla.WinRT.Phone/Resources/da/*.resw
/Source/Csla.WinRT.Phone/Resources/de/*.resw
/Source/Csla.WinRT.Phone/Resources/el/*.resw
/Source/Csla.WinRT.Phone/Resources/en-US/*.resw
/Source/Csla.WinRT.Phone/Resources/en/*.resw
/Source/Csla.WinRT.Phone/Resources/es-ES/*.resw
/Source/Csla.WinRT.Phone/Resources/es/*.resw
/Source/Csla.WinRT.Phone/Resources/fr/*.resw
/Source/Csla.WinRT.Phone/Resources/hr/*.resw
/Source/Csla.WinRT.Phone/Resources/hu/*.resw
/Source/Csla.WinRT.Phone/Resources/it/*.resw
/Source/Csla.WinRT.Phone/Resources/km-KH/*.resw
/Source/Csla.WinRT.Phone/Resources/nl/*.resw
/Source/Csla.WinRT.Phone/Resources/no/*.resw
/Source/Csla.WinRT.Phone/Resources/pt-BR/*.resw
/Source/Csla.WinRT.Phone/Resources/pt/*.resw
/Source/Csla.WinRT.Phone/Resources/ro/*.resw
/Source/Csla.WinRT.Phone/Resources/ru/*.resw
/Source/Csla.WinRT.Phone/Resources/sr/*.resw
/Source/Csla.WinRT.Phone/Resources/sv/*.resw
/Source/Csla.WinRT.Phone/Resources/tr/*.resw
/Source/Csla.WinRT.Phone/Resources/uk-ua/*.resw
/Source/Csla.WinRT.Phone/Resources/vi/*.resw
/Source/Csla.WinRT.Phone/Resources/zh-Hans/*.resw
/Source/Csla.WinRT.Phone/Resources/zh-TW/*.resw
/Source/Csla.BrokeredChannel/BrokeredDataPortal
/Source/packages
/XamarinPackage/*.xam

*.userprefs
/Source/Csla.WinRT/resources
/Source/Csla.Uwp/resources
/Samples/ProjectTracker/.vs
project.lock.json
/Source/.vs
Source/UpgradeLog.htm
/Source/Csla.NetStandard1.5/Properties/*.resx
/Source/Csla.NetStandard1.6/Properties/*.resx
/Source/Csla.NetStandard2.0/Properties/*.resx
/Source/Csla.Net5.0/Properties/*.resx

project.lock.json
*.nuget.props
Source/Csla.Uwp/Csla.Uwp.nuget.props
Source/Csla.Uwp/project.lock.json
Source/Csla.Validation.Uwp/Csla.Validation.Uwp.nuget.props
Source/Csla.Validation.Uwp/project.lock.json
Source/Csla.Xaml.Uwp/Csla.Xaml.Uwp.nuget.props
Source/Csla.Xaml.Uwp/project.lock.json

*.bak
/Source/Csla.Android/Csla.Android.csproj.bak
/Source/Csla.Axml.Android/Csla.Axml.Android.csproj.bak
/Source/Csla.Validation.Android/Csla.Validation.Android.csproj.bak
/Samples/ProjectTracker/ProjectTracker.Ui.UWP/ProjectTracker.Ui.UWP.nuget.targets
.vscode
.idea
31 changes: 31 additions & 0 deletions Marimer.Blazor.RenderMode.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35209.166
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Marimer.Blazor.RenderMode", "Marimer.Blazor.RenderMode\Marimer.Blazor.RenderMode.csproj", "{D5B205FB-A8CE-49A2-9AED-1A0300AE81A1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2A7372E0-B9B2-457A-B50C-687FF9D0BD00}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
readme.md = readme.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D5B205FB-A8CE-49A2-9AED-1A0300AE81A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D5B205FB-A8CE-49A2-9AED-1A0300AE81A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5B205FB-A8CE-49A2-9AED-1A0300AE81A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5B205FB-A8CE-49A2-9AED-1A0300AE81A1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B2DEA86C-BE8B-4777-96F0-F85D3C2B3636}
EndGlobalSection
EndGlobal
40 changes: 40 additions & 0 deletions Marimer.Blazor.RenderMode/ActiveCircuitHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//-----------------------------------------------------------------------
// <copyright file="ActiveCircuitHandler.cs" company="Marimer LLC">
// Copyright (c) Marimer LLC. All rights reserved.
// Website: https://cslanet.com
// </copyright>
// <summary>Service that detects whether an active SignalR circuit exists</summary>
//-----------------------------------------------------------------------
namespace Marimer.Blazor.RenderMode;

using Microsoft.AspNetCore.Components.Server.Circuits;

/// <summary>
/// Service that detects whether an active SignalR circuit exists.
/// </summary>
/// <param name="state">ActiveCircuitState service</param>
public class ActiveCircuitHandler(ActiveCircuitState state) : CircuitHandler
{
/// <summary>
/// Detects an open circuit.
/// </summary>
/// <param name="circuit">Circuit object</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns></returns>
public override Task OnCircuitOpenedAsync(Circuit circuit, CancellationToken cancellationToken)
{
state.CircuitExists = true;
return base.OnCircuitOpenedAsync(circuit, cancellationToken);
}

/// <summary>
/// Detects an closed circuit.
/// </summary>
/// <param name="circuit">Circuit object</param>
/// <param name="cancellationToken">Cancellation token</param>
public override Task OnCircuitClosedAsync(Circuit circuit, CancellationToken cancellationToken)
{
state.CircuitExists = false;
return base.OnCircuitClosedAsync(circuit, cancellationToken);
}
}
20 changes: 20 additions & 0 deletions Marimer.Blazor.RenderMode/ActiveCircuitState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//-----------------------------------------------------------------------
// <copyright file="ActiveCircuitState.cs" company="Marimer LLC">
// Copyright (c) Marimer LLC. All rights reserved.
// Website: https://cslanet.com
// </copyright>
// <summary>Service that maintains the active circuit state</summary>
//-----------------------------------------------------------------------
namespace Marimer.Blazor.RenderMode;

/// <summary>
/// Service that maintains the active circuit state
/// </summary>
public class ActiveCircuitState
{
/// <summary>
/// Gets or sets a value indicating whether a SignalR
/// circuit exists.
/// </summary>
public bool CircuitExists { get; set; }
}
35 changes: 35 additions & 0 deletions Marimer.Blazor.RenderMode/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//-----------------------------------------------------------------------
// <copyright file="ConfigurationExtensions.cs" company="Marimer LLC">
// Copyright (c) Marimer LLC. All rights reserved.
// Website: https://cslanet.com
// </copyright>
// <summary>Extension methods for the RenderMode enum</summary>
//-----------------------------------------------------------------------
using Microsoft.AspNetCore.Components.Server.Circuits;
using Microsoft.Extensions.DependencyInjection;

namespace Marimer.Blazor.RenderMode
{
/// <summary>
/// Extension methods for the RenderMode enum
/// </summary>
public static class ConfigurationExtensions
{
/// <summary>
/// Adds services required for render mode detection
/// </summary>
/// <param name="services">IServiceCollection instance</param>
/// <returns></returns>
public static IServiceCollection AddRenderModeDetection(this IServiceCollection services)
{
services.AddTransient<RenderModeProvider>();
services.AddScoped<ActiveCircuitState>();
var isBrowser = OperatingSystem.IsBrowser();
if (!isBrowser)
{
services.AddScoped(typeof(CircuitHandler), typeof(ActiveCircuitHandler));
}
return services;
}
}
}
46 changes: 46 additions & 0 deletions Marimer.Blazor.RenderMode/Marimer.Blazor.RenderMode.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>Blazor Render Mode Detection</Title>
<Copyright>Copyright (c) Marimer LLC</Copyright>
<PackageProjectUrl>https://github.com/MarimerLLC/Marimer.Blazor.RenderMode</PackageProjectUrl>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/MarimerLLC/Marimer.Blazor.RenderMode</RepositoryUrl>
<PackageTags>aspnetcore;blazor</PackageTags>
<PackageLicenseExpression> MIT</PackageLicenseExpression>
<IncludeSymbols>True</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<AssemblyVersion>1.0.1.0</AssemblyVersion>
<FileVersion>1.0.1.0</FileVersion>
</PropertyGroup>

<ItemGroup>
<None Include="..\readme.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>


<ItemGroup>
<SupportedPlatform Include="browser" />
</ItemGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.8" />
</ItemGroup>

<ItemGroup>
<None Update="readme.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>

</Project>
34 changes: 34 additions & 0 deletions Marimer.Blazor.RenderMode/RenderModeProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//-----------------------------------------------------------------------
// <copyright file="RenderModeProvider.cs" company="Marimer LLC">
// Copyright (c) Marimer LLC. All rights reserved.
// Website: https://cslanet.com
// </copyright>
// <summary>Service that provides the render mode</summary>
//-----------------------------------------------------------------------
using Microsoft.AspNetCore.Components;

namespace Marimer.Blazor.RenderMode;

/// <summary>
/// Service that provides the render mode.
/// </summary>
/// <param name="activeCircuitState">ActiveCircuitState service</param>
public class RenderModeProvider(ActiveCircuitState activeCircuitState)
{
/// <summary>
/// Gets the render mode for the specified page.
/// </summary>
/// <param name="page">Current page.</param>
public RenderMode GetRenderMode(ComponentBase page)
{
RenderMode result = RenderMode.ServerStatic;
var isBrowser = OperatingSystem.IsBrowser();
if (isBrowser)
result = RenderMode.WebAssemblyInteractive;
else if (activeCircuitState.CircuitExists)
result = RenderMode.ServerInteractive;
else if (page.GetType().GetCustomAttributes(typeof(StreamRenderingAttribute), true).Length > 0)
result = RenderMode.ServerStaticStreaming;
return result;
}
}
Loading

0 comments on commit a16af43

Please sign in to comment.