Skip to content
Merged
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
11 changes: 0 additions & 11 deletions samples/build-tools/build-scripts/BuildAppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// -k, --api-key <key> ArcGIS API key (required)
// -l, --license-key <key> GeoBlazor license key (required)
// -o, --output <path> Output path(s) for appsettings.json (required, can specify multiple)
// -d, --docs-url <url> Documentation URL (default: https://docs.geoblazor.com)
// -b, --bypass-key <key> API bypass key for samples (optional)
// -w, --wfs-servers <json> Additional WFS server configuration JSON fragment (optional)
// -h, --help Display help message
Expand All @@ -22,7 +21,6 @@
string? arcGISApiKey = null;
string? licenseKey = null;
List<string> outputPaths = [];
string docsUrl = "https://docs.geoblazor.com";
string byPassApiKey = "";
string wfsServers = "";
bool help = false;
Expand Down Expand Up @@ -54,13 +52,6 @@
outputPaths.Add(args[++i]);
}
break;
case "-d":
case "--docs-url":
if (i + 1 < args.Length)
{
docsUrl = args[++i];
}
break;
case "-b":
case "--bypass-key":
if (i + 1 < args.Length)
Expand Down Expand Up @@ -93,7 +84,6 @@
Console.WriteLine(" -k, --api-key <key> ArcGIS API key (required)");
Console.WriteLine(" -l, --license-key <key> GeoBlazor license key (required)");
Console.WriteLine(" -o, --output <path> Output path(s) for appsettings.json (required, can specify multiple)");
Console.WriteLine(" -d, --docs-url <url> Documentation URL (default: https://docs.geoblazor.com)");
Console.WriteLine(" -b, --bypass-key <key> API bypass key for samples (optional)");
Console.WriteLine(" -w, --wfs-servers <json> Additional WFS server configuration JSON fragment (optional)");
Console.WriteLine(" -h, --help Display this help message");
Expand Down Expand Up @@ -130,7 +120,6 @@
sb.AppendLine(" \"GeoBlazor\": {");
sb.AppendLine($" \"LicenseKey\": \"{EscapeJsonString(licenseKey)}\"");
sb.AppendLine(" },");
sb.AppendLine($" \"DocsUrl\": \"{EscapeJsonString(docsUrl)}\",");
sb.Append($" \"ByPassApiKey\": \"{EscapeJsonString(byPassApiKey)}\"");

// Add WFS servers if provided
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static MauiApp CreateMauiApp()
builder.Configuration.AddConfiguration(config);
builder.Services.AddGeoBlazor(builder.Configuration);
builder.Services.AddScoped<LayoutService>();
builder.Services.AddSingleton<ISampleSourceProvider, SampleSourceProvider>();

return builder.Build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
@page "/source-code"
@page "/source-code"
@page "/source-code/{PageUrl}"

<PageTitle>Source Code</PageTitle>
<h1>Source Code</h1>

@if (string.IsNullOrWhiteSpace(_razorContent))
@if (_notFound)
{
<p>Source for <code>@PageUrl</code> is not embedded in the sample app.</p>
}
else if (string.IsNullOrWhiteSpace(_razorContent))
{
<p>Loading...</p>
}
Expand All @@ -15,4 +19,4 @@ else
{
<CodeHighlight Language="csharp" Code="@_codeContent" />
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System.Reflection;
using dymaptic.GeoBlazor.Core.Sample.Shared.Shared;
using Microsoft.AspNetCore.Components;

namespace dymaptic.GeoBlazor.Core.Sample.Shared.Pages;

public partial class SourceCode
{
[Parameter]
public string? PageUrl { get; set; }

[Inject]
public required ISampleSourceProvider SourceProvider { get; set; }

protected override void OnParametersSet()
{
if (string.IsNullOrWhiteSpace(PageUrl))
{
_razorContent = string.Empty;
_codeContent = string.Empty;
_notFound = false;
return;
}

Type? pageType = ResolvePageType(PageUrl);
if (pageType is null)
{
_razorContent = string.Empty;
_codeContent = string.Empty;
_notFound = true;
return;
}

(string razor, string? codeBehind) = SourceProvider.GetSource(pageType);

if (string.IsNullOrEmpty(razor))
{
_razorContent = string.Empty;
_codeContent = string.Empty;
_notFound = true;
return;
}

_notFound = false;

// split apart the markup section and the code section so the highlighting can be language-specific
// for HTML and C#, since there is no widely accepted Razor syntax highlighting
if (razor.Contains("@code"))
{
int codeIndex = razor.IndexOf("@code", StringComparison.Ordinal);
_codeContent = razor[codeIndex..].Trim();
_razorContent = razor[..codeIndex].Trim();
}
else
{
_razorContent = razor;
_codeContent = string.Empty;
}

if (!string.IsNullOrEmpty(codeBehind))
{
_razorContent = $"""
## {PageUrl}.razor

{_razorContent}
""";
_codeContent = $"""
## {PageUrl}.razor.cs

{codeBehind}
""";
}
}

private static Type? ResolvePageType(string typeName)
{
Dictionary<string, Type> index = LazyPageIndex.Value;
return index.TryGetValue(typeName, out Type? t) ? t : null;
}

private static readonly Lazy<Dictionary<string, Type>> LazyPageIndex = new(() =>
{
var index = new Dictionary<string, Type>(StringComparer.Ordinal);
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
string? name = assembly.GetName().Name;
if (name is null) continue;
if (!name.Contains("Sample.Shared", StringComparison.Ordinal)) continue;

Type[] types;
try { types = assembly.GetExportedTypes(); }
catch { continue; }

foreach (Type type in types)
{
if (type.GetCustomAttributes<RouteAttribute>().Any())
{
// last writer wins; Pro can shadow Core if names collide
index[type.Name] = type;
}
}
}
return index;
});

private string _razorContent = string.Empty;
private string _codeContent = string.Empty;
private bool _notFound;
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
}

