Ejemplo n.º 1
0
        private void AssertProperties(ComponentDescription desc)
        {
            Assert.AreEqual(1, desc.Properties.Length);

            var prop = desc.Properties[0];

            Assert.AreEqual("TestProperty", prop.Name);
            Assert.AreEqual("Property", prop.DisplayName);
            Assert.AreEqual("test", prop.SerializedName);
            Assert.AreEqual(PropertyType.Decimal, prop.Type);
            Assert.AreEqual(new PropertyUnion(4700d), prop.Default);

            // Formatting
            Assert.AreEqual(3, prop.FormatRules.Count());

            // Conditional 1
            Assert.AreEqual(new ConditionTreeLeaf(ConditionType.Property, "TestProperty", ConditionComparison.Less, new PropertyUnion(1000.0)), prop.FormatRules[0].Conditions);
            Assert.AreEqual(@"$TestProperty  \u2126", prop.FormatRules[0].Value);

            // Conditional 2
            Assert.AreEqual(new ConditionTreeLeaf(ConditionType.Property, "TestProperty", ConditionComparison.Less, new PropertyUnion(1000000d)), prop.FormatRules[1].Conditions);
            Assert.AreEqual(@"$TestProperty(div_1000_)(round_1)  k\u2126", prop.FormatRules[1].Value);

            // Default
            Assert.AreEqual(@"$TestProperty(div_1000000)(round_1)  M\u2126", prop.FormatRules[2].Value);
        }
Ejemplo n.º 2
0
        private void AssertFlags(ComponentDescription desc)
        {
            Assert.AreEqual(1, desc.Flags.Length);

            var flag = desc.Flags[0];
            Assert.AreEqual(new ConditionTreeLeaf(ConditionType.Property, "TestProperty", ConditionComparison.Greater, new PropertyUnion(1000d)), flag.Conditions);
            Assert.AreEqual(FlagOptions.MiddleMustAlign, flag.Value);
        }
        public winComponentDetails(ComponentDescription component)
        {
            InitializeComponent();

            var reader = new IO.Descriptions.BinaryDescriptionReader();
            using (var file = System.IO.File.OpenRead(component.Source.Path))
            {
                if (reader.Read(file))
                {
                    lbxResources.ItemsSource = reader.Items;
                }
            }
        }
Ejemplo n.º 4
0
        private void AssertConnections(ComponentDescription desc)
        {
            Assert.AreEqual(2, desc.Connections.Length);

            var group1 = desc.Connections[0];
            Assert.AreEqual(IsHorizontalCondition, group1.Conditions);
            Assert.AreEqual(2, group1.Value.Length);
            Assert.AreEqual(new ConnectionDescription(new ComponentPoint("_Start"), new ComponentPoint("_Middle-21x"), ConnectionEdge.Start, "a"), group1.Value[0]);
            Assert.AreEqual(new ConnectionDescription(new ComponentPoint("_Middle+21x"), new ComponentPoint("_End"), ConnectionEdge.End, "b"), group1.Value[1]);

            var group2 = desc.Connections[1];
            Assert.AreEqual(IsNotHorizontalCondition, group2.Conditions);
            Assert.AreEqual(new ConnectionDescription(new ComponentPoint("_Start"), new ComponentPoint("_Middle-21y"), ConnectionEdge.Start, "a"), group2.Value[0]);
            Assert.AreEqual(new ConnectionDescription(new ComponentPoint("_Middle+21y"), new ComponentPoint("_End"), ConnectionEdge.End, "b"), group2.Value[1]);
        }
Ejemplo n.º 5
0
        private Component(ComponentDescription description)
        {
            Description = description;
            IsFlipped = false;
            m_propertyValues = new Dictionary<ComponentProperty, PropertyUnion>(description.Properties.Length);
            foreach (ComponentProperty property in description.Properties)
                m_propertyValues.Add(property, property.Default);
            if (System.Threading.Thread.CurrentThread.GetApartmentState() == System.Threading.ApartmentState.STA)
            {
                if (ComponentHelper.CreateEditor != null)
                    Editor = ComponentHelper.CreateEditor(this);

                if (Editor != null && ComponentHelper.ComponentUpdatedDelegate != null)
                    Editor.ComponentUpdated += ComponentHelper.ComponentUpdatedDelegate;
            }
        }
