示例#1
0
文件: Program.cs 项目: NodeRT/NodeRT
        static bool GenerateAndBuildNamespace(string ns, 
            VsVersions vsVersion, WinVersions winVersion,string winmd,
            string npmPackageVersion, string npmScope, string outDir, bool noDefGen, bool noBuild, bool verbose)
        {
            string moduleOutDir = Path.Combine(outDir, ns.ToLower());

            if (!Directory.Exists(moduleOutDir))
            {
                Directory.CreateDirectory(moduleOutDir);
            }

            var generator = new NodeRTProjectGenerator(winVersion, vsVersion, !noDefGen);

            Console.WriteLine("Generating code for: {0}...", ns);

            try
            {
                Reflector.GenerateProject(winmd, ns, moduleOutDir, generator, npmPackageVersion, npmScope, null);
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to generate code, error: {0}", e.Message);
                return false;
            }

            if (!noBuild)
            {
                Console.WriteLine("Building {0}...", ns);

                try
                {
                    NodeRTProjectBuildUtils.BuildWithNodeGyp(moduleOutDir, vsVersion, verbose);
                }
                catch (IOException e)
                {
                    Console.WriteLine("IO Error occured after building the project, error: {0}", e.Message);
                    Console.WriteLine("Generated project files are located at: {0}", moduleOutDir);
                    return false;
                }
                catch (Exception)
                {
                    Console.WriteLine("Failed to build the generated project, please try to build the project manually");
                    Console.WriteLine("Generated project files are located at: {0}", moduleOutDir);
                    return false;
                }
                Console.WriteLine("NodeRT module generated and built successfully at: {0}", moduleOutDir);
            }
            return true;
        }
示例#2
0
        public static string GenerateProject(string winmdFile, string winRTNamespace, string destinationFolder, NodeRTProjectGenerator generator,
                                             string npmPackageVersion, string npmScope, string baseWinMDDir)
        {
            string ns        = ResolveNamespaceCasing(winmdFile, winRTNamespace, baseWinMDDir);
            var    mainModel = GenerateModel(winmdFile, ns, baseWinMDDir);

            return(generator.GenerateProject(ns, destinationFolder, winmdFile, npmPackageVersion, npmScope, mainModel));
        }
