This example shows how to use the 51Degrees Cloud service to lookup
the details of a device based on a given 'native model name'.
Native model name is a string of characters that are returned from
a query to the device's OS. For more details on this, see the example below.
using FiftyOne.Pipeline.CloudRequestEngine.FlowElements;
using FiftyOne.Pipeline.Core.FlowElements;
using Microsoft.Extensions.Logging;
using System;
using System.Net.Http;
{
class Program
{
private static string nativemodel1 = "SC-03L";
private static string nativemodel2 = "iPhone11,8";
static void Main(string[] args)
{
string resourceKey = "!!YOUR_RESOURCE_KEY!!";
if (resourceKey.StartsWith("!!"))
{
Console.WriteLine("You need to create a resource key at " +
"https://configure.51degrees.com and paste it into the code, " +
"replacing !!YOUR_RESOURCE_KEY!!.");
Console.WriteLine("Make sure to include the 'HardwareVendor', " +
"'HardwareName' and 'HardwareModel' properties as they " +
"are used by this example.");
}
else
{
Console.WriteLine("This example shows the details of devices " +
"associated with a given 'native model name'.");
Console.WriteLine($"The native model name can be retrieved by " +
$"code running on the device (For example, a mobile app).");
Console.WriteLine($"For Android devices, see " +
$"https://developer.android.com/reference/android/os/Build#MODEL");
Console.WriteLine($"For iOS devices, see " +
$"https://gist.github.com/soapyigu/c99e1f45553070726f14c1bb0a54053b#file-machinename-swift");
Console.WriteLine("----------------------------------------");
ILoggerFactory loggerFactory = new LoggerFactory();
HttpClient httpClient = new HttpClient();
using (var cloudEngine = new CloudRequestEngineBuilder(loggerFactory, httpClient)
.SetResourceKey(resourceKey)
.Build())
using (var propertyKeyedEngine = new HardwareProfileCloudEngineBuilder(loggerFactory)
.Build())
using (var pipeline = new PipelineBuilder(loggerFactory)
.AddFlowElement(cloudEngine)
.AddFlowElement(propertyKeyedEngine)
.Build())
{
AnalyseTac(nativemodel1, pipeline);
AnalyseTac(nativemodel2, pipeline);
}
}
#if (DEBUG)
Console.WriteLine("Done. Press any key to exit.");
Console.ReadKey();
#endif
}
static void AnalyseTac(string nativemodel, IPipeline pipeline)
{
var data = pipeline.CreateFlowData();
data.AddEvidence(Constants.EVIDENCE_QUERY_NATIVE_MODEL_KEY, nativemodel);
data.Process();
var result = data.Get<MultiDeviceDataCloud>();
Console.WriteLine($"Which devices are associated with the " +
$"native model name '{nativemodel}'?");
foreach (var device in result.Profiles)
{
var vendor = device.HardwareVendor;
var name = device.HardwareName;
var model = device.HardwareModel;
if (vendor.HasValue &&
model.HasValue &&
name.HasValue)
{
Console.WriteLine($"\t{vendor.Value} {string.Join(",", name.Value)} ({model.Value})");
}
else
{
Console.WriteLine(vendor.NoValueMessage);
}
}
}
}
}