コード例 #1
0
        public void RfidDetected_LadeskabeStateLockedAndIdEqualOldId_LadeskabeIsAvailable()
        {
            // Arrange
            _usbCharger    = Substitute.For <IUsbCharger>();
            _logfile       = Substitute.For <Logfile>();
            _chargeControl = new ChargeControl(_usbCharger, _display);
            int id = 100;

            StationControl uut = new StationControl(_rfidReader, _door, _display, _logfile, _chargeControl);

            //act
            uut._state = Ladeskab.StationControl.LadeskabState.Available;

            _usbCharger.Connected.Returns(true);

            uut.RfidDetected(id); //Sætter oldId = id

            uut.RfidDetected(id);

            //Assert
            Assert.That(uut._state, Is.EqualTo(Ladeskab.StationControl.LadeskabState.Available));
        }
コード例 #2
0
        public void RfidDetected_Locked_idIsOldId_isCorrect()
        {
            // Arrange
            IUsbCharger fakeCharger = Substitute.For <IUsbCharger>();

            fakeCharger.Connected.Returns(true);

            var uut = new StationControl(new Door(), new RFIDReader(), fakeCharger, new Display());

            // Act
            uut._state = StationControl.LadeskabState.Available;
            // Call with id = 1
            uut.RfidDetected(1);

            // State is "locked" with _oldId = 1
            Assert.That(uut._state == StationControl.LadeskabState.Locked);

            // Calling with same id, unlocking and changing state to available
            uut.RfidDetected(1);

            // Assert
            Assert.That(uut._state == StationControl.LadeskabState.Available);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: JacobJH/LadeskabTeam14
    static void Main(string[] args)
    {
        // Assemble your system here from all the classes
        IDoor       door       = new DoorSimulator();
        IRFID       rfidReader = new RFIDReader();
        ILogger     fileLogger = new FileLogger();
        IUsbCharger usbCharger = new UsbChargerSimulator();
        IDisplay    display    = new ConsoleDisplay();

        IChargeControl chargeControl = new ChargeControl(display, usbCharger);

        StationControl StationController = new StationControl(chargeControl, door, display, fileLogger, rfidReader);


        Console.WriteLine("E for Exit, O for opening the door, C for closing the door, R to read an RFID-tag");
        Console.WriteLine("K for connecting phone to charger, L for disconnecting phone from charger");
        bool finish = false;

        do
        {
            System.Console.WriteLine("Indtast E, O, C, R, K, L: ");
            string input;

            input = Console.ReadLine();
            if (string.IsNullOrEmpty(input))
            {
                continue;
            }

            switch (input[0])
            {
            case 'E':
                finish = true;
                break;

            case 'O':
                door.OnDoorOpen();
                break;

            case 'C':
                door.OnDoorClose();
                break;

            case 'R':
                System.Console.WriteLine("Indtast RFID id: ");
                string idString = System.Console.ReadLine();

                int id = Convert.ToInt32(idString);
                rfidReader.OnRfidRead(id);
                break;

            case 'K':
                if (door.DoorIsOpen && !usbCharger.Connected)
                {
                    usbCharger.SimulateConnected(true);
                    Console.WriteLine("Telefon tilsluttet");
                }
                else
                {
                    Console.WriteLine("Laderen er optaget ellers er døren ikke åben");
                }
                break;

            case 'L':
                if (door.DoorIsOpen && usbCharger.Connected)
                {
                    usbCharger.SimulateConnected(false);
                    Console.WriteLine("Telefon taget ud af charger");
                }
                else
                {
                    Console.WriteLine("Døren skal være åben og laderen optaget før du kan tage den ud af opladning");
                }
                break;

            default:
                break;
            }
        } while (!finish);
    }
コード例 #4
0
ファイル: Program.cs プロジェクト: SWT-E20/Ladeskab
        static void Main(string[] args)
        {
            IDoor       door    = new Door();
            IRfidReader rfid    = new RfidReader();
            IDisplay    display = new Display();
            ILogFile    logfile = new LogFile("logfile.txt");

            UsbCharger     charger       = new UsbCharger();
            IChargeControl chargeControl = new ChargeControl(display, charger);

            StationControl ladeSkab = new StationControl(door, rfid, display, chargeControl, logfile);

            Console.WriteLine("e - Close program.");
            Console.WriteLine("o - Open/close door.");
            Console.WriteLine("r - Scan RFID.");
            Console.WriteLine("c - Phone connected.");
            Console.WriteLine("d - Phone disconnected.\n");

            bool finish = false;

            do
            {
                string input;
                Console.Write("> ");
                input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    continue;
                }

                switch (input[0])
                {
                case 'e':
                    finish = true;
                    break;

                case 'o':
                    door.ToggleDoor();
                    break;

                case 'r':
                    Console.WriteLine("Enter RFID id: ");
                    string inputId = Console.ReadLine();
                    int    id      = Convert.ToInt32(inputId);

                    rfid.OnKeySwiped(id);
                    break;

                case 'c':
                    Console.WriteLine("Phone connected.");
                    charger.SimulateConnected(true);
                    break;

                case 'd':
                    Console.WriteLine("Phone disconnected.");
                    charger.SimulateConnected(false);
                    break;

                default:
                    Console.WriteLine("!INVALID INPUT!");
                    break;
                }
                Console.WriteLine();
            } while (!finish);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: ellenhuld/Ladeskab
        static void Main(string[] args)
        {
            // Assemble your system here from all the classes
            RFIDReader    reader  = new RFIDReader();
            Door          door    = new Door();
            IConsoleWrite iWrite  = new ConsoleWrite();
            Display       display = new Display(iWrite);
            USBCharger    charger = new USBCharger();

            TimeProvider timeprovider = new TimeProvider();
            FileWriter   filewriter   = new FileWriter();
            LogFile      logfile      = new LogFile(filewriter, timeprovider);

            ChargeControl chargecontrol = new ChargeControl(charger);

            StationControl stationControl = new StationControl(reader, door, display, chargecontrol, logfile);


            bool finish = false;

            do
            {
                string input;
                System.Console.WriteLine("Indtast E (exit), O (open door), C (close door), R (rfid id), T (mobil tilsluttet), F (mobil fjernet): ");
                input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    continue;
                }

                switch (input[0])
                {
                case 'E':
                    finish = true;
                    break;

                case 'O':
                    door.DoorOpen();
                    break;

                case 'C':
                    door.DoorClose();
                    break;

                case 'R':
                    System.Console.WriteLine("Indtast RFID id: ");
                    string idString = System.Console.ReadLine();

                    int id = Convert.ToInt32(idString);
                    reader.Readtag(id);
                    break;

                case 'T':
                    System.Console.WriteLine("Mobiltelefon forbundet");
                    charger.SimulateConnected(true);
                    break;

                case 'F':
                    System.Console.WriteLine("Mobiltelefon ikke forbundet");
                    charger.SimulateConnected(false);
                    break;

                default:
                    break;
                }
            } while (!finish);
        }
