public DiagnosticController(IContentItemRepository repository, IHost host, IDefinitionManager definitions, ILinkGenerator linkGenerator, IUrlParser parser, DatabaseSection config, IFlushable flushable, IReplicationStorage repstore, IFileSystemFactory fileSystemFactory) { _repository = repository; _host = host; _definitions = definitions; _linkGenerator = linkGenerator; _parser = parser; _flushable = flushable; _tablePrefix = config.TablePrefix; _repstore = repstore; if (_forceWriteLockManager != null) return; // Create Force Write Lock Manager var storageConfig = (FileSystemNamespace) Enum.Parse(typeof (FileSystemNamespace), ConfigurationManager.AppSettings["AzureReplicationStorageContainerName"] ?? "ReplicationStorageDebug"); var fileSystem = fileSystemFactory.Create(storageConfig); _forceWriteLockManager = new ReplicationForceWriteLockManager(fileSystem); _writeLockManager = new ReplicationWriteLockManager(fileSystem); }
/// <summary> /// Add the given item to my flush list. /// </summary> internal void AddFlushAction(IFlushable item) { if (!flushActions.Contains(item)) { flushActions.Add(item); } }
/// <summary> /// Construct a new LedDriver using a collection of GPIO output pins /// </summary> /// <param name="Pins">The list of digital output pins to use</param> /// <param name="useActiveLowOutput">Whether a digital LOW value should be used to turn the LED on</param> /// <param name="controller">An IFlushable controller where the GPIO resides</param> public GpioLedDriver(IList <TDigitalOutPin> Pins, bool useActiveLowOutput = false, IFlushable controller = null) : base(Pins.Count, false, false) { this.Pins = Pins; this.controller = controller; this.useActiveLowOutput = useActiveLowOutput; }
/// <summary> /// Construct a new LedDriver using a collection of GPIO output pins /// </summary> /// <param name="Pins">The list of digital output pins to use</param> /// <param name="useActiveLowOutput">Whether a digital LOW value should be used to turn the LED on</param> /// <param name="controller">An IFlushable controller where the GPIO resides</param> public PwmLedDriver(IList <TPwm> Pins, bool useActiveLowOutput = false, IFlushable controller = null) : base(Pins.Count, false, true) { this.Pins = Pins; this.controller = controller; this.useActiveLowOutput = useActiveLowOutput; }
public DiagnosticController(IContentItemRepository repository, IHost host, IDefinitionManager definitions, ILinkGenerator linkGenerator, IUrlParser parser, DatabaseSection config, IFlushable flushable, IReplicationStorage repstore, IFileSystemFactory fileSystemFactory) { _repository = repository; _host = host; _definitions = definitions; _linkGenerator = linkGenerator; _parser = parser; _flushable = flushable; _tablePrefix = config.TablePrefix; _repstore = repstore; if (_forceWriteLockManager != null) { return; } // Create Force Write Lock Manager var storageConfig = (FileSystemNamespace)Enum.Parse(typeof(FileSystemNamespace), ConfigurationManager.AppSettings["AzureReplicationStorageContainerName"] ?? "ReplicationStorageDebug"); var fileSystem = fileSystemFactory.Create(storageConfig); _forceWriteLockManager = new ReplicationForceWriteLockManager(fileSystem); _writeLockManager = new ReplicationWriteLockManager(fileSystem); }
/// <summary> /// Returns writable stream associated with the buffer writer. /// </summary> /// <typeparam name="TWriter">The type of the writer.</typeparam> /// <param name="writer">The writer to be wrapped by the stream.</param> /// <param name="flush">Optional synchronous flush action.</param> /// <param name="flushAsync">Optiona asynchronous flush action.</param> /// <returns>The writable stream wrapping buffer writer.</returns> public static Stream AsStream <TWriter>(this TWriter writer, Action <TWriter>?flush = null, Func <TWriter, CancellationToken, Task>?flushAsync = null) where TWriter : class, IBufferWriter <byte> { flush ??= IFlushable.TryReflectFlushMethod(writer); flushAsync ??= IFlushable.TryReflectAsyncFlushMethod(writer); return(AsStream(Span.CopyTo <byte>, writer, flush, flushAsync)); }
/// <summary> /// Creates text writer backed by the char buffer writer. /// </summary> /// <param name="writer">The buffer writer.</param> /// <param name="provider">The object that controls formatting.</param> /// <param name="flush">The optional implementation of <see cref="TextWriter.Flush"/> method.</param> /// <param name="flushAsync">The optional implementation of <see cref="TextWriter.FlushAsync"/> method.</param> /// <typeparam name="TWriter">The type of the char buffer writer.</typeparam> /// <returns>The text writer backed by the buffer writer.</returns> public static TextWriter AsTextWriter <TWriter>(this TWriter writer, IFormatProvider?provider = null, Action <TWriter>?flush = null, Func <TWriter, CancellationToken, Task>?flushAsync = null) where TWriter : class, IBufferWriter <char> { flush ??= IFlushable.TryReflectFlushMethod(writer); flushAsync ??= IFlushable.TryReflectAsyncFlushMethod(writer); return(new TextBufferWriter <TWriter>(writer, provider, flush, flushAsync)); }
public void Dispose() { if (_target == null) { return; } _target.Flush(); _target = null; }
void IDisposable.Dispose() { if (_target == null) { return; } _target.Flush(); _target = null; }
/// <summary> /// Returns writable stream associated with the buffer writer. /// </summary> /// <typeparam name="TWriter">The type of the writer.</typeparam> /// <param name="writer">The writer to be wrapped by the stream.</param> /// <param name="flush">Optional synchronous flush action.</param> /// <param name="flushAsync">Optiona asynchronous flush action.</param> /// <returns>The writable stream wrapping buffer writer.</returns> public static Stream AsStream <TWriter>(this TWriter writer, Action <TWriter>?flush = null, Func <TWriter, CancellationToken, Task>?flushAsync = null) where TWriter : class, IBufferWriter <byte> { flush ??= IFlushable.TryReflectFlushMethod(writer); flushAsync ??= IFlushable.TryReflectAsyncFlushMethod(writer); var callback = writer is IGrowableBuffer <byte>? new ReadOnlySpanAction <byte, TWriter>(WriteToGrowableBuffer) : new ReadOnlySpanAction <byte, TWriter>(Span.CopyTo <byte>); return(AsStream(callback, writer, flush, flushAsync));
public static void Release(List <T> toRelease) { if (toRelease.Count > 0 && toRelease[0] is IFlushable) { for (int i = 0; i < toRelease.Count; i++) { IFlushable obj = (IFlushable)toRelease[i]; (obj).Flush(); } } toRelease.Clear(); s_ListPool.Release(toRelease); }
public static bool Flush(int millisecondsTimeout) { IFlushable flushableRepository = LoggerManager.GetRepository(Assembly.GetCallingAssembly()) as IFlushable; if (flushableRepository == null) { return(false); } else { return(flushableRepository.Flush(millisecondsTimeout)); } }
public bool Flush(int millisecondsTimeout) { if (millisecondsTimeout < -1) { throw new ArgumentOutOfRangeException("millisecondsTimeout", "Timeout must be -1 (Timeout.Infinite) or non-negative"); } // Assume success until one of the appenders fails bool result = true; // Use DateTime.UtcNow rather than a System.Diagnostics.Stopwatch for compatibility with .NET 1.x DateTime startTimeUtc = DateTime.UtcNow; // Do buffering appenders first. These may be forwarding to other appenders foreach (Appender.IAppender appender in GetAppenders()) { IFlushable flushable = appender as IFlushable; if (flushable == null) { continue; } if (appender is Appender.BufferingAppenderSkeleton) { int timeout = GetWaitTime(startTimeUtc, millisecondsTimeout); if (!flushable.Flush(timeout)) { result = false; } } } // Do non-buffering appenders. foreach (Appender.IAppender appender in GetAppenders()) { IFlushable flushable = appender as IFlushable; if (flushable == null) { continue; } if (!(appender is Appender.BufferingAppenderSkeleton)) { int timeout = GetWaitTime(startTimeUtc, millisecondsTimeout); if (!flushable.Flush(timeout)) { result = false; } } } return(result); }
public ReplicationManager( IPersister persister, IItemFinder finder, IReplicationStorage repstore, IFileSystemFactory fileSystemFactory, DatabaseSection dataBaseSection, ISecurityManager security, IIndexer indexer, // optional IFlushable flushable // optional ) { _repstore = repstore; _security = security; _persister = persister; _finder = finder; _indexer = indexer; _flushable = flushable; // detect sync direction from Database Type and double check via config string value = ConfigurationManager.AppSettings["XmlReplication"] ?? "false"; IsSlave = value.Equals("Slave", StringComparison.InvariantCultureIgnoreCase) & (dataBaseSection.Flavour == DatabaseFlavour.Xml); IsMaster = value.Equals("Master", StringComparison.InvariantCultureIgnoreCase) & !IsSlave; if (IsMaster || IsSlave) { // only initialize if replication is active var storageConfig = (FileSystemNamespace)Enum.Parse(typeof(FileSystemNamespace), ConfigurationManager.AppSettings["AzureReplicationStorageContainerName"] ?? "ReplicationStorageDebug"); _fileSystem = fileSystemFactory.Create(storageConfig); // constructing these dependencies to ensure same filesystem and simplify construction _replicationWriteLockManager = new ReplicationWriteLockManager(_fileSystem); _replicationReadLockManager = new ReplicationReadLockManager(_fileSystem); } _replicationLogPath = "/_Xml_Sync_Log"; }
/// <summary> /// Flushes all configured Appenders that implement <see cref="T:log4net.Appender.IFlushable" />. /// </summary> /// <param name="millisecondsTimeout">The maximum time in milliseconds to wait for logging events from asycnhronous appenders to be flushed, /// or <see cref="F:System.Threading.Timeout.Infinite" /> to wait indefinitely.</param> /// <returns><c>True</c> if all logging events were flushed successfully, else <c>false</c>.</returns> public bool Flush(int millisecondsTimeout) { if (millisecondsTimeout < -1) { throw new ArgumentOutOfRangeException("millisecondsTimeout", "Timeout must be -1 (Timeout.Infinite) or non-negative"); } bool result = true; DateTime utcNow = DateTime.UtcNow; IAppender[] appenders = GetAppenders(); foreach (IAppender appender in appenders) { IFlushable flushable = appender as IFlushable; if (flushable != null && appender is BufferingAppenderSkeleton) { int waitTime = GetWaitTime(utcNow, millisecondsTimeout); if (!flushable.Flush(waitTime)) { result = false; } } } appenders = GetAppenders(); foreach (IAppender appender2 in appenders) { IFlushable flushable2 = appender2 as IFlushable; if (flushable2 != null && !(appender2 is BufferingAppenderSkeleton)) { int waitTime2 = GetWaitTime(utcNow, millisecondsTimeout); if (!flushable2.Flush(waitTime2)) { result = false; } } } return(result); }
internal AsyncBufferWriter(IBufferWriter <byte> writer) { this.writer = writer ?? throw new ArgumentNullException(nameof(writer)); flush = IFlushable.TryReflectAsyncFlushMethod(writer); }
/// <summary> /// Creates a new <see cref="FlushableWrapper"/>. /// </summary> /// <param name="console">The console to implement <see cref="Console"/> methods from.</param> /// <param name="needsFlushing">The <see cref="IFlushable"/> that needs to be flushed.</param> public FlushableWrapper([NotNull] Console console, [NotNull] IFlushable needsFlushing) { _console = console; _flush = needsFlushing; }
/// <summary> /// Creates text writer backed by the char buffer writer. /// </summary> /// <param name="writer">The buffer writer.</param> /// <param name="provider">The object that controls formatting.</param> /// <param name="flush">The optional implementation of <see cref="TextWriter.Flush"/> method.</param> /// <param name="flushAsync">The optional implementation of <see cref="TextWriter.FlushAsync"/> method.</param> /// <typeparam name="TWriter">The type of the char buffer writer.</typeparam> /// <returns>The text writer backed by the buffer writer.</returns> public static TextWriter AsTextWriter <TWriter>(this TWriter writer, IFormatProvider?provider = null, Action <TWriter>?flush = null, Func <TWriter, CancellationToken, Task>?flushAsync = null) where TWriter : class, IBufferWriter <char> { IFlushable.DiscoverFlushMethods(writer, ref flush, ref flushAsync); return(new TextBufferWriter <TWriter>(writer, provider, flush, flushAsync)); }
public Flusher(IFlushable target) { _target = target; }
public AutoFlushStreamDecorator(IFlushable flushable, Stream innerStream) { _flushable = flushable; _innerStream = innerStream; }
/// <summary> /// /// </summary> /// <param name="target"></param> public BatchedScheduler(IFlushable target) { _flushable = target; }
public ReplicationManager( IPersister persister, IItemFinder finder, IReplicationStorage repstore, IFileSystemFactory fileSystemFactory, DatabaseSection dataBaseSection, ISecurityManager security, IIndexer indexer, // optional IFlushable flushable // optional ) { _repstore = repstore; _security = security; _persister = persister; _finder = finder; _indexer = indexer; _flushable = flushable; // detect sync direction from Database Type and double check via config string value = ConfigurationManager.AppSettings["XmlReplication"] ?? "false"; IsSlave = value.Equals("Slave", StringComparison.InvariantCultureIgnoreCase) & (dataBaseSection.Flavour == DatabaseFlavour.Xml); IsMaster = value.Equals("Master", StringComparison.InvariantCultureIgnoreCase) & !IsSlave; if (IsMaster || IsSlave) { // only initialize if replication is active var storageConfig = (FileSystemNamespace) Enum.Parse(typeof (FileSystemNamespace), ConfigurationManager.AppSettings["AzureReplicationStorageContainerName"] ?? "ReplicationStorageDebug"); _fileSystem = fileSystemFactory.Create(storageConfig); // constructing these dependencies to ensure same filesystem and simplify construction _replicationWriteLockManager = new ReplicationWriteLockManager(_fileSystem); _replicationReadLockManager = new ReplicationReadLockManager(_fileSystem); } _replicationLogPath = "/_Xml_Sync_Log"; }