IPCClientFactory.cs 1.1 KB

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