コード例 #1
0
        public void TestKillNPCGroupContractServerClientCompativility()
        {
            ContractResource resource = new ContractResource();

            resource.Load("Data/contracts.xml");

            var generator = ContractGenerator.Create(Common.ContractCategory.killNPCGroup);
            var contract  = generator.Generate(Common.Race.Humans, 1, "H1", null, resource);
            var info      = contract.GetInfo();

            Console.WriteLine("Server:");
            Console.WriteLine(contract.ToString());
            Console.WriteLine("=====================");

            ExitGames.Client.Photon.Hashtable photonHash = new ExitGames.Client.Photon.Hashtable();
            foreach (System.Collections.DictionaryEntry entry in info)
            {
                photonHash.Add(entry.Key, entry.Value);
            }

            Nebula.Client.Contracts.ContractFactory clientFactory = new Nebula.Client.Contracts.ContractFactory();
            var clientContract = clientFactory.Create(photonHash);

            Console.WriteLine("Client:");
            Console.WriteLine(clientContract.ToString());
        }
コード例 #2
0
        public void CanThrowOnMetadataConversionErrors()
        {
            Collection <MetadataConversionError> errors = new Collection <MetadataConversionError>();

            errors.Add(new MetadataConversionError("test", false));
            ContractGenerator.ThrowOnMetadataConversionErrors(errors);
        }
コード例 #3
0
        public void TestContractGeneration()
        {
            ContractResource resource = new ContractResource();

            resource.Load("Data/contracts.xml");

            var generator = ContractGenerator.Create(Common.ContractCategory.killNPCGroup);

            Console.WriteLine("For criptizids of lvl 6:");
            for (int i = 0; i < 10; i++)
            {
                var contract = generator.Generate(Common.Race.Criptizoids, 6, "E1", null, resource);
                Console.WriteLine(contract.ToString());
                Console.WriteLine("---");
            }
            Console.WriteLine("=========");

            Console.WriteLine("For humans of lvl 2:");
            for (int i = 0; i < 10; i++)
            {
                var contract = generator.Generate(Common.Race.Humans, 2, "H15", null, resource);
                Console.WriteLine(contract.ToString());
                Console.WriteLine("---");
            }
            Console.WriteLine("=========");
        }
コード例 #4
0
        public override void StateStarted()
        {
            /*
             *  при условии что контракта активного нет
             *
             *  выбрать рандомный контракт
             *  открыть popup с названием описанием и reward?
             *
             *  делаем его активным
             */

            var selectedContracts = ContractGenerator.ReturnContracts(Context, Db);
            var contractOptions   = new List <OptionsVotingInfo.Option>();

            foreach (var contract in selectedContracts)
            {
                var option = new OptionsVotingInfo.Option
                {
                    Name      = contract.Name,
                    Action    = new SetContract(contract),
                    IsEnabled = contract.Level <= Context.Company.Level
                };
                contractOptions.Add(option);
            }

            var optionsVotingInfo = new OptionsVotingInfo(true, contractOptions, Common.DefaultVotingDuration);

            _activeVoting = new OptionsVotingState(optionsVotingInfo);

            UIManager.Instance.ShowOptionsVotingPopup(new EventInfo("Choose contract", "Every next contract is more complicated than the previous one! But the harder the contract, the more money you will make..."), _activeVoting);
            SoundManager.Instance.Play(SoundBank.Instance.ContractStarted);
        }
コード例 #5
0
        public void CanCreateInstanceWithDefaultOptions()
        {
            ContractGenerator generator = new ContractGenerator(new ContractGenerationOptions());

            Assert.IsNull(generator.Configuration);
            Assert.AreEqual(0, generator.GeneratedChannelElements.Count);
            Assert.IsNotNull(generator.CodeCompileUnit);
        }
コード例 #6
0
        public void ThrowOnCustomWsdlImporterNotFound()
        {
            ContractGenerationOptions options = new ContractGenerationOptions();

            options.OutputConfiguration = ConfigurationLoader.LoadConfiguration(@"SampleData\DescriptionModel\WsdlImporterNotFound.config");
            ContractGenerator generator = new ContractGenerator(options);

            generator.Generate(GetMetadataSet(HostAddress));
        }
