/// <summary> /// Set the performance profile to use when constructing the data set. /// </summary> /// <param name="profile">Profile to use</param> /// <returns>This builder</returns> public override DeviceDetectionHashEngineBuilder SetPerformanceProfile( PerformanceProfiles profile) { switch (profile) { case PerformanceProfiles.LowMemory: SwigConfig.setLowMemory(); break; case PerformanceProfiles.Balanced: SwigConfig.setBalanced(); break; case PerformanceProfiles.BalancedTemp: SwigConfig.setBalancedTemp(); break; case PerformanceProfiles.HighPerformance: SwigConfig.setHighPerformance(); break; case PerformanceProfiles.MaxPerformance: SwigConfig.setMaxPerformance(); break; default: throw new ArgumentException( $"The performance profile '{profile}' is not valid " + $"for a DeviceDetectionHashEngine.", nameof(profile)); } return(this); }
private async Task <List <RefreshResult> > Refresh( IWrapper wrapper, CancellationToken cancellationToken, PerformanceProfiles profile) { List <RefreshResult> result = new List <RefreshResult>(); while (cancellationToken.IsCancellationRequested == false && result.Count < RefreshLimit()) { if (_hashTasksActive == 0) { // No hash tasks active so just wait and // then try again. await Task.Delay(10); } else { DateTime start = DateTime.UtcNow; Console.WriteLine("Refresh started"); wrapper.GetEngine().RefreshData(null); Console.WriteLine("Refresh completed"); result.Add(new RefreshResult() { StartTime = start, FinishTime = DateTime.UtcNow }); await Task.Delay(ReloadDelay(profile, false)); } } return(result); }
protected void TestInitialize(PerformanceProfiles profile) { Wrapper = new WrapperHash( TestHelpers.Utils.GetFilePath(Constants.HASH_DATA_FILE_NAME), profile); UserAgents = new UserAgentGenerator( TestHelpers.Utils.GetFilePath(Constants.UA_FILE_NAME)); }
public void Reload(IWrapper wrapper, IMetaDataHasher hasher, PerformanceProfiles profile) { CancellationTokenSource cancelRefresh = new CancellationTokenSource(); var reloader = Refresh(wrapper, cancelRefresh.Token, profile); Reload(wrapper, hasher, reloader, cancelRefresh, false); }
public void ReloadMemory(IWrapper wrapper, IMetaDataHasher hasher, PerformanceProfiles profile) { var masterData = File.ReadAllBytes( wrapper.GetEngine().GetDataFileMetaData().DataFilePath); CancellationTokenSource cancelRefresh = new CancellationTokenSource(); var reloader = RefreshInMemory(wrapper, masterData, cancelRefresh.Token, profile); Reload(wrapper, hasher, reloader, cancelRefresh, true); }
public void Hash_AllConfigurations_100_UserAgents( string datafileName, PerformanceProfiles performanceProfile, bool useLazyLoading, bool multiThreaded) { TestOnPremise_AllConfigurations_100_UserAgents(datafileName, performanceProfile, useLazyLoading, multiThreaded); }
public WrapperHash(FileInfo dataFile, PerformanceProfiles profile) { var builder = new DeviceDetectionHashEngineBuilder(_logger, null) .SetPerformanceProfile(profile) .SetUpdateMatchedUserAgent(true) .SetAutoUpdate(false) .SetDataFileSystemWatcher(false); Engine = builder .Build(dataFile.FullName, false); Pipeline = new PipelineBuilder(_logger) .AddFlowElement(Engine) .Build(); }
private async Task <List <RefreshResult> > RefreshInMemory( IWrapper wrapper, byte[] masterData, CancellationToken cancellationToken, PerformanceProfiles profile) { List <RefreshResult> result = new List <RefreshResult>(); while (cancellationToken.IsCancellationRequested == false && result.Count < RefreshLimit()) { if (_hashTasksActive == 0) { // No hash tasks active so just wait and // then try again. await Task.Delay(10); } else { using (var stream = new MemoryStream()) { stream.Write(masterData, 0, masterData.Length); stream.Seek(0, SeekOrigin.Begin); DateTime start = DateTime.UtcNow; Console.WriteLine("Refresh started"); wrapper.GetEngine().RefreshData( wrapper.GetEngine().DataFiles[0].Identifier, stream); Console.WriteLine("Refresh completed"); result.Add(new RefreshResult() { StartTime = start, FinishTime = DateTime.UtcNow }); } await Task.Delay(ReloadDelay(profile, true)); } } return(result); }
// The delay in milliseconds between calls to refresh the data // used by the engine. // The LowMemory and Balanced profiles are significantly // slower so we use a longer delay. private static int ReloadDelay( PerformanceProfiles profile, bool inmemory) { if (inmemory) { return(800); } switch (profile) { case PerformanceProfiles.MaxPerformance: case PerformanceProfiles.HighPerformance: return(800); case PerformanceProfiles.LowMemory: case PerformanceProfiles.Balanced: case PerformanceProfiles.BalancedTemp: return(1800); default: return(800); } }
public void EvidenceKeys_Hash_Core_CaseInsensitiveKeys(PerformanceProfiles profile) { TestInitialize(profile); EvidenceKeyTests.CaseInsensitiveKeys(Wrapper); }
public void EvidenceKeys_Hash_Core_ContainsOverrides(PerformanceProfiles profile) { TestInitialize(profile); EvidenceKeyTests.ContainsOverrides(Wrapper); }
/// <summary> /// Set the performance profile that the engine should use. /// </summary> /// <param name="profile"></param> /// <returns></returns> public abstract TBuilder SetPerformanceProfile(PerformanceProfiles profile);
public void Process_Hash_Core_CaseInsensitiveKeys(PerformanceProfiles profile) { TestInitialize(profile); ProcessTests.CaseInsensitiveEvidenceKeys(Wrapper, new DataValidatorHash(Wrapper.Engine)); }
/// <summary> /// Set the performance profile for the device detection engine. /// Defaults to balanced. /// </summary> /// <param name="profile"> /// The performance profile to use. /// </param> /// <returns> /// This builder instance. /// </returns> public DeviceDetectionOnPremisePipelineBuilder SetPerformanceProfile(PerformanceProfiles profile) { _performanceProfile = profile; return(this); }
public void Values_Hash_Core_DeviceId(PerformanceProfiles profile) { TestInitialize(profile); ValueTests.DeviceId(Wrapper); }
public void Process_Hash_Core_EmptyUserAgent(PerformanceProfiles profile) { TestInitialize(profile); ProcessTests.EmptyUserAgent(Wrapper, new DataValidatorHash(Wrapper.Engine)); }
public override TestBuilder SetPerformanceProfile(PerformanceProfiles profile) { return(this); }
/// <summary> /// This test will create a device detection pipeline based on the /// supplied parameters, process 1000 user agents. /// The various parameters allow the test to be run for many /// different configurations. /// </summary> /// <param name="datafileName"> /// The filename of the data file to use for device detection. /// </param> /// <param name="performanceProfile"> /// The performance profile to use. /// </param> /// <param name="useLazyLoading"> /// Whether or not to use the lazy loading feature. /// </param> /// <param name="multiThreaded"> /// Whether to use a single thread or multiple threads when /// passing user agents to the pipeline for processing. /// </param> public void TestOnPremise_AllConfigurations_100_UserAgents( string datafileName, PerformanceProfiles performanceProfile, bool useLazyLoading, bool multiThreaded) { var datafile = TestHelpers.Utils.GetFilePath(datafileName); var updateService = new Mock <IDataUpdateService>(); // Configure the pipeline builder based on the // parameters passed to this method. var builder = new DeviceDetectionPipelineBuilder( new NullLoggerFactory(), null, updateService.Object) .UseOnPremise(datafile.FullName, null, false) .SetPerformanceProfile(performanceProfile) .SetShareUsage(false) .SetDataFileSystemWatcher(false); if (useLazyLoading) { builder.UseLazyLoading(); } CancellationTokenSource cancellationSource = new CancellationTokenSource(); using (var pipeline = builder.Build()) { var options = new ParallelOptions() { CancellationToken = cancellationSource.Token, // The max parallelism is limited to 8 when the // multiThreaded flag is enabled. // This is because, if it is not limited, the lazy // loading tests will start all requests almost // immediately and then some will take so long to // complete that they exceed the configured timeout. MaxDegreeOfParallelism = (multiThreaded ? 8 : 1) }; // Create a parallel loop to actually process the user agents. Parallel.ForEach(USER_AGENTS.GetRandomUserAgents(100), options, (useragent) => { // Create the flow data instance using (var flowData = pipeline.CreateFlowData()) { // Add the user agent to the flow data // and process it flowData.AddEvidence( Pipeline.Core.Constants.EVIDENCE_HTTPHEADER_PREFIX + Pipeline.Core.Constants.EVIDENCE_SEPERATOR + "User-Agent", useragent) .Process(); // Make sure no errors occurred. If any did then // cancel the parallel process. if (flowData.Errors != null) { Assert.AreEqual(0, flowData.Errors.Count, $"Expected no errors but got {flowData.Errors.Count}" + $":{Environment.NewLine}{ReportErrors(flowData.Errors)}"); cancellationSource.Cancel(); } // Get the device data instance and access the // IsMobile property to ensure we can get // data out. var deviceData = flowData.Get <IDeviceData>(); var result = deviceData.IsMobile; } }); } }
public void Process_Hash_Core_ProfileOverride(PerformanceProfiles profile) { TestInitialize(profile); ProcessTests.ProfileOverride(Wrapper, new DataValidatorHash(Wrapper.Engine)); }
public void Values_Hash_Core_AvailableProperties(PerformanceProfiles profile) { TestInitialize(profile); ValueTests.AvailableProperties(Wrapper); }
public void Values_Hash_Core_TypedGetters(PerformanceProfiles profile) { TestInitialize(profile); ValueTests.TypedGetters(Wrapper); }
public void Process_Hash_Core_MetaDataService_DefaultProfileIdForComponent(PerformanceProfiles profile) { TestInitialize(profile); ProcessTests.MetaDataService_DefaultProfileIdForComponent(Wrapper); }
public void Values_Hash_Core_MatchedUserAgents(PerformanceProfiles profile) { TestInitialize(profile); ValueTests.MatchedUserAgents(Wrapper); }
public void Process_Hash_Core_DeviceId(PerformanceProfiles profile) { TestInitialize(profile); ProcessTests.DeviceId(Wrapper, new DataValidatorHash(Wrapper.Engine)); }
public override SimpleOnPremiseEngineBuilder SetPerformanceProfile(PerformanceProfiles profile) { // Lets not implement multiple performance profiles in this example. return(this); }
public void Process_Hash_Core_NoUsefulHeaders(PerformanceProfiles profile) { TestInitialize(profile); ProcessTests.NoUsefulHeaders(Wrapper, new DataValidatorHash(Wrapper.Engine)); }