Skip to content

Commit

Permalink
Merge pull request 8068 from hotfix/v4.4.9 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Project Collection Build Service (51degrees) authored and Project Collection Build Service (51degrees) committed Jan 13, 2023
2 parents 22db525 + cde169d commit 10d9eab
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 2 deletions.
43 changes: 43 additions & 0 deletions FiftyOne.Pipeline.Engines.TestHelpers/GenericEngine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using FiftyOne.Pipeline.Core.Data;
using FiftyOne.Pipeline.Core.FlowElements;
using FiftyOne.Pipeline.Engines.Data;
using FiftyOne.Pipeline.Engines.FlowElements;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;

namespace FiftyOne.Pipeline.Engines.TestHelpers
{
public class GenericEngine<T> : AspectEngineBase<T, IAspectPropertyMetaData>
where T : IAspectData
{
public override string DataSourceTier { get; }

public override string ElementDataKey { get; }

public override IEvidenceKeyFilter EvidenceKeyFilter => new EvidenceKeyFilterWhitelist(new List<string>());

public override IList<IAspectPropertyMetaData> Properties { get; }

public GenericEngine(
ILogger<GenericEngine<T>> logger,
string tier,
string dataKey,
IList<IAspectPropertyMetaData> properties) :
base(logger, (p, e) => default(T))
{
DataSourceTier = tier;
ElementDataKey = dataKey;
Properties = properties;
}

protected override void ProcessEngine(IFlowData data, T aspectData)
{
}

protected override void UnmanagedResourcesCleanup()
{
}
}
}
77 changes: 76 additions & 1 deletion FiftyOne.Pipeline.Engines/Services/MissingPropertyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ public class MissingPropertyService : IMissingPropertyService
private static IMissingPropertyService _instance;
private static object _lock = new object();

/// <summary>
/// Used to store the results of looking up whether a property is available or not.
/// <seealso cref="EngineDataContainsPropertyGetter"/>
/// The key is the engine type. The inner dictionary is keyed on property name.
/// </summary>
private static Dictionary<Type, Dictionary<string, bool>> _propertyAvailable =
new Dictionary<Type, Dictionary<string, bool>>();

/// <summary>
/// Get the singleton instance of this service.
/// </summary>
Expand Down Expand Up @@ -149,6 +157,14 @@ public MissingPropertyResult GetMissingPropertyReason(string propertyName, IAspe
reason = MissingPropertyReason.PropertyNotAccessibleWithResourceKey;
}
}
else if (reason == MissingPropertyReason.Unknown &&
EngineDataContainsPropertyGetter(propertyName, engine))
{
// If the property meta data is not available, but the engine
// data class defines a getter, it's safe to assume that the data
// file needs upgrading.
reason = MissingPropertyReason.DataFileUpgradeRequired;
}

