/// <summary>
 /// Initializes a new s_instance of the <see cref="ComponentMetadata"/> class.
 /// </summary>
 /// <param name="componentMetadataDefinition">The component metadata definition.</param>
 internal ComponentMetadata(ComponentMetadataDefinition componentMetadataDefinition, string experimentLocationRoot)
 {
     m_experimentLocationRoot = experimentLocationRoot;
     ComponentMetadataDefinition = componentMetadataDefinition;
     InitDefaultComponentMetadata(true);
     InitLoggingNodeSettings();
 }
示例#2
0
        /// <summary>
        /// Returns a hash code for this s_instance.
        /// </summary>
        /// <returns>
        /// A hash code for this s_instance, suitable for use in hashing algorithms and data structures like a hash table.
        /// </returns>
        public override int GetHashCode()
        {
            int iospecHash = IOSpec.GetHashCode();
            int componentMetadataDefinitionIDHash = ComponentMetadataDefinitionID.GetHashCode();
            int configWrapperHash = ConfigWrapper.GetHashCode();
            int labelHash         = Label.GetHashCode();
            int componentMetadataDefinitionHash = ComponentMetadataDefinition.GetHashCode();

            return(iospecHash ^ componentMetadataDefinitionIDHash ^ configWrapperHash ^ labelHash ^ componentMetadataDefinitionHash);
        }
        public void TestSetup()
        {
            AppContext = new TraceLabTestApplication(TestContext);

            MetadataDefinition definition;
            if (AppContext.Components.TryGetComponentDefinition(TraceLabTestApplication.TestEmptyComponentGUID, out definition))
            {
                m_emptyComponentMetaDefinition = definition as ComponentMetadataDefinition;
            }
            else
            {
                Assert.Fail("Failed to locate component metadatadefinition!");
            }

            if (AppContext.Components.TryGetComponentDefinition(TraceLabTestApplication.TestReaderComponentGUID, out definition))
            {
                m_componentReaderMetaDefinition = definition as ComponentMetadataDefinition;
            }
            else
            {
                Assert.Fail("Failed to locate component metadatadefinition!");
            }

            if (AppContext.Components.TryGetComponentDefinition(TraceLabTestApplication.TestWriterComponentGUID, out definition))
            {
                m_componentWriterMetaDefinition = definition as ComponentMetadataDefinition;
            }
            else
            {
                Assert.Fail("Failed to locate component metadatadefinition!");
            }

            if (AppContext.Components.TryGetComponentDefinition(TraceLabTestApplication.IncrementerComponentGUID, out definition))
            {
                m_incrementerComponentMetaDefinition = definition as ComponentMetadataDefinition;
            }
            else
            {
                Assert.Fail("Failed to locate component metadatadefinition!");
            }
        }
        public void FileDescriptorTest()
        {
            string componentsDir = System.IO.Path.Combine(AppContext.BaseTestDirectory, "TestComponents");
            string componentFile = System.IO.Path.Combine(componentsDir, "Importer.dll");

            AssemblyFileDescriptor assembly = new AssemblyFileDescriptor(componentFile);

            Assert.IsTrue(assembly.isUpToDate());

            string id = "MockComponent";
            string classname = "MockComponents.MockComponent"; //class exists and should be loaded
            ComponentMetadataDefinition compMetaDef = new ComponentMetadataDefinition(id, assembly.AbsolutePath, classname);

            Assert.AreEqual("MockComponents.MockComponent", compMetaDef.Classname);

            assembly.MetadataCollection.Add(compMetaDef);

            IList<FileDescriptor> files = new List<FileDescriptor>();
            files.Add(assembly);

            ComponentsLibraryCache cache = new ComponentsLibraryCache(AppContext.BaseTestDirectory);
            cache.AddComponentFiles(files);

            Assert.IsTrue(cache.ComponentFiles.Contains(assembly.AbsolutePath));

            ISet<string> filepaths = cache.GetUpToDateFiles();

            Assert.AreEqual(filepaths.Count, 1);
        }
        public void RemoveConnection()
        {
            IExperiment experiment = ExperimentManager.New();
            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            ComponentMetadataDefinition def1 = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test.dll"), "IDontExist");
            ExperimentNode node1 = ((IEditableExperiment)experiment).AddComponentFromDefinition(def1, -5, 5);

            ComponentMetadataDefinition def2 = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test2.dll"), "IDontExistEither");
            ExperimentNode node2 = ((IEditableExperiment)experiment).AddComponentFromDefinition(def2, -5, 5);

            Assert.AreEqual(0, experiment.EdgeCount);
            ExperimentNodeConnection newEdge = ((IEditableExperiment)experiment).AddConnection(node1, node2);
            Assert.IsNotNull(newEdge);
            Assert.AreEqual(1, experiment.EdgeCount);

            experiment.ResetModifiedFlag();

            Assert.AreEqual(4, experiment.VertexCount);
            ((IEditableExperiment)experiment).RemoveConnection(newEdge);

            // Verify that the edge was existed and the number of vertices was unaffected.
            Assert.AreEqual(0, experiment.EdgeCount);
            Assert.AreEqual(4, experiment.VertexCount);

            Assert.IsTrue(experiment.IsModified);
        }
        public void AddNewConnectionTwice()
        {
            IExperiment experiment = ExperimentManager.New();
            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            ComponentMetadataDefinition def1 = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test.dll"), "IDontExist");
            ExperimentNode node1 = ((IEditableExperiment)experiment).AddComponentFromDefinition(def1, -5, 5);

            ComponentMetadataDefinition def2 = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test2.dll"), "IDontExistEither");
            ExperimentNode node2 = ((IEditableExperiment)experiment).AddComponentFromDefinition(def2, -5, 5);

            Assert.AreEqual(0, experiment.EdgeCount);
            ExperimentNodeConnection newEdge = ((IEditableExperiment)experiment).AddConnection(node1, node2);
            Assert.IsNotNull(newEdge);
            Assert.AreEqual(1, experiment.EdgeCount);
            
            //add the same connection once again
            ExperimentNodeConnection newEdge2 = ((IEditableExperiment)experiment).AddConnection(node1, node2);
            Assert.IsNotNull(newEdge2);
            Assert.AreEqual(newEdge, newEdge2);
            // the amount of edges should still be the same
            Assert.AreEqual(1, experiment.EdgeCount);
        }
        public void AddNewConnectionNullNode2()
        {
            IExperiment experiment = ExperimentManager.New();
            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            ComponentMetadataDefinition def1 = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test.dll"), "IDontExist");
            ExperimentNode node2 = ((IEditableExperiment)experiment).AddComponentFromDefinition(def1, -5, 5);

            Assert.AreEqual(0, experiment.EdgeCount);
            ExperimentNodeConnection newEdge = ((IEditableExperiment)experiment).AddConnection(null, node2);
            Assert.IsNotNull(newEdge);
            Assert.AreEqual(1, experiment.EdgeCount);
        }
        public void AddNewConnectionCannotTargetStartNode()
        {
            IExperiment experiment = ExperimentManager.New();
            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            ComponentMetadataDefinition def2 = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test.dll"), "IDontExist");
            ExperimentNode node2 = ((IEditableExperiment)experiment).AddComponentFromDefinition(def2, -5, 5);

            ExperimentNodeConnection newEdge = ((IEditableExperiment)experiment).AddConnection(node2, experiment.StartNode);
        }
        public void AddNewConnection()
        {
            IExperiment experiment = ExperimentManager.New();
            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            ComponentMetadataDefinition def1 = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test.dll"), "IDontExist");
            ExperimentNode node1 = ((IEditableExperiment)experiment).AddComponentFromDefinition(def1, -5, 5);

            ComponentMetadataDefinition def2 = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test2.dll"), "IDontExistEither");
            ExperimentNode node2 = ((IEditableExperiment)experiment).AddComponentFromDefinition(def2, -5, 5);
            
            // We know already that experiments are modified after adding components, but we 
            // want to make sure that they're modified after adding a connection too, so lets clear the modification flag first.
            experiment.ResetModifiedFlag();
            Assert.IsFalse(experiment.IsModified);
            
            Assert.AreEqual(0, experiment.EdgeCount);
            ExperimentNodeConnection newEdge = ((IEditableExperiment)experiment).AddConnection(node1, node2);
            Assert.IsNotNull(newEdge);
            Assert.AreEqual(1, experiment.EdgeCount);
            Assert.IsTrue(experiment.IsModified);
        }
 public void GetRemovedComponent()
 {
     IExperiment experiment = ExperimentManager.New();
     experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
     ComponentMetadataDefinition def = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test.dll"), "IDontExist");
     ExperimentNode node = ((IEditableExperiment)experiment).AddComponentFromDefinition(def, -5, 5);
     ((IEditableExperiment)experiment).RemoveVertex(node);
     ExperimentNode foundNode = experiment.GetNode(node.ID);
     Assert.IsNull(foundNode);
 }
        public void RemoveComponent()
        {
            IExperiment experiment = ExperimentManager.New();
            experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
            ComponentMetadataDefinition def = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test.dll"), "IDontExist");
            ExperimentNode added = ((IEditableExperiment)experiment).AddComponentFromDefinition(def, -5, 5);

            ((IEditableExperiment)experiment).RemoveVertex(added);
            Assert.AreEqual(2, experiment.VertexCount);
            foreach (ExperimentNode node in experiment.Vertices)
            {
                Assert.AreNotEqual(added.ID, node.ID);
            }
        }
 public void AddNewComponent()
 {
     IExperiment experiment = ExperimentManager.New();
     experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml";
     ComponentMetadataDefinition def = new ComponentMetadataDefinition(Guid.NewGuid().ToString(), System.IO.Path.Combine(AppContext.BaseTestDirectory, "Test.dll"), "IDontExist");
     Assert.AreEqual(2, experiment.VertexCount);
     ExperimentNode node = ((IEditableExperiment)experiment).AddComponentFromDefinition(def, -5, 5);
     Assert.IsNotNull(node);
     Assert.AreEqual(3, experiment.VertexCount);
     Assert.IsTrue(experiment.IsModified);
 }
示例#13
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);
            }
        }
示例#14
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);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ComponentMetadata"/> class.
 /// </summary>
 /// <param name="info">The info.</param>
 /// <param name="context">The context.</param>
 protected ComponentMetadata(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     m_IOSpec = (IOSpec)info.GetValue("m_IOSpec", typeof(IOSpec));
     m_configWrapper = (ConfigWrapper)info.GetValue("m_configWrapper", typeof(ConfigWrapper));
     m_componentMetadataDefinitionID = (string)info.GetValue("m_componentMetadataDefinitionID", typeof(string));
     m_componentMetadataDefinition = (ComponentMetadataDefinition)info.GetValue("m_componentMetadataDefinition", typeof(ComponentMetadataDefinition));
 }