Skip to content

Commit

Permalink
Merge pull request #3368 from 2sic/develop
Browse files Browse the repository at this point in the history
v17.07
  • Loading branch information
iJungleboy committed May 1, 2024
2 parents c1a40d8 + 1c92289 commit 2692fe5
Show file tree
Hide file tree
Showing 133 changed files with 1,266 additions and 835 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ namespace ToSic.Eav;
/// <summary>
/// The Eav DI Factory, used to construct various objects through [Dependency Injection](xref:NetCode.DependencyInjection.Index).
///
/// If possible avoid using this, as it's a workaround for code which is outside of the normal Dependency Injection and therefor a bad pattern.
/// If possible avoid using this, as it's a workaround for code which is outside the normal Dependency Injection and therefor a bad pattern.
/// </summary>
[PublicApi("Careful - obsolete!")]
[Obsolete("Deprecated, please use Dnn 9 DI instead https://go.2sxc.org/brc-13-eav-factory")]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public class Factory
{
[Obsolete("Not used any more, but keep for API consistency in case something calls ActivateNetCoreDi")]
Expand All @@ -23,7 +24,9 @@ public class Factory
/// Dependency Injection resolver with a known type as a parameter.
/// </summary>
/// <typeparam name="T">The type / interface we need.</typeparam>
[PrivateApi]
[Obsolete("Please use standard Dnn 9.4+ Dnn DI instead https://go.2sxc.org/brc-13-eav-factory")]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public static T Resolve<T>()
{
DnnStaticDi.CodeInfos.Warn(WarnObsolete.UsedAs(specificId: typeof(T).FullName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace ToSic.Sxc.Compatibility;

public static class StartUpCompatibility
internal static class StartUpCompatibility
{
/// <summary>
/// Add obsolete interfaces which had previously been supported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace ToSic.Sxc.Compatibility.Sxc;
/// </summary>
// Important: Changed Dictionary... to IDictionary in 12.04 2021-08-29 - may cause issues, but probably shouldn't
[Obsolete]
[PrivateApi]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public class OldDataToDictionaryWrapper
{
public OldDataToDictionaryWrapper(bool userMayEdit, IConvertToEavLight innerConverter)
Expand Down
14 changes: 4 additions & 10 deletions Src/Dnn/ToSic.Sxc.Dnn.Core/Compatibility/Sxc/SxcHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ namespace ToSic.Sxc.Compatibility.Sxc;
/// This is for compatibility - old code had a Sxc.Serializer.Prepare code which should still work
/// </summary>
[Obsolete]
public class SxcHelper
[PrivateApi]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public class SxcHelper(bool editAllowed, IConvertToEavLight innerConverter)
{
public SxcHelper(bool editAllowed, IConvertToEavLight innerConverter)
{
_editAllowed = editAllowed;
_innerConverter = innerConverter;
}
private readonly bool _editAllowed;
private readonly IConvertToEavLight _innerConverter;

public OldDataToDictionaryWrapper Serializer => _entityToDictionary ??= new(_editAllowed, _innerConverter);
public OldDataToDictionaryWrapper Serializer => _entityToDictionary ??= new(editAllowed, innerConverter);
private OldDataToDictionaryWrapper _entityToDictionary;
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using ToSic.Eav.Data.Build;
using ToSic.Eav.DataSources;

// ReSharper disable once CheckNamespace
namespace ToSic.SexyContent.Environment.Dnn7.DataSources;

[PrivateApi]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
[Obsolete("This class was moved / to ToSic.Sxc.Dnn.DataSources.DnnSql, use that instead.")]
public class DnnSqlDataSource : Sxc.Dnn.DataSources.DnnSql
public class DnnSqlDataSource(Sql.MyServices services, IDataFactory dataFactory)
: Sxc.Dnn.DataSources.DnnSql(services, dataFactory)
{
// Todo: leave this helper class/message in till 2sxc 09.00, then either extract into an own DLL
// - we might also write some SQL to update existing pipelines, but it's not likely to have been used much...
// - and otherwise im might be in razor-code, which we couldn't auto-update

public DnnSqlDataSource(MyServices services, IDataFactory dataFactory) : base(services, dataFactory)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using ToSic.Eav.Data.Build;
using ToSic.Sxc.Dnn.DataSources;

// ReSharper disable once CheckNamespace
namespace ToSic.SexyContent.Environment.Dnn7.DataSources;

[PrivateApi]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
[Obsolete("This class was moved / to ToSic.Sxc.Dnn.DataSources.DnnUserProfile, use that instead.")]
public class DnnUserProfileDataSource : ToSic.Sxc.Dnn.DataSources.DnnUserProfile
public class DnnUserProfileDataSource(DnnUserProfile.MyServices services, IDataFactory dataFactory)
: ToSic.Sxc.Dnn.DataSources.DnnUserProfile(services, dataFactory)
{
// Todo: leave this helper class/message in till 2sxc 09.00, then either extract into an own DLL
// - we might also write some SQL to update existing pipelines, but it's not likely to have been used much...
// - and otherwise im might be in razor-code, which we couldn't auto-update

public DnnUserProfileDataSource(MyServices services, IDataFactory dataFactory) : base(services, dataFactory) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
namespace ToSic.Sxc.Services;

/// <summary>
/// Obsolete, use <see cref="ToSic.Sxc.Services.ISystemLogService"/> instead
/// Obsolete, use <see cref="ISystemLogService"/> instead.
/// Note: 2024-04-22 2dm - believe this could be internal, but not 100% sure
/// </summary>
public interface ILogService: ToSic.Sxc.Services.ISystemLogService
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public interface ILogService: ISystemLogService
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace ToSic.Sxc.Services;

/// <summary>
/// Obsolete, use <see cref="ToSic.Sxc.Services.ISystemLogService"/> instead
/// Obsolete, use <see cref="ISystemLogService"/> instead
/// </summary>
internal class LogServiceUsingOldInterface: DnnSystemLogService
{
Expand Down
2 changes: 1 addition & 1 deletion Src/Dnn/ToSic.Sxc.Dnn.Core/Dnn/Cms/DnnPagePublishing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void DoInsidePublishing(IContextOfSite context, Action<VersioningActionIn
var possibleContextOfBlock = context as IContextOfBlock;
var enabled = possibleContextOfBlock?.Publishing.ForceDraft ?? false;
var instanceId = possibleContextOfBlock?.Module.Id ?? Eav.Constants.IdNotInitialized;
var userId = (context.User as DnnUser)?.UnwrappedContents.UserID ?? Eav.Constants.IdNotInitialized;
var userId = (context.User as DnnUser)?.GetContents().UserID ?? Eav.Constants.IdNotInitialized;
Log.A($"DoInsidePublishing(module:{instanceId}, user:{userId}, enabled:{enabled})");

if (enabled)
Expand Down
54 changes: 26 additions & 28 deletions Src/Dnn/ToSic.Sxc.Dnn.Core/Dnn/Compile/AppCode.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,43 @@
using System.IO;
using System.Web;

namespace ToSic.Sxc.Dnn.Compile
namespace ToSic.Sxc.Dnn.Compile;

/// <summary>
/// DNN on start need to clean the "2sxc.bin", because it is used to temporary save shared temp AppCode assemblies.
/// </summary>
internal static class AppCode
{
/// <summary>
/// DNN on start need to clean the "2sxc.bin", because it is used to temporary save shared temp AppCode assemblies.
/// </summary>
[PrivateApi]
public static class AppCode
private static bool Cleaned { get; set; }
private static readonly object CleaningLock = new();
private static string TempAssemblyFolderPath { get; } = Path.Combine(HttpContext.Current.Server.MapPath("~/App_Data"), "2sxc.bin");

public static void CleanTempAssemblyFolder()
{
private static bool Cleaned { get; set; }
private static readonly object CleaningLock = new();
private static string TempAssemblyFolderPath { get; } = Path.Combine(HttpContext.Current.Server.MapPath("~/App_Data"), "2sxc.bin");
// Ensure that cleaning is executed only once
if (Cleaned) return;

public static void CleanTempAssemblyFolder()
lock (CleaningLock)
{
// Ensure that cleaning is executed only once
if (Cleaned) return;

lock (CleaningLock)
if (Directory.Exists(TempAssemblyFolderPath))
{
if (Cleaned) return;

if (Directory.Exists(TempAssemblyFolderPath))
var filesToClean = Directory.GetFiles(TempAssemblyFolderPath, "*.*", SearchOption.TopDirectoryOnly);
foreach (var file in filesToClean)
{
var filesToClean = Directory.GetFiles(TempAssemblyFolderPath, "*.*", SearchOption.TopDirectoryOnly);
foreach (var file in filesToClean)
try
{
try
{
File.Delete(file);
}
catch
{
// ignored
}
File.Delete(file);
}
catch
{
// ignored
}

}
Cleaned = true;

}
Cleaned = true;
}
}
}
}
19 changes: 19 additions & 0 deletions Src/Dnn/ToSic.Sxc.Dnn.Core/Dnn/Compile/AssemblyExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Reflection;
using System.Web.Configuration;

namespace ToSic.Sxc.Dnn.Compile
{
public static class AssemblyExtensions
{
// for assembly references
public static Assembly WithPolicy(this Assembly assembly)
=>
// apply binding redirections from web.config
Assembly.ReflectionOnlyLoad(System.AppDomain.CurrentDomain.ApplyPolicy(assembly.FullName));

public static Assembly WithPolicy(this AssemblyInfo ai)
=>
// apply binding redirections from web.config
Assembly.ReflectionOnlyLoad(System.AppDomain.CurrentDomain.ApplyPolicy(ai.Assembly));
}
}
27 changes: 13 additions & 14 deletions Src/Dnn/ToSic.Sxc.Dnn.Core/Dnn/Compile/DnnRoslynConstants.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
namespace ToSic.Sxc.Dnn.Compile
namespace ToSic.Sxc.Dnn.Compile;

internal class DnnRoslynConstants
{
internal class DnnRoslynConstants
{
/// <summary>
/// The web.config disable warnings which are in the default DNN web.config
/// </summary>
public const string DefaultDisableWarnings = "/nowarn:1659;1699;1701;612;618";
/// <summary>
/// The web.config disable warnings which are in the default DNN web.config
/// </summary>
public const string DefaultDisableWarnings = "/nowarn:1659;1699;1701;612;618";

/// <summary>
/// The default language version to use when compiling
/// </summary>
public const string DefaultLangVersion = "8"; // "7.3";
/// <summary>
/// The default language version to use when compiling
/// </summary>
public const string DefaultLangVersion = "8"; // "7.3";

public const string CompilerOptionLanguageVersion = $"/langversion:{DefaultLangVersion}";
}
}
public const string CompilerOptionLanguageVersion = $"/langversion:{DefaultLangVersion}";
}
27 changes: 13 additions & 14 deletions Src/Dnn/ToSic.Sxc.Dnn.Core/Dnn/Compile/HostingEnvironmentWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
namespace ToSic.Sxc.Dnn.Compile
namespace ToSic.Sxc.Dnn.Compile;

/// <summary>
/// wrapper around HostingEnvironment
/// </summary>
/// <remarks>to mock the wrapper in unit tests</remarks>
[PrivateApi]
public class HostingEnvironmentWrapper : IHostingEnvironmentWrapper
{
/// <summary>
/// wrapper around HostingEnvironment
/// </summary>
/// <remarks>to mock the wrapper in unit tests</remarks>
[PrivateApi]
public class HostingEnvironmentWrapper : IHostingEnvironmentWrapper
{
/// <summary>Maps a virtual path to a physical path on the server.</summary>
/// <param name="virtualPath">The virtual path (absolute or relative).</param>
/// <returns>The physical path on the server specified by <paramref name="virtualPath" />.</returns>
public string MapPath(string virtualPath) => System.Web.Hosting.HostingEnvironment.MapPath(virtualPath);
}
}
/// <summary>Maps a virtual path to a physical path on the server.</summary>
/// <param name="virtualPath">The virtual path (absolute or relative).</param>
/// <returns>The physical path on the server specified by <paramref name="virtualPath" />.</returns>
public string MapPath(string virtualPath) => System.Web.Hosting.HostingEnvironment.MapPath(virtualPath);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
namespace ToSic.Sxc.Dnn.Compile
namespace ToSic.Sxc.Dnn.Compile;

[PrivateApi]
public interface IHostingEnvironmentWrapper
{
[PrivateApi]
public interface IHostingEnvironmentWrapper
{
string MapPath(string virtualPath);
}
string MapPath(string virtualPath);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using ToSic.Sxc.Code.Internal.HotBuild;

namespace ToSic.Sxc.Dnn.Compile
namespace ToSic.Sxc.Dnn.Compile;

[PrivateApi]
public interface IReferencedAssembliesProvider
{
[PrivateApi]
public interface IReferencedAssembliesProvider
{
List<string> Locations(string virtualPath, HotBuildSpec spec);
}
List<string> Locations(string virtualPath, HotBuildSpec spec);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using ToSic.Eav.Apps.Internal;

namespace ToSic.Sxc.Dnn.Compile.Internal;

[PrivateApi]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public static class AppJsonExtensions
{

/// <summary>
/// Check that the app is configured in app.json to always use Roslyn compiler
/// </summary>
/// <param name="appJsonService"></param>
/// <param name="appId"></param>
/// <returns></returns>
public static bool DnnCompilerAlwaysUseRoslyn(this IAppJsonService appJsonService, int appId)
=> appJsonService.GetAppJson(appId)?.DotNet?.Compiler?.Equals("roslyn", StringComparison.OrdinalIgnoreCase) == true;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.IO;
using System.Web.Compilation;
using ToSic.Eav.Apps.Internal;
using ToSic.Sxc.Code.Internal.HotBuild;
using ToSic.Sxc.Code.Internal.SourceCode;

Expand All @@ -10,12 +11,15 @@ internal class CodeCompilerNetFull : CodeCompiler
{
private readonly IRoslynBuildManager _roslynBuildManager;
private readonly LazySvc<SourceAnalyzer> _sourceAnalyzer;
private readonly LazySvc<IAppJsonService> _appJson;

public CodeCompilerNetFull(IServiceProvider serviceProvider, IRoslynBuildManager roslynBuildManager, LazySvc<SourceAnalyzer> sourceAnalyzer) : base(serviceProvider)
public CodeCompilerNetFull(IServiceProvider serviceProvider, IRoslynBuildManager roslynBuildManager, LazySvc<SourceAnalyzer> sourceAnalyzer, LazySvc<IAppJsonService> appJson) : base(serviceProvider)
{

ConnectServices(
_roslynBuildManager = roslynBuildManager,
_sourceAnalyzer = sourceAnalyzer
_sourceAnalyzer = sourceAnalyzer,
_appJson = appJson
);
}

Expand All @@ -38,7 +42,7 @@ AssemblyResult ReportError(Exception ex, string additionalInfo)

try
{
if (codeFileInfo.IsHotBuildSupported())
if (_appJson.Value.DnnCompilerAlwaysUseRoslyn(spec.AppId) || codeFileInfo.IsHotBuildSupported())
return l.Return(_roslynBuildManager.GetCompiledAssembly(codeFileInfo, className, spec),
"Ok, RoslynBuildManager");
}
Expand Down
Loading

0 comments on commit 2692fe5

Please sign in to comment.