コード例 #7
0
        public void ShouldGenerateContractFromHostWithDefaultOptions()
        {
            ContractGenerationOptions options = new ContractGenerationOptions();

            options.OutputConfiguration = ConfigurationLoader.LoadConfiguration(@"SampleData\Empty.config");
            ContractGenerator generator = new ContractGenerator(options);

            generator.Generate(GetMetadataSet(HostAddress));

            ContractGeneratorCommonAsserts(generator, options);
        }
コード例 #8
0
        public void ShouldGenerateProtectionLevelSignValueFromHost()
        {
            ContractGenerationOptions options   = new ContractGenerationOptions();
            ContractGenerator         generator = new ContractGenerator(options);

            generator.Generate(GetMetadataSet(HostAddress));

            string proxyClass = GetClassFromCcu(options.CodeProvider, generator.CodeCompileUnit);

            Assert.IsNotNull(proxyClass);
            Assert.IsTrue(proxyClass.Contains("ProtectionLevel.Sign"), "Contains ProtectionLevel value.");
        }
コード例 #9
0
        public void ShouldGenerateContractFromWsdlWithDefaultOptions()
        {
            ContractGenerationOptions options = new ContractGenerationOptions();

            options.OutputConfiguration = ConfigurationLoader.LoadConfiguration(@"SampleData\Empty.config", "ShouldGenerateContractFromWsdlWithDefaultOptions");
            Uri wsdlLocation            = new Uri(ConfigurationLoader.GetConfigurationFilePath(@"SampleData\DescriptionModel\MockService.wsdl"));
            ContractGenerator generator = new ContractGenerator(options);

            generator.Generate(GetMetadataSet(wsdlLocation));

            ContractGeneratorCommonAsserts(generator, options);
        }
コード例 #10
0
        public void ShouldGenerateConfigFileWithWsHttpBinding()
        {
            ContractGenerationOptions options = new ContractGenerationOptions();

            options.OutputConfigurationFile = ConfigurationLoader.GetConfigurationFilePath(@"SampleData\Empty.config", "ShouldGenerateConfigFileWithWsHttpBinding");
            ContractGenerator generator = new ContractGenerator(options);

            generator.Generate(GetMetadataSet(HostAddress));
            string configFileContent = File.ReadAllText(options.OutputConfigurationFile);

            Assert.IsTrue(configFileContent.Contains("<wsHttpBinding>"));
        }
コード例 #11
0
        /// <summary>
        /// Creates the WSDL importer.
        /// </summary>
        /// <param name="wsdlFile">The WSDL file.</param>
        /// <returns></returns>
        public static WsdlImporter CreateImporter(string wsdlFile)
        {
            MetadataDiscovery discovery = new MetadataDiscovery(ConfigurationLoader.GetConfigurationFilePath(wsdlFile));
            ContractGenerator generator = CreateContractGenerator();
            WsdlImporter      importer  = generator.CreateWsdlImporter(discovery.InspectMetadata());

            importer.ImportAllEndpoints();
            importer.ImportAllContracts();
            importer.ImportAllBindings();
            ContractGenerator.ThrowOnMetadataConversionErrors(importer.Errors);
            return(importer);
        }
コード例 #12
0
        public void ShouldGenerateProtectionLevelSignValueFromWsdlFile()
        {
            ContractGenerationOptions options   = new ContractGenerationOptions();
            ContractGenerator         generator = new ContractGenerator(options);
            Uri wsdlLocation = new Uri(ConfigurationLoader.GetConfigurationFilePath(@"SampleData\DescriptionModel\MockService.wsdl"));

            generator.Generate(GetMetadataSet(wsdlLocation));

            string proxyClass = GetClassFromCcu(options.CodeProvider, generator.CodeCompileUnit);

            Assert.IsNotNull(proxyClass);
            Assert.IsTrue(proxyClass.Contains("ProtectionLevel.Sign"), "Contains ProtectionLevel value.");
        }
