public ComponentDescription(string id, string componentName, bool canResize, bool canFlip, double minSize, ComponentProperty[] properties, ConnectionGroup[] connections, RenderDescription[] renderDescriptions, Conditional<FlagOptions>[] flags, ComponentDescriptionMetadata metadata)
 {
     ID = id;
     ComponentName = componentName;
     CanResize = canResize;
     CanFlip = canFlip;
     MinSize = minSize;
     Properties = properties;
     Connections = connections;
     RenderDescriptions = renderDescriptions;
     Flags = flags;
     Metadata = metadata;
 }
Пример #2
0
        private ComponentProperty ReadPropertyNode(XElement propertyElement, LoadContext lc)
        {
            IXmlLineInfo elementLine = propertyElement as IXmlLineInfo;

            string propertyName = propertyElement.Attribute("name").Value;
            string type = propertyElement.Attribute("type").Value;
            string defaultValue = propertyElement.Attribute("default").Value;
            string serializeAs = propertyElement.Attribute("serialize").Value;
            string display = propertyElement.Attribute("display").Value;

            PropertyType propertyType;
            switch (type.ToLowerInvariant())
            {
                case "double":
                    propertyType = PropertyType.Decimal;
                    if (lc.FormatVersion >= new Version(1, 2))
                        lc.Errors.Add(new LoadError(lc.FileName, elementLine.LineNumber, elementLine.LinePosition, LoadErrorCategory.Warning,
                            "Property type 'double' is deprecated, use 'decimal' instead"));
                    break;
                case "decimal":
                    propertyType = PropertyType.Decimal;
                    break;
                case "int":
                    propertyType = PropertyType.Integer;
                    break;
                case "bool":
                    propertyType = PropertyType.Boolean;
                    break;
                default:
                    propertyType = PropertyType.String;
                    break;
            }

            PropertyUnion propertyDefaultValue = new PropertyUnion(defaultValue, propertyType);

            List<string> propertyOptions = null;
            if (type == "enum")
            {
                propertyOptions = new List<string>();
                var optionNodes = propertyElement.Elements(ns + "option");
                foreach (var optionNode in optionNodes)
                    propertyOptions.Add(optionNode.Value);
            }

            List<ComponentPropertyFormat> formatRules = new List<ComponentPropertyFormat>();
            if (propertyElement.Attribute("format") != null)
                formatRules.Add(new ComponentPropertyFormat(propertyElement.Attribute("format").Value, ConditionTree.Empty));
            else
            {
                var formatRuleNodes = propertyElement.XPathSelectElements("cd:formatting/cd:format", lc.NamespaceManager);
                foreach (var formatNode in formatRuleNodes)
                {
                    IXmlLineInfo line = formatNode as IXmlLineInfo;

                    IConditionTreeItem conditionCollection = ConditionTree.Empty;
                    if (formatNode.Attribute("conditions") != null)
                    {
                        try
                        {
                            conditionCollection = lc.ConditionParser.Parse(formatNode.Attribute("conditions").Value, lc.ParseContext);
                        }
                        catch (ConditionFormatException ex)
                        {
                            lc.Errors.Add(new LoadError(lc.FileName, line.LineNumber, line.LinePosition + formatNode.Name.LocalName.Length + 2 + ex.PositionStart, LoadErrorCategory.Error, ex.Message));
                            return null;
                        }
                    }

                    formatRules.Add(new ComponentPropertyFormat(formatNode.Attribute("value").Value, conditionCollection));
                }
            }

            Dictionary<PropertyOtherConditionType, IConditionTreeItem> otherConditions = new Dictionary<PropertyOtherConditionType, IConditionTreeItem>();
            var otherConditionsNodes = propertyElement.XPathSelectElements("cd:other/cd:conditions", lc.NamespaceManager);
            foreach (var otherConditionNode in otherConditionsNodes)
            {
                if (otherConditionNode != null && otherConditionNode.Attribute("for") != null && otherConditionNode.Attribute("value") != null)
                {
                    IXmlLineInfo line = otherConditionNode as IXmlLineInfo;

                    string conditionsFor = otherConditionNode.Attribute("for").Value;
                    string conditionsString = otherConditionNode.Attribute("value").Value;
                    IConditionTreeItem conditionCollection;

                    try
                    {
                        conditionCollection = lc.ConditionParser.Parse(conditionsString, lc.ParseContext);
                    }
                    catch (ConditionFormatException ex)
                    {
                        lc.Errors.Add(new LoadError(lc.FileName, line.LineNumber, line.LinePosition + otherConditionNode.Name.LocalName.Length + 2 + ex.PositionStart, LoadErrorCategory.Error, ex.Message));
                        return null;
                    }

                    if (Enum.IsDefined(typeof(PropertyOtherConditionType), conditionsFor))
                        otherConditions.Add((PropertyOtherConditionType)Enum.Parse(typeof(PropertyOtherConditionType), conditionsFor, true), conditionCollection);
                }
            }

            ComponentProperty property = new ComponentProperty(propertyName, serializeAs, display, propertyType, propertyDefaultValue, formatRules.ToArray(), otherConditions, (propertyOptions == null ? null : propertyOptions.ToArray()));

            return property;
        }
Пример #3
0
 public PropertyUnion GetProperty(ComponentProperty property)
 {
     if (m_propertyValues.ContainsKey(property))
         return m_propertyValues[property];
     else
         return null;
 }
Пример #4
0
 public void SetProperty(ComponentProperty property, PropertyUnion value)
 {
     if (m_propertyValues.ContainsKey(property))
     {
         m_propertyValues[property] = value;
     }
 }
Пример #5
0
 public string GetFormattedProperty(ComponentProperty property)
 {
     if (m_propertyValues.ContainsKey(property))
         return property.Format(this, m_propertyValues[property]);
     else
         return null;
 }