예제 #1
0
        public ProtoCollection Import(IEnumerable<string> inputProto)
        {
            var collection = new ProtoCollection();

            //Files from command line arguments, all import statements will be followed
            var basePath = Path.Combine(Path.GetFullPath(Directory.GetCurrentDirectory()), "dummy"); 
            foreach (string rawPath in inputProto)
            {
                string protoPath = GetFullPath(basePath, rawPath);
                var proto = Import(protoPath);
                collection.Merge(proto);

                //Include non public imports for the first level
                foreach (var path in proto.Import)
                    toImport.Add(GetFullPath(protoPath, path));
            }

            //Read imported files, nested
            while (toImport.Count != 0)
            {
                var path = toImport[0];
                toImport.RemoveAt(0);

                var c = Import(path);
                if (c != null)
                {
                    //Mark imported
                    c.MarkImported();

                    collection.Merge(c);
                }
            }
            return collection;
        }
예제 #2
0
        public ProtoCollection Import(IEnumerable <string> inputProto)
        {
            var collection = new ProtoCollection();

            //Files from command line arguments, all import statements will be followed
            var basePath = Path.Combine(Path.GetFullPath(Directory.GetCurrentDirectory()), "dummy");

            foreach (string rawPath in inputProto)
            {
                string protoPath = GetFullPath(basePath, rawPath);
                var    proto     = Import(protoPath);
                collection.Merge(proto);

                //Include non public imports for the first level
                foreach (var path in proto.Import)
                {
                    toImport.Add(GetFullPath(protoPath, path));
                }
            }

            //Read imported files, nested
            while (toImport.Count != 0)
            {
                var path = toImport[0];
                toImport.RemoveAt(0);

                var c = Import(path);
                if (c != null)
                {
                    collection.Merge(c);
                }
            }
            return(collection);
        }
예제 #3
0
파일: Main.cs 프로젝트: yanhkim/ProtoBuf
        public static int Main(string[] args)
        {
            var options = Options.Parse(args);

            if (options == null)
            {
                return(-1);
            }

            ProtoCollection collection = new ProtoCollection();

            foreach (string protoPath in options.InputProto)
            {
                try
                {
                    Console.WriteLine("Parsing " + protoPath);

                    var proto = new ProtoCollection();
                    ProtoParser.Parse(protoPath, proto);
                    collection.Merge(proto);
                }
                catch (ProtoFormatException pfe)
                {
                    Console.WriteLine();
                    Console.WriteLine(pfe.SourcePath.Path + "(" + pfe.SourcePath.Line + "," + pfe.SourcePath.Column + "): error CS001: " + pfe.Message);
                    return(-1);
                }
            }

            Console.WriteLine(collection);

            //Interpret and reformat
            try
            {
                var pp = new ProtoPrepare(options);
                pp.Prepare(collection);
            }
            catch (ProtoFormatException pfe)
            {
                Console.WriteLine();
                Console.WriteLine(pfe.SourcePath.Path + "(" + pfe.SourcePath.Line + "," + pfe.SourcePath.Column + "): error CS001: " + pfe.Message);
                return(-1);
            }

            //Generate code
            ProtoCode.Save(collection, options);
            Console.WriteLine("Saved: " + options.OutputPath);
            return(0);
        }
예제 #4
0
파일: Main.cs 프로젝트: 4eJI0Be4ur/ProtoBuf
        public static int Main(string[] args)
        {
            var options = Options.Parse(args);
            if(options == null)
                return -1;

            ProtoCollection collection = new ProtoCollection();

            foreach(string protoPath in options.InputProto)
            {
                try
                {
                    Console.WriteLine("Parsing " + protoPath);

                    var proto = new ProtoCollection();
                    ProtoParser.Parse(protoPath, proto);
                    collection.Merge(proto);
                }
                catch (ProtoFormatException pfe)
                {
                    Console.WriteLine();
                    Console.WriteLine(pfe.SourcePath.Path + "(" + pfe.SourcePath.Line + "," + pfe.SourcePath.Column + "): error CS001: " + pfe.Message);
                    return -1;
                }
            }

            Console.WriteLine(collection);

            //Interpret and reformat
            try
            {
                var pp = new ProtoPrepare(options);
                pp.Prepare(collection);
            }
            catch (ProtoFormatException pfe)
            {
                Console.WriteLine();
                Console.WriteLine(pfe.SourcePath.Path + "(" + pfe.SourcePath.Line + "," + pfe.SourcePath.Column + "): error CS001: " + pfe.Message);
                return -1;
            }

            //Generate code
            ProtoCode.Save(collection, options);
            Console.WriteLine("Saved: " + options.OutputPath);
            return 0;
        }
