Пример #1
0
        /// <summary>
        /// A public method used for creating valid insert statements on the database.  This method was
        /// deprecated early on, and should not be used.  The DBCreator class should instead by used for
        /// inserting into the database.
        /// </summary>
        /// <param name="b">The block to be inserted into the database</param>
        /// <returns>A SQL insert statement stored as a string</returns>
        public String createInsert(Block b)
        {
            //Looking back, im not sure why I thought I needed this method.
            //DB insertion should be done entirely through the DBCreator and not through the DBManager

            //I will hold off on implementing this method until I'm certain I need to
            return null;
        }
Пример #2
0
 /// <summary>
 /// A public constructor allowing the TrackModel or other modules to create RouteInfo objects.
 /// Though external moduels are allowed to create RouteInfo objects, the objects arent of any 
 /// inherent use, as the object is unreflected in the underlying database.
 /// </summary>
 /// <param name="rID">The route/line ID..0 or 1</param>
 /// <param name="rName">The route/line name: "Red" or "Green"</param>
 /// <param name="nBlocks">The number of different blocks in the line</param>
 /// <param name="blocks">An array of blocks in the line</param>
 /// <param name="sID">The ID of the first block in the line</param>
 /// <param name="eID">The ID of the final block in the line </param>
 public RouteInfo(int rID, string rName, int nBlocks, Block[] blocks, int sID, int eID)
 {
     _routeID = rID;
     _routeName = rName;
     _numBlocks = nBlocks;
     _blockList = blocks;
     _startBlockID = sID;
     _endBlockID = eID;
 }
Пример #3
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;
        }
