Example #1
0
        private static void Run(List <string> messageDirs, List <string> assemblies = null, string outputdir = null, bool interactive = false, string configuration = "Debug", string projectName = "Messages")
        {
            var loggerFactory = new LoggerFactory();

            loggerFactory.AddProvider(
                new ConsoleLoggerProvider(
                    (string text, LogLevel logLevel) => { return(logLevel >= LogLevel.Debug); }, true)
                );
            ApplicationLogging.LoggerFactory = loggerFactory;
            Logger = ApplicationLogging.CreateLogger("Program");

            string        yamlparser_parent = "";
            DirectoryInfo di = new DirectoryInfo(Directory.GetCurrentDirectory());

            while (di != null && di.Name != "YAMLParser")
            {
                di = Directory.GetParent(di.FullName);
            }
            if (di == null)
            {
                throw new InvalidOperationException("Not started from within YAMLParser directory.");
            }
            di = Directory.GetParent(di.FullName);
            yamlparser_parent = di.FullName;

            if (outputdir == null)
            {
                outputdir = yamlparser_parent;
                outputdir = Path.Combine(outputdir, DEFAULT_OUTPUT_FOLDERNAME);
            }

            Templates.LoadTemplateStrings(Path.Combine(yamlparser_parent, "YAMLParser", "TemplateProject"));

            MessageTypeRegistry.Default.ParseAssemblyAndRegisterRosMessages(MessageTypeRegistry.Default.GetType().GetTypeInfo().Assembly);

            if (assemblies != null)
            {
                string hints = "";
                foreach (var assembly in assemblies)
                {
                    var rosNetMessages = Assembly.LoadFile(Path.GetFullPath(assembly));
                    MessageTypeRegistry.Default.ParseAssemblyAndRegisterRosMessages(rosNetMessages);
                    hints += $@"
  <ItemGroup>
    <Reference Include=""Messages"">
      <HintPath>{assembly}</HintPath>
  
      </Reference>
  
    </ItemGroup>

  ";
                }

                Templates.MessagesProj = Templates.MessagesProj.Replace("$$HINTS$$", hints);
            }
            else
            {
                Templates.MessagesProj = Templates.MessagesProj.Replace("$$HINTS$$", "");
            }

            var paths               = new List <MsgFileLocation>();
            var pathssrv            = new List <MsgFileLocation>();
            var actionFileLocations = new List <MsgFileLocation>();

            Console.WriteLine("Generatinc C# classes for ROS Messages...\n");
            foreach (var messageDir in messageDirs)
            {
                string d = new DirectoryInfo(Path.GetFullPath(messageDir)).FullName;
                Console.WriteLine("Looking in " + d);
                MsgFileLocator.findMessages(paths, pathssrv, actionFileLocations, d);
            }
            // sort paths by priority
            paths = MsgFileLocator.sortMessages(paths);

            // first pass: create all msg files (and register them in static resolver dictionary)
            var baseTypes = MessageTypeRegistry.Default.GetTypeNames().ToList();

            foreach (MsgFileLocation path in paths)
            {
                var typeName = $"{path.package}/{path.basename}";
                if (baseTypes.Contains(typeName))
                {
                    Logger.LogInformation($"Skip file {path} because MessageBase already contains this message");
                }
                else
                {
                    msgsFiles.Add(new MsgFile(path));
                }
            }
            Logger.LogDebug($"Added {msgsFiles.Count} message files");

            foreach (MsgFileLocation path in pathssrv)
            {
                srvFiles.Add(new SrvFile(path));
            }

            // secend pass: parse and resolve types
            foreach (var msg in msgsFiles)
            {
                msg.ParseAndResolveTypes();
            }
            foreach (var srv in srvFiles)
            {
                srv.ParseAndResolveTypes();
            }

            var actionFileParser = new ActionFileParser(actionFileLocations);

            actionFiles = actionFileParser.GenerateRosMessageClasses();
            //var actionFiles = new List<ActionFile>();

            if (!StdMsgsProcessed()) // may seem obvious, but needed so that all other messages can build...
            {
                string resolvedPkgs = String.Join(", ", MsgFile.resolver.Keys.OrderBy(x => x.ToString()).ToArray());
                Console.WriteLine("Missing at least one of the following ROS packages: [\"" + String.Join("\", \"", required_packages) + "\"]. Exiting...");
                Console.WriteLine("resolver's keys: [" + resolvedPkgs + "]");
                return;
            }

            if (paths.Count + pathssrv.Count > 0)
            {
                MakeTempDir(outputdir);
                GenerateFiles(msgsFiles, srvFiles, actionFiles, outputdir);
                GenerateProject(msgsFiles, srvFiles, projectName, outputdir);
                BuildProject(configuration, projectName, outputdir);
            }
            else
            {
                Console.WriteLine("Usage:         YAMLParser.exe <SolutionFolder> [... other directories to search]\n      The Messages dll will be output to <SolutionFolder>/Messages/Messages.dll");
                if (interactive)
                {
                    Console.ReadLine();
                }
                Environment.Exit(1);
            }
            if (interactive)
            {
                Console.WriteLine("Finished. Press enter.");
                Console.ReadLine();
            }
        }
