public void TestStartMonitoringLastFile()
 {
     Regex regEx = new Regex("answered|disconnected");
     TalkLogMonitorUtil monUtil = new TalkLogMonitorUtil(@"C:\Iggy\TestTalkMonitor.txt", justABreakPoint, regEx);
     monUtil.startMonitoringLogFile();
     // System.Threading.Thread.Sleep(50000);
 }
        public void TestGetLogFile()
        {
            Regex regEx = new Regex("");
            TalkLogMonitorUtil monUtil = new TalkLogMonitorUtil("", null, regEx); // We don't require any of the parameters to test this method

            DateTime dTime = new DateTime(1983, 03, 12);
            string strTalkPath = @"C:\Users\cati\AppData\Roaming\NCH Software\Program Files\Talk\talk.exe";

            string strLogFileExpected = @"C:\Users\cati\AppData\Roaming\NCH Software\Talk\Logs\1983-03-12 Express Talk Log.txt";
            string strLogFileNameActual = TalkLogMonitorUtil.getTalkLogFileNameFromTalkPath(dTime, strTalkPath);

            Assert.AreEqual(strLogFileExpected, strLogFileNameActual);
        }
        public void TestGetLastLineFromFile()
        {
            TalkLogMonitorUtil monUtil = new TalkLogMonitorUtil(@"C:\Iggy\TestTalkMonitor.txt", null, null); // We just require the file path

            StreamWriter stWriter = File.AppendText(@"C:\Iggy\TestTalkMonitor.txt");

            string strExpectedLine = "Last line " + DateTime.Now.ToString();
            stWriter.WriteLine(strExpectedLine);
            stWriter.Flush();
            string strActual = monUtil.getLastLineFromFile();

            Assert.AreEqual(strExpectedLine, strActual);
        }
        public void TestCheckForPatterns()
        {
            string strLineFromFile;
            bool patternFound;

            Regex regEx = new Regex("answered|disconnected");

            TalkLogMonitorUtil monUtil = new TalkLogMonitorUtil(null, null, regEx); // We just require a regular expression

            // Test patter one = 'answered'
            strLineFromFile = "20:28:46 Call answered";
            patternFound = monUtil.checkForPatterns(strLineFromFile);

            Assert.IsTrue(patternFound);

            // Test patter two = 'disconnected'
            strLineFromFile = "20:28:58 Call has disconnected";
            patternFound = monUtil.checkForPatterns(strLineFromFile);

            Assert.IsTrue(patternFound);
        }
Пример #5
0
        /// <summary>
        /// Keep track if we have sent an error popup notification, if so use this value to supress future popups, under the assumption that the first one is the most important and probably the originator of the future popups.
        /// </summary>
        public MainForm()
        {
            // Machine number
            m_strMachineNumber = System.Configuration.ConfigurationManager.AppSettings["machineNumber"];

            //Setup the Logging system
            m_logAndErr = new LogAndErrorsUtils(AutoDialIcon, ToolTipIcon.Error);
            m_imgManUtils = new ImageManipulationUtils(m_logAndErr);
            m_logger = m_logAndErr.getLogger();

            // Give the admins a chance to change the path of tessdata
            string TESSERACT_DATA_PATH = System.Configuration.ConfigurationManager.AppSettings["tessdataPath"];
            if (TESSERACT_DATA_PATH == null)
            {

                TESSERACT_DATA_PATH = @"C:\\Autodial\\Dialing\\tessdata";
                m_logger.Error("No Config Tesseract path. Setting to: {0}", TESSERACT_DATA_PATH);
            }

            // Initilialise event for timer tick
            m_timer.Tick += new EventHandler(timerTick);

            //Initialise the Form
            InitializeComponent();

            m_logger.Info("###################################################################");
            m_logger.Info("Starting Program");

            // Checking for tesseract data path
            if (!System.IO.Directory.Exists(TESSERACT_DATA_PATH))
            {
                string strError = "Couldn't find tesseract in " + TESSERACT_DATA_PATH;
                m_logger.Error(strError);
                m_logger.Info(MailUtils.MailUtils.sendit("*****@*****.**", m_strMachineNumber, strError, m_strDailyLogFilename));
            }

            // Set the Talk Log Monitor Util
            Regex regEx = new Regex("answered|disconnected");
            string strTalkLogPath = System.Configuration.ConfigurationManager.AppSettings["talkLogPath"];
            m_logger.Info("Talk Log path: " + strTalkLogPath);
            string strLogFilePath = TalkLogMonitorUtil.getTalkLogFileNameFromTalkLogDirectory(DateTime.Today, strTalkLogPath);
            m_logger.Info("Talk File Log path: " + strLogFilePath);
            m_talkLogMonitor = new TalkLogMonitorUtil(strLogFilePath, stopAlertTimer, regEx);

            string strYear = DateTime.Today.Year.ToString();
            string strMonth = (DateTime.Today.Month < 10) ? ("0" + DateTime.Today.Month.ToString()) : DateTime.Today.Month.ToString();
            string strDay = (DateTime.Today.Day < 10) ? ("0" + DateTime.Today.Day.ToString()) : DateTime.Today.Day.ToString();

            m_strDailyLogFilename = @"C:\AutoDial\Log\AutoDial_" +
                                    strYear + "-" +
                                    strMonth + "-" +
                                    strDay + "_trace.log"; // AutoDial_2015-10-28_trace.log

            registerHotkey();
            customHide();
        }