private void GingerSocketServerMessageHandler(GingerSocketInfo gingerSocketInfo) { NewPayLoad p = gingerSocketInfo.DataAsPayload; switch (p.Name) { case "List": //TODO: use const { NewPayLoad RC = new NewPayLoad("RC"); RC.AddValue("OK"); //TODO: return the list of GingerNodeInfo RC.ClosePackage(); gingerSocketInfo.Response = RC; break; } case SocketMessages.Register: { string NodeName = p.GetValueString(); string NodeOS = p.GetValueString(); string NodeHost = p.GetValueString(); string NodeIP = p.GetValueString(); NewPayLoad RC = new NewPayLoad("SessionID", gingerSocketInfo.SessionID); gingerSocketInfo.Response = RC; // add the info of the new node to the grid list mGingerNodeInfo.Add(new GingerNodeInfo() { Name = NodeName, OS = NodeOS, Host = NodeHost, IP = NodeIP, SessionID = gingerSocketInfo.SessionID }); break; } case SocketMessages.Unregister: { Guid SessionID = p.GetGuid(); GingerNodeInfo GNI = (from x in mGingerNodeInfo where x.SessionID == SessionID select x).FirstOrDefault(); //TODO - if not found return err mGingerNodeInfo.Remove(GNI); NewPayLoad RC = new NewPayLoad("OK"); RC.ClosePackage(); gingerSocketInfo.Response = RC; break; } default: throw new Exception("GingerSocketServerMessageHandler: Unknown Message type: " + p.Name); } }
private void HubClientMessageHandler(GingerSocketInfo gingerSocketInfo) { Console.WriteLine("Processing Message"); NewPayLoad pl = gingerSocketInfo.DataAsPayload; switch (pl.Name) { case SocketMessages.Reserve: gingerSocketInfo.Response = Reserve(pl); break; case "RunAction": gingerSocketInfo.Response = RunAction(pl); break; case "RunPlatformAction": gingerSocketInfo.Response = RunPlatformAction(pl); break; case "StartDriver": gingerSocketInfo.Response = StartDriver(pl); break; case "CloseDriver": gingerSocketInfo.Response = CloseDriver(); break; case "Shutdown": gingerSocketInfo.Response = ShutdownNode(); break; case "Ping": gingerSocketInfo.Response = Ping(); break; case "AttachDisplay": gingerSocketInfo.Response = AttachDisplay(pl); break; case "ScreenshotAction": gingerSocketInfo.Response = TakeScreenot(pl); break; default: throw new Exception("Unknown Messgae: " + pl.Name); } }
private void MessageHandler(GingerSocketInfo gingerSocketInfo) { NewPayLoad PLRC = HandlePayLoad(gingerSocketInfo.DataAsPayload); gingerSocketInfo.Response = PLRC; }
// Handle server messages private void MessageHandler(GingerSocketInfo obj) { NewPayLoad PLRC = HandlePayLoadFromServer(obj.DataAsPayload); obj.Response = PLRC; }
private void GingerSocketServerMessageHandler(GingerSocketInfo gingerSocketInfo) { NewPayLoad p = gingerSocketInfo.DataAsPayload; switch (p.Name) { case "List": //TODO: use const { NewPayLoad RC = new NewPayLoad("RC"); RC.AddValue("OK"); //TODO: return the list of GingerNodeInfo RC.ClosePackage(); gingerSocketInfo.Response = RC; break; } case SocketMessages.Register: { string NodeName = p.GetValueString(); string NodeServiceID = p.GetValueString(); string NodeOS = p.GetValueString(); string NodeHost = p.GetValueString(); string NodeIP = p.GetValueString(); NewPayLoad RC = new NewPayLoad("SessionID", gingerSocketInfo.SessionID); gingerSocketInfo.Response = RC; // add the info of the new node to the grid list mGingerNodeInfo.Add(new GingerNodeInfo() { Name = NodeName, ServiceId = NodeServiceID, OS = NodeOS, Host = NodeHost, IP = NodeIP, SessionID = gingerSocketInfo.SessionID, Status = GingerNodeInfo.eStatus.Ready }); break; } case SocketMessages.Unregister: { Guid SessionID = p.GetGuid(); GingerNodeInfo GNI = (from x in mGingerNodeInfo where x.SessionID == SessionID select x).FirstOrDefault(); if (GNI == null) { gingerSocketInfo.Response = new NewPayLoad("Error", "Ginger node info not found for session id " + SessionID.ToString()); } mGingerNodeInfo.Remove(GNI); NewPayLoad RC = new NewPayLoad("OK"); RC.ClosePackage(); gingerSocketInfo.Response = RC; break; } // Combine find and send to one - send session id or how to find // Change to reserve node case SocketMessages.FindNode: // Find node which match criteria, used for remote grid string ServiceID = p.GetValueString(); // !!! find first or use better algorithm GingerNodeInfo gingerNodeInfo1 = (from x in NodeList where x.ServiceId == ServiceID select x).FirstOrDefault(); // Reserve // TODO: lock !!!!!!!!!!!!!!!!!!!! gingerNodeInfo1.Status = GingerNodeInfo.eStatus.Reserved; // TODO: release !!!!!!!!!!!!!!!! NewPayLoad RC2 = new NewPayLoad("NodeInfo", gingerNodeInfo1.SessionID); gingerSocketInfo.Response = RC2; break; case SocketMessages.SendToNode: // Send action to Node, used when Grid is remote Guid SessionID2 = p.GetGuid(); GingerNodeInfo gingerNodeInfo = (from x in NodeList where x.SessionID == SessionID2 select x).SingleOrDefault(); NewPayLoad actionPayload = p.ReadPayload(); NewPayLoad remoteNodeActionResponce = SendRequestPayLoad(gingerNodeInfo.SessionID, actionPayload); remoteNodeActionResponce.Truncate(); gingerSocketInfo.Response = remoteNodeActionResponce; gingerNodeInfo.Status = GingerNodeInfo.eStatus.Ready; //TODO: in case of session to do not release break; default: throw new Exception("GingerSocketServerMessageHandler: Unknown Message type: " + p.Name); } }