示例#3
0
        private void cmdGenerate_Click(object sender, EventArgs e)
        {
            // in case we have a single item just select it
            if (namespaceList.Items.Count == 1)
            {
                namespaceList.SelectedItem = namespaceList.Items[0];
            }

            if ((namespaceList.SelectedItem == null) || string.IsNullOrEmpty(txtFilename.Text))
            {
                MessageBox.Show("Please select a namespace to generate", "No namespace was chosen");
                return;
            }

            btnGenerate.Enabled = false;

            var winMdFile = txtFilename.Text;
            var winRTNamespace = namespaceList.SelectedItem.ToString();
            VsVersions vsVersion = (VsVersions)cmbTargetVs.SelectedIndex;

            NodeRTProjectBuildUtils.Platforms platforms = NodeRTProjectBuildUtils.Platforms.Win32;
            if (NodeRTProjectBuildUtils.IsRunningOn64Bit)
             platforms|= NodeRTProjectBuildUtils.Platforms.x64;

            string codeGenerationFolder = Path.Combine(txtProjectGenerationDirectory.Text, winRTNamespace.ToLower());
            string outputFolder = Path.Combine(txtOutputDirectory.Text, winRTNamespace.ToLower());

            var generator = new NodeRTProjectGenerator(txtProjectConfigurationRoot.Text, vsVersion);

            btnGenerate.Text = "Generating code...";
            bool succeeded = false;

            Task.Run(() =>
            {
                string slnPath;
                try
                {
                    slnPath = Reflector.GenerateProject(winMdFile, winRTNamespace, codeGenerationFolder,
                        generator, null);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to generate project file\n" + ex.Message,
                        "Failed to generate project file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw ex;
                }

                MethodInvoker invoker = new MethodInvoker(delegate() { btnGenerate.Text = "Building..."; });
                btnGenerate.Invoke(invoker);

                try
                {
                    NodeRTProjectBuildUtils.BuildAndCopyToOutputFolder(slnPath, vsVersion, outputFolder, platforms);
                    succeeded = true;
                }
                catch (IOException ex)
                {
                    MessageBox.Show("IO Error occured after building the project:\n" +
                        ex.Message + "\n" +
                        "You can access the project files at: " + codeGenerationFolder, "IO Error occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (Exception)
                {
                    MessageBox.Show("Failed to build the project from genreated code.\n" +
                        "Please try to build the project manually.\n" +
                        "You can access the project files at: " + codeGenerationFolder, "Failed to build project", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            })
            .ContinueWith((t) =>
            {
                btnGenerate.Enabled = true;
                btnGenerate.Text = "Generate and Build";

                if (succeeded)
                    MessageBox.Show("Yay! The generated NodeRT module is located at:\n" + outputFolder, "Success");
            },
            TaskScheduler.FromCurrentSynchronizationContext());
        }
示例#4
0
 public static string GenerateProject(string winmdFile, string winRTNamespace, string destinationFolder, NodeRTProjectGenerator generator, 
     string npmPackageVersion, string npmScope, string baseWinMDDir)
 {
     string ns = ResolveNamespaceCasing(winmdFile, winRTNamespace, baseWinMDDir);
     var mainModel = GenerateModel(winmdFile, ns, baseWinMDDir);
     return generator.GenerateProject(ns, destinationFolder, winmdFile, npmPackageVersion, npmScope, mainModel);
 }
示例#5
0
文件: MainForm.cs 项目: NodeRT/NodeRT
        private void cmdGenerate_Click(object sender, EventArgs e)
        {
            // in case we have a single item just select it
            if (namespaceList.Items.Count == 1)
            {
                namespaceList.SelectedItem = namespaceList.Items[0];
            }

            if ((namespaceList.SelectedItem == null) || string.IsNullOrEmpty(txtFilename.Text))
            {
                MessageBox.Show("Please select a namespace to generate", "No namespace was chosen");
                return;
            }

            btnGenerate.Enabled = false;

            var winMdFile = txtFilename.Text;
            var winRTNamespace = namespaceList.SelectedItem.ToString();
            VsVersions vsVersion = (VsVersions)cmbVsVersion.SelectedIndex;
            WinVersions winVersion = (WinVersions)cmbWindowsVersion.SelectedIndex;
            string outputFolder = Path.Combine(txtOutputDirectory.Text, winRTNamespace.ToLower());

            string errorMessage;
            if (!NodeRTProjectGenerator.VerifyVsAndWinVersions(winVersion, vsVersion, out errorMessage))
            {
                MessageBox.Show("Unsupported Windows and VS combination:\n" + errorMessage, "Unssuported options", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnGenerate.Enabled = true;
                return;
            }

            var generator = new NodeRTProjectGenerator(winVersion, vsVersion, chkDefGen.Checked);
            bool buildModule = chkBuildModule.Checked;

            btnGenerate.Text = "Generating code...";
            bool succeeded = false;

            Task.Run(() =>
            {
                string modulePath;
                try
                {
                    modulePath = Reflector.GenerateProject(winMdFile, winRTNamespace, outputFolder,
                        generator, null, null, null);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to generate project file\n" + ex.Message,
                        "Failed to generate project file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw ex;
                }

                MethodInvoker invoker = new MethodInvoker(delegate() { btnGenerate.Text = "Building..."; });
                btnGenerate.Invoke(invoker);

                if (buildModule)
                {
                    try
                    {
                        NodeRTProjectBuildUtils.BuildWithNodeGyp(modulePath, vsVersion);
                        succeeded = true;
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show("IO Error occured after building the project:\n" +
                            ex.Message + "\n" +
                            "You can access the project files at: " + outputFolder, "IO Error occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Failed to build the project from genreated code.\n" +
                            "Please try to build the project manually.\n" +
                            "You can access the project files at: " + outputFolder, "Failed to build project", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    succeeded = true;
                }
            })
            .ContinueWith((t) =>
            {
                btnGenerate.Enabled = true;
                if (chkBuildModule.Checked)
                    btnGenerate.Text = "Generate and build module";
                else
                    btnGenerate.Text = "Generate module";

                if (succeeded)
                    MessageBox.Show("Yay! The generated NodeRT module is located at:\n" + outputFolder, "Success");
            },
            TaskScheduler.FromCurrentSynchronizationContext());
        }
示例#6
0
文件: Program.cs 项目: nvdnkpr/NodeRT
        static bool GenerateAndBuildNamespace(string nodeSrcDir, string ns, 
            VsVersions vsVersion, string winmd, string outDir, string codeGenDir)
        {
            string moduleCodeGenDir = Path.Combine(codeGenDir, ns.ToLower());
            string moduleOutDir = Path.Combine(outDir, ns.ToLower());

            if (!Directory.Exists(moduleCodeGenDir))
            {
                Directory.CreateDirectory(moduleCodeGenDir);
            }

            if (!Directory.Exists(moduleOutDir))
            {
                Directory.CreateDirectory(moduleOutDir);
            }

            if (String.IsNullOrEmpty(nodeSrcDir))
            {
                nodeSrcDir = NodeRTProjectGenerator.DefaultDir;
            }

            if (String.IsNullOrEmpty(nodeSrcDir))
            {
                Console.WriteLine("Could not resolve node src dir, please specify a --nodesrcdir argument, as described below");
                PrintHelpAndExitWithError();
            }

            NodeRTProjectBuildUtils.Platforms platforms = NodeRTProjectBuildUtils.Platforms.Win32;

            if (NodeRTProjectBuildUtils.IsRunningOn64Bit)
                platforms |=  NodeRTProjectBuildUtils.Platforms.x64;

            var generator = new NodeRTProjectGenerator(nodeSrcDir, vsVersion);

            Console.WriteLine("Generating code for: {0}...", ns);

            string slnPath;
            try
            {
                slnPath = Reflector.GenerateProject(winmd, ns, moduleCodeGenDir, generator, null);
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to generate code, error: {0}", e.Message);
                return false;
            }

            Console.WriteLine("Building {0}...", ns);

            try
            {
                NodeRTProjectBuildUtils.BuildAndCopyToOutputFolder(slnPath, vsVersion, moduleOutDir, platforms);
            }
            catch (IOException e)
            {
                Console.WriteLine("IO Error occured after building the project, error: {0}", e.Message);
                Console.WriteLine("Generated project files are located at: {0}", moduleCodeGenDir);
                return false;
            }
            catch (Exception)
            {
                Console.WriteLine("Failed to build the generated project, please try to build the project manually");
                Console.WriteLine("Generated project files are located at: {0}", moduleCodeGenDir);
                return false;
            }
            Console.WriteLine("NodeRT module generated and built successfully at: {0}", moduleOutDir);
            return true;
        }