コード例 #1
0
 /// <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);
     }
 }
コード例 #2
0
        private static bool LoadBinaryComponents()
        {
            bool conflictingGuid = false;

            X509Chain certChain = new X509Chain();

            foreach (string location in componentDirectories)
            {
                foreach (string file in System.IO.Directory.GetFiles(location, "*.cdcom", SearchOption.TopDirectoryOnly))
                {
                    var binLoader = new CircuitDiagram.IO.Descriptions.BinaryDescriptionReader();
                    binLoader.CertificateChain = certChain;

                    using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        if (binLoader.Read(fs))
                        {
                            var descriptions = binLoader.ComponentDescriptions;
                            ComponentDescriptionSource source = new ComponentDescriptionSource(file, new System.Collections.ObjectModel.ReadOnlyCollection <ComponentDescription>(descriptions));
                            foreach (ComponentDescription description in descriptions)
                            {
                                description.Metadata.Location = ComponentDescriptionMetadata.LocationType.Installed;
                                description.Source            = source;

                                // 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);
        }
コード例 #3
0
 /// <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;
     }
 }
コード例 #4
0
        private static bool LoadBinaryComponents()
        {
            bool conflictingGuid = false;

            X509Chain certChain = new X509Chain();
            foreach (string location in componentDirectories)
            {
                foreach (string file in System.IO.Directory.GetFiles(location, "*.cdcom", SearchOption.TopDirectoryOnly))
                {
                    var binLoader = new CircuitDiagram.IO.Descriptions.BinaryDescriptionReader();
                    binLoader.CertificateChain = certChain;

                    using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        if (binLoader.Read(fs))
                        {
                            var descriptions = binLoader.ComponentDescriptions;
                            ComponentDescriptionSource source = new ComponentDescriptionSource(file, new System.Collections.ObjectModel.ReadOnlyCollection<ComponentDescription>(descriptions));
                            foreach (ComponentDescription description in descriptions)
                            {
                                description.Metadata.Location = ComponentDescriptionMetadata.LocationType.Installed;
                                description.Source = source;

                                // 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;
        }