public BodyDeposits(GeneratorConfiguration resource, ConfigNode node)
            {
                if (node == null) { node = new ConfigNode(); }

                this.deposits = new List<Deposit>();
                this.seed = Misc.Parse(node.GetValue("Seed"), seedGenerator.Next());

                var random = new System.Random(seed);

                for (int i = 0; i < resource.DepositCount; i++)
                {
                    float R = random.Range(resource.MinRadius, resource.MaxRadius);
                    for (int j = 0; j < resource.NumberOfTries; j++)
                    {
                        Vector2 Pos = new Vector2(random.Range(R, 360 - R), random.Range(R, 180 - R));
                        var deposit = Deposit.Generate(Pos, R, random, resource);
                        if (!deposits.Any(d => d.Shape.Vertices.Any(v => deposit.Shape.PointInPolygon(new Vector2(v.x, v.y)))) && !deposit.Shape.Vertices.Any(v => deposits.Any(d => d.Shape.PointInPolygon(new Vector2(v.x, v.y)))))
                        {
                            deposits.Add(deposit);
                            break;
                        }
                    }
                }

                var depositValues = node.GetValues("Deposit");
                for (int i = 0; i < Math.Min(deposits.Count, depositValues.Length); i++)
                {
                    deposits[i].Quantity = Misc.Parse(depositValues[i], deposits[i].InitialQuantity);
                }

                MaxQuantity = resource.MaxQuantity;
            }
예제 #2
0
        public void GivenRelativeAbiFilePathInProject()
        {
            //given
            var factory = new GeneratorConfigurationFactory();
            var context = new ProjectTestContext(this.GetType().Name, MethodBase.GetCurrentMethod().Name);

            try
            {
                context.CreateProject();

                context.WriteFileToProject("solidity\\StandardContract.abi", TestContracts.StandardContract.ABI);
                context.WriteFileToProject("solidity\\StandardContract.bin", TestContracts.StandardContract.ByteCode);

                var generatorConfig = new GeneratorConfiguration
                {
                    ABIConfigurations = new List <ABIConfiguration>
                    {
                        new ABIConfiguration
                        {
                            ContractName = "StandardContractA",
                            ABIFile      = "solidity\\StandardContract.abi"
                        }
                    }
                };

                generatorConfig.SaveToJson(context.TargetProjectFolder);

                //when
                var config = factory.FromProject(context.TargetProjectFolder, context.OutputAssemblyName);

                //then
                Assert.Equal(1, config?.ABIConfigurations?.Count);
                var abiConfig = config.ABIConfigurations.First();
                Assert.NotNull(abiConfig);
                Assert.Equal(CodeGenLanguage.CSharp, abiConfig.CodeGenLanguage);
                Assert.Equal("StandardContractA", abiConfig.ContractName);
                Assert.Equal(TestContracts.StandardContract.ABI, abiConfig.ABI);
                Assert.Equal(TestContracts.StandardContract.ByteCode, abiConfig.ByteCode);
                Assert.Equal(context.TargetProjectFolder, abiConfig.BaseOutputPath);
                Assert.Equal(Path.GetFileNameWithoutExtension(context.OutputAssemblyName), abiConfig.BaseNamespace);
                Assert.Equal("StandardContractA.CQS", abiConfig.CQSNamespace);
                Assert.Equal("StandardContractA.DTO", abiConfig.DTONamespace);
                Assert.Equal("StandardContractA.Service", abiConfig.ServiceNamespace);
            }
            finally
            {
                context.CleanUp();
            }
        }
