Example #1
0
        /// <summary>
        /// Raised when a controller reference is removed.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">The event argument.</param>
        public void OnControllerRemoved(object sender, ControllerReferenceChangedEventArgs e)
        {
            //Can't use foreach as collection is updated inside
            for (int i = 0; i < myComponents.Count; ++i)
            {
                SmartComponent myComponent = myComponents[i];
                //Test if component exists as no OnUnLoad event exists.
                if ((myComponent.ContainingProject == null) ||
                    (myComponent.ContainingProject.GetObjectFromUniqueId(myComponent.UniqueId) == null) ||
                    (myComponent.ContainingProject.Name == ""))
                {
                    Logger.AddMessage("RSMoveMecha: Remove old Component " + myComponent.Name + " from cache.", LogMessageSeverity.Information);
                    myComponents.Remove(myComponent);
                    --i;
                    continue;
                }

                string guid = ((string)myComponent.Properties["Controller"].Value).Split(' ')[0];
                if (guid != "")
                {
                    Guid systemId = new Guid(guid);
                    if (e.Controller.SystemId == systemId)
                    {
                        Logger.AddMessage("RSMoveMecha: Disconnecting Component " + myComponent.Name, LogMessageSeverity.Information);
                        myComponent.Properties["Status"].Value = "Disconnected";
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Raised when a controller reference is added.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">The event argument.</param>
        public void OnControllerAdded(object sender, ControllerReferenceChangedEventArgs e)
        {
            //Can't use foreach as collection is updated inside
            for (int i = 0; i < myComponents.Count; ++i)
            {
                SmartComponent myComponent = myComponents[i];
                //Test if component exists as no OnUnLoad event exists.
                if ((myComponent.ContainingProject == null) ||
                    (myComponent.ContainingProject.GetObjectFromUniqueId(myComponent.UniqueId) == null) ||
                    (myComponent.ContainingProject.Name == ""))
                {
                    Logger.AddMessage("RSMoveMecha: Remove old Component " + myComponent.Name + " from cache.", LogMessageSeverity.Information);
                    myComponents.Remove(myComponent);
                    --i;
                    continue;
                }

                string guid = ((string)myComponent.Properties["Controller"].Value).Split(' ')[0];
                if (guid != "")
                {
                    Guid systemId = new Guid(guid);
                    if (e.Controller.SystemId == systemId)
                    {
                        Logger.AddMessage("RSMoveMecha: Connecting Component " + myComponent.Name, LogMessageSeverity.Information);
                        if (GetController(myComponent) != null)
                        {
                            myComponent.Properties["Status"].Value = "Connected";
                        }
                    }
                }
                string allowedValues = (string)myComponent.Properties["Controller"].Attributes["AllowedValues"].ToString();
                if (!allowedValues.Contains(e.Controller.SystemId.ToString()))
                {
                    allowedValues += (";" + e.Controller.SystemId.ToString() + " (" + e.Controller.RobControllerConnection.ToString() + ")");
                }
                if (allowedValues == "")
                {
                    allowedValues = ";Update";
                }
                myComponent.Properties["Controller"].Attributes["AllowedValues"] = allowedValues;
            }
        }