internal static bool addHost(HostUrl hostUrl) //call locally { //called by HpnXmlRpcClient.sendJoinRequest() //this function will call by current client (locally) //when the client receive the hostList it must add each host on this machine of course after register itself on that host by calling addMe function throw XML-RPC //and then this function will return 'true' if the addition was successful or 'false' if the addition was failed try{ //check for iterated(repited) host String hurl = hostUrl.getHostUrl(); int port = hostUrl.getPort(); for (int index = 0; index < hostsAddresses.Count; index++) { if (hostsAddresses[index].getHostUrl().Equals(hurl) && hostsAddresses[index].getPort() == port) { return(true); //it is already exist does not need to add to hostsAddresses } } hostsAddresses.Add(hostUrl); return(true); //note: if the add procedure be successful, then a true value will be send }catch (System.Exception e) { Console.WriteLine("Adding a new host has crached, maybe entered URL or port has a problem."); Console.WriteLine(e.Message); } return(false); //if the adding process fail in any cases, this false value will show this failure }
internal static String listAllHostsExcept(HostUrl hostUrl) { //note: if the add procedure be successful, then the list of all hosts except local host and the host that has been added recently will be send, //the host that has been added recently must be sent with hostUrl parameter //if there were no host more than local host it will return an empty String same as "" but not null //if just there is local host it will return null String hostsList = ""; for (int index = 1; index < hostsAddresses.Count; index++) { if (!(hostsAddresses[index].getHostUrl() == hostUrl.getHostUrl() && hostsAddresses[index].getPort() == hostUrl.getPort())) { hostsList += hostsAddresses[index].toString(); } else { hostsList = ("true\n" + hostsList); } } return(hostsList); }
internal static bool removeHost(HostUrl hostUrl) { //this function will call by current client (locally) try{ //check for iterated(repited) host String hurl = hostUrl.getHostUrl(); int port = hostUrl.getPort(); for (int index = 0; index < hostsAddresses.Count; index++) { if (hostsAddresses[index].getHostUrl().Equals(hurl) && hostsAddresses[index].getPort() == port) { hostsAddresses.RemoveRange(index, 1); return(true); } } } catch (System.Exception e) { Console.WriteLine("Rupturing an old host has crached, maybe entered URL or port has a problem."); Console.WriteLine(e.Message); } return(false); //if the adding process fail in any cases, this false value will show this failure }