public static void ParseSmartObject(XElement child, ClassBuilder rootBuilder)
        {
            if (child == null || rootBuilder == null)
            {
                return;
            }
            var builder = new ClassBuilder(ClassType.SmartObject)
            {
                ClassName = $"{child?.Element("ObjectName")?.Value ?? ""}",
                Namespace = rootBuilder.Namespace
            };

            var props = child?.Element("Properties");

            if (ushort.TryParse(props?.Element("ControlJoin").Value, out var controlJoin))
            {
                builder.SmartJoin = controlJoin;
            }

            if (ushort.TryParse(props?.Element("DigitalEnableJoin")?.Value, out var enableJoin) && enableJoin > 0)
            {
                builder.AddJoin(new JoinBuilder(enableJoin, 0, "IsEnabled", JoinType.Digital, JoinDirection.ToPanel));
            }
            else if (ushort.TryParse(props?.Element("EnableDigitalJoin")?.Value, out var enableJoin2) && enableJoin2 > 0)
            {
                builder.AddJoin(new JoinBuilder(enableJoin2, 0, "IsEnabled", JoinType.Digital, JoinDirection.ToPanel));
            }

            if (ushort.TryParse(props?.Element("DigitalVisibilityJoin")?.Value, out var visibilityJoin) && visibilityJoin > 0)
            {
                builder.AddJoin(new JoinBuilder(visibilityJoin, 0, "IsVisible", JoinType.Digital, JoinDirection.ToPanel));
            }
            else if (ushort.TryParse(props?.Element("VisibilityDigitalJoin")?.Value, out var visibilityJoin2) && visibilityJoin2 > 0)
            {
                builder.AddJoin(new JoinBuilder(visibilityJoin2, 0, "IsVisible", JoinType.Digital, JoinDirection.ToPanel));
            }

            var joinProps = props?.Elements().Where(e => e.Attribute("Type")?.Value == "JoinCommand");

            if (joinProps != null)
            {
                foreach (var j in joinProps)
                {
                    var joinTypeText = j?.Element("JoinType")?.Value;
                    var joinName     = SanitizeSignalName(j?.Element("SignalName")?.Value ?? "");
                    _ = ushort.TryParse(j?.Element("JoinNumber")?.Value, out var joinNumber);
                    var isIn  = false;
                    var isOut = false;
                    if (j?.Element("Direction") != null && j.Element("Direction").Value.Contains("In"))
                    {
                        isIn = true;
                    }
                    if (j?.Element("Direction") != null && j.Element("Direction").Value.Contains("Out"))
                    {
                        isOut = true;
                    }


                    var joinType = JoinType.Analog;
                    if (joinTypeText == "Serial")
                    {
                        joinType = JoinType.Serial;
                    }
                    else if (joinTypeText == "Digital")
                    {
                        joinType = JoinType.Digital;
                    }

                    var joinDirection = JoinDirection.ToPanel;
                    if (isIn && isOut)
                    {
                        joinDirection = JoinDirection.Both;
                    }
                    else if (isIn && !isOut)
                    {
                        joinDirection = JoinDirection.ToPanel;
                    }
                    else if (!isIn && isOut)
                    {
                        joinDirection = JoinDirection.FromPanel;
                    }

                    if (j?.Name?.LocalName?.Contains("Button") ?? false)
                    {
                        if (joinType == JoinType.Digital)
                        {
                            joinType = JoinType.SmartDigitalButton;
                        }
                    }

                    if (!string.IsNullOrEmpty(joinName))
                    {
                        builder.AddJoin(
                            new JoinBuilder(joinNumber, builder.SmartJoin, joinName, joinType, joinDirection));
                    }
                }
            }

            //Check for specific type overrides and parse separately.
            if (child?.Element("TargetControl")?.Value == "SubpageReference_List" && props != null)
            {
                SubpageReferenceListParser.Parse(props, builder);
                rootBuilder.AddControl(builder);
                return;
            }


            joinProps = props?.Elements().Where(e => e.Attribute("Type")?.Value == "EncapsulatedJoin");

            if (joinProps != null)
            {
                foreach (var j in joinProps)
                {
                    var joinTypeText = j?.Element("JoinType")?.Value;
                    _ = ushort.TryParse(j?.Element("JoinNumber")?.Value, out var joinNumber);
                    var isIn    = false;
                    var isOut   = false;
                    var inName  = "";
                    var outName = "";
                    if (j?.Element("Direction") != null && j.Element("Direction").Value.Contains("In"))
                    {
                        isIn   = true;
                        inName = SanitizeSignalName(j?.Element("InCueName")?.Value ?? "");
                    }
                    if (j?.Element("Direction") != null && j.Element("Direction").Value.Contains("Out"))
                    {
                        isOut   = true;
                        outName = SanitizeSignalName(j?.Element("OutCueName")?.Value ?? "");
                    }


                    var joinType = JoinType.Analog;
                    if (joinTypeText == "Serial")
                    {
                        joinType = JoinType.Serial;
                    }
                    else if (joinTypeText == "Digital")
                    {
                        joinType = JoinType.Digital;
                    }

                    var joinDirection = JoinDirection.ToPanel;
                    if (isIn && isOut)
                    {
                        joinDirection = JoinDirection.Both;
                    }
                    else if (isIn && !isOut)
                    {
                        joinDirection = JoinDirection.ToPanel;
                    }
                    else if (!isIn && isOut)
                    {
                        joinDirection = JoinDirection.FromPanel;
                    }

                    if (j?.Name?.LocalName?.Contains("Button") ?? false)
                    {
                        if (joinType == JoinType.Digital)
                        {
                            joinType = JoinType.SmartDigitalButton;
                        }
                    }

                    if (!string.IsNullOrEmpty(inName))
                    {
                        if (inName != outName)
                        {
                            builder.AddJoin(
                                new JoinBuilder(joinNumber, builder.SmartJoin, inName, joinType, joinDirection)
                            {
                                ChangeEventName = outName
                            });
                        }
                        else
                        {
                            builder.AddJoin(
                                new JoinBuilder(joinNumber, builder.SmartJoin, inName, joinType, joinDirection));
                        }
                    }
                    else if (!string.IsNullOrEmpty(outName))
                    {
                        builder.AddJoin(
                            new JoinBuilder(joinNumber, builder.SmartJoin, outName, joinType, joinDirection));
                    }
                }
            }

            if (((child?.Element("TargetControl")?.Value.Contains("List") ?? false) || (child?.Element("TargetControl")?.Value.Contains("Tab_Button") ?? false)) && props != null)
            {
                var groupElement = GetEncapsulatedGroupJoins(props);
                if (groupElement != null)
                {
                    var listElementName = groupElement?.Name?.LocalName.Remove(groupElement.Name.LocalName.Length - 1, 1);

                    var itemCount = ushort.Parse(groupElement?.Elements().Where(e => e.Name.LocalName.ToUpperInvariant().Contains("COUNT"))?.FirstOrDefault()?.Value ?? "0", NumberFormatInfo.InvariantInfo);

                    if (itemCount == 0)
                    {
                        if (!ushort.TryParse(groupElement?.Parent?.Elements().Where(e => e.Name.LocalName.ToUpperInvariant().Contains("COUNT"))?.FirstOrDefault()?.Value, out itemCount))
                        {
                            return;
                        }
                    }

                    var itemBuilder = new ClassBuilder(ClassType.SrlElement)
                    {
                        SmartJoin = builder.SmartJoin
                    };

                    var groupJoins    = GetEncapsulatedGroupJoins(props)?.Elements();
                    var isDynamicList = false;
                    if (groupJoins != null)
                    {
                        if (groupJoins?.FirstOrDefault()?.Element("InCueName") != null)
                        {
                            isDynamicList = true;
                            foreach (var j in groupJoins)
                            {
                                var inName      = j?.Element("InCueName")?.Value ?? "";
                                var outName     = j?.Element("OutCueName")?.Value ?? "";
                                var isIn        = j?.Element("Direction")?.Value.Contains("In") ?? false;
                                var isOut       = j?.Element("Direction")?.Value.Contains("Out") ?? false;
                                var startJoin   = ushort.Parse(j?.Element("StartJoinNumber")?.Value ?? "0", NumberFormatInfo.InvariantInfo);
                                var jt          = j?.Element("JoinType")?.Value ?? "";
                                var inJoinType  = JoinType.None;
                                var outJoinType = JoinType.None;
                                if (jt == "Digital")
                                {
                                    inJoinType  = JoinType.SmartDigital;
                                    outJoinType = JoinType.SmartDigital;
                                }
                                else if (jt == "Analog")
                                {
                                    inJoinType  = JoinType.SmartAnalog;
                                    outJoinType = JoinType.SmartAnalog;
                                }
                                else if (jt == "Serial")
                                {
                                    inJoinType  = JoinType.SmartSerial;
                                    outJoinType = JoinType.SmartSerial;
                                }

                                if (inName.StartsWith("Set Item %i ", StringComparison.InvariantCulture))
                                {
                                    inName = inName.Replace("Set Item %i ", "");
                                }
                                else if (inName.StartsWith("Item %i ", StringComparison.InvariantCulture))
                                {
                                    inName = inName.Replace("Item %i ", "Is");
                                }

                                if (inName.StartsWith("In") && !inName.Contains("Checked"))
                                {
                                    inName = inName.Remove(0, 2);
                                }

                                inName = SanitizeSignalName(inName);

                                if (outName.StartsWith("Item %i ", StringComparison.InvariantCulture))
                                {
                                    outName = outName.Replace("Item %i ", "");
                                }

                                if (outName.ToUpperInvariant().Contains("PRESSED") || outName.ToUpperInvariant().Contains("RELEASED"))
                                {
                                    if (outJoinType == JoinType.SmartDigital)
                                    {
                                        outJoinType = JoinType.SmartDigitalButton;
                                        outName     = string.Empty;
                                    }
                                }

                                if (outName.StartsWith("In") && !outName.Contains("Checked"))
                                {
                                    outName = outName.Remove(0, 2);
                                }

                                outName = SanitizeSignalName(outName);

                                var joinDirection = JoinDirection.Unknown;

                                if (isIn && !isOut)
                                {
                                    joinDirection = JoinDirection.ToPanel;
                                }
                                else if (!isIn && isOut)
                                {
                                    joinDirection = JoinDirection.FromPanel;
                                }
                                else if (isIn && isOut)
                                {
                                    joinDirection = JoinDirection.Both;
                                }

                                if (joinDirection == JoinDirection.Both || joinDirection == JoinDirection.ToPanel)
                                {
                                    itemBuilder.AddJoin(
                                        new JoinBuilder(startJoin, itemBuilder.SmartJoin, inName, inJoinType, JoinDirection.ToPanel));
                                }

                                if (joinDirection == JoinDirection.Both || joinDirection == JoinDirection.FromPanel)
                                {
                                    itemBuilder.AddJoin(
                                        new JoinBuilder(startJoin, itemBuilder.SmartJoin, outName, outJoinType, JoinDirection.FromPanel));
                                }
                            }
                        }
                        //else if (groupJoins?.FirstOrDefault()?.Element("SignalName") != null)
                        //{
                        //    foreach (var j in groupJoins)
                        //    {
                        //        var joinName = j?.Element("SignalName")?.Value ?? "";
                        //        var isIn = j?.Element("Direction")?.Value.Contains("In") ?? false;
                        //        var isOut = j?.Element("Direction")?.Value.Contains("Out") ?? false;
                        //        var joinNumber = ushort.Parse(j?.Element("JoinNumber")?.Value ?? "0", NumberFormatInfo.InvariantInfo);
                        //        var jt = j?.Element("JoinType")?.Value ?? "";
                        //        var joinType = JoinType.None;

                        //        if (jt == "Digital")
                        //        {
                        //            joinType = JoinType.SmartDigital;
                        //        }
                        //        else if (jt == "Analog")
                        //        {
                        //            joinType = JoinType.SmartAnalog;
                        //        }
                        //        else if (jt == "Serial")
                        //        {
                        //            joinType = JoinType.SmartSerial;
                        //        }

                        //        var joinDirection = JoinDirection.Unknown;

                        //        if (isIn && !isOut)
                        //        {
                        //            joinDirection = JoinDirection.ToPanel;
                        //        }
                        //        else if (!isIn && isOut)
                        //        {
                        //            joinDirection = JoinDirection.FromPanel;
                        //        }
                        //        else if (isIn && isOut)
                        //        {
                        //            joinDirection = JoinDirection.Both;
                        //        }

                        //        if (joinName.ToUpperInvariant().Contains("PRESS") || joinName.ToUpperInvariant().Contains("CHECK"))
                        //        {
                        //            if (joinType == JoinType.Digital)
                        //            {
                        //                joinName = "";
                        //                joinType = JoinType.SmartDigitalButton;
                        //            }
                        //        }
                        //        else if (joinName.ToUpperInvariant().Contains("SELECT"))
                        //        {
                        //            joinName = "Selected";
                        //        }

                        //        if (j?.Name?.LocalName?.Contains("Button") ?? false)
                        //        {
                        //            if (joinType == JoinType.Digital)
                        //            {
                        //                joinType = JoinType.SmartDigitalButton;
                        //            }
                        //        }

                        //        joinName = SanitizeSignalName(joinName);

                        //        itemBuilder.AddJoin(
                        //            new JoinBuilder(joinNumber, itemBuilder.SmartJoin, joinName, joinType, joinDirection));
                        //    }
                        //}
                        else
                        {
                            if (groupJoins != null)
                            {
                                foreach (var j in groupJoins)
                                {
                                    var inName = j?.Element("SignalName")?.Value ?? "";

                                    if (string.IsNullOrEmpty(inName))
                                    {
                                        continue;
                                    }

                                    var isIn        = j?.Element("Direction")?.Value.Contains("In") ?? false;
                                    var isOut       = j?.Element("Direction")?.Value.Contains("Out") ?? false;
                                    var joinNumber  = ushort.Parse(j?.Element("JoinNumber")?.Value ?? "0", NumberFormatInfo.InvariantInfo);
                                    var jt          = j?.Element("JoinType")?.Value ?? "";
                                    var inJoinType  = JoinType.None;
                                    var outJoinType = JoinType.None;

                                    if (jt == "Digital")
                                    {
                                        inJoinType  = JoinType.SmartDigital;
                                        outJoinType = JoinType.SmartDigital;
                                    }
                                    else if (jt == "Analog")
                                    {
                                        inJoinType  = JoinType.SmartAnalog;
                                        outJoinType = JoinType.SmartAnalog;
                                    }
                                    else if (jt == "Serial")
                                    {
                                        inJoinType  = JoinType.SmartSerial;
                                        outJoinType = JoinType.SmartSerial;
                                    }

                                    if (inName.StartsWith("Set Item %i ", StringComparison.InvariantCulture))
                                    {
                                        inName = inName.Replace("Set Item %i ", "");
                                    }
                                    else if (inName.StartsWith("Item %i ", StringComparison.InvariantCulture))
                                    {
                                        inName = inName.Replace("Item %i ", "Is");
                                    }

                                    var joinDirection = JoinDirection.Unknown;

                                    if (isIn && !isOut)
                                    {
                                        joinDirection = JoinDirection.ToPanel;
                                    }
                                    else if (!isIn && isOut)
                                    {
                                        joinDirection = JoinDirection.FromPanel;
                                    }
                                    else if (isIn && isOut)
                                    {
                                        joinDirection = JoinDirection.Both;
                                    }

                                    var outName = inName;

                                    if (outName == "IsPressed" || outName == "IsChecked")
                                    {
                                        if (outJoinType == JoinType.SmartDigital)
                                        {
                                            outName     = "";
                                            outJoinType = JoinType.SmartDigitalButton;
                                        }
                                    }

                                    else if (inName.ToUpperInvariant().Contains("SELECT"))
                                    {
                                        inName = "Selected";
                                    }

                                    if (inName.StartsWith("Is") && !inName.Contains("Checked"))
                                    {
                                        inName = inName.Remove(0, 2);
                                    }

                                    if (outName.StartsWith("Is") && !outName.Contains("Checked"))
                                    {
                                        outName = outName.Remove(0, 2);
                                    }

                                    inName  = SanitizeSignalName(inName);
                                    outName = SanitizeSignalName(outName);

                                    if (inName == outName)
                                    {
                                        itemBuilder.AddJoin(
                                            new JoinBuilder(joinNumber, itemBuilder.SmartJoin, outName, outJoinType, joinDirection));
                                    }
                                    else
                                    {
                                        if (joinDirection == JoinDirection.Both || joinDirection == JoinDirection.ToPanel)
                                        {
                                            itemBuilder.AddJoin(
                                                new JoinBuilder(joinNumber, itemBuilder.SmartJoin, inName, inJoinType, JoinDirection.ToPanel));
                                        }

                                        if (joinDirection == JoinDirection.Both || joinDirection == JoinDirection.FromPanel)
                                        {
                                            itemBuilder.AddJoin(
                                                new JoinBuilder(joinNumber, itemBuilder.SmartJoin, outName, outJoinType, JoinDirection.FromPanel));
                                        }
                                    }
                                }
                            }
                        }

                        if (string.IsNullOrEmpty(itemBuilder.ClassName))
                        {
                            itemBuilder.ClassName = builder.ClassName + "Item";
                        }
                        else
                        {
                            itemBuilder.ClassName += "Item";
                        }
                        ListBuilder list;
                        if (isDynamicList)
                        {
                            list = new ListBuilder(itemBuilder, itemCount, 1, 1, 1);
                        }
                        else
                        {
                            list = new ListBuilder(itemBuilder, itemCount, 0, 0, 0);
                        }

                        if (list != null)
                        {
                            list.Name = props?.Parent?.Element("ObjectName")?.Value.Replace(" ", "") ?? "List";// + "Item" ?? "ListItem";
                            builder.AddList(list);
                        }
                    }
                }
            }

            CIPTagParser.ParseCIP(child, builder);
            rootBuilder.AddControl(builder);
        }