Example #2
0
        private static string configuration       = "Debug"; //Debug, Release, etc.
        private static void Main(string[] args)
        {
            string solutiondir;
            bool   interactive = false; //wait for ENTER press when complete
            int    firstarg    = 0;

            if (args.Length >= 1)
            {
                if (args[firstarg].Trim().Equals("-i"))
                {
                    interactive = true;
                    firstarg++;
                }
                configuration = args[firstarg++];
                if (args[firstarg].Trim().Equals("-i"))
                {
                    interactive = true;
                    firstarg++;
                }
            }
            string        yamlparser_parent = "";
            DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory);

            while (di.Name != "YAMLParser")
            {
                di = Directory.GetParent(di.FullName);
            }
            di = Directory.GetParent(di.FullName);
            yamlparser_parent = di.FullName;
            if (args.Length - firstarg >= 1)
            {
                solutiondir = new DirectoryInfo(args[firstarg]).FullName;
            }
            else
            {
                solutiondir = yamlparser_parent;
            }

            outputdir            = solutiondir + outputdir;
            outputdir_secondpass = solutiondir + outputdir_secondpass;
            List <MsgFileLocation> paths    = new List <MsgFileLocation>();
            List <MsgFileLocation> pathssrv = new List <MsgFileLocation>();

            Console.WriteLine("Generatinc C# classes for ROS Messages...\n");
            for (int i = firstarg; i < args.Length; i++)
            {
                string d = new DirectoryInfo(args[i]).FullName;
                Console.WriteLine("Spelunking in " + d);
                MsgFileLocator.findMessages(paths, pathssrv, d);
            }
            paths = MsgFileLocator.sortMessages(paths);
            foreach (MsgFileLocation path in paths)
            {
                msgsFiles.Add(new MsgsFile(path));
            }
            foreach (MsgFileLocation path in pathssrv)
            {
                srvFiles.Add(new SrvsFile(path));
            }
            if (paths.Count + pathssrv.Count > 0)
            {
                MakeTempDir();
                GenerateFiles(msgsFiles, srvFiles);
                GenerateProject(msgsFiles, srvFiles);
                BuildProject();
            }
            else
            {
                Console.WriteLine("Usage:         YAMLParser.exe <SolutionFolder> [... other directories to search]\n      The Messages dll will be output to <SolutionFolder>/Messages/Messages.dll");
                if (interactive)
                {
                    Console.ReadLine();
                }
                Environment.Exit(1);
            }
            if (interactive)
            {
                Console.WriteLine("Finished. Press enter.");
                Console.ReadLine();
            }
        }
