private void BuildSessions(List <LogElementInfo> logElementInfos)
        {
            var dictSessions = new Dictionary <Guid, LRAPSession>();

            foreach (var logElementInfo in logElementInfos)
            {
                LRAPSession session = null;
                if (!dictSessions.TryGetValue(logElementInfo.SessionGUID, out session))
                {
                    session = new LRAPSession()
                    {
                        GUID = logElementInfo.SessionGUID
                    };
                    dictSessions.Add(logElementInfo.SessionGUID, session);
                }
                List <LRAPSessionElement> flows = null;

                var flowKey = LogTypeHelper.IsClientsideEvent(logElementInfo.LogType) ? LRAPSessionFlowType.Client : LRAPSessionFlowType.Server;
                if (!session.Flows.TryGetValue(flowKey, out flows))
                {
                    flows = new List <LRAPSessionElement>();
                    session.Flows.Add(flowKey, flows);
                }

                flows.Add(new LRAPSessionElement(session, logElementInfo));
            }

            Sessions = dictSessions.Values.ToList();
            SessionElementOrderedList = GetOrderedList(Sessions);
            var xxx = SessionElementOrderedList.Where(x => x.Any(y => y.LogElementInfo.LogType == LogType.OnKeyPress)).ToList();
        }
        public string GetToolTipMessage()
        {
            var sb = new StringBuilder();

            sb.AppendLine($"Session: {Session.GUID}");
            sb.AppendLine($"Clientside: {LogTypeHelper.IsClientsideEvent(LogElementInfo.LogType)}");
            sb.AppendLine($"LogType: {LogElementInfo.LogType}");
            return(sb.ToString());
        }
        public void Refresh()
        {
            if (this.Parent == null || Sessions == null)
            {
                return;
            }

            //Skal anvende minimum distance til at tegne resten

            //this.Visible = false;
            //this.SuspendLayout();
            this.Parent.SuspendLayout();
            this.RowCount = Sessions.SelectMany(x => x.Flows).Count() + 1; //plus footer for taking last space

            this.Controls.Clear();

            var row = 0;

            this.RowStyles.Clear();
            foreach (var session in Sessions)
            {
                if (session.Flows.ContainsKey(LRAPSessionFlowType.Server))
                {
                    this.Controls.Add(new Label()
                    {
                        Text = $"{session.GUID} ({LRAPSessionFlowType.Server}):", AutoSize = true
                    }, 0, row);
                    this.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
                    session.ServerRowIndex = row++;
                }

                if (session.Flows.ContainsKey(LRAPSessionFlowType.Client))
                {
                    this.Controls.Add(new Label()
                    {
                        Text = $"{session.GUID} ({LRAPSessionFlowType.Client}):", AutoSize = true
                    }, 0, row);
                    this.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
                    session.ClientRowIndex = row++;
                }
            }

            this.ColumnStyles.Clear();
            this.ColumnStyles.Add(new ColumnStyle()); //autosize for titles

            //PageIndex = 3 => 2
            //var numberOfPages = (SessionElementOrderedList.Count/PageElements) + 1;
            //SessionElementOrderedList.Count

            var numOfElements = SessionElementOrderedList.Count > (PageIndex + 1) * PageElements ? PageElements : SessionElementOrderedList.Count % PageElements;

            this.ColumnCount = numOfElements + 1 /*title*/ + 1 /*fillout*/;

            for (int c = 0; c < numOfElements; c++)
            {
                this.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 10));
            }

            var sessionDistincter = new HashSet <Guid>();

            int startIdx = PageElements * PageIndex;
            int endIdx   = startIdx + numOfElements - 1;
            int colorIdx = 0;
            int colIndex = 1; //skip title

            for (var idx = startIdx; idx <= endIdx; idx++)
            {
                var sessionElementsAtPosition = SessionElementOrderedList[idx];
                foreach (var sessionElement in sessionElementsAtPosition)
                {
                    var rowIndex = LogTypeHelper.IsClientsideEvent(sessionElement.LogElementInfo.LogType) ? sessionElement.Session.ClientRowIndex : sessionElement.Session.ServerRowIndex;

                    if (IsValidStartingEvent(sessionElement) && !sessionDistincter.Contains(sessionElement.Session.GUID))
                    {
                        sessionDistincter.Add(sessionElement.Session.GUID);

                        var btn = new Button();
                        btn.FlatStyle = FlatStyle.Flat;
                        btn.Margin    = new Padding(0);
                        btn.Size      = new System.Drawing.Size(10, 20);
                        btn.Text      = "";
                        btn.Image     = Resources.start;
                        btn.UseVisualStyleBackColor = true;
                        btn.Tag         = sessionElement;
                        btn.MouseHover += Panel_MouseHover;
                        btn.MouseLeave += Panel_MouseLeave;
                        btn.Click      += Btn_Click;
                        this.Controls.Add(btn, colIndex, rowIndex);
                    }
                    else
                    {
                        var panel = new Panel()
                        {
                            BackColor = GetColorByLogType(sessionElement.LogElementInfo.LogType), Margin = new Padding(0)
                        };
                        panel.MouseHover += Panel_MouseHover;
                        panel.MouseLeave += Panel_MouseLeave;
                        panel.Tag         = sessionElement;
                        this.Controls.Add(panel, colIndex, rowIndex);
                    }
                }
                colIndex++;
            }

            this.RowStyles.Add(new RowStyle());       //Fill out bottom
            this.ColumnStyles.Add(new ColumnStyle()); //Fill out the right

            this.AutoSize = true;
            this.Parent.ResumeLayout();
            //this.ResumeLayout();
            //this.Visible = true;
        }
        private List <List <LRAPSessionElement> > GetOrderedList(List <LRAPSession> sessions)
        {
            List <LRAPSessionElement> lstOrderedByTimestamp = new List <LRAPSessionElement>();

            foreach (var session in sessions)
            {
                foreach (var flowValues in session.Flows.Values)
                {
                    //Har brug for at gemme et columnIndex per LogElementInfo, men burde jo være en liste man enten appender til eller updatere den eksisterende column med den ekstra LogElementInfo

                    foreach (var sessionElement in flowValues)
                    {
                        //if (!CheckIfOrdered(lstOrderedByTimestamp))
                        //    throw new Exception("GRRR");

                        //int debug;
                        var idx = BinaryFindClosestIndex(lstOrderedByTimestamp, sessionElement.LogElementInfo.Timestamp);
                        if (sessionElement.LogElementInfo.LogType == LogType.OnKeyPress)
                        {
                            idx = idx + 1 - 1;
                        }
                        if (idx == -1)
                        {
                            lstOrderedByTimestamp.Add(sessionElement);
                            //debug = lstOrderedByTimestamp.Count - 1;
                        }
                        else
                        {
                            var otherSessionElement = lstOrderedByTimestamp[idx];
                            if (otherSessionElement.LogElementInfo.Timestamp > sessionElement.LogElementInfo.Timestamp)
                            {
                                lstOrderedByTimestamp.Insert(idx, sessionElement);
                                //debug = idx;
                            }
                            else
                            {
                                if (idx == lstOrderedByTimestamp.Count - 1)
                                {
                                    lstOrderedByTimestamp.Add(sessionElement);
                                    //debug = lstOrderedByTimestamp.Count - 1;
                                }
                                else
                                {
                                    lstOrderedByTimestamp.Insert(idx + 1, sessionElement);
                                    //debug = idx + 1;
                                }
                            }
                        }

                        //if (lstOrderedByTimestamp.Count > 1)
                        //{
                        //    LRAPSessionElement seBefore = debug - 1 >= 0 ? lstOrderedByTimestamp[debug - 1] : null;
                        //    LRAPSessionElement seAfter = debug + 1 < lstOrderedByTimestamp.Count ? lstOrderedByTimestamp[debug + 1] : null;
                        //    if (seBefore != null && seBefore.LogElementInfo.Timestamp > lstOrderedByTimestamp[debug].LogElementInfo.Timestamp)
                        //    {
                        //        MessageBox.Show("hmm before?");
                        //    }
                        //    if (seAfter != null && seAfter.LogElementInfo.Timestamp < lstOrderedByTimestamp[debug].LogElementInfo.Timestamp)
                        //    {
                        //        MessageBox.Show("hmm after?");
                        //    }
                        //}
                    }
                }
            }
            DateTime?lastTimestamp = null;
            bool?    lastIsClient  = null;

            List <List <LRAPSessionElement> > result = new List <List <LRAPSessionElement> >();
            List <LRAPSessionElement>         curr   = new List <LRAPSessionElement>();
            int orderedListIndex = 0;

            foreach (var sessionElement in lstOrderedByTimestamp)
            {
                if (lastTimestamp != null && (!lastTimestamp.Value.Equals(sessionElement.LogElementInfo.Timestamp) || lastIsClient.Value == LogTypeHelper.IsClientsideEvent(sessionElement.LogElementInfo.LogType)))
                {
                    result.Add(curr);
                    orderedListIndex++;
                    curr = new List <LRAPSessionElement>();
                }
                lastTimestamp        = sessionElement.LogElementInfo.Timestamp;
                lastIsClient         = LogTypeHelper.IsClientsideEvent(sessionElement.LogElementInfo.LogType);
                sessionElement.Index = orderedListIndex;
                sessionElement.State = SessionElementState.Waiting;
                curr.Add(sessionElement);
            }
            if (curr.Count > 0)
            {
                result.Add(curr);
            }

            return(result);
        }