Skip to content

Commit

Permalink
Restructure Razor and Code files to protect old code #2540
Browse files Browse the repository at this point in the history
  • Loading branch information
iJungleboy committed Oct 4, 2021
1 parent 54f4a4a commit 438e992
Show file tree
Hide file tree
Showing 45 changed files with 543 additions and 332 deletions.
2 changes: 1 addition & 1 deletion Src/Dnn/ToSic.Sxc.Dnn.WebApi/Custom/Hybrid/Api12.cs
Expand Up @@ -25,7 +25,7 @@ namespace Custom.Hybrid
/// </summary>
[InternalApi_DoNotUse_MayChangeWithoutNotice("WIP for 2sxc 12")]
[DnnLogExceptions]
public abstract partial class Api12: DynamicApiController, IDynamicCode, IDynamicWebApi, IHasDynamicCodeRoot
public abstract partial class Api12: DynamicApiController, IDynamicCode, IDynamicCode12, IDynamicWebApi, IHasDynamicCodeRoot
{
[PrivateApi] public int CompatibilityLevel => _DynCodeRoot.CompatibilityLevel;

Expand Down
7 changes: 4 additions & 3 deletions Src/Dnn/ToSic.Sxc.Dnn.WebApi/Dnn/ApiController.cs
Expand Up @@ -28,9 +28,10 @@ public abstract class ApiController : Api12, IDnnDynamicWebApi

#region Convert-Service - 2sxc 12.05 only

[PrivateApi]
public new IConvertService Convert => throw new NotSupportedException(
$"The command {nameof(Convert)} is only available in newer base classes. {ErrRecommendedNamespaces}");
// todo: 12.05
//[PrivateApi]
//public new IxConvertService Convert => throw new NotSupportedException(
// $"The command {nameof(Convert)} is only available in newer base classes. {ErrRecommendedNamespaces}");

#endregion

Expand Down
Expand Up @@ -193,11 +193,11 @@ public IFolder AsAdam(IDynamicEntity entity, string fieldName)
/// <inheritdoc />
public ICmsContext CmsContext => _DynCodeRoot.CmsContext;

/// <inheritdoc />
public dynamic Resources => _DynCodeRoot.Resources;
///// <inheritdoc />
//public dynamic Resources => _DynCodeRoot.Resources;

/// <inheritdoc />
public dynamic Settings => _DynCodeRoot.Settings;
///// <inheritdoc />
//public dynamic Settings => _DynCodeRoot.Settings;

#endregion
}
Expand Down
Expand Up @@ -36,9 +36,9 @@ public IEnumerable<dynamic> AsList(object list)

#region Convert-Service - 2sxc 12.05 only

[PrivateApi]
public IConvertService Convert => throw new NotSupportedException(
$"The command {nameof(Convert)} is only available in newer base classes. {ApiController.ErrRecommendedNamespaces}");
//[PrivateApi]
//public IxConvertService Convert => throw new NotSupportedException(
// $"The command {nameof(Convert)} is only available in newer base classes. {ApiController.ErrRecommendedNamespaces}");

#endregion

