private void BikeAutoLocked() { string stand_id = Data[0]; List <LockProcedure> instances = localSafe.Load(); Verification ver = new Verification(); string verification_key = ver.GetNewKey(); if (Database.AutoLockBikeStand(stand_id, verification_key)) { string send = $"ACK_BIKE_LOCKED:{stand_id};"; SendMessageToSerialPort(send); } else { string send = $"NACK_BIKE_LOCKED:{stand_id};"; SendMessageToSerialPort(send); } instances.Add(new LockProcedure(stand_id, verification_key)); localSafe.Save(instances); }
private static void CommandCentre() { string[] commands = { "scrash", "config", "config socket", "config serial", "socket start", "serial start", "help", "check db", "sessions list", string.Empty }; while (!shuttingDown) { string command = Console.ReadLine(); bool commandExists = CheckIfCommandExists(commands, command); if (commandExists) { if (command == "scrash") { SecureString masked = MaskInputString(); string Password = new NetworkCredential(string.Empty, masked).Password; ConsoleKeyInfo keyInfo = Console.ReadKey(true); if (Password == serverPassword) { shuttingDown = true; } else { Console.WriteLine($"\n{serverPrefix}Wrong"); CommandCentre(); } } else if (command == "config") { Console.WriteLine("config [socket/serial] <?>"); } else if (command == "config socket") { string hostName = Dns.GetHostName(); IPAddress[] ipList = Dns.GetHostEntry(hostName).AddressList; Console.WriteLine($"{serverPrefix}Possible ip-addresses for {hostName}:"); IPAddress[] cleanIpList = new IPAddress[10]; int j = 0; foreach (IPAddress ip in ipList) { if (!ip.ToString().Contains("%")) { Console.WriteLine(ip.ToString()); cleanIpList[j] = ip; j++; } } chosenIpAdress = ChooseIpSetting(cleanIpList); Console.WriteLine($"{serverPrefix}Chosen IP-Address: {chosenIpAdress.ToString()}."); } else if (command == "config serial") { string[] availablePortnames = SerialPort.GetPortNames(); Console.WriteLine($"{serverPrefix}Available ports:"); if (availablePortnames.Length != 0) { foreach (string portName in availablePortnames) { Console.WriteLine(portName); } chosenPortName = ChoosePortName(availablePortnames); Console.WriteLine($"{serverPrefix}Chosen port-name: {chosenPortName}"); } else { Console.WriteLine($"{serverPrefix}No available Ports"); } } else if (command == "socket start") { if (chosenIpAdress != null) { Console.WriteLine($"{serverPrefix}Starting SocketProcess with: {chosenIpAdress.ToString()}:{port}."); StartSocketProcess(); } else { Console.WriteLine($"{serverPrefix}No chosen IP-Address. Try choosing one by using command: config socket."); } } else if (command == "serial start") { if (chosenPortName != "") { Console.WriteLine($"{serverPrefix}Starting SerialProcess with: {chosenPortName}"); StartSerialProcess(); } else { Console.WriteLine($"{serverPrefix}No chosen Portname. Try choosing one by using command: config serial."); } } else if (command == "help") { Console.WriteLine($"{serverPrefix}Existing commands:"); foreach (string existingCommand in commands) { Console.WriteLine(existingCommand); } } else if (command == "check db") { if (chosenIpAdress != null && socketProcessStarted == true) { Console.WriteLine($"Connected:{socketProcess.CheckDbReachable()}"); } else { Console.WriteLine($"{serverPrefix}Server has not been configured for Socket connection."); } } else if (command == "sessions list") { LocalSafe localSafe = new LocalSafe(); List <LockProcedure> sessionlist = localSafe.Load(); if (sessionlist.Count != 0) { foreach (LockProcedure lp in sessionlist) { Console.WriteLine(lp); } } } } else { Console.WriteLine($"{serverPrefix}'{command}' is not a command."); } } Environment.Exit(0); }