Skip to content

Commit

Permalink
clean up webapis for #2540
Browse files Browse the repository at this point in the history
  • Loading branch information
iJungleboy committed Oct 4, 2021
1 parent 438e992 commit d7c67bd
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 76 deletions.
3 changes: 2 additions & 1 deletion Src/Dnn/ToSic.Sxc.Dnn.WebApi/Custom/Dnn/Api12.cs
@@ -1,4 +1,5 @@
using ToSic.Eav.Documentation;
using ToSic.Sxc.Dnn.Code;
using ToSic.Sxc.Dnn.Run;
using ToSic.Sxc.Dnn.WebApi;
using ToSic.Sxc.Dnn.WebApi.Logging;
Expand All @@ -12,7 +13,7 @@ namespace Custom.Dnn
/// </summary>
[PublicApi_Stable_ForUseInYourCode]
[DnnLogExceptions]
public abstract class Api12 : Hybrid.Api12, IDnnDynamicWebApi
public abstract class Api12 : Hybrid.Api12, IDnnDynamicWebApi, IDnnDynamicCodeAdditions
{
/// <inheritdoc />
public new IDnnContext Dnn => base.Dnn;
Expand Down
2 changes: 0 additions & 2 deletions Src/Dnn/ToSic.Sxc.Dnn.WebApi/Custom/Hybrid/Api12.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
115 changes: 108 additions & 7 deletions Src/Dnn/ToSic.Sxc.Dnn.WebApi/Dnn/ApiController.cs
@@ -1,10 +1,21 @@
using System;
using Custom.Hybrid;
using System.Collections.Generic;
using ToSic.Eav;
using ToSic.Eav.Data;
using ToSic.Eav.DataSources;
using ToSic.Eav.Documentation;
using ToSic.Eav.LookUp;
using ToSic.Sxc.Adam;
using ToSic.Sxc.Apps;
using ToSic.Sxc.Blocks;
using ToSic.Sxc.Code;
using ToSic.Sxc.Context;
using ToSic.Sxc.Data;
using ToSic.Sxc.DataSources;
using ToSic.Sxc.Dnn.WebApi;
using ToSic.Sxc.Dnn.WebApi.Logging;
using ToSic.Sxc.Web;
using ToSic.Sxc.WebApi;

namespace ToSic.Sxc.Dnn
{
Expand All @@ -15,7 +26,7 @@ namespace ToSic.Sxc.Dnn
[PublicApi_Stable_ForUseInYourCode]
[DnnLogExceptions]
[Obsolete("This will continue to work, but you should use the Custom.Hybrid.Api12 or Custom.Dnn.Api12 instead.")]
public abstract class ApiController : Api12, IDnnDynamicWebApi
public abstract class ApiController : DynamicApiController, IDnnDynamicWebApi, IDynamicCode, /*IDynamicCode12,*/ IDynamicWebApi, IHasDynamicCodeRoot
{

public const string ErrRecommendedNamespaces = "To use it, use the new base class from Custom.Hybrid.Api12 or Custom.Dnn.Api12 instead.";
Expand All @@ -26,14 +37,104 @@ public abstract class ApiController : Api12, IDnnDynamicWebApi
/// </remarks>
[PrivateApi] public IBlock Block => GetBlock();

#region Convert-Service - 2sxc 12.05 only
[PrivateApi] public int CompatibilityLevel => _DynCodeRoot.CompatibilityLevel;

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

/// <inheritdoc />
public IBlockDataSource Data => _DynCodeRoot.Data;


#region AsDynamic implementations
/// <inheritdoc/>
public dynamic AsDynamic(string json, string fallback = DynamicJacket.EmptyJson) => _DynCodeRoot.AsDynamic(json, fallback);

/// <inheritdoc />
public dynamic AsDynamic(IEntity entity) => _DynCodeRoot.AsDynamic(entity);

/// <inheritdoc />
public dynamic AsDynamic(object dynamicEntity) => _DynCodeRoot.AsDynamic(dynamicEntity);

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

/// <inheritdoc />
public IEntity AsEntity(object dynamicEntity) => _DynCodeRoot.AsEntity(dynamicEntity);

#endregion


#region AsList

/// <inheritdoc />
public IEnumerable<dynamic> AsList(object list) => _DynCodeRoot?.AsList(list);

#endregion

#region CreateSource implementations

/// <inheritdoc />
public T CreateSource<T>(IDataSource inSource = null, ILookUpEngine configurationProvider = null)
where T : IDataSource
=> _DynCodeRoot.CreateSource<T>(inSource, configurationProvider);

/// <inheritdoc />
public T CreateSource<T>(IDataStream inStream) where T : IDataSource
=> _DynCodeRoot.CreateSource<T>(inStream);

#endregion

#region Content, Presentation & List

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

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


#endregion

#region Adam

/// <inheritdoc />
public IFolder AsAdam(IDynamicEntity entity, string fieldName) => _DynCodeRoot.AsAdam(AsEntity(entity), fieldName);

/// <inheritdoc />
public IFolder AsAdam(IEntity entity, string fieldName) => _DynCodeRoot.AsAdam(entity, fieldName);


///// <inheritdoc />
//public new ToSic.Sxc.Adam.IFile SaveInAdam(string noParamOrder = ToSic.Eav.Parameters.Protector,
// Stream stream = null,
// string fileName = null,
// string contentType = null,
// Guid? guid = null,
// string field = null,
// string subFolder = "")
// => base.SaveInAdam(noParamOrder, stream, fileName, contentType, guid, field, subFolder);

public dynamic File(string noParamOrder = Parameters.Protector, bool? download = null, string virtualPath = null,
string contentType = null, string fileDownloadName = null, object contents = null) =>
throw new NotSupportedException("Not implemented. " + ErrRecommendedNamespaces);

#endregion

#region Link & Edit - added to API in 2sxc 10.01

/// <inheritdoc />
public ILinkHelper Link => _DynCodeRoot?.Link;

/// <inheritdoc />
public IInPageEditingSystem Edit => _DynCodeRoot?.Edit;

#endregion
#region RunContext WiP

/// <inheritdoc />
public ICmsContext CmsContext => _DynCodeRoot?.CmsContext;
#endregion
}
}
Expand Up @@ -4,7 +4,6 @@
using DotNetNuke.Web.Api;
using ToSic.Eav.Logging;
using ToSic.Eav.Logging.Simple;
using ToSic.Eav.Plumbing;
using ToSic.Eav.WebApi;
using ToSic.Eav.WebApi.Helpers;
using ToSic.Sxc.Dnn.WebApi.Logging;
Expand Down
Expand Up @@ -47,6 +47,7 @@ public abstract partial class SxcApiController :
public new IDnnContext Dnn => base.Dnn;

[Obsolete]
[PrivateApi]
public SxcHelper Sxc => _sxc ?? (_sxc = new SxcHelper(_DynCodeRoot?.Block?.Context?.UserMayEdit ?? false));
[Obsolete]
private SxcHelper _sxc;
Expand Down
@@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using ToSic.Eav;
using ToSic.Eav.Documentation;
using ToSic.Sxc.Data;
using ToSic.Sxc.Dnn;
using ToSic.Sxc.Web;

// ReSharper disable once CheckNamespace
namespace ToSic.SexyContent.WebApi
Expand Down Expand Up @@ -34,13 +32,6 @@ public IEnumerable<dynamic> AsList(object list)
string virtualPath = null, string contentType = null, string fileDownloadName = null, object contents = null) =>
throw new NotSupportedException($"This method is not available in the old {nameof(SxcApiController)}. {ApiController.ErrRecommendedNamespaces}");

