views:

20

answers:

0

I am working on a program that transfers a file from a CentOS VM, and parses the file for multiple Start, finish, and host ID values. After this the values are then moved into an Access database for tracking purposes. So far I am able to pull a file down from the CentOS VM and parse it for the desired values. However, I have run into a few problems. The first one being that the only retrieves the first set of start, finish, and host ID then stops. The second problem is the program adds the same value to the database. I’ve tried to make the start time a primary key to prevent this but the code just crashes and reports that it would add the same value. Any help on this code would be appreciated. Here is what I have so far:

 TextReader tr = new StreamReader(new FileStream("H:\\Work\\Monitor\\StarterLog.txt", FileMode.Open, FileAccess.Read));
           string dataRow = "";
           System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
           conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data Source=H:\Test3.mdb;Persist Security Info=True";
           conn.Open();
           OleDbCommand insert = new OleDbCommand("INSERT INTO Table1([Start], [Host], [Stop]) VALUES(@Host, @Start, @Stop)", conn);; 
            string line;
            while((line = tr.ReadLine()) != null)
            {

                if (line.Contains("PID"))
                { 

                    int i = line.IndexOf("=") + 1;
                    string PUID = line.Substring(i, line.Length - i).Trim();
                    insert.Parameters.Add("@Host", OleDbType.Char).Value = PUID;
                    Console.WriteLine("Submit Host: {0}", PUID);
                }
                if (line.Contains("STARTING UP"))
                {
                    int i = line.IndexOf("");
                    string conStart = line.Substring(0,14).Trim();//i, line.Length - i).Trim();
                    insert.Parameters.Add("@Start", OleDbType.Char).Value = conStart;
                    Console.WriteLine("Condor Start: {0}", conStart);

                }
                if (line.Contains("ShutdownFast all jobs."))
                {
                    int i = line.IndexOf("");
                    string conFinish = line.Substring(0,14).Trim();
                    insert.Parameters.Add("@Stop", OleDbType.Char).Value = conFinish;
                    Console.WriteLine("Condor Stop: {0}", conFinish);    
                }
            }
                insert.ExecuteNonQuery();
                conn.Close();