Ejemplo n.º 1
0
 public void AddExistingRouteTest()
 {
     Administration admin = new Administration();
     Route route = new Route(1);
     admin.Add(route);
     Assert.AreEqual(false, admin.Add(route));
 }
Ejemplo n.º 2
0
 public void AddExistingStationTest()
 {
     Administration admin = new Administration();
     Station station = new Station("station1");
     admin.Add(station);
     Assert.AreEqual(station, admin.Add(station));
 }
Ejemplo n.º 3
0
 public void AddExistingWagonTest()
 {
     Administration admin = new Administration();
     Wagon wagon = new Wagon(1, 20, 10);
     admin.Add(wagon);
     Assert.AreEqual(false, admin.Add(wagon));
 }
Ejemplo n.º 4
0
 public void AddExistingTrainTest()
 {
     Administration admin = new Administration();
     Train train = new Train(1, 1);
     admin.Add(train);
     Assert.AreEqual(false, admin.Add(train));
 }
Ejemplo n.º 5
0
 public void AddedTrainCanBeFoundTest()
 {
     Administration admin = new Administration();
     Train train = new Train(1, 1);
     admin.Add(train);
     Train foundTrain = admin.FindTrain(1);
     Assert.AreEqual(foundTrain, train);
 }
Ejemplo n.º 6
0
 public void AddedWagonCanBeFoundTest()
 {
     Administration admin = new Administration();
     Wagon wagon = new Wagon(1, 20, 10);
     admin.Add(wagon);
     Wagon foundWagon = admin.FindWagon(1);
     Assert.AreEqual(foundWagon, wagon);
 }
Ejemplo n.º 7
0
 public void AddedStationCanBeFoundTest()
 {
     Administration admin = new Administration();
     Station station = new Station("station1");
     admin.Add(station);
     Station foundStation = admin.FindStation("station1");
     Assert.AreEqual(foundStation, station);
 }
Ejemplo n.º 8
0
 public void AddedRouteCanBeFoundTest()
 {
     Administration admin = new Administration();
     Route route = new Route(1);
     admin.Add(route);
     Route foundRoute = admin.FindRoute(1);
     Assert.AreEqual(foundRoute, route);
 }