Expand Down
2 changes: 1 addition & 1 deletion Src/Dnn/ToSic.Sxc.Dnn/Custom.Dnn/Code12.cs
Expand Up @@ -10,7 +10,7 @@ namespace Custom.Dnn
/// By inheriting from this base class, you will automatically have the context like the App object etc. available.
/// </summary>
[PublicApi_Stable_ForUseInYourCode]
public abstract class Code12 : ToSic.Sxc.Code.DynamicCode, IDnnDynamicCodeAdditions
public abstract class Code12 : ToSic.Sxc.Code.DynamicCode12, IDnnDynamicCodeAdditions
{
/// <inheritdoc />
public IDnnContext Dnn => (_DynCodeRoot as DnnDynamicCodeRoot)?.Dnn;
Expand Down
6 changes: 1 addition & 5 deletions Src/Dnn/ToSic.Sxc.Dnn/Dnn/Code/DnnDynamicCodeRoot.cs
Expand Up @@ -3,7 +3,6 @@
using ToSic.Sxc.Blocks;
using ToSic.Sxc.Code;
using ToSic.Sxc.Dnn.Run;
using ToSic.Sxc.Dnn.Web;

namespace ToSic.Sxc.Dnn.Code
{
Expand All @@ -21,20 +20,17 @@ public DnnDynamicCodeRoot(Dependencies dependencies, IDnnContext dnnContext): ba
/// <param name="block">CMS Block which provides context and maybe some edit-allowed info.</param>
/// <param name="parentLog">parent logger for logging what's happening</param>
/// <param name="compatibility">compatibility level - changes behaviour if level 9 or 10</param>
public /*new*/ override IDynamicCodeRoot Init(IBlock block, ILog parentLog, int compatibility = 10)
public override IDynamicCodeRoot Init(IBlock block, ILog parentLog, int compatibility = 10)
{
base.Init(block, parentLog, compatibility);
// Init things than require module-info or similar, but not 2sxc
((DnnContextOld)Dnn).Init(block?.Context.Module);
//Link.Init(block?.Context, App);
return this;
}

/// <summary>
/// Dnn context with module, page, portal etc.
/// </summary>
public IDnnContext Dnn { get; private set; }

//public IDynamicCodeRoot _DynCodeRoot => this;
}
}
5 changes: 3 additions & 2 deletions Src/Dnn/ToSic.Sxc.Razor/2sxc Razor.csproj
Expand Up @@ -121,13 +121,14 @@
<Compile Include="Custom\Dnn\Razor12.cs" />
<Compile Include="Custom\Dnn\Razor12Code.cs" />
<Compile Include="Custom\Hybrid\Razor12_DynamicModel.cs" />
<Compile Include="Dnn\beta\InheritRazorComponent.cs" />
<Compile Include="Dnn\IDnnRazor.cs" />
<Compile Include="Dnn\IDnnRazor11.cs" />
<Compile Include="Dnn\RazorCodeManager.cs" />
<Compile Include="Dnn\RazorComponent.NewNotAvailable.cs" />
<Compile Include="Dnn\RazorComponentCode.cs" />
<Compile Include="Dnn\RazorComponent_Code.cs" />
<Compile Include="Dnn\RazorComponent_Customize.cs" />
<Compile Include="Dnn\Web\IRazorComponent.cs" />
<Compile Include="Dnn\Web\IDnnRazorCustomize.cs" />
<Compile Include="Dnn\Web\IHtmlHelper.cs" />
<Compile Include="Dnn\RazorComponent.cs" />
<Compile Include="Engines\Razor\RazorEngine_Callbacks.cs" />
Expand Down
57 changes: 3 additions & 54 deletions Src/Dnn/ToSic.Sxc.Razor/Custom/Dnn/Razor12.cs
@@ -1,14 +1,8 @@
using System;
using System.Collections.Generic;
using Custom.Hybrid;
using ToSic.Eav.Documentation;
using ToSic.Eav.Run;
using ToSic.Sxc.Blocks;
using ToSic.Sxc.Context;
using ToSic.Sxc.Dnn;
using ToSic.Sxc.Dnn.Code;
using ToSic.Sxc.Dnn.Run;
using ToSic.Sxc.Dnn.Web;
using ToSic.Sxc.Search;