Ejemplo n.º 6
0
        internal override void Read(System.IO.BinaryReader reader, BinaryReadInfo readInfo)
        {
            uint length = reader.ReadUInt32();

            ID = reader.ReadUInt32();
            uint numSections = reader.ReadUInt32();

            string componentName = null;
            bool canResize = false;
            bool canFlip = false;
            double minSize = ComponentHelper.GridSize;
            List<ComponentProperty> properties = new List<ComponentProperty>();
            List<ConnectionGroup> connections = new List<ConnectionGroup>();
            List<RenderDescription> renderDescriptions = new List<RenderDescription>();
            List<Conditional<FlagOptions>> flagOptions = new List<Conditional<FlagOptions>>();
            ComponentDescriptionMetadata descriptionMetadata = new ComponentDescriptionMetadata();
            uint? iconResourceId = null;

            for (uint sectionCounter = 0; sectionCounter < numSections; sectionCounter++)
            {
                ushort sectionType = reader.ReadUInt16();
                uint sectionLength = reader.ReadUInt32();

                #region Metadata
                if (sectionType == (uint)BinaryConstants.ComponentSectionType.Metadata)
                {
                    componentName = reader.ReadString();
                    canResize = reader.ReadBoolean();
                    canFlip = reader.ReadBoolean();
                    minSize = reader.ReadDouble();
                    descriptionMetadata.Type = String.Format("Binary r{0} (*.cdcom)", readInfo.FormatVersion);
                    descriptionMetadata.GUID = new Guid(reader.ReadBytes(16));
                    descriptionMetadata.Author = reader.ReadString();
                    if (readInfo.IsSignatureValid && readInfo.Certificate != null && readInfo.IsCertificateTrusted)
                        descriptionMetadata.Author = readInfo.Certificate.GetNameInfo(X509NameType.EmailName, false);
                    descriptionMetadata.Version = new Version(reader.ReadUInt16(), reader.ReadUInt16());
                    descriptionMetadata.AdditionalInformation = reader.ReadString();
                    descriptionMetadata.ImplementSet = reader.ReadString();
                    descriptionMetadata.ImplementItem = reader.ReadString();
                    descriptionMetadata.Signature.IsHashValid = readInfo.IsSignatureValid;
                    descriptionMetadata.Signature.Certificate = readInfo.Certificate;
                    descriptionMetadata.Signature.IsCertificateTrusted = readInfo.IsCertificateTrusted;
                    int iconResource = reader.ReadInt32();
                    if (iconResource != -1)
                        iconResourceId = (uint)iconResource;
                    long created = reader.ReadInt64();
                }
                #endregion
                #region Flags
                else if (sectionType == (uint)BinaryConstants.ComponentSectionType.Flags)
                {
                    uint numFlagGroups = reader.ReadUInt32();
                    for (uint j = 0; j < numFlagGroups; j++)
                    {
                        IConditionTreeItem conditions;
                        if (readInfo.FormatVersion > 1)
                            conditions = reader.ReadConditionTree();
                        else
                            conditions = reader.ReadConditionCollection();

                        FlagOptions value = (FlagOptions)reader.ReadUInt32();
                        flagOptions.Add(new Conditional<FlagOptions>(value, conditions));
                    }
                }
                #endregion
                #region Properties
                else if (sectionType == (uint)BinaryConstants.ComponentSectionType.Properties)
                {
                    uint numProperties = reader.ReadUInt32();
                    for (uint j = 0; j < numProperties; j++)
                    {
                        string propertyName = reader.ReadString();
                        string serializedName = reader.ReadString();
                        string displayName = reader.ReadString();
                        BinaryType propType;
                        object rawDefaultValue = reader.ReadType(out propType);
                        PropertyUnion defaultValue = propType.ToPropertyUnion(rawDefaultValue);
                        string[] enumOptions = null;
                        if (propType == BinaryType.Enum)
                        {
                            enumOptions = new string[reader.ReadInt32()];
                            for (int k = 0; k < enumOptions.Length; k++)
                                enumOptions[k] = reader.ReadString();
                        }

                        // Format rules
                        List<ComponentPropertyFormat> formatRules = new List<ComponentPropertyFormat>();
                        uint numFormatRules = reader.ReadUInt32();
                        for (uint k = 0; k < numFormatRules; k++)
                        {
                            IConditionTreeItem conditions;
                            if (readInfo.FormatVersion > 1)
                                conditions = reader.ReadConditionTree();
                            else
                                conditions = reader.ReadConditionCollection();
                            string formatRule = reader.ReadString();
                            formatRules.Add(new ComponentPropertyFormat(formatRule, conditions));
                        }

                        // Other conditions
                        uint numOtherConditions = reader.ReadUInt32();
                        Dictionary<PropertyOtherConditionType, IConditionTreeItem> otherConditions = new Dictionary<PropertyOtherConditionType, IConditionTreeItem>((int)numOtherConditions);
                        for (uint k = 0; k < numOtherConditions; k++)
                        {
                            uint uintConditionType = reader.ReadUInt32();
                            IConditionTreeItem conditions;
                            if (readInfo.FormatVersion > 1)
                                conditions = reader.ReadConditionTree();
                            else
                                conditions = reader.ReadConditionCollection();
                            PropertyOtherConditionType conditionType = (PropertyOtherConditionType)uintConditionType;
                            otherConditions.Add(conditionType, conditions);
                        }

                        properties.Add(new ComponentProperty(propertyName, serializedName, displayName, BinaryIOExtentions.BinaryTypeToPropertyType(propType), defaultValue, formatRules.ToArray(), otherConditions, enumOptions));
                    }
                }
                #endregion
                #region Configurations
                else if (sectionType == (uint)BinaryConstants.ComponentSectionType.Configurations)
                {
                    uint numConfigurations = reader.ReadUInt32();
                    for (int j = 0; j < numConfigurations; j++)
                    {
                        string configurationName = reader.ReadString();
                        string implementationName = reader.ReadString();

                        int numSetters = reader.ReadInt32();
                        var setters = new Dictionary<string, PropertyUnion>(numSetters);
                        for (int k = 0; k < numSetters; k++)
                        {
                            BinaryType tempType;
                            string name = reader.ReadString();
                            var setterValue = reader.ReadType(out tempType);
                            setters.Add(name, tempType.ToPropertyUnion(setterValue));
                        }

                        int iconID = reader.ReadInt32();

                        var configuration = new ComponentConfiguration(implementationName, configurationName, setters);
                        descriptionMetadata.Configurations.Add(configuration);

                        if (iconID != -1)
                            iconResources.Add(configuration, (uint)iconID);
                    }
                }
                #endregion
                #region Connections
                else if (sectionType == (uint)BinaryConstants.ComponentSectionType.Connections)
                {
                    uint numConnectionGroups = reader.ReadUInt32();
                    List<ConnectionGroup> connectionGroups = new List<ConnectionGroup>();
                    for (int j = 0; j < numConnectionGroups; j++)
                    {
                        IConditionTreeItem conditions;
                        if (readInfo.FormatVersion > 1)
                            conditions = reader.ReadConditionTree();
                        else
                            conditions = reader.ReadConditionCollection();

                        List<ConnectionDescription> tConnections = new List<ConnectionDescription>();
                        uint numConnections = reader.ReadUInt32();
                        for (uint k = 0; k < numConnections; k++)
                        {
                            tConnections.Add(new ConnectionDescription(reader.ReadComponentPoint(), reader.ReadComponentPoint(), (ConnectionEdge)reader.ReadInt32(), reader.ReadString()));
                        }

                        connections.Add(new ConnectionGroup(conditions, tConnections.ToArray()));
                    }
                }
                #endregion
                #region Render
                else if (sectionType == (uint)BinaryConstants.ComponentSectionType.Render)
                {
                    uint numRenderGroups = reader.ReadUInt32();
                    for (uint j = 0; j < numRenderGroups; j++)
                    {
                        IConditionTreeItem conditions;
                        if (readInfo.FormatVersion > 1)
                            conditions = reader.ReadConditionTree();
                        else
                            conditions = reader.ReadConditionCollection();

                        int numRenderCommands = (int)reader.ReadUInt32();
                        List<IRenderCommand> renderCommands = new List<IRenderCommand>(numRenderCommands);
                        for (int k = 0; k < numRenderCommands; k++)
                        {
                            RenderCommandType commandType = (RenderCommandType)reader.ReadUInt32();
                            switch (commandType)
                            {
                                case RenderCommandType.Line:
                                    {
                                        ComponentPoint start = reader.ReadComponentPoint();
                                        ComponentPoint end = reader.ReadComponentPoint();
                                        double thickness = reader.ReadDouble();
                                        renderCommands.Add(new Line(start, end, thickness));
                                    }
                                    continue;
                                case RenderCommandType.Rect:
                                    {
                                        ComponentPoint location = reader.ReadComponentPoint();
                                        double width = reader.ReadDouble();
                                        double height = reader.ReadDouble();
                                        double thickness = reader.ReadDouble();
                                        bool fill = (reader.ReadUInt32() == 0 ? false : true);
                                        renderCommands.Add(new Rectangle(location, width, height, thickness, fill));
                                    }
                                    continue;
                                case RenderCommandType.Ellipse:
                                    {
                                        ComponentPoint centre = reader.ReadComponentPoint();
                                        double radiusX = reader.ReadDouble();
                                        double radiusY = reader.ReadDouble();
                                        double thickness = reader.ReadDouble();
                                        bool fill = (reader.ReadUInt32() == 0 ? false : true);
                                        renderCommands.Add(new Ellipse(centre, radiusX, radiusY, thickness, fill));
                                    }
                                    continue;
                                case RenderCommandType.Path:
                                    {
                                        ComponentPoint start = reader.ReadComponentPoint();
                                        double thickness = reader.ReadDouble();
                                        bool fill = (reader.ReadUInt32() == 0 ? false : true);

                                        int numCommands = reader.ReadInt32();
                                        List<IPathCommand> pathCommands = new List<IPathCommand>(numCommands);
                                        for (int l = 0; l < numCommands; l++)
                                        {
                                            CommandType pType = (CommandType)reader.ReadInt32();
                                            IPathCommand theCommand = null;
                                            switch (pType)
                                            {
                                                case CommandType.MoveTo:
                                                    theCommand = new MoveTo();
                                                    break;
                                                case CommandType.LineTo:
                                                    theCommand = new LineTo();
                                                    break;
                                                case CommandType.CurveTo:
                                                    theCommand = new CurveTo();
                                                    break;
                                                case CommandType.EllipticalArcTo:
                                                    theCommand = new EllipticalArcTo();
                                                    break;
                                                case CommandType.QuadraticBeizerCurveTo:
                                                    theCommand = new QuadraticBeizerCurveTo();
                                                    break;
                                                case CommandType.SmoothCurveTo:
                                                    theCommand = new SmoothCurveTo();
                                                    break;
                                                case CommandType.SmoothQuadraticBeizerCurveTo:
                                                    theCommand = new SmoothQuadraticBeizerCurveTo();
                                                    break;
                                                default:
                                                    theCommand = new ClosePath();
                                                    break;
                                            }
                                            theCommand.Read(reader);
                                            pathCommands.Add(theCommand);
                                        }

                                        renderCommands.Add(new RenderPath(start, thickness, fill, pathCommands));
                                    }
                                    continue;
                                case RenderCommandType.Text:
                                    {
                                        byte formattedTextVersion = reader.ReadByte();
                                        ComponentPoint location = reader.ReadComponentPoint();
                                        TextAlignment alignment = (TextAlignment)reader.ReadUInt32();

                                        uint numTextRuns = reader.ReadUInt32();
                                        List<TextRun> textRuns = new List<TextRun>((int)numTextRuns);
                                        for (uint l = 0; l < numTextRuns; l++)
                                        {
                                            TextRunFormattingType formattingType = (TextRunFormattingType)reader.ReadUInt32();
                                            double runSize = reader.ReadDouble();
                                            string runText = reader.ReadString();
                                            textRuns.Add(new TextRun(runText, new TextRunFormatting(formattingType, runSize)));
                                        }

                                        renderCommands.Add(new Text(location, alignment, textRuns));
                                    }
                                    continue;
                            }
                        }

                        renderDescriptions.Add(new RenderDescription(conditions, renderCommands.ToArray()));
                    }
                }
                #endregion
                #region Skip
                else
                {
                    // Unknown type - skip
                    reader.BaseStream.Seek(sectionLength, SeekOrigin.Current);
                }
                #endregion
            }

            ComponentDescription = new ComponentDescription(ID.ToString(), componentName, canResize, canFlip, minSize, properties.ToArray(), connections.ToArray(), renderDescriptions.ToArray(), flagOptions.ToArray(), descriptionMetadata);

            if (iconResourceId.HasValue)
                mainIconResource = iconResourceId.Value;
        }