예제 #3
0
        public void Should_read_configuration_from_file()
        {
            var config = GeneratorConfiguration.FromFile("data/configbuddy.sets.xml");

            Assert.AreEqual("config-dir", config.ConfigDir);
            Assert.AreEqual("config-extension", config.ConfigExtension);
            Assert.AreEqual("config-root", config.ConfigRoot);
            Assert.AreEqual(true, config.Debug);
            Assert.AreEqual("output-dir", config.OutputDir);
            Assert.AreEqual("template-dir", config.TemplateDir);
            Assert.AreEqual("template-extension", config.TemplateExtension);
            Assert.AreEqual(2, config.Projects.Count);
            Assert.AreEqual("project1-name", config.Projects[0].Name);
            Assert.AreEqual("project1-path", config.Projects[0].Path);
        }
        private void GenerateClassesForIniFile(string pathToIniFile)
        {
            var configuration = new GeneratorConfiguration(pathToIniFile,
                                                           OutputFolder,
                                                           NameSpace,
                                                           MainConfigurationClassName,
                                                           BufferSize,
                                                           ListSeparator.ToCharArray().FirstOrDefault(),
                                                           GenerateIniOptionAttribute,
                                                           ImmutableConfiguration);

            var generator = new IniWrapperConfigurationGeneratorFactory().Create(configuration);

            generator.Generate();
        }
        /// <summary>   Constructor. </summary>
        ///
        /// <remarks>   Ken, 10/1/2020. </remarks>
        ///
        /// <param name="projectType">          Type of the project. </param>
        /// <param name="projectFolderRoot">    The project folder root. </param>
        /// <param name="templateFile">         The template file. </param>
        /// <param name="additionalOptions">    Options for controlling the additional. </param>
        /// <param name="generatorMode">        (Optional) The generator mode. </param>
        /// <param name="generatorOptions">     (Optional) Options for controlling the generator. </param>

        public BusinessModelGeneratorEngine(Guid projectType, string projectFolderRoot, string templateFile, Dictionary <string, object> additionalOptions, GeneratorMode generatorMode = GeneratorMode.Console, GeneratorOptions generatorOptions = null)
        {
            var thisAssembly = Assembly.GetEntryAssembly();
            var inputFiles   = new Dictionary <string, string> {
                { "templateFile", templateFile }
            };
            List <Type> types;

            this.projectType       = projectType;
            this.projectFolderRoot = projectFolderRoot;

            types = thisAssembly.GetAllTypes().OrderBy(t => t.Name).ToList();

            this.GeneratorConfiguration = new GeneratorConfiguration(projectType, projectFolderRoot, inputFiles, additionalOptions, generatorOptions, this, types);
            this.generatorMode          = generatorMode;
            this.generatorOptions       = generatorOptions;
        }
예제 #6
0
        public void Should_apply_property_transformation_for_its_properties()
        {
            var config = new GeneratorConfiguration();

            config.ConfigDir       = "aaa";
            config.ConfigExtension = "$(aaa)";
            config.ConfigRoot      = "aaa $(bbb)";

            var properties = new Dictionary <string, string> {
                { "aaa", "AAA" }, { "bbb", "BBB" }
            };

            config.ApplyProperties(properties);
            Assert.AreEqual("aaa", config.ConfigDir);
            Assert.AreEqual("AAA", config.ConfigExtension);
            Assert.AreEqual("aaa BBB", config.ConfigRoot);
        }
예제 #7
0
        public static void CreateTestGeneratorConfigFile(string outputFilePath)
        {
            var config = new GeneratorConfiguration
            {
                ABIConfigurations = new List <ABIConfiguration>
                {
                    new ABIConfiguration
                    {
                        ContractName = "StandardContract",
                        ABIFile      = "StandardContract.abi",
                        BinFile      = "StandardContract.bin"
                    }
                }
            };

            config.SaveToJson(outputFilePath);
        }
