public Airplane(int airplaneID, string type, double cruisingKPH, double fuelConsPerHour, int currentAirportID)
 {
     this.airplaneID = airplaneID;
     this.type = type;
     this.state = PlaneState.Landed;
     this.cruisingKPH = cruisingKPH;
     this.fuelConsPerHour = fuelConsPerHour;
     this.currentAirRouteID = -1;
     this.distanceAlongRoute = 0;
     this.currentAirportID = currentAirportID;
     this.timeLanded = 0;
     this.fuel = 0;
     this.currentAirport = null;
     this.currentAirRoute = null;
     this.simTime = 0;
 }
        /// <summary>
        /// Connects to the Master server and initialises the slave, getting back the allocated airport
        /// </summary>
        private void Initialise()
        {
            try
            {
                //connect to the server
                DuplexChannelFactory<IATCMasterController> IATCMasterFactory;
                NetTcpBinding tcpBinding = new NetTcpBinding();
                tcpBinding.MaxReceivedMessageSize = System.Int32.MaxValue;
                tcpBinding.ReaderQuotas.MaxArrayLength = System.Int32.MaxValue;
                string sURL = "net.tcp://" + address;
                IATCMasterFactory = new DuplexChannelFactory<IATCMasterController>(this, tcpBinding, sURL);
                m_ATCMaster = IATCMasterFactory.CreateChannel();
                //add callback to Master and get allocated airport
                m_Airport = m_ATCMaster.InitialiseSlave();

                //set simulation time to 0
                m_SimTime = 0;

                //display the allocated airport (for debug purposes)
                System.Console.WriteLine(m_Airport.name);
            }
            catch (EndpointNotFoundException exception)
            {
                //if you get one of these four exceptions, print the error and try again, asking for a new address
                System.Console.WriteLine("Server connection failed\n\n" + exception.Message + "\n\nInput Server Address (leave blank for localhost:50002/ATCMaster)");
                address = System.Console.ReadLine();
                if (address == "")
                {
                    address = "localhost:50002/ATCMaster";
                }
                Initialise();
            }
            catch (CommunicationObjectFaultedException exception)
            {
                System.Console.WriteLine("Server connection failed\n\n" + exception.Message + "\n\nInput Server Address (leave blank for localhost:50002/ATCMaster)");
                address = System.Console.ReadLine();
                if (address == "")
                {
                    address = "localhost:50002/ATCMaster";
                }
                Initialise();
            }
            catch (CommunicationObjectAbortedException exception)
            {
                System.Console.WriteLine("Server connection failed\n\n" + exception.Message + "\n\nInput Server Address (leave blank for localhost:50002/ATCMaster)");
                address = System.Console.ReadLine();
                if (address == "")
                {
                    address = "localhost:50002/ATCMaster";
                }
                Initialise();
            }
            catch (NullReferenceException exception)
            {
                //usually this exception happens when there is four slaves connected and the master rejects the InitialiseSlave call
                System.Console.WriteLine("Server connection failed - Maybe there are already the max slaves connected?\n\n" + exception.Message + "\n\nInput Server Address (leave blank for localhost:50002/ATCMaster)");
                address = System.Console.ReadLine();
                if (address == "")
                {
                    address = "localhost:50002/ATCMaster";
                }
                Initialise();
            }
        }
Exemple #3
0
 public void OnDeserialization(StreamingContext context)
 {
     this.currentAirport = null;
     this.currentAirRoute = null;
 }