Advertisement
nerru86

51Degrees .NET list signatures with Samsung HardwareVendor

Oct 12th, 2015
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.54 KB | None | 0 0
  1. using FiftyOne.Foundation.Mobile.Detection;
  2. using FiftyOne.Foundation.Mobile.Detection.Entities;
  3. using FiftyOne.Foundation.Mobile.Detection.Factories;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9.  
  10. namespace ConsoleApplication2
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             Provider provider = new Provider(MemoryFactory.Create("path\\to\\51Degrees\\file.dat"));          
  17.             string requiredProperty = "HardwareVendor";
  18.             string requiredValue = "Samsung";
  19.             Property property = provider.DataSet.GetProperty(requiredProperty);
  20.  
  21.             if (property == null)
  22.             {
  23.                 //Property not found.
  24.                 return;
  25.             }
  26.             List<Signature> signatures = new List<Signature>();
  27.  
  28.             //For each signature.
  29.             foreach (Signature sig in provider.DataSet.Signatures)
  30.             {
  31.                 // Each signature has 4 components associated with it.
  32.                 // Find the component the property belongs to.
  33.                 foreach (Profile profile in sig.Profiles)
  34.                 {
  35.                     if (profile.Component == property.Component)
  36.                     {
  37.                         foreach (Value val in profile.Values) {
  38.                             // Verify the current value is related to the property that we are interested in.
  39.                             // If not - move on to the next value.
  40.                             if (val.Property.Index != property.Index) {
  41.                                 continue;
  42.                             }
  43.                             // Otherwise compare current value to the one we are interested in.
  44.                             if (val.Name.Equals(requiredValue)) {
  45.                                 // Add signature to the list.
  46.                                 signatures.Add(sig);
  47.                                 //Console.Write("Componenet: " + profile.Component)
  48.                                 //Console.WriteLine(" Profile: "+profile.ProfileId+" - "+val.Property.Name+": "+val.Name);
  49.                             }
  50.                         }
  51.                     }
  52.                 }
  53.             }
  54.             //At this point we have a list of Signatures where HardwareProfile component's HardwareVendor
  55.             //value is 'Samsung'
  56.             Console.WriteLine("There are: " + signatures.Count+" signatures in the list");
  57.             Console.ReadLine();
  58.            
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement