Check out the latest documentation.

What's Covered

This tutorial covers:

  1. How to iterate through all available properties in the data file.
  2. How to iterate through all possible values for each property.
  3. How to access the description for each property.
  4. How to access the description for each value.

Code and Explanation

Example of listing properties and possible values from a Dataset The example illustrates:

  1. Initialize the data set

    												
    DataSet dataSet = StreamFactory.Create(fileName, false);
    
    												

  • Fetch and print the name and description of all properties contained in the data set

    									
    foreach (var property in dataSet.Properties) 
    {
        Console.WriteLine(property.Name + " - " + 
            property.Description);
    }
    
    									
  • Fetch and print the possible values and description (if available) for a given property

    									
    foreach (var property in dataSet.Properties) 
    {
        Console.WriteLine(property.Name + " - " + 
            property.Description);
    
        foreach (var value in property.Values)
        {
            sb.Append(" - ");
            sb.Append(value.Name);
            if (value.Description != null)
            {
                sb.Append(" - ");
                sb.Append(value.Description);
            }
            sb.Append("\n");
            Console.WriteLine(sb.ToString());
            sb.Clear();
        }
    }
    
    									
    This tutorial assumes you are building this from within the 51Degrees Visual Studio solution. Running the executable produced inside Visual Studio will ensure all the command line arguments are preset correctly. If you are running outside of Visual Studio, make sure to add the path to a 51Degrees data file as an argument.

    Full Source File
    												
            public static void Run(string fileName)
            {
                // DataSet is the object used to interact with the data file.
                // StreamFactory creates Dataset with pool of binary readers to 
                // perform device lookup using file on disk.
                DataSet dataSet = StreamFactory.Create(fileName, false);
                StringBuilder sb = new StringBuilder();
    
                Console.WriteLine("Starting Mata Data Example");
    
                // Loops over all properties.
                foreach (var property in dataSet.Properties) 
                {
                    // Print property name and description.
                    Console.WriteLine(property.Name + " - " + 
                        property.Description);
    
                    // For each of the values of the current property.
                    foreach (var value in property.Values)
                    {
                        // Print value name.
                        sb.Append(" - ");
                        sb.Append(value.Name);
                        // If value has a description add it.
                        if (value.Description != null)
                        {
                            sb.Append(" - ");
                            sb.Append(value.Description);
                        }
                        sb.Append("\n");
                        // Print value and reset string builder.
                        Console.WriteLine(sb.ToString());
                        sb.Clear();
                    }
                }
    
                // Finally close the dataset, releasing resources and file locks.
                dataSet.Dispose();
            }
    
    
    												
    Full Source File

  • Summary

    Metadata is essentially a short description for an entity in the 51Degrees device data model. Metadata is used to provide a meaningful description for an entity such as property or value and can be useful in a variety of situations:

    • When generating reports using 51Degrees data it can aid the reader to have a short description alongside each property listed.
    • When exposing part of the API to the end user it can help to know what the property definition is, or what the value definitions are before they make a choice. E.G. An advertising agency that lets their clients' target specific devices can benefit if every choice is provided with a description.

    The Property Dictionary page is an example that uses our metadata. The page is generated dynamically using the metadata and entities of the 51Degrees Enterprise data file. The following table shows just a few of the available properties.

    Property Description Values
    IsMobile Indicates if the device's primary data connection is wireless and is designed to operate mostly from battery power (ie a mobile phone, smart phone or tablet). True, False
    PlatformName The name of the software platform (operating system) the device is using. Android, Windows, PS4 Software, ...
    BrowserName The name of the browser. Many mobile browsers come default with the OS. Unless specifically named, these browsers are named after the accompanying OS Firefox, Safari, Chrome Mobile, ...

     

    Enterprise and Premium Only

    Property Description Values
    HardwareVendor The company that manufactures the device or primarily sells it. May return 'Unknown'. Samsumg, Asus, Panasonic, ...
    ScreenInchesDiagonal The diagonal size of the device's screen in inches. May return 'N/A' or 'Unknown'. 5, 5.1, 7, ...
    IsTv Indicates if the device is a smart TV. True, False