Exemple #1
0
        /// <summary>
        /// Updates Green Line
        /// </summary>
        private void UpdateGreen()
        {
            _updateTrackMutex.WaitOne();
            //request blocks in green line
            IRouteInfo rtnfo = _env.TrackModel.requestRouteInfo(1);

            foreach (IBlock b in rtnfo.BlockList)
            {
                //find block in layout and change image
                LayoutCellDataContainer c = _greenLineData.TriangulateContainer(b);
                if (c != null)
                {
                    c.Tile = _greenLineData.GetBlockType(b);
                    if (c.Panel != null)
                    {
                        string msg = "Red Line: Block ID: " + c.Block.BlockID + " is now " + c.Block.State.ToString();
                        _messages.Add(msg);
                        _env.SendLogEntry("CTC Office: " + msg);
                        c.Panel.ReDrawMe();
                    }
                }
            }
            rtnfo = null;
            _updateTrackMutex.ReleaseMutex();
        }
Exemple #2
0
        }     //end track changed

        /// <summary>
        /// Updates Red Line
        /// </summary>
        private void UpdateRed()
        {
            _updateTrackMutex.WaitOne();
            //request blocks in red line
            IRouteInfo rtnfo = _env.TrackModel.requestRouteInfo(0);

            foreach (IBlock b in rtnfo.BlockList)
            {
                //find block in layout and change image
                //speed limit of 500 is unique to block id 0 (yard) on both red and green line
                if (b.SpeedLimit != 500)
                {
                    LayoutCellDataContainer c = _redLineData.TriangulateContainer(b);
                    if (c != null)
                    {
                        c.Tile = _redLineData.GetBlockType(b);
                        if (c.Panel != null)
                        {
                            string msg = "Red Line: Block ID: " + c.Block.BlockID + " is now " + c.Block.State.ToString();
                            _messages.Add(msg);
                            _env.SendLogEntry("CTC Office: " + msg);
                            c.Panel.ReDrawMe();
                        }
                    }
                }
            }
            rtnfo = null;
            _updateTrackMutex.ReleaseMutex();
        }
        private List <IBlock>[] createBlockListArray(int lineID)
        {
            List <IBlock>[] blockList = new List <IBlock> [16];
            for (int i = 0; i < blockList.Length; i++)
            {
                blockList[i] = new List <IBlock>();
            }

            IRouteInfo temp = this.requestRouteInfo(lineID);

            IBlock[] blockArr = temp.BlockList;
            for (int i = 0; i < blockArr.Length; i++)
            {
                if (blockArr[i].BlockID != 0)    //Dont add 0 block to Track Controllers responsibility
                {
                    try
                    {
                        blockList[blockArr[i].TrackCirID].Add(blockArr[i]);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }
            }
            return(blockList);
        }
        /// <summary>
        /// A public method allowing outside modules to request info pertaining to a track line.
        /// </summary>
        /// <param name="routeID">The route ID should be 0 for the Red line, or 1 for the Green line</param>
        /// <returns>an IRouteInfo object containing information pertaining to the Line/Route requested, or null if an error occurred</returns>
        public IRouteInfo requestRouteInfo(int routeID)
        {
            if (routeID != 0 && routeID != 1)
            {
                return(null);
            }
            string routeQuery = _dbManager.createQueryString("ROUTE", routeID, null);

            //Check query return val
            if (routeQuery == null)
            {
                return(null);
            }

            //Get data reader from query
            SQLiteDataReader queryReader = _dbManager.runQuery(routeQuery);

            //Check data reader return val
            if (queryReader == null)
            {
                return(null);
            }

            IRouteInfo temp = _dbManager.formatRouteQueryResults(queryReader);

            return(temp);
        }
 /// <summary>
 ///     create route objuct for Green Route
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void _btnGreen_Click(object sender, EventArgs e)
 {
     if (SubmitRoute != null)
     {
         IRouteInfo routeInfo = _env.TrackModel.requestRouteInfo(1);
         IBlock     endBlock  = _env.TrackModel.requestBlockInfo(routeInfo.EndBlock, routeInfo.RouteName);
         IRoute     r         = new Route(RouteTypes.DefinedRoute, endBlock, routeInfo.RouteID, routeInfo.BlockList.ToList());
         SubmitRoute(this, new RoutingToolEventArgs(r, null));
     }
 }
Exemple #6
0
        /// <summary>
        ///  Requests Data from each Track Controller
        /// </summary>
        private void AddAutomaticUpdate()
        {
            ITrackModel tm = _env.TrackModel;

            if (tm != null)
            {
                IRouteInfo redInfo = tm.requestRouteInfo(0);
                foreach (IBlock b in redInfo.BlockList)
                {
                    trackControllerDataRequest(b.TrackCirID);
                }

                IRouteInfo greenInfo = tm.requestRouteInfo(1);
                foreach (IBlock b in greenInfo.BlockList)
                {
                    trackControllerDataRequest(b.TrackCirID);
                }
            }
        }//End AddAutomaticUpdate
        public bool DoTest(out int pass, out int fail, out List <string> message)
        {
            pass    = 0;
            fail    = 0;
            message = new List <string>();

            ISimulationEnvironment environment = new SimulationEnvironment.SimulationEnvironment();
            var tm = new TrackModel.TrackModel(environment);

            /////////////////////////////////
            //Test 1
            //Check that RedLoaded is initially false
            if (tm.RedLoaded == false)
            {
                pass++;
                message.Add("Pass: RedLoaded is initially false");
            }
            else
            {
                fail++;
                message.Add("Fail: RedLoaded was not initially false, as it should be prior to loading RedLine");
            }
            //End test 1
            /////////////////////////////////


            /////////////////////////////////
            //Test 2
            //Check that GreenLoaded is initially false
            if (tm.GreenLoaded == false)
            {
                pass++;
                message.Add("Pass: GreenLoaded is initially false, as desired");
            }
            else
            {
                fail++;
                message.Add("Fail: GreenLoaded was not initially false, as it should be prior to loading GreenLine");
            }
            /////////////////////////////////


            /////////////////////////////////
            //Test 3
            //provideInputFile returns false when given bad input file
            bool resBool = tm.provideInputFile("asdfawecxwe");/** Gee, Really hope this file doesnt exist*/

            if (resBool == false)
            {
                pass++;
                message.Add("Pass: provideInputFile returns false when given bad file");
            }
            else
            {
                fail++;
                message.Add("Fail: provideInputFile didn't return false when given an invalid filename");
            }
            //End Test 3
            /////////////////////////////////


            /////////////////////////////////
            //Test 4
            //provideInputFile should return false when given a null argument
            resBool = tm.provideInputFile(null);
            if (resBool == false)
            {
                pass++;
                message.Add("Pass: provideInputFile returns false when given a null argument");
            }
            else
            {
                fail++;
                message.Add("Fail: provideInputFile should return false when given a null argument");
            }
            //End Test 4
            /////////////////////////////////


            /////////////////////////////////
            //Test 5
            //provideInputFile should return false when given a non-csv file
            resBool = tm.provideInputFile(@"..\..\red.bad");//An existent but non csv file
            if (resBool == false)
            {
                pass++;
                message.Add("Pass: provideInputFile returns false when given a non-csv file");
            }
            else
            {
                fail++;
                message.Add("Fail: provideInputFile did not return false when given a non-csv file as expected");
            }
            //End Test 5
            /////////////////////////////////


            /////////////////////////////////
            //Test 6
            //provideInputFile should return true when given a valid file
            resBool = tm.provideInputFile(@"..\..\red.csv");
            if (resBool == true)
            {
                pass++;
                message.Add("Pass: provideInputFile returned true when given a valid, existing, and properly formatted file (red.csv)");
            }
            else
            {
                fail++;
                message.Add("Pass: provideInputFile returned false when given a valid and proper file, expected val was true (red.csv)");
            }
            //End Test 6
            /////////////////////////////////


            /////////////////////////////////
            //Test 7
            //provideInputFile should return true when given a valid file
            resBool = tm.provideInputFile(@"..\..\green.csv");
            if (resBool == true)
            {
                pass++;
                message.Add("Pass: provideInputFile returned true when given a valid, existing, and properly formatted file (green.csv)");
            }
            else
            {
                fail++;
                message.Add("Pass: provideInputFile returned false when given a valid and proper file, expected val was true (green.csv)");
            }
            //End Test 7
            /////////////////////////////////


            /////////////////////////////////
            //Test 8
            //Check that RedLoaded property returns true after loading
            if (tm.RedLoaded)
            {
                pass++;
                message.Add("Pass: the RedLoaded Property shows that the red line has now been loaded");
            }
            else
            {
                fail++;
                message.Add("Fail: the RedLoaded Property does not show that the red line has been loaded");
            }
            //End Test 8
            /////////////////////////////////


            /////////////////////////////////
            //Test 9
            if (tm.GreenLoaded)
            {
                pass++;
                message.Add("Pass: The GreenLoaded Property shows that the green line has now been loaded");
            }
            else
            {
                fail++;
                message.Add("Fail: The GreenLoaded Property does not show that the green line has been loaded");
            }
            //End Test 9
            /////////////////////////////////


            /////////////////////////////////
            //Test 10
            //requestBlockInfo should return null when given a negative block number
            IBlock tempIBlock = tm.requestBlockInfo(-1, "Red");

            if (tempIBlock == null)
            {
                pass++;
                message.Add("Pass: requestBlockInfo returned null when given a negative blockID");
            }
            else
            {
                fail++;
                message.Add("Fail: requestBlockInfo returned a valid block when given negative blockID, expected val was null");
            }
            //End Test 10
            /////////////////////////////////


            /////////////////////////////////
            //Test 11
            //requestBlockInfo should return null when given a blockID=0
            tempIBlock = tm.requestBlockInfo(0, "Red");
            if (tempIBlock != null)
            {
                pass++;
                message.Add("Pass: requestBlockInfo was able to retrieve the 0 block of a line");
            }
            else
            {
                fail++;
                message.Add("Fail: requestBlockInfo returned null when given blockID=0, expected val was valid block");
            }
            //End Test 11
            /////////////////////////////////


            /////////////////////////////////
            //Test 12
            //requestBlockInfo should return null when asked to retrieve an out-of-range block id
            tempIBlock = tm.requestBlockInfo(19191, "Red");
            if (tempIBlock == null)
            {
                pass++;
                message.Add("Pass: requestBlockInfo returned null as expected when given an out of range block ID");
            }
            else
            {
                fail++;
                message.Add("Fail: requestBlockInfo did not return null when given an out of range blockID, expected val was null");
            }
            //End Test 12
            /////////////////////////////////


            /////////////////////////////////
            //Test 13
            //requestBlockInfo should return null when given a bad line string
            tempIBlock = tm.requestBlockInfo(0, "asdf");
            if (tempIBlock == null)
            {
                pass++;
                message.Add("Pass: requestBlockInfo returned null when given an invalid line string");
            }
            else
            {
                fail++;
                message.Add("Fail: requestBlockInfo did not return null when given an invalid line string");
            }
            //End Test 13
            /////////////////////////////////


            /////////////////////////////////
            //Test 14
            //requestBlockInfo should return a valid block when asked to retrieve a basic block (without extra infrastructure)
            tempIBlock = tm.requestBlockInfo(1, "Red");
            if (tempIBlock != null)
            {
                pass++;
                message.Add("Pass: requestBlockInfo successfully returned a basic block without extra infrastructure");
            }
            else
            {
                fail++;
                message.Add("Fail: requestBlockInfo returned null when asked to retrieve a basic block without extra infrastructure");
            }
            //End Test 14
            /////////////////////////////////


            /////////////////////////////////
            //Test 15
            //requestBlockInfo should return a valid block when asked to retrieve a more complex block (containing infrastructure such as switch, heater, etc).
            tempIBlock = tm.requestBlockInfo(27, "Red");
            if (tempIBlock != null)
            {
                pass++;
                message.Add("Pass: requestBlockInfo successfully returned a complex block (with additional infra)");
            }
            else
            {
                fail++;
                message.Add("Fail: requestBlockInfo returns null when asked for a more complex block (with additional infra)");
            }
            //End Test 15
            /////////////////////////////////


            /////////////////////////////////
            //Test 16
            //requestUpdateBlock returns false when provided with a null value
            resBool = tm.requestUpdateBlock(null);
            if (resBool == false)
            {
                pass++;
                message.Add("Pass: requestUpdateBlock returns false when given a null value");
            }
            else
            {
                fail++;
                message.Add("Fail: requestUpdateBlock returns true when given a null value, expected value is false");
            }
            //End Test 16
            /////////////////////////////////



            /////////////////////////////////
            //Test 17
            //requestUpdateBlock returns false when provided with a block w/ ID=0 (no updating the yard)
            tempIBlock = tm.requestBlockInfo(0, "Red");
            resBool    = tm.requestUpdateBlock(tempIBlock);
            if (resBool == false)
            {
                pass++;
                message.Add("Pass: requestUpdateBlock returned false when attempting to update 0 block (yard)");
            }
            else
            {
                fail++;
                message.Add("Fail: requestUpdateBlock returned true when attempting to update 0 block (yard), expected value was false");
            }
            //End Test 17
            /////////////////////////////////


            /////////////////////////////////
            //Test 18
            //requestBlockUpdate should allow change of Health State
            tempIBlock = tm.requestBlockInfo(1, "Red");

            //Store old state, and assign new state in a way that ensures oldState and newState are different
            var oldState = tempIBlock.State;

            if (oldState != StateEnum.CircuitFailure)
            {
                tempIBlock.State = StateEnum.CircuitFailure;
            }
            else
            {
                tempIBlock.State = StateEnum.BrokenTrackFailure;
            }

            //Update the block
            resBool = tm.requestUpdateBlock(tempIBlock);
            //Re-request info from database
            tempIBlock = tm.requestBlockInfo(1, "Red");
            if (resBool && tempIBlock.State != oldState)
            {
                pass++;
            }
            else if (!resBool && tempIBlock.State == oldState)
            {
                fail++;
                message.Add("Fail: requestUpdateBlock returnd a false value, when given a changed state, expected val was true");
            }
            else
            {
                fail++;
                message.Add("Fail: requestUpdateBlock returned true, but failed to update the database");
            }
            //End Test 18
            /////////////////////////////////


            /////////////////////////////////
            //Test 19
            //requestUpdateBlock should allow updating of heater state

            //////////////////////////////////
            //THIS NEEDS IMPLEMENTED STILL
            //No blocks in the init file contain heaters by default
            //Should I assume that every block has a heater?
            //I prob want to write a method in the BLOCK object that lets you turn the heater on and off
            //
            //////////////////////////////////
            //End Test 19
            /////////////////////////////////


            /////////////////////////////////
            //Test 20
            //requestUpdateBlock should return true but fail to update swith when asked to update switch information in db
            tempIBlock = tm.requestBlockInfo(1, "Red");
            int oldSD1 = tempIBlock.SwitchDest1;

            tempIBlock.SwitchDest1 = tempIBlock.SwitchDest2;
            tempIBlock.SwitchDest2 = oldSD1;
            resBool    = tm.requestUpdateBlock(tempIBlock);
            tempIBlock = tm.requestBlockInfo(1, "Red");
            if (resBool == true && tempIBlock.SwitchDest1 == oldSD1)
            {
                pass++;
                message.Add("Pass: requestUpdateBlock did not update Switch state in database");
            }
            else
            {
                fail++;
                message.Add("Fail: either the returned boolean was false, or the data was updated in the db.");
            }
            //End Test 20
            /////////////////////////////////


            /////////////////////////////////
            //Test 21
            //requestRouteInfo should return a null value when given a negative route ID
            IRouteInfo tempIRouteInfo = tm.requestRouteInfo(-1);

            if (tempIRouteInfo == null)
            {
                pass++;
                message.Add("Pass: requestRouteInfo returns null when given a negative routeID");
            }
            else
            {
                fail++;
                message.Add("Fail: requestRouteInfo returned a Route when given a negative routeID, expected val was null");
            }
            //End Test 21
            /////////////////////////////////


            /////////////////////////////////
            //Test 22
            //requestRouteInfo should return a null value when given a line other than 0 or 1
            tempIRouteInfo = tm.requestRouteInfo(2);
            if (tempIRouteInfo == null)
            {
                pass++;
                message.Add("Pass: requestRouteInfo returns null when given an out of range routeID");
            }
            else
            {
                fail++;
                message.Add("Fail: requestRouteInfo returned a Route when given an out of range route ID, expected val was null");
            }
            //End Test 22
            /////////////////////////////////


            /////////////////////////////////
            //Test 23
            //requestRouteInfo returns a valid IRouteInfo object when given a line ID of 0 or 1
            tempIRouteInfo = tm.requestRouteInfo(0);
            if (tempIRouteInfo != null)
            {
                pass++;
                message.Add("Pass: requestRouteInfo returns valid IRouteInfo when given valid lineID");
            }
            else
            {
                fail++;
                message.Add("Fail: requestRouteInfo returns null when given valid lineID, expected val was null");
            }
            //End Test 23
            /////////////////////////////////


            /////////////////////////////////
            //Test 24
            //requestTrackGrid should return null when given an invalid line ID
            IBlock[,] tempIBlockArr = tm.requestTrackGrid(-1);
            if (tempIBlockArr == null)
            {
                pass++;
                message.Add("Pass: requestTrackGrid returns null when given invalid line ID");
            }
            else
            {
                fail++;
                message.Add("Fail: requestTrackGrid returns valid IBlock[,] when given invalid line id, expected value was null");
            }
            //End Test 24
            /////////////////////////////////


            /////////////////////////////////
            //Test 25
            //requestTrackGrid should return valid IBlock[,] when given valid line ID
            tempIBlockArr = tm.requestTrackGrid(0);
            if (tempIBlockArr != null)
            {
                pass++;
                message.Add("Pass: requestTrackGrid returns valid IBlock[,] when given valid line id");
            }
            else
            {
                fail++;
                message.Add("Fail: requestTrackGrid returns null when given valid line id, expected val was IBlock[,] object");
            }
            //End Test 25
            /////////////////////////////////


            /////////////////////////////////
            //Test 26
            //requestUpdateSwitch should return false when given a null Block value
            resBool = tm.requestUpdateSwitch(null);
            if (resBool == false)
            {
                pass++;
                message.Add("Pass: requestUpdateSwitch returns false when given a null parameter");
            }
            else
            {
                fail++;
                message.Add("Fail: requestUpdateSwitch returns true when given a null parameter, expected value was false");
            }
            //End Test 26
            /////////////////////////////////


            /////////////////////////////////
            //Test 27
            //requestUpdateSwitch should return false when given a block that doesnt contain a switch
            tempIBlock = tm.requestBlockInfo(1, "Red");
            resBool    = tm.requestUpdateSwitch(tempIBlock);
            if (resBool == false)
            {
                pass++;
                message.Add("Pass: requestUpdateSwitch returns false when given a block without a switch");
            }
            else
            {
                fail++;
                message.Add("Fail: requestUpdateSwitch returns true when given a block without a switch");
            }
            //End Test 27
            /////////////////////////////////


            /////////////////////////////////
            //Test 28
            //requestUpdateSwitch should return true when given a block that contains a switch. Actual DB update checked in next test
            tempIBlock = tm.requestBlockInfo(15, "Red");
            int oldDest1 = tempIBlock.SwitchDest1;

            tempIBlock.SwitchDest1 = tempIBlock.SwitchDest2;
            tempIBlock.SwitchDest2 = oldDest1;
            resBool = tm.requestUpdateSwitch(tempIBlock);

            tempIBlock = tm.requestBlockInfo(15, "Red");
            if (resBool == true)
            {
                if (tempIBlock.SwitchDest1 != oldDest1)
                {
                    pass++;
                    message.Add("Pass: requestUpdateSwitch returned true and updated the database when given valid block");
                }
                else
                {
                    fail++;
                    message.Add("Fail: requestUpdateSwitch returned true but failed to update database when given valid block");
                }
            }
            else
            {
                fail++;
                message.Add("Fail: requestUpdateSwitch returned false when given valid block");
            }

            //End Test 28
            /////////////////////////////////
            return(true);
        }