// Snippet Start public static void Run(string fileName) { // DataSet is the object used to interact with the data file. // DataSetBuilder creates Dataset with pool of binary readers to // perform device lookup using file on disk. The type is // disposable and is therefore contained in using block to // ensure file handles and resources are freed. using (DataSet dataSet = DataSetBuilder.File() .ConfigureDefaultCaches() // Set the cache size for the Values cache to 200,000 // This is done because FindProfiles performs significantly // faster when all Value objects can be held in memory. // The number of Value objects varies by data file type: // Lite < 5000 // Premium < 180,000 // Enterprise < 200,000 .SetCacheSize(CacheType.ValuesCache, 200000) .SetTempFile(false) .Build(fileName)) { Console.WriteLine("Staring Find Profiles Example."); // Retrieve all mobile profiles from the data set. Profile[] profiles = dataSet.FindProfiles("IsMobile", "True"); Console.WriteLine("There are " + profiles.Count() + " mobile profiles in the " + dataSet.Name + " data set."); // Retrieve all non-mobile profiles from the data set. profiles = dataSet.FindProfiles("IsMobile", "False"); Console.WriteLine("There are " + profiles.Count() + " non-mobile profiles in the " + dataSet.Name + " data set."); } }
/// <summary> /// Creates a new <see cref="IndirectDataSet"/> from the file provided. /// </summary> /// <param name="filePath">Uncompressed file containing the data for /// the data set</param> /// <param name="lastModified">Date and time the source data was last /// modified.</param> /// <param name="isTempFile">True if the file should be deleted when /// the source is disposed</param> /// <returns> /// A <see cref="IndirectDataSet"/>configured to read entities from the file /// path when required /// </returns> public static IndirectDataSet Create(string filePath, DateTime lastModified, bool isTempFile) { return(DataSetBuilder.File() .ConfigureDefaultCaches() .SetTempFile(isTempFile) .LastModified(lastModified) .Build(filePath)); }
public void CreateDataSet() { _memory = new Utils.MemoryMonitor(); Utils.CheckFileExists(DataFile); _dataSet = DataSetBuilder.File() .ConfigureDefaultCaches() .SetCacheSize(CacheType.ValuesCache, ValuesCacheSize) .Build(DataFile); }
public void CreateDataSet() { var start = DateTime.UtcNow; Utils.CheckFileExists(DataFile); _dataSet = DataSetBuilder.File() .ConfigureDefaultCaches() .ConfigureCache(CacheType.ValuesCache, new CacheOptions() { Builder = new LruCacheBuilder(), Size = ValuesCacheSize }) .Build(DataFile); }
// Snippet Start public static void Run(string fileName) { // DataSet is the object used to interact with the data file. // DataSetBuilder creates a DataSet with a pool of binary // readers to perform device lookup using file on disk. // The type is disposable and is therefore contained in using // block to ensure file handles and resources are freed. using (DataSet dataSet = DataSetBuilder.File() // First, the SingleThreadLowMemory configuration template // is specified in order to provide initial values for the // cache settings. .ConfigureCachesFromTemplate( DataSetBuilder.CacheTemplate.SingleThreadLowMemory) // A custom cache implementation is specified to store signatures. .SetCacheBuilder(CacheType.SignaturesCache, new CustomCacheBuilder()) // A null cache is specified for profiles in order to reduce // memory usage. This means that profiles will always be // loaded from disk when needed. .SetCacheBuilder(CacheType.ProfilesCache, null) .SetTempFile(false) .Build(fileName)) { // Create a provider using the dataset. // The provider handles the process of finding a match // in the dataset for a given user agent. using (Provider provider = new Provider(dataSet)) { Console.WriteLine("Staring Caching Configuration Example."); // Used to store and access detection results. Match match; // Contains detection result for the IsMobile property. string IsMobile; // User-Agent string of an iPhone mobile device. string mobileUserAgent = ("Mozilla/5.0 (iPhone; CPU iPhone " + "OS 7_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like " + "Gecko) 'Version/7.0 Mobile/11D167 Safari/9537.53"); // Get a match object and display the IsMobile property match = provider.Match(mobileUserAgent); IsMobile = match["IsMobile"].ToString(); Console.WriteLine(" IsMobile: " + IsMobile); } } }