public void Run(CompileContext context)
        {
            var settings = new BinaryWriter.BinaryWriterSettings();

            if (context.Options.CertificateThumbprint != null)
                settings.Certificate = FindCertificate(context.Options.CertificateThumbprint);

            var writer = new BinaryWriter(context.Output, settings);
            writer.Descriptions.Add(context.Description);
            writer.Write();
        }
Beispiel #2
0
        private static bool CompileComponent(string inputPath, CompileOptions compileOptions)
        {
            List <ComponentDescription> componentDescriptions = new List <ComponentDescription>();
            List <BinaryResource>       binaryResources       = new List <BinaryResource>();

            XmlLoader loader = new XmlLoader();

            loader.Load(new FileStream(inputPath, FileMode.Open));

            if (loader.LoadErrors.Count(e => e.Category == LoadErrorCategory.Error) > 0)
            {
                foreach (var error in loader.LoadErrors)
                {
                    Console.WriteLine(error.ToString());
                }
                return(false);
            }

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

            description.ID = "C0";
            componentDescriptions.Add(description);

            SetIcons(compileOptions, description);

            string output = compileOptions.Output;

            if (!Path.HasExtension(output))
            {
                if (!Directory.Exists(output))
                {
                    Directory.CreateDirectory(output);
                }
                output += "\\" + description.ComponentName.ToLowerInvariant() + ".cdcom";
            }
            FileStream stream = new FileStream(output, FileMode.Create, FileAccess.Write);

            X509Certificate2 certificate = SelectCertificate(compileOptions);

            CircuitDiagram.IO.BinaryWriter.BinaryWriterSettings settings = new CircuitDiagram.IO.BinaryWriter.BinaryWriterSettings();
            settings.Certificate = certificate;
            CircuitDiagram.IO.BinaryWriter writer = new CircuitDiagram.IO.BinaryWriter(stream, settings);
            writer.Descriptions.AddRange(componentDescriptions);
            writer.Resources.AddRange(binaryResources);
            writer.Write();
            stream.Flush();

            return(true);
        }