Changes namesspace, fixes cdf registrations, fixes bundle registrations, cleanup

This commit is contained in:
Shannon
2020-04-02 21:19:42 +11:00
parent a67bb197b7
commit 95a36b3064
24 changed files with 72 additions and 119 deletions

View File

@@ -21,7 +21,6 @@ using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
using Umbraco.Core.Services;
using Umbraco.Web.Features;
using Umbraco.Web.JavaScript;
using Umbraco.Web.Models.Identity;
using Umbraco.Web.Security;
using Constants = Umbraco.Core.Constants;
@@ -33,6 +32,7 @@ using Umbraco.Core.IO;
using Umbraco.Core.Runtime;
using Umbraco.Core.WebAssets;
using Umbraco.Web.Trees;
using Umbraco.Web.WebAssets;
namespace Umbraco.Web.Editors
{

View File

@@ -17,12 +17,9 @@ using Umbraco.Core.Models.Packaging;
using Umbraco.Net;
using Umbraco.Core.Packaging;
using Umbraco.Core.Persistence;
using Umbraco.Core.Runtime;
using Umbraco.Core.Services;
using Umbraco.Core.Strings;
using Umbraco.Core.WebAssets;
using Umbraco.Net;
using Umbraco.Web.JavaScript;
using Umbraco.Web.Models;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Web.Mvc;

View File

@@ -14,10 +14,10 @@ using Umbraco.Core.Services;
using Umbraco.Core.WebAssets;
using Umbraco.Web.Composing;
using Umbraco.Web.Features;
using Umbraco.Web.JavaScript;
using Umbraco.Web.Mvc;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Trees;
using Umbraco.Web.WebAssets;
using Constants = Umbraco.Core.Constants;
namespace Umbraco.Web.Editors

View File

@@ -14,9 +14,9 @@ using Umbraco.Core.WebAssets;
using Umbraco.Web.Composing;
using Umbraco.Web.Editors;
using Umbraco.Web.Features;
using Umbraco.Web.JavaScript;
using Umbraco.Web.Models;
using Umbraco.Web.Trees;
using Umbraco.Web.WebAssets;
namespace Umbraco.Web
{

View File

@@ -1,13 +1,9 @@
using System;
using System.Web.Mvc;
using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Web.Composing;
using Umbraco.Core.Configuration;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Runtime;
using Umbraco.Core.WebAssets;
using Umbraco.Web.JavaScript;
using Umbraco.Web.Mvc;
using Umbraco.Web.Security;

View File

@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Web.Http;
using System.Web.Http.Dispatcher;
@@ -10,7 +8,6 @@ using System.Web.Routing;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration;
using Umbraco.Core.Hosting;
using Umbraco.Core.Strings;
using Umbraco.Core.IO;
using Umbraco.Web.Install;
@@ -27,33 +24,24 @@ namespace Umbraco.Web.Runtime
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly SurfaceControllerTypeCollection _surfaceControllerTypes;
private readonly UmbracoApiControllerTypeCollection _apiControllerTypes;
private readonly IHostingSettings _hostingSettings;
private readonly IGlobalSettings _globalSettings;
private readonly IHostingEnvironment _hostingEnvironment;
private readonly IIOHelper _ioHelper;
private readonly IShortStringHelper _shortStringHelper;
private readonly IRuntimeSettings _settings;
public WebInitialComponent(
IUmbracoContextAccessor umbracoContextAccessor,
SurfaceControllerTypeCollection surfaceControllerTypes,
UmbracoApiControllerTypeCollection apiControllerTypes,
IHostingSettings hostingSettings,
IGlobalSettings globalSettings,
IHostingEnvironment hostingEnvironment,
IIOHelper ioHelper,
IShortStringHelper shortStringHelper,
IRuntimeSettings settings)
IShortStringHelper shortStringHelper)
{
_umbracoContextAccessor = umbracoContextAccessor;
_surfaceControllerTypes = surfaceControllerTypes;
_apiControllerTypes = apiControllerTypes;
_hostingSettings = hostingSettings;
_globalSettings = globalSettings;
_hostingEnvironment = hostingEnvironment;
_ioHelper = ioHelper;
_shortStringHelper = shortStringHelper;
_settings = settings;
}
public void Initialize()

View File

@@ -547,7 +547,6 @@
<Compile Include="UmbracoWebService.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="WebAssets\WebAssetsComponent.cs" />
<Compile Include="WebViewPageExtensions.cs" />
<Compile Include="Runtime\WebFinalComponent.cs" />
<Compile Include="Runtime\WebFinalComposer.cs" />

View File

@@ -5,18 +5,15 @@ using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using ClientDependency.Core;
using ClientDependency.Core.CompositeFiles;
using ClientDependency.Core.Config;
using ClientDependency.Core.Mvc;
using Umbraco.Core.Configuration;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Manifest;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.WebAssets;
using Umbraco.Web.JavaScript;
using CssFile = ClientDependency.Core.CssFile;
using JavascriptFile = ClientDependency.Core.JavascriptFile;
@@ -87,13 +84,9 @@ namespace Umbraco.Web.WebAssets.CDF
var assetType = bundleFiles[0].DependencyType == ClientDependencyType.Css ? AssetType.Css : AssetType.Javascript;
// get the output string for these registrations which will be processed by CDF correctly to stagger the output based
// on internal vs external resources. The output will be delimited based on our custom Umbraco.Web.JavaScript.DependencyPathRenderer
var dependencies = new List<IClientDependencyFile>();
// This is a hack on CDF so that we can resolve CDF urls directly since that isn't directly supported by the lib
var renderer = ClientDependencySettings.Instance.MvcRendererCollection["Umbraco.DependencyPathRenderer"];
renderer.RegisterDependencies(dependencies, new HashSet<IClientDependencyPath>(), out var scripts, out var stylesheets, _httpContextAccessor.HttpContext);
renderer.RegisterDependencies(bundleFiles, new HashSet<IClientDependencyPath>(), out var scripts, out var stylesheets, _httpContextAccessor.HttpContext);
var toParse = assetType == AssetType.Javascript ? scripts : stylesheets;
return Task.FromResult<IEnumerable<string>>(toParse.Split(new[] { DependencyPathRenderer.Delimiter }, StringSplitOptions.RemoveEmptyEntries));
@@ -133,28 +126,26 @@ namespace Umbraco.Web.WebAssets.CDF
new HashSet<IClientDependencyPath>(),
out var jsOutput, out var cssOutput, _httpContextAccessor.GetRequiredHttpContext());
return HttpUtility.HtmlEncode(assetType == AssetType.Css ? cssOutput : jsOutput);
return assetType == AssetType.Css ? cssOutput : jsOutput;
}
private IEnumerable<IClientDependencyFile> GetCssBundleFiles(string bundleName)
{
// the result of this is internal too, so use dynamic
dynamic bundle = typeof(BundleManager)
// internal methods needs reflection
var bundle = typeof(BundleManager)
.GetMethod("GetCssBundle", BindingFlags.NonPublic | BindingFlags.Static)
.Invoke(null, new object[] { bundleName });
if (bundle == null) return null;
IEnumerable<IClientDependencyFile> bundleFiles = bundle.Files;
var bundleFiles = (IEnumerable<IClientDependencyFile>) bundle?.GetType().GetProperty("Files").GetValue(bundle, null);
return bundleFiles;
}
private IEnumerable<IClientDependencyFile> GetJsBundleFiles(string bundleName)
{
// the result of this is internal too, so use dynamic
dynamic bundle = typeof(BundleManager)
// internal methods needs reflection
var bundle = typeof(BundleManager)
.GetMethod("GetJsBundle", BindingFlags.NonPublic | BindingFlags.Static)
.Invoke(null, new object[] { bundleName });
if (bundle == null) return null;
IEnumerable<IClientDependencyFile> bundleFiles = bundle.Files;
var bundleFiles = (IEnumerable<IClientDependencyFile>)bundle?.GetType().GetProperty("Files").GetValue(bundle, null);
return bundleFiles;
}

View File

@@ -1,43 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Hosting;
using Umbraco.Core.Manifest;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.WebAssets;
using Umbraco.Web.JavaScript;
using Umbraco.Web.PropertyEditors;
using Umbraco.Infrastructure.WebAssets;
namespace Umbraco.Web.WebAssets
{
public sealed class WebAssetsComposer : ComponentComposer<WebAssetsComponent>
{
}
public sealed class WebAssetsComponent : IComponent
{
private readonly BackOfficeWebAssets _backOfficeWebAssets;
public WebAssetsComponent(BackOfficeWebAssets backOfficeWebAssets)
{
_backOfficeWebAssets = backOfficeWebAssets;
}
public void Initialize()
{
// TODO: This will eagerly scan types but we don't really want that, however it works for now.
// We don't actually have to change Smidge or anything, all we have to do is postpone this call for when the first request on the website arrives.
_backOfficeWebAssets.CreateBundles();
}
public void Terminate()
{
}
}
}