private NewPayLoad ShutdownNode() { Console.WriteLine("Payload - Shutdown, start closing"); GingerNodeMessage.Invoke(this, eGingerNodeEventType.Shutdown); NewPayLoad PLRC = new NewPayLoad("OK"); PLRC.ClosePackage(); return(PLRC); }
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); } }
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); } }