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(); } }
private static string configuration = "Debug"; //Debug, Release, etc. private static void Main(string[] args) { MessageTypeRegistry.Default.ParseAssemblyAndRegisterRosMessages(MessageTypeRegistry.Default.GetType().GetTypeInfo().Assembly); /*System.Console.WriteLine($"Process ID: {System.Diagnostics.Process.GetCurrentProcess().Id}"); * while (!System.Diagnostics.Debugger.IsAttached) * { * System.Threading.Thread.Sleep(1); * }*/ List <string> exclusionFilters = new List <string>(); List <string> sources = new List <string>(); bool interactive = false; //wait for ENTER press when complete int firstarg = 0; if (args.Length >= 1) { Dictionary <string, List <string> > arguments = ParseArguments(args); foreach (KeyValuePair <string, List <string> > data in arguments) { if (data.Key.Trim().Equals("-i")) { interactive = true; } else if (data.Key.Trim().Equals("-c")) { if (data.Value.Count > 0) { configuration = data.Value[0]; } else { configuration = "Debug"; } } else if (data.Key.Trim().Equals("-e")) { exclusionFilters.InsertRange(0, data.Value); } else if (data.Key.Trim().Equals("-s")) { sources.InsertRange(0, data.Value); } } } 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 (sources.Count >= 1) { solutiondir = new DirectoryInfo(sources[0]).FullName; } else { solutiondir = yamlparser_parent; } Templates.LoadTemplateStrings(Path.Combine(yamlparser_parent, "YAMLParser", "TemplateProject")); outputdir = Path.Combine(yamlparser_parent, outputdir); var paths = new List <MsgFileLocation>(); var pathssrv = new List <MsgFileLocation>(); var actionFileLocations = new List <MsgFileLocation>(); Console.WriteLine("Generating C# classes for ROS Messages...\n"); foreach (string source in sources) { string d = new DirectoryInfo(Path.GetFullPath(source)).FullName; Console.WriteLine($"Looking in {d}"); MsgFileLocator.findMessages(paths, pathssrv, actionFileLocations, exclusionFilters, d); } // 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)) { Console.WriteLine($"Skip file {path} because MessageBase already contains this message"); } else { msgsFiles.Add(new MsgFile(path)); } } Debug.WriteLine($"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 (paths.Count + pathssrv.Count > 0) { MakeTempDir(); GenerateFiles(msgsFiles, srvFiles, actionFiles); GenerateProject(msgsFiles, srvFiles, actionFiles); 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(); } }
private static void Run(List <string> messageDirs, List <string> assemblies, IEnumerable <string> nugetPackages, string projectDir, bool interactive, string configuration, string projectName, string outputVersion) { InitializeLogger(); var programRootDir = GetYamlParserDirectory(); var tempDir = Path.Combine(Directory.GetParent(programRootDir.FullName).FullName, "Temp"); if (projectDir == null) { projectDir = Path.Combine(tempDir, projectName); } Templates.LoadTemplateStrings(Path.Combine(programRootDir.FullName, "TemplateProject")); SetProjectVersion(outputVersion); BuildExternalProjectReferences(assemblies, nugetPackages, projectName, programRootDir, tempDir); using (new AssemblyResolver(externalMessageAssemblies, AppDomain.CurrentDomain)) { RegisterExternalMessageAssemblies(); 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); } // 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)); } // second 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(); if (paths.Count + pathssrv.Count + actionFiles.Count > 0) { CreateProjectDir(projectDir); GenerateFiles(msgsFiles, srvFiles, actionFiles, projectDir); GenerateProject(msgsFiles, srvFiles, projectName, projectDir); BuildProject(configuration, projectName, projectDir); } 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(); } } }
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(); } }
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 }