Ejemplo n.º 9
0
        public TrainConnection(CTrafficMessage trafficMessage)
        {
            administration = Program._Administration;

            TrafficMessage = trafficMessage;

            connectedTrains = new List <Arduino>();
            _IP2ARDUINO     = new Dictionary <IPEndPoint, Arduino>();
            _ARDUINO2IP     = new Dictionary <Arduino, IPEndPoint>();
            _ID2ARDUINO     = new Dictionary <int, Arduino>();
            _ARDUINO2ID     = new Dictionary <Arduino, int>();
            _ARDUINO2TRAIN  = new Dictionary <Arduino, Train>();

            string[] ports = System.IO.Ports.SerialPort.GetPortNames();
            int      id    = 1;

            foreach (string port in ports)
            {
                IPEndPoint endpoint     = new IPEndPoint(new IPAddress(0xA9FE0000 + ArduinoIdToIPAddress(id)), 3333);//169.254.0.0+id:3333
                Arduino    a            = new Arduino(id, port);
                Train      arduinoTrain = new Train(id, int.Parse(port.Remove(0, 3)));

                connectedTrains.Add(a);
                AddArduino(endpoint, a, arduinoTrain);

                try
                {
                    a.Connect();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                id++;
            }

            //_timer = new Timer(1000.0);
            //_timer.Elapsed += Tick;
            _timer          = new System.Windows.Forms.Timer();
            _timer.Interval = 127;
            _timer.Tick    += _timer_Tick;;
            _timer.Enabled  = true;
            _timer.Start();

            Program._TrainConnection = this;
        }
Ejemplo n.º 10
0
        public TrainConnection(CTrafficMessage trafficMessage)
        {
            administration = Program._Administration;

            TrafficMessage = trafficMessage;

            connectedTrains = new List<Arduino>();
            _IP2ARDUINO = new Dictionary<IPEndPoint, Arduino>();
            _ARDUINO2IP = new Dictionary<Arduino, IPEndPoint>();
            _ID2ARDUINO = new Dictionary<int, Arduino>();
            _ARDUINO2ID = new Dictionary<Arduino, int>();
            _ARDUINO2TRAIN = new Dictionary<Arduino, Train>();

            string[] ports = System.IO.Ports.SerialPort.GetPortNames();
            int id = 1;
            foreach(string port in ports)
            {
                IPEndPoint endpoint = new IPEndPoint(new IPAddress(0xA9FE0000+ArduinoIdToIPAddress(id)), 3333);//169.254.0.0+id:3333
                Arduino a = new Arduino(id, port);
                Train arduinoTrain = new Train(id, int.Parse(port.Remove(0, 3)));

                connectedTrains.Add(a);
                AddArduino(endpoint, a, arduinoTrain);

                try
                {
                    a.Connect();
                }
                catch(Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                id++;
            }

            //_timer = new Timer(1000.0);
            //_timer.Elapsed += Tick;
            _timer = new System.Windows.Forms.Timer();
            _timer.Interval = 127;
            _timer.Tick += _timer_Tick; ;
            _timer.Enabled = true;
            _timer.Start();

            Program._TrainConnection = this;
        }
Ejemplo n.º 11
0
        public AdministrationForm()
        {
            InitializeComponent();

            administration = Program._Administration;

            administration.OnStationUpdate += Administration_OnStationUpdate;
            administration.OnTrainUpdate   += Administration_OnTrainUpdate;

            //add any objects that have been added to administration before this constructor executed
            foreach (Train train in new List <Train>(administration.Trains))
            {
                Administration_OnTrainUpdate(this, train, true);
            }
            foreach (Station station in new List <Station>(administration.Stations))
            {
                Administration_OnStationUpdate(this, station, true);
            }
        }
Ejemplo n.º 12
0
        public AdministrationForm()
        {
            InitializeComponent();

            administration = Program._Administration;

            administration.OnStationUpdate += Administration_OnStationUpdate;
            administration.OnTrainUpdate += Administration_OnTrainUpdate;

            //add any objects that have been added to administration before this constructor executed
            foreach (Train train in new List<Train>(administration.Trains))
            {
                Administration_OnTrainUpdate(this, train, true);
            }
            foreach (Station station in new List<Station>(administration.Stations))
            {
                Administration_OnStationUpdate(this, station, true);
            }
        }
Ejemplo n.º 13
0
        public CTrafficMessage()
        {
            administration = Program._Administration;

            trafficMessages = new Dictionary <IPEndPoint, TrafficClient>();
            int amountOfEnumValues = Enum.GetValues(typeof(ObjectType)).Length;

            receipentList = new Dictionary <string, IPEndPoint> [amountOfEnumValues];
            for (int i = 0; i < amountOfEnumValues; ++i)
            {
                receipentList[i] = new Dictionary <string, IPEndPoint>();
            }

            trainConnection = new TrainConnection(this);

            Program._CTrafficMessage = this;

            Console.WriteLine("CTrafficMessage Server initialized!");
        }
Ejemplo n.º 14
0
        public CTrafficMessage()
        {
            administration = Program._Administration;

            trafficMessages = new Dictionary<IPEndPoint, TrafficClient>();
            int amountOfEnumValues = Enum.GetValues(typeof(ObjectType)).Length;

            receipentList = new Dictionary<string, IPEndPoint>[amountOfEnumValues];
            for (int i = 0; i < amountOfEnumValues; ++i)
            {
                receipentList[i] = new Dictionary<string, IPEndPoint>();
            }

            trainConnection = new TrainConnection(this);

            Program._CTrafficMessage = this;

            Console.WriteLine("CTrafficMessage Server initialized!");
        }
Ejemplo n.º 15
0
 public void FindStationTest()
 {
     Administration admin = new Administration();
     Station station1 = new Station("station1");
     Station station2 = new Station("station2");
     Station station3 = new Station("station3");
     admin.Add(station1);
     admin.Add(station2);
     admin.Add(station3);
     Assert.AreEqual(station3, admin.FindStation("station3"));
     Assert.AreEqual(station2, admin.FindStation("station2"));
     Assert.AreEqual(station1, admin.FindStation("station1"));
 }
Ejemplo n.º 16
0
 public void FindTrainTest()
 {
     Administration admin = new Administration();
     Train train1 = new Train(1, 1);
     Train train2 = new Train(2, 2);
     Train train3 = new Train(3, 3);
     admin.Add(train1);
     admin.Add(train2);
     admin.Add(train3);
     Assert.AreEqual(train1, admin.FindTrain(1));
     Assert.AreEqual(train2, admin.FindTrain(2));
     Assert.AreEqual(train3, admin.FindTrain(3));
 }
Ejemplo n.º 17
0
 public void FindWagonTest()
 {
     Administration admin = new Administration();
     Wagon wagon1 = new Wagon(1, 1, 1);
     Wagon wagon2 = new Wagon(2, 1, 1);
     Wagon wagon3 = new Wagon(3, 1, 1);
     admin.Add(wagon1);
     admin.Add(wagon2);
     admin.Add(wagon3);
     Assert.AreEqual(wagon3, admin.FindWagon(3));
     Assert.AreEqual(wagon2, admin.FindWagon(2));
     Assert.AreEqual(wagon1, admin.FindWagon(1));
 }
Ejemplo n.º 18
0
 public void RemoveNotExistinRouteTest()
 {
     Administration admin = new Administration();
     Route route = new Route(1);
     Assert.AreEqual(false, admin.Remove(route));
 }
Ejemplo n.º 19
0
 public void RemoveRouteNullTest()
 {
     Administration admin = new Administration();
     Route route = null;
     admin.Remove(route);
 }
Ejemplo n.º 20
0
 public void RemoveTrainNullTest()
 {
     Administration admin = new Administration();
     Train train = null;
     admin.Remove(train);
 }
Ejemplo n.º 21
0
        static void Main()
        {
            Program._Administration = new Administration();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            ip = "localhost:8000";

            if (!File.Exists("bind.txt"))
            {
                File.Create("bind.txt");
            }
            if (File.Exists("bind.txt"))
            {
                try
                {
                    string temp = File.ReadAllText("bind.txt");
                    if (!string.IsNullOrEmpty(temp) && !string.IsNullOrWhiteSpace(temp) && temp.Length > 2)
                    {
                        ip = temp;
                    }
                }
                catch (Exception)
                {
                }
            }

            ServerGUI gui = new ServerGUI();

            ControlWriter consoleWriter = new ControlWriter(gui.infoText);

            Console.SetOut(consoleWriter);

            // creeer een host proces voor de TrafficMessageService
            ServiceHost host = new ServiceHost(typeof(CTrafficMessage));

            // creeer een zgn. end-point voor de service
            Type             contract    = typeof(ITrafficMessage);
            BasicHttpBinding binding     = new BasicHttpBinding();
            string           baseAddress = "http://" + ip + "/MEX";
            Uri address = new Uri(baseAddress + "/MessageService");

            host.AddServiceEndpoint(contract, binding, address);

            // creeer een zgn. mex endpoint om de wsdl van de service te hosten
            host.Description.Behaviors.Add(new ServiceMetadataBehavior());
            EndpointAddress endPointAddress = new EndpointAddress(baseAddress + "/MEX");
            ServiceEndpoint mexEndpoint     = new ServiceMetadataEndpoint(endPointAddress);

            host.AddServiceEndpoint(mexEndpoint);

            ServiceDebugBehavior debug = host.Description.Behaviors.Find <ServiceDebugBehavior>();

            // if not found - add behavior with setting turned on
            if (debug == null)
            {
                host.Description.Behaviors.Add(
                    new ServiceDebugBehavior()
                {
                    IncludeExceptionDetailInFaults = true
                });
            }
            else
            {
                // make sure setting is turned ON
                if (!debug.IncludeExceptionDetailInFaults)
                {
                    debug.IncludeExceptionDetailInFaults = true;
                }
            }

            // start de service
            host.Open();

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            _ITTF_SERVER_CONTROL_FORM = new ITTF_SERVER_CONTROL_FORM();
            _ITTF_SERVER_CONTROL_FORM.Show();

            _rawinput = new CRawInput(gui.Handle, CaptureOnlyInForeground);

            _rawinput.AddMessageFilter();   // Adding a message filter will cause keypresses to be handled

            _rawinput.KeyPressed += OnKeyPressed;

            new AdministrationForm().Show();
            Application.Run(gui);

            _CTrafficMessage.Bye();
        }
Ejemplo n.º 22
0
 public void RemoveNotExistinStationTest()
 {
     Administration admin = new Administration();
     Station station1 = new Station("station1");
     Assert.AreEqual(false, admin.Remove(station1));
 }
Ejemplo n.º 23
0
 public void RemoveStationWithoutNameTest()
 {
     Administration admin = new Administration();
     Station station = new Station("");
     admin.Remove(station);
 }
Ejemplo n.º 24
0
 public void RemoveNotExistinTrainTest()
 {
     Administration admin = new Administration();
     Train train = new Train(1, 1);
     Assert.AreEqual(false, admin.Remove(train));
 }
Ejemplo n.º 25
0
 public void RemoveStationNullTest()
 {
     Administration admin = new Administration();
     Station station = null;
     admin.Remove(station);
 }
Ejemplo n.º 26
0
 public void RemoveRouteTest()
 {
     Administration admin = new Administration();
     Route route1 = new Route(1);
     Route route2 = new Route(2);
     Route route3 = new Route(3);
     admin.Add(route1);
     admin.Add(route2);
     admin.Add(route3);
     Assert.AreEqual(true, admin.Remove(route1));
     Assert.AreEqual(true, admin.Remove(route2));
     Assert.AreEqual(true, admin.Remove(route3));
 }
Ejemplo n.º 27
0
 public void FindStationNullTest()
 {
     Administration admin = new Administration();
     admin.FindStation(null);
 }
Ejemplo n.º 28
0
 public void RemoveTrainTest()
 {
     Administration admin = new Administration();
     Train train1 = new Train(1, 1);
     Train train2 = new Train(2, 2);
     Train train3 = new Train(3, 3);
     admin.Add(train1);
     admin.Add(train2);
     admin.Add(train3);
     Assert.AreEqual(true, admin.Remove(train1));
     Assert.AreEqual(true, admin.Remove(train2));
     Assert.AreEqual(true, admin.Remove(train3));
 }
Ejemplo n.º 29
0
 public void AddNewRouteTest()
 {
     Administration admin = new Administration();
     Route route = new Route(1);
     Assert.AreEqual(true, admin.Add(route));
 }
Ejemplo n.º 30
0
 public void RemoveWagonNullTest()
 {
     Administration admin = new Administration();
     Wagon wagon = null;
     admin.Remove(wagon);
 }
Ejemplo n.º 31
0
        static void Main()
        {
            Program._Administration = new Administration();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            ip = "localhost:8000";

            if (!File.Exists("bind.txt"))
            {
                File.Create("bind.txt");
            }
            if (File.Exists("bind.txt"))
            {
                try
                {
                    string temp = File.ReadAllText("bind.txt");
                    if (!string.IsNullOrEmpty(temp) && !string.IsNullOrWhiteSpace(temp) && temp.Length > 2)
                    {
                        ip = temp;
                    }
                }
                catch(Exception)
                {

                }
            }

            ServerGUI gui = new ServerGUI();

            ControlWriter consoleWriter = new ControlWriter(gui.infoText);
            Console.SetOut(consoleWriter);

            // creeer een host proces voor de TrafficMessageService
            ServiceHost host = new ServiceHost(typeof(CTrafficMessage));

            // creeer een zgn. end-point voor de service
            Type contract = typeof(ITrafficMessage);
            BasicHttpBinding binding = new BasicHttpBinding();
            string baseAddress = "http://" + ip + "/MEX";
            Uri address = new Uri(baseAddress + "/MessageService");
            host.AddServiceEndpoint(contract, binding, address);

            // creeer een zgn. mex endpoint om de wsdl van de service te hosten
            host.Description.Behaviors.Add(new ServiceMetadataBehavior());
            EndpointAddress endPointAddress = new EndpointAddress(baseAddress + "/MEX");
            ServiceEndpoint mexEndpoint = new ServiceMetadataEndpoint(endPointAddress);
            host.AddServiceEndpoint(mexEndpoint);

            ServiceDebugBehavior debug = host.Description.Behaviors.Find<ServiceDebugBehavior>();

            // if not found - add behavior with setting turned on
            if (debug == null)
            {
                host.Description.Behaviors.Add(
                     new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });
            }
            else
            {
                // make sure setting is turned ON
                if (!debug.IncludeExceptionDetailInFaults)
                {
                    debug.IncludeExceptionDetailInFaults = true;
                }
            }

            // start de service
            host.Open();

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            _ITTF_SERVER_CONTROL_FORM = new ITTF_SERVER_CONTROL_FORM();
            _ITTF_SERVER_CONTROL_FORM.Show();

            _rawinput = new CRawInput(gui.Handle, CaptureOnlyInForeground);

            _rawinput.AddMessageFilter();   // Adding a message filter will cause keypresses to be handled

            _rawinput.KeyPressed += OnKeyPressed;

            new AdministrationForm().Show();
            Application.Run(gui);

            _CTrafficMessage.Bye();
        }
Ejemplo n.º 32
0
 public void RemoveWagonTest()
 {
     Administration admin = new Administration();
     Wagon wagon1 = new Wagon(1, 1, 1);
     Wagon wagon2 = new Wagon(2, 1, 1);
     Wagon wagon3 = new Wagon(3, 1, 1);
     admin.Add(wagon1);
     admin.Add(wagon2);
     admin.Add(wagon3);
     Assert.AreEqual(true, admin.Remove(wagon3));
     Assert.AreEqual(true, admin.Remove(wagon2));
     Assert.AreEqual(true, admin.Remove(wagon1));
 }
Ejemplo n.º 33
0
 public void RemoveStationTest()
 {
     Administration admin = new Administration();
     Station station1 = new Station("station1");
     Station station2 = new Station("station2");
     Station station3 = new Station("station3");
     admin.Add(station1);
     admin.Add(station2);
     admin.Add(station3);
     Assert.AreEqual(true, admin.Remove(station3));
     Assert.AreEqual(true, admin.Remove(station2));
     Assert.AreEqual(true, admin.Remove(station1));
 }
Ejemplo n.º 34
0
 public void RemoveNotExistinWagonTest()
 {
     Administration admin = new Administration();
     Wagon wagon = new Wagon(1, 1, 1);
     Assert.AreEqual(false, admin.Remove(wagon));
 }