Skip to content

Commit

Permalink
Merge pull request #1941 from 2sic/develop
Browse files Browse the repository at this point in the history
about to release 10.24
  • Loading branch information
iJungleboy committed Dec 18, 2019
2 parents 7a70b15 + bdcc96a commit dde8c90
Show file tree
Hide file tree
Showing 51 changed files with 637 additions and 439 deletions.
2 changes: 2 additions & 0 deletions ToSIC_SexyContent/2Sexy Content Razor/Dnn/RazorComponent.cs
Expand Up @@ -44,6 +44,8 @@ public abstract partial class RazorComponent : RazorComponentBase, IRazorCompone
[PrivateApi("todo: try to remove thi")]
public SxcHelper Sxc => DynCode.Sxc;

[PrivateApi] public int CompatibilityLevel => DynCode.CompatibilityLevel;

/// <inheritdoc />
public new IApp App => DynCode.App;

Expand Down
Expand Up @@ -3,6 +3,7 @@
using ToSic.Eav.Documentation;
using ToSic.Eav.Run;
using ToSic.Sxc.Blocks;
using ToSic.Sxc.Dnn.Code;
using ToSic.Sxc.Search;

// ReSharper disable UnusedMemberInSuper.Global
Expand All @@ -13,7 +14,7 @@ namespace ToSic.Sxc.Dnn.Web
/// All DNN Razor Pages inherit from this class
/// </summary>
[PublicApi]
public interface IRazorComponent: IDynamicCode
public interface IRazorComponent: IDnnDynamicCode
{
/// <summary>
/// Helper for Html.Raw - for creating raw html output which doesn't encode &gt; and &lt;
Expand Down
18 changes: 11 additions & 7 deletions ToSIC_SexyContent/2Sexy Content Razor/Engines/Razor/RazorEngine.cs
Expand Up @@ -15,10 +15,10 @@
using ToSic.SexyContent.Razor;
using ToSic.SexyContent.Search;
using ToSic.Sxc.Dnn;
using ToSic.Sxc.Dnn.Code;
using ToSic.Sxc.Dnn.Web;
using ToSic.Sxc.Search;
using ToSic.Sxc.Web;
using DynamicCode = ToSic.Sxc.Dnn.DynamicCode;

// ReSharper disable once CheckNamespace
namespace ToSic.Sxc.Engines
Expand Down Expand Up @@ -108,7 +108,7 @@ private object CreateWebPageInstance()
}
}

private void InitHelpers(RazorComponentBase webPage)
private void InitHelpers(RazorComponentBase webPage, int compatibiltiy)
{
webPage.Html = new Razor.HtmlHelper();
// Deprecated 2019-05-27 2dm - I'm very sure this isn't used anywhere or by anyone.
Expand All @@ -117,7 +117,7 @@ private void InitHelpers(RazorComponentBase webPage)

// deprecated 2019-11-28 2dm, it's also in the CmsBlock
// webPage.Sexy = CmsBlock;
webPage.DynCode = new DynamicCode(CmsBlock);
webPage.DynCode = new DnnDynamicCode(CmsBlock, compatibiltiy, Log);

}

Expand All @@ -130,20 +130,24 @@ private void InitWebpage()
if (objectValue == null)
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "The webpage found at '{0}' was not created.", TemplatePath));

Webpage = objectValue as RazorComponentBase;// SexyContentWebPage;
Webpage = objectValue as RazorComponentBase;

if ((Webpage == null))
if (Webpage == null)
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "The webpage at '{0}' must derive from SexyContentWebPage.", TemplatePath));

Webpage.Context = HttpContext;
Webpage.VirtualPath = TemplatePath;
if(Webpage is RazorComponent rzrPage)
int compatibility = 9;
if (Webpage is RazorComponent rzrPage)
{
rzrPage.Purpose = Purpose;
compatibility = 10;
}
#pragma warning disable 618
if(Webpage is SexyContentWebPage oldPage)
oldPage.InstancePurpose = (InstancePurposes) Purpose;
#pragma warning restore 618
InitHelpers(Webpage);
InitHelpers(Webpage, compatibility);
}