コード例 #13
0
        public void ShouldGenerateAndSaveConfigFile()
        {
            ContractGenerationOptions options = new ContractGenerationOptions();

            options.OutputConfigurationFile = ConfigurationLoader.GetConfigurationFilePath(@"SampleData\Empty.config", "ShouldGenerateAndSaveConfigFile", true);

            string            originalConfig = File.ReadAllText(options.OutputConfigurationFile);
            ContractGenerator generator      = new ContractGenerator(options);

            generator.Generate(GetMetadataSet(HostAddress));

            Assert.AreNotEqual(originalConfig, File.ReadAllText(options.OutputConfigurationFile));
        }
コード例 #14
0
        public void ShouldGenerateOneEndpointFromHostWithMultipleEndpoints()
        {
            ContractGenerationOptions options = new ContractGenerationOptions();

            options.OutputConfiguration = ConfigurationLoader.LoadConfiguration(@"SampleData\Empty.config");
            options.ImportedEndpointNames.Add(Constants.ServiceDescription.WsHttpHostClientName);
            ContractGenerator generator = new ContractGenerator(options);
            MetadataSet       metadata  = GetMetadataSet(HostAddressMultiEndpoint);

            generator.Generate(GetMetadataSet(HostAddressMultiEndpoint));

            ContractGeneratorCommonAsserts(generator, options);
        }
コード例 #15
0
        public void ShouldGenerateVBProxy()
        {
            ContractGenerationOptions options = new ContractGenerationOptions();

            options.CodeProvider = new VBCodeProvider();
            ContractGenerator generator = new ContractGenerator(options);
            Uri wsdlLocation            = new Uri(ConfigurationLoader.GetConfigurationFilePath(@"SampleData\DescriptionModel\MockService.wsdl"));

            generator.Generate(GetMetadataSet(wsdlLocation));

            string proxyClass = GetClassFromCcu(options.CodeProvider, generator.CodeCompileUnit);

            Assert.IsNotNull(proxyClass);
            Assert.IsTrue(proxyClass.Contains("Public Sub New()"), "Contains VB code");
        }
コード例 #16
0
 public ApplicationController(ApplicationPreferences applicationPreferences, Table table)
 {
     this.applicationPreferences = applicationPreferences;
     codeGenerator     = new CodeGenerator(applicationPreferences, table);
     fluentGenerator   = new FluentGenerator(applicationPreferences, table);
     castleGenerator   = new CastleGenerator(applicationPreferences, table);
     contractGenerator = new ContractGenerator(applicationPreferences, table);
     byCodeGenerator   = new ByCodeGenerator(applicationPreferences, table);
     if (applicationPreferences.ServerType == ServerType.Oracle)
     {
         mappingGenerator = new OracleMappingGenerator(applicationPreferences, table);
     }
     else
     {
         mappingGenerator = new SqlMappingGenerator(applicationPreferences, table);
     }
 }
コード例 #17
0
        private void ContractGeneratorCommonAsserts(ContractGenerator generator, ContractGenerationOptions options)
        {
            // Assert proxy class
            string proxyClass = GetClassFromCcu(options.CodeProvider, generator.CodeCompileUnit);

            Assert.IsNotNull(proxyClass);
            Assert.IsTrue(proxyClass.Contains("IMockServiceContract"));

            // Assert config file
            ServiceModelConfigurationManager manager = new ServiceModelConfigurationManager(generator.Configuration);
            ClientSection client = manager.GetClient();

            Assert.AreEqual(1, client.Endpoints.Count);
            ChannelEndpointElement createdEndpoint = client.Endpoints[0];

            Assert.AreEqual(Constants.Uris.TestContractGenerationEndpointAddress, createdEndpoint.Address.AbsoluteUri);
            Assert.AreEqual(Constants.ServiceDescription.WsHttpHostClientName, createdEndpoint.Name);
            Assert.AreEqual(Constants.ServiceDescription.WsHttpHostClientBinding, createdEndpoint.Binding);
        }
