Esempio n. 1
0
        public void AddAllInPackagePath(string packagePath, string packageName)
        {
            if (string.IsNullOrEmpty(packagePath))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(packagePath));
            }

            if (string.IsNullOrEmpty(packageName))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(packageName));
            }

            if (packages.Contains(packageName))
            {
                throw new ArgumentException($"Package '{packageName}' has already been added!", nameof(packageName));
            }

            packages.Add(packageName);

            List <string> msgFullPaths = new List <string>();

            CollectMsgFiles(packagePath, msgFullPaths);

            foreach (string msgPath in msgFullPaths)
            {
                ClassInfo classInfo = new ClassInfo(packageName, msgPath);
                messages.Add(classInfo.FullRosName, classInfo);
            }

            List <string> srvFullPaths = new List <string>();

            CollectSrvFiles(packagePath, srvFullPaths);

            foreach (string srvPath in srvFullPaths)
            {
                ServiceInfo classInfo = new ServiceInfo(packageName, srvPath);
                services.Add(classInfo.FullRosName, classInfo);
            }

            List <string> actionFullPaths = new List <string>();

            CollectActionFiles(packagePath, actionFullPaths);

            foreach (string actionPath in actionFullPaths)
            {
                var actionClasses = ActionGenerator.GenerateFor(packageName, actionPath);
                if (actionClasses == null)
                {
                    continue;
                }

                foreach (var classInfo in actionClasses)
                {
                    messages[classInfo.FullRosName] = classInfo;
                }
            }
        }
Esempio n. 2
0
        static void CreateIndividualMessages(string[] args, string fullOutputPath, string package)
        {
            if (!Directory.Exists(fullOutputPath))
            {
                Console.WriteLine($"EE Output path '{fullOutputPath}' does not exist.");
                return;
            }

            var messageFullPaths = new List <string>();
            var serviceFullPaths = new List <string>();
            var actionFullPaths  = new List <string>();

            foreach (string path in args.Skip(5))
            {
                string absolutePath = Path.GetFullPath(path);
                if (!File.Exists(absolutePath))
                {
                    Console.WriteLine($"EE File path '{absolutePath}' does not exist.");
                    return;
                }

                Console.WriteLine(absolutePath);
                string extension = Path.GetExtension(absolutePath);
                switch (extension)
                {
                case ".msg":
                    messageFullPaths.Add(absolutePath);
                    break;

                case ".srv":
                    serviceFullPaths.Add(absolutePath);
                    break;

                case ".action":
                    actionFullPaths.Add(absolutePath);
                    break;

                default:
                    Console.WriteLine($"EE File path '{absolutePath}' has an unknown extension.");
                    return;
                }
            }

            if (messageFullPaths.Count == 0 && serviceFullPaths.Count == 0 && actionFullPaths.Count == 0)
            {
                Console.WriteLine("** No files given. Nothing to do.");
                return;
            }

            if (messageFullPaths.Count != 0)
            {
                Directory.CreateDirectory($"{fullOutputPath}/msg/");
            }

            if (serviceFullPaths.Count != 0)
            {
                Directory.CreateDirectory($"{fullOutputPath}/srv/");
            }

            foreach (string fullPath in messageFullPaths)
            {
                ClassInfo classInfo = new ClassInfo(package, fullPath);
                string    classCode = classInfo.ToCsString();
                string    destPath  = $"{fullOutputPath}/msg/{classInfo.Name}.cs";
                File.WriteAllText(destPath, classCode);
            }

            foreach (string fullPath in serviceFullPaths)
            {
                ServiceInfo serviceInfo = new ServiceInfo(package, fullPath);
                string      classCode   = serviceInfo.ToCsString();
                string      destPath    = $"{fullOutputPath}/srv/{serviceInfo.Name}.cs";
                File.WriteAllText(destPath, classCode);
            }

            foreach (string fullPath in actionFullPaths)
            {
                var actionClasses = ActionGenerator.GenerateFor(package, fullPath);
                if (actionClasses == null)
                {
                    continue;
                }

                foreach (ClassInfo classInfo in actionClasses)
                {
                    string classCode = classInfo.ToCsString();
                    string destPath  = $"{fullOutputPath}/msg/{classInfo.Name}.cs";
                    File.WriteAllText(destPath, classCode);
                }
            }

            Console.WriteLine("** Done!");
        }