예제 #5
0
파일: Builder.cs 프로젝트: ZeroCry/ProtoBuf
        public static void Build(Options options)
        {
            ProtoCollection collection = new ProtoCollection();

            foreach (string protoPath in options.InputProto)
            {
                try
                {
                    var proto = new ProtoCollection();
                    ProtoParser.Parse(protoPath, proto);
                    collection.Merge(proto);
                }
                catch (ProtoFormatException pfe)
                {
                    Console.WriteLine();
                    Console.WriteLine(pfe.SourcePath.Path + "(" + pfe.SourcePath.Line + "," + pfe.SourcePath.Column + "): error CS001: " + pfe.Message);
                    throw;
                }
            }

            Console.WriteLine(collection);

            //Interpret and reformat
            try
            {
                var pp = new ProtoPrepare(options);
                pp.Prepare(collection);
            }
            catch (ProtoFormatException pfe)
            {
                Console.WriteLine();
                Console.WriteLine(pfe.SourcePath.Path + "(" + pfe.SourcePath.Line + "," + pfe.SourcePath.Column + "): error CS001: " + pfe.Message);
                throw;
            }

            //Generate code
            ProtoCode.Save(collection, options);
            Console.WriteLine("Saved: " + options.OutputPath);
        }
예제 #6
0
파일: Main.cs 프로젝트: kyapp69/ProtoBuf
        public static int Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.Error.WriteLine("Usage:\n\tCodeGenerator.exe [--preserve-names] [--use-tabs] path-to.proto [path-to-second.proto [...]] [output.cs]");
                return(-1);
            }

            ProtoCollection collection = new ProtoCollection();
            string          outputPath = null;

            int argIndex = 0;

            while (args.Length > argIndex && args [argIndex].StartsWith("--"))
            {
                switch (args[argIndex])
                {
                case "--preserve-names":
                    ProtoPrepare.ConvertToCamelCase = false;
                    break;

                case ProtoPrepare.FixNameclashArgument:
                    ProtoPrepare.FixNameclash = true;
                    break;

                case "--use-tabs":
                    CodeWriter.IndentPrefix = "\t";
                    break;

                default:
                    Console.Error.WriteLine("Unknown option: " + args[argIndex]);
                    return(-1);
                }
                argIndex++;
            }

            while (argIndex < args.Length)
            {
                string protoPath = Path.GetFullPath(args[argIndex]);
                string protoBase = Path.Combine(
                    Path.GetDirectoryName(protoPath),
                    Path.GetFileNameWithoutExtension(protoPath));
                argIndex += 1;

                //First .proto filename is used as output unless specified later
                if (outputPath == null)
                {
                    outputPath = protoBase + ".cs";
                }

                //Handle last argument as the output .cs path
                if (argIndex == args.Length && protoPath.EndsWith(".cs"))
                {
                    outputPath = protoPath;
                    break;
                }

                //Handle last argument as the output path
                //Filename is taken from first .proto argument
                if (argIndex == args.Length && protoPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
                {
                    Directory.CreateDirectory(protoPath);

                    // Replace the original output directory with the custom one
                    outputPath = Path.Combine(protoPath, Path.GetFileName(outputPath));
                    break;
                }

                if (File.Exists(protoPath) == false)
                {
                    Console.Error.WriteLine("File not found: " + protoPath);
                    return(-1);
                }

                try
                {
                    var proto = new ProtoCollection();

                    //Parse .proto
                    Console.WriteLine("Parsing " + protoPath);
                    ProtoParser.Parse(protoPath, proto);

                    collection.Merge(proto);
                } catch (ProtoFormatException pfe)
                {
                    Console.WriteLine();
                    Console.WriteLine(pfe.SourcePath.Path + "(" + pfe.SourcePath.Line + "," + pfe.SourcePath.Column + "): error CS001: " + pfe.Message);
                    return(-1);
                }
            }

            Console.WriteLine(collection);

            //Interpret and reformat
            try
            {
                ProtoPrepare.Prepare(collection);
            } catch (ProtoFormatException pfe)
            {
                Console.WriteLine();
                Console.WriteLine(pfe.SourcePath.Path + "(" + pfe.SourcePath.Line + "," + pfe.SourcePath.Column + "): error CS001: " + pfe.Message);
                return(-1);
            }

            //Generate code
            ProtoCode.Save(collection, outputPath);
            Console.WriteLine("Saved: " + outputPath);
            return(0);
        }
