public void DrawFlowChart()
 {
     foreach (var p in allParticipants)
     {
         ParticipantInfoBlock pInfoBlock = ConstructParticipantInfoBlock(p);
         allParticipantInfoBlock.Add(pInfoBlock);
         parentPanelToDisplayOn.Controls.Add(pInfoBlock);
         UpdateParticipantInfoPanelPosition(pInfoBlock);
     }
 }
        private ParticipantInfoBlock ConstructParticipantInfoBlock(Participant p)
        {
            ParticipantInfoBlock pInfoBlock = new ParticipantInfoBlock(p);
            int initialX = parentPanelToDisplayOn.Width;
            int initialY = parentPanelToDisplayOn.Top + (parentPanelToDisplayOn.Height / 2);

            pInfoBlock.Left = initialX;
            pInfoBlock.Top  = initialY;
            return(pInfoBlock);
        }
        public void UpdateParticipantInfoPanelPosition(ParticipantInfoBlock pInfo)
        {
            if (pInfo == null)
            {
                throw new NullReferenceException("Participant pInfo is null");
            }
            Participant updatedParticipantValue = allParticipants.Find(p => p.UserName == pInfo.CurrentParticipant.UserName);

            pInfo.CurrentParticipant = updatedParticipantValue;

            Block newPos = CalculateParticipantInfoPositionInGrid(pInfo.CurrentParticipant);

            newPos.IsOccupied = true;
            pInfo.block       = newPos;
            pInfo.UpdateBlockColor(newPos.BlockColor);
            pInfo.NewPosition = new Point(newPos.BlockPosition.X, newPos.BlockPosition.Y);
        }
        private void RearrangePartitionInfoBlocksInTheFlowChart()
        {
            if (allParticipants.Count > allParticipantInfoBlock.Count)
            {
                List <Participant> newParticipants = new List <Participant>();
                foreach (Participant participant in allParticipants)
                {
                    bool exists = allParticipantInfoBlock.FindIndex(p => p.CurrentParticipant.UserName == participant.UserName) >= 0;
                    if (!exists)
                    {
                        newParticipants.Add(participant);
                    }
                }

                //now construct the new participants
                foreach (Participant p in newParticipants)
                {
                    ParticipantInfoBlock pInfoBlock = ConstructParticipantInfoBlock(p);
                    allParticipantInfoBlock.Add(pInfoBlock);
                    parentPanelToDisplayOn.Controls.Add(pInfoBlock);
                }
            }


            //since after queue position changes for participants, their info position needs to be changed
            //to do that set all blocks occupy property to false so that all the blocks are available
            //and rearrange the allParticipantInfoBlock list order by desc
            foreach (ParticipantInfoBlock participantInfoBlock in allParticipantInfoBlock)
            {
                if (participantInfoBlock.block == null)
                {
                    participantInfoBlock.block = CalculateParticipantInfoPositionInGrid(participantInfoBlock.CurrentParticipant);
                }

                participantInfoBlock.block.IsOccupied   = false;
                participantInfoBlock.CurrentParticipant = allParticipants.Find(p => p.UserName == participantInfoBlock.CurrentParticipant.UserName);
            }

            allParticipantInfoBlock = allParticipantInfoBlock.OrderByDescending(item => item.CurrentParticipant.QueuePosition).ToList();

            foreach (ParticipantInfoBlock participantInfoBlock in allParticipantInfoBlock)
            {
                UpdateParticipantInfoPanelPosition(participantInfoBlock);
            }
        }