Esempio n. 1
0
        // Public Methods
        public int execute(CreateCommand command)
        {
            // delay
            this.delay();

            if (this.isFrozen)
            {
                this.frozenCommands.Add(command);
                return(0);
            }
            else
            {
                Console.WriteLine("Recieved " + command.getType() + " command from " + command.getIssuerId());
                this.createMeeting(command.getIssuerId(), command.getMeetingProposal());
                return(1);
            }
        }
Esempio n. 2
0
        public void unfreeze()
        {
            Console.WriteLine("Unfreeze");
            this.isFrozen = false;

            for (int i = 0; i < this.frozenCommands.Count; i++)
            {
                Command command = this.frozenCommands[i];

                if (command.getType() == "CREATE")
                {
                    CreateCommand c = (CreateCommand)command;
                    this.execute(c);
                }
                else if (command.getType() == "LIST")
                {
                    ListCommand c = (ListCommand)command;
                    this.execute(c);
                }
                else if (command.getType() == "CLOSE")
                {
                    CloseCommand c = (CloseCommand)command;
                    this.execute(c);
                }
                else if (command.getType() == "JOIN")
                {
                    JoinCommand c = (JoinCommand)command;
                    this.execute(c);
                }
                else if (command.getType() == "WAIT")
                {
                    WaitCommand c = (WaitCommand)command;
                    this.execute(c);
                }
            }
            this.frozenCommands = new List <Command>();
        }
Esempio n. 3
0
        public CreateCommand parseCreateCommand(string[] instruction, string issuerId)
        {
            string topic         = instruction[1];
            int    min_attendees = Int32.Parse(instruction[2]);
            int    nr_slots      = Int32.Parse(instruction[3]);
            int    nr_invitees   = Int32.Parse(instruction[4]);

            List <Slot> slots = new List <Slot>();

            for (int i = 0; i < nr_slots; i++)
            {
                string   slot_info  = instruction[i + 5];
                char[]   delimiter  = { ',' };
                string[] slot_infos = slot_info.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
                string   location   = slot_infos[0];
                DateTime date       = DateTime.Parse(slot_infos[1]);
                slots.Add(new Slot(location, date));
            }

            List <string> invitees = new List <string>();

            if (nr_invitees == 0)
            {
                invitees = null;
            }

            else
            {
                invitees = new List <string>();
            }

            CreateCommand command = new CreateCommand(topic, min_attendees, nr_slots, nr_invitees, slots, invitees);

            command.getMeetingProposal().setCoordinator(issuerId);
            return(command);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            string myId       = args[0];
            string url        = args[1];
            string server_url = args[2];

            Regex r = new Regex(@"^(?<protocol>\w+)://[^/]+?:(?<port>\d+)?/",
                                RegexOptions.None, TimeSpan.FromMilliseconds(100));
            Match m    = r.Match(url);
            int   port = Int32.Parse(m.Result("${port}"));

            myId += "-" + url;

            TcpChannel   channel = new TcpChannel(port);
            ClientObject client  = new ClientObject();

            RemotingServices.Marshal(client, "ClientObject", typeof(ClientObject));

            ChannelServices.RegisterChannel(channel, false);
            ServerInterface server = (ServerInterface)Activator.GetObject(typeof(ServerInterface), server_url);

            if (server == null)
            {
                System.Console.WriteLine("Could not locate server");
            }
            else
            {
                System.Console.WriteLine("Found");

                InstructsParser parser = new InstructsParser();

                string clientScript = @"C:\Users\cash\MEIC\Development of Distributed Systems\DAD2019\MeetingsScheduleV1\" + args[3];

                string[] lines = File.ReadAllLines(clientScript);

                foreach (string line in lines)
                {
                    char[]   delimiter        = { ' ' };
                    string[] instructionParts = line.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);

                    if (instructionParts[0] == "create")
                    {
                        CreateCommand command = parser.parseCreateCommand(instructionParts, myId);
                        command.setIssuerId(myId);
                        Console.WriteLine(command.getType());

                        CreateRemoteAsyncDelegate RemoteDel = new CreateRemoteAsyncDelegate(server.execute);
                        IAsyncResult RemAr = RemoteDel.BeginInvoke(command, null, null);
                        RemAr.AsyncWaitHandle.WaitOne();
                        Console.WriteLine(RemoteDel.EndInvoke(RemAr));

                        // server.execute(command);
                    }
                    else if (instructionParts[0] == "list")
                    {
                        ListCommand command = parser.parseListCommand(instructionParts);
                        command.setIssuerId(myId);
                        Console.WriteLine(command.getType());

                        ListRemoteAsyncDelegate RemoteDel = new ListRemoteAsyncDelegate(server.execute);
                        IAsyncResult            RemAr     = RemoteDel.BeginInvoke(command, null, null);
                        RemAr.AsyncWaitHandle.WaitOne();
                        List <MeetingProposal> proposals = RemoteDel.EndInvoke(RemAr);

                        // List<MeetingProposal> proposals = server.execute(command);

                        foreach (MeetingProposal meeting in proposals)
                        {
                            string closed = "Open";
                            if (meeting.isClosed())
                            {
                                closed = "Closed";
                            }
                            if (meeting.isCancelled())
                            {
                                closed = "Cancelled";
                            }
                            Console.WriteLine(meeting.getCoordinator() + " " + meeting.getTopic() + " - " + closed);
                        }
                    }
                    else if (instructionParts[0] == "join")
                    {
                        JoinCommand command = parser.parseJoinCommand(instructionParts);
                        command.setIssuerId(myId);
                        Console.WriteLine(command.getType());

                        JoinRemoteAsyncDelegate RemoteDel = new JoinRemoteAsyncDelegate(server.execute);
                        IAsyncResult            RemAr     = RemoteDel.BeginInvoke(command, null, null);
                        RemAr.AsyncWaitHandle.WaitOne();
                        Console.WriteLine(RemoteDel.EndInvoke(RemAr));
                        // server.execute(command);
                    }
                    else if (instructionParts[0] == "close")
                    {
                        CloseCommand command = parser.parseCloseCommand(instructionParts);
                        command.setIssuerId(myId);
                        Console.WriteLine(command.getType());

                        CloseRemoteAsyncDelegate RemoteDel = new CloseRemoteAsyncDelegate(server.execute);
                        IAsyncResult             RemAr     = RemoteDel.BeginInvoke(command, null, null);
                        RemAr.AsyncWaitHandle.WaitOne();
                        Console.WriteLine(RemoteDel.EndInvoke(RemAr));

                        //server.execute(command);
                    }
                    else if (instructionParts[0] == "wait")
                    {
                        WaitCommand command = parser.parseWaitCommand(instructionParts);
                        command.setIssuerId(myId);
                        Console.WriteLine(command.getType());

                        WaitRemoteAsyncDelegate RemoteDel = new WaitRemoteAsyncDelegate(server.execute);
                        IAsyncResult            RemAr     = RemoteDel.BeginInvoke(command, null, null);
                        RemAr.AsyncWaitHandle.WaitOne();
                        Console.WriteLine(RemoteDel.EndInvoke(RemAr));

                        //server.execute(command);
                    }
                    else
                    {
                        NotFoundCommand command = new NotFoundCommand();
                        Console.WriteLine(command.getType());
                    }
                }
            }
            System.Console.ReadLine();
        }