コード例 #6
0
        static void Main(string[] args)
        {
            // Assemble your system here from all the classes
            Door _door = new Door();
            RfidReaderSimulator _rfid           = new RfidReaderSimulator();
            UsbChargerSimulator _usbCharger     = new UsbChargerSimulator();
            DisplayOutput       _displayOutput  = new DisplayOutput();
            DisplaySimulator    _display        = new DisplaySimulator(_displayOutput);
            ChargeControl       _chargeControl  = new ChargeControl(_display, _usbCharger);
            LogOutput           _logOutput      = new LogOutput();
            LogfileWriter       _logfile        = new LogfileWriter(_logOutput);
            StationControl      _stationControl = new StationControl(_chargeControl, _door, _rfid, _display, _logfile);
            bool finish = false;

            System.Console.WriteLine("Indtast:\n" +
                                     "(E) Exit\n" +
                                     "(O) Open\n" +
                                     "(C) Close\n" +
                                     "(R) Read RF-ID");

            do
            {
                string input = null;

                // Gate the blocking ReadLine function
                if (Console.KeyAvailable)
                {
                    input = Console.ReadLine();
                }
                if (string.IsNullOrEmpty(input))
                {
                    continue;
                }

                input = input.ToUpper();

                switch (input[0])
                {
                case 'E':
                    finish = true;
                    break;

                case 'O':
                    _door.DoorOpened();
                    break;

                case 'C':
                    _door.DoorClosed();
                    break;

                case 'R':
                    System.Console.WriteLine("Indtast RFID id: ");
                    string idString = System.Console.ReadLine();

                    int id = Convert.ToInt32(idString);
                    _rfid.ScanRfidTag(id);

                    break;

                default:
                    break;
                }

                System.Console.WriteLine("Indtast:\n" +
                                         "(E) Exit\n" +
                                         "(O) Open\n" +
                                         "(C) Close\n" +
                                         "(R) Read RF-ID");
            } while (!finish);
        }
コード例 #7
0
 public void Setup()
 {
     _uut = new StationControl(_fakeIdReader, _fakeDoor, _fakeChargeControl, _fakeLogger);
 }
コード例 #8
0
 public VacantDoorClosedPhoneConnectedAwaitingRFID(StationControl stationControlRef)
 {
     StationControlRef = stationControlRef;
 }