#region Convert-Service - 2sxc 12.05 only

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

#endregion

}
}
16 changes: 8 additions & 8 deletions Src/Dnn/ToSic.Sxc.Razor/Custom/Dnn/Razor12.cs
Expand Up @@ -12,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, /*IDnnRazorCustomize,*/ IRazor12, IDnnRazor, IDnnRazor11
public abstract class Razor12 : Hybrid.Razor12, IDnnDynamicCodeAdditions, IRazor12, IDnnRazor // , IDnnRazor11 /* IDnnRazor11 adds the Code property which probably doesn't make sense in future */
{
[PrivateApi("Hide this, no need to publish; would only confuse users")]
protected Razor12()
Expand All @@ -25,16 +25,16 @@ protected Razor12()
/// <inheritdoc />
public IDnnContext Dnn => (_DynCodeRoot as IDnnDynamicCode)?.Dnn;

#region Code Behind - a Dnn feature which probably won't exist in Oqtane
//#region Code Behind - a Dnn feature which probably won't exist in Oqtane

[PrivateApi]
internal RazorCodeManager CodeManager => _codeManager ?? (_codeManager = new RazorCodeManager(this));
private RazorCodeManager _codeManager;
//[PrivateApi]
//internal RazorCodeManager CodeManager => _codeManager ?? (_codeManager = new RazorCodeManager(this));
//private RazorCodeManager _codeManager;

/// <inheritdoc />
public dynamic Code => CodeManager.CodeOrException;
///// <inheritdoc />
//public dynamic Code => CodeManager.CodeOrException;

#endregion
//#endregion



Expand Down
36 changes: 18 additions & 18 deletions Src/Dnn/ToSic.Sxc.Razor/Custom/Dnn/Razor12Code.cs
@@ -1,21 +1,21 @@
using ToSic.Eav.Documentation;
//using ToSic.Eav.Documentation;

// ReSharper disable once CheckNamespace
namespace Custom.Dnn
{
/// <summary>
/// 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: Razor12
{
//// ReSharper disable once CheckNamespace
//namespace Custom.Dnn
//{
// /// <summary>
// /// 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: Razor12
// {


}
}
// }
//}
6 changes: 0 additions & 6 deletions Src/Dnn/ToSic.Sxc.Razor/Custom/Hybrid/Razor12_Obsolete.cs
Expand Up @@ -110,11 +110,5 @@ public IEnumerable<dynamic> AsDynamic(IEnumerable<IEntity> entities)

#endregion


[PrivateApi]
[Obsolete("left for compatibility, use Purpose instead")]
public object InstancePurpose
=> throw new Exception($"InstancePurpose {NotSupportedIn10}. Use Purpose");

}
}
7 changes: 1 addition & 6 deletions Src/Dnn/ToSic.Sxc.Razor/Dnn/IDnnRazor.cs
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ToSic.Sxc.Dnn.Web;
using ToSic.Sxc.Dnn.Web;

