Пример #1
0
        public int execute(NotFoundCommand command)
        {
            // delay
            this.delay();

            Console.WriteLine("Recieved " + command.getType() + " command from " + command.getIssuerId());
            return(0);
        }
Пример #2
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();
        }