コード例 #9
0
        static void Main(string[] args)
        {
            bool finish = false;

            //Assemble your system here from all the classes
            Door          door          = new Door(); //Der bruges metoder (open og close) der ikke er en del af interface
            IDisplay      display       = new Display(new ConsoleWriter());
            IUsbCharger   usb           = new UsbChargerSimulator();
            ChargeControl chargeControl = new ChargeControl(usb, display);
            ILogFile      logFile       = new LogFile(new TimeProvider(), new FileWriter());
            RfidReader    rfidReader    = new RfidReader();

            door = new Door();

            StationControl station = new StationControl(door, rfidReader, display, chargeControl, logFile);

            System.Console.WriteLine(
                "Velkommen til ladeskabet :) Her kan du få frisk strøm, mens din telefon er låst inde\n");
            do
            {
                string input;
                System.Console.WriteLine("Indtast bogstav: E_nd, O_pen, C_lose, R_rfid, P_lug eller U_nplug: ");
                input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    continue;
                }
                input = input.ToUpper();
                switch (input[0])
                {
                case 'E':
                    finish = true;
                    break;

                case 'O':
                    door.OpenDoor();
                    break;

                case 'C':
                    door.CloseDoor();
                    break;

                case 'R':
                    System.Console.WriteLine("Indtast RFID id: ");
                    string idString = System.Console.ReadLine();

                    rfidReader.ManualScanTag(idString);
                    break;

                case 'P':
                    chargeControl.PlugPhoneIn();
                    break;

                case 'U':
                    chargeControl.UnPlugPhone();
                    break;

                default:
                    break;
                }
            } while (!finish);
        }
コード例 #10
0
        static void Main(string[] args)
        {
            // Assemble your system here from all the classes

            IDoor          door          = new Door();
            IRFIDReader    rfidReader    = new RFIDReader();
            ILogFile       logFile       = new LogFile();
            IUsbCharger    usbCharger    = new UsbCharger();
            IChargeControl chargeControl = new ChargeControl(usbCharger);
            IDisplay       display       = new Display();

            StationControl stationController = new StationControl(door, logFile, rfidReader, chargeControl, usbCharger, display);

            bool finish = false;

            do
            {
                string input;
                System.Console.WriteLine("Indtast (E)nd, (O)pen, (C)lose, (R)ead Card, Connect (P)hone: ");
                input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    continue;
                }

                switch (input[0])
                {
                case 'E':
                    System.Environment.Exit(1);
                    break;

                case 'O':
                    door.OpenDoor();
                    break;

                case 'C':
                    door.CloseDoor();
                    break;

                case 'R':
                    rfidReader.CardID = int.Parse(Console.ReadLine());
                    break;

                case 'P':
                    if (door.Closed)
                    {
                        Console.WriteLine("Cant connect phone when door is closed");
                    }
                    else
                    {
                        usbCharger.Connected = true;
                        Console.WriteLine("Phone connected");
                    }

                    break;

                default:
                    break;
                }
            } while (!finish);
        }