Example #3
0
        private static string configuration       = "Debug"; //Debug, Release, etc.
        private static void Main(string[] args)
        {
#if NET35
            string solutiondir;
            bool   interactive = false; //wait for ENTER press when complete
            int    firstarg    = 0;
            if (args.Length >= 1)
            {
                if (args[firstarg].Trim().Equals("-i"))
                {
                    interactive = true;
                    firstarg++;
                }
                configuration = args[firstarg++];
                if (args[firstarg].Trim().Equals("-i"))
                {
                    interactive = true;
                    firstarg++;
                }
            }
            string        yamlparser_parent = "";
            DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory);
            while (di.Name != "YAMLParser")
            {
                di = Directory.GetParent(di.FullName);
            }
            di = Directory.GetParent(di.FullName);
            yamlparser_parent = di.FullName;
            if (args.Length - firstarg >= 1)
            {
                solutiondir = new DirectoryInfo(args[firstarg]).FullName;
            }
            else
            {
                solutiondir = yamlparser_parent;
            }

            outputdir            = Path.Combine(solutiondir, outputdir);
            outputdir_secondpass = Path.Combine(solutiondir, outputdir_secondpass);
            List <MsgFileLocation> paths    = new List <MsgFileLocation>();
            List <MsgFileLocation> pathssrv = new List <MsgFileLocation>();
            Console.WriteLine("Generatinc C# classes for ROS Messages...\n");
            for (int i = firstarg; i < args.Length; i++)
            {
                string d = new DirectoryInfo(args[i]).FullName;
                Console.WriteLine("Spelunking in " + d);
                MsgFileLocator.findMessages(paths, pathssrv, d);
            }
            paths = MsgFileLocator.sortMessages(paths);
            foreach (MsgFileLocation path in paths)
            {
                msgsFiles.Add(new MsgsFile(path));
            }
            foreach (MsgFileLocation path in pathssrv)
            {
                srvFiles.Add(new SrvsFile(path));
            }
            if (!StdMsgsProcessed()) // may seem obvious, but needed so that all other messages can resolve...
            {
                Console.WriteLine("std_msgs was not found in any search directory. Exiting...");
                return;
            }
            if (paths.Count + pathssrv.Count > 0)
            {
                MakeTempDir();
                GenerateFiles(msgsFiles, srvFiles);
                GenerateProject(msgsFiles, srvFiles);
                BuildProjectMSBUILD();
            }
            else
            {
                Console.WriteLine("Usage:         YAMLParser.exe <SolutionFolder> [... other directories to search]\n      The Messages dll will be output to <SolutionFolder>/Messages/Messages.dll");
                if (interactive)
                {
                    Console.ReadLine();
                }
                Environment.Exit(1);
            }
            if (interactive)
            {
                Console.WriteLine("Finished. Press enter.");
                Console.ReadLine();
            }
#elif NETCOREAPP2_1
            if (args.Length < 1)
            {
                Console.WriteLine("Usage:\tdotnet YAMLParser_NetCore.dll <DLL output path> [... other directories to search]\n\tThe Messages dll will be output to <DLL output folder>/Messages/Messages.dll");
                return;
            }

            string specifiedOutput = args[0];

            if (!Directory.Exists(specifiedOutput))
            {
                Console.WriteLine("DLL Output Path (" + specifiedOutput + ") does not exist");
                return;
            }

            outputdir = Path.Combine(specifiedOutput, outputdir);
            List <MsgFileLocation> msgFileLocs = new List <MsgFileLocation>();
            List <MsgFileLocation> srvFileLocs = new List <MsgFileLocation>();

            string[] searchDirectories = args.Skip(1).ToArray();
            foreach (string dir in searchDirectories)
            {
                if (!Directory.Exists(dir))
                {
                    Console.WriteLine("Skipping directory '" + dir + "' because it does not exist.");
                    continue;
                }
                string d = new DirectoryInfo(dir).FullName;
                Console.WriteLine("Spelunking in " + d);
                MsgFileLocator.findMessages(msgFileLocs, srvFileLocs, d);
            }

            if ((msgFileLocs.Count + srvFileLocs.Count) == 0)
            {
                Console.WriteLine("Not going to generate Messages.dll because there were no .msg or .srv files found in the specified arguments");
                return;
            }

            Console.WriteLine("Generating Messages C# project...");
            msgFileLocs = MsgFileLocator.sortMessages(msgFileLocs);
            foreach (MsgFileLocation path in msgFileLocs)
            {
                msgsFiles.Add(new MsgsFile(path));
            }
            foreach (MsgFileLocation path in srvFileLocs)
            {
                srvFiles.Add(new SrvsFile(path));
            }

            if (!StdMsgsProcessed()) // may seem obvious, but needed so that all other messages can resolve...
            {
                Console.WriteLine("std_msgs was not found in any search directory. Exiting...");
                return;
            }

            Console.WriteLine("making temp dir...");
            MakeTempDir();
            Console.WriteLine("Generating files...");
            GenerateFiles(msgsFiles, srvFiles);
            Console.WriteLine("Generating project...");
            GenerateProject(msgsFiles, srvFiles);
            Console.WriteLine("Building project...");
            Console.WriteLine("------------------------------------");
            BuildProjectNETCORE();
            Console.WriteLine("------------------------------------");
            Console.WriteLine("Done!");
#else
            Console.WriteLine("Unsupported TargetFramework. Must be .NET Framework v3.5 or .NET Core netcoreapp2.1");
            return;
#endif
        }