private static IEnumerable <Tuple <string, long> > Do(Transistor vtn, Transistor vtp, Filter filter, long sweepStart, long sweepEnd, long seedStart, long seedEnd) { var dn = Transistor.ToTableName(vtn, vtp); var repo = new MssqlRepository(); repo.Use(dn); return(repo.Count(r => r.Sweep.Within(sweepStart, sweepEnd) && r.Seed.Within(seedStart, seedEnd), filter)); }
private Exception PushFiles(CancellationToken token, ProgressBarBase parentBar, ProgressBarBase parseBar, ProgressBarBase pushBar) { try { var repo = new MssqlRepository(); var name = Transistor.ToTableName( new Transistor(VtnVoltage, VtnSigma, VtnDeviation), new Transistor(VtpVoltage, VtpSigma, VtpDeviation) ); repo.Use(name); using (var pipeline = new PipeLine.PipeLine(token)) { var first = pipeline.AddSelectMany(Parallel, QueueBuffer, InputFiles, RecordFactory.BuildFromCsv); first.OnInterval += s => parseBar?.Tick($"parsed: {s}"); first.OnFinish += () => parentBar?.Tick($"Finished parse csv files. {first.TotalResultsCount} records were parsed"); pipeline.Invoke(() => { var list = new List <Record>(); var sum = 0; foreach (var r in first.Results.GetConsumingEnumerable()) { list.Add(r); pushBar.MaxTicks++; if (list.Count != QueueBuffer) { continue; } sum += list.Count; repo.BulkUpsert(list); foreach (var record in list) { pushBar.Tick($"{record}"); } pushBar.Message = $"{sum} records pushed"; list = new List <Record>(); } if (!list.Any()) { return; } sum += list.Count; repo.BulkUpsert(list); foreach (var record in list) { pushBar.Tick($"{record}"); } pushBar.Message = $"{sum} records pushed"; }); parentBar.Tick("Finished push"); } } catch (OperationCanceledException e) { return(e); } catch (Exception e) { return(e); } return(null); }