public void OurLookupAsyncCallBack(IAsyncResult ar) { Monitor.Enter(this); try { try { RemoteLookupDelegate del = (RemoteLookupDelegate)((AsyncResult)ar).AsyncDelegate; data = del.EndInvoke(ar); Console.WriteLine("\nSIGNALLED STATUS"); waiter.Set(); Thread.Sleep(WAIT_TIME); } catch (Exception e) { Console.WriteLine("Exception" + e.Message); data = null; Console.WriteLine("\nFAILURE SIGNALLED STATUS"); waiter.Set(); Thread.Sleep(WAIT_TIME); } return; } finally { Monitor.Exit(this); } }
public bool registerClient(string username, string ip_addr, int port) { //creating a ClientMetadata object to store client information ClientMetadata cm = new ClientMetadata(); cm.Username = username; cm.IP_Addr = ip_addr; cm.Port = port; //adding the client metadata to the global hashtable so that it can be used later on clients_list.Add(username, cm); IClientFacade facadeService = connectToClientFacadeService(cm); clientFacadeList.Add(username, facadeService); //update the Clients tree in PuppetGUI Gui.updateClientsTree(cm, null); return true; }
private IClientFacade connectToClientFacadeService(ClientMetadata cm) { //connect to PuppetMaster here String connectionString = "tcp://" + cm.IP_Addr + ":" + cm.Port + "/" + cm.Username + "/" + Common.Constants.CLIENT_FACADE_SERVICE; IDictionary RemoteChannelProperties = new Dictionary<string, string>(); RemoteChannelProperties["name"] = cm.Username; TcpChannel client_channel = new TcpChannel(RemoteChannelProperties, null, null); ChannelServices.RegisterChannel(client_channel, true); //TODO: uncomment and fix this to make it work IClientFacade facadeService = (IClientFacade)Activator.GetObject( typeof(IClientFacade), connectionString); return facadeService; }
private bool RegisterInfoOnAllServer(ClientMetadata client) { IConsistencyService[] server = new IConsistencyService[_servers.Count]; for (int i = 0; i < _servers.Count; i++) { server[i] = getOtherServers(_servers[i]); } callback returnedValueOnRegister1 = new callback(); callback.RemoteAsyncDelegate RemoteDelforRegister1 = new callback.RemoteAsyncDelegate(() => server[0].WriteClientMetadata(client)); AsyncCallback RemoteCallbackOnRegister1 = new AsyncCallback(returnedValueOnRegister1.OurRemoteAsyncCallBack); IAsyncResult RemArForRegister1 = RemoteDelforRegister1.BeginInvoke(RemoteCallbackOnRegister1, null); callback.RemoteAsyncDelegate RemoteDelforRegister2 = new callback.RemoteAsyncDelegate(() => server[1].WriteClientMetadata(client)); IAsyncResult RemArForRegister2 = RemoteDelforRegister2.BeginInvoke(RemoteCallbackOnRegister1, null); action.WriteClientMetadata(client); //First Self Register Log.Show(_username, "[REGISTER CLIENT] Registered on self!!"); Log.Show(_username, "[REGISTER CLIENT] Waiting for atleast one Server to return"); returnedValueOnRegister1.waiter.WaitOne(); //returnedValueOnRegister1.waiter.Reset(); if (returnedValueOnRegister1._status == false) { Log.Show(_username, "[REGISTER CLIENT] One of the Servers failed to register"); returnedValueOnRegister1.waiter.WaitOne(); // returnedValueOnRegister1.waiter.Reset(); if (returnedValueOnRegister1._status == false) { Log.Show(_username, "[REGISTER CLIENT] Both the Servers failed to register"); return false; } else { Log.Show(_username, "[REGISTER CLIENT] One Server successfully registered"); return true; } } else { Log.Show(_username, "[REGISTER CLIENT] One Server successfully registered"); return true; } }
private bool CompareValues(ClientMetadata myValue, ClientMetadata receivedValue) { if ((myValue == null) || (receivedValue == null)) return false; if ((myValue.Username.Equals(receivedValue.Username)) && (myValue.IP_Addr.Equals(receivedValue.IP_Addr)) && (myValue.Port.Equals(receivedValue.Port))) return true; else return false; }
void ILookupService.RegisterUser(string username, string ip, int port) { Monitor.Enter(this); try { ClientMetadata client = new ClientMetadata(); client.IP_Addr = ip; client.Port = port; client.Username = username; RegisterInfoOnAllServer(client); Log.Show(_username, "Registered client " + username + ": " + ip + ":" + port); pms.show("[REGISTER USER]" + _username + "-Registered client " + username + ": " + ip + ":" + port); } finally { Monitor.Exit(this); } }