public GeneratorConfiguration FromProject(string destinationProjectFolderOrFileName, string assemblyName)
        {
            (string projectFolder, string projectFilePath) =
                GeneratorConfigurationUtils.GetFullFileAndFolderPaths(destinationProjectFolderOrFileName);

            if (string.IsNullOrEmpty(projectFolder) ||
                !Directory.Exists(projectFolder))
            {
                return(null);
            }

            var codeGenConfig = FromConfigFile(projectFolder, assemblyName);

            if (codeGenConfig != null)
            {
                return(codeGenConfig);
            }

            if (string.IsNullOrEmpty(projectFilePath))
            {
                projectFilePath = GeneratorConfigurationUtils.FindFirstProjectFile(projectFolder);
            }

            if (string.IsNullOrEmpty(projectFilePath) ||
                !File.Exists(projectFilePath))
            {
                return(null);
            }

            var language = GeneratorConfigurationUtils.DeriveCodeGenLanguage(projectFilePath);

            return(FromAbiFilesInProject(projectFilePath, assemblyName, language));
        }
예제 #2
0
        public IEnumerable <ContractProjectGenerator> FromAbiFilesInProject(string projectFileName, string assemblyName, CodeGenLanguage language)
        {
            var projectFolder = Path.GetDirectoryName(projectFileName);
            var abiFiles      = Directory.GetFiles(projectFolder, "*.abi", SearchOption.AllDirectories);
            var contracts     = new List <ContractDefinition>(abiFiles.Length);

            foreach (var file in abiFiles)
            {
                var contractName = Path.GetFileNameWithoutExtension(file);
                var binFileName  = Path.Combine(Path.GetDirectoryName(file), contractName + ".bin");
                var byteCode     = File.Exists(binFileName) ? File.ReadAllText(binFileName) : string.Empty;

                contracts.Add(new ContractDefinition(File.ReadAllText(file))
                {
                    ContractName = contractName,
                    Bytecode     = byteCode
                });
            }

            var generator = new ProjectGenerator
            {
                Language     = language,
                Contracts    = contracts,
                OutputFolder = projectFolder,
                Namespace    = GeneratorConfigurationUtils.CreateNamespaceFromAssemblyName(assemblyName)
            };

            return(generator.GetProjectGenerators());
        }
        public GeneratorConfiguration FromConfigFile(string destinationProjectFolder, string assemblyName)
        {
            var configFilePath = GeneratorConfigurationUtils.DeriveConfigFilePath(destinationProjectFolder);

            if (!File.Exists(configFilePath))
            {
                return(null);
            }

            var configuration = GeneratorConfiguration.FromJson(configFilePath);

            if (configuration == null)
            {
                return(null);
            }

            var defaultNamespace = GeneratorConfigurationUtils.CreateNamespaceFromAssemblyName(assemblyName);

            foreach (var abiConfiguration in configuration.ABIConfigurations)
            {
                abiConfiguration.ResolveEmptyValuesWithDefaults(defaultNamespace, destinationProjectFolder);
            }

            return(configuration);
        }
예제 #4
0
        public IEnumerable <ContractProjectGenerator> FromConfigFile(string destinationProjectFolder, string assemblyName)
        {
            var configFilePath = GeneratorConfigurationUtils.DeriveConfigFilePath(destinationProjectFolder);

            if (!File.Exists(configFilePath))
            {
                return(null);
            }

            var defaultNamespace = GeneratorConfigurationUtils.CreateNamespaceFromAssemblyName(assemblyName);
            var configuration    = ABICollectionConfiguration.FromJson(configFilePath);

            return(configuration.GetContractProjectGenerators(defaultNamespace, destinationProjectFolder));
        }
        private static ABIConfiguration CreateAbiConfiguration(string abiFile, string projectFolder, string projectName, string assemblyName, CodeGenLanguage language)
        {
            var contractName = Path.GetFileNameWithoutExtension(abiFile);

            var binFileName = Path.Combine(Path.GetDirectoryName(abiFile), contractName + ".bin");
            var byteCode    = File.Exists(binFileName) ? File.ReadAllText(binFileName) : string.Empty;

            var abiConfig = new ABIConfiguration
            {
                CodeGenLanguage = language,
                ABI             = File.ReadAllText(abiFile),
                ByteCode        = byteCode,
                ContractName    = contractName
            };

            var defaultNamespace = GeneratorConfigurationUtils.CreateNamespaceFromAssemblyName(assemblyName);

            abiConfig.ResolveEmptyValuesWithDefaults(defaultNamespace, projectFolder);
            return(abiConfig);
        }