예제 #8
0
        public static void CreateTestGeneratorConfigFile(string outputFilePath)
        {
            var config = new GeneratorConfiguration
            {
                ABIConfigurations = new List <ABIConfiguration>
                {
                    new ABIConfiguration
                    {
                        ContractName = "EIP20",
                        ABI          = "[{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"}],\"name\":\"balances\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"cryptletProofKey\",\"type\":\"bytes32\"},{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"cryptletProofKey\",\"type\":\"bytes32\"},{\"name\":\"_from\",\"type\":\"address\"},{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"address\"}],\"name\":\"allowed\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"balance\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"bindingId\",\"type\":\"string\"},{\"name\":\"registryVersionHash\",\"type\":\"string\"},{\"name\":\"runtimeBindingHash\",\"type\":\"string\"},{\"name\":\"cryptletProofKey\",\"type\":\"bytes32\"}],\"name\":\"stampContract\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"cryptletProofKey\",\"type\":\"bytes32\"},{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"},{\"name\":\"_spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"name\":\"remaining\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"cryptletProofKey\",\"type\":\"bytes32\"},{\"name\":\"_initialAmount\",\"type\":\"uint256\"},{\"name\":\"_tokenName\",\"type\":\"string\"},{\"name\":\"_decimalUnits\",\"type\":\"uint8\"},{\"name\":\"_tokenSymbol\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"cryptletProofKey\",\"type\":\"bytes32\"},{\"indexed\":true,\"name\":\"_from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"cryptletProofKey\",\"type\":\"bytes32\"},{\"indexed\":true,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_spender\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"level\",\"type\":\"uint8\"},{\"indexed\":false,\"name\":\"message\",\"type\":\"string\"}],\"name\":\"Log\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"cryptletProofKey\",\"type\":\"bytes32\"}],\"name\":\"Created\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"cryptletProofKey\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"bindingId\",\"type\":\"string\"},{\"indexed\":false,\"name\":\"registryVersionHash\",\"type\":\"string\"},{\"indexed\":false,\"name\":\"runtimeBindingHash\",\"type\":\"string\"}],\"name\":\"CryptletStamp\",\"type\":\"event\"}]",
                        ByteCode     = "608060405234801561001057600080fd5b50604051610a34380380610a3483398101604090815281516020808401518385015160608601516080870151600160a060020a0333166000908152600186529687208490559583905590860180519496929590949193920191610078916003918601906100d1565b506004805460ff191660ff8416179055805161009b9060059060208401906100d1565b5060405185907f102d25c49d33fcdb8976a3f2744e0785c98d9e43b88364859e6aec4ae82eff5c90600090a2505050505061016c565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061011257805160ff191683800117855561013f565b8280016001018555821561013f579182015b8281111561013f578251825591602001919060010190610124565b5061014b92915061014f565b5090565b61016991905b8082111561014b5760008155600101610155565b90565b6108b98061017b6000396000f3006080604052600436106100b95763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100be57806318160ddd1461014857806327e235e31461016f578063313ce567146101905780633feb1bd8146101bb578063500d2f6d146101f65780635c6581651461022357806370a082311461024a5780638bfd72691461026b57806395d89b4114610344578063bf1ed1eb14610359578063dd62ed3e14610380575b600080fd5b3480156100ca57600080fd5b506100d36103a7565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561010d5781810151838201526020016100f5565b50505050905090810190601f16801561013a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015457600080fd5b5061015d610435565b60408051918252519081900360200190f35b34801561017b57600080fd5b5061015d600160a060020a036004351661043b565b34801561019c57600080fd5b506101a561044d565b6040805160ff9092168252519081900360200190f35b3480156101c757600080fd5b506101e2600435600160a060020a0360243516604435610456565b604080519115158252519081900360200190f35b34801561020257600080fd5b506101e2600435600160a060020a03602435811690604435166064356104ee565b34801561022f57600080fd5b5061015d600160a060020a03600435811690602435166105f3565b34801561025657600080fd5b5061015d600160a060020a0360043516610610565b34801561027757600080fd5b506040805160206004803580820135601f810184900484028501840190955284845261034294369492936024939284019190819084018382808284375050604080516020601f89358b018035918201839004830284018301909452808352979a99988101979196509182019450925082915084018382808284375050604080516020601f89358b018035918201839004830284018301909452808352979a999881019791965091820194509250829150840183828082843750949750509335945061062b9350505050565b005b34801561035057600080fd5b506100d361079d565b34801561036557600080fd5b506101e2600435600160a060020a03602435166044356107f8565b34801561038c57600080fd5b5061015d600160a060020a0360043581169060243516610862565b6003805460408051602060026001851615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561042d5780601f106104025761010080835404028352916020019161042d565b820191906000526020600020905b81548152906001019060200180831161041057829003601f168201915b505050505081565b60005481565b60016020526000908152604090205481565b60045460ff1681565b600160a060020a03331660009081526001602052604081205482111561047b57600080fd5b600160a060020a033381166000818152600160209081526040808320805488900390559387168083529184902080548701905583518681529351919388927ff8ca259b4b82670be7501ff56ad1fc9c7cd199d3431e3c502f2c5f86884bc150929181900390910190a45060019392505050565b600160a060020a03808416600081815260026020908152604080832033909516835293815283822054928252600190529182205483118015906105315750828110155b151561053c57600080fd5b600160a060020a03808516600090815260016020526040808220805487019055918716815220805484900390556000198110156105a157600160a060020a03808616600090815260026020908152604080832033909416835292905220805484900390555b604080518481529051600160a060020a03808716929088169189917ff8ca259b4b82670be7501ff56ad1fc9c7cd199d3431e3c502f2c5f86884bc150919081900360200190a450600195945050505050565b600260209081526000928352604080842090915290825290205481565b600160a060020a031660009081526001602052604090205490565b80600019167fbd823fd1310f6b49d60595ebd0b25acbd05842e81d0a07eaeb74879980af0f3685858560405180806020018060200180602001848103845287818151815260200191508051906020019080838360005b83811015610699578181015183820152602001610681565b50505050905090810190601f1680156106c65780820380516001836020036101000a031916815260200191505b50848103835286518152865160209182019188019080838360005b838110156106f95781810151838201526020016106e1565b50505050905090810190601f1680156107265780820380516001836020036101000a031916815260200191505b50848103825285518152855160209182019187019080838360005b83811015610759578181015183820152602001610741565b50505050905090810190601f1680156107865780820380516001836020036101000a031916815260200191505b50965050505050505060405180910390a250505050565b6005805460408051602060026001851615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561042d5780601f106104025761010080835404028352916020019161042d565b600160a060020a033381166000818152600260209081526040808320948716808452948252808320869055805186815290519294939288927f71dc57be39b79a8b1f8e288bc0ad3f1bc02a354d540618df5cb7ed1c95b9c140928290030190a45060019392505050565b600160a060020a039182166000908152600260209081526040808320939094168252919091522054905600a165627a7a72305820fc7ea7b251b34b3456c58e4d8a5f78817d2f4d0d2744a4fb4f551efa17fbc73f0029"
                    }
                }
            };

            config.SaveXml(outputFilePath);
        }
        public static string Enums(CodeTypeDeclaration ctd, GeneratorConfiguration configuration)
        {
            string declare = Format.Tabs(1);

            if (configuration.AssemblyVisible)
            {
                declare = "internal ";
            }
            else
            {
                declare = "public ";
            }


            declare = declare + "enum " + ctd.Name;

            return(declare);
        }
        private static SyntaxGeneratorFacade GetSyntaxGeneratorFacade(GeneratorConfiguration configuration)
        {
            if (configuration.ImmutableConfiguration)
            {
                return(new SyntaxGeneratorFacade(new IniOptionsAttributeSyntaxGenerator(),
                                                 new ImmutableListPropertyDeclarationSyntaxGenerator(),
                                                 new ImmutablePropertyDeclarationSyntaxGenerator(),
                                                 new Syntax.UsingSyntax.UsingSyntaxGenerator(),
                                                 new ClassDeclarationSyntaxGenerator(),
                                                 new ConstructorDeclarationSyntaxGenerator()));
            }

            return(new SyntaxGeneratorFacade(new IniOptionsAttributeSyntaxGenerator(),
                                             new ListPropertyDeclarationSyntaxGenerator(),
                                             new PropertyDeclarationSyntaxGenerator(),
                                             new Syntax.UsingSyntax.UsingSyntaxGenerator(),
                                             new ClassDeclarationSyntaxGenerator(),
                                             new ConstructorDeclarationSyntaxGenerator()));
        }
