Example #1
0
        private static Guid?ReadRepositoryEvents(EEventRepository repos)
        {
            string xmlFile   = InstallPath + repos.ToString() + ".xml";
            Guid?  lastEvent = null;

            if (!File.Exists(xmlFile))
            {
                return(null);
            }

            bool mutexHeld = false;

            try
            {
                eventWriterMutex.WaitOne();
                mutexHeld = true;

                using (FileStream fs = new FileStream(xmlFile, FileMode.Open))
                {
                    using (XmlReader xml = XmlReader.Create(fs))
                    {
                        lastEvent = ReadAndAddDifference(repos, xml);
                    }
                }
            }
            catch (Exception ex)
            {
                // not a valid repository
                //MessageBox.Show(ex.ToString());
            }
            finally
            {
                if (mutexHeld)
                {
                    eventWriterMutex.ReleaseMutex();
                }
            }

            return(lastEvent);
        }
Example #2
0
        private void DisplayNewEvent(EEventRepository r, EventItem e, bool isRealtime)
        {
            try
            {
                if (this.lvAlerts.InvokeRequired)
                {
                    lvAlerts.Invoke(new DisplayNewEventDelegate(DisplayNewEvent), new object[] { r, e, isRealtime });
                }
                else
                {
                    if (String.Compare(cmbRepos.Text, r.ToString(), true) != 0 && String.Compare(cmbRepos.Text, "All", true) != 0)
                    {
                        return;
                    }

                    lock (displaylock)
                    {
                        EThreatRiskRating risk      = (EThreatRiskRating)Enum.Parse(typeof(EThreatRiskRating), e.EventRisk, true);
                        Color             riskColor = Color.LightGray;

                        switch (risk)
                        {
                        case EThreatRiskRating.Information:
                            riskColor = Color.LightGray;
                            break;

                        case EThreatRiskRating.LowRisk:
                            riskColor = Color.LightGreen;
                            break;

                        case EThreatRiskRating.MediumRisk:
                            riskColor = Color.Orange;
                            break;

                        case EThreatRiskRating.HighRisk:
                            riskColor = Color.OrangeRed;
                            break;
                        }

                        string date = e.EventDate.ToString().Substring(0, e.EventDate.ToString().IndexOf(' '));
                        string time = e.EventDate.ToString().Substring(e.EventDate.ToString().IndexOf(' ') + 1);

                        ListViewItem lvi = new ListViewItem(new string[] { date, time, e.EventProcess, e.EventRisk, e.EventTitle });
                        lvi.BackColor = riskColor;
                        lvi.Tag       = e;

                        bool showAllCount = false;
                        int  showMax      = 0;

                        if (!GetFormItemsCount(out showMax, out showAllCount))
                        {
                            showAllCount = true;
                        }


                        if (!showAllCount && lvAlerts.Items.Count == showMax)
                        {
                            lvAlerts.Items.RemoveAt(showMax - 1);
                        }

                        lvAlerts.Items.Insert(0, lvi);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }