Example #1
0
        public void ApplyOverridesTest()
        {
            string        definitionId = Guid.NewGuid().ToString();
            ComponentTags baseTag      = new ComponentTags(definitionId);

            List <string> tags = new List <string>(new string[] { "+Test", "+Foo", "+Bar" });

            foreach (string tag in tags)
            {
                baseTag.SetTag(tag, false);
            }

            ComponentTags overrideTag  = new ComponentTags(definitionId);
            List <string> overrideTags = new List <string>(new string[] { "+AnotherTestValue", "+Foo", "-Foo" });

            foreach (string tag in overrideTags)
            {
                overrideTag.SetTag(tag, false);
            }

            baseTag.ApplyOverrides(overrideTag);
            Assert.AreEqual(3, baseTag.Values.Count);
            Assert.IsTrue(baseTag.Values.Contains("Test"));
            Assert.IsTrue(baseTag.Values.Contains("Bar"));
            Assert.IsTrue(baseTag.Values.Contains("AnotherTestValue"));
            Assert.IsFalse(baseTag.Values.Contains("Foo"));
        }
Example #2
0
        public void SetTagTest()
        {
            string        definitionId = Guid.NewGuid().ToString();
            ComponentTags target       = new ComponentTags(definitionId);
            string        tag          = "+Test";
            bool          isUserTag    = false;

            target.SetTag(tag, isUserTag);

            Assert.AreEqual(1, target.Values.Count);
            Assert.AreEqual("Test", target.Values[0]);

            target.SetTag("-Test", false);
            Assert.AreEqual(0, target.Values.Count);

            target.SetTag("-Test", false);
            Assert.AreEqual(0, target.Values.Count);
        }
