Exemple #1
0
 public void SetAuction(Auction auction)
 {
     foreach (ClientHandler client in _clients)
     {
         client.SetAuction(auction);
     }
 }
        public ClientHandler(Socket clientSocket, Broadcaster broadcaster)
        {
            this._clientSocket = clientSocket;
            this._broadcaster = broadcaster;

            this._disconnected = false;

            _auction = null;

            /* Udskriver IP'en */
            string clientIp = clientSocket.RemoteEndPoint.ToString();

            client = new Client(clientIp);
            _broadcaster.Clients.Add(client);

            Console.WriteLine(clientIp +"("+client.Name+") connected");
        }
Exemple #3
0
        private void HandleInput()
        {
            while (_running)
            {
                Console.WriteLine("Server klar til input");
                string input = Console.ReadLine();

                try
                {
                    switch (input?.Trim().ToUpper())
                    {
                        case "NEW":
                            if (_auction == null)
                            {
                                bool inputrunning = true;

                                while (inputrunning)
                                {
                                    Console.WriteLine("Auction's navn:");
                                    string name = Console.ReadLine();

                                    Console.WriteLine("Auction's beskrivelse:");
                                    string description = Console.ReadLine();

                                    Console.WriteLine("Auction's estimerede pris:");
                                    double estimatedprice = double.Parse(Console.ReadLine());

                                    Console.WriteLine("Auction's pris:");
                                    double currentprice = double.Parse(Console.ReadLine());

                                    Auction auction = new Auction(name, description, estimatedprice, currentprice, null);

                                    _auction = auction;

                                    ConnectClients();
                                    _broadcaster.SetAuction(auction);

                                    _auction.Timer.Elapsed += OnTimedEvent;
                                    inputrunning = false;
                                }
                            }
                            else
                            {
                                Console.WriteLine("Auktion allerede i gang");
                            }
                            break;
                        case "STOP":
                            StopAuction();
                            break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("HandleInput() " + e.Message);
                }
            }
        }
Exemple #4
0
        private void StopAuction()
        {
            _auction.Timer.Stop();
            _auction = null;
            _broadcaster.SetAuction(null);

            _broadcaster.Broadcast("MESSAGE");
            _broadcaster.Broadcast("Auktion stoppet af serveren");
        }
 public void SetAuction(Auction auction)
 {
     _auction = auction;
 }