public DevicePanel(Data.DeviceModel model)
        {
            InitializeComponent();
            DataContext = this;

            _deviceId = model.DeviceId;
            Model     = model;

            UpdateModel(model);
        }
        private void UpdateModel(Data.DeviceModel model)
        {
            if (model != null)
            {
                StatusPanels.Clear();

                if (model.Connection != null)
                {
                    Address = model.Connection.Address;
                    Port    = model.Connection.Port;
                }

                ID                 = model.Id;
                DeviceName         = model.Name;
                DeviceManufacturer = model.Manufacturer;
                DeviceModel        = model.Model;
                DeviceSerial       = model.SerialNumber;
                DeviceDescription  = !string.IsNullOrEmpty(model.Description) ? model.Description.Trim() : null;


                var dataItems = model.GetDataItems();

                Data.DataItem execution      = null;
                Data.DataItem controllerMode = null;

                bool multipleStatuses = false;

                // Find Availability
                var avail = model.GetDataItems().Find(o => o.Type == "AVAILABILITY");

                // Find Functional Mode
                var functionalMode = model.GetDataItems().Find(o => o.Type == "FUNCTIONAL_MODE");

                // Find Emergency Stop
                var estop = model.GetDataItems().Find(o => o.Type == "EMERGENCY_STOP");

                // Add Alarm Conditions
                dataItemIds.AddRange(model.GetDataItems().FindAll(o => o.Category == "CONDITION").Select(o => o.Id));

                // Get Paths
                var paths = model.GetComponents().FindAll(o => o.Type == "Path");
                if (paths != null && paths.Count > 1)
                {
                    foreach (var path in paths)
                    {
                        if (path.DataItems != null && path.DataItems.Exists(o => o.Type == "EXECUTION"))
                        {
                            multipleStatuses = true;

                            // Create a new StatusPanel control
                            var statusPanel = new StatusPanel(DeviceId, path);
                            if (avail != null)
                            {
                                statusPanel.AvailabilityId = avail.Id;
                            }
                            if (estop != null)
                            {
                                statusPanel.EmergencyStopId = estop.Id;
                            }
                            dataItemIds.AddRange(statusPanel.GetIds());
                            StatusPanels.Add(statusPanel);
                        }
                    }
                }

                if (!multipleStatuses)
                {
                    execution      = model.GetDataItems().Find(o => o.Type == "EXECUTION");
                    controllerMode = model.GetDataItems().Find(o => o.Type == "CONTROLLER_MODE");

                    if (execution != null || controllerMode != null)
                    {
                        var statusPanel = new StatusPanel();
                        statusPanel.DeviceId = DeviceId;

                        var obj = model.GetDataItems().Find(o => o.Type == "EXECUTION");
                        if (obj != null)
                        {
                            statusPanel.ExecutionId = obj.Id;
                        }

                        obj = model.GetDataItems().Find(o => o.Type == "CONTROLLER_MODE");
                        if (obj != null)
                        {
                            statusPanel.ControllerModeId = obj.Id;
                        }

                        // Get Alarm Condition IDs
                        statusPanel.AlarmIds.AddRange(model.GetDataItems().FindAll(o => o.Category == "CONDITION").Select(o => o.Id));

                        // Get Program ID
                        obj = model.GetDataItems().Find(o => o.Type == "PROGRAM" && string.IsNullOrEmpty(o.SubType));
                        if (obj != null)
                        {
                            statusPanel.ProgramNameId = obj.Id;
                        }

                        // Get Message
                        obj = model.GetDataItems().Find(o => o.Type == "MESSAGE");
                        if (obj != null)
                        {
                            statusPanel.MessageId = obj.Id;
                        }

                        // Feedrate Override
                        obj = model.GetDataItems().Find(o => (o.Type == "PATH_FEEDRATE_OVERRIDE" && o.SubType == "PROGRAMMED") || (o.Type == "PATH_FEEDRATE" && o.Units == "PERCENT"));
                        if (obj != null)
                        {
                            statusPanel.FeedrateOverrideId = obj.Id;
                        }

                        paths = model.GetComponents().FindAll(o => o.Type == "Path");
                        foreach (var path in paths)
                        {
                            statusPanel.PathPanels.Add(new PathPanel(path));
                        }

                        if (avail != null)
                        {
                            statusPanel.AvailabilityId = avail.Id;
                        }
                        if (estop != null)
                        {
                            statusPanel.EmergencyStopId = estop.Id;
                        }
                        dataItemIds.AddRange(statusPanel.GetIds());
                        StatusPanels.Add(statusPanel);
                    }
                }


                if (samplesStream != null)
                {
                    samplesStream.DataItemIds = dataItemIds.ToArray();
                }
            }
        }