private void HumasonLogFileListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            //New date, new log
            string writeLog  = "";
            string parsedLog = "";

            HumasonLogTextBox.Clear();
            ParsedTextBox.Clear();
            //figure out the new datetime from the selected log file name
            if (HumasonLogFileListBox.SelectedItem == null)
            {
                return;
            }
            DateTime      sdate   = Convert.ToDateTime(HumasonLogFileListBox.SelectedItem.ToString());
            HumasonReader hReader = new HumasonReader(sdate);

            if (hReader.HumasonJoinedLog != null)
            {
                foreach (string line in hReader.HumasonJoinedLog)
                {
                    writeLog += line + "\r\n";
                }
                List <string> plog = ParseLog(hReader);
                if (plog != null)
                {
                    foreach (string line in plog)
                    {
                        parsedLog += line + "\r\n";
                    }
                }
            }
            HumasonLogTextBox.Text = writeLog;
            HumasonLogTextBox.Select(0, 0);
            ParsedTextBox.Text = parsedLog;;
            ParsedTextBox.Select(0, 0);
            return;
        }
        private List <string> ParseLog(HumasonReader hReader)
        {
            //Routines goes through log looking for successful images count with filters
            //Look at each successive line in the log file
            //When an "Imaging Target is found, then save the last word as the targetname
            string targetName = null;

            int[]         filterXcount = { 0, 0, 0, 0, 0, 0, 0, 0 };
            string        exposureLen  = null;
            List <string> imgDataOut   = new List <string>();

            //List<string> logList = hReader.HumasonLog.ToList()) ;
            foreach (string line in hReader.HumasonJoinedLog)
            {
                // this is the per line loop
                // at the start,
                //   targetName = null;
                //   filterXcount[] = null;
                //   exposureLen = null;
                if (line.Contains("Session Done"))
                {
                    //if the target name is not null, then serve up the previously parsed data
                    if (targetName != null)
                    {
                        //readout filters
                        string fstr = null;
                        for (int i = 0; i < filterXcount.Length; i++)
                        {
                            if (filterXcount[i] != 0)
                            {
                                fstr += "\r\n\t" + "Filter " + i.ToString() + " - " + filterXcount[i].ToString() + " ";
                            }
                        }
                        imgDataOut.Add(targetName + "- " + "Exposure: " + exposureLen + " sec, " + fstr);
                    }
                    targetName = null;
                }
                if (line.Contains("Imaging Target:"))
                {
                    //start target loop
                    //  then clear the counters
                    for (int i = 0; i < filterXcount.Length; i++)
                    {
                        filterXcount[i] = 0;
                    }
                    exposureLen = "None";

                    //set target to last word in line
                    targetName = line.Split(' ')[5];
                }
                if (line.Contains("Imaging Filter"))
                {
                    //pickup image information
                    string[] ls = line.Split(' ');
                    //Time Imaging Filter 0 @ 600 sec (# 1 of 14) as example
                    exposureLen = ls[5];
                    ++filterXcount[Convert.ToInt32(ls[3])];
                }
            }
            //if the target name is not null, then serve up the previously parsed data
            if (targetName != null) //meaning that the session did not end before the log ended
            {
                //readout filters
                string fstr = null;
                for (int i = 0; i < filterXcount.Length; i++)
                {
                    if (filterXcount[i] != 0)
                    {
                        fstr += "Filter " + i.ToString() + " - " + filterXcount[i].ToString() + " ";
                    }
                }
                imgDataOut.Add(targetName + "- " + "Exposure: " + exposureLen + " sec, " + fstr);
            }
            return(imgDataOut);
        }
        public FormNightShift()
        {
            InitializeComponent();
            // Acquire the version information and put it in the form header
            try { this.Text = ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString(); }
            catch { this.Text = " in Debug"; } //probably in debug, no version info available
            this.Text = "NightShift V" + this.Text;

            TargetSpecs ts = new TargetSpecs("Sun");

            SunRiseTextBox.Text  = ts.RiseTime.ToString(@"hh\:mm");
            SunSetTextBox.Text   = ts.SetTime.ToString(@"hh\:mm");
            TwilightTextBox.Text = ts.TwilightEODTime.ToString(@"hh\:mm");
            DawnTextBox.Text     = ts.TwilightSODTime.ToString(@"hh\:mm");

            TargetSpecs tm = new TargetSpecs("Moon");

            MoonRiseTextBox.Text    = tm.RiseTime.ToString(@"hh\:mm");
            MoonSetTextBox.Text     = tm.SetTime.ToString(@"hh\:mm");
            MoonTransitTextBox.Text = tm.TransitTime.ToString(@"hh\:mm");
            MoonPhaseTextBox.Text   = (tm.PhasePercent.ToString("0")) + "%";

            //Test to see which buttons have installed applications
            QualifyToolKitButtons();

            //Load the Target Plan datagridview
            WriteTargetList();

            //Load the task list datagridview
            LogXDataBase  tldb     = new LogXDataBase();
            List <string> taskList = tldb.GetTasks();

            TaskDataGrid.Rows.Clear();
            int tidx = 0;

            if (taskList != null)
            {
                foreach (string task in taskList)
                {
                    TaskDataGrid.Rows.Add();
                    TaskDataGrid.Rows[tidx].Cells[0].Value = task;
                    TaskDataGrid.Rows[tidx].Cells[1].Value = false;
                    tidx++;
                }
            }
            Show();
            TaskDataGrid.ClearSelection();
            //Set the display date the the current date
            LogDateTimePicker.Value = DateTime.Now;
            //Create Humason Log content for Humason Log tab
            //Open log based on the most recent log
            HumasonReader hReader = new HumasonReader(DateTime.Now);
            //Get full list of logs in Log directory
            List <DateTime> hLogList = hReader.HumasonLogDates;

            foreach (DateTime ldate in hLogList)
            {
                HumasonLogFileListBox.Items.Add(ldate.ToShortDateString());
            }
            HumasonLogFileListBox.SelectedIndex = HumasonLogFileListBox.Items.Count - 1;
            Show();
            return;
        }