// Build the message string to return to the caller.
StringBuilder message = new StringBuilder();
Expand All @@ -163,7 +179,9 @@ public MissingPropertyResult GetMissingPropertyReason(string propertyName, IAspe
message.Append(
string.Format(CultureInfo.InvariantCulture,
Messages.MissingPropertyMessageDataUpgradeRequired,
string.Join(",", property.DataTiersWherePresent),
property == null ?
"Unknown" :
string.Join(",", property.DataTiersWherePresent),
engine.GetType().Name));
break;
case MissingPropertyReason.PropertyExcludedFromEngineConfiguration:
Expand Down Expand Up @@ -193,5 +211,62 @@ public MissingPropertyResult GetMissingPropertyReason(string propertyName, IAspe
result.Reason = reason;
return result;
}

/// <summary>
/// Return true if there is an explicit property getter for the name provided
/// in the data type returned by the engine.
/// </summary>
/// <param name="propertyName"></param>
/// <param name="engine"></param>
/// <returns></returns>
private bool EngineDataContainsPropertyGetter(string propertyName, IAspectEngine engine)
{
// Get the property dictionary for this engine
Dictionary<string, bool> engineProperties;
if(_propertyAvailable.TryGetValue(engine.GetType(), out engineProperties) == false)
{
lock (_propertyAvailable)
{
if (_propertyAvailable.TryGetValue(engine.GetType(), out engineProperties) == false)
{
engineProperties = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
_propertyAvailable.Add(engine.GetType(), engineProperties);
}
}
}

// If we don't have a stored result in the dictionary for this property then use
// reflection to figure it out.
if (engineProperties.TryGetValue(propertyName, out var result) == false)
{
result = false;

foreach (var dataType in engine.GetType().GetInterfaces().SelectMany(i => i.GetGenericArguments())
.Where(i => typeof(IAspectData).IsAssignableFrom(i)))
{
if (dataType != null && result == false)
{
foreach (var property in dataType.GetProperties())
{
if (property.Name.Equals(propertyName, StringComparison.InvariantCultureIgnoreCase))
{
result = true;
break;
}
}
}
}

// Add the result to the property dictionary.
lock (engineProperties)
{
if (engineProperties.ContainsKey(propertyName) == false)
{
engineProperties.Add(propertyName, result);
}
}
}
return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@
* such notice(s) shall fulfill the requirements of that article.
* ********************************************************************* */

using FiftyOne.Pipeline.Core.Data;
using FiftyOne.Pipeline.Core.FlowElements;
using FiftyOne.Pipeline.Core.TypedMap;
using FiftyOne.Pipeline.Engines.Caching;
using FiftyOne.Pipeline.Engines.Configuration;
using FiftyOne.Pipeline.Engines.Data;
using FiftyOne.Pipeline.Engines.FlowElements;
using FiftyOne.Pipeline.Engines.Services;
using FiftyOne.Pipeline.Engines.TestHelpers;
using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System;
Expand Down Expand Up @@ -62,6 +69,71 @@ public void MissingPropertyService_GetReason_Upgrade()
Assert.AreEqual(MissingPropertyReason.DataFileUpgradeRequired, result.Reason);
}

public interface ITestData : IAspectData
{
public string TestProperty { get; }
}

/// <summary>
/// Check that when the property meta data is not present, so the data tier
/// cannot be checked, that an upgrade message is returned correctly.
/// This will be the case if the property is not present in the data file,
/// but there is an explicit getter for it in the data class.
/// </summary>
[TestMethod]
public void MissingPropertyService_GetReason_UnknownUpgrade()
{
// Arrange
GenericEngine<ITestData> engine = new GenericEngine<ITestData>(
new Mock<ILogger<GenericEngine<ITestData>>>().Object,
"lite",
"test",
new List<IAspectPropertyMetaData>());

// Act
var result = _service.GetMissingPropertyReason("testProperty", engine);

// Assert
Assert.AreEqual(MissingPropertyReason.DataFileUpgradeRequired, result.Reason);
}

public class InheritedTestEngine : GenericEngine<ITestData>
{
public InheritedTestEngine(
ILogger<GenericEngine<ITestData>> logger,
string tier,
string dataKey,
IList<IAspectPropertyMetaData> properties)
: base(logger, tier, dataKey, properties)
{
}
}

/// <summary>
/// Check that when the property meta data is not present, so the data tier
/// cannot be checked, that an upgrade message is returned correctly.
/// This will be the case if the property is not present in the data file,
/// but there is an explicit getter for it in the data class.
/// This test uses a further inherited class to check that the data type
/// can still be worked out if the generic data type is burried.
/// </summary>
[TestMethod]
public void MissingPropertyService_GetReason_UnknownUpgrade_Inherited()
{
// Arrange
InheritedTestEngine engine = new InheritedTestEngine(
new Mock<ILogger<InheritedTestEngine>>().Object,
"lite",
"test",
new List<IAspectPropertyMetaData>());

// Act
var result = _service.GetMissingPropertyReason("testProperty", engine);

// Assert
Assert.AreEqual(MissingPropertyReason.DataFileUpgradeRequired, result.Reason);
}

/// <summary>
/// Check that the missing property service works as expected when
/// the property has been excluded from the result set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,35 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="FiftyOne.Caching, Version=4.4.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\FiftyOne.Caching.4.4.1\lib\netstandard2.0\FiftyOne.Caching.dll</HintPath>
</Reference>
<Reference Include="FiftyOne.Common, Version=4.4.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\FiftyOne.Common.4.4.1\lib\netstandard2.0\FiftyOne.Common.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NUglify, Version=1.5.12.0, Culture=neutral, PublicKeyToken=15bc7810aec21b5e, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\NUglify.1.5.12\lib\net40\NUglify.dll</HintPath>
</Reference>
<Reference Include="Stubble.Core, Version=1.7.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Stubble.Core.1.7.2\lib\net45\Stubble.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\System.Collections.Immutable.1.5.0\lib\netstandard2.0\System.Collections.Immutable.dll</HintPath>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\System.Threading.Tasks.Extensions.4.5.1\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Entity" />
<Reference Include="System.Web.ApplicationServices" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<packages>
<package id="Antlr" version="3.5.0.2" targetFramework="net472" />
<package id="bootstrap" version="3.4.1" targetFramework="net472" />
<package id="FiftyOne.Caching" version="4.4.1" targetFramework="net462" />
<package id="FiftyOne.Common" version="4.4.1" targetFramework="net462" />
<package id="jQuery" version="3.3.1" targetFramework="net472" />
<package id="jQuery.Validation" version="1.17.0" targetFramework="net472" />
<package id="Microsoft.AspNet.Mvc" version="5.2.4" targetFramework="net472" />
Expand All @@ -14,6 +16,11 @@
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net472" />
<package id="Modernizr" version="2.8.3" targetFramework="net472" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net462" />
<package id="NUglify" version="1.5.12" targetFramework="net462" />
<package id="Stubble.Core" version="1.7.2" targetFramework="net462" />
<package id="System.Collections.Immutable" version="1.5.0" targetFramework="net462" />
<package id="System.Diagnostics.DiagnosticSource" version="4.4.1" targetFramework="net472" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.0" targetFramework="net462" />
<package id="System.Threading.Tasks.Extensions" version="4.5.1" targetFramework="net462" />
<package id="WebGrease" version="1.6.0" targetFramework="net472" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ private void OnBeginRequestJavascript(object sender, EventArgs e)
StringComparison.OrdinalIgnoreCase))
{
FiftyOneJsProvider.GetInstance().ServeJavascript(context);
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
if (context.Request.Path.EndsWith("51dpipeline/json",
StringComparison.OrdinalIgnoreCase))
{
FiftyOneJsProvider.GetInstance().ServeJson(context);
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ci/common-ci
Submodule common-ci updated 1 files
+9 −60 release-config.json

0 comments on commit 10d9eab

Please sign in to comment.