private static void Output(PatternWrapper wrapper, IMatchResult results)
 {
     Output((IWrapper)wrapper, (IMatchResult)results);
     Console.WriteLine("User-Agent -> {0}", results.UserAgent);
     Console.WriteLine("Rank -> {0}", results.Rank);
     Console.WriteLine("Difference -> {0}", results.Difference);
     Console.WriteLine("Method -> {0}", results.Method);
 }
 /// <summary>
 /// Creates the device detection providers.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void Application_Start(object sender, EventArgs e)
 {
     _pattern = new PatternWrapper(
     Path.Combine(
         AppDomain.CurrentDomain.BaseDirectory,
         "..\\..\\data\\51Degrees-LiteV3.2.dat"));
     _trie = new TrieWrapper(
     Path.Combine(
         AppDomain.CurrentDomain.BaseDirectory,
         "..\\..\\data\\51Degrees-LiteV3.2.trie"));
 }
 /// <summary>
 /// Disposes of the device detection providers.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void Application_End(object sender, EventArgs e)
 {
     if (_pattern != null)
     {
         _pattern.Dispose();
         _pattern = null;
     }
     if (_trie != null)
     {
         _trie.Dispose();
         _trie = null;
     }
 }
        static void Main(string[] args)
        {
            // Initialise the pattern provider with a list of 4 properties.
            using (var pattern = new PatternWrapper(
                new FileInfo("..\\..\\..\\..\\..\\data\\51Degrees-LiteV3.2.dat").FullName,
                    new[] { "Id", "DeviceType", "IsMobile", "ScreenPixelsWidth", "ScreenPixelsHeight" }))
            {

                // Initialise the trie provider with a data file and a list of 4 properties.
                using (var trie = new TrieWrapper(
                    new FileInfo("..\\..\\..\\..\\..\\data\\51Degrees-LiteV3.2.trie").FullName,
                    new[] { "Id", "DeviceType", "IsMobile", "ScreenPixelsWidth", "ScreenPixelsHeight" }))
                {

                    // IMPORTANT: For a full list of properties see: https://51degrees.com/resources/property-dictionary

                    using (var reader = new FileInfo(args.Length > 0 ? args[0] : "..\\..\\..\\..\\..\\data\\20000 User Agents.csv").OpenText())
                    {
                        var start = DateTime.UtcNow;
                        Console.WriteLine("Started -> {0}", start);
                        var line = reader.ReadLine();
                        while (line != null)
                        {
                            using (var patternResults = pattern.Match(line.Trim()))
                            {
                                Output(pattern, patternResults);
                            }
                            using (var trieResults = trie.Match(line.Trim()))
                            {
                                Output(trie, trieResults);
                            }
                            line = reader.ReadLine();
                        }
                        Console.WriteLine("Elapsed Time -> {0} seconds", (DateTime.UtcNow - start).TotalSeconds);
                    }
                }
            }
            Console.ReadKey();
        }
 /// <summary>
 /// Create the two providers for managed and unmanaged code.
 /// </summary>
 public virtual void Initialise()
 {
     _unmanagedProvider = new PatternWrapper(DataFile, String.Empty, 5000);
     _managedProvider = new Provider(StreamFactory.Create(DataFile, false));
 }
 /// <summary>
 /// Disposes of the providers if not already done so.
 /// </summary>
 /// <param name="disposing"></param>
 protected virtual void Disposing(bool disposing)
 {
     if (_managedProvider != null)
     {
         _managedProvider.DataSet.Dispose();
         _managedProvider = null;
     }
     if (_unmanagedProvider != null)
     {
         _unmanagedProvider.Dispose();
         _unmanagedProvider = null;
     }
 }