コード例 #11
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            // Assemble your system here from all the classes
            var         door          = new Door();
            IUsbCharger usbCharger    = new UsbChargerSimulator();
            var         chargeDisplay = new ChargeDisplay();
            var         charger       = new ChargeControl(usbCharger, chargeDisplay);
            var         reader        = new RfidReader();
            var         display       = new Display();
            var         fileWriter    = new FileWriter("LogFile.txt");
            var         timeStamp     = new DateTime();
            var         log           = new Log(fileWriter, timeStamp);

            var stationControl = new StationControl(door, charger, reader, display, log);

            bool finish = false;

            do
            {
                string input;
                System.Console.WriteLine("Indtast E, O, C, R, T: ");
                input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    continue;
                }

                switch (input[0])
                {
                case 'E':
                    finish = true;
                    break;

                case 'O':
                    door.SimulateDoorOpens();
                    break;

                case 'C':
                    door.SimulateDoorCloses();
                    break;

                case 'R':
                    System.Console.WriteLine("Indtast RFID id: ");
                    string idString = System.Console.ReadLine();

                    int id = Convert.ToInt32(idString);
                    reader.SimulateDetection();
                    reader.RfidDetected(id);
                    break;

                case 'T':    // Tilføjet for at kunne "Connected" telefonen til opladeren.
                    charger.Connected = true;
                    break;

                default:
                    break;
                }
            } while (!finish);
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: SWTgrp12/Ladeskab
        static void Main(string[] args)
        {
            // Assemble your system here from all the classes
            Door                door       = new Door();
            DisplayControl      display    = new DisplayControl();
            UsbChargerSimulator usbCharger = new UsbChargerSimulator();
            RFIDReader          rfidReader = new RFIDReader();

            ChargeControl  chargeControl  = new ChargeControl(usbCharger, display);
            StationControl stationControl = new StationControl(rfidReader, door, display, chargeControl);
            bool           connectedPhone = true;
            bool           overcharge     = false;


            bool finish = false;

            do
            {
                string input;
                System.Console.WriteLine("Indtast (E)xit, (O)pendoor, (C)losedoor, (P)hone, (K)overload (R)fid: ");
                input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    continue;
                }


                switch (input[0])
                {
                case 'e':
                case 'E':
                    finish = true;
                    break;

                case 'o':
                case 'O':
                    door.Open();
                    break;

                case 'c':
                case 'C':
                    door.Close();
                    break;

                case 'r':
                case 'R':
                    System.Console.WriteLine("Indtast RFID id: ");
                    string idString = System.Console.ReadLine();
                    int    id       = 0;
                    while (!Int32.TryParse(idString, out id))
                    {
                        System.Console.WriteLine("Rfid not accepted, Try again: ");
                        idString = System.Console.ReadLine();
                    }
                    rfidReader.RfidEvent(id);
                    break;

                case 'P':
                case 'p':
                    if (connectedPhone == false)
                    {
                        usbCharger.SimulateConnected(true);
                        connectedPhone = true;
                    }
                    else
                    {
                        usbCharger.SimulateConnected(false);
                    }
                    connectedPhone = false;

                    break;

                case 'k':
                case 'K':
                    if (overcharge == false)
                    {
                        usbCharger.SimulateOverload(true);
                        overcharge = true;
                    }
                    else
                    {
                        usbCharger.SimulateConnected(false);
                    }
                    overcharge = false;

                    break;

                default:
                    break;
                }
            } while (!finish);
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: Yoda92/SWT-Aflevering2
        static void Main(string[] args)
        {
            Display             _display             = new Display();
            UsbChargerSimulator _usbChargerSimulator = new UsbChargerSimulator();
            ChargeControl       _chargeControl       = new ChargeControl(_display, _usbChargerSimulator);
            RFIDReaderSimulator _RFIDReaderSimulator = new RFIDReaderSimulator();
            DoorSimulator       _doorSimulator       = new DoorSimulator();
            LogFile             _logfile             = new LogFile();
            StationControl      _stationControl      = new StationControl(_display, _doorSimulator, _logfile, _RFIDReaderSimulator, _chargeControl);

            bool finish = false;

            System.Console.WriteLine("Indtast E = Exit\nO = Open\nC = Close\nR = RFID Read\nT = Tilslut/Fjern telefon");
            do
            {
                string input;
                input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    continue;
                }

                switch (input[0])
                {
                case 'E':
                    finish = true;
                    break;

                case 'O':
                    _doorSimulator.SimulateDoorOpen();
                    break;

                case 'C':
                    _doorSimulator.SimulateDoorClose();
                    break;

                case 'T':
                    if (_stationControl._state == StationControl.LadeskabState.DoorOpen)
                    {
                        _usbChargerSimulator.SimulateConnected(!_usbChargerSimulator.Connected);
                        Console.WriteLine("Telephone connected: " + _usbChargerSimulator.Connected);
                    }
                    else
                    {
                        Console.WriteLine("Open door first!");
                    }
                    break;

                case 'R':
                    Console.WriteLine("Indtast RFID id: ");
                    string idString = Console.ReadLine();

                    int id = Convert.ToInt32(idString);
                    _RFIDReaderSimulator.SimulateReadRFID(id);
                    break;

                default:
                    break;
                }
            } while (!finish);
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: SWTTestGrp4/PhoneLocker
        static void Main(string[] args)
        {
            #region Instantiering af dependencies
            IUsbCharger usbCharger = new UsbCharger();
            IDisplay    display    = new Display();
            IDoor       door       = new Door();
            ILogging    logging    = new LogFileDAL();
            IRFIDReader rfidReader = new RFIDReader();

            IChargeControl chargeControl = new ChargeControl(usbCharger);

            IStationControl stationControl = new StationControl(door, rfidReader, chargeControl, logging, display);
            #endregion


            bool finish = false;
            do
            {
                string input;
                System.Console.WriteLine("Indtast E (exit), O (open), C (close), R (rfid), P (phone): ");
                input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    continue;
                }


                switch (input[0])
                {
                case 'E':
                case 'e':
                    finish = true;
                    break;

                case 'O':
                case 'o':
                    if (stationControl.State == PhoneLockerState.DoorOpen)
                    {
                        display.DisplayText("Ladedøren er allerede åben. Frakobl eller tilslut mobil.");
                        break;
                    }
                    else
                    {
                        stationControl.State = PhoneLockerState.DoorOpen;
                        display.DisplayText("Døren er åben");
                        display.DisplayText("Tilslut telefon");
                    }
                    break;

                case 'C':
                case 'c':
                    if (stationControl.State != PhoneLockerState.DoorOpen)
                    {
                        break;
                    }
                    stationControl.State = PhoneLockerState.Available;
                    display.DisplayText("Døren er lukket");
                    display.DisplayText("Scan venligst RFID");
                    break;

                case 'R':
                case 'r':
                    Console.Clear();
                    display.DisplayText("Indtast RFID id: ");
                    string idString = System.Console.ReadLine();

                    int id = Convert.ToInt32(idString);
                    rfidReader.ReadRFID(id);

                    break;

                case 'P':
                case 'p':
                    if (stationControl.State != PhoneLockerState.DoorOpen)
                    {
                        display.DisplayText("Døren er lukket. Åben før der kan tilsluttes.");
                        break;
                    }
                    if (chargeControl.Connected)
                    {
                        chargeControl.Connected = false;
                        display.DisplayText("Telefon frakoblet");
                    }
                    else
                    {
                        chargeControl.Connected = true;
                        display.DisplayText("Telefon tilsluttet");
                    }
                    break;

                default:
                    break;
                }
            } while (!finish);
        }