コード例 #18
0
 public ApplicationController(IApplicationSettings applicationPreferences, Table table)
 {
     this.applicationPreferences = applicationPreferences;
     codeGenerator            = new CodeGenerator(applicationPreferences, table);
     fluentGenerator          = new FluentGenerator(applicationPreferences, table);
     entityFrameworkGenerator = new EntityFrameworkGenerator(applicationPreferences, table);
     castleGenerator          = new CastleGenerator(applicationPreferences, table);
     contractGenerator        = new ContractGenerator(applicationPreferences, table);
     byCodeGenerator          = new ByCodeGenerator(applicationPreferences, table);
     testGenerator            = new PersistenceSpecificationTestCodeGenerator(applicationPreferences, table);
     if (applicationPreferences.ServerType == ServerType.Oracle)
     {
         mappingGenerator = new OracleMappingGenerator(applicationPreferences, table);
     }
     else
     {
         mappingGenerator = new SqlMappingGenerator(applicationPreferences, table);
     }
 }
コード例 #19
0
        //public Hashtable CompleteContract(string id) {
        //    ContractManager contractManager = player.GetComponent<ContractManager>();
        //    bool success = contractManager.CompleteContract(id);
        //    Hashtable hash = CreateResponse(Common.RPCErrorCode.Ok);
        //    hash.Add(SPCKEY(SPC.Status), success);
        //    return hash;
        //}

        public Hashtable ProposeContract(int icategory)
        {
            ContractCategory category        = (ContractCategory)icategory;
            ContractManager  contractManager = player.GetComponent <ContractManager>();

            if (contractManager.HasActiveContract(category))
            {
                Hashtable resp = CreateResponse(RPCErrorCode.AlreadyHasAcceptedContractWithSuchCategory);
                resp.Add((int)SPC.ContractCategory, icategory);
                return(resp);
            }
            var generator = ContractGenerator.Create(category);

            if (generator == null)
            {
                Hashtable resp = CreateResponse(RPCErrorCode.ContractGeneratorNotFound);
                resp.Add((int)SPC.ContractCategory, icategory);
                return(resp);
            }

            var playerRaceable  = player.GetComponent <RaceableObject>();
            var playerCharacter = player.GetComponent <CharacterObject>();

            var contract = generator.Generate((Race)playerRaceable.race, playerCharacter.level, (player.World as MmoWorld).Name, contractManager, player.resource);

            if (contract == null)
            {
                Hashtable resp = CreateResponse(RPCErrorCode.NoValidContract);
                return(resp);
            }

            if (false == contractManager.ProposeContract(contract))
            {
                return(CreateResponse(RPCErrorCode.UnableProposeContract));
            }

            Hashtable result = CreateResponse(RPCErrorCode.Ok);

            result.Add((int)SPC.Contract, contract.GetInfo());

            return(result);
        }
コード例 #20
0
        public static string FromContainer(IWrappedTypeContainer container, string namespaceForWrappers)
        {
            var typeOptions = new TypeGeneratorOptionsBuilder(TypeNamingStrategy)
                              .WithPartial()
                              .WithPublic()
                              .Build();

            var contractOptions = new ContractGeneratorOptionsBuilder(ContractNamingStrategy)
                                  .WithPartial()
                                  .WithPublic()
                                  .ExcludeMembersDeclaredOn <object>()
                                  .Build();

            var typeGenerator = new TypeGenerator(typeOptions, container);

            var contractGenerator = new ContractGenerator(contractOptions, container);

            var codeGenerator = new CodeGenerator();

            var ns = new CodeNamespace(namespaceForWrappers);

            foreach (var type in container.RegisteredTypes)
            {
                ns.Types.Add(
                    contractGenerator.GenerateDeclaration(type)
                    );
            }

            foreach (var type in container.RegisteredTypes)
            {
                ns.Types.Add(
                    typeGenerator.GenerateDeclaration(type)
                    );
            }

            var targetUnit = new CodeCompileUnit();

            targetUnit.Namespaces.Add(ns);

            return(codeGenerator.GenerateCode(targetUnit));
        }
