private void updateFlags()
        {
            var jointTypes = Enum.GetValues(typeof(JointType));

            // Copy session workers so iteration doesnt break the collection
            SessionWorker[] workers = new SessionWorker[_sessionManager.OpenConnections.Count];
            _sessionManager.OpenConnections.CopyTo(workers);

            foreach (SessionWorker sw in workers)
            {
                // Get the port and IP of this session
                string id = sw.Ip + ":" + sw.Port.ToString();

                // Copy the flags
                ConfigFlags flags = sw.ConfigFlags;

                // Get the list of active joints
                List <string> jointList = new List <string>();
                foreach (JointType jt in jointTypes)
                {
                    if (flags.JointFlags[jt])
                    {
                        jointList.Add(jt.ToString());
                    }
                }

                // If this session already exists update the flags
                if (_localSessions.Exists(tab => tab.Header == id))
                {
                    _localSessions.Find(tab => tab.Header.Equals(id)).displayFlags = flags.JointFlags;
                    _localSessions.Find(tab => tab.Header.Equals(id)).Items        = jointList;
                    _localSessions.Find(tab => tab.Header.Equals(id)).Active       = true;
                }
                else
                {
                    TabData tabData = new TabData(id, jointList, flags.JointFlags, true);
                    _localSessions.Add(tabData);
                }
            }
            updateTabs();
        }
        private void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
        {
            var reference = e.FrameReference.AcquireFrame();

            // Draw the Image from the Camera
            using (var frame = reference.ColorFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    XAMLImage.Source = frame.ToBitmap();
                }
            }

            // Acquire skeleton data as well
            using (var frame = reference.BodyFrameReference.AcquireFrame())
            {
                if (frame == null)
                {
                    return;
                }

                XAMLCanvas.Children.Clear();

                _bodies = new Body[frame.BodyFrameSource.BodyCount];

                frame.GetAndRefreshBodyData(_bodies);

                foreach (var body in _bodies)
                {
                    if (body == null || !body.IsTracked)
                    {
                        continue;
                    }

                    IReadOnlyDictionary <JointType, Joint> joints = body.Joints;

                    // convert the joint points to depth (display) space
                    Dictionary <JointType, Point> alignedJointPoints = new Dictionary <JointType, Point>();

                    foreach (JointType jointType in joints.Keys)
                    {
                        // sometimes the depth(Z) of an inferred joint may show as negative
                        // clamp down to 0.1f to prevent coordinatemapper from returning (-Infinity, -Infinity)
                        CameraSpacePoint position = joints[jointType].Position;
                        if (position.Z < 0)
                        {
                            position.Z = 0.01f;
                        }

                        ColorSpacePoint colorPoint = _coordinateMapper.MapCameraPointToColorSpace(position);

                        alignedJointPoints[jointType] = new Point(colorPoint.X, colorPoint.Y);
                    }

                    TabData ti = tabControl.SelectedItem as TabData;
                    if (ti != null)
                    {
                        string id = ti.Header;
                        XAMLCanvas.DrawSkeleton(body, alignedJointPoints, _localSessions[_localSessions.IndexOf(ti)].displayFlags);
                    }
                    else
                    {
                        var jointTypes = Enum.GetValues(typeof(JointType));
                        Dictionary <JointType, bool> displayFlags = new Dictionary <JointType, bool>();
                        foreach (JointType jt in jointTypes)
                        {
                            displayFlags[jt] = true;
                        }
                        XAMLCanvas.DrawSkeleton(body, alignedJointPoints, displayFlags);
                    }
                }
            }
        }