Exemplo n.º 1
0
 /// <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"));
 }
Exemplo n.º 2
0
 /// <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;
     }
 }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Create the two providers for managed and unmanaged code.
 /// </summary>
 public virtual void Initialise()
 {
     _unmanagedProvider = new TrieWrapper(DataFile);
     _managedProvider = TrieFactory.Create(DataFile);
 }
Exemplo n.º 5
0
 /// <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.Dispose();
         _managedProvider = null;
     }
     if (_unmanagedProvider != null)
     {
         _unmanagedProvider.Dispose();
         _unmanagedProvider = null;
     }
 }