2using System.Collections.Generic;
5using System.Security.Principal;
7using System.Threading.Tasks;
26 private readonly LinkedList<byte[]> pipeQueue =
new LinkedList<byte[]>();
28 private readonly
string pipeName;
29 private NamedPipeClientStream pipe;
30 private bool writing =
false;
38 : this(ObjectId, PipeName, DefaultFactory)
51 this.pipeStreamFactory = StreamFactory;
53 this.pipeName = PipeName;
56 private static NamedPipeClientStream DefaultFactory(
string Name)
58 return new NamedPipeClientStream(
".", Name, PipeDirection.Out, PipeOptions.Asynchronous,
59 TokenImpersonationLevel.Anonymous, HandleInheritability.None);
65 public NamedPipeClientStream
Pipe => this.pipe;
93 return this.
Queue(Xml,
true);
100 private async Task Queue(
string Xml,
bool ValidateXml)
103 throw new ArgumentException(
"Invalid XML.", nameof(Xml));
107 byte[] Bin = Encoding.UTF8.GetBytes(Xml);
109 lock (this.pipeQueue)
113 this.pipeQueue.AddLast(Bin);
120 if (!(this.pipe is
null) && !this.pipe.IsConnected)
126 if (this.pipe is
null)
128 this.pipe = this.pipeStreamFactory(this.pipeName);
130 await this.pipe.ConnectAsync(5000);
134 while (!(Bin is
null))
136 await this.pipe.WriteAsync(Bin, 0, Bin.Length);
138 lock (this.pipeQueue)
140 if (this.pipeQueue.First is
null)
142 this.writing =
false;
147 Bin = this.pipeQueue.First.Value;
148 this.pipeQueue.RemoveFirst();
153 catch (TimeoutException)
155 this.EmptyPipeQueue();
159 this.EmptyPipeQueue();
163 this.EmptyPipeQueue();
168 private void EmptyPipeQueue()
170 lock (this.pipeQueue)
172 this.pipeQueue.Clear();
173 this.writing =
false;
Helps with common XML-related tasks.
static bool IsValidXml(string Xml)
Checks if a string is valid XML
Class representing an event.
Base class for event sinks.
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Writes logged events to an operating system pipe, for inter-process communication.
PipeEventSink(string ObjectId, string PipeName)
Writes logged events to an operating system pipe, for inter-process communication.
override void Dispose()
IDisposable.Dispose()
EventHandlerAsync AfterConnect
Raised after connecting to the pipe stream
override Task Queue(Event Event)
Queues an event to be output.
PipeEventSink(string ObjectId, string PipeName, NamedPipeClientStreamFactory StreamFactory)
Writes logged events to an operating system pipe, for inter-process communication.
NamedPipeClientStream Pipe
Pipe object.
EventHandlerAsync BeforeConnect
Raised before connecting to the pipe stream.
Task Queue(string Xml)
Queues XML-encoded information to be output.
delegate NamedPipeClientStream NamedPipeClientStreamFactory(string Name)
Delegate for methods that create object instances of NamedPipeClientStream.
delegate Task EventHandlerAsync(object Sender, EventArgs e)
Asynchronous version of EventArgs.