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); }
private IList <Task <HashTaskResult> > StartHashingTasks( int taskCount, bool inMemory, IWrapper wrapper, IMetaDataHasher hasher) { var tasks = new List <Task <HashTaskResult> >(); while (tasks.Count < taskCount) { tasks.Add(HashData(tasks.Count * HashTaskDelay(inMemory), inMemory, wrapper, hasher)); } return(tasks); }
private void Reload(IWrapper wrapper, IMetaDataHasher hasher, Task <List <RefreshResult> > reloader, CancellationTokenSource cancelRefresh, bool inMemory) { IList <Task <HashTaskResult> > tasks = StartHashingTasks( HashTaskCount, inMemory, wrapper, hasher); HashTaskResult[] hashes = Task.WhenAll(tasks).Result; cancelRefresh.Cancel(); var refreshResults = reloader.Result; Console.WriteLine($"Refreshed the dataset {refreshResults.Count} times."); ValidateResults(HashTaskCount, hashes, refreshResults); }
private async Task <HashTaskResult> HashData( int delayMs, bool inMemory, IWrapper wrapper, IMetaDataHasher hasher) { DateTime start = DateTime.UtcNow; await Task.Delay(delayMs); int taskId = delayMs / HashTaskDelay(inMemory); Console.WriteLine($"Hash task '{taskId}' started."); Interlocked.Increment(ref _hashTasksActive); int hash = 0; try { hash = hasher.HashProperties(hash, wrapper); hash = hasher.HashValues(hash, wrapper); hash = hasher.HashComponents(hash, wrapper); hash = hasher.HashProfiles(hash, wrapper); } finally { Interlocked.Decrement(ref _hashTasksActive); } Console.WriteLine($"Hash task '{taskId}' finished with hash value '{hash}'."); return(new HashTaskResult() { HashValue = hash, StartTime = start, FinishTime = DateTime.UtcNow }); }