public NewPayLoad ExecuteActionOnRemoteGridPlugin(NewPayLoad payload) { bool closeConn = false; if (hubClient == null) { hubClient = new GingerSocketClient2(); hubClient.Connect(RemoteGridIP, RemoteGridPort); // For action without session NewPayLoad fpl = new NewPayLoad(SocketMessages.FindNode, "MathService", "ccc"); // !!!!!!!!!!!!!!!! // NewPayLoad fpl = new NewPayLoad(SocketMessages.FindNode, "SeleniumChromeService", "ccc"); // !!!!!!!!!!!!!!!! DUP REMOVE !!!! NewPayLoad rc = hubClient.SendRequestPayLoad(fpl); sessionID = rc.GetGuid(); closeConn = true; } else { } // TODO: reserve if session NewPayLoad fpl3 = new NewPayLoad(SocketMessages.SendToNode, sessionID, payload); // fpl3.ClosePackage(); NewPayLoad rc4 = hubClient.SendRequestPayLoad(fpl3); // Send to Ginger Grid which will send to Ginger Node to run the action if (closeConn) { hubClient.CloseConnection(); // Not for session } return(rc4); }
public NewPayLoad ExecuteActionOnRemoteGridPlugin(NewPayLoad payload) { // Improve for speed keep connection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! find correct service/node, session !!!!!!!!!!!!!! if (mHubClient == null) { mHubClient = new GingerSocketClient2(); mHubClient.Connect(RemoteGridIP, RemoteGridPort); } NewPayLoad fpl = new NewPayLoad(SocketMessages.FindNode, "MathService", "ccc"); NewPayLoad rc = mHubClient.SendRequestPayLoad(fpl); Guid sessionID = rc.GetGuid(); // TODO: reserve if session // NewPayLoad actionPayload = CreateActionPayload(actPlugin); NewPayLoad fpl3 = new NewPayLoad(SocketMessages.SendToNode, sessionID, payload); // fpl3.ClosePackage(); NewPayLoad rc4 = mHubClient.SendRequestPayLoad(fpl3); // Send to Ginger Grid which will send to Ginger Node to run the action mHubClient.CloseConnection(); return(rc4); // rc4.DumpToConsole(); }
public void Connect() { mGingerSocketClient2 = new GingerSocketClient2(); mGingerSocketClient2.MessageHandler = MessageHandler; IPAddress ipAddress = Dns.GetHostEntry(Dns.GetHostName()).AddressList.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork); mGingerSocketClient2.Connect(SocketHelper.GetLocalHostIP(), mMyGingerServer.ServerPort); }
public void StartGingerNode(string Name, string HubIP, int HubPort) { Console.WriteLine("Starting Ginger Node"); Console.WriteLine("ServiceID: " + mServiceID); string Domain = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName; string IP = SocketHelper.GetLocalHostIP(); string MachineName = System.Environment.MachineName; string OSVersion = System.Environment.OSVersion.ToString(); //TODO: first register at the hub mHubClient = new GingerSocketClient2(); mHubClient.MessageHandler = HubClientMessageHandler; Console.WriteLine("Connecting to Ginger Grid Hub: " + HubIP + ":" + HubPort); mHubClient.Connect(HubIP, HubPort); if (!mHubClient.IsConnected) { return; } Console.WriteLine("Connected!"); Console.WriteLine("Registering Ginger node"); //Register the service in GG NewPayLoad PLRegister = new NewPayLoad(SocketMessages.Register); PLRegister.AddValue(Name); PLRegister.AddValue(mServiceID); PLRegister.AddValue(OSVersion); PLRegister.AddValue(MachineName); PLRegister.AddValue(IP); PLRegister.ClosePackage(); NewPayLoad RC = mHubClient.SendRequestPayLoad(PLRegister); if (RC.Name == "SessionID") { mSessionID = RC.GetGuid(); Console.WriteLine("Ginger Node started SessionID - " + mSessionID); if (GingerNodeMessage != null) { GingerNodeMessage.Invoke(this, eGingerNodeEventType.Started); } } else { throw new Exception("Unable to find Ginger Grid at: " + HubIP + ":" + HubPort); } }
/// <summary> /// Find Node in Remote Grid and return GingerNodeProxy /// </summary> /// <param name="ServiceID"></param> /// <param name="remoteServiceGrids"></param> /// <returns></returns> public static GingerNodeProxy FindRemoteNode(string ServiceID, ObservableList <RemoteServiceGrid> remoteServiceGrids) { foreach (RemoteServiceGrid remoteServiceGrid in remoteServiceGrids) { GingerSocketClient2 hubClient = new GingerSocketClient2(); hubClient.Connect(remoteServiceGrid.Host, remoteServiceGrid.HostPort); NewPayLoad findNodePayload = new NewPayLoad(SocketMessages.FindNode, ServiceID, "ccc"); // !!!!!!!!!!!!!!!! ccc NewPayLoad RC = hubClient.SendRequestPayLoad(findNodePayload); if (RC.Name == "NodeInfo") { Guid sessionID = RC.GetGuid(); GingerNodeProxy gingerNodeProxy = new GingerNodeProxy(hubClient, sessionID); return(gingerNodeProxy); } } return(null); }
public void StartGingerNode(string Name, string HubIP, int HubPort) { Console.WriteLine("Starting Ginger Node"); Console.WriteLine("ServiceID: " + mServiceID); string Domain = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName; string IP = SocketHelper.GetLocalHostIP(); string MachineName = System.Environment.MachineName; string OSVersion = System.Environment.OSVersion.ToString(); //TODO: first register at the hub mHubClient = new GingerSocketClient2(); mHubClient.MessageHandler = HubClientMessageHandler; // We have retry mechanism bool IsConnected = false; int count = 0; while (!IsConnected) { try { Console.WriteLine("Connecting to Ginger Grid Hub: " + HubIP + ":" + HubPort); mHubClient.Connect(HubIP, HubPort); IsConnected = true; } catch (Exception ex) { Console.WriteLine("Connection failed: " + ex.Message); Console.WriteLine("Will retry in 5 seconds"); Thread.Sleep(5000); count++; if (count > 50) //TODO: Change it to stop watch wait for 60 seconds, or based on config { Console.WriteLine("All connection attempts failed, exiting"); return; } } } //Register the service in GG NewPayLoad PLRegister = new NewPayLoad(SocketMessages.Register); PLRegister.AddValue(Name); PLRegister.AddValue(mServiceID); PLRegister.AddValue(OSVersion); // TODO: translate to normal name? PLRegister.AddValue(MachineName); // TODO: if local host write local host PLRegister.AddValue(IP); PLRegister.ClosePackage(); NewPayLoad RC = mHubClient.SendRequestPayLoad(PLRegister); //TODO: we can disconnect from hub, make Register/Unregister a function if (RC.Name == "SessionID") { mSessionID = RC.GetGuid(); Console.WriteLine("Ginger Node started SessionID - " + mSessionID); if (GingerNodeMessage != null) { GingerNodeMessage.Invoke(this, eGingerNodeEventType.Started); } } else { throw new Exception("Unable to find Ginger Grid at: " + HubIP + ":" + HubPort); } }