コード例 #15
0
        // this method will be reworked
        private void Load()
        {
            Stations           = new ObservableCollection <StationViewModel>();
            StationConnections = new ObservableCollection <StationConnectionViewModel>();

            SelectStationCommand = new RelayCommand(SelectStation);

            List <Station> stationsData;
            double         canvasLeft;
            double         canvasBottom;
            StationControl sc = new StationControl();

            using (var context = new MetroNavigationContext())
            {
                stationsData = context.Stations.
                               Include(s => s.StationConnection).ToList();
            }

            MinX = stationsData.Min(s => s.OsX);
            MaxX = stationsData.Max(s => s.OsX);
            MinY = stationsData.Min(s => s.OsY);
            MaxY = stationsData.Max(s => s.OsY);
            List <double> l = new List <double>();

            foreach (var station in stationsData)
            {
                canvasLeft = (SystemParameters.WorkArea.Width * 0.9) *
                             (station.OsX - MinX) / (MaxX - MinX);

                canvasBottom = (SystemParameters.WorkArea.Height * 0.9) *
                               (station.OsY - MinY) / (MaxY - MinY);

                canvasLeft = canvasLeft > (SystemParameters.WorkArea.Width * 0.9)
                                          ? canvasLeft
                                          : canvasLeft;

                canvasBottom = canvasBottom > (SystemParameters.WorkArea.Height * 0.9)
                                          ? canvasBottom
                                          : canvasBottom;

                Stations.Add(new StationViewModel()
                {
                    CanvasLeft = canvasLeft, CanvasBottom = canvasBottom, Name = station.Name, Line = station.Line, ConnectedStationO = new StationConnectionViewModel()
                    {
                        NextStation = station.StationConnection.NextStation, PreviousStation = station.StationConnection.PreviousStation
                    }, TransitToLine = station.TransitToLine, TransitToStation = station.TransitToStation
                });
            }

            var temp = Stations.OrderBy(s => s.Line).ToList();

            foreach (StationViewModel station in temp)
            {
                StationViewModel connected = null;
                if (station.ConnectedStationO.NextStation != null)
                {
                    connected = temp.Find(s => s.Name.Trim() == station.ConnectedStationO.NextStation.Trim());
                }

                if (connected != null)
                {
                    Brush lineColor = Brushes.Black;
                    if (station.Line == 1)
                    {
                        lineColor = Brushes.Red;
                    }
                    else if (station.Line == 2)
                    {
                        lineColor = Brushes.Green;
                    }
                    else if (station.Line == 3)
                    {
                        lineColor = Brushes.Blue;
                    }

                    if (station.CanvasBottom > connected.CanvasBottom & station.CanvasLeft > connected.CanvasLeft | station.CanvasBottom > connected.CanvasBottom & station.CanvasLeft < connected.CanvasLeft)
                    {
                        StationConnections.Add(new StationConnectionViewModel()
                        {
                            X1 = station.CanvasLeft + sc.MaxHeight / 2, X2 = connected.CanvasLeft + sc.MaxHeight / 2, Y1 = SystemParameters.WorkArea.Height - station.CanvasBottom, Y2 = SystemParameters.WorkArea.Height - connected.CanvasBottom, CanvasBottom = connected.CanvasBottom + (sc.MaxHeight / 2) - 2, LineColor = lineColor, NextStation = connected.Name
                        });
                    }
                    else if (station.CanvasBottom < connected.CanvasBottom & station.CanvasLeft < connected.CanvasLeft | station.CanvasBottom <connected.CanvasBottom& station.CanvasLeft> connected.CanvasLeft)
                    {
                        StationConnections.Add(new StationConnectionViewModel()
                        {
                            X1 = station.CanvasLeft + sc.MaxHeight / 2, X2 = connected.CanvasLeft + sc.MaxHeight / 2, Y1 = SystemParameters.WorkArea.Height - connected.CanvasBottom + (station.CanvasBottom - connected.CanvasBottom), Y2 = (SystemParameters.WorkArea.Height - connected.CanvasBottom) + (station.CanvasBottom - connected.CanvasBottom) * 2, CanvasBottom = station.CanvasBottom + (sc.MaxHeight / 2) - 2, LineColor = lineColor, NextStation = connected.Name
                        });
                    }
                }
            }
        }
コード例 #16
0
ファイル: Program.cs プロジェクト: KunJakob/SWT-PhoneCharger
    static void Main(string[] args)
    {
        //set up DI
        ServiceProvider   ServiceProvider;
        ServiceCollection services = new ServiceCollection();

        //register services and build service provider
        ConfigureServices(services);
        ServiceProvider = services.BuildServiceProvider();

        //get instances
        IDoor          door            = ServiceProvider.GetService <IDoor>();
        IRfidReader    rfidReader      = ServiceProvider.GetService <IRfidReader>();
        IDisplay       Display         = ServiceProvider.GetService <IDisplay>();
        StationControl _stationControl = ServiceProvider.GetService <StationControl>();
        //local vars
        bool finish = false;

        do
        {
            Display.NotifyStation("Indtast E, O, C, R: ");
            string input = Display.ReadInput();
            if (string.IsNullOrEmpty(input))
            {
                continue;
            }

            switch (input[0])
            {
            case 'E':
                finish = true;
                break;

            case 'O':
                door.OpenDoor();
                break;

            case 'C':
                door.CloseDoor();
                break;

            case 'R':
                Display.NotifyStation("Input RFID id: ");
                string idString = Display.ReadInput();
                //fix maybe?
                try
                {
                    int id = Convert.ToInt32(idString);
                    rfidReader.Read(id);
                }
                catch (FormatException e)
                {
                    Display.NotifyStation("You must input a valid number!");
                }
                break;

            default:
                break;
            }
        } while (!finish);
    }