예제 #11
0
        public void Builder_Real_Test()
        {
            var config = new GeneratorConfiguration
            {
                GeneratorName = "NetCore3Solution",
                LocalFolder   = "F:\\Repos\\Modeller.SampleGenerators\\src\\Generators",
                Target        = "net5.0",
                OutputPath    = "f:\\dev\\test\\members",
                SourceModel   = "f:\\repos\\modeller.samplegenerators\\src\\members_model.json"
            };

            var logger          = new Mock <ILogger <IPackageService> >();
            var loggerContext   = new Mock <ILogger <IContext> >();
            var settingLoader   = new JsonSettingsLoader();
            var moduleLoader    = new JsonModuleLoader();
            var generatorLoader = new GeneratorLoader();
            var packageLoader   = new PackageFileLoader();
            var packageService  = new PackageService(packageLoader, logger.Object);

            var context = new Context(settingLoader, moduleLoader, generatorLoader, packageService, loggerContext.Object);

            var loggerCG      = new Mock <ILogger <ICodeGenerator> >();
            var loggerFW      = new Mock <ILogger <FileWriter> >();
            var loggerB       = new Mock <ILogger <IBuilder> >();
            var codeGenerator = new CodeGenerator(loggerCG.Object);

            var fileWriter = new FileWriter(loggerFW.Object);
            var fc1        = new CreateFile(fileWriter);
            var fc2        = new CreateFileGroup(fileWriter);
            var fc3        = new CreateProject(fileWriter);
            var fc4        = new CreateSnippet(fileWriter);
            var fc5        = new CreateSolution(fileWriter);
            var list       = new List <IFileCreator> {
                fc1, fc2, fc3, fc4, fc5
            };
            var outputStrategy = new OutputStrategy(list);

            var builder = new Builder(context, codeGenerator, outputStrategy, loggerB.Object);

            builder.Create(config);
        }
        public IIniWrapperConfigurationGenerator Create(GeneratorConfiguration configuration)
        {
            var iniWrapper    = new IniParserWrapper(configuration.FilePath, configuration.BufferSize, new ReadSectionsParser());
            var syntaxManager = new SyntaxKindManager(configuration.ListSeparator);

            var syntaxGeneratorFacade = GetSyntaxGeneratorFacade(configuration);

            var iniFileAnalyzer = new IniFileAnalyzer(iniWrapper,
                                                      new SectionsAnalyzer(configuration.ComplexDataSeparator),
                                                      syntaxManager,
                                                      new IniFileUsingsAnalyzer(configuration),
                                                      configuration.MainConfigurationClassName);

            var attributePropertyModifier  = GetPropertyDeclarationSyntaxModifier(configuration, syntaxGeneratorFacade);
            var classDeclarationGenerators = new List <IClassDeclarationGenerator>()
            {
                new PropertySyntaxGenerator(syntaxGeneratorFacade, attributePropertyModifier),
                new PropertyListSyntaxGenerator(syntaxGeneratorFacade, attributePropertyModifier),
            };

            if (configuration.ImmutableConfiguration)
            {
                classDeclarationGenerators.Add(new ConstructorSyntaxGenerator(syntaxGeneratorFacade));
            }

            var compilationUnitGenerators = new List <ICompilationUnitGenerator>()
            {
                new UsingSyntaxGenerator(syntaxGeneratorFacade),
                new ClassSyntaxGenerator(syntaxGeneratorFacade, classDeclarationGenerators, configuration.NameSpace)
            };

            var syntaxGenerators = new List <Syntax.Generators.ICompilationUnitGenerator>()
            {
                new ClassCompilationUnitGenerator(compilationUnitGenerators.AsReadOnly(), syntaxGeneratorFacade)
            };

            return(new IniWrapperConfigurationGenerator(syntaxGenerators,
                                                        iniFileAnalyzer,
                                                        new FileSystem(),
                                                        configuration));
        }