namespace ToSic.Sxc.Dnn
{
Expand Down
7 changes: 1 addition & 6 deletions Src/Dnn/ToSic.Sxc.Razor/Dnn/IDnnRazor11.cs
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ToSic.Eav.Documentation;
using ToSic.Eav.Documentation;

namespace ToSic.Sxc.Dnn
{
Expand Down
11 changes: 1 addition & 10 deletions Src/Dnn/ToSic.Sxc.Razor/Dnn/RazorComponent.NewNotAvailable.cs
@@ -1,19 +1,10 @@
using System;
using ToSic.Eav.Documentation;
using ToSic.SexyContent.Razor;
using ToSic.Sxc.Web;

namespace ToSic.Sxc.Dnn
namespace ToSic.Sxc.Dnn
{
public abstract partial class RazorComponent
{

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

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

}
}
3 changes: 2 additions & 1 deletion Src/Dnn/ToSic.Sxc.Razor/Web/RazorComponentBase.cs
Expand Up @@ -7,6 +7,7 @@
using ToSic.Eav.Logging;
using ToSic.Eav.Logging.Simple;
using ToSic.Sxc.Code;
using ToSic.Sxc.Dnn;
using ToSic.Sxc.Dnn.Web;
using ToSic.Sxc.Engines.Razor;
using File = System.IO.File;
Expand All @@ -19,7 +20,7 @@ namespace ToSic.Sxc.Web
/// It only contains internal wiring stuff, so not to be published
/// </summary>
[PrivateApi("internal class only!")]
public abstract partial class RazorComponentBase: WebPageBase, ICreateInstance, IHasLog, ICoupledDynamicCode, IRazor
public abstract partial class RazorComponentBase: WebPageBase, ICreateInstance, IHasLog, ICoupledDynamicCode, IRazor, IDnnRazor
{
public IHtmlHelper Html => _html ?? (_html = new HtmlHelper(this));
private IHtmlHelper _html;
Expand Down
2 changes: 1 addition & 1 deletion Src/Razor/ToSic.Sxc.Razor/Custom.Hybrid/Razor12_T_Block.cs
Expand Up @@ -6,7 +6,7 @@
// ReSharper disable once CheckNamespace
namespace Custom.Hybrid
{
public partial class Razor12<TModel>: IRazor12
public partial class Razor12<TModel>: IRazor, IRazor12
{
const string DynCode = "_dynCode";

Expand Down
3 changes: 3 additions & 0 deletions Src/Sxc/ToSic.Sxc.WebApi/IDynamicWebApi.cs
Expand Up @@ -45,6 +45,9 @@ public interface IDynamicWebApi
/// <param name="fileDownloadName">Download name. If provided, it will try to force download/save on the browser. </param>
/// <param name="contents">Content of the result - a string, byte[] or stream to include.</param>
/// <returns></returns>
/// <remarks>
/// Added in 2sxc 12.05
/// </remarks>
dynamic File(string noParamOrder = ToSic.Eav.Parameters.Protector,
// Important: the second parameter should _not_ be a string, otherwise the signature looks the same as the built-in File(...) method
bool? download = null,
Expand Down

0 comments on commit d7c67bd

Please sign in to comment.