// ReSharper disable once CheckNamespace
namespace Custom.Dnn
Expand All @@ -18,7 +12,7 @@ namespace Custom.Dnn
/// Provides context infos like the Dnn object, helpers like Edit and much more. <br/>
/// </summary>
[PublicApi_Stable_ForUseInYourCode]
public abstract class Razor12 : Hybrid.Razor12, IRazorComponent
public abstract class Razor12 : Hybrid.Razor12, /*IDnnRazorCustomize,*/ IRazor12, IDnnRazor, IDnnRazor11
{
[PrivateApi("Hide this, no need to publish; would only confuse users")]
protected Razor12()
Expand All @@ -37,57 +31,12 @@ protected Razor12()
internal RazorCodeManager CodeManager => _codeManager ?? (_codeManager = new RazorCodeManager(this));
private RazorCodeManager _codeManager;

/// <summary>
/// Code-Behind of this .cshtml file - located in a file with the same name but ending in .code.cshtml
/// </summary>
/// <inheritdoc />
public dynamic Code => CodeManager.CodeOrException;

#endregion


#region CustomizeSearch corrections

/// <inheritdoc />
[PrivateApi("shouldn't be used any more, but was still in v12 when released. v13+ must completely remove this")]
public virtual void CustomizeSearch(Dictionary<string, List<ISearchItem>> searchInfos, IModule moduleInfo,
DateTime beginDate)
{
// in 2sxc 11.11 the signature changed.
// so the engine will call this function
// but the override will be the other one - so I must call that
// unless of course this method was overridden by the final inheriting RazorComponent
#pragma warning disable 618 // disable warning about IContainer being obsolete
CustomizeSearch(searchInfos, moduleInfo as IContainer, beginDate);
#pragma warning restore 618
}

[PrivateApi("shouldn't be used any more, but was still in v12 when released. v13+ must completely remove this")]
#pragma warning disable 618 // disable warning about IContainer being obsolete
public virtual void CustomizeSearch(Dictionary<string, List<ISearchItem>> searchInfos, IContainer moduleInfo,
#pragma warning restore 618
DateTime beginDate)
{
// new in 2sxc 11, if it has not been overridden, then try to check if code has something for us.
var code = CodeManager.CodeOrNull;
if (code == null) return;
if (code is Razor12Code codeAsRazor) codeAsRazor.CustomizeSearch(searchInfos, moduleInfo, beginDate);
}

[PrivateApi("shouldn't be used any more, but was still in v12 when released. v13+ must completely remove this")]
public virtual void CustomizeData()
{
// new in 2sxc 11, if it has not been overridden, then try to check if code has something for us.
var code = CodeManager.CodeOrNull;
if (code == null) return;
if (code is Razor12Code codeAsRazor) codeAsRazor.CustomizeData();
}

/// <inheritdoc />
[PrivateApi("shouldn't be used any more, but was still in v12 when released. v13+ must completely remove this")]
public Purpose Purpose { get; internal set; }


#endregion

}
}
30 changes: 7 additions & 23 deletions Src/Dnn/ToSic.Sxc.Razor/Custom/Dnn/Razor12Code.cs
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using ToSic.Eav.Documentation;
using ToSic.Eav.Run;
using ToSic.Sxc.Context;
using ToSic.Sxc.Dnn;
using ToSic.Sxc.Search;
using ToSic.Eav.Documentation;

