summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.Helpers/PipeServer.cs
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 15:29:41 +0000
committerLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 15:29:41 +0000
commit225aa1499e37faf9d38257caabbadc68d78b427e (patch)
tree102bb7a40c58595348ae9d3c7076201759fe0720 /Decompiler/Gestor.Application.Helpers/PipeServer.cs
parent1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (diff)
downloadgestor-225aa1499e37faf9d38257caabbadc68d78b427e.tar.gz
gestor-225aa1499e37faf9d38257caabbadc68d78b427e.zip
decompiler.com
Diffstat (limited to 'Decompiler/Gestor.Application.Helpers/PipeServer.cs')
-rw-r--r--Decompiler/Gestor.Application.Helpers/PipeServer.cs96
1 files changed, 96 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.Helpers/PipeServer.cs b/Decompiler/Gestor.Application.Helpers/PipeServer.cs
new file mode 100644
index 0000000..36c40c3
--- /dev/null
+++ b/Decompiler/Gestor.Application.Helpers/PipeServer.cs
@@ -0,0 +1,96 @@
+using System;
+using System.IO;
+using System.IO.Pipes;
+using System.Security.AccessControl;
+using System.Security.Principal;
+using Assinador.Model.Common;
+using Gestor.Application.Actions;
+using Newtonsoft.Json;
+
+namespace Gestor.Application.Helpers;
+
+public class PipeServer : IDisposable
+{
+ private string _pipeName;
+
+ private NamedPipeServerStream Pipe { get; set; }
+
+ public bool CreateServer(string name)
+ {
+ _pipeName = name;
+ return Create();
+ }
+
+ private bool Create()
+ {
+ bool flag = true;
+ try
+ {
+ new NamedPipeClientStream(".", _pipeName, PipeDirection.Out, PipeOptions.Asynchronous).Connect(1000);
+ }
+ catch (TimeoutException)
+ {
+ flag = false;
+ }
+ catch (Exception)
+ {
+ return false;
+ }
+ if (flag)
+ {
+ return true;
+ }
+ try
+ {
+ PipeSecurity pipeSecurity = new PipeSecurity();
+ SecurityIdentifier securityIdentifier = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
+ securityIdentifier.Translate(typeof(NTAccount));
+ pipeSecurity.SetAccessRule(new PipeAccessRule(securityIdentifier, PipeAccessRights.ReadWrite, AccessControlType.Allow));
+ Pipe = new NamedPipeServerStream(_pipeName, PipeDirection.In, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous, 1, 1, pipeSecurity);
+ Pipe.BeginWaitForConnection(WaitForConnectionCallBack, Pipe);
+ }
+ catch (Exception)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ private void WaitForConnectionCallBack(IAsyncResult iar)
+ {
+ try
+ {
+ NamedPipeServerStream namedPipeServerStream = (NamedPipeServerStream)iar.AsyncState;
+ namedPipeServerStream.EndWaitForConnection(iar);
+ using (StreamReader streamReader = new StreamReader(Pipe))
+ {
+ string text = streamReader.ReadLine();
+ if (text != null && text.IndexOf("exit", StringComparison.InvariantCultureIgnoreCase) > -1)
+ {
+ Dispose();
+ }
+ Handle(text);
+ }
+ namedPipeServerStream.Close();
+ namedPipeServerStream = null;
+ Create();
+ }
+ catch
+ {
+ }
+ }
+
+ public void Dispose()
+ {
+ Pipe.Dispose();
+ }
+
+ private void Handle(string message)
+ {
+ if (message != null)
+ {
+ PipeMessageResult obj = JsonConvert.DeserializeObject<PipeMessageResult>(message);
+ Gestor.Application.Actions.Actions.AcessarHoster?.Invoke(obj);
+ }
+ }
+}