Example #3
0
        /// <summary>
        /// Checks the type for existence of Component Attribute. If type has Component Attribute it creates 
        /// component metadata definition and adds it to the assembly file descriptor.
        /// If Component Attribute was found, but was in incorrect format error is reported. 
        /// </summary>
        /// <param name="assemblyPath">The assembly path.</param>
        /// <param name="exportedType">Type of the exported.</param>
        /// <param name="assemblyFile">The assembly file.</param>
        private void CheckType(string assemblyPath, Type exportedType, AssemblyFileDescriptor assemblyFile)
        {
            var attribs = exportedType.GetCustomAttributes(typeof(ComponentAttribute), false);
            if (attribs.Length == 1)
            {
                try
                {
                    var attrib = (ComponentAttribute)attribs[0];
                    var ioSpecDefinition = ComponentScannerHelper.ReadIOSpec(exportedType);
                    var configurationWrapperDefinition = ComponentScannerHelper.CreateConfigWrapperDefinition(attrib.ConfigurationType);
                    var componentId = ComponentScannerHelper.CreateComponentId(attrib.Name, ioSpecDefinition, attrib.Version, configurationWrapperDefinition);

                    ComponentTags tags = new ComponentTags(componentId);
                    var tagAttribs = exportedType.GetCustomAttributes(typeof(TagAttribute), false);
                    foreach (TagAttribute tag in tagAttribs)
                    {
                        tags.SetTag(tag.Tag, false);
                    }

                    //name participates in guid generation, and is assign as default label, unless other default label has been specified
                    string defaultLabel = (String.IsNullOrWhiteSpace(attrib.DefaultLabel)) ? attrib.Name : attrib.DefaultLabel;

                    //gather all documentation links
                    List<DocumentationLink> documentationLinks = new List<DocumentationLink>();
                    var linkAttribs = exportedType.GetCustomAttributes(typeof(LinkAttribute), false);
                    foreach (LinkAttribute link in linkAttribs)
                    {
                        Uri url;
                        if (Uri.TryCreate(link.Url, UriKind.Absolute, out url))
                        {
                            documentationLinks.Add(new DocumentationLink(url, link.Title, link.Description, link.Order));
                        }
                        else
                        {
                            NLog.LogManager.GetCurrentClassLogger().Warn(
                                String.Format("Documentation link url '{0}' for component '{1}' could not be processed correctly and has been ommitted", link.Url , defaultLabel));
                        }
                    }

                    var compDef = new ComponentMetadataDefinition(componentId,
                                                        assemblyPath,
                                                        exportedType.FullName,
                                                        ioSpecDefinition,
                                                        defaultLabel,
                                                        attrib.Version,
                                                        attrib.Description,
                                                        attrib.Author,
                                                        attrib.IsJava ? Language.JAVA : Language.NET,
                                                        configurationWrapperDefinition,
                                                        tags,
                                                        documentationLinks);

                    assemblyFile.MetadataCollection.Add(compDef);

                    //if old manual guid has been set, add it to the map from new autogenerated guid to old guid
                    if (attrib.GuidIDString != null && attrib.GuidID != null)
                    {
                        string oldGuidID = attrib.GuidID.ToString();
                        if (!assemblyFile.NewGuidToOldGuid.ContainsValue(oldGuidID))
                        {
                            assemblyFile.NewGuidToOldGuid.Add(componentId, oldGuidID);
                        }
                    }
                }
                catch (Exceptions.ComponentsLibraryException ex)
                {
                    Errors.Add(String.Format("Potential component type {0} located in assembly {1} has invalid ComponentAttribute: {2}", exportedType, assemblyPath, ex.Message));
                }
            }
            else if (1 < attribs.Length)
            {
                var errorMsg = "ERROR: Somehow there are more than one ComponentAttribute instances on type " + exportedType.FullName;
                Errors.Add(errorMsg);
            }
        }
        public void ReadXml(System.Xml.XmlReader reader)
        {
            int version = int.Parse(reader.GetAttribute("xmlVersion"));

            if (version != xmlVersion && version != 1) 
            {
                throw new InvalidOperationException("Version file not recognized");
            }
            
            XPathDocument doc = new XPathDocument(reader);
            XPathNavigator nav = doc.CreateNavigator();

            XPathNavigator iter = ReadComponentInfo(nav);

            if (version == xmlVersion)
            {
                ReadCurrentVersionIODefinitions(nav);
            }
            else if (version == 1)
            {
                ReadOldIODefinitions(nav);
            }

            iter = nav.SelectSingleNode("/CompositeComponentMetadataDefinition/ConfigDefinition");
            ConfigurationWrapperDefinition.ReadXml(iter.ReadSubtree());

            //get experiment xml -> reading this xml is done in PostProcessReadXml
            iter = nav.SelectSingleNode("/CompositeComponentMetadataDefinition/ComponentGraph");
            m_experimentXml = iter.InnerXml;

            //read tags
            Tags = new ComponentTags(ID);

            XPathNodeIterator tagsIterator = nav.Select("/CompositeComponentMetadataDefinition/Tags//Tag");

            while (tagsIterator.MoveNext())
            {
                string tagValue = tagsIterator.Current.Value;
                Tags.SetTag(tagValue, false);
            }
        }
        public void SetTagTest()
        {
            string definitionId = Guid.NewGuid().ToString();
            ComponentTags target = new ComponentTags(definitionId);
            string tag = "+Test";
            bool isUserTag = false;
            target.SetTag(tag, isUserTag);

            Assert.AreEqual(1, target.Values.Count);
            Assert.AreEqual("Test", target.Values[0]);

            target.SetTag("-Test", false);
            Assert.AreEqual(0, target.Values.Count);

            target.SetTag("-Test", false);
            Assert.AreEqual(0, target.Values.Count);
        }
        public void ApplyOverridesTest()
        {
            string definitionId = Guid.NewGuid().ToString();
            ComponentTags baseTag = new ComponentTags(definitionId);

            List<string> tags = new List<string>(new string[]{"+Test", "+Foo", "+Bar"});
            foreach(string tag in tags)
            {
                baseTag.SetTag(tag, false);
            }

            ComponentTags overrideTag = new ComponentTags(definitionId);
            List<string> overrideTags = new List<string>(new string[] { "+AnotherTestValue", "+Foo", "-Foo" });
            foreach (string tag in overrideTags)
            {
                overrideTag.SetTag(tag, false);
            }

            baseTag.ApplyOverrides(overrideTag);
            Assert.AreEqual(3, baseTag.Values.Count);
            Assert.IsTrue(baseTag.Values.Contains("Test"));
            Assert.IsTrue(baseTag.Values.Contains("Bar"));
            Assert.IsTrue(baseTag.Values.Contains("AnotherTestValue"));
            Assert.IsFalse(baseTag.Values.Contains("Foo"));
        }