/// <inheritdoc />
Expand Down
30 changes: 17 additions & 13 deletions ToSIC_SexyContent/2Sexy Content Razor/SexyContentWebPage.cs
@@ -1,8 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using DotNetNuke.Entities.Modules;
using ToSic.Eav.Data;
using ToSic.Eav.DataSources;
using ToSic.Eav.Documentation;
using ToSic.Eav.LookUp;
Expand All @@ -21,7 +20,6 @@
using ToSic.Sxc.Dnn.Web;
using ToSic.Sxc.Search;
using ToSic.Sxc.Web;
using DynamicCode = ToSic.Sxc.Web.DynamicCode;
using DynamicJacket = ToSic.Sxc.Data.DynamicJacket;
using IApp = ToSic.Sxc.Apps.IApp;
using IEntity = ToSic.Eav.Data.IEntity;
Expand Down Expand Up @@ -59,6 +57,8 @@ public abstract class SexyContentWebPage :
[PrivateApi("try to remove")]
public SxcHelper Sxc => DynCode.Sxc;

[PrivateApi] public int CompatibilityLevel => DynCode.CompatibilityLevel;

/// <inheritdoc />
public new IApp App => DynCode.App;

Expand All @@ -70,6 +70,7 @@ public abstract class SexyContentWebPage :
#region AsDynamic in many variations

/// <inheritdoc />
[Obsolete]
public dynamic AsDynamic(IEntity entity) => DynCode.AsDynamic(entity);


Expand All @@ -78,19 +79,22 @@ public abstract class SexyContentWebPage :

// todo: only in "old" controller, not in new one
/// <inheritdoc />
[Obsolete]
public dynamic AsDynamic(KeyValuePair<int, IEntity> entityKeyValuePair) => DynCode.AsDynamic(entityKeyValuePair.Value);



/// <inheritdoc />
public IEnumerable<dynamic> AsDynamic(IDataStream stream) => DynCode.AsDynamic(stream.List);
[Obsolete]
public IEnumerable<dynamic> AsDynamic(IDataStream stream) => DynCode.AsList(stream.List);

/// <inheritdoc />
public IEntity AsEntity(dynamic dynamicEntity) => DynCode.AsEntity(dynamicEntity);


/// <inheritdoc />
public IEnumerable<dynamic> AsDynamic(IEnumerable<IEntity> entities) => DynCode.AsDynamic(entities);
[Obsolete]
public IEnumerable<dynamic> AsDynamic(IEnumerable<IEntity> entities) => DynCode.AsList(entities);

#endregion

Expand All @@ -106,31 +110,31 @@ public IEnumerable<dynamic> AsList(dynamic list)
#region Compatibility with Eav.Interfaces.IEntity - introduced in 10.10
[PrivateApi]
[Obsolete("for compatibility only, avoid using this and cast your entities to ToSic.Eav.Data.IEntity")]
public dynamic AsDynamic(Eav.Interfaces.IEntity entity) => DynCode.AsDynamic(entity);
public dynamic AsDynamic(Eav.Interfaces.IEntity entity) => DynCode.AsDynamic(entity as IEntity);


[PrivateApi]
[Obsolete("for compatibility only, avoid using this and cast your entities to ToSic.Eav.Data.IEntity")]
public dynamic AsDynamic(KeyValuePair<int, Eav.Interfaces.IEntity> entityKeyValuePair) => DynCode.AsDynamic(entityKeyValuePair.Value);
public dynamic AsDynamic(KeyValuePair<int, Eav.Interfaces.IEntity> entityKeyValuePair) => DynCode.AsDynamic(entityKeyValuePair.Value as IEntity);

[PrivateApi]
[Obsolete("for compatibility only, avoid using this and cast your entities to ToSic.Eav.Data.IEntity")]
public IEnumerable<dynamic> AsDynamic(IEnumerable<Eav.Interfaces.IEntity> entities) => DynCode.AsDynamic(entities);
public IEnumerable<dynamic> AsDynamic(IEnumerable<Eav.Interfaces.IEntity> entities) => DynCode.AsList(entities.Cast<IEntity>());
#endregion


#region Data Source Stuff
/// <inheritdoc cref="ToSic.Sxc.Dnn.Web.IDynamicCode" />
/// <inheritdoc />
[Obsolete]
public IDataSource CreateSource(string typeName = "", IDataSource inSource = null, ILookUpEngine lookUpEngine = null)
=> DynCode.CreateSource(typeName, inSource, lookUpEngine);
=> new DynamicCodeObsolete(DynCode).CreateSource(typeName, inSource, lookUpEngine);

