/// <summary>
        /// Function that builds the contents of the generated file based on the contents of the input file
        /// </summary>
        /// <param name="inputFileContent">Content of the input file</param>
        /// <returns>Generated file as a byte array</returns>
        protected override byte[] GenerateCode(string inputFileContent)
        {
            var vsItem = this.GetVSProjectItem();
            var name   = vsItem?.ProjectItem?.Document?.Name;
            var path   = vsItem?.ProjectItem?.Document?.Path;

            if (_protocPath == null)
            {
                IHaveProtoc protocFinder = new HaveProtoc(path, GenerateGRPC);
                if (protocFinder.HaveFoundProtoc)
                {
                    _protocPath = protocFinder.ProtocPath;
                    _grpcPath   = protocFinder.GrpcPath;
                }
            }

            if (string.IsNullOrEmpty(_protocPath))
            {
                this.GeneratorError(4, "Protoc.exe not found. Please read the documentation for ProtobufGenerator", 1, 1);
                return(null);
            }

            ICanGenerateFromProto generator = new GenerateFromProto(_protocPath, _grpcPath);

            try
            {
                var inputFile = Path.GetFileName(InputFilePath)
                                ?? (Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".proto");

                if (this.CodeGeneratorProgress != null)
                {
                    this.CodeGeneratorProgress.Progress(50, 100);
                }
                var res = generator.GenerateCsharpFromProto(Path.Combine(path, name));
                if (this.CodeGeneratorProgress != null)
                {
                    this.CodeGeneratorProgress.Progress(100, 100);
                }
                return(res);
            }
            catch (Exception e)
            {
                this.GeneratorError(4, e.ToString(), 1, 1);
                //Returning null signifies that generation has failed
                return(null);
            }
        }
示例#2
0
        /// <summary>
        /// Function that builds the contents of the generated file based on the contents of the input file
        /// </summary>
        /// <param name="inputFileContent">Content of the input file</param>
        /// <returns>Generated file as a byte array</returns>
        protected override byte[] GenerateCode(string inputFileContent)
        {
            var vsItem = this.GetVSProjectItem();
            var name   = vsItem?.ProjectItem?.Name;
            var path   = vsItem?.ProjectItem?.Document?.Path;

            if (_protocPath == null)
            {
                IHaveProtoc protocFinder = new HaveProtoc(path);
                if (protocFinder.HaveFoundProtoc)
                {
                    _protocPath = protocFinder.ProtocPath;
                }
            }
            if (_protocPath == null)
            {
                this.GeneratorError(4, "Protoc.exe not found. Please read the documentation for ProtobufGenerator", 1, 1);
                return(null);
            }

            ICanGenerateFromProto generator = new GenerateFromProto(_protocPath);

            try
            {
                if (this.CodeGeneratorProgress != null)
                {
                    this.CodeGeneratorProgress.Progress(50, 100);
                }
                var res = generator.GenerateCsharpFromProto(inputFileContent, path);
                if (this.CodeGeneratorProgress != null)
                {
                    this.CodeGeneratorProgress.Progress(100, 100);
                }
                return(res);
            }
            catch (Exception e)
            {
                this.GeneratorError(4, e.ToString(), 1, 1);
                //Returning null signifies that generation has failed
                return(null);
            }
        }