Select a tab to view language specific
aspect engine implementation.
First let's change the class to extend
CloudAspectEngineBase
. This has the type arguments of
IStarSignData
- the interface extending
aspect data which will be added to the
flow data, and
IAspectPropertyMetaData
- instead of
IElementPropertyMetaData
.
The existing constructor needs to change to match the CloudAspectEngineBase
class.
The constructor will also take a CloudRequestEngine
instance to get the available properties from.
public class SimpleCloudEngine : CloudAspectEngineBase<IStarSignData>
{
public SimpleCloudEngine(
ILogger<SimpleCloudEngine> logger,
Func<IPipeline, FlowElementBase<IStarSignData, IAspectPropertyMetaData>, IStarSignData> deviceDataFactory,
CloudRequestEngine engine)
: base(logger, deviceDataFactory)
{
if (engine == null)
{
throw new PipelineConfigurationException(
$"The '{GetType().Name}' requires a 'CloudRequestEngine' " +
$"before it in the Pipeline. This engine will be unable " +
$"to produce results until this is corrected.");
}
}
Now the abstract methods can be implemented to create a functional aspect engine.
public class SimpleCloudEngine : CloudAspectEngineBase<IStarSignData>
{
public SimpleCloudEngine(
ILogger<SimpleCloudEngine> logger,
Func<IPipeline, FlowElementBase<IStarSignData, IAspectPropertyMetaData>, IStarSignData> deviceDataFactory,
CloudRequestEngine engine)
: base(logger, deviceDataFactory)
{
if (engine == null)
{
throw new PipelineConfigurationException(
$"The '{GetType().Name}' requires a 'CloudRequestEngine' " +
$"before it in the Pipeline. This engine will be unable " +
$"to produce results until this is corrected.");
}
}
public override string ElementDataKey => "starsign";
public override IEvidenceKeyFilter EvidenceKeyFilter =>
new EvidenceKeyFilterWhitelist(new List<string>());
protected override void ProcessCloudEngine(IFlowData data, IStarSignData aspectData, string json)
{
StarSignData starSignData = (StarSignData)aspectData;
var dictionary = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
var starSign = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
JsonConvert.PopulateObject(dictionary["starsign"].ToString(), starSign);
starSignData.StarSign = starSign["starsign"].ToString();
}
}
First let's change the class to extend
CloudAspectEngineBase
. This has the type arguments of
StarSignData
- the interface extending
aspect data which will be added to the
flow data, and
AspectPropertyMetaData
- instead of
ElementPropertyMetaData
.
The existing constructor needs to change to match the CloudAspectEngineBase
class.
The constructor will also take a CloudRequestEngine
instance to get the available properties from.
The loadAspectProperties
method in this example will get the aspect properties from the CloudRequestEngine
and store them. In this case we know the only property will be 'star sign', but more complex cloud engines can have many properties.
Now the abstract methods can be implemented to create a functional aspect engine.