/// <inheritdoc cref="ToSic.Sxc.Dnn.Web.IDynamicCode" />
/// <inheritdoc />
public T CreateSource<T>(IDataSource inSource = null, ILookUpEngine configurationProvider = null)
where T : IDataSource
=> DynCode.CreateSource<T>(inSource, configurationProvider);

/// <inheritdoc cref="ToSic.Sxc.Dnn.Web.IDynamicCode" />
/// <inheritdoc />
public T CreateSource<T>(IDataStream inStream) where T : IDataSource
=> DynCode.CreateSource<T>(inStream);

Expand All @@ -156,7 +160,7 @@ public dynamic Header
public dynamic ListPresentation => DynCode.Header?.Presentation;

[Obsolete("This is an old way used to loop things - shouldn't be used any more - will be removed in a future version")]
public List<Element> List => DynCode.List;
public List<Element> List => new DynamicCodeObsolete(DynCode).ElementList;

/// <inheritdoc/>
public dynamic AsDynamic(string json, string fallback = DynamicJacket.EmptyJson)
Expand Down
Expand Up @@ -4,6 +4,7 @@
using ToSic.Eav.Documentation;
using ToSic.Sxc.Code;
using ToSic.Sxc.Dnn;
using ToSic.Sxc.Dnn.Code;
using ToSic.Sxc.Dnn.Web;
using File = System.IO.File;

