public static async Task<string> SendToOneMachineAsync(String ipAddress, String command, Object[] parameters) { await Task.Delay(100); try { //don't send to self String myIpAddress = NetworkHelper.GetMyIpAddress(); if (ipAddress != myIpAddress) { newProxy = XmlRpcProxyGen.Create<ICSharpRpcClient>(); newProxy.Url = ServerUrlStart + ipAddress + ServerUrlEnd; object response; switch (command) { case GlobalMethodName.leaderElection: newProxy.leaderElection(parameters[0].ToString()); response = "Async call called"; break; case GlobalMethodName.requestHandlerStartMessage: response = newProxy.requestStartMessage(Convert.ToBoolean(parameters[0]), Convert.ToBoolean(parameters[1])); break; case GlobalMethodName.requestHandlerReceivePermission: newProxy.requestReceivePermission((int)parameters[0], (int)parameters[1], parameters[2].ToString()); response = "Async call receive permission called"; break; case GlobalMethodName.requestCentralStartMessage: response = newProxy.requestCentralStartMessage((bool)parameters[0], (bool)parameters[1]); break; case GlobalMethodName.requestCentralReceiveRequest: newProxy.requestCentralReceiveRequest(parameters[0].ToString(), parameters[1].ToString()); response = "Async call receive request called"; break; case GlobalMethodName.requestCentralGetPermission: newProxy.requestCentralGetPermission(parameters[0].ToString(), parameters[1].ToString()); response = "success"; break; case GlobalMethodName.requestCentralFinishRequest: newProxy.requestCentralFinishRequest(parameters[0].ToString()); response = "Async call finish request called"; break; default: response = "no such command"; break; } Console.WriteLine(classNameLog + "Message: " + response); return response.ToString(); } else { return "Sending to self is not permitable"; } } catch (XmlRpcException e) { return "Connection refused"; } catch (Exception e) { Console.WriteLine("{0}", e.InnerException); return e.Message; } }
static void Main(string[] args) { ClientObject co = new ClientObject(); string myIpAddress = co.GetClientIpAdress(); HttpChannel chnl = new HttpChannel(null, new XmlRpcClientFormatterSinkProvider(), null); ChannelServices.RegisterChannel(chnl, false); _localProxy = XmlRpcHelper.Connect("localhost"); _currentMasterUrl = _localProxy.getIpMaster(myIpAddress); _masterProxy = XmlRpcHelper.Connect(_currentMasterUrl); try { // ====== Begin client input ====== string input; ClientUI clientUi = new ClientUI(); do { clientUi.DisplayMainMenu(myIpAddress); input = Console.ReadLine(); switch (input) { case "1": // Menu 1: Show master hashmap. // localProxy.checkMasterStatus(); XmlRpcStruct masterMap = _masterProxy.getMachines(myIpAddress); Dictionary<int, string> networkHashMap = Helper.ConvertObjToDict(masterMap); Console.WriteLine("The Masternode hashmap"); foreach (KeyValuePair<int, string> networkNode in networkHashMap) { Console.WriteLine("Priority {0} : {1}", networkNode.Key, networkNode.Value); } Console.ReadKey(); break; case "2": // Menu 2: Show local hashmap. // localProxy.checkMasterStatus(); XmlRpcStruct localMap = _localProxy.getMachines(myIpAddress); Dictionary<int, string> localhostHashMap = Helper.ConvertObjToDict(localMap); Console.WriteLine("The localnode hashmap"); foreach (KeyValuePair<int, string> localNode in localhostHashMap) { Console.WriteLine("Priority {0} : {1}", localNode.Key, localNode.Value); } Console.ReadKey(); break; case "3": // Menu 3: Get Master Ip. //localProxy.checkMasterStatus(); string result = _localProxy.getIpMaster(myIpAddress); Console.WriteLine("the masterNode is {0}", result); Console.ReadKey(); break; case "4": //Menu 4: do election. // masterProxy.checkMasterStatus(); Console.WriteLine("Election held!!!"); string newMaster = _localProxy.leaderElection(myIpAddress); //string newMasterIp = localProxy.getIpMaster(ipAddress); Console.WriteLine("The new masternode is {0}", newMaster); Console.ReadKey(); break; case "5": // Menu 5: Ricart Agrawala Exlusion. StartMutualExclusion(false); Console.ReadKey(); break; case "6": // Menu 6: Test Mutual Exclusion. StartMutualExclusion(true); Console.ReadKey(); break; case "0": // exit break; default: Console.WriteLine("Invalid command. Please re-enter the command."); Console.ReadKey(); break; } } while (input != "0"); Console.WriteLine("Ending the client session."); Console.ReadKey(); } catch (XmlRpcFaultException fex) { Console.WriteLine("Fault response {0} {1} {2}", fex.FaultCode, fex.FaultString, fex.Message); Console.ReadLine(); } // ===========End of Client Input================ }
public static Object SendToOneMachine(String ipAddress, String command, Object[] parameter) { try { //don't send to self String myIpAddress = NetworkHelper.GetMyIpAddress(); if (ipAddress != myIpAddress) { newProxy = XmlRpcProxyGen.Create<ICSharpRpcClient>(); newProxy.Url = ServerUrlStart + ipAddress + ServerUrlEnd; object response; switch (command) { case GlobalMethodName.getMachines: response = newProxy.getMachines(parameter[0].ToString()); break; case GlobalMethodName.serverShutDownFromClient: newProxy.serverShutDownFromClient(); response = "success"; break; case GlobalMethodName.leaderElection: response = newProxy.leaderElection(parameter[0].ToString()); break; case GlobalMethodName.getIpMaster: response = newProxy.getIpMaster(parameter[0].ToString()); break; case GlobalMethodName.removeMachineIp: response = newProxy.removeMachineIp(parameter[0].ToString()); break; case GlobalMethodName.newMachineJoin: response = newProxy.newMachineJoin(parameter[0].ToString()); break; case GlobalMethodName.newMachineJoinNotification: response = newProxy.newMachineJoinNotification(parameter[0].ToString(), parameter[1].ToString()); break; case GlobalMethodName.addNewMachine: response = newProxy.addNewMachine(parameter[0].ToString(), parameter[1].ToString()); break; case GlobalMethodName.getKeyMaster: response = newProxy.getKeyMaster(parameter[0].ToString()); break; case GlobalMethodName.checkLeaderValidity: response = newProxy.checkLeaderValidity(parameter[0].ToString()); break; case GlobalMethodName.setNewLeader: response = newProxy.setNewLeader((int)parameter[0]); break; #region Request Handler case GlobalMethodName.requestHandlerStartMessage: response = newProxy.requestStartMessage(Convert.ToBoolean(parameter[0]), Convert.ToBoolean(parameter[1])); break; case GlobalMethodName.requestHandlerReceivePermission: response = newProxy.requestReceivePermission((int)parameter[0], (int)parameter[1], parameter[2].ToString()); break; case GlobalMethodName.requestHandlerRequestPermission: response = newProxy.requestRequestPermission((int)parameter[0], (int)parameter[1], parameter[2].ToString(), parameter[3].ToString()); break; #endregion #region RequestCentral Handler case GlobalMethodName.requestCentralStartMessage: response = newProxy.requestCentralStartMessage((bool)parameter[0], (bool)parameter[1]); break; case GlobalMethodName.requestCentralGetPermission: newProxy.requestCentralGetPermission(parameter[0].ToString(), parameter[1].ToString()); response = "success"; break; #endregion #region Resource Handler case GlobalMethodName.resourceGetString: response = newProxy.resourceGetString(parameter[0].ToString()); break; case GlobalMethodName.resourceSetString: response = newProxy.resourceSetString(parameter[0].ToString(), parameter[1].ToString()); break; #endregion default: response = "No such command"; break; } Console.WriteLine(classNameLog + "Message: " + response); return response; } else { return "Sending to self is not permitable"; } } catch (XmlRpcException e) { return "Connection refused"; } catch (Exception e) { Console.WriteLine("{0}", e.Message); return e.Message; } }