Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Sacha Trauwaen committed Sep 11, 2024
1 parent 5def7cc commit 07d8366
Show file tree
Hide file tree
Showing 36 changed files with 3,999 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
<Reference Include="ClientDependency.Core, Version=1.9.10.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Dnn.ClientDependency.1.9.10\lib\net45\ClientDependency.Core.dll</HintPath>
</Reference>
<Reference Include="ClientDependency.Core.Mvc">
<HintPath>..\..\..\dnnClientDependency\src\ClientDependency.Mvc\bin\Debug-MVC5\ClientDependency.Core.Mvc.dll</HintPath>
</Reference>
<Reference Include="DotNetNuke.Instrumentation">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\DotNetNuke.Instrumentation\bin\DotNetNuke.Instrumentation.dll</HintPath>
Expand All @@ -63,12 +66,16 @@
<Reference Include="System.Web" />
<Reference Include="System.Web.Abstractions" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Web.Mvc">
<HintPath>..\..\Packages\Microsoft.AspNet.Mvc.5.2.9\lib\net45\System.Web.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\SolutionInfo.cs">
<Link>SolutionInfo.cs</Link>
</Compile>
<Compile Include="MvcClientResourceManager.cs" />
<Compile Include="Controls\ClientResourceExclude.cs" />
<Compile Include="Controls\DnnJsExclude.cs" />
<Compile Include="Controls\DnnCssExclude.cs" />
Expand Down
581 changes: 581 additions & 0 deletions DNN Platform/DotNetNuke.Web.Client/MvcClientResourceManager.cs

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions DNN Platform/DotNetNuke.Web.Mvc/DnnMvcPageHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace DotNetNuke.Web.Mvc
{
using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.SessionState;

using DotNetNuke.ComponentModel;
using DotNetNuke.Entities.Portals;
using DotNetNuke.HttpModules.Membership;
using DotNetNuke.Services.Localization;
using DotNetNuke.UI.Modules;
using DotNetNuke.Web.Mvc.Common;
using DotNetNuke.Web.Mvc.Framework.Modules;
using DotNetNuke.Web.Mvc.Routing;

public class DnnMvcPageHandler : MvcHandler, IHttpHandler, IRequiresSessionState
{
public DnnMvcPageHandler(RequestContext requestContext)
: base(requestContext)
{
}

/// <inheritdoc/>
protected override void ProcessRequest(HttpContext httpContext)
{
this.SetThreadCulture();
MembershipModule.AuthenticateRequest(this.RequestContext.HttpContext, allowUnknownExtensions: true);
base.ProcessRequest(httpContext);
}

protected override IAsyncResult BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, object state)
{
this.SetThreadCulture();
MembershipModule.AuthenticateRequest(this.RequestContext.HttpContext, allowUnknownExtensions: true);
return base.BeginProcessRequest(httpContext, callback, state);
}

private void SetThreadCulture()
{
var portalSettings = PortalController.Instance.GetCurrentSettings();
if (portalSettings is null)
{
return;
}

var pageLocale = Localization.GetPageLocale(portalSettings);
if (pageLocale is null)
{
return;
}

Localization.SetThreadCultures(pageLocale, portalSettings);
}
}
}
52 changes: 52 additions & 0 deletions DNN Platform/DotNetNuke.Web.Mvc/DnnMvcPageRouteHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace DotNetNuke.Web.Mvc
{
using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.SessionState;

public class DnnMvcPageRouteHandler : IRouteHandler
{
private readonly IControllerFactory controllerFactory;

/// <summary>Initializes a new instance of the <see cref="DnnMvcPageRouteHandler"/> class.</summary>
public DnnMvcPageRouteHandler()
{
}

/// <summary>Initializes a new instance of the <see cref="DnnMvcPageRouteHandler"/> class.</summary>
/// <param name="controllerFactory">The controller factory.</param>
public DnnMvcPageRouteHandler(IControllerFactory controllerFactory)
{
this.controllerFactory = controllerFactory;
}

/// <inheritdoc/>
IHttpHandler IRouteHandler.GetHttpHandler(RequestContext requestContext)
{
return this.GetHttpHandler(requestContext);
}

protected virtual IHttpHandler GetHttpHandler(RequestContext requestContext)
{
requestContext.HttpContext.SetSessionStateBehavior(this.GetSessionStateBehavior(requestContext));
return new DnnMvcPageHandler(requestContext);
}

protected virtual SessionStateBehavior GetSessionStateBehavior(RequestContext requestContext)
{
string controllerName = (string)requestContext.RouteData.Values["controller"];
if (string.IsNullOrWhiteSpace(controllerName))
{
throw new InvalidOperationException("No Controller");
}

IControllerFactory controllerFactory = this.controllerFactory ?? ControllerBuilder.Current.GetControllerFactory();
return controllerFactory.GetControllerSessionBehavior(requestContext, controllerName);
}
}
}
6 changes: 6 additions & 0 deletions DNN Platform/DotNetNuke.Web.Mvc/DotNetNuke.Web.Mvc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
<Compile Include="Common\PropertyHelper.cs" />
<Compile Include="Common\TypeHelper.cs" />
<Compile Include="DnnMvcDependencyResolver.cs" />
<Compile Include="DnnMvcPageHandler.cs" />
<Compile Include="DnnMvcPageRouteHandler.cs" />
<Compile Include="Extensions\StartupExtensions.cs" />
<Compile Include="Framework\ActionFilters\AuthFilterContext.cs" />
<Compile Include="Framework\ActionFilters\AuthorizeAttributeBase.cs" />
Expand Down Expand Up @@ -194,6 +196,10 @@
<Compile Include="Routing\MvcRoutingManager.cs" />
<Compile Include="Routing\PortalAliasMvcRouteManager.cs" />
<Compile Include="Routing\StandardModuleRoutingProvider.cs" />
<Compile Include="Skins\Controllers\DnnPageController.cs" />
<Compile Include="Skins\MvcContainer.cs" />
<Compile Include="Skins\MvcPane.cs" />
<Compile Include="Skins\MvcSkin.cs" />
<Compile Include="StandardTabAndModuleInfoProvider.cs" />
<Compile Include="Startup.cs" />
</ItemGroup>
Expand Down
42 changes: 35 additions & 7 deletions DNN Platform/DotNetNuke.Web.Mvc/Routing/MvcRoutingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace DotNetNuke.Web.Mvc.Routing
using System;
using System.Collections.Generic;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;