예제 #6
0
        public ContractProjectGenerator CreateGenerator(string defaultNamespace, string projectFolder)
        {
            SetBinPath();

            var abiString = ABI ?? GeneratorConfigurationUtils.GetFileContent(projectFolder, ABIFile);
            var byteCode  = ByteCode ?? GeneratorConfigurationUtils.GetFileContent(projectFolder, BinFile);
            var abi       = new GeneratorModelABIDeserialiser().DeserialiseABI(abiString);

            return(new ContractProjectGenerator(
                       abi,
                       ContractName,
                       byteCode,
                       BaseNamespace ?? defaultNamespace,
                       ServiceNamespace ?? $"{ContractName}.Service",
                       CQSNamespace ?? $"{ContractName}.CQS",
                       DTONamespace ?? $"{ContractName}.DTO",
                       BaseOutputPath ?? projectFolder,
                       Path.DirectorySeparatorChar.ToString(),
                       CodeGenLanguage
                       ));
        }
예제 #7
0
        public IEnumerable <ContractProjectGenerator> FromAbi(string contractName, string abiFilePath, string binFilePath, string baseNamespace, string outputFolder)
        {
            var abi = GeneratorConfigurationUtils.GetFileContent(outputFolder, abiFilePath);

            if (string.IsNullOrEmpty(abi))
            {
                throw new ArgumentException("Could not find abi file or abi content is empty");
            }

            if (string.IsNullOrEmpty(binFilePath))
            {
                binFilePath = abiFilePath.Replace(".abi", ".bin");
            }

            var byteCode = GeneratorConfigurationUtils.GetFileContent(outputFolder, binFilePath);

            if (string.IsNullOrEmpty(contractName))
            {
                contractName = Path.GetFileNameWithoutExtension(abiFilePath);
            }

            var generator = new ProjectGenerator
            {
                Namespace    = baseNamespace,
                OutputFolder = outputFolder,
                Contracts    = new List <ContractDefinition>
                {
                    new ContractDefinition(abi)
                    {
                        ContractName = contractName,
                        Bytecode     = byteCode
                    }
                }
            };

            return(generator.GetProjectGenerators());
        }
        public GeneratorConfiguration FromAbi(string contractName, string abiFilePath, string binFilePath, string baseNamespace, string outputFolder)
        {
            var config = new GeneratorConfiguration();

            var abi = GeneratorConfigurationUtils.GetFileContent(outputFolder, abiFilePath);

            if (string.IsNullOrEmpty(abi))
            {
                throw new ArgumentException("Could not find abi file or abi content is empty");
            }

            if (string.IsNullOrEmpty(binFilePath))
            {
                binFilePath = abiFilePath.Replace(".abi", ".bin");
            }

            var byteCode = GeneratorConfigurationUtils.GetFileContent(outputFolder, binFilePath);

            if (string.IsNullOrEmpty(contractName))
            {
                contractName = Path.GetFileNameWithoutExtension(abiFilePath);
            }

            var abiConfig = new ABIConfiguration
            {
                ABI          = abi,
                ByteCode     = byteCode,
                ContractName = contractName
            };

            abiConfig.ResolveEmptyValuesWithDefaults(baseNamespace, outputFolder);

            config.ABIConfigurations = new List <ABIConfiguration>();
            config.ABIConfigurations.Add(abiConfig);
            return(config);
        }