Beispiel #1
0
        /// <summary>
        /// Done
        /// </summary>
        /// <param name="array"></param>
        /// <param name="text"></param>
        private void AddToIndex(HashSet <string> array, string text)
        {
            List <string> Event = SplitText(text);

            if (Event.Count < 13)
            {
                return;
            }

            int    index       = Event[0].Replace("Event[", "").Replace("]:", "").ToInt();
            string description = GetDescription(Event);
            string date        = Event[3].Replace("Date: ", "");

            if (array.Add(date + ", " + description))
            {
                EventLog @event = new EventLog
                {
                    Id          = index.ToString(),
                    Date        = date,
                    Description = description,
                    Log         = text
                };
                Eventlogs.Add(@event);
            }

            Events.Add(text);
        }
        /// <summary>
        /// Filter events on date
        /// </summary>
        /// <returns>List of non-duplicate events</returns>
        private List <EventLog> FilterOnDate()
        {
            List <EventLog> results = new List <EventLog>();
            EventLog        start   = new EventLog();
            EventLog        end     = new EventLog();

            // Get the first match with DateStart
            if (!Keyword.DateStart.IsEmpty())
            {
                start = FindClosestMatchingEvent(Keyword.DateStart);
            }
            // Get the first match with DateEnd
            if (!Keyword.DateEnd.IsEmpty())
            {
                end = FindClosestMatchingEvent(Keyword.DateEnd);
            }

            if (start.Id == null && end.Id != null)
            {
                // Get the range
                var x = Eventlogs.ToList();
                results = x.GetRange(0, end.GetId());
            }

            if (start.Id != null && end.Id == null)
            {
                // Get the range
                results = Eventlogs.ToList().GetRange(start.GetId(), ((Eventlogs.Count - 1) - start.GetId()));
            }

            if (start.Id != null && end.Id != null)
            {
                // Get the range
                if (start.GetId() < end.GetId())
                {
                    results = Eventlogs.ToList().GetRange(start.GetId(), ((end.GetId() - 1) - start.GetId()));
                }
            }

            return(results.Distinct().ToList());
        }
        private EventLog FindClosestMatchingEvent(string eventDate)
        {
            SortedList <long, EventLog> data = new SortedList <long, EventLog>();
            EventLog?eventLog = null;

            Eventlogs.ForEach(e =>
            {
                if (e.Date.Contains(eventDate))
                {
                    eventLog = e;
                }

                long result = eventDate.ToDate().Ticks - e.Date.ToDate().Ticks;

                if (!data.ContainsKey(result))
                {
                    data.Add(result, e);
                }
            });

            return(eventLog is EventLog log ? log : data.First().Value);
        }