public void Test() { var sink = new BufferSink <int>(10); var step = 7; for (int i = 0; 2048 > i; i += step) { var data = new int[step]; for (int j = 0; j < step; j++) { data[j] = i + j; } sink.PushCopied(data, 0, data.Length, false); } int index = 0; while (sink.IsFilled) { var buffer = sink.Pop(); foreach (var element in buffer) { Assert.AreEqual(index++, element); } } }
public void AddRowTestWithOverflowExceptionRedirect() { OutputTestImpl output = null; ComponentBufferServiceTestImpl bufferService = null; GenerateOutputColumns(new string[] { "A", "B", "C", "D" }, true, DTSRowDisposition.RD_FailComponent, DTSRowDisposition.RD_RedirectRow, out output, out bufferService); BufferSink target = new BufferSink(bufferService, output, true); // Say we have headers, etc... target.CurrentRowCount = 3; string[] data = new string[] { "1", "", "3", "4" }; RowData rowData = GenerateRowData(data); target.AddRow(rowData); Assert.AreEqual <Int64>(4, target.CurrentRowCount); Assert.AreEqual <int>(1, bufferService.RowCount); Assert.AreEqual <int>(0, bufferService.ErrorRowCount); VerifyAddedRowData(bufferService, new object[] { "1", null, "3", "4" }); bufferService.ExceptionToFire = new OverflowException(); target.AddRow(rowData); Assert.AreEqual <Int64>(5, target.CurrentRowCount); Assert.AreEqual <int>(1, bufferService.RowCount); Assert.AreEqual <int>(1, bufferService.ErrorRowCount); }
public void AddRowTestWithException() { OutputTestImpl output = null; ComponentBufferServiceTestImpl bufferService = null; GenerateOutputColumns(new string[] { "A", "B", "C", "D" }, true, DTSRowDisposition.RD_FailComponent, DTSRowDisposition.RD_FailComponent, out output, out bufferService); bufferService.ExceptionToFire = new System.Runtime.InteropServices.COMException(); BufferSink target = new BufferSink(bufferService, output, true); string[] data = new string[] { "1", "", "3", "4" }; RowData rowData = GenerateRowData(data); try { target.AddRow(rowData); } catch (Exception ex) { Assert.AreEqual <Int64>(1, target.CurrentRowCount); Assert.AreEqual <int>(0, bufferService.RowCount); Assert.AreEqual <int>(0, bufferService.ErrorRowCount); throw ex; } }
public void AddRowTestWithOverflowException() { OutputTestImpl output = null; ComponentBufferServiceTestImpl bufferService = null; GenerateOutputColumns(new string[] { "A", "B", "C", "D" }, true, DTSRowDisposition.RD_FailComponent, DTSRowDisposition.RD_FailComponent, out output, out bufferService); bufferService.ExceptionToFire = new DoesNotFitBufferException(); BufferSink target = new BufferSink(bufferService, output, true); // Say we have headers, etc... target.CurrentRowCount = 3; string[] data = new string[] { "1", "", "3", "4" }; RowData rowData = GenerateRowData(data); try { target.AddRow(rowData); } catch (Exception ex) { Assert.AreEqual <Int64>(4, target.CurrentRowCount); Assert.AreEqual <int>(0, bufferService.RowCount); Assert.AreEqual <int>(0, bufferService.ErrorRowCount); throw ex; } }
public void CurrentRowCountTest() { IDTSOutput100 output = new OutputTestImpl(); IComponentBufferService bufferService = new ComponentBufferServiceTestImpl(new string[0], false); BufferSink target = new BufferSink(bufferService, output, false); Assert.AreEqual <Int64>(0, target.CurrentRowCount); }
public PoolSource(IAudioSource source, TimeSpan delay) { this.source = source; defaultDelay = delay; int size = (int)(source.Format.SampleRate * source.Format.Channels * delay.TotalSeconds) * 3; sink = new BufferSink <float>(size); FillSink(); }
public FftView(int size = 4096) { InitializeComponent(); Timer = new DispatcherTimer(TimeSpan.FromSeconds(0.05), DispatcherPriority.Loaded, new EventHandler(updatePlot), Dispatcher); Timer.Stop(); WavePlotModel.Axes.Add(WaveXAxis); WavePlotModel.Axes.Add(WaveYAxis); WavePlotModel.Series.Add(WaveSeries); plotView.Model = WavePlotModel; Sink = new BufferSink <float>(size); Sink.Filled += Sink_Filled; }
public void AddRowTestWithTooManyColumnsIgnore() { OutputTestImpl output = null; ComponentBufferServiceTestImpl bufferService = null; GenerateOutputColumns(new string[] { "A", "B", "C", "D" }, true, DTSRowDisposition.RD_FailComponent, DTSRowDisposition.RD_FailComponent, out output, out bufferService); output.TruncationRowDisposition = DTSRowDisposition.RD_IgnoreFailure; BufferSink target = new BufferSink(bufferService, output, true); string[] data = new string[] { "1", "", "3", "4", "5", "6" }; RowData rowData = GenerateRowData(data); target.AddRow(rowData); Assert.AreEqual <Int64>(1, target.CurrentRowCount); Assert.AreEqual <int>(0, bufferService.RowCount); Assert.AreEqual <int>(0, bufferService.ErrorRowCount); }
public void AddRowTest() { OutputTestImpl output = null; ComponentBufferServiceTestImpl bufferService = null; GenerateOutputColumns(new string[] { "A", "B", "C", "D" }, false, DTSRowDisposition.RD_FailComponent, DTSRowDisposition.RD_FailComponent, out output, out bufferService); BufferSink target = new BufferSink(bufferService, output, false); string[] data = new string[] { "1", "2", "3", "4" }; RowData rowData = GenerateRowData(data); target.AddRow(rowData); Assert.AreEqual <Int64>(1, target.CurrentRowCount); Assert.AreEqual <int>(1, bufferService.RowCount); Assert.AreEqual <int>(0, bufferService.ErrorRowCount); VerifyAddedRowData(bufferService, data); }
public void BufferSinkConstructorTest2() { ComponentBufferServiceTestImpl bufferService = new ComponentBufferServiceTestImpl(new string[0], false); BufferSink target = new BufferSink(bufferService, null, false); }
public void BufferSinkConstructorTest1() { BufferSink target = new BufferSink(null, null, false); }
private static LoggerConfiguration CreateBufferSink( LoggerConfiguration sourceConfig, IEnumerable <SourceConfig> configSet, LoggingLevelSwitch fallbackLevelSwitch, LogEventLevel triggerEventLevel, int bufferCapacity, IEnumerable <Action <LoggerConfiguration> > configureOutput) { var configSetList = configSet.ToList(); var userLc = new LoggerConfiguration().MinimumLevel.Verbose(); foreach (var action in configureOutput) { action?.Invoke(userLc); } var outputSink = userLc.CreateLogger(); sourceConfig.MinimumLevel.Verbose().Enrich.WithBufferContext(); bool IsFallbackSourceConfig(SourceConfig s) { return(string.IsNullOrEmpty(s.SourceToMatchOn) || s.SourceToMatchOn == "*"); } var sourceConfigs = configSetList.Where(x => !IsFallbackSourceConfig(x)).ToList(); var fallbackConfig = configSetList.LastOrDefault(IsFallbackSourceConfig); // Create source configs and fallback for the BufferSink var bufferConfigs = sourceConfigs.Select( x => new BufferSink.SourceConfig_Internal( Matching.FromSource(x.SourceToMatchOn), x.MinLevelAlways, null ) ) .ToList(); var bufferFallbackConfig = fallbackConfig != null ? new BufferSink.SourceConfig_Internal(_ => true, fallbackConfig.MinLevelAlways, fallbackLevelSwitch) : null; // Create BufferSink with configs and outputSink var bufferSink = new BufferSink( new BufferSinkConfig(triggerEventLevel, outputSink, bufferCapacity), bufferConfigs, bufferFallbackConfig ); foreach (var c in sourceConfigs) { // Events matching a source config will obey the lower of the two minimum levels var minimumLevel = c.MinLevelAlways < c.MinLevelOnDetailed ? c.MinLevelAlways : c.MinLevelOnDetailed; // NB: MinimumLevel.Override not usable in sub-loggers, see Serilog issue #967 // We implement the equivalent filter sourceConfig.WriteTo.Logger( l => l.Filter.ByIncludingOnly(Matching.FromSource(c.SourceToMatchOn)) .MinimumLevel.Is(minimumLevel) .WriteTo.Sink(bufferSink) ); } // Handle anything without a matching source config sourceConfig.WriteTo.Logger( l => { // Exclude events that match any config foreach (var c in sourceConfigs) { l.Filter.ByExcluding(Matching.FromSource(c.SourceToMatchOn)); } ILogEventSink baseSink; if (fallbackConfig != null) { // Events matching a source config will obey the lower of the two minimum levels l.MinimumLevel.Is( fallbackConfig.MinLevelAlways < fallbackConfig.MinLevelOnDetailed ? fallbackConfig.MinLevelAlways : fallbackConfig.MinLevelOnDetailed ); baseSink = bufferSink; } else { // No fallback config given, so write to output immediately baseSink = outputSink; } l.WriteTo.Sink(baseSink); } ); return(sourceConfig); }
/// <summary> /// Add output configuration for the the buffered sink. /// </summary> /// <param name="configureOutput">Logger configuration setup to handle writing events to outputs.</param> public BufferSinkLoggerConfiguration WriteTo(Action <LoggerConfiguration> configureOutput) { // Create a LogBufferScope as early as possible to capture the most general AsyncLocal context // TODO: Replace this with a global static scope that is parent to all orphan scopes LogBufferScope.EnsureCreated(); var userLc = new LoggerConfiguration().MinimumLevel.Verbose(); configureOutput.Invoke(userLc); var outputSink = userLc.CreateLogger(); LoggerConfiguration.MinimumLevel.Verbose().Enrich.WithBufferContext(); bool IsFallbackSourceConfig(SourceConfig s) { return(string.IsNullOrEmpty(s.SourceToMatchOn) || s.SourceToMatchOn == "*"); } var sourceConfigs = SourceConfigs.Where(x => !IsFallbackSourceConfig(x)).ToList(); var fallbackConfig = SourceConfigs.LastOrDefault(IsFallbackSourceConfig); // Create source configs and fallback for the BufferSink var bufferConfigs = sourceConfigs.Select( x => new BufferSink.SourceConfig_Internal( Matching.FromSource(x.SourceToMatchOn), x.MinLevelAlways, null ) ) .ToList(); var bufferFallbackConfig = fallbackConfig != null ? new BufferSink.SourceConfig_Internal(_ => true, fallbackConfig.MinLevelAlways, FallbackLevelSwitch) : null; // Create BufferSink with configs and outputSink var bufferSink = new BufferSink( new BufferSinkConfig(TriggeringLevel, outputSink, BufferCapacity), bufferConfigs, bufferFallbackConfig ); foreach (var c in sourceConfigs) { // Events matching a source config will obey the lower of the two minimum levels var minimumLevel = c.MinLevelAlways < c.MinLevelOnDetailed ? c.MinLevelAlways : c.MinLevelOnDetailed; // NB: MinimumLevel.Override not usable in sub-loggers, see Serilog issue #967 // We implement the equivalent filter LoggerConfiguration.WriteTo.Logger( l => l.Filter.ByIncludingOnly(Matching.FromSource(c.SourceToMatchOn)) .MinimumLevel.Is(minimumLevel) .WriteTo.Sink(bufferSink) ); } // Handle anything without a matching source config LoggerConfiguration.WriteTo.Logger( l => { // Exclude events that match any config foreach (var c in sourceConfigs) { l.Filter.ByExcluding(Matching.FromSource(c.SourceToMatchOn)); } if (fallbackConfig != null) { // Events matching a source config will obey the lower of the two minimum levels l.MinimumLevel.Is( fallbackConfig.MinLevelAlways < fallbackConfig.MinLevelOnDetailed ? fallbackConfig.MinLevelAlways : fallbackConfig.MinLevelOnDetailed ); l.WriteTo.Sink(bufferSink); } else { // No fallback config given, so write to output immediately l.WriteTo.Sink(outputSink); } } ); return(new BufferSinkLoggerConfiguration(LoggerConfiguration)); }