using DotNetNuke.Common;
Expand All @@ -19,8 +20,8 @@ public sealed class MvcRoutingManager : IMapRoute
{
private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(MvcRoutingManager));
private readonly Dictionary<string, int> moduleUsage = new Dictionary<string, int>();
private readonly RouteCollection routes;
private readonly PortalAliasMvcRouteManager portalAliasMvcRouteManager;
private readonly RouteCollection routes;

public MvcRoutingManager()
: this(RouteTable.Routes)
Expand Down Expand Up @@ -108,11 +109,6 @@ private static bool IsTracingEnabled()
return !string.IsNullOrEmpty(configValue) && Convert.ToBoolean(configValue);
}

private static void RegisterSystemRoutes()
{
// routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
}

private static Route MapRouteWithNamespace(string name, string url, object defaults, object constraints, string[] namespaces)
{
var route = new Route(url, new DnnMvcRouteHandler())
Expand Down Expand Up @@ -141,9 +137,41 @@ private static RouteValueDictionary CreateRouteValueDictionaryUncached(object va
return dictionary != null ? new RouteValueDictionary(dictionary) : TypeHelper.ObjectToDictionary(values);
}

private void RegisterSystemRoutes()
{
// routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// var route = MapRouteWithNamespace(
// name: "Default",
// url: "mvc/{controller}/{action}/{id}",
// defaults: new { action = "Index", id = UrlParameter.Optional },
// constraints: null,
// namespaces: new string[] { "DotNetNuke.Framework.Controllers" });
// this.routes.Add(route);

/*
this.routes.MapRoute(
name: "Default",
url: "mvc/{controller}/{action}/{tabid}/{language}",
defaults: new { action = "Index", tabid = UrlParameter.Optional, language= UrlParameter.Optional },
namespaces: new string[] { "DotNetNuke.Framework.Controllers" });
*/

var route = new Route("mvc/{controller}/{action}/{tabid}/{language}", new DnnMvcPageRouteHandler())
{
Defaults = CreateRouteValueDictionaryUncached(new { action = "Index", tabid = UrlParameter.Optional, language = UrlParameter.Optional }),

// Constraints = CreateRouteValueDictionaryUncached(constraints),
};
route.DataTokens = new RouteValueDictionary();
ConstraintValidation.Validate(route);
route.SetNameSpaces(new string[] { "DotNetNuke.Framework.Controllers" });
route.SetName("Default");
this.routes.Add(route);
}

private void LocateServicesAndMapRoutes()
{
RegisterSystemRoutes();
this.RegisterSystemRoutes();
this.ClearCachedRouteData();

this.moduleUsage.Clear();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.Web.Mvc.Skins.Controllers
{
using System;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.UI;

using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Entities.Users;
using DotNetNuke.Services.Localization;
using DotNetNuke.UI.Modules;
using DotNetNuke.Web.Mvc.Framework.ActionResults;
using DotNetNuke.Web.Mvc.Framework.Modules;
using DotNetNuke.Web.Mvc.Helpers;

public abstract class DnnPageController : Controller // IDnnController
{
/// <summary>Initializes a new instance of the <see cref="DnnPageController"/> class.</summary>
protected DnnPageController()
{
// this.ActionInvoker = new ResultCapturingActionInvoker();
}

public TabInfo ActivePage
{
get { return (this.PortalSettings == null) ? null : this.PortalSettings.ActiveTab; }
}

public PortalSettings PortalSettings
{
get
{
return PortalController.Instance.GetCurrentPortalSettings();
}
}

public ActionResult ResultOfLastExecute
{
get
{
var actionInvoker = this.ActionInvoker as ResultCapturingActionInvoker;
return (actionInvoker != null) ? actionInvoker.ResultOfLastInvoke : null;
}
}

/*
public new UserInfo User
{
get { return (this.PortalSettings == null) ? null : this.PortalSettings.UserInfo; }
}
public new DnnUrlHelper Url { get; set; }
*/
public string LocalResourceFile { get; set; }

public string LocalizeString(string key)
{
return Localization.GetString(key, this.LocalResourceFile);
}

/// <inheritdoc/>
protected override void Initialize(RequestContext requestContext)
{
base.Initialize(requestContext);

// this.Url = new DnnUrlHelper(requestContext, this);
}
}
}
Loading

0 comments on commit 07d8366

Please sign in to comment.