// ReSharper disable once CheckNamespace
namespace Custom.Dnn
Expand All @@ -13,25 +7,15 @@ namespace Custom.Dnn
/// This is the type used by code-behind classes of razor components in 2sxc v12+
/// Use it to move logic / functions etc. into a kind of code-behind razor instead of as part of your view-template.
/// </summary>
/// <remarks>
/// The Custom.Dnn.Razor12Code was created in 2sxc12 and has similar functionality to the previous <see cref="ToSic.Sxc.Dnn.RazorComponentCode"/>.
/// It's different in an important way: it does not have `CustomizeData` or `CustomizeSearch` any more, since that's deprecated.
/// If you think you still need that, then you must use the old base class
/// </remarks>
[PublicApi_Stable_ForUseInYourCode]
public abstract class Razor12Code: RazorComponent
public abstract class Razor12Code: Razor12
{

/// <inheritdoc />
[Obsolete("Shouldn't be used any more, but will continue to work for indefinitely. There are now better ways of doing this")]
public override void CustomizeData() { }

#pragma warning disable 618
/// <inheritdoc />
[PrivateApi]
public override void CustomizeSearch(Dictionary<string, List<ISearchItem>> searchInfos, IModule moduleInfo, DateTime beginDate)
{
CustomizeSearch(searchInfos, moduleInfo as IContainer, beginDate);
}

[Obsolete("Shouldn't be used any more, but will continue to work for indefinitely. There are now better ways of doing this")]
public override void CustomizeSearch(Dictionary<string, List<ISearchItem>> searchInfos, IContainer moduleInfo, DateTime beginDate) { }
#pragma warning restore 618

}
}
2 changes: 0 additions & 2 deletions Src/Dnn/ToSic.Sxc.Razor/Custom/Hybrid/Razor12.cs
Expand Up @@ -133,11 +133,9 @@ public T CreateSource<T>(IDataSource inSource = null, ILookUpEngine configuratio
public ICmsContext CmsContext => _DynCodeRoot.CmsContext;

/// <inheritdoc />
[PublicApi("Careful - still Experimental in 12.02")]
public dynamic Resources => _DynCodeRoot.Resources;

/// <inheritdoc />
[PublicApi("Careful - still Experimental in 12.02")]
public dynamic Settings => _DynCodeRoot.Settings;

#endregion
Expand Down
18 changes: 18 additions & 0 deletions Src/Dnn/ToSic.Sxc.Razor/Dnn/IDnnRazor.cs
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ToSic.Sxc.Dnn.Web;

namespace ToSic.Sxc.Dnn
{
public interface IDnnRazor
{
/// <summary>
/// Helper for Html.Raw - for creating raw html output which doesn't encode &gt; and &lt;
/// </summary>
IHtmlHelper Html { get; }

}
}
18 changes: 18 additions & 0 deletions Src/Dnn/ToSic.Sxc.Razor/Dnn/IDnnRazor11.cs
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ToSic.Eav.Documentation;

namespace ToSic.Sxc.Dnn
{
[PrivateApi]
public interface IDnnRazor11
{
/// <summary>
/// Code-Behind of this .cshtml file - located in a file with the same name but ending in .code.cshtml
/// </summary>
dynamic Code { get; }
}
}
5 changes: 3 additions & 2 deletions Src/Dnn/ToSic.Sxc.Razor/Dnn/RazorCodeManager.cs
Expand Up @@ -2,13 +2,14 @@
using System.IO;
using System.Web;
using ToSic.Eav.Logging;
using ToSic.Sxc.Web;

namespace ToSic.Sxc.Dnn
{
public class RazorCodeManager: HasLog
{
public Custom.Dnn.Razor12 Parent;
public RazorCodeManager(Custom.Dnn.Razor12 parent): base("Rzr.Code", parent.Log)
public RazorComponentBase Parent;
public RazorCodeManager(RazorComponentBase parent): base("Rzr.Code", parent.Log)
{
Parent = parent;
}
Expand Down
13 changes: 4 additions & 9 deletions Src/Dnn/ToSic.Sxc.Razor/Dnn/RazorComponent.NewNotAvailable.cs
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ToSic.Eav.Documentation;
using ToSic.SexyContent.Razor;
using ToSic.Sxc.Web;
Expand All @@ -11,14 +7,13 @@ namespace ToSic.Sxc.Dnn
{
public abstract partial class RazorComponent
{
#region Convert-Service

public const string NotImplementedUseCustomBase = "Use a newer base class like Custom.Hybrid.Razor12 or Custom.Dnn.Razor12 to leverage this.";

[PrivateApi]
public new IConvertService Convert => throw new NotSupportedException($"{nameof(Convert)} not implemented on {nameof(SexyContentWebPage)}. {NotImplementedUseCustomBase}");

#endregion
//#region Convert-Service
//[PrivateApi]
//public new IxConvertService Convert => throw new NotSupportedException($"{nameof(Convert)} not implemented on {nameof(SexyContentWebPage)}. {NotImplementedUseCustomBase}");
//#endregion

}
}

0 comments on commit 438e992

Please sign in to comment.