예제 #13
0
        private bool DetectFromConfig(GeneratorInfo generatorInfo, GeneratorConfiguration generatorConfiguration)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(generatorConfiguration.GeneratorPath))
                {
                    return(false);
                }

                var generatorFolder = Path.GetFullPath(
                    Path.Combine(VsxHelper.GetProjectFolder(project), generatorConfiguration.GeneratorPath));

                tracer.Trace("Generator is configured to be at " + generatorFolder, "VsGeneratorInfoProvider");
                return(DetectFromFolder(generatorInfo, generatorFolder));
            }
            catch (Exception exception)
            {
                tracer.Trace(exception.ToString(), "VsGeneratorInfoProvider");
                return(false);
            }
        }
        public override string FormatName(string name, GeneratorConfiguration configuration)
        {
            string result = "";
            var    list   = GetSeparatedWords(name, configuration);

            for (var i = 0; i < list.Count; i++)
            {
                var    word = list[i];
                string letter;
                if (i == 0)
                {
                    letter = word[0].ToString().ToLower();
                }
                else
                {
                    letter = word[0].ToString().ToUpper();
                }
                result += letter + word.Substring(1).ToLower();
            }
            return(Clean(result));
        }
        public static string Class(CodeTypeDeclaration ctd, GeneratorConfiguration configuration)
        {
            string declare = "";

            if (configuration.AssemblyVisible)
            {
                declare = "internal ";
            }
            else
            {
                declare = "public ";
            }

            if (ctd.IsPartial)
            {
                declare = declare + "partial ";
            }

            declare = declare + "class " + ctd.Name;

            return(declare);
        }
