Skip to content

Commit

Permalink
Merge pull request #3392 from 2sic/develop
Browse files Browse the repository at this point in the history
Release 17.09
  • Loading branch information
iJungleboy authored May 22, 2024
2 parents e96aec6 + 814a7e9 commit 6a06fe2
Show file tree
Hide file tree
Showing 38 changed files with 1,003 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private LookUpEngine BuildDnnBasedLookupEngine(PortalSettings portalSettings, in
{
{ KeyId, original.Get(OldDnnModuleId) }
});
additions.Add(new LookUpInLookUps(SourceModule, modAdditional, original));
additions.Add(new LookUpInLookUps(SourceModule, [modAdditional, original]));
}

// Create the lookup for "site" based on the "portal" and only give it "id" & "guid"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private CSharpCodeProvider GetCSharpCodeProvider()
{
var l = Log.Fn<CSharpCodeProvider>();
// See if in memory cache
if (memoryCacheService.Get(CSharpCodeProviderCacheKey) is CSharpCodeProvider fromCache)
if (memoryCacheService.TryGet<CSharpCodeProvider>(CSharpCodeProviderCacheKey, out var fromCache))
return l.Return(fromCache, "from cached");

var codeProvider = new CSharpCodeProvider(); // TODO: @stv test with latest nuget package for @inherits ; issue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private HttpControllerDescriptor Get(string appFolder, string editionPath, strin
//SetPathForCompilersInsideController(appFolder, editionPath, controllerTypeName, shared);

var descriptorCacheKey = CacheKey(appFolder, controllerTypeName, shared, spec);
if (memoryCacheService.Get(descriptorCacheKey) is HttpControllerDescriptorWithPaths dataWithPaths)
if (memoryCacheService.TryGet<HttpControllerDescriptorWithPaths>(descriptorCacheKey, out var dataWithPaths))
{
PreservePathForGetCodeInController(dataWithPaths.Folder, dataWithPaths.FullPath);
return dataWithPaths.Descriptor;
Expand Down
2 changes: 1 addition & 1 deletion Src/Dnn/ToSic.Sxc.Dnn/DnnPackageBuilder/ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<dl>
<dt>v17.08.00</dt>
<dt>v17.09.00</dt>
<dd>Part of module installation is the deletion of unneeded data. In an infrequent case, You could get a
timeout exception. This is not a show-stopper. Simply reload the page so DNN can continue deletion
until all unnecessary data is deleted and the module is installed.</dd>
Expand Down
8 changes: 4 additions & 4 deletions Src/Dnn/ToSic.Sxc.Dnn/DnnPackageBuilder/ToSic.Sxc.Dnn.dnn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="2SexyContent" type="Module" version="17.08.00">
<package name="2SexyContent" type="Module" version="17.09.00">
<friendlyName> Content</friendlyName>
<description>2sxc is a DNN Extension to create attractive and designed content. It solves the common problem, allowing the web designer to create designed templates for different content elements, so that the user must only fill in fields and receive a perfectly designed and animated output.</description>
<iconFile>icon.png</iconFile>
Expand Down Expand Up @@ -69,7 +69,7 @@
<script type="UnInstall">
<path>SqlDataProvider</path>
<name>Uninstall.SqlDataProvider</name>
<version>17.08.00</version>
<version>17.09.00</version>
</script>
</scripts>
</component>
Expand Down Expand Up @@ -120,7 +120,7 @@
<businessControllerClass>ToSic.SexyContent.DnnBusinessController</businessControllerClass>
<desktopModuleID>[DESKTOPMODULEID]</desktopModuleID>
<!-- This must contain all versions which have upgrade-code. By convention, we also add the main entry versions, even if no upgrade code exists for them -->
<upgradeVersionsList>01.00.00,08.11.00,08.12.00,09.00.00,10.00.00,11.00.00,12.00.00,13.00.00,13.01.00,13.04.00,14.00.00,15.00.00,15.02.00,16.00.00,16.07.01,17.00.00,17.08.00</upgradeVersionsList>
<upgradeVersionsList>01.00.00,08.11.00,08.12.00,09.00.00,10.00.00,11.00.00,12.00.00,13.00.00,13.01.00,13.04.00,14.00.00,15.00.00,15.02.00,16.00.00,16.07.01,17.00.00,17.09.00</upgradeVersionsList>
</attributes>
</eventMessage>
</component>
Expand Down Expand Up @@ -627,7 +627,7 @@
</components>
</package>

<package name="2SexyContent-App" type="Module" version="17.08.00">
<package name="2SexyContent-App" type="Module" version="17.09.00">
<friendlyName> App</friendlyName>
<description>2sxc App is an extension that allows to install and use a 2sxc app.</description>
<iconFile>icon-app.png</iconFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>ToSic.Sxc.Oqtane.Install</id>
<version>17.08.00</version>
<version>17.09.00</version>
<authors>2sic internet solutions GmbH, Switzerland</authors>
<owners>2sic internet solutions GmbH, Switzerland</owners>
<title>2sxc CMS and Meta-Module for Oqtane</title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static Task PageOutputCached(HttpContext context, IWebHostEnvironment env

var key = CacheKey(virtualPath);
var memoryCacheService = sp.GetService<MemoryCacheService>();
if (memoryCacheService.Get(key) is not string html)
if (!memoryCacheService.TryGet<string>(key, out var html))
{
var path = Path.Combine(env.WebRootPath, virtualPath);
if (!File.Exists(path)) throw new FileNotFoundException("File not found: " + path);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using ToSic.Sxc.Services.Cache;
using static Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
using static ToSic.Sxc.Services.Cache.CacheServiceConstants;

namespace ToSic.Sxc.Tests.ServicesTests.CacheTests;

[TestClass]
public class CacheKeyTests
{
internal const string FullDefaultPrefix = $"{DefaultPrefix}{Sep}App:0{Sep}{SegmentPrefix}{DefaultSegment}{Sep}";

[DataRow(null)]
[DataRow("")]
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void MainKeyBad(string main)
=> AreEqual(FullDefaultPrefix + main, new CacheKeySpecs(0, main).Key);

[DataRow(Sep + "App:0", 0, "zero")]
[DataRow(Sep + "App:27", 27, "27")]
[DataRow(Sep + "App:42", 42, "42")]
[DataRow("", CacheKeySpecs.NoApp, "no app")]
[TestMethod]
public void MainKeyAppIds(string expectedReplace, int appId, string message)
=> AreEqual(FullDefaultPrefix.Replace(Sep + "App:0", expectedReplace) + "Test", new CacheKeySpecs(appId, "Test").Key, message);



[DataRow("TestKey")]
[DataRow("A")]
[DataRow("A\nB")]
[TestMethod]
public void MainKeyOnly(string main)
=> AreEqual( FullDefaultPrefix + main, new CacheKeySpecs(0, main).Key);

private const string FullSegmentPrefix = $"{DefaultPrefix}{Sep}App:0{Sep}{SegmentPrefix}";

[DataRow($"{DefaultSegment}{Sep}Main", "Main", null)]
[DataRow($"{DefaultSegment}{Sep}Main", "Main", "")]
[DataRow($"MySegment{Sep}Main", "Main", "MySegment")]
[TestMethod]
public void MainAndSegment(string expected, string main, string segment)
=> AreEqual( FullSegmentPrefix + expected, new CacheKeySpecs(0, main, segment).Key);


[TestMethod]
public void EnsureDicIsSorted()
{
var expected = $"{Sep}A=AVal{Sep}B=BVal{Sep}C=CVal";
var dic = new Dictionary<string, string>
{
{ "B", "BVal" },
{ "A", "AVal" },
{ "C", "CVal" }
};
var resultDic1 = CacheKeySpecs.GetVaryByOfDic(dic);
AreEqual(expected, resultDic1);

var dic2 = new Dictionary<string, string>
{
{ "C", "CVal" },
{ "A", "AVal" },
{ "B", "BVal" }
};
var resultDic2 = CacheKeySpecs.GetVaryByOfDic(dic2);
AreEqual(expected, resultDic2);
AreEqual(resultDic1, resultDic2);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ToSic.Sxc.Context.Internal;
using ToSic.Sxc.Services;
using ToSic.Sxc.Services.Cache;
using static Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
using static ToSic.Sxc.Services.Cache.CacheServiceConstants;

namespace ToSic.Sxc.Tests.ServicesTests.CacheTests;

[TestClass]
public class CacheSpecsTests: TestBaseSxcDb
{
private static readonly string MainPrefix = $"{CacheKeyTests.FullDefaultPrefix.Replace("App:0", "App:-1")}Main{Sep}";

private ICacheSpecs GetForMain(string name = "Main") => GetService<ICacheService>().CreateSpecs(name);

[TestMethod]
public void ShareKeyAcrossApps()
{
var expected = $"{CacheKeyTests.FullDefaultPrefix.Replace(Sep + "App:0", "")}Main";
var svc = GetService<ICacheService>();
var specs = svc.CreateSpecs("Main", shared: true);
AreEqual(expected, specs.Key);
}

[TestMethod]
public void VaryByCustom1CaseSensitive()
{
var expected = MainPrefix + "VaryByKey1=Value1";
var svc = GetService<ICacheService>();
var specs = svc.CreateSpecs("Main")
.VaryBy("Key1", "Value1", caseSensitive: true);
AreEqual(expected, specs.Key);
}

[TestMethod]
public void VaryByCustom1()
{
var expected = MainPrefix + "VaryByKey1=Value1".ToLowerInvariant();
var specs = GetForMain()
.VaryBy("Key1", "Value1");
AreEqual(expected, specs.Key);
}

[TestMethod]
public void VaryByCustom2SameKey()
{
var expected = MainPrefix + "VaryByKey1=Value1".ToLowerInvariant();
var specs = GetForMain()
.VaryBy("Key1", "valueWhichWillGoAway")
.VaryBy("Key1", "Value1");
AreEqual(expected, specs.Key);
}

[TestMethod]
public void VaryByCustom2DiffKey()
{
var expected = MainPrefix + $"VaryByKey1=Val1{Sep}VaryByKey2=Value2".ToLowerInvariant();
var specs = GetForMain()
.VaryBy("Key1", "Val1")
.VaryBy("Key2", "Value2");
AreEqual(expected, specs.Key);
}

// Disabled for now, not sure if this single-value case is needed
//[TestMethod]
//public void VaryByCustom1ValueOnly()
//{
// var expected = MainPrefix + "VaryByThisIsTheValue=".ToLowerInvariant();
// var specs = GetForMain()
// .VaryBy("ThisIsTheValue");
// AreEqual(expected, specs.Key);
//}

[TestMethod]
public void VaryByParameters()
{
var expected = MainPrefix + "VaryByParameters=".ToLowerInvariant();
var pars = new Parameters();
var specs = GetForMain().VaryByParameters(pars);
AreEqual(expected, specs.Key);
}

[DataRow(null, "no names specified")]
[DataRow("", "empty names specified")]
[DataRow("A,B,C", "too many names")]
[DataRow("A", "names with exact casing")]
[DataRow("a", "names with different casing")]
[TestMethod]
public void VaryByParametersOneNamed(string names, string testName)
{
var expected = MainPrefix + "VaryByParameters=A=AVal".ToLowerInvariant();
var pars = new Parameters(new()
{
{ "A", "AVal" }
});
var specs = GetForMain().VaryByParameters(pars, names: names);
AreEqual(expected, specs.Key, testName);
}


[TestMethod]
public void VaryByParametersWithNamesAll()
{
var expected = MainPrefix + "VaryByParameters=A=AVal&B=BVal&C=CVal".ToLowerInvariant();
var pars = new Parameters(new()
{
{ "A", "AVal" },
{ "B", "BVal" },
{ "C", "CVal" }
});
var specs = GetForMain().VaryByParameters(pars, names: "A,B,c");
AreEqual(expected, specs.Key);
}

[TestMethod]
public void VaryByParametersWithNamesSome()
{
var expected = MainPrefix + "VaryByParameters=A=AVal&C=CVal".ToLowerInvariant();
var pars = new Parameters(new()
{
{ "A", "AVal" },
{ "B", "BVal" },
{ "C", "CVal" }
});
var specs = GetForMain().VaryByParameters(pars, names: "A,c");
AreEqual(expected, specs.Key);
}

[TestMethod]
public void VaryByParametersBlankSameAsNone()
{
var expected = MainPrefix + "VaryByParameters=A=AVal&C=CVal".ToLowerInvariant();
var pars = new Parameters(new()
{
{ "A", "AVal" },
{ "B", "" },
{ "C", "CVal" }
});
var specsFiltered = GetForMain().VaryByParameters(pars, names: "A,c");
var specsAll = GetForMain().VaryByParameters(pars);
AreEqual(expected, specsFiltered.Key);
AreEqual(specsFiltered.Key, specsAll.Key);
}

}
2 changes: 2 additions & 0 deletions Src/Sxc.Tests/ToSic.Sxc.Tests/ToSic.Sxc.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@
<Compile Include="DataTests\HasKeysTests.cs" />
<Compile Include="DataTests\TypedItemTestAccessors.cs" />
<Compile Include="LinksAndImages\ParametersTestExtensions.cs" />
<Compile Include="ServicesTests\CacheTests\CacheSpecsTests.cs" />
<Compile Include="ServicesTests\CacheTests\CacheKeyTests.cs" />
<Compile Include="ServicesTests\CmsService\CmsServiceTest.cs" />
<Compile Include="ServicesTests\CmsService\CmsServiceTestBase.cs" />
<Compile Include="DataTests\DynWrappers\WrapObjDeep.cs" />
Expand Down
19 changes: 10 additions & 9 deletions Src/Sxc/ToSic.Sxc.WebApi/Backend/AppStack/AppStackBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class AppStackBackend(
AppDataStackService dataStackService,
IZoneCultureResolver zoneCulture,
IAppStates appStates,
LazySvc<QueryDefinitionBuilder> qDefBuilder)
Generator<QueryDefinitionBuilder> qDefBuilder)
: ServiceBase("Sxc.ApiApQ", connect: [dataStackService, zoneCulture, appStates])
{
public List<AppStackDataRaw> GetAll(int appId, string part, string key, Guid? viewGuid, string[] languages)
Expand Down Expand Up @@ -56,15 +56,16 @@ public List<PropertyDumpItem> GetStackDump(IAppState appState, string partName,

private IEntity GetViewSettingsForMixin(Guid? viewGuid, string[] languages, IAppEntityService appState, string realName)
{
IEntity viewStackPart = null;
if (viewGuid != null)
{
var viewEnt = appState.List.One(viewGuid.Value);
if (viewEnt == null) throw new($"Tried to get view but not found. Guid was {viewGuid}");
var view = new View(viewEnt, languages, Log, qDefBuilder);
if (viewGuid == null)
return null;

viewStackPart = realName == RootNameSettings ? view.Settings : view.Resources;
}
var viewEnt = appState.List.One(viewGuid.Value)
?? throw new($"Tried to get view but not found. Guid was {viewGuid}");

var view = new View(viewEnt, languages, Log, qDefBuilder);
var viewStackPart = realName == RootNameSettings
? view.Settings
: view.Resources;

return viewStackPart;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ViewsExportImport(
AppIconHelpers appIconHelpers,
Generator<ImpExpHelpers> impExpHelpers,
IResponseMaker responseMaker,
LazySvc<QueryDefinitionBuilder> qDefBuilder,
Generator<QueryDefinitionBuilder> qDefBuilder,
IAppPathsMicroSvc appPathSvc)
: ServiceBase("Bck.Views",
connect:
Expand Down
Loading

0 comments on commit 6a06fe2

Please sign in to comment.