/// <summary> /// Execute the command. Sends to Server /// </summary> /// <param name="command"></param> /// <param name="t"></param> public static void Execute(string command, MyTuple t) { Console.WriteLine("EXECUTAR"); Command c = new Command(command, t, MyAddress, ++SequenceNumber, null); Stopwatch sw = new Stopwatch(); switch (command) { case "read": //Console.WriteLine("=======ENTREI NO READ================================="); ClientServices.SetCurrentCommandAndView(command, GetView()); SendToView(c); Read_SignalEvent.WaitOne(); Read_SignalEvent.Reset(); //Console.WriteLine("=========SAI DO READ==============================="); break; case "add": //Console.WriteLine("========================================"); ClientServices.SetCurrentCommandAndView(command, GetView()); SendToView(c); Add_SignalEvent.WaitOne(); Add_SignalEvent.Reset(); break; case "take": //FASE 1 Console.WriteLine("========================================"); ClientServices.SetCurrentCommandAndView(command, GetView()); SendToView(c); Take_SignalEvent.WaitOne(); Take_SignalEvent.Reset(); break; /*case "remove": //FASE 2 * Console.WriteLine("========================================"); * for (int i = 0; i < AllServers.Count; i++) * { * ThreadWithState tws = new ThreadWithState(c, i); * Thread td = new Thread(new ThreadStart(tws.TX_Command_thread)); * * ThreadsInAction.Add(new SenderPool(tws, td, new Uri(AllServers[i]), c)); * td.Start(); * } * Console.WriteLine("============SAIR DO REMOVW======================STATE_WAIT_FOR_REPLY_TAKE"); * STATE_EXECUTE = STATE_WAIT_FOR_REPLY_TAKE;*/ break; } //break; /*case STATE_WAIT_FOR_REPLY_READ: * Read_SignalEvent.WaitOne(); * Read_SignalEvent.Reset(); * STATE_EXECUTE = STATE_COMMAND; * break; ; * case STATE_WAIT_FOR_REPLY_ADD: * * Add_SignalEvent.WaitOne(); * Add_SignalEvent.Reset(); * * STATE_EXECUTE = STATE_COMMAND; * return; * case STATE_WAIT_FOR_REPLY_TAKE: * Console.WriteLine("============INICIO======================STATE_WAIT_FOR_REPLY_TAKE"); * * Take_SignalEvent.WaitOne(); * Take_SignalEvent.Reset(); * * Console.WriteLine("============ENTREI======================STATE_WAIT_FOR_REPLY_TAKE: " + TerminateTakenActivity.ToString()); * STATE_EXECUTE = STATE_COMMAND; * if (TerminateTakenActivity == true && command == "take") * { * //Console.WriteLine("============ACABEI======================STATE_WAIT_FOR_REPLY_TAKE"); * TerminateTakenActivity = false; * command = "remove"; * c = new Command(command, t, MyAddress, ++SequenceNumber, null); * //Take_SignalEvent.Set(); * //return; * } * else * { * if (TerminateTakenActivity == true && command == "remove") * { * TerminateTakenActivity = false; * return; * } * } * break;*/ }