Esempio n. 1
0
        //check to see if theres a more up-to-date version of any channel
        private void refreshChannels()
        {
            LogDirectoryMonitor l = new LogDirectoryMonitor(IntelProperties.EXPIRY);

            l.Path = IntelProperties.getProperty("LOG_DIR");

            List <LogFileMonitor> monitors = l.ReadDirectory();

            foreach (LogFileMonitor m in monitors)
            {
                m.Refresh(true);
                string name = m.FileChannel.Channel.ChannelName;

                //if this channel is already being monitored, check to make sure the files are the same
                if (monitoredChannels.Contains(name) && channels.ContainsKey(name))
                {
                    Monitor om = channels[name];
                    if (om.logMonitor.FileChannel.File.Name != m.FileChannel.File.Name && om.logMonitor.FileChannel.File.LastWriteTime < m.FileChannel.File.LastWriteTime)
                    {
                        Console.WriteLine("Updating file " + m.FileChannel.File.Name);
                        channels.Remove(name);
                        channels.Add(name, new Monitor(m));
                    }
                }
                else if (monitoredChannels.Contains(name) && !channels.ContainsKey(name))
                {
                    //else, just add a new monitor
                    Console.WriteLine("Monitoring " + name);
                    channels.Add(name, new Monitor(m));
                }
            }
        }
Esempio n. 2
0
        private void populateFields()
        {
            this.username.Text = IntelProperties.getProperty("USER_ID");
            this.key.Text      = IntelProperties.getProperty("USER_KEY");
            this.logDir.Text   = IntelProperties.getProperty("LOG_DIR");

            this.channelList.Items.Clear();
            foreach (string channel in IntelProperties.getProperty("CHANNELS").Split(','))
            {
                this.channelList.Items.Add(channel.Trim());
            }
        }
Esempio n. 3
0
        public static void reportViaHTTP(string message)
        {
            WebClient webClient = new WebClient();

            webClient.Proxy = null;
            NameValueCollection values = new NameValueCollection();

            values.Add("user", IntelProperties.getProperty("USER_ID"));
            values.Add("userkey", IntelProperties.getProperty("USER_KEY"));
            values.Add("message", message);

            webClient.UploadValues(IntelProperties.HTTP_URL, "POST", values);
            webClient.Dispose();
        }
Esempio n. 4
0
        private void initChannels()
        {
            LogDirectoryMonitor l = new LogDirectoryMonitor(IntelProperties.EXPIRY);

            l.Path = IntelProperties.getProperty("LOG_DIR");

            List <LogFileMonitor> monitors = l.ReadDirectory();

            foreach (LogFileMonitor m in monitors)
            {
                m.Refresh(true);
                string name = m.FileChannel.Channel.ChannelName;
                if (monitoredChannels.Contains(name))
                {
                    Console.WriteLine("Monitoring " + name);
                    channels.Add(name, new Monitor(m));
                }
            }
        }
Esempio n. 5
0
        public void run()
        {
            try
            {
                onStatusChange("Adding channels");
                foreach (string channel in IntelProperties.getProperty("CHANNELS").Split(','))
                {
                    Console.WriteLine("\t" + channel);
                    monitoredChannels.Add(channel.Trim());
                }
                onStatusChange("Initializing channels");
                refreshChannels();

                onStatusChange("Monitoring channels");

                int fullRefreshCount = 0;
                while (true)
                {
                    //Console.WriteLine("Sleeping");
                    Thread.Sleep(IntelProperties.SLEEP * 1000);
                    readChannels();
                    if (fullRefreshCount++ == 5)
                    {
                        //Console.WriteLine("Full refresh");
                        refreshChannels();
                        fullRefreshCount = 0;
                    }
                }
            }
            catch (ThreadAbortException e)
            {
                //return, we've been killed
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                logError(e);
            }
        }