Exemplo n.º 2
0
        public static void ParseChildElement(XElement child, ClassBuilder rootBuilder)
        {
            if (rootBuilder == null)
            {
                throw new ArgumentNullException(nameof(rootBuilder));
            }

            if (child == null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            if (ushort.TryParse(child.Element("Properties")?.Element("ControlJoin")?.Value, out var result))
            {
                SmartObjectParser.ParseSmartObject(child, rootBuilder);
                return;
            }
            var isSubpageRefItem = rootBuilder.ClassType == ClassType.SrlElement;
            var builder          = new ClassBuilder(ClassType.Control)
            {
                ClassName = $"{(isSubpageRefItem ? rootBuilder.ClassName : "")}{child.Element("ObjectName")?.Value ?? ""}", NamespaceBase = rootBuilder.NamespaceBase
            };

            builder.DigitalOffset = rootBuilder.DigitalOffset;
            builder.AnalogOffset  = rootBuilder.AnalogOffset;
            builder.SerialOffset  = rootBuilder.SerialOffset;
            if (rootBuilder.SmartJoin > 0)
            {
                builder.SmartJoin = rootBuilder.SmartJoin;
            }

            CIPTagParser.ParseCIP(child, builder);

            var controlType = child?.Element("TargetControl").Value.ToUpperInvariant();

            if (child?.Element("Properties")?.Descendants().Count() > 0)
            {
                foreach (var e in child.Element("Properties").Descendants().
                         Where(e => e.Name.LocalName.ToUpperInvariant().Contains("JOIN") || e.Name.LocalName.ToUpperInvariant().Contains("FEEDBACK")))
                {
#pragma warning disable CA1308 // Normalize strings to uppercase
                    var name = e.Name.LocalName.ToLower(CultureInfo.InvariantCulture);
#pragma warning restore CA1308 // Normalize strings to uppercase
                    if (ushort.TryParse(e.Value, out var join) && join > 0)
                    {
                        if (name.StartsWith("digitalpresshigh", StringComparison.InvariantCulture))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "Raise", JoinType.DigitalButton, JoinDirection.FromPanel));
                        }
                        else if (name.StartsWith("digitalpresslow", StringComparison.InvariantCulture))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "Lower", JoinType.DigitalButton, JoinDirection.FromPanel));
                        }
                        else if (name.StartsWith("digitalpress", StringComparison.InvariantCulture))
                        {
                            if (child.Element("Properties")?.Element("ShowSelectFeedback")?.Value == "true")
                            {
                                builder.AddJoin(
                                    new JoinBuilder(join, builder.SmartJoin, $"IsActive", JoinType.Digital, JoinDirection.ToPanel));
                            }

                            builder.AddJoin(new JoinBuilder(join, builder.SmartJoin, $"", JoinType.DigitalButton, JoinDirection.FromPanel));
                        }
                        else if (name.StartsWith("digitalenable", StringComparison.InvariantCulture))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "IsEnabled", JoinType.Digital, JoinDirection.ToPanel));
                        }
                        else if (name.StartsWith("digitalvisibility", StringComparison.InvariantCulture) || name.StartsWith("visibility", StringComparison.InvariantCulture))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "IsVisible", JoinType.Digital, JoinDirection.ToPanel));
                        }
                        else if (name.StartsWith("digitalonoff", StringComparison.InvariantCulture))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "OnOffToggle", JoinType.DigitalButton, JoinDirection.FromPanel));
                        }
                        else if (name.StartsWith("butoffdigitalpress", StringComparison.InvariantCulture))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "Off", JoinType.DigitalButton, JoinDirection.FromPanel));
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "OffIsActive", JoinType.Digital, JoinDirection.ToPanel));
                        }
                        else if (name.StartsWith("butondigitalpress", StringComparison.InvariantCulture))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "On", JoinType.DigitalButton, JoinDirection.FromPanel));
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "OnIsActive", JoinType.Digital, JoinDirection.ToPanel));
                        }
                        else if (name.StartsWith("checkedstate", StringComparison.InvariantCulture))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "Toggle", JoinType.DigitalButton, JoinDirection.FromPanel));
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "IsChecked", JoinType.Digital, JoinDirection.ToPanel));
                        }
                        else if (name.StartsWith("indirecttext", StringComparison.InvariantCulture))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "Text", JoinType.Serial, JoinDirection.ToPanel));
                        }
                        else if (name.Contains("butonindirecttext"))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "OnText", JoinType.Serial, JoinDirection.ToPanel));
                        }
                        else if (name.Contains("butofindirecttext"))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "OffText", JoinType.Serial, JoinDirection.ToPanel));
                        }
                        else if (name.Contains("analogmode"))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "Mode", JoinType.Analog, JoinDirection.ToPanel));
                        }
                        else if (name == "analogchildpositionjoin")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "ChildPosition", JoinType.Analog, JoinDirection.ToPanel));
                        }
                        else if (name == "primarylabeljoin")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "LeftLabel", JoinType.Serial, JoinDirection.ToPanel));
                        }
                        else if (name == "primarychildlabeljoin")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "LeftChildLabel", JoinType.Serial, JoinDirection.ToPanel));
                        }
                        else if (name == "secondarylabeljoin")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "CenterLabel", JoinType.Serial, JoinDirection.ToPanel));
                        }
                        else if (name == "secondarychildlabeljoin")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "CenterChildLabel", JoinType.Serial, JoinDirection.ToPanel));
                        }
                        else if (name == "tertiarylabeljoin")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "RightLabel", JoinType.Serial, JoinDirection.ToPanel));
                        }
                        else if (name == "tertiarychildlabeljoin")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "RightChildLabel", JoinType.Serial, JoinDirection.ToPanel));
                        }
                        else if (name.Contains("digitalswipeup"))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "SwipedUp", JoinType.DigitalButton, JoinDirection.FromPanel));
                        }
                        else if (name.Contains("digitalswipedown"))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "SwipedDown", JoinType.DigitalButton, JoinDirection.FromPanel));
                        }
                        else if (name.Contains("digitalswipeleft"))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "SwipedLeft", JoinType.DigitalButton, JoinDirection.FromPanel));
                        }
                        else if (name.Contains("digitalswiperight"))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "SwipedRight", JoinType.DigitalButton, JoinDirection.FromPanel));
                        }
                        else if (name.StartsWith("analogfeedbackjoin1", StringComparison.InvariantCulture))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "LowValue", JoinType.Analog, JoinDirection.Both));
                        }
                        else if (name.StartsWith("analogfeedbackjoin2", StringComparison.InvariantCulture))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "HighValue", JoinType.Analog, JoinDirection.Both));
                        }
                        else if (name.StartsWith("analogminvalue", StringComparison.InvariantCulture))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "MinValue", JoinType.Analog, JoinDirection.ToPanel));
                        }
                        else if (name.StartsWith("analogmaxvalue", StringComparison.InvariantCulture))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "MaxValue", JoinType.Analog, JoinDirection.ToPanel));
                        }
                        else if (name.StartsWith("digitalanimation", StringComparison.InvariantCulture))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "IsAnimating", JoinType.Digital, JoinDirection.ToPanel));
                        }
                        else if (name.StartsWith("serialmode", StringComparison.InvariantCulture))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "Mode", JoinType.Analog, JoinDirection.ToPanel));
                        }
                        else if (name.StartsWith("enterkeypress", StringComparison.InvariantCulture))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "Enter", JoinType.DigitalButton, JoinDirection.FromPanel)
                            {
                                ChangeEventName = "Enter"
                            });
                        }
                        else if (name.StartsWith("esckeypress", StringComparison.InvariantCulture))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "Escape", JoinType.DigitalButton, JoinDirection.FromPanel)
                            {
                                ChangeEventName = "Escape"
                            });
                        }
                        else if (name == "serialjoin")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "TextOverride", JoinType.Serial, JoinDirection.ToPanel));
                        }
                        else if (name == "serialindirecttextjoin")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "Text", JoinType.Serial, JoinDirection.ToPanel));
                        }
                        else if (name == "serialoutputjoin")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "Text", JoinType.Serial, JoinDirection.FromPanel));
                        }
                        else if (name == "setfocusjoinon")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "SetFocus", JoinType.DigitalPulse, JoinDirection.ToPanel));

                            //var focuson = new PropertyElement($"Focus", join, builder.SmartJoin, JoinType.Digital, PropertyMethod.Void)
                            //{
                            //    ContentOverride = $"public void {child.Element("ObjectName").Value}Focus()\n\t{{\n\t\tPulse({join}, 100);"
                            //};
                            //builder.AddProperty(focuson);
                        }
                        else if (name == "setfocusjoinoff")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "RemoveFocus", JoinType.DigitalPulse, JoinDirection.ToPanel));

                            //var focusoff = new PropertyElement($"Focus", join, builder.SmartJoin, JoinType.Digital, PropertyMethod.Void)
                            //{
                            //    ContentOverride = $"public void {child.Element("ObjectName").Value}Unfocus()\n\t{{\n\t\tPulse({join}, 100);"
                            //};
                            //builder.AddProperty(focusoff);
                        }
                        else if (name == "hasfocusjoin")
                        {
                            //if ((child.Element("Properties")?.Element("SetFocusJoinOn")?.Value == "0" || string.IsNullOrEmpty(child.Element("Properties")?.Element("SetFocusJoinOn")?.Value)) && (child.Element("Properties")?.Element("SetFocusJoinOff")?.Value == "0" || string.IsNullOrEmpty(child.Element("Properties")?.Element("SetFocusJoinOff")?.Value)))
                            //{
                            //    var focus1 = new PropertyElement($"IsFocused", join, builder.SmartJoin, JoinType.Digital, PropertyMethod.Void)
                            //    {
                            //        ContentOverride = $"public void Focus()\n{{\n\tParentPanel.Pulse({(builder.SmartJoin > 0 ? builder.SmartJoin + ", " : "")}{join}, 100);\n}}"
                            //    };
                            //    builder.AddProperty(focus1);
                            //}
                            //builder.AddEvent(new EventElement($"IsFocusedChanged", join, builder.SmartJoin, JoinType.Digital));

                            var direction = JoinDirection.Both;

                            if ((child.Element("Properties")?.Element("SetFocusJoinOn")?.Value == "0" || string.IsNullOrEmpty(child.Element("Properties")?.Element("SetFocusJoinOn")?.Value)) && (child.Element("Properties")?.Element("SetFocusJoinOff")?.Value == "0" || string.IsNullOrEmpty(child.Element("Properties")?.Element("SetFocusJoinOff")?.Value)))
                            {
                                direction = JoinDirection.FromPanel;
                            }

                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "IsFocused", JoinType.Digital, direction));
                        }
                        else if (name == "prependtextjoin")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "PrependText", JoinType.SerialSet, JoinDirection.ToPanel));
                        }
                        else if (name == "appendtextjoin")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "AppendText", JoinType.Serial, JoinDirection.ToPanel));
                        }
                        else if (name == "serialgraphicsjoin")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "GraphicsPath", JoinType.Serial, JoinDirection.Both));
                        }
                        else if (name == "serialdynamicgraphicsjoin")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "GraphicsPath", JoinType.Serial, JoinDirection.Both));
                        }
                        else if (name == "serialdynamiciconjoin")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "IconName", JoinType.Serial, JoinDirection.ToPanel));
                        }
                        else if (name == "analogdynamiciconjoin")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "IconNumber", JoinType.Analog, JoinDirection.ToPanel));
                        }
                        else if (name == "analogredjoin")
                        {
                            if (controlType == "COLOR_CHIP")
                            {
                                builder.AddJoin(
                                    new JoinBuilder(join, builder.SmartJoin, "Red", JoinType.Analog, JoinDirection.ToPanel));
                            }
                            else
                            {
                                builder.AddJoin(
                                    new JoinBuilder(join, builder.SmartJoin, "Red", JoinType.Analog, JoinDirection.Both));
                            }
                        }
                        else if (name == "analoggreenjoin")
                        {
                            if (controlType == "COLOR_CHIP")
                            {
                                builder.AddJoin(
                                    new JoinBuilder(join, builder.SmartJoin, "Green", JoinType.Analog, JoinDirection.ToPanel));
                            }
                            else
                            {
                                builder.AddJoin(
                                    new JoinBuilder(join, builder.SmartJoin, "Green", JoinType.Analog, JoinDirection.Both));
                            }
                        }
                        else if (name == "analogbluejoin")
                        {
                            if (controlType == "COLOR_CHIP")
                            {
                                builder.AddJoin(
                                    new JoinBuilder(join, builder.SmartJoin, "Blue", JoinType.Analog, JoinDirection.ToPanel));
                            }
                            else
                            {
                                builder.AddJoin(
                                    new JoinBuilder(join, builder.SmartJoin, "Blue", JoinType.Analog, JoinDirection.Both));
                            }
                        }
                        else if (name.StartsWith("velocity", StringComparison.InvariantCulture))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, e.Name.LocalName.Replace("Join", ""), JoinType.Analog, JoinDirection.FromPanel));
                        }
                        else if (name.Contains("analogtouchfeedback"))
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, e.Name.LocalName.Replace("Feedback", ""), JoinType.Analog, JoinDirection.FromPanel));
                        }
                        else if (name == "holdjoin")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "Hold", JoinType.Digital, JoinDirection.FromPanel));
                        }
                        else if (name == "clickjoin")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "Click", JoinType.Digital, JoinDirection.FromPanel));
                        }
                        else if (name == "negxdigitaljoin" || name == "negydigitaljoin" || name == "posxdigitaljoin" || name == "posydigitaljoin")
                        {
                            var tempName = name == "negxdigitaljoin" ? "GestureLeft" :
                                           name == "negydigitaljoin" ? "GestureDown" :
                                           name == "posxdigitaljoin" ? "GestureRight" :
                                           name == "posydigitaljoin" ? "GestureUp" : "";

                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, tempName, JoinType.Digital, JoinDirection.FromPanel));
                        }
                        else if (name.Contains("analogfeedback") || name == "analogjoin")
                        {
                            builder.AddJoin(
                                new JoinBuilder(join, builder.SmartJoin, "Value", JoinType.Analog, JoinDirection.Both));
                        }
                    }

                    var useModes = child.Element("ModesOrDynamicGraphics")?.Element("UseModes");
                    if (ushort.TryParse(useModes?.Element("AnalogModeJoin")?.Value, out var modeJoin))
                    {
                        builder.AddJoin(
                            new JoinBuilder(modeJoin, builder.SmartJoin, "ControlMode", JoinType.Analog, JoinDirection.ToPanel));
                    }
                }
            }

            rootBuilder.AddControl(builder);
        }