Exemplo n.º 1
0
        public void SaveReportFile(string _ReportFileName,
                                   List <LogFile_In_rec> _LogFile_In_table,
                                   List <Disp_LogFiles_rec> _Disp_LogFile_table,
                                   List <Disp_LogMachEvents_rec> _Disp_LogMachEvents_table
                                   )
        {
            //saves the report file name
            //first get the time frame
            string ReportTimeStart;
            string ReportTimeStop;

            ReportTimeStart = ConvLogTimeToStr(_LogFile_In_table[0].timeInStr);
            int LastLogRec = _LogFile_In_table.Count() - 1;

            ReportTimeStop = ConvLogTimeToStr(_LogFile_In_table[LastLogRec].timeInStr);

            StreamWriter sw = new StreamWriter(_ReportFileName);

            sw.WriteLine("");
            sw.WriteLine("               Network Monitoring Report - by machine");
            sw.WriteLine("");
            sw.WriteLine("Report Generated on : " + DateTime.Now.ToString("MM/dd/yyyy  hh:mm:ss"));
            sw.WriteLine("");
            sw.WriteLine("Time span in report : " + ReportTimeStart + " to " + ReportTimeStop);
            sw.WriteLine("Log Files Read in   : ");

            for (int i = 0; i < _Disp_LogFile_table.Count(); i++)
            {
                string FileNum = StringFixedLength((i + 1).ToString().Trim(), 3, false, '0');
                sw.WriteLine("     " + FileNum + "=" + _Disp_LogFile_table[i].fileName);
            }
            ;
            sw.WriteLine("");
            sw.WriteLine("");

            //setup columns widths for headers and data
            List <int> ColWid = new List <int>();

            ColWid.Add(15);    //mach num
            ColWid.Add(20);    //start time
            ColWid.Add(20);    //stop time
            ColWid.Add(15);    //time diff
            ColWid.Add(15);    //on time
            ColWid.Add(15);    //off time

            string ColHead00 = StringFixedLength("Machine", ColWid[0], true, ' ');
            string ColHead01 = StringFixedLength("Start Time", ColWid[1], true, ' ');
            string ColHead02 = StringFixedLength("Stop Time", ColWid[2], true, ' ');
            string ColHead03 = StringFixedLength("Duration", ColWid[3], true, ' ');
            string ColHead04 = StringFixedLength("On Time", ColWid[4], true, ' ');
            string ColHead05 = StringFixedLength("Off Time", ColWid[5], true, ' ');
            string HeaderStr = ColHead00 + " " + ColHead01 + " " + ColHead02 + " | " + ColHead03 + " | ";

            HeaderStr = HeaderStr + ColHead04 + " " + ColHead05;
            sw.WriteLine(HeaderStr);

            ColHead00 = StringFixedLength("_", ColWid[0], true, '_');
            ColHead01 = StringFixedLength("_", ColWid[1], true, '_');
            ColHead02 = StringFixedLength("_", ColWid[2], true, '_');
            ColHead03 = StringFixedLength("_", ColWid[3], true, '_');
            ColHead04 = StringFixedLength("_", ColWid[4], true, '_');
            ColHead05 = StringFixedLength("_", ColWid[5], true, '_');
            HeaderStr = ColHead00 + " " + ColHead01 + " " + ColHead02 + " | " + ColHead03 + " | ";
            HeaderStr = HeaderStr + ColHead04 + " " + ColHead05;
            sw.WriteLine(HeaderStr);

            //now loop thru all of the machine data
            string LastMachNum = "";

            for (int i = 0; i < _Disp_LogMachEvents_table.Count(); i++)
            {
                Disp_LogMachEvents_rec currRec = _Disp_LogMachEvents_table[i];
                if (currRec.machNum.Contains("M"))
                {
                    LastMachNum = LeftStr(currRec.machNum, 3);
                }
                string Col00   = StringFixedLength(currRec.machNum, ColWid[0], true, ' ');
                string Col01   = StringFixedLength(currRec.timeStartStr, ColWid[1], true, ' ');
                string Col02   = StringFixedLength(currRec.timeStopStr, ColWid[2], true, ' ');
                string Col03   = StringFixedLength(currRec.timeDiffStr, ColWid[3], true, ' ');
                string Col04   = StringFixedLength(currRec.timeOnStr, ColWid[4], true, ' ');
                string tempStr = "";
                if (currRec.machNum.Contains("total"))
                {
                    tempStr = " " + LastMachNum;
                }
                string Col05  = StringFixedLength(currRec.timeOffStr + tempStr, ColWid[5], true, ' ');
                string RecStr = Col00 + " " + Col01 + " " + Col02 + " | " + Col03 + " | ";
                RecStr = RecStr + Col04 + " " + Col05;
                sw.WriteLine(RecStr);
            }
            ;

            sw.WriteLine("");
            sw.Flush();
            sw.Close();
        }