コード例 #17
0
ファイル: Program.cs プロジェクト: lasseloef/SWT_Ladeskab
        static void Main(string[] args)
        {
            //Classes that need to be influenced outside stationControl
            IDoor       door       = new Door();
            IRfidReader rfidReader = new RfidReader();

            IUsbCharger    sim           = new UsbChargerSimulator();
            IChargeControl chargeControl = new ChargeControl(sim);


            //Classes only used inside stationControl just declared in ctor args
            StationControl stationControl = new StationControl(new Logger(), new Display(), door, rfidReader, chargeControl);

            //Circular dependency
            sim.Controller = stationControl;

            //User interaction:

            bool keepGoing = true;
            bool connected = false;
            bool shorted   = false;

            Console.WriteLine("INPUTS:");
            Console.WriteLine("[P/p]: Toggle phone plugged in.\t[S/s]: Toggle a short in the charger");
            Console.WriteLine("[O/o]: Try to open door\t\t[C/c]: Try to close door");
            Console.WriteLine("[R/r]: Scan RFID 1: 12345\t[T/t]: Scan RFID 2: 54321");
            Console.WriteLine("[Q/q]: Quit");
            stationControl.Start();
            while (keepGoing)
            {
                switch (Console.ReadKey(true).Key)
                {
                case ConsoleKey.P:

                    connected = !connected;
                    ((UsbChargerSimulator)sim).SimulateConnected(connected);
                    break;

                case ConsoleKey.S:
                    shorted = !shorted;
                    ((UsbChargerSimulator)sim).SimulateOverload(shorted);
                    break;

                case ConsoleKey.O:
                    ((Door)door).OpenDoor();
                    break;

                case ConsoleKey.C:
                    ((Door)door).CloseDoor();
                    break;

                case ConsoleKey.R:
                    ((RfidReader)rfidReader).RfidRead(12345);
                    break;

                case ConsoleKey.T:
                    ((RfidReader)rfidReader).RfidRead(54321);
                    break;

                case ConsoleKey.Q:
                    keepGoing = false;
                    break;
                }
            }
        }
コード例 #18
0
        static void Main(string[] args)
        {
            // Assemble your system here from all the classes
            IDoor          _door          = new Door();
            IConsoleWriter _consoleWriter = new ConsoleWriter();
            IRFidReader    _rfidReader    = new RFidReader();
            IUsbCharger    _charger       = new UsbChargerSimulator();
            IFileLogger    _fileLogger    = new FileLogger();


            IChargeControl _chargeControl  = new ChargeControl(_charger, _consoleWriter);
            StationControl _stationControl = new StationControl(_door, _rfidReader, _chargeControl, _fileLogger, _consoleWriter);


            //Use this
            //System.Console.WriteLine("Indtast E: Finish, O: Open , C: Close, R: RFid, K: Telefon sat til, L: Overload: ");
            System.Console.WriteLine("E: Finish");
            System.Console.WriteLine("O: Open");
            System.Console.WriteLine("C: Close");
            System.Console.WriteLine("R: RFid");
            System.Console.WriteLine("K: Connect phone");
            System.Console.WriteLine("L: Simulate overload");
            System.Console.WriteLine("___________________________");

            bool finish = false;

            do
            {
                string input;
                input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    continue;
                }

                switch (input[0])
                {
                case 'E':
                    finish = true;
                    break;

                case 'O':
                    //_door.DoorOpened();
                    _door.SetDoorState(true);
                    break;

                case 'C':
                    //_door.DoorClosed();
                    _door.SetDoorState(false);
                    break;

                case 'R':
                    System.Console.WriteLine("Indtast RFID id: ");
                    string idString = System.Console.ReadLine();

                    int id = Convert.ToInt32(idString);
                    _rfidReader.SetID(id);

                    break;


                case 'K':
                    System.Console.WriteLine("Telefon er sat til ");
                    _charger.SimulateConnected(true);
                    break;

                case 'L':
                    System.Console.WriteLine("Kabel Overloaded ");
                    _charger.SimulateOverload(true);
                    break;


                default:
                    break;
                }
            } while (!finish);
        }