コード例 #21
0
        public void ShouldGenerateContractFromHostWithDataContractSerializerType()
        {
            ContractGenerationOptions options = new ContractGenerationOptions();

            options.OutputConfiguration = ConfigurationLoader.LoadConfiguration(@"SampleData\Empty.config");
            options.ClrNamespace        = "Test.Namespace1";
            ContractGenerator generator = new ContractGenerator(options);

            generator.Generate(GetMetadataSet(HostAddress));

            string proxyClass = GetClassFromCcu(options.CodeProvider, generator.CodeCompileUnit);

            Assert.IsNotNull(proxyClass);
            Assert.IsTrue(proxyClass.Contains(options.ClrNamespace), "Contains namespace");
            Assert.IsTrue(proxyClass.Contains("MyDataContract"), "Contains MyDataContract class");

            CompilerResults results = DynamicCompilation.CompileAssemblyFromSource(proxyClass);

            Type generatedType = results.CompiledAssembly.GetType(options.ClrNamespace + ".MyDataContract", false);

            Assert.IsNotNull(generatedType);
        }
コード例 #22
0
        void GeneratedContractSourceFiles(
            ContractInfo[] contractInfos,
            List <GeneratedEventMetadata> generatedEvents)
        {
            int skippedAlreadyUpdated = 0;

            foreach (var contractInfo in contractInfos)
            {
                var(solFile, contractName, contract, hash, bytecode) = contractInfo;
                var hashHex          = HexUtil.GetHexFromBytes(hash);
                var hashHexBytes     = Encoding.ASCII.GetBytes(hashHex);
                var contactEventInfo = GeneratedEventMetadata.Parse(contractName, _namespace, contract).ToList();
                generatedEvents.AddRange(contactEventInfo);

                var outputFilePath = Path.Combine(_generatedContractsDirectory, contractName + G_CS_FILE_EXT);
                if (!_returnFullSources && FileStartsWithHash(outputFilePath, hashHexBytes))
                {
                    skippedAlreadyUpdated++;
                    continue;
                }

                var generator = new ContractGenerator(contractInfo, _solSourceDirectory, _namespace, contactEventInfo);
                var(generatedContractCode, syntaxTree) = generator.GenerateSourceCode();
                using (var fs = new StreamWriter(outputFilePath, append: false, encoding: StringUtil.UTF8))
                {
                    _logger("Writing source file: " + outputFilePath);
                    fs.WriteLine("//" + hashHex);
                    fs.WriteLine(generatedContractCode);

                    var generatedCSharpEntry = new SolCodeGenCSharpResult(outputFilePath, generatedContractCode, syntaxTree);
                    _genResults.GeneratedCSharpEntries.Add(generatedCSharpEntry);
                }
            }

            if (skippedAlreadyUpdated > 0)
            {
                _logger($"Detected already up-to-date generated files: {skippedAlreadyUpdated} contracts");
            }
        }
コード例 #23
0
        public void ShouldMergeConfigContentWithSameEndpoint()
        {
            ContractGenerationOptions options = new ContractGenerationOptions();

            options.OutputConfigurationFile = ConfigurationLoader.GetConfigurationFilePath(@"SampleData\Empty.config", "ShouldMergeConfigContentWithSameEndpoint", true);

            string            originalConfig = File.ReadAllText(options.OutputConfigurationFile);
            ContractGenerator generator      = new ContractGenerator(options);
            MetadataSet       metadata       = GetMetadataSet(HostAddress);
            WsdlImporter      importer       = generator.CreateWsdlImporter(metadata);

            generator.Generate(importer);
            // generate twice in order to update and get only one endpoint in config
            generator.Generate(importer);

            Assert.AreNotEqual(originalConfig, File.ReadAllText(options.OutputConfigurationFile));

            // Assert config file
            ServiceModelConfigurationManager manager = new ServiceModelConfigurationManager(generator.Configuration);
            ClientSection client = manager.GetClient();

            Assert.AreEqual <int>(2, client.Endpoints.Count);
        }
コード例 #24
0
        public static void Main(string[] args)
        {
            var generator = new ContractGenerator(args);

            generator.Run();
        }