Exemplo n.º 2
0
        public void Disp_LogInfo_load(
            List <LogFile_In_rec> _LogFile_In_table,
            List <Disp_LogInfo_rec> _DispLogInfo_table,
            List <LogEvents_rec> _LogEvents_table,
            List <Disp_LogEvents_rec> _Disp_LogEvents_table
            )
        {
            //load all of the data into disp table
            //this routine is for all the Log data even if there were no changes
            //_DispLogInfo_table = new List<Disp_LogInfo_rec>();

            _DispLogInfo_table.Clear();

            //store the first record automatically
            if (_LogFile_In_table.Count() > 0)
            {
                //used to store prev log, now it does not matter
            }
            ;
            if (_LogFile_In_table.Count() > 1) //more than one record
            {
                //there is more than one record, so loop thru all
                for (int i = 0; i < _LogFile_In_table.Count(); i++)
                {
                    //first step is to load all of the log data as it came in
                    Disp_LogInfo_add(_LogFile_In_table[i], _DispLogInfo_table);
                }
                ;
            }
            ;
            Console.WriteLine("End of log info");

            //load the log Events
            //make as a separate function later on
            LogFile_In_rec prevLogRec = new LogFile_In_rec();
            LogFile_In_rec newLogRec  = new LogFile_In_rec();

            if (_LogFile_In_table.Count() > 0)
            {
                prevLogRec.timeInStr = _LogFile_In_table[0].timeInStr;
                prevLogRec.machStat  = new List <bool>();
                for (int j = 0; j < NumMachines; j++)
                {
                    prevLogRec.machStat.Add(_LogFile_In_table[0].machStat[j]);
                }
                ;

                //add a record to the events display table with the first record
            }
            ;

            if (_LogFile_In_table.Count() > 1) //more than one record
            {
                //there is more than one record, so loop thru all
                for (int i = 0; i < _LogFile_In_table.Count(); i++)
                {
                    newLogRec.timeInStr = "";
                    newLogRec.machStat  = new List <bool>();

                    bool forceAdd = false;
                    if (i == 0)
                    {
                        forceAdd = true;
                    }
                    LogEvents_Check_add(_LogEvents_table, _LogFile_In_table[i], prevLogRec, forceAdd);
                }
                ;
                //for the storage of the last record
                LogEvents_Check_add(_LogEvents_table, _LogFile_In_table[_LogFile_In_table.Count() - 1], prevLogRec, true);
            }
            ;
            Console.WriteLine("End of Log Events");

            //now load LogEvents to the Display Log Events
            Disp_LogEvents_add(_Disp_LogEvents_table, LogEvents_table);
            Console.WriteLine("all display log events are created");


            //sort by machine
            for (int machNum = 0; machNum < NumMachines; machNum++)
            {
                //reset running sum
                TimeSpan totOnSpan   = new TimeSpan(0, 0, 0, 0);
                TimeSpan totOffSpan  = new TimeSpan(0, 0, 0, 0);
                TimeSpan totTimeSpan = new TimeSpan(0, 0, 0, 0);

                //load the first data
                Disp_LogMachEvents_rec newRec = new Disp_LogMachEvents_rec();  //new record
                string machNumStr             = "M" + RightStr(("000" + (machNum + 1).ToString().Trim()), 2);
                newRec.timeStartStr = ConvLogTimeToStr(_LogFile_In_table[0].timeInStr);

                bool oldStat = _LogFile_In_table[0].machStat[machNum];
                if (oldStat)
                {
                    newRec.machNum = machNumStr + " on";
                }
                else
                {
                    newRec.machNum = machNumStr + " off";
                }

                for (int i = 1; i < _LogFile_In_table.Count() - 1; i++)
                {
                    if (_LogFile_In_table[i].machStat[machNum] != oldStat)
                    {
                        //status has changed
                        newRec.timeStopStr = ConvLogTimeToStr(_LogFile_In_table[i].timeInStr);
                        newRec.timeDiffStr = CalcTimeDiffStr(newRec.timeStartStr, newRec.timeStopStr);
                        if (newRec.machNum.Contains("on"))
                        {
                            newRec.timeOnStr  = newRec.timeDiffStr;
                            newRec.timeOffStr = "";
                            totOnSpan         = AddToTime(totOnSpan, newRec.timeOnStr);
                            totTimeSpan       = AddToTime(totTimeSpan, newRec.timeOnStr);
                        }
                        else
                        {
                            newRec.timeOnStr  = "";
                            newRec.timeOffStr = newRec.timeDiffStr;
                            totOffSpan        = AddToTime(totOffSpan, newRec.timeOffStr);
                            totTimeSpan       = AddToTime(totTimeSpan, newRec.timeOffStr);
                        };
                        Disp_LogMachEvents_table.Add(newRec);
                        oldStat = _LogFile_In_table[i].machStat[machNum];

                        //now prepare for the next record
                        newRec = new Disp_LogMachEvents_rec();
                        newRec.timeStartStr = ConvLogTimeToStr(_LogFile_In_table[i].timeInStr);
                        if (oldStat)
                        {
                            newRec.machNum = machNumStr + " on";
                        }
                        else
                        {
                            newRec.machNum = machNumStr + " off";
                        }
                    }
                    ;
                }
                ;
                //loop ended so close out the record
                newRec.timeStopStr = ConvLogTimeToStr(_LogFile_In_table[_LogFile_In_table.Count() - 1].timeInStr);
                newRec.timeDiffStr = CalcTimeDiffStr(newRec.timeStartStr, newRec.timeStopStr);
                if (newRec.machNum.Contains("on"))
                {
                    newRec.timeOnStr  = newRec.timeDiffStr;
                    newRec.timeOffStr = "";
                    totOnSpan         = AddToTime(totOnSpan, newRec.timeOnStr);
                    totTimeSpan       = AddToTime(totTimeSpan, newRec.timeOnStr);
                }
                else
                {
                    newRec.timeOnStr  = "";
                    newRec.timeOffStr = newRec.timeDiffStr;
                    totOffSpan        = AddToTime(totOffSpan, newRec.timeOffStr);
                    totTimeSpan       = AddToTime(totTimeSpan, newRec.timeOffStr);
                };
                Disp_LogMachEvents_table.Add(newRec);

                newRec              = new Disp_LogMachEvents_rec();
                newRec.machNum      = "------------";
                newRec.timeStartStr = "";
                newRec.timeStopStr  = "";
                newRec.timeDiffStr  = "";
                newRec.timeOnStr    = "----------";
                newRec.timeOffStr   = "----------";
                Disp_LogMachEvents_table.Add(newRec);

                newRec              = new Disp_LogMachEvents_rec();
                newRec.machNum      = "total times";
                newRec.timeStartStr = "";
                newRec.timeStopStr  = "";
                //newRec.timeDiffStr = "";
                if (totTimeSpan.TotalHours == 0)
                {
                    newRec.timeDiffStr = "--";
                }
                else
                {
                    newRec.timeDiffStr = totTimeSpan.TotalHours.ToString("####.##") + " total";
                }
                if (totOnSpan.TotalHours == 0)
                {
                    newRec.timeOnStr = "--";
                }
                else
                {
                    newRec.timeOnStr = totOnSpan.TotalHours.ToString("####.##") + " hrs";
                }
                if (totOffSpan.TotalHours == 0)
                {
                    newRec.timeOffStr = "--";
                }
                else
                {
                    newRec.timeOffStr = totOffSpan.TotalHours.ToString("####.##") + " hrs";
                }

                /*
                 * newRec.timeOnStr = (totOnSpan.Days*24+totOnSpan.Hours).ToString().Trim() + ":" +
                 *  RightStr("000" + totOnSpan.Minutes.ToString().Trim(),2);
                 * newRec.timeOffStr = (totOffSpan.Days * 24 + totOffSpan.Hours).ToString().Trim() + ":" +
                 *  RightStr("000" + totOffSpan.Minutes.ToString().Trim(), 2);
                 */
                Disp_LogMachEvents_table.Add(newRec);

                newRec              = new Disp_LogMachEvents_rec();
                newRec.machNum      = "percentages";
                newRec.timeStartStr = "";
                newRec.timeStopStr  = "";
                newRec.timeDiffStr  = "";
                double OnPercent = (totOnSpan.TotalHours / totTimeSpan.TotalHours) * 100.00;
                if (OnPercent == 0)
                {
                    newRec.timeOnStr = "";
                }
                else
                {
                    newRec.timeOnStr = OnPercent.ToString("###.##") + "%";
                }

                double OffPercent = (totOffSpan.TotalHours / totTimeSpan.TotalHours) * 100.00;
                if (OffPercent == 0)
                {
                    newRec.timeOffStr = "";
                }
                else
                {
                    newRec.timeOffStr = OffPercent.ToString("###.##") + "%";
                }
                Disp_LogMachEvents_table.Add(newRec);

                newRec              = new Disp_LogMachEvents_rec();
                newRec.machNum      = "------------";
                newRec.timeStartStr = "";
                newRec.timeStopStr  = "";
                newRec.timeDiffStr  = "";
                newRec.timeOnStr    = "----------";
                newRec.timeOffStr   = "----------";
                Disp_LogMachEvents_table.Add(newRec);

                newRec              = new Disp_LogMachEvents_rec();
                newRec.machNum      = "";
                newRec.timeStartStr = "";
                newRec.timeStopStr  = "";
                newRec.timeDiffStr  = "";
                newRec.timeOnStr    = "";
                newRec.timeOffStr   = "";
                Disp_LogMachEvents_table.Add(newRec);
            }
            ;
        }