5using System.Security.Principal;
7using System.Threading.Tasks;
25 private readonly LinkedList<byte[]> pipeQueue =
new LinkedList<byte[]>();
27 private readonly
string pipeName;
28 private NamedPipeClientStream pipe;
29 private bool writing =
false;
37 : this(ObjectId, PipeName, DefaultFactory)
50 this.pipeStreamFactory = StreamFactory;
52 this.pipeName = PipeName;
55 private static NamedPipeClientStream DefaultFactory(
string Name)
57 return new NamedPipeClientStream(
".", Name, PipeDirection.Out, PipeOptions.Asynchronous,
58 TokenImpersonationLevel.Anonymous, HandleInheritability.None);
64 public NamedPipeClientStream
Pipe => this.pipe;
71 if (!(this.pipe is
null))
77 return base.DisposeAsync();
95 return this.
Queue(Xml,
true);
104 private async Task Queue(
string Xml,
bool ValidateXml)
107 throw new ArgumentException(
"Invalid XML.", nameof(Xml));
111 byte[] Bin = Encoding.UTF8.GetBytes(Xml);
113 lock (this.pipeQueue)
117 this.pipeQueue.AddLast(Bin);
124 if (!(this.pipe is
null) && !this.pipe.IsConnected)
130 if (this.pipe is
null)
132 this.pipe = this.pipeStreamFactory(this.pipeName);
134 await this.pipe.ConnectAsync(5000);
138 while (!(Bin is
null))
140 await this.pipe.WriteAsync(Bin, 0, Bin.Length);
142 lock (this.pipeQueue)
144 if (this.pipeQueue.First is
null)
146 this.writing =
false;
151 Bin = this.pipeQueue.First.Value;
152 this.pipeQueue.RemoveFirst();
157 catch (TimeoutException)
159 this.EmptyPipeQueue();
163 this.EmptyPipeQueue();
167 this.EmptyPipeQueue();
172 private void EmptyPipeQueue()
174 lock (this.pipeQueue)
176 this.pipeQueue.Clear();
177 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.
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.
override Task DisposeAsync()
IDisposableAsync.DisposeAsync()
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.