public void Run(CompileContext context)
        {
            XmlLoader loader = new XmlLoader();
            loader.Load(context.Input);

            context.Errors.AddRange(loader.LoadErrors.Select(e => new CompileError(e)));
            if (loader.LoadErrors.Count(e => e.Category == LoadErrorCategory.Error) > 0)
                return;

            var description = loader.GetDescriptions()[0];

            // The component XML format doesn't provide an ID, so make one now
            description.ID = "C0";

            context.Description = description;
        }
 /// <summary>
 /// Loads a component description from the stream and adds it to the component descriptions store.
 /// </summary>
 /// <param name="stream">The stream to load from.</param>
 /// <param name="type">The type to find within the description.</param>
 /// <returns>A configuration with the loaded component description if it was available, null if it could not be loaded.</returns>
 private static ComponentIdentifier LoadDescription(EmbedComponentData data, IOComponentType type)
 {
     if (data.ContentType == IO.CDDX.ContentTypeNames.BinaryComponent)
     {
         // Binary component
         var reader = new CircuitDiagram.IO.Descriptions.BinaryDescriptionReader();
         if (reader.Read(data.Stream))
         {
             var descriptions = reader.ComponentDescriptions;
             if (descriptions.Count > 0)
                 return FindIdentifier(type, descriptions[0]);
             else
                 return null;
         }
         else
         {
             // Load failed
             return null;
         }
     }
     else if (data.ContentType == "application/xml")
     {
         // XML component
         XmlLoader loader = new XmlLoader();
         loader.Load(data.Stream);
         if (loader.LoadErrors.Count() == 0)
         {
             var descriptions = loader.GetDescriptions();
             if (descriptions.Length > 0)
                 return FindIdentifier(type, descriptions[0]);
             else
                 return null;
         }
         else
         {
             // Load failed
             return null;
         }
     }
     else
     {
         // Unknown type
         return null;
     }
 }
        private static bool LoadXmlComponents()
        {
            bool conflictingGuid = false;

            var xmlLoader = new XmlLoader();
            foreach (string location in componentDirectories)
            {
                foreach (string file in System.IO.Directory.GetFiles(location, "*.xml", SearchOption.TopDirectoryOnly))
                {
                    using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        xmlLoader.Load(fs);
                        if (xmlLoader.LoadErrors.Count() == 0)
                        {
                            ComponentDescription description = xmlLoader.GetDescriptions()[0];
                            description.Metadata.Location = ComponentDescriptionMetadata.LocationType.Installed;
                            description.Source = new ComponentDescriptionSource(file, new System.Collections.ObjectModel.ReadOnlyCollection<ComponentDescription>(new ComponentDescription[] { description }));

                            // Check if duplicate GUID
                            if (!conflictingGuid && description.Metadata.GUID != Guid.Empty)
                            {
                                foreach (ComponentDescription compareDescription in ComponentHelper.ComponentDescriptions)
                                    if (compareDescription.Metadata.GUID == description.Metadata.GUID)
                                        conflictingGuid = true;
                            }

                            ComponentHelper.AddDescription(description);
                            if (ComponentHelper.WireDescription == null && description.ComponentName.ToLowerInvariant() == "wire" && description.Metadata.GUID == new Guid("6353882b-5208-4f88-a83b-2271cc82b94f"))
                                ComponentHelper.WireDescription = description;
                        }
                    }
                }
            }

            return conflictingGuid;
        }
Esempio n. 4
0
        private void TestComponent(string resource)
        {
            var assembly = Assembly.GetExecutingAssembly();
            var resources = assembly.GetManifestResourceNames();
            var resourceName = resources.First(r => r.EndsWith(resource));

            using (var xml = assembly.GetManifestResourceStream(resourceName))
            {
                var loader = new XmlLoader();
                loader.Load(xml);

                // Make sure there were no errors
                Assert.AreEqual(0, loader.LoadErrors.Count());

                var testDescription = loader.GetDescriptions()[0];

                // Check component data
                AssertMetadata(testDescription);
                AssertProperties(testDescription);
                AssertFlags(testDescription);
                AssertConnections(testDescription);
                AssertRender(testDescription);
            }
        }
Esempio n. 5
0
        private void TestComponent(string path)
        {
            using (var xml = File.OpenRead(path))
            {
                var loader = new XmlLoader();
                loader.Load(xml);

                // Make sure there were no errors
                Assert.AreEqual(0, loader.LoadErrors.Count());

                var testDescription = loader.GetDescriptions()[0];

                // Check component data
                AssertMetadata(testDescription);
                AssertProperties(testDescription);
                AssertFlags(testDescription);
                AssertConnections(testDescription);
                AssertRender(testDescription);
            }
        }