Exemplo n.º 1
0
        public static int Main(String[] args)
        {
            //Action Log löschen
            ActionLogger.cleanActionLog();

            // Server definieren
            HttpServer httpServer;

            //in den Args kann der Port fürs listening mitgegeben werden
            if (args.GetLength(0) > 0)
            {
                httpServer = new MyHttpServer(Convert.ToInt16(args[0]));
            }
            //Standard Port: gemäss DEFAULT_PORT
            else
            {
                httpServer = new MyHttpServer(DEFAULT_PORT);
            }

            // Thread starten und listen!
            Thread thread = new Thread(new ThreadStart(httpServer.listen));

            thread.Start();
            return(0);
        }
Exemplo n.º 2
0
        public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData)
        {
            Console.WriteLine("DEBUG: {0} : {1}", p.http_method, p.http_url);
            //string jsonData = inputData.ReadToEnd();
            string data = inputData.ReadToEnd();

            string[] param = data.Split(';');

            // Recording Route
            if (p.http_url_split[1].Equals("Route"))
            {
                // TrackLine
                if (p.http_url_split[2].Equals("TrackLine"))
                {
                    TrackLine trackLine = new TrackLine(float.Parse(param[1]));
                    Console.WriteLine("DEBUG: TrackLine: ValueL - " + trackLine.ValueL.ToString());
                    p.writeSuccess();
                    ActionLogger.writeActionLog(trackLine.ToString());

                    MyHttpServer.Fahrbefehle.addAction(trackLine);
                    Console.WriteLine("Fahrbefehl hinzugefügt");
                }

                // TrackTurnLeft
                else if (p.http_url_split[2].Equals("TrackTurnLeft"))
                {
                    TrackTurnLeft trackTurnLeft = new TrackTurnLeft(float.Parse(param[1]));
                    Console.WriteLine("DEBUG: TrackTurnLeft: ValueA - " + trackTurnLeft.ValueA.ToString());
                    p.writeSuccess();
                    ActionLogger.writeActionLog(trackTurnLeft.ToString());
                }

                // TrackTurnRight
                else if (p.http_url_split[2].Equals("TrackTurnRight"))
                {
                    TrackTurnRight trackTurnRight = new TrackTurnRight(float.Parse(param[1]));
                    Console.WriteLine("DEBUG: TrackTurnRight: ValueA - " + trackTurnRight.ValueA.ToString());
                    p.writeSuccess();
                    ActionLogger.writeActionLog(trackTurnRight.ToString());
                }

                // TrackArcLeft
                else if (p.http_url_split[2].Equals("TrackArcLeft"))
                {
                    TrackArcLeft trackArcLeft = new TrackArcLeft(float.Parse(param[1]), float.Parse(param[3]));
                    Console.WriteLine("DEBUG: TrackArcLeft: ValueA - " + trackArcLeft.ValueA.ToString());
                    Console.WriteLine("DEBUG: TrackArcLeft: ValueL - " + trackArcLeft.ValueL.ToString());
                    p.writeSuccess();
                    ActionLogger.writeActionLog(trackArcLeft.ToString());
                }

                // TrackArcRight
                else if (p.http_url_split[2].Equals("TrackArcRight"))
                {
                    TrackArcRight trackArcRight = new TrackArcRight(float.Parse(param[1]), float.Parse(param[3]));
                    Console.WriteLine("DEBUG: TrackArcRight: ValueA - " + trackArcRight.ValueA.ToString());
                    Console.WriteLine("DEBUG: TrackArcRight: ValueL - " + trackArcRight.ValueL.ToString());
                    p.writeSuccess();
                    ActionLogger.writeActionLog(trackArcRight.ToString());
                }

                // Error
                else
                {
                    p.writeFailure();
                }
            }
            // Start
            else if (p.http_url_split[1].Equals("Start"))
            {
                Console.WriteLine("DEBUG: Tuck Tuck");
                p.writeSuccess();

                //Alle Befehle abarbeiten
                bool BefehleErfolgreich = Fahrbefehle.executeActions();
                if (BefehleErfolgreich)
                {
                    Console.WriteLine("Alle Befehle abgearbeitet");
                }
                else
                {
                    Console.WriteLine("Fehler bei der Verarbeitung");
                }
            }
            else
            {
                p.writeFailure();
            }
        }