예제 #7
0
        public static int Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.Error.WriteLine("Usage:\n\tCodeGenerator.exe [--preserve-names] [--use-tabs] path-to.proto [path-to-second.proto [...]] [output.cs]");
                return -1;
            }

            ProtoCollection collection = new ProtoCollection();
            string outputPath = null;

            int argIndex = 0;

            while (args.Length > argIndex && args [argIndex].StartsWith("--"))
            {
                switch (args[argIndex])
                {
                    case "--preserve-names":
                        ProtoPrepare.ConvertToCamelCase = false;
                        break;
                    case ProtoPrepare.FixNameclashArgument:
                        ProtoPrepare.FixNameclash = true;
                        break;
                    case "--use-tabs":
                        CodeWriter.IndentPrefix = "\t";
                        break;
                    default:
                        Console.Error.WriteLine("Unknown option: " + args[argIndex]);
                        return -1;
                }
                argIndex++;
            }

            while (argIndex < args.Length)
            {
                string protoPath = Path.GetFullPath(args[argIndex]);
                string protoBase = Path.Combine(
                    Path.GetDirectoryName(protoPath),
                    Path.GetFileNameWithoutExtension(protoPath));
                argIndex += 1;

                //First .proto filename is used as output unless specified later
                if (outputPath == null)
                    outputPath = protoBase + ".cs";

                //Handle last argument as the output .cs path
                if (argIndex == args.Length && protoPath.EndsWith(".cs"))
                {
                    outputPath = protoPath;
                    break;
                }

                //Handle last argument as the output path
                //Filename is taken from first .proto argument
                if (argIndex == args.Length && protoPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
                {
                    Directory.CreateDirectory(protoPath);

                    // Replace the original output directory with the custom one
                    outputPath = Path.Combine(protoPath, Path.GetFileName(outputPath));
                    break;
                }

                if (File.Exists(protoPath) == false)
                {
                    Console.Error.WriteLine("File not found: " + protoPath);
                    return -1;
                }

                try
                {
                    var proto = new ProtoCollection();

                    //Parse .proto
                    Console.WriteLine("Parsing " + protoPath);
                    ProtoParser.Parse(protoPath, proto);

                    collection.Merge(proto);
                } catch (ProtoFormatException pfe)
                {
                    Console.WriteLine();
                    Console.WriteLine(pfe.SourcePath.Path + "(" + pfe.SourcePath.Line + "," + pfe.SourcePath.Column + "): error CS001: " + pfe.Message);
                    return -1;
                }
            }

            Console.WriteLine(collection);

            //Interpret and reformat
            try
            {
                ProtoPrepare.Prepare(collection);
            } catch (ProtoFormatException pfe)
            {
                Console.WriteLine();
                Console.WriteLine(pfe.SourcePath.Path + "(" + pfe.SourcePath.Line + "," + pfe.SourcePath.Column + "): error CS001: " + pfe.Message);
                return -1;
            }

            //Generate code
            ProtoCode.Save(collection, outputPath);
            Console.WriteLine("Saved: " + outputPath);
            return 0;
        }