예제 #1
0
파일: MainForm.cs 프로젝트: pauze3220/Node
        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, "Unsupported 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 occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Failed to build the project from generated 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());
        }
예제 #2
0
        static void Main(string[] args)
        {
            var argsDictionary = ParseCommandLineArgs(args);

            if (argsDictionary.ContainsKey("help"))
            {
                PrintHelp();
                return;
            }

            if (!ValidateArguments(argsDictionary))
            {
                PrintHelpAndExitWithError();
                return;
            }

            if (argsDictionary.ContainsKey("namespaces"))
            {
                PrintNamespaces(argsDictionary);
                return;
            }

            string winmd  = argsDictionary["winmd"];
            string outDir = argsDictionary["outdir"];

            bool noDefGen = argsDictionary.ContainsKey("nodefgen");
            bool noBuild  = argsDictionary.ContainsKey("nobuild");
            bool verbose  = argsDictionary.ContainsKey("verbose");

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

            string ns             = ValueOrNull(argsDictionary, "namespace");
            string customWinMdDir = ValueOrNull(argsDictionary, "customwinmddir");

            VsVersions  vsVersion  = VsVersions.Vs2017;
            WinVersions winVersion = WinVersions.v10;

            if (argsDictionary.ContainsKey("vs"))
            {
                if (!Enum.TryParse <VsVersions>(argsDictionary["vs"], true, out vsVersion))
                {
                    Console.WriteLine("Unsupported VS version. Supported options are: VS2017, VS2015, VS2013, VS2012");
                    Environment.Exit(1);
                }
            }

            if (argsDictionary.ContainsKey("winver"))
            {
                if (!NodeRTProjectGenerator.TryParseWinVersion(argsDictionary["winver"], out winVersion))
                {
                    Console.WriteLine("Unssuported Windows version. Supported options are: 10, 8.1, 8");
                    Environment.Exit(1);
                }
            }

            string npmPackageVersion = null;

            if (argsDictionary.ContainsKey("npmversion"))
            {
                npmPackageVersion = argsDictionary["npmversion"];
            }

            string npmPackageScope = null;

            if (argsDictionary.ContainsKey("npmscope"))
            {
                npmPackageScope = argsDictionary["npmscope"];
            }

            String errorMessage = null;

            if (!NodeRTProjectGenerator.VerifyVsAndWinVersions(winVersion, vsVersion, out errorMessage))
            {
                Console.WriteLine("Unssuported Windows and VS versions combination.");
                Console.WriteLine(errorMessage);
                Environment.Exit(1);
            }

            // generate specific namespace
            if (!String.IsNullOrEmpty(ns))
            {
                GenerateAndBuildNamespace(ns, vsVersion, winVersion, winmd,
                                          npmPackageVersion, npmPackageScope,
                                          outDir, noDefGen, noBuild, verbose);
            }
            else // try to generate & build all namespaces in winmd file
            {
                List <String> failedList = new List <string>();
                Console.WriteLine("Started to generate and build all namespaces in given WinMD...\n");
                foreach (string winRtNamespace in Reflector.GetNamespaces(winmd, customWinMdDir))
                {
                    if (!GenerateAndBuildNamespace(winRtNamespace,
                                                   vsVersion, winVersion, winmd,
                                                   npmPackageVersion, npmPackageScope, outDir, noDefGen, noBuild, verbose))
                    {
                        failedList.Add(winRtNamespace);
                    }
                    Console.WriteLine();
                }

                if (failedList.Count > 0)
                {
                    Console.WriteLine("Failed to generate or build for the following namespaces:");
                    foreach (string winRtNamespace in failedList)
                    {
                        Console.WriteLine("\t{0}", winRtNamespace);
                    }
                }
                else
                {
                    Console.WriteLine("Finished!");
                }
            }
        }