//*Constructors
        public EditNodes(string NetPath)
            : base(NetPath)
        {
            FileName = "nodes";

            using (StreamReader ReadFile = new StreamReader((NetPath + "\\" + FileName)))// open the paths file
            {
                try
                {
                    string   FileLine;
                    N_W_Node temp = new N_W_Node();
                    while ((FileLine = ReadFile.ReadLine()) != null)//read the file line by line
                    {
                        if (FileLine.Contains("node "))
                        {
                            string[] splitline  = FileLine.Split(new Char[] { ' ' });           // split the line up into an array of strings
                            string   NodeNum    = splitline[1];
                            string[] splitline2 = FileLine.Split(new Char[] { 't', 'm', ',' }); // split the line up into an array of strings
                            double   X          = Convert.ToDouble(splitline2[1]);
                            double   Y          = Convert.ToDouble(splitline2[3]);
                            double   Z          = Convert.ToDouble(splitline2[5]);
                            //temp = new N_W_Node(NodeNum,X,Y,Z);
                            NodeList.Add(new N_W_Node(NodeNum, X, Y, Z));
                        }
                    }
                }
                catch (Exception e)
                {
                    // Let the user know what went wrong.
                    Console.WriteLine("The pathroutes file could not be read:");
                    Console.WriteLine(e.Message);
                }
            }
        }
 //class constructor
 public ReadStatsGeneral(string NetworkName)
     : base(NetworkName)
 {
     AverageDelay = 0;
     DelayCount   = 0;
     using (StreamReader ReadFile = new StreamReader((LogDir + @"\stats-general.csv")))
     {
         try
         {
             string FileLine;
             string data = "";
             while ((FileLine = ReadFile.ReadLine()) != null)
             {
                 if (!FileLine.Contains("Day"))
                 {
                     data = FileLine;
                     DelayCount++;
                 }
             }
             string[] SplitLine = data.Split(',');
             AverageDelay = Convert.ToDouble(SplitLine[5]);
         }
         catch (Exception e)
         {
             // Let the user know what went wrong.
             Console.WriteLine("The events file could not be read:");
             Console.WriteLine(e.Message);
         }
     }
 }
Esempio n. 3
0
        public string LinkTurningFile = @"C:\Documents and Settings\Siemens\Desktop\Andrew's Work\Paramics Models\Sopers\SopersLaneApproachMovements.txt"; //This is the clockwise link order
        //public string LinkFile = @"C:\Documents and Settings\Siemens\Desktop\Andrew's Work\Paramics Models\Poole Junction\Paramics 2010.1 Version\Cabot Lane Poole V3\links";
        //public string PrioritiesFile = @"C:\Documents and Settings\Siemens\Desktop\Andrew's Work\Paramics Models\Poole Junction\Paramics 2010.1 Version\Cabot Lane Poole V3\priorities";
        //public string PrioritiesStages = @"C:\Documents and Settings\Siemens\Desktop\Andrew's Work\Paramics Models\Simple Crossroads\Simple Crossroads\priorities_file"; //This is the required stage


        /// <summary>
        /// This  returns the link number being turned onto. (i.e. moving from link 1 0 to link 0 3
        /// would return '3'.
        /// </summary>
        /// <returns></returns>
        public string NextLinkNumber(string ApproachNode, string JunctionNode, string TurningNumber)
        {
            string Returner             = "";
            string WithoutCommaReturner = "";

            using (StreamReader ReadFile = new StreamReader(LinkTurningFile))
            {
                string FileLine;
                while ((FileLine = ReadFile.ReadLine()) != null)
                {
                    if (FileLine.Contains("Link " + ApproachNode + " " + JunctionNode + ": "))
                    {
                        string[] SplitString = FileLine.Split(' ');
                        Returner             = SplitString[3 + Convert.ToInt16(TurningNumber)];
                        WithoutCommaReturner = Returner.Substring(0, Returner.Length - 1);
                        return(WithoutCommaReturner);
                        //break;
                    }
                }
            }

            /*using (StreamReader ReadFile = new StreamReader(LinkFile))
             * {
             *  string FileLine2;
             *  while ((FileLine2 = ReadFile.ReadLine()) != null)
             *  {
             *      if (FileLine2.Contains("link " + JunctionNode + " " + WithoutCommaReturner))
             *      {
             *          return WithoutCommaReturner;
             *      }
             *  }
             * }*/
            return("null");
        }
        public EditLink(String NetPath)
            : base(NetPath)
        {
            FileName = "links";

            using (StreamReader ReadFile = new StreamReader((NetPath + "\\" + FileName)))// open the paths file
            {
                try
                {
                    string FileLine;

                    while ((FileLine = ReadFile.ReadLine()) != null)//read the file line by line
                    {
                        if (FileLine.Contains("link ") && FileLine.Contains("category"))
                        {
                            string[] splitline = FileLine.Split(new Char[] { ' ' });// split the line up into an array of strings
                            string   StartNode = splitline[1];
                            string   EndNode   = splitline[2];
                            int      Cat       = Convert.ToInt32(splitline[4]);

                            LinkList.Add(new N_W_Link(StartNode, EndNode, Cat, false));//TODO un hardcode false to read oneway data from file
                        }
                    }
                }
                catch (Exception e)
                {
                    // Let the user know what went wrong.
                    Console.WriteLine("The pathroutes file could not be read:");
                    Console.WriteLine(e.Message);
                }
            }
        }
