//private int BinaryFindClosestIndex(List<LRAPSessionElement> orderedLst, DateTime timestamp, int? start = null, int? end = null, long smallestTicksSoFar = long.MaxValue)
        //{
        //    start = start ?? 0;
        //    end = end ?? orderedLst.Count - 1;
        //    if (start > end) //empty list
        //        return -1;
        //    var m = (end.Value + start.Value) / 2;

        //    var newTicksPrev = long.MaxValue;
        //    var newTicksNext = long.MaxValue;
        //    if (m > 0)
        //        newTicksPrev = Math.Abs(orderedLst[m - 1].LogElementInfo.Timestamp.Ticks - timestamp.Ticks);
        //    if (m < orderedLst.Count - 1)
        //        newTicksNext = Math.Abs(orderedLst[m + 1].LogElementInfo.Timestamp.Ticks - timestamp.Ticks);
        //    var newTicks0 = Math.Abs(orderedLst[m].LogElementInfo.Timestamp.Ticks - timestamp.Ticks);
        //    if (newTicks0 < newTicksNext)
        //    {
        //        if (newTicks0 <= newTicksPrev || start == m) //Found the smallest in an ordered list
        //            return m;
        //        return BinaryFindClosestIndex(orderedLst, timestamp, start, m - 1, newTicks0);
        //    }
        //    if (newTicks0 <= newTicksPrev) //Go right
        //    {
        //        if (end == m)
        //            return m;
        //        return BinaryFindClosestIndex(orderedLst, timestamp, m + 1, end, newTicks0);
        //    }

        //    //newTicks0>=newTicksNext && newTicks0>=newTicksPrev
        //    //should not happen in an ordered list
        //    throw new Exception("Are you sure this is an ordered list?");
        //}

        private bool IsValidStartingEvent(LRAPSessionElement sessionElement)
        {
            return(sessionElement.LogElementInfo.LogType == LogType.OnPageRequest);
        }
        public FetchLogElementResponse FetchLogElement(Guid?sessionGUID, Guid?pageGUID, LogType logType, string handlerUrl = null, int?currentIndex = null)
        {
            currentIndex = currentIndex ?? CurrentIndex;

            if (SessionElementOrderedList.Count <= currentIndex.Value)
            {
                return new FetchLogElementResponse()
                       {
                           Type = FetchLogElementResponseType.NoMore
                       }
            }
            ;

            var lst = SessionElementOrderedList[currentIndex.Value];

            LRAPSessionElement sessionElement = null;

            if (sessionGUID.HasValue)
            {
                sessionElement = lst.FirstOrDefault(x => x.Session.GUID.Equals(sessionGUID));
            }
            if (sessionElement == null && pageGUID.HasValue)
            {
                sessionElement = lst.FirstOrDefault(x => x.LogElementInfo.PageGUID.Equals(pageGUID));
            }
            sessionElement = sessionElement ?? lst.First() /*Only one session is supported atm*/; //Skal være på samme linie som denne.. eller de efterfølgende "bundlede" events er ikke nødvendigvis på samme index

            switch (sessionElement.State)
            {
            case SessionElementState.Played:
                //Look at the next event if it matches the LogType for the current PageGUID
                return(FetchLogElement(sessionGUID, pageGUID, logType, handlerUrl, currentIndex.Value + 1));

            case SessionElementState.WaitingToTestIfCalledAutomatically:
            case SessionElementState.Playing:
                if (sessionElement.LogElementInfo.LogType == logType)
                {
                    var logElementDTO = OnLoadLogElement?.Invoke(sessionElement);

                    //"Element":"/TestHandler.ashx?request=%7B%22SomeValue%22%3A%22andersand%22%7D"
                    if (handlerUrl != null && logElementDTO.Element != handlerUrl)
                    {
                        throw new Exception($"LogType({logType}) was located, but with invalid url ({logElementDTO.Element}), should have been ({handlerUrl})");
                    }

                    sessionElement.LogElementInfo.GUID = logElementDTO.GUID;
                    return(new FetchLogElementResponse()
                    {
                        Type = FetchLogElementResponseType.OK, LogElementDTO = logElementDTO
                    });
                }
                return(new FetchLogElementResponse()
                {
                    Type = FetchLogElementResponseType.IncorrectLogType
                });

            //throw new Exception("Shouldn't happen, unless the running events are in a different order now");
            case SessionElementState.Waiting:
                throw new Exception("Shouldn't happen");

            default:
                throw new NotImplementedException();
            }
        }
Example #3
0
 private LogElementDTO EventsTable1_OnLoadLogElement(LRAPSessionElement element)
 {
     return(LoggingHelper.LoadElement(LRAPLogType.JSON, element.LogElementInfo));
 }