コード例 #19
0
ファイル: Program.cs プロジェクト: team24SWT/Handin2_LAdeskab
    public static void  Main(string[] args)
    {
        // Assemble your system here from all the classes
        Door           _door           = new Door();
        RFIDReader     _rfid           = new RFIDReader();
        PrintToDisplay _printToDisplay = new PrintToDisplay();
        Display        _display        = new Display(_printToDisplay);
        LogDisplay     _logDisplay     = new LogDisplay();
        Log            _log            = new Log(_logDisplay);
        UsbCharger     _charger        = new UsbCharger();
        ChargeControl  _chargeControl  = new ChargeControl(_display, _charger);
        StationControl _stationControl = new StationControl(_chargeControl, _door, _display, _rfid, _log);

        bool   finish = false;
        string input;

        System.Console.WriteLine(" -----------------------------------------\n\n " +
                                 " INDTAST FOR AT FORTAGE EN HANDLING\n " +
                                 "  E (Exit)\n " +
                                 "  O (Open)\n " +
                                 "  C (Closed)\n " +
                                 "  R (Read RFID)\n " +
                                 "  G (Guide)\n\n" +
                                 "-----------------------------------------");


        do
        {
            input = Console.ReadLine();
            if (string.IsNullOrEmpty(input))
            {
                continue;
            }

            switch (input[0])
            {
            case 'E':
            case 'e':
                finish = true;
                break;

            case 'O':
            case 'o':
                _door.DoorOpen();
                break;

            case 'C':
            case 'c':
                _door.DoorClosed();
                break;

            case 'R':
            case 'r':
                System.Console.WriteLine("Indtast RFID id: ");
                string idString = System.Console.ReadLine();

                int id = Convert.ToInt32(idString);
                if (id > 0)
                {
                    _rfid.OnRfidRead(id);
                }
                else
                {
                    System.Console.WriteLine("RFID er ugyldigt! RFID kan ikke være et negativt tal eller over 10.000!");
                }

                break;

            case 'G':
            case 'g':
                System.Console.WriteLine(" -----------------------------------------\n\n " +
                                         " 1. Open the door of the Ladeskab\n " +
                                         " 2. Insert your phone into the Ladeskab\n " +
                                         " 3. Connect your phone to the USB charger inside the Ladeskab\n " +
                                         " 4. CLose the door of the Ladeskab\n " +
                                         " 5. Read your RFID tag on the RFID-Reader\n " +
                                         " !!Congratulations! Your phone is now charging!!\n\n" +
                                         " Note: To remove your phone from the Ladeskab read your RFID tag on the RFID Reader and open the door to the Ladeskab\n\n" +
                                         "-----------------------------------------");
                break;

            default:
                break;
            }
        } while (!finish); //test af push
    }
コード例 #20
0
ファイル: Program.cs プロジェクト: hoej98/SWT_2_LMM
    static void Main(string[] args)
    {
        // Assemble your system here from all the classes
        IDoor          door           = new Door();
        IDisplay       display        = new Display();
        IRFID          rfidReader     = new RFIDReader();
        IUsbCharger    usbCharger     = new UsbChargerSimulator();
        StationControl stationControl = new StationControl(door, rfidReader, usbCharger, display);

        // Udskriver de forskellige muligheder brugeren har i starten
        System.Console.WriteLine("Indtast 'E' for 'Exit'\n" +
                                 "Indtast 'O' for 'Open door'\n" +
                                 "Indtast 'C' for 'Close door'\n" +
                                 "Indtast 'K' for 'Connect phone'\n" +
                                 "Indtast 'R' for 'RFID'");

        // Kalder chargeSurveillance hvert 5. sekund - udskriver status og stopper opladning når fuldt opladt.
        var timer = new System.Threading.Timer(
            e => stationControl.chargeSurveillance(),
            null,
            TimeSpan.Zero,
            TimeSpan.FromSeconds(5));

        bool finish = false;

        do
        {
            string input;
            //Console.WriteLine("Indtast E, O, C, K, R: ");
            input = Console.ReadLine();
            if (string.IsNullOrEmpty(input))
            {
                continue;
            }

            switch (input[0])
            {
            case 'E':
                finish = true;
                break;

            case 'O':
                door.OnDoorOpen();
                break;

            case 'C':
                door.OnDoorClose();
                break;

            case 'K':
                bool isconnect = usbCharger.Connected;
                while (isconnect == false)
                {
                    Console.WriteLine("Telefon ikke tilsluttet");
                    break;
                }
                Console.WriteLine("Telefon tilsluttet. Luk venligst døren");
                break;

            case 'R':
                System.Console.WriteLine("Indtast RFID id: ");
                string idString = System.Console.ReadLine();

                int id = Convert.ToInt32(idString);
                rfidReader.OnRfidRead(id);
                break;

            default:
                break;
            }
        } while (!finish);
    }