Пример #4
0
        /// <summary>
        /// A public method, most notably called by the TrackModel, that parses the input file and
        /// requests inserts into the database.
        /// </summary>
        /// <param name="fPath">The path to the file to be parsed</param>
        /// <returns>An integer flag: 0 for success, -3 for a null database, -1 for an invalid path, 
        /// -2 for a file format error</returns>
        public int parseInputFile(string fPath)
        {
            //If our constructor failed, return an error code please
            if (_dbCon == null)
            {
                return -3;
            }

            if (fPath == null)
            {
                //Console.WriteLine("Input fPath was null");
                return -1;
            }

            //Check that file exists
            if (!File.Exists(fPath))
            {
                //Console.WriteLine("File apparently doesnt exist");
                return -1;
            }

            //Check the file format
            if (!fPath.EndsWith(".csv"))
            {
                return -2;
            }

            //Read all information from file into an array of lines
            string[] fileLines = File.ReadAllLines(fPath);

            //Set up character delimiter
            var commaArr = new char[1];
            commaArr[0] = ',';

            //Console.WriteLine("About to enter forloop");
            ////////////////////////////////////////////////////////
            //Iterate through each one.

            List<IBlock>[] trackConBlockLists=new List<IBlock>[16];
            for (int i = 0; i < trackConBlockLists.Length; i++)
            {
                trackConBlockLists[i] = new List<IBlock>();
            }
            bool redLine = false;
            foreach (string line in fileLines)
            {

                //Console.WriteLine("Line is: "+line);
                //IF we're not a blank line (begins with comma) or a header line (begins with Line)
                //THEN process and insert
                if (!line.StartsWith(",") && !line.StartsWith("Line") && !line.StartsWith(" "))
                {
                    //Delimit around comma's
                    string[] fields = line.Split(commaArr);
                    string blockID = fields[2];
                    string lineName = fields[0];

                    //Set flag for which line you're on
                    if(redLine==false && lineName.Equals("Red",StringComparison.OrdinalIgnoreCase))
                        redLine=true;

                    string speedLimit = fields[5];
                    int trackConID=int.Parse(fields[10]);
                    int prev = int.Parse(fields[11]);
                    int d1 = int.Parse(fields[12]);
                    int d2 = int.Parse(fields[13]);
                    string dirString = fields[14];
                    //Once we get our line name, we should check if it's already in the database.
                    //If its already in the database, then we can assume success and just return 0
                    //Maybe this should just be some sort of continue, but I can sort that out later
                    if (blockExists(int.Parse(blockID), lineName))
                    {
                        return 0;
                    }

                    string infra;
                    if (fields[6].Equals("", StringComparison.OrdinalIgnoreCase))
                    {
                        infra = "none";
                    }
                    else
                    {
                        infra = fields[6];
                    }
                    string sElev = fields[9];
                    string grade = fields[4];
                    string blockSize = fields[3];
                    string singleInsert =
                        "INSERT INTO BLOCKS(blockID, line, infra, starting_elev, grade, bSize,dir,state,trackCirID,locX,locY,speedLimit,prev,dest1,dest2) VALUES(" +blockID + ", '" + lineName + "', '" + infra + "', " + sElev + ", " + grade + ", " + blockSize +",'"+dirString+"', 'Healthy',"+trackConID+",-1,-1, "+speedLimit+","+prev+","+d1+","+d2+")";
                    //Console.WriteLine(singleInsert);
                    if (_dbCon.State != ConnectionState.Open)
                        _dbCon.Open();
                    var insertCommand = new SQLiteCommand(singleInsert);
                    insertCommand.Connection = _dbCon;

                    try
                    {
                        int res = insertCommand.ExecuteNonQuery(); //Exec CREATE
                        //Console.WriteLine(res);
                        //if (_dbCon.State != ConnectionState.Closed)
                            //_dbCon.Close(); //CLOSE DB

                        //Prepare values to create block
                        char[] splitArr = new char[1];
                        splitArr[0] = ';';
                        string[] tempAtts = infra.Split(splitArr);
                        int[] locArray = new int[2];
                        locArray[0] = -1; locArray[1] = -1;

                        //Create block and add to the list of blocks for temp
                        IBlock temp = new Block(int.Parse(blockID), StateEnum.Healthy, prev, double.Parse(sElev), double.Parse(grade),locArray, double.Parse(blockSize), (DirEnum)Enum.Parse(typeof(DirEnum),dirString), tempAtts, d1, d2, trackConID, lineName, int.Parse(speedLimit));
                        trackConBlockLists[trackConID].Add(temp);

                        if (res != 1)
                        {
                            //Console.WriteLine("Database insert failed");
                            return -1;
                        }
                    }
                    catch (Exception crap)
                    {
                        //if (_dbCon.State != ConnectionState.Closed)
                          //  _dbCon.Close();
                        //Console.WriteLine(crap.Message.ToString());
                        return -1;
                    }
                } //End if statement for valid data line
            }
            //End for loop iterating through all strings
            ///////////////////////////////////////////////////

            //Now that all blocks in our line are inserted, and the block lists for each TrackController have been assembled...
            //We can create the Track Circuits and Track Controllers.
            bool tempRes=populateTCs(trackConBlockLists,redLine);

            return 0; //If you get to this point, you've executed successfully.
        }
        public void createTrackController()
        {
            IBlock b0 = new Block(0, StateEnum.Healthy, -1, 0, 0, new[] {0, 0}, 1000, DirEnum.East, new[] {""}, 0, 0, 0,
                                  "Green",70);
            IBlock b1 = new Block(1, StateEnum.Healthy, 0, 0, 0, new[] {1, 1}, 1000, DirEnum.East, new[] {""}, 0, 0, 0,
                                  "Green",70);
            IBlock b2 = new Block(2, StateEnum.Healthy, 1, 0, 0, new[] {2, 2}, 1000, DirEnum.East, new[] {""}, 0, 0, 0,
                                  "Green",70);
            IBlock b3 = new Block(3, StateEnum.BrokenTrackFailure, 2, 0, 0, new[] {3, 3}, 1000, DirEnum.East, new[] {""},
                                  0, 0, 0, "Green",70);

            var sectionA = new List<IBlock>();
            sectionA.Add(b0);
            var sectionB = new List<IBlock>();
            sectionB.Add(b1);
            sectionB.Add(b2);
            var sectionC = new List<IBlock>();
            sectionC.Add(b3);

            // Track Controller
            _currCircuit = new TrackCircuit(_env, sectionA);
            // Next track controller's circuit
            _nextCircuit = new TrackCircuit(_env, sectionB);
            // Previous track controller's circuit
            _prevCircuit = new TrackCircuit(_env, sectionC);

            _prev = new TrackController.TrackController(_env, _prevCircuit);
            _curr = new TrackController.TrackController(_env, _currCircuit);
            _next = new TrackController.TrackController(_env, _nextCircuit);

            _prev.Previous = null;
            _prev.Next = _curr;

            _curr.Previous = _prev;
            _curr.Next = _next;

            _next.Previous = _curr;
            _next.Next = null;

            _env.PrimaryTrackControllerGreen = _prev;
            _env.PrimaryTrackControllerRed = _prev;
        }
        private bool TestMovement_PositiveGrade(List<string> messages)
        {
            bool result = true;

            Block oldStart = startBlock;
            startBlock = new Block(0, StateEnum.Healthy, 0, 0, 0.01, new[] { 0, 0 }, 100000, DirEnum.East, new[] { "" }, 0, 0, 0, "Red", 70);
            blocks[0] = startBlock;
            Train train = new Train(0, startBlock, _environment);

            train.ChangeMovement(200);
            train.updateMovement(); // should be less than 0.5

            if (train.CurrentAcceleration >= 0.5) // error
            {
                string error = train.ToString() + " did not lose any acceleration due to slope.";
                messages.Add(error);
                result = false;
            }

            // reset
            blocks[0] = oldStart;
            startBlock = oldStart;

            return result;
        }
        private bool TestMovement_NegativeGrade(List<string> messages)
        {
            bool result = true;

            Block oldStart = startBlock;
            startBlock = new Block(0, StateEnum.Healthy, 0, 0, -0.01, new[] { 0, 0 }, 100000, DirEnum.East, new[] { "" }, 0, 0, 0, "Red", 70);
            blocks[0] = startBlock;
            Train train = new Train(1, startBlock, _environment);

            train.ChangeMovement(200);

            // allow 10 iterations of update movement
            for (int i = 0; i < 8; i++)
            {
                train.updateMovement();
            }

            train.EmergencyBrake();
            train.updateMovement(); // should be greater than -2.73

            if (train.CurrentAcceleration == -2.73) // error
            {
                string error = train.ToString() + " did not gain any acceleration due to slope.";
                messages.Add(error);
                result = false;
            }

            // reset
            blocks[0] = oldStart;
            startBlock = oldStart;

            return result;
        }
        public bool DoTest(out int pass, out int fail, out List<string> message)
        {
            pass = 0;
            fail = 0;
            message = new List<string>();

            _environment = new SimulationEnvironment.SimulationEnvironment();

            // Create 100 blocks for the red line
            blocks = new List<IBlock>();

            // First block
            startBlock = new Block(0, StateEnum.Healthy, 99, 0, 0, new[] { 0, 0 }, BlockLengh, DirEnum.East, new[] { "" }, 2, 0, 0, "Red", 100);
            blocks.Add(startBlock);

            // Next 99 blocks
            for (var i = 1; i < 99; i++)
                blocks.Add(new Block(i, StateEnum.Healthy, i - 1, 0, 0, new[] { 0, 0 }, BlockLengh, DirEnum.East, new[] { "" }, i + 1, 0, 0, "Red", 100));

            // Last block
            blocks.Add(new Block(99, StateEnum.Healthy, 98, 0, 0, new[] { 0, 0 }, BlockLengh, DirEnum.East, new[] { "" }, 0, 0, 0, "Red", 100));

            _environment.TrackModel = new DummyTrackModel(blocks);

            // mass test
            if (TestMass(message))
                pass++;
            else
                fail++;

            // adding passengers test
            if (TestAddPassengers(message))
                pass++;
            else
                fail++;

            // removing passengers test
            if (TestRemovePassengers(message))
                pass++;
            else
                fail++;

            // lights test
            if (TestLights(message))
                pass++;
            else
                fail++;

            // doors test
            if (TestDoors(message))
                pass++;
            else
                fail++;

            // changing temperature test
            if (TestTemperature(message))
                pass++;
            else
                fail++;

            // test emergency brake
            if (TestEmergencyBrake(message))
                pass++;
            else
                fail++;

            // test movement without grade
            if (TestMovement_NoGrade(message))
                pass++;
            else
                fail++;

            // test movement with positive grade
            if (TestMovement_PositiveGrade(message))
                pass++;
            else
                fail++;

            // test movement with negative grade
            if (TestMovement_NegativeGrade(message))
                pass++;
            else
                fail++;

            // test braking during brake failure
            if (TestBrakeFailureMovement(message))
                pass++;
            else
                fail++;

            // test acceleration during engine failure
            if (TestEngineFailureMovement(message))
                pass++;
            else
                fail++;

            return true;
        }
