IPCClientFactory.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using InABox.Clients;
  2. using InABox.Core;
  3. using InABox.IPC;
  4. using System;
  5. using System.Collections.Concurrent;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace InABox.Client.IPC
  11. {
  12. public static class IPCClientFactory
  13. {
  14. private static ConcurrentDictionary<string, IPCClientTransport> Clients = new();
  15. public static IPCClientTransport GetClient(string pipeName)
  16. {
  17. if (!Clients.TryGetValue(pipeName, out var client))
  18. {
  19. client = new IPCClientTransport(pipeName);
  20. Clients[pipeName] = client;
  21. client.OnPush += Client_OnPush;
  22. }
  23. return client;
  24. }
  25. private static void Client_OnPush(IPCMessage request)
  26. {
  27. if(request.Method == Method.Push)
  28. {
  29. if(request.Type is not null && CoreUtils.TryGetEntity(request.Type, out var entity))
  30. {
  31. ClientFactory.PushHandlers.Push(entity, request.GetRequest(entity));
  32. }
  33. }
  34. }
  35. }
  36. }