Beispiel #1
0
        static LogStack compareWithFile(FileToMonitor fileToMonitor, LogStack logStack,LogStack historyStack)
        {
            if (!fileToMonitor.getPath().Equals(null))
            {
                DateTime dateToCompare = File.GetLastWriteTime(fileToMonitor.getPath());

                if (DateTime.Compare(dateToCompare, fileToMonitor.getTimeStamp()) > 0)
                {
                    StreamReader sr = new StreamReader(fileToMonitor.getPath());

                    while (!sr.EndOfStream)
                    {
                        Node node = new Node();
                        string line = sr.ReadLine();

                        if(!line.Equals(historyStack.ViewHead()))
                        {
                            node.setText(line);
                            logStack.Push(node);
                        }
                    }

                    sr.Close();
                }
            }
            return historyStack;
        }
Beispiel #2
0
 private static void timer_Elapsed(FileToMonitor fileToMonitor,BackgroundWorker bgw1, LogStack logStack,LogStack historyStack)
 {
     object[] args = new object[3];
     args[0] = fileToMonitor;
     args[1] = logStack;
     args[2] = historyStack;
     if (!bgw1.IsBusy)
     {
         bgw1.RunWorkerAsync(args);
     }
 }
Beispiel #3
0
        private void BeginMonitoring(bool hasBeenMonitored,DateTime accessedTimeStamp)
        {
            if(!String.IsNullOrEmpty(filePathToMonitor))
            {
                fileToMonitor.setPath(filePathToMonitor);
                fileToMonitor.setDateTime(File.GetLastWriteTime(fileToMonitor.getPath()));
            }

            if (DateTime.Compare(accessedTimeStamp, fileToMonitor.getTimeStamp()) > 0)
            {
                logStack = Monitor();
            }

            if (hasBeenMonitored.Equals(false) || DateTime.Compare(accessedTimeStamp, fileToMonitor.getTimeStamp())== 0)
            {
                logStack = Monitor();
            }

            var timer = new System.Timers.Timer(10000);
            timer.Elapsed += delegate { timer_Elapsed(fileToMonitor, backgroundWorker1,logStack,historyStack); };
            timer.AutoReset = true;
            timer.Start();
        }
Beispiel #4
0
 private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     historyStack = (LogStack)e.Result;
     WriteValuesToScreenFromThread(logStack,fileToMonitor);
 }
Beispiel #5
0
        private void WriteValuesToScreenFromThread(LogStack logStack, FileToMonitor fileToMonitor)
        {
            if (DateTime.Compare(File.GetLastWriteTime(fileToMonitor.getPath()), fileToMonitor.getTimeStamp()) > 0)
            {
                string text = String.Empty;

                while (!logStack.GetCount().Equals(0))
                {
                    Node node = logStack.Pop();

                    text = text + Environment.NewLine + node.getText();
                    historyStack.Push(node);
                }

                txtbxLogDisplay.Invoke((MethodInvoker)delegate { txtbxLogDisplay.Text = text; });
                fileToMonitor.setDateTime(File.GetLastWriteTime(fileToMonitor.getPath()));
            }
        }
Beispiel #6
0
        private void WriteValuesToScreen(LogStack logStack)
        {
            string text = String.Empty;

            while (!logStack.GetCount().Equals(0))
            {
                Node node = logStack.Pop();

                text = text + Environment.NewLine + node.getText();
                historyStack.Push(node);
            }

            txtbxLogDisplay.Text = text;
        }