예제 #16
0
        public void FromAbi_CallsConfigFactory_GeneratesCode_SendsToWriter()
        {
            //given
            GeneratorConfiguration stubGeneratorConfiguration = CreateStubConfiguration();

            _mockGeneratorConfigurationFactory
            .Setup(f => f.FromAbi(
                       "StandardContract", "StandardContract.abi", "StandardContract.bin", "DefaultNamespace", "c:/temp"))
            .Returns(stubGeneratorConfiguration);

            IEnumerable <GeneratedFile> actualFilesSentToWriter = null;

            _mockGeneratedFileWriter
            .Setup(f => f.WriteFiles(It.IsAny <IEnumerable <GeneratedFile> >()))
            .Callback <IEnumerable <GeneratedFile> >((files) => actualFilesSentToWriter = files);

            //when
            _codeGenerationWrapper.FromAbi("StandardContract", "StandardContract.abi", "StandardContract.bin", "DefaultNamespace", "c:/temp", false);

            //then
            Assert.NotNull(actualFilesSentToWriter);
            Assert.True(actualFilesSentToWriter.ToArray().Length > 0);
        }
예제 #17
0
        public void FromProject_CallsConfigFactory_GeneratesCode_SendsToWriter()
        {
            //given
            GeneratorConfiguration stubGeneratorConfiguration = CreateStubConfiguration();

            _mockGeneratorConfigurationFactory
            .Setup(f => f.FromProject(
                       "c:/temp/projectx", "CompanyA.ProjectX.dll"))
            .Returns(stubGeneratorConfiguration);

            IEnumerable <GeneratedFile> actualFilesSentToWriter = null;

            _mockGeneratedFileWriter
            .Setup(f => f.WriteFiles(It.IsAny <IEnumerable <GeneratedFile> >()))
            .Callback <IEnumerable <GeneratedFile> >((files) => actualFilesSentToWriter = files);

            //when
            _codeGenerationWrapper.FromProject("c:/temp/projectx", "CompanyA.ProjectX.dll");

            //then
            Assert.NotNull(actualFilesSentToWriter);
            Assert.True(actualFilesSentToWriter.ToArray().Length > 0);
        }
예제 #18
0
            public BodyDeposits(GeneratorConfiguration resource, ConfigNode node)
            {
                if (node == null)
                {
                    node = new ConfigNode();
                }

                this.deposits = new List <Deposit>();
                this.seed     = Misc.Parse(node.GetValue("Seed"), seedGenerator.Next());

                var random = new System.Random(seed);

                for (int i = 0; i < resource.DepositCount; i++)
                {
                    float R = random.Range(resource.MinRadius, resource.MaxRadius);
                    for (int j = 0; j < resource.NumberOfTries; j++)
                    {
                        Vector2 Pos     = new Vector2(random.Range(R, 360 - R), random.Range(R, 180 - R));
                        var     deposit = Deposit.Generate(Pos, R, random, resource);
                        if (!deposits.Any(d => d.Shape.Vertices.Any(v => deposit.Shape.PointInPolygon(new Vector2(v.x, v.y)))) && !deposit.Shape.Vertices.Any(v => deposits.Any(d => d.Shape.PointInPolygon(new Vector2(v.x, v.y)))))
                        {
                            deposits.Add(deposit);
                            break;
                        }
                    }
                }

                var depositValues = node.GetValues("Deposit");

                for (int i = 0; i < Math.Min(deposits.Count, depositValues.Length); i++)
                {
                    deposits[i].Quantity = Misc.Parse(depositValues[i], deposits[i].InitialQuantity);
                }

                MaxQuantity = resource.MaxQuantity;
            }
예제 #19
0
        public TestGenerator(GeneratorConfiguration generatorConfiguration, ProjectSettings projectSettings, ITestHeaderWriter testHeaderWriter, ITestUpToDateChecker testUpToDateChecker)
        {
            if (generatorConfiguration == null)
            {
                throw new ArgumentNullException("generatorConfiguration");
            }
            if (projectSettings == null)
            {
                throw new ArgumentNullException("projectSettings");
            }
            if (testHeaderWriter == null)
            {
                throw new ArgumentNullException("testHeaderWriter");
            }
            if (testUpToDateChecker == null)
            {
                throw new ArgumentNullException("testUpToDateChecker");
            }

            this.generatorConfiguration = generatorConfiguration;
            this.testUpToDateChecker    = testUpToDateChecker;
            this.testHeaderWriter       = testHeaderWriter;
            this.projectSettings        = projectSettings;
        }
