Ejemplo n.º 1
0
        public EventLogHelper(EventFilters eventFilters)
        {
            lstErrors = new List<string>();
            Validate(eventFilters);
            this.eventFilters = eventFilters;

        }
Ejemplo n.º 2
0
        public Result Post(EventFilters eventFilter)
        {
            EventLogHelper helper=new EventLogHelper(eventFilter);
            helper.GenerateEventLog();
            return helper.GetResult();

        }
Ejemplo n.º 3
0
        private void Validate(EventFilters eventFilters)
        {

            if (String.IsNullOrEmpty(eventFilters.IP))
            {
                eventFilters.MachineName = System.Environment.MachineName;
            }
            else
            {
                try
                {

                    if (PingHost(eventFilters.IP))
                    {
                        try
                        {
                            IPHostEntry entry = Dns.GetHostEntry(eventFilters.IP);
                            eventFilters.MachineName = entry.HostName;
                        }
                        catch (Exception)
                        {

                            lstErrors.Add(string.Format("Unable to get Host Name for {0} ", eventFilters.IP));
                        }

                    }
                    else
                    {
                        lstErrors.Add(string.Format("Unable to ping host {0} ", eventFilters.IP));
                    }
                }
                catch (Exception e)
                {
                    Debug.Print(e.Message);
                    lstErrors.Add("An error occured while validating");
                }

            }
            if (eventFilters.fromDate != null && eventFilters.toDate != null)
            {
                
                if (eventFilters.fromDate.Value > eventFilters.toDate.Value)
                {
                    lstErrors.Add("from Date cant be greater than To date");
                }
            }
        }
Ejemplo n.º 4
0
        private static string GetQueryString(EventFilters eventFilters)
        {
            string xPathQuery = string.Empty;
            bool connector = false;

            //if (eventFilters.BeforeTimeStamp > eventFilters.AfterTimeStamp)
            //{
            //  return string.Empty;
            //}
            xPathQuery = "*[System[";
            if (eventFilters.Level != LogLevel.Nothing)
            {
                xPathQuery = xPathQuery + "(Level = " + ((int)eventFilters.Level).ToString() + ')';
                connector = true;
            }
            if (eventFilters.eventID > 0)
            {
                if (connector == true)
                {
                    xPathQuery = xPathQuery + " and ";
                }
                xPathQuery = xPathQuery + "(EventID = " + (eventFilters.eventID).ToString() + ')';
                connector = true;
            }
            if (eventFilters.fromDate != null)
            {
                if (connector == true)
                {
                    xPathQuery = xPathQuery + " and ";
                }

                xPathQuery = xPathQuery + "(TimeCreated[(@SystemTime >= '" + eventFilters.fromDate.Value.ToUniversalTime().ToString("o") + "')])";
                connector = true;
            }
            if (eventFilters.toDate != null)
            {
                if (eventFilters.fromDate != null && eventFilters.fromDate.Value != eventFilters.toDate.Value)
                {
                    if (connector == true)
                    {
                        xPathQuery = xPathQuery + " and ";
                    }
                    xPathQuery = xPathQuery + "(TimeCreated[(@SystemTime <=  '" + eventFilters.toDate.Value.ToUniversalTime().ToString("o") + "')])";
                    connector = true;
                }
            }

            xPathQuery = xPathQuery + "]]";

            return xPathQuery;

        }