コード例 #21
0
    static void Main(string[] args)
    {
        // Assemble your system here from all the classes
        //DoorSimulator doorSimulator = new DoorSimulator();
        IUsbCharger    charger       = new UsbChargerSimulator();
        IDisplay       display       = new Display();
        IChargeControl chargeControl = new ChargeControl(charger, display);
        IDoor          doorSimulator = new DoorSimulator();
        //RfidReaderSimulator rfidReaderSimulator = new RfidReaderSimulator();
        IRfidReader rfidReaderSimulator = new RfidReaderSimulator();
        IFileLog    fileLog             = new FileLog();

        StationControl stationControl = new StationControl(doorSimulator, rfidReaderSimulator, chargeControl, fileLog, display);

        //Det man indtaster simulerer det som brugeren fysisk gør.
        //Fra program bliver der sat gang i Events, som StationControl får besked om

        bool finish = false;

        do
        {
            string input;
            System.Console.WriteLine("Indtast E, O, C, R, Y, N: ");
            input = Console.ReadLine();
            if (string.IsNullOrEmpty(input))
            {
                continue;
            }

            switch (input[0])
            {
            case 'E':
                finish = true;
                break;

            case 'O':
                doorSimulator.OnDoorOpen();
                break;

            case 'C':
                doorSimulator.OnDoorClose();
                break;

            case 'R':
                System.Console.WriteLine("Indtast RFID id: ");
                string idString = System.Console.ReadLine();

                int id = Convert.ToInt32(idString);

                rfidReaderSimulator.OnRfidRead(id);
                break;

            case 'Y':
                charger.SimulateConnected(true);
                break;

            case 'N':
                charger.SimulateConnected(false);
                break;

            default:
                break;
            }
        } while (!finish);
    }
コード例 #22
0
 public VacantDoorClosedNoPhoneConnected(StationControl stationControlRef)
 {
     StationControlRef = stationControlRef;
 }
コード例 #23
0
 public OccupiedDoorClosedAwaitingRFID(StationControl stationControlRef)
 {
     StationControlRef = stationControlRef;
 }
コード例 #24
0
    private static void Main(string[] args)
    {
        // Assemble your system here from all the classes

        //Make objects, so that we can call door methods and rfidreader.
        IRFIDReader    rfidReader    = new RFIDReader();
        IDoor          door          = new Door();
        IDisplay       display       = new Display();
        IChargeControl chargeControl = new ChargeControl(new UsbChargerSimulator());

        IStationControl stationControl = new StationControl(door, display, rfidReader, chargeControl);

        var finish = false;

        do
        {
            string input;
            Console.WriteLine("Indtast E, O, C, R: ");
            input = Console.ReadLine();
            if (string.IsNullOrEmpty(input))
            {
                continue;
            }

            switch (input[0])
            {
            case 'E':
            case 'e':
                finish = true;
                break;

            case 'O':
            case 'o':
                door.open();
                break;

            case 'C':
            case 'c':
                door.close();
                break;

            case 'R':
            case 'r':
                if (door.getDoorState() == 0)
                {
                    Console.WriteLine("Indtast RFID id: ");
                    var idString = Console.ReadLine();
                    var id       = Convert.ToInt32(idString);
                    rfidReader.onRfidDetectedEvent(id);
                }
                else
                {
                    {
                        Console.WriteLine("Luk venligst døren");
                    }
                }

                break;

            default:
                break;
            }
        } while (!finish);
    }
コード例 #25
0
 public VacantDoorOpenPhoneConnected(StationControl stationControlRef)
 {
     StationControlRef = stationControlRef;
 }
コード例 #26
0
        static void Main(string[] args)
        {
            // Assemble your system here from all the classes
            IDoor          _door          = new Door();
            IUsbCharger    _usbCharger    = new UsbChargerSimulator();
            IDisplay       _display       = new Display();
            IRFIDReader    _rfidReader    = new RFIDReaderSimulator();
            ILogWriter     _log           = new LogWriter();
            IChargeControl _charge        = new ChargeControl(_display, _usbCharger);
            StationControl stationControl = new StationControl(_door, _display, _rfidReader, _log, _charge);

            int  runs   = 0;
            bool finish = false;

            do
            {
                string input;

                if (runs == 0)
                {
                    System.Console.WriteLine("Welcome to ChargingLocker");
                    System.Console.WriteLine("Type 'Open' to open locker door");
                    System.Console.WriteLine("Type 'Close' to close locker door");
                    System.Console.WriteLine("Type 'Scan' to scan your RFID tag");
                    System.Console.WriteLine("Type 'Exit' to exit program");
                }
                else
                {
                    System.Console.WriteLine("Type 'List' to show all options");
                }
                runs = 1;
                System.Console.Write("Input: ");
                input = Console.ReadLine();

                if (string.IsNullOrEmpty(input))
                {
                    continue;
                }
                switch (input)
                {
                case "Exit" or "exit":
                    finish = true;
                    break;

                case "Open" or "open":
                    if (_door._lock == true)
                    {
                        _display.DisplayDoorIsLocked();
                    }
                    else
                    {
                        _door.DoorOpened();
                    }
                    break;

                case "Close" or "close":
                    if (_door._lock == true)
                    {
                        _display.DisplayDoorIsLocked();
                    }
                    else
                    {
                        _door.DoorClosed();
                    }
                    break;

                case "Scan" or "scan":
                    System.Console.WriteLine("Indtast RFID id: ");
                    string idString = System.Console.ReadLine();

                    int id = Convert.ToInt32(idString);
                    stationControl.runProgram(id);
                    break;

                case "List" or "list":
                    runs = 0;
                    break;

                default:
                    break;
                }
            } while (!finish);
        }