Ejemplo n.º 7
0
        public void Load(System.IO.Stream stream)
        {
            LoadContext lc = new LoadContext();

            try
            {
                string fileName = "file.xml";
                if (stream is System.IO.FileStream)
                    fileName = (stream as System.IO.FileStream).Name;
                lc.FileName = fileName;

                var reader = new XmlTextReader(stream);
                var root = XElement.Load(reader, LoadOptions.SetLineInfo);

                ns = XNamespace.Get(ComponentNamespace);
                lc.NS = ns;

                lc.NamespaceManager = new XmlNamespaceManager(reader.NameTable);
                lc.NamespaceManager.AddNamespace("cd", ComponentNamespace);

                // Read format version
                lc.FormatVersion = new Version(1, 2);
                if (root.Attribute("version") != null)
                    lc.FormatVersion = new Version(root.Attribute("version").Value);

                // Decide which condition parser to use
                if (lc.FormatVersion >= new Version(1, 1))
                {
                    ConditionFormat conditionParseFormat = new ConditionFormat();
                    if (lc.FormatVersion == new Version(1, 1))
                        conditionParseFormat.StatesUnderscored = true;
                    else
                        conditionParseFormat.StatesUnderscored = false;

                    lc.ConditionParser = new ConditionParser(conditionParseFormat);

                }
                else
                    lc.ConditionParser = new LegacyConditionParser();

                ComponentDescription description = new ComponentDescription();

                var declaration = root.XPathSelectElement("/cd:declaration", lc.NamespaceManager);
                ReadDeclarationSection(declaration, ns, lc, description);

                ReadConnectionsSection(declaration, lc, description);

                ReadRenderSection(declaration, lc, description);

                m_descriptions = new ComponentDescription[] { description };
            }
            catch (Exception ex)
            {
                lc.Errors.Add(new LoadError(lc.FileName, 0, 0, LoadErrorCategory.Error, "A fatal error occurred - '" + ex.Message + "'"));
                m_descriptions = new ComponentDescription[0];
            }
            finally
            {
                LoadErrors = lc.Errors;
            }
        }