Esempio n. 5
0
        /*public string StageRequired(string ApproachNode, string NextLinkNumber)
         * {
         *  string Returner = "";
         *  using (StreamReader ReadFile = new StreamReader(PrioritiesStages))
         *  {
         *      string FileLine;
         *      while ((FileLine = ReadFile.ReadLine()) != null)
         *      {
         *          if (FileLine.Contains("link " + ApproachNode + " to " + NextLinkNumber + ": "))
         *          {
         *              string[] SplitString = FileLine.Split(' ');
         *              Returner = SplitString[4];
         *              return Returner;
         *          }
         *      }
         *  }
         *  return "null";
         * }*/

        /// <summary>
        /// This  returns the direction they are turning. (i.e. 'Left'.)
        /// </summary>
        /// <returns></returns>
        public string NextTurnDirection(string ApproachNode, string JunctionNode, string TurningNumber)
        {
            string Returner             = "";
            string WithoutCommaReturner = "";

            using (StreamReader ReadFile = new StreamReader(LinkTurningFile))
            {
                string FileLine;
                while ((FileLine = ReadFile.ReadLine()) != null)
                {
                    if (FileLine.Contains("Link " + ApproachNode + " " + JunctionNode + ": "))
                    {
                        string[] SplitString = FileLine.Split(' ');
                        if (SplitString[4] == "None,")
                        {
                            return("None");
                        }
                        if (SplitString[5] == "Left," || SplitString[5] == "Straight," || SplitString[5] == "Right,")
                        {
                            Returner             = SplitString[5 + Convert.ToInt16(TurningNumber)];
                            WithoutCommaReturner = Returner.Substring(0, Returner.Length - 1);
                            return(WithoutCommaReturner);
                        }
                        else
                        {
                            Returner             = SplitString[6 + Convert.ToInt16(TurningNumber)];
                            WithoutCommaReturner = Returner.Substring(0, Returner.Length - 1);
                            return(WithoutCommaReturner);
                        }
                    }
                }
            }
            return("null");
        }
        //*Constructor
        public EditPaths(string NetPath)
            : base(NetPath)
        {
            FileName = "paths";

            using (StreamReader ReadFile = new StreamReader((NetPath + "\\" + FileName)))// open the paths file
            {
                try
                {
                    string   FileLine;
                    N_W_Path temp = new N_W_Path();
                    LinkID   tLiD = new LinkID();
                    while ((FileLine = ReadFile.ReadLine()) != null)//read the file line by line
                    {
                        if (FileLine.Contains("number "))
                        {
                            temp = new N_W_Path();

                            string[] splitline = FileLine.Split(new Char[] { ' ' });// split the line up into an array of strings
                            //read the data from the file into the class object lists
                            int index = splitline.Length;
                            index--;
                            int num = Convert.ToInt32(splitline[index]);
                            temp.PathIDn = num;
                        }
                        if (FileLine.Contains("name "))
                        {
                            string[] splitline = FileLine.Split(new Char[] { '"' });// split the line up into an array of strings
                            temp.PathName = splitline[1];
                        }
                        if (FileLine.Contains("link "))
                        {
                            string[] splitline       = FileLine.Split(new Char[] { ':' });// split the line up into an array of strings
                            string[] splitsplitline1 = splitline[0].Split(new Char[] { ' ' });
                            string[] splitsplitline2 = splitline[1].Split(new Char[] { ' ' });
                            int      index1          = splitsplitline1.Length;
                            int      index2          = 0;
                            index1--;
                            string num1 = splitsplitline1[index1];
                            string num2 = splitsplitline2[index2];

                            tLiD = new LinkID(num1, num2);
                            temp.PathDescription.Add(tLiD);
                        }
                        if (FileLine.Contains(" end"))
                        {
                            PathList.Add(temp);
                        }
                    }
                }
                catch (Exception e)
                {
                    // Let the user know what went wrong.
                    Console.WriteLine("The pathroutes file could not be read:");
                    Console.WriteLine(e.Message);
                }
            }
        }
        //*Constructor
        public EditZones(string NetPath)
            : base(NetPath)
        {
            FileName = "zones";

            using (StreamReader ReadFile = new StreamReader((NetPath + "\\" + FileName)))// open the paths file
            {
                try
                {
                    string   FileLine;
                    N_W_Zone temp = new N_W_Zone();

                    while ((FileLine = ReadFile.ReadLine()) != null)//read the file line by line
                    {
                        if (FileLine.Contains("zone ") && !FileLine.Contains("Count"))
                        {
                            string[] splitline = FileLine.Split(new Char[] { ' ' });// split the line up into an array of strings
                            temp.ZoneNum = Convert.ToInt32(splitline[1]);
                        }
                        else if (FileLine.Contains("m ") && !FileLine.Contains("max") && !FileLine.Contains("min") && !FileLine.Contains("centroid"))
                        {
                            string[] splitline = FileLine.Split(new Char[] { ' ' });// split the line up into an array of strings
                            double[] corner    = new double[2] {
                                Convert.ToDouble(splitline[0]), Convert.ToDouble(splitline[2])
                            };
                            temp.Corners.Add(corner);
                        }
                        else if (FileLine.Contains("max"))
                        {
                            string[] splitline = FileLine.Split(new Char[] { ' ' });// split the line up into an array of strings
                            temp.Max = new double[2] {
                                Convert.ToDouble(splitline[1]), Convert.ToDouble(splitline[3])
                            };
                        }
                        else if (FileLine.Contains("min"))
                        {
                            string[] splitline = FileLine.Split(new Char[] { ' ' });// split the line up into an array of strings
                            temp.Min = new double[2] {
                                Convert.ToDouble(splitline[1]), Convert.ToDouble(splitline[3])
                            };
                        }
                        else if (FileLine.Contains("centroid"))
                        {
                            ZoneList.Add(temp);
                            temp = new N_W_Zone();
                        }
                    }
                }
                catch (Exception e)
                {
                    // Let the user know what went wrong.
                    Console.WriteLine("The pathroutes file could not be read:");
                    Console.WriteLine(e.Message);
                }
            }
        }
        //class constructor
        public ReadPointLoopFiles(string NetworkName, int ModelTimeofDay, int dT)
            : base(NetworkName)
        {
            string[] Paths     = Directory.GetFiles(LogDir, "point-*.csv");
            TimeSpan TS        = new TimeSpan(0, 0, ModelTimeofDay / 100);
            string   TimeOfDay = TS.ToString();

            foreach (string p in Paths)
            {
                FileInfo f         = new FileInfo(p);
                DateTime StartTime = new DateTime();
                DateTime EndTime   = new DateTime();

                StartTime = StartTime.AddSeconds(ModelTimeofDay / 100 - dT);
                EndTime   = EndTime.AddSeconds(ModelTimeofDay / 100);

                LoopRecord LoopData = new LoopRecord(StartTime, EndTime, f.Name);

                using (StreamReader ReadFile = new StreamReader(File.Open(p, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
                {
                    try
                    {
                        string FileLine;
                        while ((FileLine = ReadFile.ReadLine()) != null)
                        {
                            if (!FileLine.Contains("Day"))
                            {
                                string[] Fields    = FileLine.Split(',');
                                DateTime Detection = new DateTime();
                                DateTime Holder    = Convert.ToDateTime(Fields[1]);
                                Detection = Detection.Add(Holder.TimeOfDay);

                                int Comparitor1 = Detection.CompareTo(StartTime);
                                int Comparitor2 = Detection.CompareTo(EndTime);

                                if (Comparitor1 == 1)
                                {
                                    if (Comparitor2 <= 0)
                                    {
                                        LoopData.AddData(Detection, Convert.ToDouble(Fields[8]));
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        // Let the user know what went wrong.
                        Console.WriteLine("A point loop file could not be read:");
                        Console.WriteLine(e.Message);
                    }
                }
                LoopSensors.Add(LoopData);
            }
        }
        //costructor function
        private void ConstructorFunction()
        {
            using (StreamReader ReadFile = new StreamReader((LogDir + @"\vehicleroutes.csv")))
            {
                try
                {
                    string FileLine;
                    while ((FileLine = ReadFile.ReadLine()) != null)
                    {
                        if (!FileLine.Contains("Vehicle"))
                        {
                            string[] splitstring = FileLine.Split(new char[] { ',' });

                            FileData TempDat = new FileData();

                            TempDat.Tag          = Convert.ToInt32(splitstring[0]);
                            TempDat.Vtype        = Convert.ToInt32(splitstring[3]);
                            TempDat.Origin       = Convert.ToInt32(splitstring[1]);
                            TempDat.Destination  = Convert.ToInt32(splitstring[2]);
                            TempDat.NextLink     = "NULL2"; //have made it 512 as opposed to 511 to help notice a different problem if it arises
                            TempDat.NextNextLink = "NULL2";
                            TempDat.NextTurn     = "NULL2";
                            TempDat.NextNextTurn = "NULL2";


                            string[] splitsplitstring = splitstring[7].Split(new char[] { '"', ':' });
                            string   LinkStart        = splitsplitstring[1];
                            string   LinkEnd          = splitsplitstring[2];
                            TempDat.EnterLink = new LinkID(LinkStart, LinkEnd);
                            TempDat.EnterTime = DateTime.Parse(splitstring[8]);//change this to include date if relevant

                            Fdata.Add(TempDat);
                        }
                    }
                }
                catch (Exception e)
                {
                    // Let the user know what went wrong.
                    Console.WriteLine("The events file could not be read:");
                    Console.WriteLine(e.Message);
                }
            }
        }
Esempio n. 10
0
        }          // END private void DoCompile(Boolean pExecute)

        /// <summary>
        /// Select the C# file to execute as external,
        /// uncompiled code.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SelectFileButton_Click(object sender, EventArgs e)
        {
            GetCSDialog.InitialDirectory = Application.ExecutablePath;

            DialogResult UserChoice = GetCSDialog.ShowDialog(this);

            if (UserChoice == System.Windows.Forms.DialogResult.OK)
            {
                String CSFileName = GetCSDialog.FileName;

                String[] FileLines = File.ReadAllLines(CSFileName);

                // read the lines in, and replace tabs with 4 spaces so the
                // column numbers make more sense in the UI. A tab reads as 1 column
                // because it is 12 character in the textbox.
                StringBuilder SB = new StringBuilder();

                foreach (String FileLine in FileLines)
                {
                    String Line2Add = "";

                    if (FileLine.Contains("\t"))
                    {
                        Line2Add = FileLine.Replace("\t", "    ");
                    }
                    else
                    {
                        Line2Add = FileLine;
                    }

                    SB.AppendLine(Line2Add);
                }                // END foreach (String FileLine in FileLines)

                CSTextBox.Text = SB.ToString();

                SB.Clear();

                SB = null;
            }              // END if (UserChoice == System.Windows.Forms.DialogResult.OK)
        }
Esempio n. 11
0
        //constructor function
        private void ConstructorFunction()
        {
            using (StreamReader ReadFile = new StreamReader((LogDir + @"\events.csv")))
            {
                try
                {
                    string FileLine;
                    while ((FileLine = ReadFile.ReadLine()) != null)
                    {
                        if (!FileLine.Contains("Day"))
                        {
                            string[] splitstring = FileLine.Split(new char[] { ',' });
                            if ((Convert.ToInt32(splitstring[3])) == 23)
                            {
                                FileData TempDat = new FileData();
                                TempDat.Tag      = Convert.ToInt32(splitstring[9]);
                                TempDat.Vtype    = Convert.ToInt32(splitstring[4]);
                                TempDat.Lane     = Convert.ToInt32(splitstring[8]);
                                TempDat.Vspeed   = (Convert.ToDouble(splitstring[5])) * 0.44704;//convert speed to m/s
                                TempDat.LinkDist = Convert.ToDouble(splitstring[6]);

                                string[] splitsplitstring = splitstring[2].Split(new char[] { '"', ':' });
                                string   LinkStart        = splitsplitstring[1];
                                string   LinkEnd          = splitsplitstring[2];
                                TempDat.OnLink = new LinkID(LinkStart, LinkEnd);
                                TempDat.AtTime = DateTime.Parse(splitstring[1]);//change this to include date if relevant

                                Fdata.Add(TempDat);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    // Let the user know what went wrong.
                    Console.WriteLine("The events file could not be read:");
                    Console.WriteLine(e.Message);
                }
            }
        }
        public void SetStartTime(double StartTime)
        {
            string Contents = "";

            using (StreamReader ReadFile = new StreamReader((NetPath + "\\" + FileName)))// open the paths file
            {
                try
                {
                    string FileLine;
                    while ((FileLine = ReadFile.ReadLine()) != null)//read the file line by line
                    {
                        if (FileLine.Contains("start time "))
                        {
                            FileLine = "start time  " + StartTime.ToString() + ":00:00";
                        }
                        Contents += FileLine + '\n';
                    }
                }
                catch (Exception e)
                {
                    // Let the user know what went wrong.
                    Console.WriteLine("The configuration file could not be read:");
                    Console.WriteLine(e.Message);
                }
            }

            using (StreamWriter WriteFile = new StreamWriter((NetPath + "\\" + FileName))) // create a new text file to write to.
            {
                try
                {
                    WriteFile.Write(Contents);
                }
                catch (Exception e)
                {
                    // Let the user know what went wrong.
                    Console.WriteLine("There was a problem writing configuration file");
                    Console.WriteLine(e.Message);
                }
            }
        }
        //*Constructor
        public EditDetectors(string NetPath)
            : base(NetPath)
        {
            FileName = "detectors";

            using (StreamReader ReadFile = new StreamReader((NetPath + "\\" + FileName)))// open the paths file
            {
                try
                {
                    string   FileLine;
                    Detector temp = new Detector();
                    LinkID   tLiD = new LinkID();
                    while ((FileLine = ReadFile.ReadLine()) != null)//read the file line by line
                    {
                        if (!FileLine.Contains("Detector Count"))
                        {
                            string[] splitline = FileLine.Split(new Char[] { '"' });// split the line up into an array of strings
                            temp.Name = splitline[1];

                            string[] splitline2 = FileLine.Split(new Char[] { ' ' });// split the line up into an array of strings
                            temp.Type     = splitline2[0];
                            temp.LinkDist = Convert.ToDouble(splitline2[5]);
                            tLiD          = new LinkID(splitline2[9]);
                            temp.OnLink   = tLiD;
                            temp.Length   = Convert.ToDouble(splitline2[12]);
                            DetectorList.Add(temp);
                            temp = new Detector();
                        }
                    }
                }
                catch (Exception e)
                {
                    // Let the user know what went wrong.
                    Console.WriteLine("The detectors file could not be read:");
                    Console.WriteLine(e.Message);
                }
            }
        }
        //**Constructor
        public Editpathroutes(string NetPath)
            : base(NetPath)
        {
            FileName = "pathroutes";

            using (StreamReader ReadFile = new StreamReader(String.Concat(NetPath, "\\", FileName)))// open the pathroutes file
            {
                try
                {
                    string FileLine;
                    while ((FileLine = ReadFile.ReadLine()) != null)//read the file line by line
                    {
                        if (FileLine.Contains("Path "))
                        {
                            string[] splitline = FileLine.Split(new Char[] { ' ', '"' });// split the line up into an array of strings
                            //read the data from the file into the class object lists
                            RouteNames.Add(splitline[3]);
                            Profile.Add(Convert.ToInt32(splitline[6]));
                            Matrix.Add(Convert.ToInt32(splitline[8]));
                            Rate.Add(Convert.ToInt32(splitline[10]));
                        }
                    }
                }
                catch (Exception e)
                {
                    // Let the user know what went wrong.
                    Console.WriteLine("The pathroutes file could not be read:");
                    Console.WriteLine(e.Message);
                }
            }
            //Check to make sure that all the lists are the same length
            if (RouteNames.Count != Profile.Count || RouteNames.Count != Matrix.Count || RouteNames.Count != Rate.Count)
            {
                Console.WriteLine("Warning: The lists of data in PathRoutes are not all the same length");
            }
        }
Esempio n. 15
0
        //constructor function
        private void ConstructorFunction()
        {
            try
            {
                DirectoryInfo LogDirI  = new DirectoryInfo(LogDir);
                FileInfo[]    snaplist = LogDirI.GetFiles("snap*");
                DateTime      TimeNow  = new DateTime();
                DateTime      ZeroHour = DateTime.Parse("00:00:00");
                LinkID        LinkNow  = new LinkID();
                foreach (FileInfo snapfile in snaplist)
                {
                    using (StreamReader ReadFile = new StreamReader(snapfile.FullName))
                    {
                        string FileLine;
                        while ((FileLine = ReadFile.ReadLine()) != null)
                        {
                            if (FileLine.Contains("snapshot at time"))
                            {
                                string[] splitline = FileLine.Split(new char[] { ' ' });
                                double   TimeSecs  = Convert.ToDouble(splitline[3]);
                                TimeNow = ZeroHour.AddSeconds(TimeSecs);
                            }
                            else if (FileLine.Contains("on link"))
                            {
                                string[] splitline = FileLine.Split(new char[] { ' ', ':' });
                                LinkNow = new LinkID(splitline[2], splitline[3]);
                            }
                            else if (FileLine.Contains("type "))
                            {
                                FileData TempDat = new FileData();

                                if (FileLine.Contains("path"))
                                {
                                    string[] splitline = FileLine.Split(new char[] { ' ', '"' });
                                    TempDat.Vtype       = Convert.ToInt32(splitline[1]) + 1;
                                    TempDat.Origin      = Convert.ToInt32(splitline[15]) + 1;
                                    TempDat.Destination = Convert.ToInt32(splitline[16]) + 1;
                                    TempDat.Vspeed      = Convert.ToDouble(splitline[13]);
                                    TempDat.LinkDist    = Convert.ToDouble(splitline[8]);
                                    TempDat.RouteName   = splitline[6];
                                    TempDat.OnLink      = LinkNow;
                                    TempDat.AtTime      = TimeNow;
                                    double bornsecs = Convert.ToDouble(splitline[17]);
                                    TempDat.BornTime      = ZeroHour.AddSeconds(bornsecs);
                                    TempDat.MagicNumbers  = ("[" + splitline[10]);
                                    TempDat.MagicNumbers += ("," + splitline[20] + "]");//This needs to be checked


                                    Fdata.Add(TempDat);
                                }
                                else
                                {
                                    string[] splitline = FileLine.Split(new char[] { ' ' });
                                    TempDat.Vtype        = (Convert.ToInt32(splitline[1])) + 1;
                                    TempDat.Origin       = (Convert.ToInt32(splitline[10])) + 1;
                                    TempDat.Destination  = (Convert.ToInt32(splitline[11])) + 1;
                                    TempDat.Vspeed       = Convert.ToDouble(splitline[8]);
                                    TempDat.LinkDist     = Convert.ToDouble(splitline[3]);
                                    TempDat.NextLink     = splitline[13];
                                    TempDat.NextNextLink = splitline[14];
                                    TempDat.NextTurn     = "NULL3";
                                    TempDat.NextNextTurn = "NULL3";

                                    TempDat.OnLink = LinkNow;
                                    TempDat.AtTime = TimeNow;
                                    double bornsecs = Convert.ToDouble(splitline[12]);
                                    TempDat.BornTime      = ZeroHour.AddSeconds(bornsecs);
                                    TempDat.MagicNumbers  = ("[" + splitline[5]);
                                    TempDat.MagicNumbers += ("," + splitline[15] + "]");


                                    Fdata.Add(TempDat);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // Let the user know what went wrong.
                Console.WriteLine("Error reading snapfiles:");
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 16
0
        public static void Main(string[] args)
        {
            string ParentPath = Path.GetFullPath(Path.Combine(System.Reflection.Assembly.GetEntryAssembly().Location, @"../../../../../"));

            string[] BrowsableDirectories = { Path.Combine(ParentPath, "game",   "gameObjects"),
                                              Path.Combine(ParentPath, "engine", "Primitives") };


            string LoadUtilityDirectory = Path.Combine(ParentPath, "engine", "Utility");

            string IncludesFileName = "ReflectionIncludes.h";

            List <string> ClassNames         = new List <string>();
            List <string> HeaderFileIncludes = new List <string>();

            foreach (string Dir in BrowsableDirectories)
            {
                foreach (string File in Directory.GetFiles(Dir, "*.h"))
                {
                    // Loop through file and find class name
                    string[] FileLines = System.IO.File.ReadAllLines(Path.Combine(Dir, File));
                    foreach (string FileLine in FileLines)
                    {
                        if (FileLine.Contains("class") && FileLine.Contains("GameObject"))
                        {
                            string TempClassString = FileLine.Replace("class", "");
                            TempClassString = TempClassString.TrimStart();
                            TempClassString = TempClassString.Substring(0, TempClassString.IndexOf(" "));
                            ClassNames.Add(TempClassString);


                            string TempIncludeStr = "#include " + "\"" + Path.Combine(Dir, File) + "\"";
                            TempIncludeStr = TempIncludeStr.Replace(ParentPath, "../");
                            TempIncludeStr = TempIncludeStr.Replace("\\", "/");
                            HeaderFileIncludes.Add(TempIncludeStr);

                            break;
                        }
                    }
                }
            }



            List <string> UtilityLines     = new List <string>(System.IO.File.ReadAllLines(Path.Combine(LoadUtilityDirectory, "LoadUtility.cpp")));
            int           StartRemoveIndex = 0;
            int           EndRemoveIndex   = 0;
            int           EmptySpaceIndex  = 0;

            bool FoundFunction = false;

            int CloseFound = 0;

            for (int LineNum = 0; LineNum < UtilityLines.Count; LineNum++)
            {
                if (UtilityLines[LineNum].Contains("ReflectionIncludes.h"))
                {
                    EmptySpaceIndex = LineNum;
                }

                if (UtilityLines[LineNum].Contains("LoadUtility::AddLoadableObjects"))
                {
                    StartRemoveIndex = LineNum + 2;
                    FoundFunction    = true;
                    continue;
                }

                if (UtilityLines[LineNum].Contains("{") && FoundFunction)
                {
                    CloseFound += 1;
                }

                else if (UtilityLines[LineNum].Contains("}") && FoundFunction)
                {
                    CloseFound -= 1;
                }

                else if (CloseFound == 0 && FoundFunction)
                {
                    EndRemoveIndex = LineNum;
                    break;
                }
            }



            UtilityLines.RemoveRange(StartRemoveIndex, EndRemoveIndex - StartRemoveIndex);



            File.WriteAllLines(Path.Combine(LoadUtilityDirectory, IncludesFileName), HeaderFileIncludes);

            string CombinedFunctions = "";

            for (int NameIndex = 0; NameIndex < ClassNames.Count; NameIndex++)
            {
                string TemplateArray = "\n\t SaveManager::LoadableObjects.emplace(" + "\"" + "class " + ClassNames[NameIndex] + "\"" + ", std::make_shared<" + ClassNames[NameIndex] + "> (\"None\", MATH::Vec3())); \n";

                CombinedFunctions += TemplateArray;
            }

            UtilityLines.RemoveAt(EmptySpaceIndex);
            UtilityLines.Insert(EmptySpaceIndex, "#include " + "\"" + IncludesFileName + "\"");
            UtilityLines.Insert(StartRemoveIndex, CombinedFunctions + "\n} ");



            File.WriteAllLines(Path.Combine(LoadUtilityDirectory, "LoadUtility.cpp"), UtilityLines);
        }
Esempio n. 17
0
        //constructor function
        private void ConstructorFunction()
        {
            try
            {
                DirectoryInfo        LogDirI                  = new DirectoryInfo(LogDir);
                FileInfo[]           snaplist                 = LogDirI.GetFiles("snap*");
                DateTime             TimeNow                  = new DateTime();
                DateTime             ZeroHour                 = DateTime.Parse("00:00:00");
                LinkID               LinkNow                  = new LinkID();
                ReadTurningIntention RTI                      = new ReadTurningIntention();
                string               TempVariableNextLink     = "";
                string               TempVariableNextNextLink = "";
                string               TempVariableNextTurn     = "";
                string               TempVariableNextNextTurn = "";


                FileInfo snapfile = snaplist[snaplist.Length - 1];
                using (StreamReader ReadFile = new StreamReader(snapfile.FullName))
                {
                    string FileLine;
                    while ((FileLine = ReadFile.ReadLine()) != null)
                    {
                        if (FileLine.Contains("snapshot at time"))
                        {
                            string[] splitline = FileLine.Split(new char[] { ' ' });
                            double   TimeSecs  = Convert.ToDouble(splitline[3]);
                            TimeNow = ZeroHour.AddSeconds(TimeSecs);
                        }
                        else if (FileLine.Contains("on link"))
                        {
                            string[] splitline = FileLine.Split(new char[] { ' ', ':' });
                            LinkNow = new LinkID(splitline[2], splitline[3]);
                            //ApproachNode = splitline[2];
                            //JunctionNode = splitline[3];
                        }
                        else if (FileLine.Contains("type "))
                        {
                            FileData TempDat = new FileData();

                            if (FileLine.Contains("path"))
                            {
                                string[] splitline = FileLine.Split(new char[] { ' ', '"' });
                                TempDat.Vtype       = Convert.ToInt32(splitline[1]) + 1;
                                TempDat.Origin      = Convert.ToInt32(splitline[15]) + 1;
                                TempDat.Destination = Convert.ToInt32(splitline[16]) + 1;
                                TempDat.Vspeed      = Convert.ToDouble(splitline[13]);
                                TempDat.LinkDist    = Convert.ToDouble(splitline[8]);
                                TempDat.RouteName   = splitline[6];
                                TempDat.OnLink      = LinkNow;
                                TempDat.AtTime      = TimeNow;
                                double bornsecs = Convert.ToDouble(splitline[17]);
                                TempDat.BornTime      = ZeroHour.AddSeconds(bornsecs);
                                TempDat.MagicNumbers  = ("[" + splitline[10]);
                                TempDat.MagicNumbers += ("," + splitline[20] + "]");    //This needs to be checked

                                Fdata.Add(TempDat);
                            }
                            else
                            {
                                string[] splitline = FileLine.Split(new char[] { ' ' });
                                TempDat.Vtype       = (Convert.ToInt32(splitline[1])) + 1;
                                TempDat.Origin      = (Convert.ToInt32(splitline[10])) + 1;
                                TempDat.Destination = (Convert.ToInt32(splitline[11])) + 1;
                                TempDat.Lane        = (Convert.ToInt32(splitline[7]));

                                TempDat.Vspeed   = Convert.ToDouble(splitline[8]);
                                TempDat.LinkDist = Convert.ToDouble(splitline[3]);
                                TempDat.OnLink   = LinkNow;
                                TempDat.AtTime   = TimeNow;
                                double bornsecs = Convert.ToDouble(splitline[12]);
                                TempDat.BornTime      = ZeroHour.AddSeconds(bornsecs);
                                TempDat.MagicNumbers  = ("[" + splitline[5]);
                                TempDat.MagicNumbers += ("," + splitline[15] + "]");
                                TempVariableNextLink  = RTI.NextLinkNumber(LinkNow.StartNode, LinkNow.EndNode, splitline[13]);
                                if (TempVariableNextLink == "null")
                                {
                                    TempDat.NextLink     = "99999";           //TODO 99999 could be a next link number!
                                    TempDat.NextNextLink = "99999";
                                }
                                else
                                {
                                    TempDat.NextLink = TempVariableNextLink;
                                }
                                TempVariableNextNextLink = RTI.NextLinkNumber(LinkNow.EndNode, TempVariableNextLink, splitline[14]);
                                if (TempVariableNextNextLink == "null")
                                {
                                    TempDat.NextNextLink = "99999";
                                }
                                else
                                {
                                    TempDat.NextNextLink = TempVariableNextNextLink;
                                }
                                TempVariableNextTurn = RTI.NextTurnDirection(LinkNow.StartNode, LinkNow.EndNode, splitline[13]);
                                if (TempVariableNextTurn == "null")
                                {
                                    TempDat.NextTurn     = "None";           //99999 shows an error
                                    TempDat.NextNextTurn = "None";
                                }
                                else
                                {
                                    TempDat.NextTurn = TempVariableNextTurn;
                                }
                                TempVariableNextNextTurn = RTI.NextTurnDirection(LinkNow.EndNode, TempVariableNextLink, splitline[14]);
                                if (TempVariableNextNextTurn == "null")
                                {
                                    TempDat.NextNextTurn = "None";          //99999 shows an error
                                }
                                else
                                {
                                    TempDat.NextNextTurn = TempVariableNextNextTurn;
                                }
                                //TempDat.NextTurn = "Null10";
                                //TempDat.NextNextTurn = "Null10";
                                Fdata.Add(TempDat);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // Let the user know what went wrong.
                Console.WriteLine("Error reading snapfiles:");
                Console.WriteLine(e.Message);
            }
        }