Пример #9
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);
        }
Пример #10
0
        //Argument to this function shouldbe changed
        //into the SQLResults object returned from
        //runQuery() above
        /// <summary>
        /// A public method allowing the track model and other modules to format 
        /// database query results into coherent Block objects
        /// </summary>
        /// <param name="bR">The SQLiteDataReader containing the results of the query</param>
        /// <returns>A valid Block object, or null in the case of an error</returns>
        public Block formatBlockQueryResults(SQLiteDataReader bR)
        {
            Block tempBlock = null;
            int i = 0;
            if (!bR.IsClosed)
            {
                while (bR.Read())
                {
                    //Get all fields for a given block
                    string line = null, infra = null, dir = null;
                    string state = null;

                    int bIDFinal = -1, locXFinal = -1, locYFinal = -1;
                    double sEFinal = -1.0, gradeFinal = -1.0, bSizeFinal = -1.0;
                    int prevFinal = -1, dest1Final = -1, dest2Final = -1;
                    int trackCirIDFinal = -1;
                    int speedLimitFinal = -1;
                    try
                    {
                        bIDFinal = bR.GetInt32(bR.GetOrdinal("blockID"));
                        line = bR.GetString(bR.GetOrdinal("line"));
                        infra = bR.GetString(bR.GetOrdinal("infra"));
                        dir = bR.GetString(bR.GetOrdinal("dir"));
                        state = bR.GetString(bR.GetOrdinal("state"));
                        if (bIDFinal != 0)
                        {
                            sEFinal = bR.GetDouble(bR.GetOrdinal("starting_elev"));
                            gradeFinal = bR.GetDouble(bR.GetOrdinal("grade"));
                            locXFinal = bR.GetInt32(bR.GetOrdinal("locX"));
                            locYFinal = bR.GetInt32(bR.GetOrdinal("locY"));
                            bSizeFinal = bR.GetDouble(bR.GetOrdinal("bSize"));
                            prevFinal = bR.GetInt32(bR.GetOrdinal("prev"));
                            dest1Final = bR.GetInt32(bR.GetOrdinal("dest1"));
                            dest2Final = bR.GetInt32(bR.GetOrdinal("dest2"));
                            trackCirIDFinal = bR.GetInt32(bR.GetOrdinal("trackCirID"));
                            speedLimitFinal = bR.GetInt32(bR.GetOrdinal("speedLimit"));
                        }
                    }
                    catch (Exception e)
                    {
                        //Console.WriteLine("Exception was raised");
                    }
                    //////////////////////////////////////////////////////////////////////
                    //Parse fields that must be provided as a different type
                    string[] infraFinal = infra.Split(';');
                    var dirFinal = (DirEnum) Enum.Parse(typeof (DirEnum), dir, true);
                    var stateFinal = (StateEnum) Enum.Parse(typeof (StateEnum), state, true);

                    var locFinal = new int[2];
                    locFinal[0] = locXFinal;
                    locFinal[1] = locYFinal;

                    tempBlock = new Block(bIDFinal, stateFinal, prevFinal, sEFinal, gradeFinal, locFinal, bSizeFinal,
                                          dirFinal, infraFinal, dest1Final, dest2Final, trackCirIDFinal, line,speedLimitFinal);
                    i++; //Inc counter
                }
            }
            else
            {
                //Console.WriteLine("Reader was closed, this was a mistake.");
            }

            if (i != 1)
                return null;
            else
                return tempBlock;
        }