Esempio n. 1
0
        private void InterogateTable()
        {
            DataTable dt = DataGateway.GetRecordsSinceLastPoll(connStr, selectQuery, timeColumn, lastTimeProcessed);

            foreach (DataRow row in dt.Rows)
            {
                DateTime dtLastModified;
                object[] arguments = new object[dt.Columns.Count];

                dtLastModified = Convert.ToDateTime(row[timeColumn]);

                if (row[errColumn].ToString() == "")
                {
                    row[errColumn] = "INFO";
                }
                else
                {
                    row[errColumn] = "ERROR";
                }

                for (int iCol = 0; iCol < dt.Columns.Count; iCol++)
                {
                    arguments[iCol] = row[iCol];
                }

                masterLogger.WriteEntry(string.Format(outputString, arguments));

                // Get last Date Modified
                lastTimeProcessed = dtLastModified;
            }
        }
Esempio n. 2
0
        private void ProcessXMLOnChange(object sender, ElapsedEventArgs e)
        {
            var xmlLogfile = XDocument.Load(xmlFileLocation);
            var logEntries = (from x in xmlLogfile.Descendants(groupTagName)
                              where Convert.ToDateTime(x.Element(timeStampTag).Value) > Convert.ToDateTime(lastProcessedTime)
                              select x);

            foreach (XElement logEntry in logEntries)
            {
                int      i         = 0;
                string[] arguments = new string[logEntry.Elements().Count <XElement>()];
                foreach (XElement field in logEntry.Elements())
                {
                    arguments[i] = field.Value;
                    i++;
                }
                mlw.WriteEntry(string.Format(formatStr, arguments));
                lastProcessedTime = logEntry.Element(timeStampTag).Value;
            }
        }
Esempio n. 3
0
        private void SetUpWatcher()
        {
            FileInfo fi = new FileInfo(location);

            var lockMe = new object();

            using (var latch = new ManualResetEvent(true))
                using (var fsReader = new FileStream(location, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite))
                    using (var fsw = new FileSystemWatcher(fi.DirectoryName, fi.Name))
                    {
                        fsw.Changed += (s, e) =>
                        {
                            lock (lockMe)
                            {
                                if (e.FullPath != location)
                                {
                                    return;
                                }
                                latch.Set();
                            }
                        };
                        using (var sr = new StreamReader(fsReader))
                            while (true)
                            {
                                latch.WaitOne();
                                lock (lockMe)
                                {
                                    String line;
                                    while ((line = sr.ReadLine()) != null)
                                    {
                                        // Process line in log file
                                        string[] cols = line.Split(',');
                                        object[] args = new object[cols.Length + 1];
                                        args[0] = DateTime.Now;
                                        cols.CopyTo(args, 1);
                                        if (ignoreFirstLine)
                                        {
                                            ignoreFirstLine = false;
                                        }
                                        else
                                        {
                                            mlw.WriteEntry(string.Format(formatString, args));
                                        }
                                    }
                                    latch.Set();
                                }
                            }
                    }
        }
Esempio n. 4
0
        private void SetUpWatcher()
        {
            FileInfo fi = new FileInfo(location);

            var lockMe = new object();

            using (var latch = new ManualResetEvent(true))
                using (var fsReader = new FileStream(location, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite))
                    using (var fsw = new FileSystemWatcher(fi.DirectoryName, fi.Name))
                    {
                        fsw.Changed += (s, e) =>
                        {
                            lock (lockMe)
                            {
                                if (e.FullPath != location)
                                {
                                    return;
                                }
                                latch.Set();
                            }
                        };
                        using (var sr = new StreamReader(fsReader))
                            while (true)
                            {
                                latch.WaitOne();
                                lock (lockMe)
                                {
                                    String line;
                                    while ((line = sr.ReadLine()) != null)
                                    {
                                        // Process line in log file
                                        string[] cols = line.Split(',');

                                        masterLogger.WriteEntry(string.Format(formatString, cols));
                                    }
                                    latch.Set();
                                }
                            }
                    }
        }