コード例 #1
0
ファイル: DataFlow.cs プロジェクト: HerrDmitry/Importer
        private void WriterTask(CancellationToken token)
        {
            while (!token.IsCancellationRequested || this.buffer.Count > 0)
            {
                if (this.buffer.TryTake(out DataRecord record))
                {
                    var failed = record.Parsed.Values.FirstOrDefault(x => x.IsFailed);
                    if (failed != null)
                    {
                        lock (this.buffer)
                        {
                            this.exceptionRecordCount++;
                            ErrorOutput.Write($"Line {record.RecordNumber} - Column {failed.Column.Name} - ");
                            ErrorOutput.WriteLine(string.Join(", ", record.Source));
                        }
                    }
                    else
                    {
                        foreach (var writer in this.writers)
                        {
                            writer.WriteLine(record.Parsed);
                        }

                        lock (this.buffer)
                        {
                            this.successfulRecordCount++;
                        }
                    }
                }
                else
                {
                    Thread.Sleep(50);
                }
            }
        }