Exemplo n.º 1
0
        /// <summary>
        /// Unload the project layout.
        /// </summary>
        public void UnloadLayout()
        {
            // Un-register element events
            foreach (ElementBase element in this.Elements.Values)
            {
                if (ElementBase.IsAccessoryElement(element))
                {
                    ((IAccessory)element).AccessoryStatusChanged -= OnAccessoryStatusChanged;
                }
                if (ElementBase.IsFeedbackElement(element))
                {
                    ((IFeedback)element).FeedbackStatusChanged -= OnFeedbackStatusChanged;
                }
                element.ImageChanged -= OnBlockImageChanged;
            }

            // Initializations
            this.Panels           = new Dictionary <int, SwitchboardPanel>();
            this.AccessoryModules = new Dictionary <int, ControlModule>();
            this.SensorModules    = new Dictionary <int, ControlModule>();
            this.Elements         = new Dictionary <int, ElementBase>();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Ensure that the database exists and have the latest schema.
        /// </summary>
        public void LoadLayout()
        {
            try
            {
                // Initializations
                this.UnloadLayout();

                // Load all control modules
                foreach (ControlModule module in OTCContext.Layout.ControlModuleManager.GetAll())
                {
                    switch (module.Type)
                    {
                    case ControlModule.ModuleType.Accessory:
                        this.AccessoryModules.Add(module.ID, module);
                        break;

                    case ControlModule.ModuleType.Sensor:
                        this.SensorModules.Add(module.ID, module);
                        break;
                    }
                }

                // Load all panels
                foreach (SwitchboardPanel panel in OTCContext.Layout.SwitchboardPanelManager.GetAll())
                {
                    this.Panels.Add(panel.ID, panel);
                }

                // Load all elements
                foreach (ElementBase element in OTCContext.Layout.ElementManager.GetAll())
                {
                    this.Elements.Add(element.ID, element);

                    if (this.Panels.ContainsKey(element.SwitchboardPanel.ID))
                    {
                        element.SwitchboardPanel = this.Panels[element.SwitchboardPanel.ID];
                        element.SwitchboardPanel.Elements.Add(element);
                    }
                }

                // Load elements to switchboard panels
                foreach (ElementBase element in this.Elements.Values)
                {
                    // Get all element actions
                    element.Actions = OTCContext.Layout.ElementActionManager.GetByElement(element.ID);

                    // Get all element accessory connections
                    element.AccessoryConnections = OTCContext.Layout.ControlModuleConnectionManager.GetByElement(element, ControlModule.ModuleType.Accessory);
                    foreach (ControlModuleConnection connection in element.AccessoryConnections)
                    {
                        if (connection != null)
                        {
                            if (this.AccessoryModules.ContainsKey(connection.DecoderID))
                            {
                                connection.Decoder = this.AccessoryModules[connection.DecoderID];
                            }
                            else
                            {
                                Logger.LogWarning(this,
                                                  "Accessory control module #{0} not found for connection #{1}.",
                                                  connection.DecoderID, connection.ID);
                            }
                        }
                    }

                    // Get all element sensor connections
                    element.FeedbackConnections = OTCContext.Layout.ControlModuleConnectionManager.GetByElement(element, ControlModule.ModuleType.Sensor);
                    foreach (ControlModuleConnection connection in element.FeedbackConnections)
                    {
                        if (connection != null)
                        {
                            if (this.SensorModules.ContainsKey(connection.DecoderID))
                            {
                                connection.Decoder = this.SensorModules[connection.DecoderID];
                            }
                            else
                            {
                                Logger.LogWarning(this,
                                                  "Sensor module #{0} not found for connection #{1}.",
                                                  connection.DecoderID, connection.ID);
                            }
                        }
                    }
                }

                // Load routes
                foreach (Route route in OTCContext.Layout.RouteManager.GetAll())
                {
                    this.Routes.Add(route.ID, route);
                }

                // Register element events
                foreach (ElementBase element in this.Elements.Values)
                {
                    if (ElementBase.IsAccessoryElement(element))
                    {
                        ((IAccessory)element).AccessoryStatusChanged += OnAccessoryStatusChanged;
                    }
                    if (ElementBase.IsFeedbackElement(element))
                    {
                        ((IFeedback)element).FeedbackStatusChanged += OnFeedbackStatusChanged;
                    }
                    element.ImageChanged += OnBlockImageChanged;
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);

                throw;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Ensure that the database exists and have the latest schema.
        /// </summary>
        internal void LoadLayout()
        {
            try
            {
                // Initializations
                this.UnloadLayout();

                // Load all database objects
                this.Sounds.Add(OTCProject.LayoutManager.SoundDAO.GetAll());
                this.Devices.Add(OTCProject.LayoutManager.DeviceDAO.GetAll());
                this.DeviceConnections.Add(OTCProject.LayoutManager.DeviceConnectionDAO.GetAll());
                this.Switchboards.Add(OTCProject.LayoutManager.SwitchboardDAO.GetAll());
                this.Elements.Add(OTCProject.LayoutManager.ElementDAO.GetAll());
                this.ElementActions.Add(OTCProject.LayoutManager.ElementActionDAO.GetAll());
                this.Routes.Add(OTCProject.LayoutManager.RouteDAO.GetAll());

                // Load elements to switchboards
                foreach (ElementBase element in this.Elements)
                {
                    element.Switchboard         = this.Switchboards.Get(element.SwitchboardID);
                    element.Switchboard.Project = this;
                    element.Switchboard.Elements.Add(element);
                }

                // Load actions to elements
                foreach (ElementAction action in this.ElementActions)
                {
                    action.Element = this.Elements.Get(action.ElementID);
                    action.Element.Actions.Add(action);
                }

                // Load connections to accessory devices
                foreach (DeviceConnection conn in this.DeviceConnections)
                {
                    conn.Decoder = this.Devices.Get(conn.DecoderID);
                    conn.Element = this.Elements.Get(conn.ElementID);
                    conn.Decoder.Connections.Add(conn);
                }

                // Load elements to routes
                foreach (RouteElement re in this.RouteElements)
                {
                    re.Element = this.Elements.Get(re.ElementID);
                    re.Route   = this.Routes.Get(re.RouteID);
                }

                // Register element events
                foreach (ElementBase element in this.Elements)
                {
                    if (ElementBase.IsAccessoryElement(element))
                    {
                        ((IAccessory)element).AccessoryStatusChanged += OnAccessoryStatusChanged;
                    }
                    if (ElementBase.IsFeedbackElement(element))
                    {
                        ((IFeedback)element).FeedbackStatusChanged += OnFeedbackStatusChanged;
                    }
                    element.ImageChanged += OnBlockImageChanged;
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);

                throw;
            }
        }