Ejemplo n.º 8
0
        private void ReadRenderSection(XElement declaration, LoadContext lc, ComponentDescription description)
        {
            List<RenderDescription> parsedRenderDescriptions = new List<RenderDescription>();
            var renderDescriptions = declaration.XPathSelectElements("/cd:render/cd:group", lc.NamespaceManager);
            foreach (var renderNode in renderDescriptions)
            {
                IConditionTreeItem conditionCollection = ConditionTree.Empty;
                List<IRenderCommand> commands = new List<IRenderCommand>();

                var conditionsAttribute = renderNode.Attribute("conditions");
                if (conditionsAttribute != null)
                {
                    IXmlLineInfo line = conditionsAttribute as IXmlLineInfo;

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

                foreach (var renderCommandNode in renderNode.Descendants())
                {
                    string commandType = renderCommandNode.Name.LocalName;
                    if (commandType == "line")
                    {
                        var command = new Line();
                        command.LoadFromXml(renderCommandNode, lc);
                        commands.Add(command);
                    }
                    else if (commandType == "rect")
                    {
                        var command = new Rectangle();
                        command.LoadFromXml(renderCommandNode);
                        commands.Add(command);
                    }
                    else if (commandType == "ellipse")
                    {
                        var command = new Ellipse();
                        command.LoadFromXml(renderCommandNode, lc);
                        commands.Add(command);
                    }
                    else if (commandType == "text")
                    {
                        var command = new Text();
                        command.LoadFromXml(renderCommandNode, lc);
                        commands.Add(command);
                    }
                    else if (commandType == "path")
                    {
                        var command = new RenderPath();
                        command.LoadFromXml(renderCommandNode, lc);
                        commands.Add(command);
                    }
                }

                parsedRenderDescriptions.Add(new RenderDescription(conditionCollection, commands.ToArray()));
            }

            description.RenderDescriptions = parsedRenderDescriptions.ToArray();
        }
Ejemplo n.º 9
0
        public static Component Create(ComponentDescription description, Dictionary<string, object> data)
        {
            Component newComponent = new Component(description);

            // Load other properties
            newComponent.Deserialize(data);

            newComponent.ResetConnections();

            if (newComponent.Editor != null)
                newComponent.Editor.Update();

            return newComponent;
        }
Ejemplo n.º 10
0
 public static void SetStandardComponent(string collection, string item, ComponentDescription description, ComponentConfiguration configuration)
 {
     if (!m_standardComponents.ContainsKey(collection))
         m_standardComponents.Add(collection, new Dictionary<string, ComponentIdentifier>());
     if (!m_standardComponents[collection].ContainsKey(item))
         m_standardComponents[collection].Add(item, new ComponentIdentifier(description, configuration));
     else
         m_standardComponents[collection][item] = new ComponentIdentifier(description, configuration);
 }
Ejemplo n.º 11
0
 public static ComponentProperty FindProperty(ComponentDescription description, string key, PropertySearchKey keyType)
 {
     foreach (ComponentProperty property in description.Properties)
     {
         if (keyType == PropertySearchKey.FullName && property.Name == key)
             return property;
         else if (keyType == PropertySearchKey.SerializedName && property.SerializedName == key)
             return property;
     }
     return null;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Creates a new component identifier with the specified description and configuration.
 /// </summary>
 /// <param name="description">The component description.</param>
 /// <param name="configuration">The component configuration.</param>
 public ComponentIdentifier(ComponentDescription description, ComponentConfiguration configuration)
 {
     Description = description;
     Configuration = configuration;
 }
Ejemplo n.º 13
0
        private void AssertRender(ComponentDescription desc)
        {
            Assert.AreEqual(2, desc.RenderDescriptions.Length);

            var group1 = desc.RenderDescriptions[0];
            Assert.AreEqual(IsHorizontalCondition, group1.Conditions);
            Assert.AreEqual(new Line(new ComponentPoint("_Start"), new ComponentPoint("_Middle-20x"), 2d), group1.Value[0]);
            Assert.AreEqual(new Rectangle(new ComponentPoint("_Middle-20x", "_Start-8y"), 40d, 16d, 2d, false), group1.Value[1]);
            Assert.AreEqual(new Line(new ComponentPoint("_Middle+20x"), new ComponentPoint("_End"), 2d), group1.Value[2]);
            Assert.AreEqual(new Text(new ComponentPoint("_Middle", "_Start-17"), Render.TextAlignment.CentreCentre, 10d, "$TestProperty"), group1.Value[3]);

            var group2 = desc.RenderDescriptions[1];
            Assert.AreEqual(IsNotHorizontalCondition, group2.Conditions);
            Assert.AreEqual(new Line(new ComponentPoint("_Start"), new ComponentPoint("_Middle-20y"), 2d), group2.Value[0]);
            Assert.AreEqual(new Rectangle(new ComponentPoint("_Start-8x", "_Middle-20y"), 16d, 40d, 2d, false), group2.Value[1]);
            Assert.AreEqual(new Line(new ComponentPoint("_Middle+20y"), new ComponentPoint("_End"), 2d), group2.Value[2]);
            Assert.AreEqual(new Text(new ComponentPoint("_Start-14", "_Middle"), Render.TextAlignment.CentreRight, 10d, "$TestProperty"), group2.Value[3]);
        }
Ejemplo n.º 14
0
 private void AssertMetadata(ComponentDescription desc)
 {
     Assert.AreEqual("Test Component", desc.ComponentName);
     Assert.AreEqual(60d, desc.MinSize);
     Assert.AreEqual("Circuit Diagram", desc.Metadata.Author);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Finds the component implementation which represents the specified type.
 /// </summary>
 /// <param name="type">The type to find.</param>
 /// <param name="description">The description to search.</param>
 /// <returns>The ComponentConfiguration if one could be found, null otherwise.</returns>
 private static ComponentIdentifier FindIdentifier(IOComponentType type, ComponentDescription description)
 {
     // Check implementation
     if (description.Metadata.ImplementSet == type.Collection && description.Metadata.ImplementItem == type.Item)
         return new ComponentIdentifier(description);
     // Check configurations
     else if (description.Metadata.ImplementItem == type.Collection)
     {
         foreach (ComponentConfiguration configuration in description.Metadata.Configurations)
         {
             if (configuration.ImplementationName == type.Item)
                 return new ComponentIdentifier(description, configuration);
         }
     }
     // Check GUID
     if (description.Metadata.GUID != Guid.Empty && description.Metadata.GUID == type.GUID)
         return new ComponentIdentifier(description);
     // Check name
     else if (description.ComponentName == type.Name)
         return new ComponentIdentifier(description);
     else
         return null; // Incorrect
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Creates a new component identifier with the specified description.
 /// </summary>
 /// <param name="description">The component description.</param>
 public ComponentIdentifier(ComponentDescription description)
 {
     Description = description;
 }
Ejemplo n.º 17
0
        private static ComponentConfiguration ReadConfigurationNode(XElement configurationElement, ComponentDescription description)
        {
            string configName = configurationElement.Attribute("name").Value;
            string configValue = configurationElement.Attribute("value").Value;
            string configImplements = null;
            if (configurationElement.Attribute("implements") != null)
                configImplements = configurationElement.Attribute("implements").Value;

            ComponentConfiguration newConfiguration = new ComponentConfiguration(configImplements, configName, new Dictionary<string,PropertyUnion>());

            string[] setters = configValue.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string setter in setters)
            {
                string[] tempSplit = setter.Split(':');
                string propertyName = tempSplit[0];
                string value = tempSplit[1];

                // convert from string to proper type
                foreach (ComponentProperty property in description.Properties)
                {
                    if (propertyName == property.Name)
                    {
                        newConfiguration.Setters.Add(property.SerializedName, new PropertyUnion(value, property.Type));
                        break;
                    }
                }
            }
            return newConfiguration;
        }
Ejemplo n.º 18
0
        public static void AddDescription(ComponentDescription description)
        {
            if (description.RuntimeID == 0)
                description.RuntimeID = NewRuntimeID();

            if (!m_descriptions.Contains(description))
                m_descriptions.Add(description);
        }
Ejemplo n.º 19
0
        private void ReadConnectionsSection(XElement declaration, LoadContext lc, ComponentDescription description)
        {
            List<ConnectionGroup> parsedConnectionGroups = new List<ConnectionGroup>();
            var connectionGroupNodes = declaration.XPathSelectElements("/cd:connections/cd:group", lc.NamespaceManager);
            foreach (var connectionGroupNode in connectionGroupNodes)
            {
                IConditionTreeItem conditionCollection = ConditionTree.Empty;
                List<ConnectionDescription> connections = new List<ConnectionDescription>();

                var conditionsAttribute = connectionGroupNode.Attribute("conditions");
                if (conditionsAttribute != null)
                {
                    IXmlLineInfo line = conditionsAttribute as IXmlLineInfo;

                    try
                    {
                        conditionCollection = lc.ConditionParser.Parse(connectionGroupNode.Attribute("conditions").Value, lc.ParseContext);
                    }
                    catch (ConditionFormatException ex)
                    {
                        lc.Errors.Add(new LoadError(lc.FileName, line.LineNumber, line.LinePosition + conditionsAttribute.Name.LocalName.Length + 2 + ex.PositionStart, LoadErrorCategory.Error, ex.Message));
                        continue;
                    }
                }

                foreach (var connectionNode in connectionGroupNode.Elements(ns + "connection"))
                {
                    ConnectionEdge edge = ConnectionEdge.None;
                    if (connectionNode.Attribute("edge") != null)
                    {
                        string edgeText = connectionNode.Attribute("edge").Value.ToLowerInvariant();
                        if (edgeText == "start")
                            edge = ConnectionEdge.Start;
                        else if (edgeText == "end")
                            edge = ConnectionEdge.End;
                        else if (edgeText == "both")
                            edge = ConnectionEdge.Both;
                    }
                    string connectionName = "#";
                    if (connectionNode.Attribute("name") != null)
                        connectionName = connectionNode.Attribute("name").Value;
                    connections.Add(new ConnectionDescription(new ComponentPoint(connectionNode.Attribute("start").Value), new ComponentPoint(connectionNode.Attribute("end").Value), edge, connectionName));
                }

                parsedConnectionGroups.Add(new ConnectionGroup(conditionCollection, connections.ToArray()));
            }

            description.Connections = parsedConnectionGroups.ToArray();
        }
Ejemplo n.º 20
0
 public static bool IsStandardComponent(ComponentDescription componentDescription)
 {
     if (componentDescription.Metadata.GUID == Guid.Empty || componentDescription.Source == null)
         return false;
     #if DEBUG
         return (System.IO.Path.GetDirectoryName(componentDescription.Source.Path) == System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\ext"
             || System.IO.Path.GetDirectoryName(componentDescription.Source.Path) == Path.GetFullPath("../../Components"));
     #else
         return (System.IO.Path.GetDirectoryName(componentDescription.Source.Path) == System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\ext");
     #endif
 }
Ejemplo n.º 21
0
        private void ReadDeclarationSection(XElement declaration, XNamespace ns, LoadContext lc, ComponentDescription description)
        {
            IXmlLineInfo line = declaration as IXmlLineInfo;

            // Read meta nodes
            foreach (var metaElement in declaration.Elements(ns + "meta"))
            {
                ReadMetaNode(metaElement, lc, description);
            }

            // Check all required metadata was set
            if (String.IsNullOrEmpty(description.ComponentName))
                lc.Errors.Add(new LoadError(lc.FileName, line.LineNumber, line.LinePosition, LoadErrorCategory.Error,
                    "Component name is required"));

            //Read properties
            List<ComponentProperty> properties = new List<ComponentProperty>();
            foreach (var propertyElement in declaration.Elements(ns + "property"))
            {
                ScanPropertyNode(propertyElement, lc);
            }
            foreach (var propertyElement in declaration.Elements(ns + "property"))
            {
                ComponentProperty property = ReadPropertyNode(propertyElement, lc);
                properties.Add(property);
            }
            description.Properties = properties.ToArray();

            // Read flags
            List<Conditional<FlagOptions>> flagOptions = new List<Conditional<FlagOptions>>();
            foreach (var flagGroup in declaration.Elements(ns + "flags"))
            {
                var flags = ReadFlagOptionNode(flagGroup, lc);
                if (flags != null)
                    flagOptions.Add(flags);
            }
            description.Flags = flagOptions.ToArray();

            // Read configurations
            var componentConfigurations = new List<ComponentConfiguration>();
            var configurations = declaration.Element(ns + "configurations");
            if (configurations != null)
            {
                foreach (var node in configurations.Elements(ns + "configuration"))
                {
                    ComponentConfiguration newConfiguration = ReadConfigurationNode(node, description);

                    componentConfigurations.Add(newConfiguration);
                }
            }
            description.Metadata.Configurations.AddRange(componentConfigurations);
        }
Ejemplo n.º 22
0
 internal static bool ShouldEmbedDescription(ComponentDescription componentDescription)
 {
     if (EmbedOptions == ComponentEmbedOptions.All)
         return true;
     else if (EmbedOptions == ComponentEmbedOptions.None)
         return false;
     else
         return !IsStandardComponent(componentDescription);
 }
Ejemplo n.º 23
0
        private void ReadMetaNode(XElement metaElement, LoadContext lc, ComponentDescription description)
        {
            string metaName;
            if (!metaElement.GetAttribute("name", lc, out metaName))
                return;

            string metaValue;
            if (!metaElement.GetAttribute("value", lc, out metaValue))
                return;

            IXmlLineInfo line = metaElement as IXmlLineInfo;

            switch (metaName)
            {
                case "name":
                    description.ComponentName = metaValue;
                    break;
                case "canresize":
                    description.CanResize = metaValue.ToLower() != "false";
                    break;
                case "canflip":
                    description.CanFlip = metaValue.ToLower() != "false";
                    break;
                case "minsize":
                    double minSize;
                    if (double.TryParse(metaValue, out minSize))
                        description.MinSize = minSize;
                    else
                        lc.Errors.Add(new LoadError(lc.FileName, line.LineNumber, line.LinePosition, LoadErrorCategory.Error,
                            "Illegal value for attribute 'value' on <meta> tag 'minsize' (expected decimal)"));
                    break;
                case "version":
                    try
                    {
                        description.Metadata.Version = new Version(metaValue);
                    }
                    catch
                    {
                        lc.Errors.Add(new LoadError(lc.FileName, line.LineNumber, line.LinePosition, LoadErrorCategory.Error,
                            "Illegal value for attribute 'value' on <meta> tag 'version' (expected version number)"));
                    }
                    break;
                case "author":
                    description.Metadata.Author = metaValue;
                    break;
                case "additionalinformation":
                    description.Metadata.AdditionalInformation = metaValue;
                    break;
                case "implementset":
                    description.Metadata.ImplementSet = metaValue;
                    break;
                case "implementitem":
                    description.Metadata.ImplementItem = metaValue;
                    break;
                case "guid":
                    try
                    {
                        description.Metadata.GUID = new Guid(metaValue);
                    }
                    catch
                    {
                        lc.Errors.Add(new LoadError(lc.FileName, line.LineNumber, line.LinePosition, LoadErrorCategory.Error,
                            "Illegal value for attribute 'value' on <meta> tag 'guid' (expected GUID)"));
                    }
                    break;
            }
        }