public AuthorityTool(CTCOfficeGUI ctcgui, CTCOffice ctc, ISimulationEnvironment env)
 {
     InitializeComponent();
     _ctc = ctc;
     _ctcgui = ctcgui;
     _env = env;
 }
Пример #2
0
        public void createCTCOffice()
        {
            // Assign the same track controller to both lines
            _office = new CTCOffice.CTCOffice(_env, _prev, _prev);

            _env.CTCOffice = _office;
        }
 public AuthorityTool(CTCOfficeGUI ctcgui, CTCOffice ctc, ISimulationEnvironment env)
 {
     InitializeComponent();
     _ctc    = ctc;
     _ctcgui = ctcgui;
     _env    = env;
 }
Пример #4
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Environment
            env = new SimulationEnvironment.SimulationEnvironment();

            // TrackModel
            TrackModel.TrackModel trackModel = new TrackModel.TrackModel(env);
            env.TrackModel = trackModel;
            TrackModel.TrackModelGUI trackModelGui = new TrackModelGUI(env, trackModel);

            // CTCOffice
            CTCOffice.CTCOffice ctcOffice = new CTCOffice.CTCOffice(env, env.PrimaryTrackControllerRed, env.PrimaryTrackControllerGreen);
            env.CTCOffice = ctcOffice;
            CTCOffice.CTCOfficeGUI ctcOfficeGui = new CTCOfficeGUI(env, ctcOffice);
            ctcOfficeGui.ShowTrain += new EventHandler<ShowTrainEventArgs>(ctcOfficeGui_ShowTrain);
            ctcOfficeGui.ShowSchedule += new EventHandler<EventArgs>(ctcOfficeGui_ShowSchedule);

            // Scheduler
            SystemScheduler.SystemScheduler scheduler = new SystemScheduler.SystemScheduler(env, ctcOffice);
            env.SystemScheduler = scheduler;
            SystemScheduler.SystemSchedulerGUI schedulerGui = new SystemScheduler.SystemSchedulerGUI(env, scheduler, ctcOffice);

            // train model form
            TrainModel.TrainGUI trainGui = new TrainGUI(env);

            // Track Controllers
            if (env.PrimaryTrackControllerRed != null)
            {
                TrackController.TrackController red = (TrackController.TrackController)env.PrimaryTrackControllerRed;
                TrackControllerUi redTcGui = new TrackControllerUi(env, red);
                trackControllerRedForm = new Form() { Controls = { redTcGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Track Controller Red" };
            }

            if (env.PrimaryTrackControllerGreen != null)
            {
                TrackController.TrackController green = (TrackController.TrackController)env.PrimaryTrackControllerGreen;
                TrackControllerUi greenTcGui = new TrackControllerUi(env, green);
                trackControllerGreenForm = new Form() { Controls = { greenTcGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Track Controller Green" };
            }

            ctcForm = new Form() { Controls = { ctcOfficeGui }, AutoSize = true, Text="Terminal Velocity - CTC Office"};
            schedulerForm = new Form() { Controls = { schedulerGui }, TopLevel = true, AutoSize = true, Parent = null, Text="Terminal Velocity - System Scheduler" };
            trackModelForm = new Form() { Controls = { trackModelGui }, TopLevel = true, AutoSize = true, Parent = null, Text="Terminal Velocity - Track Model"};
            trainModelForm = new Form() { Controls = { trainGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Trains" };

            //TODO
            /*
             * Train Controller Form(s)
             * Train Model Form
            */

            ctcForm.Shown += new EventHandler(ctcForm_Shown);

            Application.Run(ctcForm);
        }
        public CTCGUITest()
        {
            //using all testing classes the ctc office (created a new instance of ctc)

            //create environment instance
            _env = new SimulationEnvironment.SimulationEnvironment();

            //create testing track model
            _trackMod = new TestingTrackModel(_env);

            //creating testing track controllers
            _red   = new TestingTrackController(0, _trackMod, _env, true);
            _green = new TestingTrackController(1, _trackMod, _env, true);

            //hook to environment
            _env.PrimaryTrackControllerRed   = _red;
            _env.PrimaryTrackControllerGreen = _green;
            _env.TrackModel = _trackMod;

            //creating office instance
            _ctc = new CTCOffice.CTCOffice(_env, _red, _green);

            _env.CTCOffice        = _ctc;
            _ctc.StartAutomation += new EventHandler <EventArgs>(_ctc_StartAutomation);
            _ctc.StopAutomation  += new EventHandler <EventArgs>(_ctc_StopAutomation);

            //making Request Panel Objects (For red and green)
            _redRequest   = new RequestFrame("Red", _red);
            _greenRequest = new RequestFrame("Green", _green);

            //creating office gui
            _ctcGui = new CTCOfficeGUI(_env, _ctc);
            _ctcGui.ShowSchedule += new EventHandler <EventArgs>(_ctcGui_ShowSchedule);


            var MyTestingControls = new TestingControls(_trackMod);

            //creating testing gui
            _control = new OfficeGUITest(
                _ctcGui,
                _redRequest,
                _greenRequest,
                MyTestingControls
                );

            _env.StartTick();

            Form f = new Form();

            f.AutoSize = true;
            f.Text     = "CTC Office Standalone GUI Test";
            f.Controls.Add(_control);
            f.Show();
        }
Пример #6
0
        public CTCGUITest()
        {
            //using all testing classes the ctc office (created a new instance of ctc)

            //create environment instance
            _env = new SimulationEnvironment.SimulationEnvironment();

            //create testing track model
            _trackMod = new TestingTrackModel(_env);

            //creating testing track controllers
            _red = new TestingTrackController(0,_trackMod,_env, true);
            _green = new TestingTrackController(1,_trackMod,_env, true);

            //hook to environment
            _env.PrimaryTrackControllerRed = _red;
            _env.PrimaryTrackControllerGreen = _green;
            _env.TrackModel = _trackMod;

            //creating office instance
            _ctc = new CTCOffice.CTCOffice(_env, _red, _green);

            _env.CTCOffice = _ctc;
            _ctc.StartAutomation += new EventHandler<EventArgs>(_ctc_StartAutomation);
            _ctc.StopAutomation += new EventHandler<EventArgs>(_ctc_StopAutomation);

            //making Request Panel Objects (For red and green)
            _redRequest = new RequestFrame("Red", _red);
            _greenRequest = new RequestFrame("Green", _green);

            //creating office gui
            _ctcGui = new CTCOfficeGUI(_env, _ctc);
            _ctcGui.ShowSchedule += new EventHandler<EventArgs>(_ctcGui_ShowSchedule);

            var MyTestingControls = new TestingControls(_trackMod);
            //creating testing gui
            _control = new OfficeGUITest(
                _ctcGui,
                _redRequest,
                _greenRequest,
                MyTestingControls
                );

            _env.StartTick();

            Form f = new Form();
            f.AutoSize = true;
            f.Text = "CTC Office Standalone GUI Test";
            f.Controls.Add(_control);
            f.Show();
        }
        public RoutingTool(CTCOfficeGUI ctcgui, CTCOffice ctc, ISimulationEnvironment env, IBlock sBlock, bool mode)
        {
            InitializeComponent();

            //mode = true for dispatch, mode = flase for update
            _btnPoint.Enabled = !mode;

            _ctc        = ctc;
            _ctcGui     = ctcgui;
            _env        = env;
            _startBlock = sBlock;

            _ctcGui.RoutingToolResponse += _ctcGui_RoutingToolResponse;

            _endBlock = null;
        }
Пример #8
0
        public RoutingTool(CTCOfficeGUI ctcgui, CTCOffice ctc, ISimulationEnvironment env, IBlock sBlock, bool mode)
        {
            InitializeComponent();

            //mode = true for dispatch, mode = flase for update
            _btnPoint.Enabled = !mode;

            _ctc = ctc;
            _ctcGui = ctcgui;
            _env = env;
            _startBlock = sBlock;

            _ctcGui.RoutingToolResponse += _ctcGui_RoutingToolResponse;

            _endBlock = null;
        }
Пример #9
0
        public bool DoTest(out int pass, out int fail, out List <string> message)
        {
            //local
            pass    = 0;
            fail    = 0;
            message = new List <string>();

            //global for events
            _pass    = 0;
            _fail    = 0;
            _message = new List <string>();

            redRequests = new bool[7] {
                false, false, false, false, false, false, false
            };
            greenRequests = new bool[7] {
                false, false, false, false, false, false, false
            };


            //create environment instance
            _env = new SimulationEnvironment.SimulationEnvironment();

            //create testing track model
            _trackMod = new TestingTrackModel(_env);

            //creating testing track controllers
            _red   = new TestingTrackController(0, _trackMod, _env, false);
            _green = new TestingTrackController(1, _trackMod, _env, false);

            //hook to environment
            _env.PrimaryTrackControllerRed   = _red;
            _red.TransferRequest            += new EventHandler <EventArgs>(_red_TransferRequest);
            _env.PrimaryTrackControllerGreen = _green;
            _green.TransferRequest          += new EventHandler <EventArgs>(_green_TransferRequest);
            _env.TrackModel = _trackMod;

            //creating office instance
            _ctc = new CTCOffice.CTCOffice(_env, _red, _green);
            if (_ctc != null)
            {
                pass++;
                message.Add("CTC Object Secessfully Created");
            }
            else
            {
                fail++;
                message.Add("CTC Object Not Secessfully Created");
            }

            _env.CTCOffice        = _ctc;
            _ctc.StartAutomation += new EventHandler <EventArgs>(_ctc_StartAutomation);
            _ctc.StopAutomation  += new EventHandler <EventArgs>(_ctc_StopAutomation);
            _ctc.LoadData        += new EventHandler <EventArgs>(_ctc_LoadData);
            _ctc.MessagesReady   += new EventHandler <EventArgs>(_ctc_MessagesReady);
            _ctc.UnlockLogin     += new EventHandler <EventArgs>(_ctc_UnlockLogin);
            _ctc.UpdatedData     += new EventHandler <EventArgs>(_ctc_UpdatedData);
            _env.StartTick();

            _trackMod.ThrowTrackChanged();



            if (_env.CTCOffice != null)
            {
                pass++;
                message.Add("CTC Office Added to Environment");

                #region Login Testing
                //Test Improper Login
                if (!_ctc.Login("me", "42"))
                {
                    pass++;
                    message.Add("PASS: Operator has invalid credentials");
                }
                else
                {
                    fail--;
                    message.Add("FAIL: Operator has invlaid credentials");
                }

                //Test Operator Auth (invalid creds)
                if (!_ctc.IsAuth())
                {
                    pass++;
                    message.Add("PASS: Op Auth (Lockout)");
                }
                else
                {
                    fail++;
                    message.Add("FAIL: Op Auth (Lockout)");
                }

                //Test Proper Login
                if (_ctc.Login("root", "admin"))
                {
                    pass++;
                    message.Add("PASS: Operator Login");
                }
                else
                {
                    fail--;
                    message.Add("FAIL: Operator Login");
                }

                //Test Operator Auth (invalid creds)
                if (_ctc.IsAuth())
                {
                    pass++;
                    message.Add("PASS: Op Auth");
                }
                else
                {
                    fail++;
                    message.Add("FAIL: Op Auth");
                }

                //Logout
                //Always returns true
                pass++;
                message.Add("PASS: Logout (always true)");

                #endregion

                //Populate Track -> void function.. always passes unit test
                pass++;
                message.Add("PASS: PopulateTrack() (always true unless exception is generated)");

                //call for start scheduling
                _ctc.StartScheduling();
                _ctc.StopScheduling();

                #region Test Get Line
                if (_ctc.GetLine(0) != null)
                {
                    pass++;
                    message.Add("PASS: GetLine(0) -> Red.");
                }
                else
                {
                    fail++;
                    message.Add("Fail: GetLine(0) -> Red.");
                }

                if (_ctc.GetLine(1) != null)
                {
                    pass++;
                    message.Add("PASS: GetLine(1) -> Green.");
                }
                else
                {
                    fail++;
                    message.Add("Fail: GetLine(1) -> Green.");
                }

                if (_ctc.GetLine(2) == null)
                {
                    pass++;
                    message.Add("PASS: GetLine(2) -> null.");
                }
                else
                {
                    fail++;
                    message.Add("Fail: GetLine(0) -> null.");
                }
                #endregion

                //Cannot test private functions (including Line ID functions)

                //RequestTypes.AssignTrainRoute
                //RequestTypes.SetTrainAuthority
                //RequestTypes.SetTrainOOS
                //RequestTypes.SetTrainSpeed
                ////RequestTypes.TrackControllerData
                //RequestTypes.TrackMaintenanceClose
                //RequestTypes.TrackMaintenanceOpen

                TestingBlock redBlock   = new TestingBlock("Red", 0, 0, 0, null, true, false, false, false, false, false, StateEnum.Healthy);
                TestingBlock greenBlock = new TestingBlock("Green", 0, 0, 0, null, true, false, false, false, false, false, StateEnum.Healthy);

                _ctc.assignTrainRouteRequest(1, 0, null, redBlock);
                _ctc.setTrainAuthorityRequest(1, 0, 50, redBlock);
                _ctc.setTrainOutOfServiceRequest(1, 0, redBlock);
                _ctc.setTrainSpeedRequest(1, 0, 50, redBlock);
                _ctc.closeTrackBlockRequest(0, redBlock);
                _ctc.openTrackBlockRequest(0, redBlock);

                _ctc.assignTrainRouteRequest(1, 1, null, greenBlock);
                _ctc.setTrainAuthorityRequest(1, 1, 50, greenBlock);
                _ctc.setTrainOutOfServiceRequest(1, 1, greenBlock);
                _ctc.setTrainSpeedRequest(1, 1, 50, greenBlock);
                _ctc.closeTrackBlockRequest(1, greenBlock);
                _ctc.openTrackBlockRequest(1, greenBlock);

                //dispatch train handled in GUI Tester

                //cannot test handleResponse.  No actual case to test
            }
            else
            {
                fail++;
                message.Add("CTC Office Not Added to Environment");
            }



            //add event handler tests
            pass = pass + _pass;
            fail = fail + _fail;
            message.AddRange(_message);
            return(true);
        }
Пример #10
0
        private static Form GuiTestFramework(int test)
        {
            ////////////////////////////////////////////////////////////////////////////////////////
            //                              Initializations                                       //
            ////////////////////////////////////////////////////////////////////////////////////////

            // Environment object
            var environment = new SimulationEnvironment.SimulationEnvironment();

            IBlock b0 = new TrackModel.Block(1, StateEnum.Healthy, 0, 0, 0, new[] {0, 0}, 10, DirEnum.East, new[] {""}, 0, 0, 0, "Red",70);
            IBlock b1 = new TrackModel.Block(2, StateEnum.Healthy, 1, 0, 0, new[] {1, 1}, 10, DirEnum.East, new[] {""}, 0, 0, 0, "Red",70);
            IBlock b2 = new TrackModel.Block(3, StateEnum.Healthy, 2, 0, 0, new[] {2, 2}, 10, DirEnum.East, new[] {""}, 0, 0, 0, "Red",70);
            IBlock b3 = new TrackModel.Block(4, StateEnum.BrokenTrackFailure, 3, 0, 0, new[] {3, 3}, 10, DirEnum.East, new[] {""}, 0, 0, 0, "Red",70);

            var sectionA = new List<IBlock> {b0};
            var sectionB = new List<IBlock> {b1, b2};
            var sectionC = new List<IBlock> {b3};

            // Previous track controller's circuit
            var prevCircuit = new TrackCircuit(environment, sectionA);
            // Our track circuit
            var currCircuit = new TrackCircuit(environment, sectionB);
            // Next track controller's circuit
            var nextCircuit = new TrackCircuit(environment, sectionC);

            var prev = new TrackController.TrackController(environment, prevCircuit);
            var curr = new TrackController.TrackController(environment, currCircuit);
            var next = new TrackController.TrackController(environment, nextCircuit);

            //Create TrackModel
            var trackMod = new TrackModel.TrackModel(environment);
            //Let TrackModel read in the lines before you proceed..shouldnt be done this way, but needed to stop CTC Office from faulting
            bool res = trackMod.provideInputFile("red.csv");
            //Console.WriteLine("Res was "+res);
            res = trackMod.provideInputFile("green.csv");
            //Console.WriteLine("Res was " + res);

            environment.TrackModel = trackMod;
            prev.Previous = null;
            prev.Next = curr;

            curr.Previous = prev;
            curr.Next = next;

            next.Previous = curr;
            next.Next = null;

            // Assign the same track controller to both lines
            var office = new CTCOffice.CTCOffice(environment, prev, prev);

            environment.CTCOffice = office;
            environment.PrimaryTrackControllerGreen = prev;
            environment.PrimaryTrackControllerRed = prev;

            ////////////////////////////////////////////////////////////////////////////////////////
            //                            End Initializations                                     //
            ////////////////////////////////////////////////////////////////////////////////////////

            var form = new Form();
            var control = new UserControl();
            switch (test)
            {
                case 0: // SystemScheduler

                    var testSystemScheduler = new SystemScheduler.SystemScheduler(environment, office);
                    control = new SystemSchedulerGUI(environment, testSystemScheduler, office);
                    environment.StartTick();
                    break;
                case 1: // CTCOffice
                    environment = null;

                    b0 = null;
                    b1 = null;
                    b2 = null;
                    b3 = null;

                    sectionA = null;
                    sectionB = null;
                    sectionC = null;

                    prevCircuit = null;
                    currCircuit = null;
                    nextCircuit = null;

                    prev = null;
                    curr = null;
                    next = null;

                    trackMod = null;
                    office = null;

                    new CTCGUITest();
                    break;
                case 2: // TrackModel
                    control = new TrackModelGUI(environment, trackMod);
                    break;
                case 3: // TrackController
                    ITrainModel t = new Train(0, b0, environment);

                    environment.AllTrains.Add(t);

                    prevCircuit.Trains.Add(0, t);

                    control = new TrackControllerUi(environment, environment.PrimaryTrackControllerRed);
                    break;
                case 4: // TrainModel
                    var loc = new int[2];
                    loc[0] = 10;
                    loc[1] = 10;
                    var start = new Block(0, StateEnum.Healthy, 0, 0, -0.02, loc, 100, DirEnum.East, null, 1, 2, 0, "Red",70);
                    environment.AddTrain(new Train(0, start, environment));
                    environment.AddTrain(new Train(1, start, environment));

                    var train0 = (Train)environment.AllTrains[0];
                    train0.ChangeMovement(200);

                    control = new TrainGUI(environment);

                    break;
                case 5: // TrainController
                    var loc2 = new int[2];
                    loc2[0] = 10;
                    loc2[1] = 10;
                    var start2 = new Block(0, StateEnum.Healthy, 0, 0, 0, loc2, 100, DirEnum.East, null, 1, 2, 0, "Red",70);
                    var tc = new TrainController.TrainController(environment, new Train(0, start2, environment));
                    control = new TrainControllerUI(tc, environment);
                    break;
            }

            if (environment != null)
            {
                environment.StartTick();
            }

            if (form != null)
            {
                form.Controls.Add(control);
                form.AutoSize = true;
            }
            else
            {
                return null;
            }

            return form;
        }
Пример #11
0
        public CTCOfficeGUI(ISimulationEnvironment env, CTCOffice ctc)
        {
            InitializeComponent();
            //set refs to ctc office and environment
            _ctcOffice = ctc;
            _environment = env;
            _speedState = 0;

            _res = _ctcOffice.Resource;

            _ctcOffice.LoadData += new EventHandler<EventArgs>(_ctcOffice_LoadData);
            _ctcOffice.UnlockLogin += new EventHandler<EventArgs>(_ctcOffice_UnlockLogin);
            _ctcOffice.MessagesReady += new EventHandler<EventArgs>(_ctcOffice_MessagesReady);
            _ctcOffice.UpdatedData += new EventHandler<EventArgs>(_ctcOffice_UpdatedData);
            _loginState = false;

            _btnLoginLogout.Enabled = _loginState;
            _txtPassword.Enabled = _loginState;
            _txtUsername.Enabled = _loginState;

            _rate = 100;
            _tickCount = 0;

            //init routing vars
            _routeTool = null;
            _inRoutingPoint = false;
            _routingToolOpen = false;
            _routeToolMode = RoutingMode.Dispatch;

            _lastRightClickContainer = null;

            _keyForm = null;
            _keyOpen = false;

            //subscribe to Environment Tick
            _environment.Tick += _environment_Tick;

            //ensure the user is logged out
            _ctcOffice.Logout();
            //change button text
            _btnLoginLogout.Text = "Login";

            //show team logo (block out user)
            MainDisplayLogo();
            DisableUserControls();
            _loginStatusImage.Image = _res.RedLight;
            _imageTeamLogo.Image = Properties.Resources.TerminalVelocity;

            UpdateMetrics();
            RefreshStatus();

            //populate red line and green line panel
            //parseLineData();

            //enables double buffering for control drawings
            //this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);

            //post to log that the gui has loaded
            _environment.SendLogEntry("CTCOffice: GUI Loaded");

            _tt = null;
        }
Пример #12
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Environment
            env = new SimulationEnvironment.SimulationEnvironment();

            // TrackModel
            TrackModel.TrackModel trackModel = new TrackModel.TrackModel(env);
            env.TrackModel = trackModel;
            TrackModel.TrackModelGUI trackModelGui = new TrackModelGUI(env, trackModel);

            // CTCOffice
            CTCOffice.CTCOffice ctcOffice = new CTCOffice.CTCOffice(env, env.PrimaryTrackControllerRed, env.PrimaryTrackControllerGreen);
            env.CTCOffice = ctcOffice;
            CTCOffice.CTCOfficeGUI ctcOfficeGui = new CTCOfficeGUI(env, ctcOffice);
            ctcOfficeGui.ShowTrain    += new EventHandler <ShowTrainEventArgs>(ctcOfficeGui_ShowTrain);
            ctcOfficeGui.ShowSchedule += new EventHandler <EventArgs>(ctcOfficeGui_ShowSchedule);


            // Scheduler
            SystemScheduler.SystemScheduler scheduler = new SystemScheduler.SystemScheduler(env, ctcOffice);
            env.SystemScheduler = scheduler;
            SystemScheduler.SystemSchedulerGUI schedulerGui = new SystemScheduler.SystemSchedulerGUI(env, scheduler, ctcOffice);

            // train model form
            TrainModel.TrainGUI trainGui = new TrainGUI(env);

            // Track Controllers
            if (env.PrimaryTrackControllerRed != null)
            {
                TrackController.TrackController red = (TrackController.TrackController)env.PrimaryTrackControllerRed;
                TrackControllerUi redTcGui          = new TrackControllerUi(env, red);
                trackControllerRedForm = new Form()
                {
                    Controls = { redTcGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Track Controller Red"
                };
            }

            if (env.PrimaryTrackControllerGreen != null)
            {
                TrackController.TrackController green = (TrackController.TrackController)env.PrimaryTrackControllerGreen;
                TrackControllerUi greenTcGui          = new TrackControllerUi(env, green);
                trackControllerGreenForm = new Form()
                {
                    Controls = { greenTcGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Track Controller Green"
                };
            }

            ctcForm = new Form()
            {
                Controls = { ctcOfficeGui }, AutoSize = true, Text = "Terminal Velocity - CTC Office"
            };
            schedulerForm = new Form()
            {
                Controls = { schedulerGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - System Scheduler"
            };
            trackModelForm = new Form()
            {
                Controls = { trackModelGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Track Model"
            };
            trainModelForm = new Form()
            {
                Controls = { trainGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Trains"
            };


            //TODO

            /*
             * Train Controller Form(s)
             * Train Model Form
             */

            ctcForm.Shown += new EventHandler(ctcForm_Shown);

            Application.Run(ctcForm);
        }
        public void createCTCOffice()
        {
            // Assign the same track controller to both lines
            _office = new CTCOffice.CTCOffice(_env, _prev, _prev);

            _env.CTCOffice = _office;
        }
Пример #14
0
        private static Form GuiTestFramework(int test)
        {
            ////////////////////////////////////////////////////////////////////////////////////////
            //                              Initializations                                       //
            ////////////////////////////////////////////////////////////////////////////////////////


            // Environment object
            var environment = new SimulationEnvironment.SimulationEnvironment();

            IBlock b0 = new TrackModel.Block(1, StateEnum.Healthy, 0, 0, 0, new[] { 0, 0 }, 10, DirEnum.East, new[] { "" }, 0, 0, 0, "Red", 70);
            IBlock b1 = new TrackModel.Block(2, StateEnum.Healthy, 1, 0, 0, new[] { 1, 1 }, 10, DirEnum.East, new[] { "" }, 0, 0, 0, "Red", 70);
            IBlock b2 = new TrackModel.Block(3, StateEnum.Healthy, 2, 0, 0, new[] { 2, 2 }, 10, DirEnum.East, new[] { "" }, 0, 0, 0, "Red", 70);
            IBlock b3 = new TrackModel.Block(4, StateEnum.BrokenTrackFailure, 3, 0, 0, new[] { 3, 3 }, 10, DirEnum.East, new[] { "" }, 0, 0, 0, "Red", 70);

            var sectionA = new List <IBlock> {
                b0
            };
            var sectionB = new List <IBlock> {
                b1, b2
            };
            var sectionC = new List <IBlock> {
                b3
            };

            // Previous track controller's circuit
            var prevCircuit = new TrackCircuit(environment, sectionA);
            // Our track circuit
            var currCircuit = new TrackCircuit(environment, sectionB);
            // Next track controller's circuit
            var nextCircuit = new TrackCircuit(environment, sectionC);

            var prev = new TrackController.TrackController(environment, prevCircuit);
            var curr = new TrackController.TrackController(environment, currCircuit);
            var next = new TrackController.TrackController(environment, nextCircuit);

            //Create TrackModel
            var trackMod = new TrackModel.TrackModel(environment);
            //Let TrackModel read in the lines before you proceed..shouldnt be done this way, but needed to stop CTC Office from faulting
            bool res = trackMod.provideInputFile("red.csv");

            //Console.WriteLine("Res was "+res);
            res = trackMod.provideInputFile("green.csv");
            //Console.WriteLine("Res was " + res);


            environment.TrackModel = trackMod;
            prev.Previous          = null;
            prev.Next = curr;

            curr.Previous = prev;
            curr.Next     = next;

            next.Previous = curr;
            next.Next     = null;

            // Assign the same track controller to both lines
            var office = new CTCOffice.CTCOffice(environment, prev, prev);

            environment.CTCOffice = office;
            environment.PrimaryTrackControllerGreen = prev;
            environment.PrimaryTrackControllerRed   = prev;


            ////////////////////////////////////////////////////////////////////////////////////////
            //                            End Initializations                                     //
            ////////////////////////////////////////////////////////////////////////////////////////

            var form    = new Form();
            var control = new UserControl();

            switch (test)
            {
            case 0:     // SystemScheduler

                var testSystemScheduler = new SystemScheduler.SystemScheduler(environment, office);
                control = new SystemSchedulerGUI(environment, testSystemScheduler, office);
                environment.StartTick();
                break;

            case 1:     // CTCOffice
                environment = null;

                b0 = null;
                b1 = null;
                b2 = null;
                b3 = null;

                sectionA = null;
                sectionB = null;
                sectionC = null;

                prevCircuit = null;
                currCircuit = null;
                nextCircuit = null;

                prev = null;
                curr = null;
                next = null;

                trackMod = null;
                office   = null;

                new CTCGUITest();
                break;

            case 2:     // TrackModel
                control = new TrackModelGUI(environment, trackMod);
                break;

            case 3:     // TrackController
                ITrainModel t = new Train(0, b0, environment);

                environment.AllTrains.Add(t);

                prevCircuit.Trains.Add(0, t);

                control = new TrackControllerUi(environment, environment.PrimaryTrackControllerRed);
                break;

            case 4:     // TrainModel
                var loc = new int[2];
                loc[0] = 10;
                loc[1] = 10;
                var start = new Block(0, StateEnum.Healthy, 0, 0, -0.02, loc, 100, DirEnum.East, null, 1, 2, 0, "Red", 70);
                environment.AddTrain(new Train(0, start, environment));
                environment.AddTrain(new Train(1, start, environment));

                var train0 = (Train)environment.AllTrains[0];
                train0.ChangeMovement(200);

                control = new TrainGUI(environment);

                break;

            case 5:     // TrainController
                var loc2 = new int[2];
                loc2[0] = 10;
                loc2[1] = 10;
                var start2 = new Block(0, StateEnum.Healthy, 0, 0, 0, loc2, 100, DirEnum.East, null, 1, 2, 0, "Red", 70);
                var tc     = new TrainController.TrainController(environment, new Train(0, start2, environment));
                control = new TrainControllerUI(tc, environment);
                break;
            }

            if (environment != null)
            {
                environment.StartTick();
            }

            if (form != null)
            {
                form.Controls.Add(control);
                form.AutoSize = true;
            }
            else
            {
                return(null);
            }


            return(form);
        }
Пример #15
0
        public CTCOfficeGUI(ISimulationEnvironment env, CTCOffice ctc)
        {
            InitializeComponent();
            //set refs to ctc office and environment
            _ctcOffice   = ctc;
            _environment = env;
            _speedState  = 0;

            _res = _ctcOffice.Resource;

            _ctcOffice.LoadData      += new EventHandler <EventArgs>(_ctcOffice_LoadData);
            _ctcOffice.UnlockLogin   += new EventHandler <EventArgs>(_ctcOffice_UnlockLogin);
            _ctcOffice.MessagesReady += new EventHandler <EventArgs>(_ctcOffice_MessagesReady);
            _ctcOffice.UpdatedData   += new EventHandler <EventArgs>(_ctcOffice_UpdatedData);
            _loginState = false;

            _btnLoginLogout.Enabled = _loginState;
            _txtPassword.Enabled    = _loginState;
            _txtUsername.Enabled    = _loginState;

            _rate      = 100;
            _tickCount = 0;

            //init routing vars
            _routeTool       = null;
            _inRoutingPoint  = false;
            _routingToolOpen = false;
            _routeToolMode   = RoutingMode.Dispatch;

            _lastRightClickContainer = null;

            _keyForm = null;
            _keyOpen = false;

            //subscribe to Environment Tick
            _environment.Tick += _environment_Tick;

            //ensure the user is logged out
            _ctcOffice.Logout();
            //change button text
            _btnLoginLogout.Text = "Login";


            //show team logo (block out user)
            MainDisplayLogo();
            DisableUserControls();
            _loginStatusImage.Image = _res.RedLight;
            _imageTeamLogo.Image    = Properties.Resources.TerminalVelocity;

            UpdateMetrics();
            RefreshStatus();

            //populate red line and green line panel
            //parseLineData();

            //enables double buffering for control drawings
            //this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);

            //post to log that the gui has loaded
            _environment.SendLogEntry("CTCOffice: GUI Loaded");

            _tt = null;
        }
        public bool DoTest(out int pass, out int fail, out List<string> message)
        {
            //local
            pass = 0;
            fail = 0;
            message = new List<string>();

            //global for events
            _pass = 0;
            _fail = 0;
            _message = new List<string>();

            redRequests = new bool[7] { false, false, false, false, false, false, false };
            greenRequests = new bool[7] { false, false, false, false, false, false, false };

            //create environment instance
            _env = new SimulationEnvironment.SimulationEnvironment();

            //create testing track model
            _trackMod = new TestingTrackModel(_env);

            //creating testing track controllers
            _red = new TestingTrackController(0, _trackMod, _env, false);
            _green = new TestingTrackController(1, _trackMod, _env, false);

            //hook to environment
            _env.PrimaryTrackControllerRed = _red;
            _red.TransferRequest += new EventHandler<EventArgs>(_red_TransferRequest);
            _env.PrimaryTrackControllerGreen = _green;
            _green.TransferRequest += new EventHandler<EventArgs>(_green_TransferRequest);
            _env.TrackModel = _trackMod;

            //creating office instance
            _ctc = new CTCOffice.CTCOffice(_env, _red, _green);
            if (_ctc != null)
            {
                pass++;
                message.Add("CTC Object Secessfully Created");
            }
            else
            {
                fail++;
                message.Add("CTC Object Not Secessfully Created");
            }

            _env.CTCOffice = _ctc;
            _ctc.StartAutomation += new EventHandler<EventArgs>(_ctc_StartAutomation);
            _ctc.StopAutomation += new EventHandler<EventArgs>(_ctc_StopAutomation);
            _ctc.LoadData += new EventHandler<EventArgs>(_ctc_LoadData);
            _ctc.MessagesReady += new EventHandler<EventArgs>(_ctc_MessagesReady);
            _ctc.UnlockLogin += new EventHandler<EventArgs>(_ctc_UnlockLogin);
            _ctc.UpdatedData += new EventHandler<EventArgs>(_ctc_UpdatedData);
            _env.StartTick();

            _trackMod.ThrowTrackChanged();

            if (_env.CTCOffice != null)
            {
                pass++;
                message.Add("CTC Office Added to Environment");

                #region Login Testing
                //Test Improper Login
                if (!_ctc.Login("me", "42"))
                {
                    pass++;
                    message.Add("PASS: Operator has invalid credentials");
                }
                else
                {
                    fail--;
                    message.Add("FAIL: Operator has invlaid credentials");
                }

                //Test Operator Auth (invalid creds)
                if (!_ctc.IsAuth())
                {
                    pass++;
                    message.Add("PASS: Op Auth (Lockout)");
                }
                else
                {
                    fail++;
                    message.Add("FAIL: Op Auth (Lockout)");
                }

                //Test Proper Login
                if (_ctc.Login("root", "admin"))
                {
                    pass++;
                    message.Add("PASS: Operator Login");
                }
                else
                {
                    fail--;
                    message.Add("FAIL: Operator Login");
                }

                //Test Operator Auth (invalid creds)
                if (_ctc.IsAuth())
                {
                    pass++;
                    message.Add("PASS: Op Auth");
                }
                else
                {
                    fail++;
                    message.Add("FAIL: Op Auth");
                }

                //Logout
                //Always returns true
                pass++;
                message.Add("PASS: Logout (always true)");

                #endregion

                //Populate Track -> void function.. always passes unit test
                pass++;
                message.Add("PASS: PopulateTrack() (always true unless exception is generated)");

                //call for start scheduling
                _ctc.StartScheduling();
                _ctc.StopScheduling();

                #region Test Get Line
                if (_ctc.GetLine(0) != null)
                {
                    pass++;
                    message.Add("PASS: GetLine(0) -> Red.");
                }
                else
                {
                    fail++;
                    message.Add("Fail: GetLine(0) -> Red.");
                }

                if (_ctc.GetLine(1) != null)
                {
                    pass++;
                    message.Add("PASS: GetLine(1) -> Green.");
                }
                else
                {
                    fail++;
                    message.Add("Fail: GetLine(1) -> Green.");
                }

                if (_ctc.GetLine(2) == null)
                {
                    pass++;
                    message.Add("PASS: GetLine(2) -> null.");
                }
                else
                {
                    fail++;
                    message.Add("Fail: GetLine(0) -> null.");
                }
                #endregion

                //Cannot test private functions (including Line ID functions)

                //RequestTypes.AssignTrainRoute
                //RequestTypes.SetTrainAuthority
                //RequestTypes.SetTrainOOS
                //RequestTypes.SetTrainSpeed
                ////RequestTypes.TrackControllerData
                //RequestTypes.TrackMaintenanceClose
                //RequestTypes.TrackMaintenanceOpen

                TestingBlock redBlock = new TestingBlock("Red", 0, 0, 0, null, true, false, false, false, false, false, StateEnum.Healthy);
                TestingBlock greenBlock = new TestingBlock("Green", 0, 0, 0, null, true, false, false, false, false, false, StateEnum.Healthy);

                _ctc.assignTrainRouteRequest(1, 0, null, redBlock);
                _ctc.setTrainAuthorityRequest(1, 0, 50, redBlock);
                _ctc.setTrainOutOfServiceRequest(1, 0, redBlock);
                _ctc.setTrainSpeedRequest(1, 0, 50, redBlock);
                _ctc.closeTrackBlockRequest(0, redBlock);
                _ctc.openTrackBlockRequest(0, redBlock);

                _ctc.assignTrainRouteRequest(1, 1, null, greenBlock);
                _ctc.setTrainAuthorityRequest(1, 1, 50, greenBlock);
                _ctc.setTrainOutOfServiceRequest(1, 1, greenBlock);
                _ctc.setTrainSpeedRequest(1, 1, 50, greenBlock);
                _ctc.closeTrackBlockRequest(1, greenBlock);
                _ctc.openTrackBlockRequest(1, greenBlock);

                //dispatch train handled in GUI Tester

                //cannot test handleResponse.  No actual case to test
            }
            else
            {
                fail++;
                message.Add("CTC Office Not Added to Environment");
            }

            //add event handler tests
            pass = pass + _pass;
            fail = fail + _fail;
            message.AddRange(_message);
            return true;
        }