ServiceClientGenerator.GeneratorDriver.Execute C# (CSharp) Method

Execute() public method

public Execute ( ) : void
return void
        public void Execute()
        {
            this.FilesWrittenToGeneratorFolder.Clear();
            if (Options.Clean && !Configuration.IsChildConfig)
            {
                Console.WriteLine(@"-clean option set, deleting previously-generated code under .\Generated subfolders");

                Directory.Delete(GeneratedFilesRoot, true);
                Directory.CreateDirectory(GeneratedFilesRoot);
            }

            // .NET Framework 3.5 version
            ExecuteGenerator(new ServiceClients(), "Amazon" + Configuration.BaseName + "Client.cs", Bcl35SubFolder);
            ExecuteGenerator(new ServiceInterface(), "IAmazon" + Configuration.BaseName + ".cs", Bcl35SubFolder);

            // .NET Framework 4.5 version
            ExecuteGenerator(new ServiceClients45(), "Amazon" + Configuration.BaseName + "Client.cs", Bcl45SubFolder);
            ExecuteGenerator(new ServiceInterface45(), "IAmazon" + Configuration.BaseName + ".cs", Bcl45SubFolder);

            // Phone/Rt/Portable version
            ExecuteGenerator(new ServiceClientsMobile(), "Amazon" + Configuration.BaseName + "Client.cs", MobileSubFolder);
            ExecuteGenerator(new ServiceInterfaceMobile(), "IAmazon" + Configuration.BaseName + ".cs", MobileSubFolder);

            if (string.IsNullOrEmpty(Options.SelfServiceModel))
            {
                //unity version
                if (Configuration.SupportedInUnity)
                {
                    ExecuteGenerator(new ServiceInterfaceUnity(), "IAmazon" + Configuration.BaseName + ".cs", UnitySubFolder);
                    ExecuteGenerator(new ServiceClientUnity(), "Amazon" + Configuration.BaseName + "Client.cs", UnitySubFolder);
                }
                // Do not generate AssemblyInfo.cs and nuspec file for child model.
                // Use the one generated for the parent model.
                if (!this.Configuration.IsChildConfig)
                {
                    ExecuteNugetFileGenerators();

                    if (this.Configuration.EnableXamarinComponent)
                        GenerateXamarinComponents();

                    GenerateCodeAnalysisProject();
                }
            }

            if (!this.Configuration.IsChildConfig)
            {
                ExecuteGeneratorAssemblyInfo();
            }

            // Client config object
            ExecuteGenerator(new ServiceConfig(), "Amazon" + Configuration.BaseName + "Config.cs");

            if (Configuration.Namespace == "Amazon.S3")
            {
                ExecuteProjectFileGenerators();
                return;
            }


            // The top level request that all operation requests are children of
            ExecuteGenerator(new BaseRequest(), "Amazon" + Configuration.BaseName + "Request.cs", "Model");

            var enumFileName = this.Configuration.IsChildConfig ?
                string.Format("ServiceEnumerations.{0}.cs", Configuration.BaseName) : "ServiceEnumerations.cs";

            // Any enumerations for the service
            this.ExecuteGenerator(new ServiceEnumerations(), enumFileName);

            // Do not generate base exception if this is a child model.
            // We use the base exceptions generated for the parent model.
            if (!this.Configuration.IsChildConfig)
            {
                this.ExecuteGenerator(new BaseServiceException(), "Amazon" + this.Configuration.BaseName + "Exception.cs");
            }

            // Generates the Request, Responce, Marshaller, Unmarshaller, and Exception objects for a given client operation
            foreach (var operation in Configuration.ServiceModel.Operations)
            {
                GenerateRequest(operation);
                GenerateResponse(operation);
                GenerateRequestMarshaller(operation);
                GenerateResponseUnmarshaller(operation);
                GenerateExceptions(operation);
            }

            if (Configuration.ServiceModel.Customizations.GenerateCustomUnmarshaller)
            {
                GenerateUnmarshaller(Configuration.ServiceModel.Customizations.CustomUnmarshaller);
            }

            // Generate any missed structures that are not defined or referenced by a request, response, marshaller, unmarshaller, or exception of an operation
            GenerateStructures();

            var fileName = Configuration.LockedApiVersion != null
                ? string.Format("{0}_{1}_MarshallingTests.cs", Configuration.BaseName, Configuration.LockedApiVersion)
                : string.Format("{0}MarshallingTests.cs", Configuration.BaseName);

            // Generate tests based on the type of request it is
            if (Configuration.ServiceModel.Type == ServiceType.Json)
                ExecuteTestGenerator(new JsonMarshallingTests(), fileName);
            else if (Configuration.ServiceModel.Type == ServiceType.Query)
            {
                if (Configuration.ServiceModel.IsEC2Protocol)
                    ExecuteTestGenerator(new AWSQueryEC2MarshallingTests(), fileName);
                else
                    ExecuteTestGenerator(new AWSQueryMarshallingTests(), fileName);
            }
            else if (Configuration.ServiceModel.Type == ServiceType.Rest_Xml || Configuration.ServiceModel.Type == ServiceType.Rest_Json)
                ExecuteTestGenerator(new RestMarshallingTests(), fileName);

            // Test that simple customizations were generated correctly
            GenerateCustomizationTests();
            ExecuteProjectFileGenerators();
            if (this.Configuration.ServiceModel.Customizations.HasExamples)
            {
                var servicename = Configuration.Namespace.Split('.').Last();
                ExecuteExampleGenerator(new ExampleCode(), servicename + ".GeneratedSamples.cs", servicename);
                ExecuteExampleGenerator(new ExampleMetadata(), servicename + ".GeneratedSamples.extra.xml");
            }
        }