protected virtual Type NavMenuType => typeof(NavMenu);
protected virtual Type? AdditionalLinksType => null;
protected virtual Type? AdditionalLinksType => typeof(SourceNav);

private readonly string[] _btnTypes = ["btn-primary", "btn-secondary", "btn-accent"];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Reflection;

namespace dymaptic.GeoBlazor.Core.Sample.Shared.Shared;

public interface ISampleSourceProvider
{
(string Razor, string? CodeBehind) GetSource(Type pageType);
}

public class SampleSourceProvider : ISampleSourceProvider
{
public (string Razor, string? CodeBehind) GetSource(Type pageType)
{
Assembly assembly = pageType.Assembly;
string razor = ReadResource(assembly, $"SampleSource/{pageType.Name}.razor") ?? string.Empty;
string? codeBehind = ReadResource(assembly, $"SampleSource/{pageType.Name}.razor.cs");
return (razor, codeBehind);
}

private static string? ReadResource(Assembly assembly, string logicalName)
{
using Stream? stream = assembly.GetManifestResourceStream(logicalName);
if (stream is null) return null;
using var reader = new StreamReader(stream);
return reader.ReadToEnd();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<a class="btn btn-secondary" @onclick="ViewRepositorySource">GitHub<br/>Repo</a>

@code {

[Inject]
public required NavigationManager NavigationManager { get; set; }

[CascadingParameter(Name="PageRouteData")]
public required RouteData RouteData { get; set; }

Expand All @@ -25,4 +25,4 @@
NavigationManager.NavigateTo("https://github.com/dymaptic/GeoBlazor");
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@
<ItemGroup>
<AdditionalFiles Include="Shared\RenderModeSelector.razor" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Pages\**\*.razor" LogicalName="SampleSource/%(Filename)%(Extension)" />
<EmbeddedResource Include="Pages\**\*.razor.cs" LogicalName="SampleSource/%(Filename)%(Extension)" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

builder.Services.AddGeoBlazor(builder.Configuration);
builder.Services.AddScoped<LayoutService>();
builder.Services.AddSingleton<ISampleSourceProvider, SampleSourceProvider>();
builder.Configuration.AddInMemoryCollection();
builder.Services.AddScoped<HttpClient>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
builder.Services.AddGeoBlazor(builder.Configuration);
builder.Services.AddSingleton<IConfiguration>(_ => builder.Configuration);
builder.Services.AddScoped<LayoutService>();
builder.Services.AddSingleton<ISampleSourceProvider, SampleSourceProvider>();

await builder.Build().RunAsync();
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
builder.Services.AddGeoBlazor(builder.Configuration);
builder.Services.AddScoped<HttpClient>();
builder.Services.AddScoped<LayoutService>();
builder.Services.AddSingleton<ISampleSourceProvider, SampleSourceProvider>();
builder.Configuration.AddInMemoryCollection();

WebApplication app = builder.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static MauiApp CreateMauiApp()
builder.Configuration.AddConfiguration(config);
builder.Services.AddGeoBlazorPro(builder.Configuration);
builder.Services.AddScoped<LayoutService>();
builder.Services.AddSingleton<ISampleSourceProvider, SampleSourceProvider>();

return builder.Build();
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@
<Target Name="Copy Razor Files" BeforeTargets="Build" Condition="'$(UseProjectReferences)' == 'true'">
<Exec Command="dotnet $(ProGBBuildToolsPath)/RazorCopy.dll"/>
</Target>

<ItemGroup>
<EmbeddedResource Include="Pages\**\*.razor" LogicalName="SampleSource/%(Filename)%(Extension)" />
<EmbeddedResource Include="Pages\**\*.razor.cs" LogicalName="SampleSource/%(Filename)%(Extension)" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions samples/pro/dymaptic.GeoBlazor.Pro.Sample.Wasm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@

builder.Services.AddGeoBlazorPro(builder.Configuration);
builder.Services.AddScoped<LayoutService>();
builder.Services.AddSingleton<ISampleSourceProvider, SampleSourceProvider>();

await builder.Build().RunAsync();
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
builder.Services.AddScoped<HttpClient>();
builder.Services.AddGeoBlazorPro(builder.Configuration);
builder.Services.AddScoped<LayoutService>();
builder.Services.AddSingleton<ISampleSourceProvider, SampleSourceProvider>();
builder.Services.AddSingleton<IConfiguration>(_ => builder.Configuration);

await builder.Build().RunAsync();
Loading
Loading