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 save_Click(object sender, EventArgs e)
        {
            IntelProperties.setProperty("USER_ID", this.username.Text);
            IntelProperties.setProperty("USER_KEY", this.key.Text);

            if (!Directory.Exists(this.logDir.Text))
            {
                MessageBox.Show(this, "Log directory not found");
                return;
            }
            IntelProperties.setProperty("LOG_DIR", this.logDir.Text);

            string chnls = "";

            foreach (string channel in this.channelList.Items)
            {
                chnls += "," + channel;
            }
            IntelProperties.setProperty("CHANNELS", chnls.Substring(1));

            if (IntelProperties.validateProperties())
            {
                IntelProperties.save();
                Program.stopMonitor();
                Program.runMonitor();
                this.Hide();
            }
            else
            {
                MessageBox.Show(this, "Please fill in all required fields");
            }
        }
Esempio n. 3
0
        public static void initMonitor()
        {
            IntelMonitor.onStatusChange += window.updateStatus;
            IntelMonitor.onError        += handleError;

            IntelProperties.onConfigCreate += openSettings;
            IntelProperties.init();
        }
Esempio n. 4
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. 5
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. 6
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. 7
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);
            }
        }