Usage Example

Beispiel #1
0
        static int Main(string[] args)
        {
            var commandArguments = CommandArguments.Parse(args);
            if (!string.IsNullOrEmpty(commandArguments.Error))
            {
                Console.WriteLine(commandArguments.Error);
                return -1;
            }

            var returnCode = 0;
            var options = commandArguments.ParsedOptions;
            var modelsToProcess = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

            if (!string.IsNullOrEmpty(options.ServiceModels))
            {
                foreach (var s in options.ServiceModels.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    modelsToProcess.Add(s);
                }
            }

            try
            {
                if (options.CompileCustomizations) // Compile all servicename.customizations*.json files into one json file in bin
                    CustomizationCompiler.CompileServiceCustomizations(options.ModelsFolder);

                var generationManifest = GenerationManifest.Load(options.Manifest, options.Versions, options.ModelsFolder);
                foreach (var serviceConfig in generationManifest.ServiceConfigurations)
                {
                    if (modelsToProcess.Any() && !modelsToProcess.Contains(serviceConfig.ModelName))
                    {
                        Console.WriteLine("Skipping model (not in -servicemodels set to process): {0} ({1})", serviceConfig.ModelName, serviceConfig.ModelPath);
                        continue;
                    }

                    Console.WriteLine("Processing model: {0} ({1})", serviceConfig.ModelName, serviceConfig.ModelPath);
                    var driver = new GeneratorDriver(serviceConfig, generationManifest, options);
                    driver.Execute();
                }

                GeneratorDriver.UpdateSolutionFiles(options);
                GeneratorDriver.UpdateAssemblyVersionInfo(generationManifest, options);
                GeneratorDriver.UpdateUnitTestProjectReferences(options);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error running generator: " + e.Message);
                Console.Error.WriteLine(e.StackTrace);
                returnCode = -1;
            }

            if (options.WaitOnExit)
            {
                Console.WriteLine();
                Console.WriteLine("Generation complete. Press a key to exit.");
                Console.ReadLine();
            }

            return returnCode;
        }
All Usage Examples Of ServiceClientGenerator.GeneratorDriver::Execute