The cloud service exposes meta data that can provide additional information about the various properties that might be returned.This example shows how to access this data and display the values available.
A list of the properties will be displayed, along with some additional information about each property. Note that this is the list of properties used by the supplied resource key, rather than all properties that can be returned by the cloud service.
In addition, the evidence keys that are accepted by the service are listed. These are the keys that, when added to the evidence collection in flow data, could have some impact on the result that is returned.
Bear in mind that this is a list of ALL evidence keys accepted by all products offered by the cloud. If you are only using a single product (for example - device detection) then not all of these keys will be relevant.
using FiftyOne.Pipeline.CloudRequestEngine.FlowElements;
using Microsoft.Extensions.Logging;
using System;
using System.IO;
{
public class Program
{
public class Example : ExampleBase
{
public void Run(string resourceKey, ILoggerFactory loggerFactory, TextWriter output)
{
using (var pipeline = new DeviceDetectionPipelineBuilder(loggerFactory)
.UseCloud(resourceKey)
.Build())
{
OutputProperties(pipeline.GetElement<DeviceDetectionCloudEngine>(), output);
OutputEvidenceKeyDetails(pipeline.GetElement<CloudRequestEngine>(), output);
}
}
private void OutputEvidenceKeyDetails(CloudRequestEngine engine, TextWriter output)
{
output.WriteLine();
if (typeof(EvidenceKeyFilterWhitelist).IsAssignableFrom(engine.EvidenceKeyFilter.GetType()))
{
var filter = engine.EvidenceKeyFilter as EvidenceKeyFilterWhitelist;
output.WriteLine($"Accepted evidence keys:");
foreach (var entry in filter.Whitelist)
{
output.WriteLine($"\t{entry.Key}");
}
}
else
{
output.WriteLine($"The evidence key filter has type " +
$"{engine.EvidenceKeyFilter.GetType().Name}. As this does not extend " +
$"EvidenceKeyFilterWhitelist, a list of accepted values cannot be " +
$"displayed. As an alternative, you can pass evidence keys to " +
$"filter.Include(string) to see if a particular key will be included " +
$"or not.");
output.WriteLine($"For example, header.user-agent is " +
(engine.EvidenceKeyFilter.Include("header.user-agent") ? "" : "not ") +
"accepted.");
}
}
private void OutputProperties(DeviceDetectionCloudEngine engine, TextWriter output)
{
foreach (var property in engine.Properties)
{
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = ConsoleColor.DarkRed;
output.Write($"Property - {property.Name}");
Console.ResetColor();
var typeName = property.Type.IsGenericType ?
property.Type.GenericTypeArguments[0].Name : property.Type.Name;
output.WriteLine($"[Category: {property.Category}] ({typeName})");
}
}
}
static void Main(string[] args)
{
string resourceKey = args.Length > 0 ? args[0] :
Environment.GetEnvironmentVariable(
ExampleUtils.CLOUD_RESOURCE_KEY_ENV_VAR);
var loggerFactory = LoggerFactory.Create(b => b.AddConsole());
var logger = loggerFactory.CreateLogger<Program>();
if (string.IsNullOrEmpty(resourceKey))
{
logger.LogError($"No resource key specified in the configuration file " +
$"'appsettings.json' or the environment variable " +
$"'{ExampleUtils.CLOUD_RESOURCE_KEY_ENV_VAR}'. The 51Degrees cloud service is " +
$"accessed using a 'ResourceKey'. For more information see " +
$"https://51degrees.com/documentation/_info__resource_keys.html. " +
$"A resource key with the properties required by this example can be " +
$"created for free at https://configure.51degrees.com/1QWJwHxl. " +
$"Once complete, supply the resource key as a command line argument or via " +
$"the environment variable mentioned at the start of this message.");
}
else
{
new Example().Run(resourceKey, loggerFactory, Console.Out);
}
loggerFactory.Dispose();
}
}
}