Expand All @@ -15,15 +16,15 @@ namespace ToSic.Sxc.Web
/// It only contains internal wiring stuff, so not to be published
/// </summary>
[PrivateApi("internal class only!")]
public abstract class RazorComponentBase: WebPageBase, ISharedCodeBuilder
public abstract class RazorComponentBase: WebPageBase, ICreateInstance
{
public IHtmlHelper Html { get; internal set; }

// 2019-11-28 2dm: see if we can drop this, I believe it's also attached to the DynCodeHelper
//[PrivateApi]
//protected internal Blocks.ICmsBlock Sexy { get; set; }
[PrivateApi]
protected internal Dnn.DynamicCode DynCode { get; set; }
protected internal DnnDynamicCode DynCode { get; set; }


/// <summary>
Expand All @@ -48,7 +49,7 @@ protected override void ConfigurePage(WebPageBase parentPage)

#region Compile Helpers

public string SharedCodeVirtualRoot { get; set; }
public string CreateInstancePath { get; set; }

/// <summary>
/// Creates instances of the shared pages with the given relative path
Expand Down
6 changes: 3 additions & 3 deletions ToSIC_SexyContent/2sxc Dnn/2sxc Dnn.csproj
Expand Up @@ -83,7 +83,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Code\AppDataDnnHelpers.cs" />
<Compile Include="Dnn\DynamicCode.cs" />
<Compile Include="Code\ErrorHelp.cs" />
<Compile Include="Compatibility\ToSic.SexyContent.Environment.Dnn7.DataSources.DnnSqlDataSource.cs" />
<Compile Include="Compatibility\ToSic.SexyContent.Environment.Dnn7.DataSources.DnnUserProfileDataSource.cs" />
Expand All @@ -93,9 +93,9 @@
<Compile Include="Dnn\Run\DnnContext.cs" />
<Compile Include="Dnn\Factory.cs" />
<Compile Include="Dnn\Web\IDynamicWebApi.cs" />
<Compile Include="Dnn\Web\IDynamicCode.cs" />
<Compile Include="Dnn\Code\IDnnDynamicCode.cs" />
<Compile Include="Dnn\Run\DnnSecurity.cs" />
<Compile Include="Dnn\DynamicCode.cs" />
<Compile Include="Dnn\Code\DnnDynamicCode.cs" />
<Compile Include="Dnn\Web\DnnClientDependency.cs" />
<Compile Include="Dnn\Web\ClientInfos\ClientInfosAll.cs" />
<Compile Include="Dnn\Web\ClientInfos\ClientInfosEnvironment.cs" />
Expand Down
20 changes: 0 additions & 20 deletions ToSIC_SexyContent/2sxc Dnn/Code/AppDataDnnHelpers.cs

This file was deleted.

Expand Up @@ -3,6 +3,7 @@
using DotNetNuke.Entities.Portals;
using ToSic.Eav.Run;
using ToSic.Sxc.Blocks;
using ToSic.Sxc.Code;
using ToSic.Sxc.Web;
using IApp = ToSic.Sxc.Apps.IApp;

Expand Down
39 changes: 39 additions & 0 deletions ToSIC_SexyContent/2sxc Dnn/Dnn/Code/DnnDynamicCode.cs
@@ -0,0 +1,39 @@
using ToSic.Eav.Documentation;
using ToSic.Eav.Logging;
using ToSic.Sxc.Blocks;
using ToSic.Sxc.Dnn.Run;
using ToSic.Sxc.Dnn.Web;

namespace ToSic.Sxc.Dnn.Code
{
public class DnnDynamicCode : Sxc.Code.DynamicCodeRoot, IDnnDynamicCode
{
[PrivateApi]
public new ICmsBlock CmsBlock => base.CmsBlock;

/// <summary>
/// Standard constructor
/// </summary>
/// <param name="cmsBlock">The CMS Block which is used in this code.</param>
/// <param name="parentLog">parent logger for logging what's happening</param>
public DnnDynamicCode(ICmsBlock cmsBlock, int compatibility, ILog parentLog = null): base(cmsBlock, new DnnTenant(null), compatibility, parentLog)
{
//CmsBlock = cmsBlock;
// Init things than require module-info or similar, but not 2sxc
var instance = cmsBlock?.Container;
Dnn = new DnnContext(instance);
Link = new DnnLinkHelper(Dnn);
}

#region IHasDnnContext

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

#endregion


}
}
@@ -1,14 +1,14 @@
using ToSic.Eav.Documentation;
using ToSic.Sxc.Dnn.Run;

namespace ToSic.Sxc.Dnn.Web
namespace ToSic.Sxc.Dnn.Code
{
/// <summary>
/// This interface extends the IAppAndDataHelpers with the DNN Context.
/// It's important, because if 2sxc also runs on other CMS platforms, then the Dnn Context won't be available, so it's in a separate interface.
/// </summary>
[PublicApi]
public interface IDynamicCode : Sxc.Web.IDynamicCode
public interface IDnnDynamicCode : Sxc.Code.IDynamicCode
{
/// <summary>
/// The DNN context.
Expand Down
40 changes: 17 additions & 23 deletions ToSIC_SexyContent/2sxc Dnn/Dnn/DynamicCode.cs
@@ -1,32 +1,26 @@
using ToSic.Eav.Logging;
using ToSic.Sxc.Blocks;
using ToSic.Eav.Documentation;
using ToSic.Sxc.Code;
using ToSic.Sxc.Dnn.Run;
using ToSic.Sxc.Dnn.Web;
using IDynamicCode = ToSic.Sxc.Code.IDynamicCode;

namespace ToSic.Sxc.Dnn
{
public class DynamicCode : Sxc.Web.DynamicCode, IDynamicCode
// ReSharper disable once UnusedMember.Global
/// <summary>
/// This is a base class for custom code files with context. <br/>
/// If you create a class file for dynamic use and inherit from this, then the compiler will automatically add objects like Link, Dnn, etc.
/// The class then also has AsDynamic(...) and AsList(...) commands like a normal razor page.
/// </summary>
[PublicApi]
public abstract class DynamicCode : Sxc.Code.DynamicCode, Code.IDnnDynamicCode
{
public ICmsBlock CmsBlock;
public IDnnContext Dnn { get; private set; }

public DynamicCode(ICmsBlock cmsBlock, ILog parentLog = null): base(cmsBlock, new DnnTenant(null), parentLog)
internal override void InitShared(IDynamicCode parent)
{
CmsBlock = cmsBlock;
// Init things than require module-info or similar, but not 2sxc
var instance = cmsBlock?.Container;
Dnn = new DnnContext(instance);
Link = new DnnLinkHelper(Dnn);
}

#region IHasDnnContext

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

#endregion

if (parent is Code.IDnnDynamicCode withDnn) Dnn = withDnn.Dnn;

base.InitShared(parent);
}
}
}
}

0 comments on commit dde8c90

Please sign in to comment.