예제 #20
0
        public virtual GeneratorInfo GetGeneratorInfo()
        {
            tracer.Trace("Discovering generator information...", "VsGeneratorInfoProvider");

            GeneratorConfiguration generatorConfiguration = GenGeneratorConfig();

            try
            {
                var generatorInfo = new GeneratorInfo
                {
                    UsesPlugins = generatorConfiguration.UsesPlugins
                };

                if (DetectFromConfig(generatorInfo, generatorConfiguration))
                {
                    return(generatorInfo);
                }

                if (DetectDirectGeneratorReference(generatorInfo))
                {
                    return(generatorInfo);
                }

                if (!DetectFromRuntimeReference(generatorInfo))
                {
                    tracer.Trace("Unable to detect generator path", "VsGeneratorInfoProvider");
                }

                return(generatorInfo);
            }
            catch (Exception exception)
            {
                tracer.Trace(exception.ToString(), "VsGeneratorInfoProvider");
                return(null);
            }
        }
 private static IPropertyDeclarationSyntaxModifier GetPropertyDeclarationSyntaxModifier(GeneratorConfiguration configuration, SyntaxGeneratorFacade syntaxGeneratorFacade)
 {
     return(configuration.GenerateIniOptionAttribute ? new AttributePropertyDeclarationSyntaxModifier(syntaxGeneratorFacade) as IPropertyDeclarationSyntaxModifier : new NullPropertyDeclarationSyntaxModifier());
 }
 public LegacyResourceGenerator(ConfigNode node)
 {
     config = new GeneratorConfiguration(node);
 }
            public static Deposit Generate(Vector2 Pos, float radius, System.Random random, GeneratorConfiguration resource)
            {
                var initialQuantity = random.Range(resource.MinQuantity, resource.MaxQuantity);

                var vertices = new List<Vector2>();
                int vertexCount = random.Next(resource.MinVertices, resource.MaxVertices);
                for (int i = 0; i < vertexCount; i++)
                {
                    float randomRadius = random.Range(resource.RadiusVariance * radius, radius);
                    float angle = 2.0f * (float)Math.PI * ((float)i / (float)vertexCount);
                    float x = Pos.x + randomRadius * (float)Math.Cos(angle);
                    float z = Pos.y - randomRadius * (float)Math.Sin(angle);

                    vertices.Add(new Vector2(x, z));
                }
                var Shape = new Polygon(vertices.ToArray());

                return new Deposit(Shape, initialQuantity, initialQuantity);
            }
예제 #24
0
 public override string FormatName(string name, GeneratorConfiguration configuration)
 {
     return(Clean(string.Join("", GetSeparatedWords(name, configuration)
                              .Select(word => word[0].ToString().ToUpper() + word.Substring(1).ToLower()))));
 }
예제 #25
0
 public DataController(IDataGenerator generator, IDataAggregator aggregator, GeneratorConfiguration configuration, IRangeFilterer <AggregatedDataRange> aggregatedFilterer, IRangeFilterer <RawDataRange> rawFilterer)
 {
     _generator          = generator;
     _aggregatedFilterer = aggregatedFilterer;
     _rawFilterer        = rawFilterer;
 }
예제 #26
0
        public override string FormatName(string name, GeneratorConfiguration configuration)
        {
            var list = GetSeparatedWords(name, configuration).Select(s => s.ToLower());

            return(Clean(string.Join("_", list)));
        }
 public SubscriptionManager(ILogger <SubscriptionManager> logger, ILogger <RangeJoiner <RawDataRange> > rangeLogger, GeneratorConfiguration configuration, IDataGenerator generator)
 {
     _logger        = logger;
     _rangeLogger   = rangeLogger;
     _configuration = configuration;
     _generator     = generator;
 }
