Example #1
0
        private ISchedulingServer findOriginServer(string meetingTopic)
        {
            ISchedulingServer result  = null;
            List <string>     auxArgs = new List <string>();

            auxArgs.Add(meetingTopic);
            Message        urlMess; // = server.Response("GetMeetingProposalURL", auxArgs); //TODO
            Task <Message> task = null;

            try
            {
                task = Task <Message> .Factory.StartNew(() => server.Response("GetMeetingProposalURL", auxArgs));
            }
            catch (Exception e)
            {
                if (connectToBackup(0, new List <string>()))
                {
                    task = Task <Message> .Factory.StartNew(() => server.Response("GetMeetingProposalURL", auxArgs));
                }
                return(null);
            }
            task.Wait();
            urlMess = task.Result;

            if (urlMess.getSucess())
            {
                result = (ISchedulingServer)Activator.GetObject(typeof(ISchedulingServer), (string)urlMess.getObj());
            }
            else
            {
                Console.WriteLine(urlMess.getMessage());
            }

            return(result);
        }
Example #2
0
        private void CloseProposal(String meetingTopic)
        {
            //look for the server that created that meeting proposal
            ISchedulingServer otherServer = null;

            try
            {
                otherServer = findOriginServer(meetingTopic);
            }
            catch (Exception e)
            {
                if (connectToBackup(0, new List <string>()))
                {
                    otherServer = findOriginServer(meetingTopic);
                }
                return;
            }

            if (otherServer != null)
            {
                List <String> args = new List <String>();
                args.Add(meetingTopic);
                args.Add(cs.getUser().getName());
                Message output;
                try
                {
                    Task <Message> task = Task <Message> .Factory.StartNew(() => otherServer.Response("CloseMeetingProposal", args));

                    bool taskCompleted = task.Wait(timeout);

                    if (taskCompleted)
                    {
                        output = task.Result;
                        Console.WriteLine((String)output.getMessage());
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Bolas 1");
                    Console.WriteLine(e);
                    Console.WriteLine("###################################################################");
                    if (connectToBackup(0, new List <string>()))
                    {
                        CloseProposal(meetingTopic);
                    }
                    return;
                }
            }
        }
Example #3
0
        //TODO we have to make all calls to the server fail proof, both from freezes and crashes
        public Boolean connectToBackup(int index, List <String> args)
        {
            Boolean _return = true;

            Console.WriteLine("Connection to Server lost. Trying to reconnect...");
            try
            {
                args.Add(sURL);
                this.sURL = sURLBackup[index];
                server    = (ISchedulingServer)Activator.GetObject(typeof(ISchedulingServer), sURLBackup[index]);
                //server.Response("RemoveServerFromView", args).getMessage();

                Task <Message> task = Task <Message> .Factory.StartNew(() => server.Response("RemoveServerFromView", args));

                task.Wait();

                List <String> arg = new List <String>();
                arg.Add(cURL);
                Message mess;                                                                    // = server.Response("Register", arg);

                task = Task <Message> .Factory.StartNew(() => server.Response("Register", arg)); // should we send an error here ?

                task.Wait();
                mess = task.Result;

                sURLBackup = Array.ConvertAll((object[])mess.getObj(), Convert.ToString);
                Console.WriteLine("Cliente " + new Uri(cURL).Port + " (" + username + ") " + mess.getMessage());

                //coordinate local clients to reconnect to different backup servers
                int pointer = index + 1 % sURLBackup.Length;
                foreach (string url in localClients)
                {
                    if (url != cURL)
                    {
                        ClientServ c = (ClientServ)Activator.GetObject(typeof(ClientServ), url);
                        c.connectToBackup(pointer % sURLBackup.Length, new List <String>());
                        pointer++;
                    }
                }

                _return = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                try
                {
                    if (index + 1 < sURLBackup.Length)
                    {
                        connectToBackup(index + 1, args);
                    }
                    else
                    {
                        Console.WriteLine("Error: No Backup-server reachable!");
                        _return = false;
                    }
                }
                catch (Exception e2)
                {
                    _return = false;
                }
            }
            return(_return);
        }
Example #4
0
        private void Participate(String meetingTopic, String[] slots)
        {
            if (slots == null)
            {
                Console.WriteLine("No slots input");
                return;
            }

            //look for the server that created that meeting proposal
            ISchedulingServer otherServer = null;

            try
            {
                otherServer = findOriginServer(meetingTopic);
            }
            catch (Exception e)
            {
                if (connectToBackup(0, new List <string>()))
                {
                    otherServer = findOriginServer(meetingTopic);
                }
                return;
            }
            if (otherServer != null)
            {
                List <String> args = new List <String>();
                args.Add(meetingTopic);
                args.Add(cs.getUser().getName());
                args.Add(string.Join(" ", slots));

                Message output;

                try
                {
                    Task <Message> task = Task <Message> .Factory.StartNew(() => otherServer.Response("AddUserToProposal", args));

                    bool taskCompleted = task.Wait(timeout);

                    if (taskCompleted)
                    {
                        output = task.Result;
                        //Message output = server.Response("AddUserToProposal", args);
                        if (output.getSucess())
                        {
                            Console.WriteLine("Meeting " + meetingTopic + " joined successfully.");
                        }
                        else
                        {
                            switch (output.getObj())
                            {
                            case 0:
                                Console.WriteLine("Joing meeting " + meetingTopic + " failed. Topic not found.");
                                break;

                            case 1:
                                Console.WriteLine("Joing meeting " + meetingTopic + " failed. Meeting is restricted.");
                                break;
                            }
                        }
                        return;
                    }
                }
                catch (Exception e)
                {
                    if (connectToBackup(0, new List <string>()))
                    {
                        Participate(meetingTopic, slots);
                    }
                    return;
                }
                Console.WriteLine("Request: Timeout, abort request.");
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            TcpChannel channel;
            Cliente    cli;
            String     script = "";

            if (args.Length == 2)
            {
                script = args[1];
            }

            string[] vs = args[0].Split(
                new[] { "'" },
                StringSplitOptions.None);

            String username = vs[0];
            String cURL     = vs[1];
            String sURL     = vs[2];

            String[]      sURLBackup;
            List <String> localClients = new List <String>();

            cli = new Cliente(username, cURL, sURL, script);
            Uri myUri = new Uri(cURL);

            channel = new TcpChannel(myUri.Port);
            ChannelServices.RegisterChannel(channel, false);

            cs = new ClientServ(cli);

            //RemotingServices.Marshal(cs, "cc", typeof(ClientServ));

            RemotingServices.Marshal(cs, myUri.Segments[1], typeof(ClientServ));


            server = (ISchedulingServer)Activator.GetObject(typeof(ISchedulingServer), sURL);

            List <String> arg = new List <String>();

            arg.Add(cURL);
            Message mess = null; // = server.Response("Register", arg); //it should wait but it should be a task!

            try
            {
                Task <Message> task = Task <Message> .Factory.StartNew(() => server.Response("Register", arg));

                task.Wait();
                mess = task.Result;
            }
            catch (Exception e)
            {
                //Should we give here another server for the Client to connect?
                Console.WriteLine("The server you tried to connect unfortunately is not available");
                Console.WriteLine("Please close window and try to connect to another server adress");
                Console.ReadLine();
            }

            sURLBackup = Array.ConvertAll((object[])mess.getObj(), Convert.ToString);
            cs.setBackupServerURL(sURLBackup);
            cs.setLocalClients(localClients);
            Console.WriteLine("Cliente " + new Uri(cURL).Port + " (" + username + ") " + mess.getMessage());
            //check if the client has to be updated
            cs.updateClientState();

            if (args.Length == 1 || args.Length == 2)
            {
                Boolean run = true;
                Console.WriteLine("Hello, " + username + ". Welcome to MSDAD");
                Console.WriteLine("Type list to list the user's meeting proposals");
                Console.WriteLine("Type create <topic> <# of min participants> <# of slots> <# of invitees> [slots] [invitees] to create a new meeting proposal");
                Console.WriteLine("Type join <meetingTopic> <# of slots> [slots] to join the specific meeting");
                Console.WriteLine("Type close <meetingTopic> to close the specific meeting proposal");
                Console.WriteLine("Type wait <time in milliseconds> to let the Cliente wait");
                Console.WriteLine("Type quit to exit");

                //if script client
                if (args.Length == 2)
                {
                    string   allScript   = System.IO.File.ReadAllText(script);
                    string[] commandList = allScript.Split(
                        new[] { Environment.NewLine },
                        StringSplitOptions.None);
                    Console.WriteLine("If you wish the script to be run stpe-by-step write YES");
                    String s = Console.ReadLine();
                    if (s.ToLower().Equals("yes"))
                    {
                        foreach (string command in commandList)
                        {
                            Console.WriteLine("Press Enter to execute the line:");
                            Console.WriteLine(command);
                            Console.ReadLine();
                            cli.ProcessConsoleLine(command);
                        }
                    }
                    else
                    {
                        foreach (string command in commandList)
                        {
                            cli.ProcessConsoleLine(command);
                        }
                    }
                }
                else
                {
                    while (run)
                    {
                        Console.Write("Insert command: ");
                        string command = Console.ReadLine();
                        if (command.Split(
                                new[] { " " }, StringSplitOptions.None)[0].Equals("quit"))
                        {
                            System.Environment.Exit(1);
                        }
                        else
                        {
                            cli.ProcessConsoleLine(command);
                        }
                    }
                }
            }
            else
            {
                System.Console.WriteLine("ERROR: Wrong number of arguments!");
            }
        }