internal string FeaturesPointToString() { ConcurrentBag <string> seq = new ConcurrentBag <string>(); Parallel.ForEach(featurePoints.Keys, image_id => { string s = ""; foreach (FeaturePoint fp in featurePoints[image_id]) { s += (image_id + SaveLoad.Space2 + fp.ToString() + SaveLoad.Space1); if (s.Count() > 4096) { seq.Add(s); s = ""; } } seq.Add(s); }); if (seq.Count == 0) { return(""); } return(seq.Aggregate((a, b) => a + b)); }
private static Statistic GetSolutionStatistics( IEnumerable <Project> projects, CancellationToken cancellationToken ) { var sums = new ConcurrentBag <Statistic>(); Parallel.ForEach( projects.SelectMany(project => project.Documents), document => { var documentStatistics = GetSolutionStatisticsAsync(document, cancellationToken) .ConfigureAwait(false) .GetAwaiter() .GetResult(); sums.Add(documentStatistics); } ); var sum = sums.Aggregate( new Statistic(0, 0, 0), (currentResult, value) => currentResult + value ); return(sum); }
/// <summary> /// Creates a tooltip from skipped filenames for the statusbar message. /// </summary> /// <param name="skippedFiles">Collection of filenames that were skipped.</param> private void UpdateStatusBarForSkippedFiles(ConcurrentBag <string> skippedFiles) { string tooltip = skippedFiles.Aggregate( new StringBuilder("Skipped files:" + Environment.NewLine), (sb, fileName) => sb.AppendLine().Append(fileName)) .ToString(); ShowInStatusbar($"{skippedFiles.Count} file{(skippedFiles.Count == 1 ? "" : "s")} skipped", tooltip); }
private IList <DocumentScore> Collect(QueryContext query) { var collectors = _indices.Values.Select(ix => new Collector(_directory, ix, _scorer)).ToList(); var scores = new ConcurrentBag <IEnumerable <DocumentScore> >(); Parallel.ForEach(collectors, c => scores.Add(c.Collect(query.Clone()))); return(scores .Aggregate(DocumentScore.CombineOr) .OrderByDescending(p => p.Score).ToList()); }
private static Task <Statistic> GetAnalyzerStatisticsAsync(IEnumerable <Project> projects, CancellationToken cancellationToken) { ConcurrentBag <Statistic> sums = new ConcurrentBag <Statistic>(); Parallel.ForEach(projects.SelectMany(i => i.Documents), document => { var documentStatistics = GetAnalyzerStatisticsAsync(document, cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult(); sums.Add(documentStatistics); }); Statistic sum = sums.Aggregate(new Statistic(0, 0, 0), (currentResult, value) => currentResult + value); return(Task.FromResult(sum)); }
private static Statistic GetAnalyzerStatistics(IEnumerable <Project> projects) { ConcurrentBag <Statistic> sums = new ConcurrentBag <Statistic>(); Parallel.ForEach(projects.SelectMany(i => i.Documents), document => { var documentStatistics = GetAnalyzerStatistics(document).ConfigureAwait(false).GetAwaiter().GetResult(); sums.Add(documentStatistics); }); Statistic sum = sums.Aggregate(new Statistic(0, 0, 0), (currentResult, value) => currentResult + value); return(sum); }
private void ProcessUpdatedMerchandiseTypeProductPids() { if (!_updatedMerchandiseTypeProductPids.Any()) { Log.Info("There were no products that required merch types to be updated inside CJ table."); return; } var query = string.Empty; var time = DateTime.Now; const string insertStatementFormat = "UPDATE [dbo].[tbl_CJ_Products] SET [CJ_MERCHANDISETYPE] = '{0}', [DATECHANGED] = '{1}' WHERE [PID] = {2} "; query = _updatedMerchandiseTypeProductPids.Aggregate(query, (current, updatedMerchandiseTypeProductPid) => current + string.Format(insertStatementFormat, ZeroCommissionListName, time.ToString("yyyy-MM-dd HH:mm:ss"), updatedMerchandiseTypeProductPid)); DbUtils.ExecuteTransaction("BatchDB", query, null); Log.InfoFormat("There were {0} products whose merch types were updated inside CJ table.", _updatedMerchandiseTypeProductPids.Count); }
static void Test(Action <string, Action <Action <string> > > context) { var dir = Environment.CurrentDirectory; var filePath = Path.Combine(dir, "AsyncFileWriterTest.txt"); File.Delete(filePath); // Start from scratch. (comment out for further appends.) var byteCounter = new ConcurrentBag <int>(); var timeCounter = new ConcurrentBag <TimeSpan>(); var sw = Stopwatch.StartNew(); context(filePath, writeHandler => { int count = 0; void write(int i) { var message = $"{i}) {DateTime.Now}\n 00000000000000000000000000000000111111111111111111111111111222222222222222222222222222"; var t = Stopwatch.StartNew(); writeHandler(message); timeCounter.Add(t.Elapsed); byteCounter.Add(message.Length); Interlocked.Increment(ref count); } Parallel.For(0, 10000, write); Parallel.For(10000, 20000, write); //writer.Fault(new Exception("Stop!")); Task.Delay(1).Wait(); Parallel.For(20000, 100000, write); Task.Delay(1000).Wait(); // Demonstrate that when nothing buffered the active stream closes. Parallel.For(100000, 1000000, write); //Console.WriteLine("Total Posted: {0:#,##0}", count); }); Console.WriteLine($"Total Time: {sw.Elapsed.TotalSeconds} seconds"); Console.WriteLine("Total Bytes: {0:#,##0}", byteCounter.Sum()); Console.WriteLine($"Total Blocking Time: {timeCounter.Aggregate((b, c) => b + c)}"); Console.WriteLine("------------------------"); Console.WriteLine(); }
private static Task<Statistic> GetAnalyzerStatisticsAsync(IEnumerable<Project> projects, CancellationToken cancellationToken) { ConcurrentBag<Statistic> sums = new ConcurrentBag<Statistic>(); Parallel.ForEach(projects.SelectMany(i => i.Documents), document => { var documentStatistics = GetAnalyzerStatisticsAsync(document, cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult(); sums.Add(documentStatistics); }); Statistic sum = sums.Aggregate(new Statistic(0, 0, 0), (currentResult, value) => currentResult + value); return Task.FromResult(sum); }
private static Statistic GetAnalyzerStatistics(IEnumerable<Project> projects) { ConcurrentBag<Statistic> sums = new ConcurrentBag<Statistic>(); Parallel.ForEach(projects.SelectMany(i => i.Documents), document => { var documentStatistics = GetAnalyzerStatistics(document).ConfigureAwait(false).GetAwaiter().GetResult(); sums.Add(documentStatistics); }); Statistic sum = sums.Aggregate(new Statistic(0, 0, 0), (currentResult, value) => currentResult + value); return sum; }
public virtual long GetTotalDocSize() { return(OperationResults .Aggregate <WorkloadOperationResult, long>(0, (current, result) => current + result.DocSize)); }