예제 #28
0
 public TestUpToDateChecker(ITestHeaderWriter testHeaderWriter, GeneratorConfiguration generatorConfiguration, ProjectSettings projectSettings)
 {
     this.testHeaderWriter       = testHeaderWriter;
     this.projectSettings        = projectSettings;
     this.generatorConfiguration = generatorConfiguration;
 }
        public static IGeneratorConfiguration GetConfiguration(string filePath)
        {
            var configuration = new GeneratorConfiguration(filePath);

            return(configuration);
        }
 public UnitTestFeatureGenerator(IUnitTestGeneratorProvider testGeneratorProvider, CodeDomHelper codeDomHelper, GeneratorConfiguration generatorConfiguration, IDecoratorRegistry decoratorRegistry, IStepDefinitionMatchService stepDefinitionMatchService)
 {
     this.testGeneratorProvider   = testGeneratorProvider;
     this.codeDomHelper           = codeDomHelper;
     this.generatorConfiguration  = generatorConfiguration;
     this.decoratorRegistry       = decoratorRegistry;
     m_stepDefinitionMatchService = stepDefinitionMatchService;
 }
예제 #31
0
        //public static DeployScript CreateDeploymentScript(CodeTypeDeclaration ctd, CodeCompileUnit cu, List<CodeMemberField> lFieldMembers)
        //{
        //    DeployScript dp = new DeployScript();
        //    dp.Name = Format.CamelCaseId(ctd.Name);


        //    return dp;
        //}

        public static bool Output(CodeTypeDeclaration ctd, CodeCompileUnit cu, string path, GeneratorConfiguration configuration)
        {
            try
            {
                List <CodeAttributeDeclaration> lAttributes = new List <CodeAttributeDeclaration>();
                List <CodeMemberField>          lFields     = new List <CodeMemberField>();

                List <string> lAttributeNames = new List <string>();
                foreach (CodeAttributeDeclaration at in ctd.CustomAttributes)
                {
                    lAttributes.Add(at);
                    lAttributeNames.Add(at.Name.Substring(0, at.Name.LastIndexOf(".")));
                }
                lAttributeNames = lAttributeNames.Distinct().OrderBy(a => a).ToList();

                foreach (CodeMemberField m in ctd.Members)
                {
                    lFields.Add(m);
                }
                lFields.OrderBy(f => f.Name);

                using (var sw = new StreamWriter(path))
                {
                    //using
                    lAttributeNames.ForEach(a => sw.WriteLine("using " + a + ";"));
                    sw.WriteLine("");

                    //namespace
                    sw.WriteLine("namespace " + Namespace.NameIsValid(cu.Namespaces[0].Name));
                    sw.WriteLine("{");

                    //Custom attributes
                    Custom.GetAttributes(ctd, lAttributeNames).ForEach(s => sw.WriteLine(Format.Tabs(1) + s));

                    //enum
                    sw.WriteLine(Format.Tabs(1) + Declare.Enums(ctd, configuration));
                    sw.WriteLine(Format.Tabs(1) + "{");

                    //Fields
                    foreach (CodeMemberField f in lFields)
                    {
                        bool isFinalField = false;
                        if (lFields.IndexOf(f) == lFields.Count - 1)
                        {
                            isFinalField = true;
                        }

                        //Custom field attributes
                        Custom.GetFieldAttributes(f, lAttributeNames).ForEach(s => sw.WriteLine(Format.Tabs(2) + s));

                        Declare.Fields(ctd, f, isFinalField, configuration).ForEach(s => sw.WriteLine(Format.Tabs(2) + s));
                    }

                    //Enclose class
                    sw.WriteLine(Format.Tabs(1) + "}");

                    //Enclose Namespace
                    sw.WriteLine("}");
                    sw.Close();
                }
            }
            catch (Exception ae)
            {
                string s = ae.ToString();
                return(false);
            }
            return(true);
        }
예제 #32
0
 public UnitTestFeatureGenerator(IUnitTestGeneratorProvider testGeneratorProvider, CodeDomHelper codeDomHelper, GeneratorConfiguration generatorConfiguration, IDecoratorRegistry decoratorRegistry)
 {
     this.testGeneratorProvider  = testGeneratorProvider;
     this.codeDomHelper          = codeDomHelper;
     this.generatorConfiguration = generatorConfiguration;
     this.decoratorRegistry      = decoratorRegistry;
 }
예제 #33
0
 public ClientGenerator(GeneratorConfiguration configuration)
 {
     _configuration = configuration;
 }