Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Johnson committed Nov 28, 2021
2 parents 10b9585 + 6fa7ec1 commit 9eabd05
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 53 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ $ dotnet tool install --global Umbraco.Docs.Preview.App
## Running the project

```bash
$ umbracodocs # run from UmbracoDocs repo root
$ umbracodocs # from UmbracoDocs repository
$ umbracodocs -h # view help.
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace Umbraco.Docs.Preview.App.Extensions
{
public static class UmbracoDocsApplicationBuilderExtensions
public static class ApplicationBuilderExtensions
{
public static IApplicationBuilder UseUmbracoDocsImageFileProviders(this IApplicationBuilder app)
public static IApplicationBuilder UseUmbracoDocsStaticFiles(this IApplicationBuilder app)
{
var settings = app.ApplicationServices.GetRequiredService<IOptions<UmbracoDocsOptions>>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public void Intercept(IInvocation invocation)

if (_cache.TryGetValue(attribute.CacheKey, out var value))
{
_log.LogDebug("Cache hit for {info}", invocation.Method);
_log.LogDebug("Cache hit for {info}", $"{invocation.Method.DeclaringType!.FullName}{invocation.Method.Name}");
invocation.ReturnValue = value;
return;
}

_log.LogDebug("Cache miss for {info}", invocation.Method);
_log.LogDebug("Cache miss for {info}", $"{invocation.Method.DeclaringType!.FullName}{invocation.Method.Name}");
invocation.Proceed();
_cache.Set(attribute.CacheKey, invocation.ReturnValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,30 @@

namespace Umbraco.Docs.Preview.App.Messaging.Notifications.DocumentationUpdated
{
public class InvalidateDocsTreeCache : INotificationHandler<DocsUpdated>
public class DocsUpdatedHandler : INotificationHandler<DocsUpdated>
{
private readonly ILogger _log;
private readonly IMemoryCache _memoryCache;
private readonly IDocumentationChangeNotifier _clientNotifier;

public InvalidateDocsTreeCache(
ILogger<InvalidateDocsTreeCache> log,
IMemoryCache memoryCache)
public DocsUpdatedHandler(
ILogger<DocsUpdatedHandler> log,
IMemoryCache memoryCache,
IDocumentationChangeNotifier clientNotifier)
{
_log = log;
_memoryCache = memoryCache;
_clientNotifier = clientNotifier;
}

public Task Handle(DocsUpdated notification, CancellationToken cancellationToken)
{
_log.LogDebug("Clearing DocsTree cache.");
_log.LogDebug("Documentation updated clearing DocsTree cache.");
_memoryCache.Remove(nameof(IDocumentService.GetDocsTree));

_log.LogInformation("Documentation updated, triggering UI reload.");
_clientNotifier.PublishChangeNotifications();

return Task.CompletedTask;
}
}
Expand Down

This file was deleted.

29 changes: 19 additions & 10 deletions src/Umbraco.Docs.Preview.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
using System.CommandLine;
using System.CommandLine.Invocation;
using System.IO;
using System.Reflection;
// ReSharper disable once RedundantUsingDirective
using System.Reflection; // Used in Release build.
using Lamar.Microsoft.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -21,14 +22,23 @@ public static int Main(string[] args)
{
Name = "path",
Arity = new ArgumentArity(0, 1),
Description = "Path to UmbracoDocs repository."
Description = "Optional path to UmbracoDocs repository. Defaults to current directory when omitted."
}
};
rootCommand.Name = "umbracodocs";
rootCommand.Description = "Run UmbracoDocs preview server";
rootCommand.Handler = CommandHandler.Create<string>(RunServer);

return rootCommand.Invoke(args);
var result = rootCommand.Invoke(args);

switch (result)
{
case -1:
rootCommand.Invoke("--help");
break;
}

return result;
}

private static int RunServer(string path = null)
Expand All @@ -37,18 +47,18 @@ private static int RunServer(string path = null)

var docsAbsolutePath = Path.GetFullPath(path);


if (!File.Exists(Path.Combine(docsAbsolutePath!, "index.md")))
if (!File.Exists(Path.Combine(docsAbsolutePath, "index.md")))
{
Console.Error.WriteLine("Fatal Error: current directory doesn't appear to be the UmbracoDocs repo.");
Console.Error.WriteLine($"Specified path doesn't appear to be the UmbracoDocs repository.{Environment.NewLine}");
return -1;
}

Host.CreateDefaultBuilder(new[] { path })
#if !DEBUG
// dotnet tools configures cwd as you would expect, but Host.CreateDefaultBuilder isn't expecting that
// to be miles away from appsettings.json and wwwroot etc.
// So more prefer configuration over convention for ContentRoot (unless debugging).
// Host.CreateDefaultBuilder sets ContentRoot to cwd which will cause issues
// when this app is run from its installed location i.e. ~/.dotnet/tools
// e.g. wwwroot & appsettings.json won't be found.
// Prefer configuration over convention for ContentRoot (except when debugging).
.UseContentRoot(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))
#endif
.UseLamar()
Expand All @@ -60,7 +70,6 @@ private static int RunServer(string path = null)
services.Configure<UmbracoDocsOptions>(cfg => cfg.UmbracoDocsRootFolder = docsAbsolutePath);
});
webBuilder.UseStartup<Startup>();

})
.Build()
.Run();
Expand Down
2 changes: 1 addition & 1 deletion src/Umbraco.Docs.Preview.App/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger<

app.UseStatusCodePages();

app.UseUmbracoDocsImageFileProviders();
app.UseUmbracoDocsStaticFiles();

app.UseStaticFiles();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<PropertyGroup>
<Version>0.1.2</Version>
<Version>0.1.3</Version>
<Company>Umbraco HQ</Company>
<Description>Enables local preview of UmbracoDocs.</Description>
<PackageTags>umbraco</PackageTags>
Expand Down

0 comments on commit 9eabd05

Please sign in to comment.