CSHARP   34

ClientController

Guest on 24th November 2022 01:32:28 AM

  1. using System;
  2. using XSockets.Core.XSocket;
  3. using XSockets.Core.XSocket.Helpers;
  4. using Toolbox;
  5. using XSockets.Core.Common.Socket.Event.Interface;
  6. using XSockets.Core.Common.Socket.Event.Arguments;
  7.  
  8. namespace H_Man
  9. {
  10.   public class ClientController : XSocketController
  11.   {
  12.     private string vmGUID = string.Empty;
  13.  
  14.     public ClientController()
  15.     {
  16.       this.OnOpen += ClientAcceptor_OnOpen;
  17.       this.OnClose += ClientAcceptor_OnClose;
  18.     }
  19.  
  20.     private void ClientAcceptor_OnOpen(object sender, OnClientConnectArgs e)
  21.     {      
  22.       this.vmGUID = e.Controller.ClientGuid.ToString();
  23.       GlobalCache.HostMachine.AddVM(this.vmGUID);
  24.  
  25.       Console.WriteLine("Client connected from x: {0}", e.Controller.ClientGuid);
  26.     }
  27.  
  28.     private void ClientAcceptor_OnClose(object sender, OnClientDisconnectArgs e)
  29.     {
  30.       GlobalCache.HostMachine.RemoveVM(this.vmGUID);
  31.       Console.WriteLine("Client disconnected from x: {0}", e.Controller.ClientGuid);
  32.     }
  33.  
  34.     public override void OnMessage(ITextArgs textArgs)
  35.     {
  36.       string eventType = textArgs.@event;
  37.  
  38.       switch (eventType)
  39.       {
  40.         case MessageName.VmantoHmanResInfo:
  41.           VMPacket vmPacket = textArgs.data.Deserialize<VMPacket>();
  42.           // Resource handler : read rest of the resource from Xen
  43.           ResourceHandler.UpdateVMPacket(vmPacket);
  44.           GlobalCache.HostMachine.UpdateVM(this.vmGUID, vmPacket);
  45.           ResourceHandler.ReadHostInfo();
  46.           GlobalCache.HostMachine.Print();
  47.           break;
  48.       }
  49.     }
  50.   }
  51. }

Raw Paste


Login or Register to edit or fork this paste. It's free.