Represents the information for generating the code for a service
コード例 #1
0
        void SetupProjectFile(string codeAnalysisRoot, ServiceConfiguration serviceConfiguration)
        {
            if (!Directory.Exists(codeAnalysisRoot))
                Directory.CreateDirectory(codeAnalysisRoot);

            var assemblyName = "AWSSDK." + serviceConfiguration.Namespace.Split('.')[1] + ".CodeAnalysis";
            var projectFilename = string.Concat(assemblyName, ".csproj");
            string projectGuid;
            if (File.Exists(Path.Combine(codeAnalysisRoot, projectFilename)))
            {
                Console.WriteLine("...updating existing project file {0}", projectFilename);
                var projectPath = Path.Combine(codeAnalysisRoot, projectFilename);
                projectGuid = Utils.GetProjectGuid(projectPath);
            }
            else
            {
                projectGuid = Utils.NewProjectGuid;
                Console.WriteLine("...creating project file {0}", projectFilename);
            }

            var templateSession = new Dictionary<string, object>();

            templateSession["ProjectGuid"] = projectGuid;
            templateSession["RootNamespace"] = serviceConfiguration.Namespace + ".CodeAnalysis";
            templateSession["AssemblyName"] = assemblyName;
            templateSession["SourceDirectories"] = GetProjectSourceFolders(codeAnalysisRoot);
            templateSession["EmbeddedResources"] = GetEmbeddedResources(codeAnalysisRoot);

            CodeAnalysisProjectFile generator = new CodeAnalysisProjectFile();
            generator.Session = templateSession;
            var generatedContent = generator.TransformText();

            GeneratorDriver.WriteFile(codeAnalysisRoot, string.Empty, projectFilename, generatedContent);
        }
コード例 #2
0
 public void Execute(string codeAnalysisRoot, ServiceConfiguration serviceConfiguration)
 {
     SetupProjectFile(codeAnalysisRoot, serviceConfiguration);
     SetupPackageConfigFile(codeAnalysisRoot, serviceConfiguration);
     GenerateAssemblyInfo(codeAnalysisRoot, serviceConfiguration);
     GenerateProperyValueRules(codeAnalysisRoot, serviceConfiguration);
     GenerateProperyValueAnalyzer(codeAnalysisRoot, serviceConfiguration);
 }
コード例 #3
0
        public GeneratorDriver(ServiceConfiguration config, GenerationManifest generationManifest, GeneratorOptions options)
        {
            GenerationManifest = generationManifest;
            Configuration = config;
            ProjectFileConfigurations = GenerationManifest.ProjectFileConfigurations;
            Options = options;

            // Base name in the manifest is not a reliable source of info, as if append-service
            // is set 'Service' gets appended and in the case of IAM then sends us to the wrong folder.
            // Instead we'll use the namespace and rip off any Amazon. prefix. This also helps us
            // handle versioned namespaces too.
            var serviceNameRoot = Configuration.Namespace.StartsWith("Amazon.", StringComparison.Ordinal) 
                ? Configuration.Namespace.Substring(7) 
                : Configuration.Namespace;

            ServiceFilesRoot = Path.Combine(Options.SdkRootFolder, SourceSubFoldername, ServicesSubFoldername, serviceNameRoot);
            GeneratedFilesRoot = Path.Combine(ServiceFilesRoot, GeneratedCodeFoldername);

            TestFilesRoot = Path.Combine(Options.SdkRootFolder, TestsSubFoldername);
        }
コード例 #4
0
        private void GenerateProperyValueRules(string codeAnalysisRoot, ServiceConfiguration serviceConfiguration)
        {
            StringBuilder sb = new StringBuilder();
            using (var writer = XmlWriter.Create(sb, new XmlWriterSettings {Indent = true }))
            {
                writer.WriteStartElement("property-value-rules");

                if (!string.Equals(serviceConfiguration.BaseName, "S3", StringComparison.InvariantCultureIgnoreCase))
                {

                    HashSet<string> requestAndResponseShapes = new HashSet<string>();
                    foreach (var operation in serviceConfiguration.ServiceModel.Operations)
                    {
                        if (operation.RequestStructure != null)
                        {
                            GenerateProperyValueRules(serviceConfiguration, writer, operation.Name + "Request", operation.RequestStructure);
                            requestAndResponseShapes.Add(operation.RequestStructure.Name);
                        }
                        if (operation.ResponseStructure != null)
                        {
                            GenerateProperyValueRules(serviceConfiguration, writer, operation.Name + "Response", operation.ResponseStructure);
                            requestAndResponseShapes.Add(operation.ResponseStructure.Name);
                        }
                    }

                    foreach (var shape in serviceConfiguration.ServiceModel.Shapes.OrderBy(x => x.Name))
                    {
                        if (requestAndResponseShapes.Contains(shape.Name))
                            continue;

                        if (shape.IsStructure)
                        {
                            GenerateProperyValueRules(serviceConfiguration, writer, shape.Name, shape);
                        }
                    }
                }
                writer.WriteEndElement();
            }
            var content = sb.ToString();
            GeneratorDriver.WriteFile(Path.Combine(codeAnalysisRoot, "Generated"), string.Empty, "PropertyValueRules.xml", content);
        }
コード例 #5
0
        static bool IsShapePresentInParentModel(ServiceConfiguration config, string shapeName)
        {
            if (config.IsChildConfig)
            {
                // Check to see if the structure is present in a parent model
                if (config.ParentConfig.ServiceModel.Shapes.SingleOrDefault(
                    e => e.Name.Equals(shapeName)) != null)
                {
                    return true;
                }
            }

            return false;
        }
コード例 #6
0
 private void SetupPackageConfigFile(string codeAnalysisRoot, ServiceConfiguration serviceConfiguration)
 {
     CodeAnalysisPackages generator = new CodeAnalysisPackages();
     var generatedContent = generator.TransformText();
     GeneratorDriver.WriteFile(codeAnalysisRoot, string.Empty, "packages.config", generatedContent);
 }
コード例 #7
0
 private void GenerateAssemblyInfo(string codeAnalysisRoot, ServiceConfiguration serviceConfiguration)
 {
     var generator = new CodeAnalysisAssemblyInfo { Config = serviceConfiguration };
     var text = generator.TransformText();
     GeneratorDriver.WriteFile(codeAnalysisRoot, "Properties", "AssemblyInfo.cs", text);
 }
コード例 #8
0
 private void GenerateProperyValueAnalyzer(string codeAnalysisRoot, ServiceConfiguration serviceConfiguration)
 {
     var generator = new PropertyValueAssignmentAnalyzer { Config = serviceConfiguration };
     var text = generator.TransformText();
     GeneratorDriver.WriteFile(codeAnalysisRoot, "Generated", "PropertyValueAssignmentAnalyzer.cs", text);
 }
コード例 #9
0
        /// <summary>
        /// Parses the service configuration metadata from the supplied manifest document,
        /// fixing up file references to the actual service model and customization files.
        /// Sets the ServiceConfigurations member on exit with the collection of loaded
        /// configurations.
        /// </summary>
        /// <param name="document"></param>
        /// <param name="modelsFolder"></param>
        void LoadServiceConfigurations(JsonData manifest, string coreVersion, JsonData versions, string modelsFolder)
        {
            var serviceConfigurations = new List <ServiceConfiguration>();

            var modelsNode = manifest[ModelsSectionKeys.ModelsKey];

            foreach (JsonData modelNode in modelsNode)
            {
                var activeNode = modelNode[ModelsSectionKeys.ActiveKey];
                if (activeNode != null && activeNode.IsBoolean && !(bool)activeNode) // skip models with active set to false
                {
                    continue;
                }

                // A new config that the api generates from
                var modelName = modelNode[ModelsSectionKeys.ModelKey].ToString();
                var config    = new ServiceConfiguration
                {
                    ModelName                 = modelName,
                    ModelPath                 = DetermineModelPath(modelName, modelsFolder),                                                                     // Path to the file servicename-*-.normal.json
                    Namespace                 = modelNode[ModelsSectionKeys.NamespaceKey] != null ? modelNode[ModelsSectionKeys.NamespaceKey].ToString() : null, // Namespace of the service if it's different from basename
                    LockedApiVersion          = modelNode[ModelsSectionKeys.LockedApiVersionKey] != null ? modelNode[ModelsSectionKeys.LockedApiVersionKey].ToString() : null,
                    BaseName                  = modelNode[ModelsSectionKeys.BaseNameKey].ToString(),                                                             // The name that is used as the client name and base request name
                    RegionLookupName          = modelNode[ModelsSectionKeys.RegionLookupNameKey].ToString(),
                    AuthenticationServiceName = modelNode[ModelsSectionKeys.AuthenticationServiceNameKey] != null ? modelNode[ModelsSectionKeys.AuthenticationServiceNameKey].ToString() : null,
                    ServiceUrl                = modelNode[ModelsSectionKeys.ServiceUrlKey] != null ? modelNode[ModelsSectionKeys.ServiceUrlKey].ToString() : null,
                    DefaultRegion             = modelNode[ModelsSectionKeys.DefaultRegionKey] != null ? modelNode[ModelsSectionKeys.DefaultRegionKey].ToString() : null,
                    GenerateConstructors      = modelNode[ModelsSectionKeys.GenerateClientConstructorsKey] == null || (bool)modelNode[ModelsSectionKeys.GenerateClientConstructorsKey], // A way to prevent generating basic constructors
                    SupportedMobilePlatforms  = modelNode[ModelsSectionKeys.PlatformsKey] == null ? new List <string>() : (from object pcf in modelNode[ModelsSectionKeys.PlatformsKey]
                                                                                                                           select pcf.ToString()).ToList(),
                    EnableXamarinComponent = modelNode.PropertyNames.Contains(ModelsSectionKeys.EnableXamarinComponent) && (bool)modelNode[ModelsSectionKeys.EnableXamarinComponent]
                };

                if (modelNode[ModelsSectionKeys.PclVariantsKey] != null)
                {
                    config.PclVariants = (from object pcf in modelNode[ModelsSectionKeys.PclVariantsKey]
                                          select pcf.ToString()).ToList();
                }

                if (modelNode[ModelsSectionKeys.NugetPackageTitleSuffix] != null)
                {
                    config.NugetPackageTitleSuffix = modelNode[ModelsSectionKeys.NugetPackageTitleSuffix].ToString();
                }


                if (modelNode[ModelsSectionKeys.ReferenceDependenciesKey] != null)
                {
                    config.ReferenceDependencies = new Dictionary <string, List <Dependency> >();
                    foreach (KeyValuePair <string, JsonData> kvp in modelNode[ModelsSectionKeys.ReferenceDependenciesKey])
                    {
                        var platformDependencies = new List <Dependency>();
                        foreach (JsonData item in kvp.Value)
                        {
                            var platformDependency = new Dependency
                            {
                                Name     = item[ModelsSectionKeys.DependencyNameKey].ToString(),
                                Version  = item.PropertyNames.Contains(ModelsSectionKeys.DependencyVersionKey) ? item[ModelsSectionKeys.DependencyVersionKey].ToString() : "0.0.0.0",
                                HintPath = item[ModelsSectionKeys.DependencyHintPathKey].ToString(),
                            };
                            platformDependencies.Add(platformDependency);
                        }
                        config.ReferenceDependencies.Add(kvp.Key, platformDependencies);
                    }
                }

                if (modelNode[ModelsSectionKeys.NugetDependenciesKey] != null)
                {
                    config.NugetDependencies = new Dictionary <string, List <Dependency> >();
                    foreach (KeyValuePair <string, JsonData> kvp in modelNode[ModelsSectionKeys.NugetDependenciesKey])
                    {
                        var nugetDependencies = new List <Dependency>();
                        foreach (JsonData item in kvp.Value)
                        {
                            var nugetDependency = new Dependency
                            {
                                Name    = item[ModelsSectionKeys.DependencyNameKey].ToString(),
                                Version = item[ModelsSectionKeys.DependencyVersionKey].ToString(),
                            };
                            nugetDependencies.Add(nugetDependency);
                        }
                        config.NugetDependencies.Add(kvp.Key, nugetDependencies);
                    }
                }

                config.Tags = new List <string>();
                if (modelNode[ModelsSectionKeys.TagsKey] != null)
                {
                    foreach (JsonData tag in modelNode[ModelsSectionKeys.TagsKey])
                    {
                        config.Tags.Add(tag.ToString());
                    }
                }

                // Provides a way to specify a customizations file rather than using a generated one
                config.CustomizationsPath = modelNode[ModelsSectionKeys.CustomizationFileKey] == null
                    ? DetermineCustomizationsPath(modelNode[ModelsSectionKeys.ModelKey].ToString())
                    : Path.Combine(modelsFolder, modelNode[ModelsSectionKeys.CustomizationFileKey].ToString());

                if (modelNode[ModelsSectionKeys.AppendServiceKey] != null && (bool)modelNode[ModelsSectionKeys.AppendServiceKey])
                {
                    config.BaseName += "Service";
                }

                if (modelNode[ModelsSectionKeys.MaxRetriesKey] != null && modelNode[ModelsSectionKeys.MaxRetriesKey].IsInt)
                {
                    config.OverrideMaxRetries = Convert.ToInt32(modelNode[ModelsSectionKeys.MaxRetriesKey].ToString());
                }

                if (modelNode[ModelsSectionKeys.SynopsisKey] != null)
                {
                    config.Synopsis = (string)modelNode[ModelsSectionKeys.SynopsisKey];
                }

                if (modelNode[ModelsSectionKeys.CoreCLRSupportKey] != null)
                {
                    config.CoreCLRSupport = (bool)modelNode[ModelsSectionKeys.CoreCLRSupportKey];
                }
                else
                {
                    config.CoreCLRSupport = true;
                }

                config.ServiceDependencies = new Dictionary <string, string>(StringComparer.Ordinal);
                if (modelNode[ModelsSectionKeys.DependenciesKey] != null && modelNode[ModelsSectionKeys.DependenciesKey].IsArray)
                {
                    foreach (var d in modelNode[ModelsSectionKeys.DependenciesKey])
                    {
                        config.ServiceDependencies.Add(d.ToString(), null);
                    }
                }

                if (modelNode[ModelsSectionKeys.UsePclProjectDependenciesKey] != null && modelNode[ModelsSectionKeys.UsePclProjectDependenciesKey].IsBoolean)
                {
                    config.UsePclProjectDependencies = bool.Parse(modelNode[ModelsSectionKeys.UsePclProjectDependenciesKey].ToString());
                }
                else
                {
                    config.UsePclProjectDependencies = false;
                }

                if (modelNode[ModelsSectionKeys.LicenseUrlKey] != null && modelNode[ModelsSectionKeys.LicenseUrlKey].IsString)
                {
                    config.LicenseUrl = modelNode[ModelsSectionKeys.LicenseUrlKey].ToString();
                    config.RequireLicenseAcceptance = true;
                }
                else
                {
                    config.LicenseUrl = ApacheLicenseURL;
                }

                var serviceName     = config.ServiceNameRoot;
                var versionInfoJson = versions[serviceName];
                if (versionInfoJson != null)
                {
                    var dependencies = versionInfoJson["Dependencies"];
                    foreach (var name in dependencies.PropertyNames)
                    {
                        var version = dependencies[name].ToString();
                        config.ServiceDependencies[name] = version;
                    }


                    var versionText = versionInfoJson["Version"].ToString();
                    config.ServiceFileVersion = versionText;

                    if (versionInfoJson["InPreview"] != null && (bool)versionInfoJson["InPreview"])
                    {
                        config.InPreview = true;
                    }
                    else
                    {
                        config.InPreview = this.DefaultToPreview;
                    }
                }
                else
                {
                    config.ServiceDependencies["Core"] = coreVersion;
                    var versionTokens = coreVersion.Split('.');
                    config.ServiceFileVersion = string.Format("{0}.{1}.0.0", versionTokens[0], versionTokens[1]);
                    config.InPreview          = this.DefaultToPreview;
                }

                // The parent model for current model, if set, the client will be generated
                // in the same namespace and share common types.
                var parentModelName = modelNode[ModelsSectionKeys.ParentBaseNameKey] != null ? modelNode[ModelsSectionKeys.ParentBaseNameKey].ToString() : null;
                if (parentModelName != null)
                {
                    try
                    {
                        config.ParentConfig = serviceConfigurations.Single(c => c.BaseName.Equals(parentModelName));
                    }
                    catch (KeyNotFoundException exception)
                    {
                        // Note : the parent model should be defined in the manifest before being referred by a child model
                        throw new KeyNotFoundException(
                                  string.Format("A parent model with name {0} is not defined in the manifest", parentModelName),
                                  exception);;
                    }
                }

                serviceConfigurations.Add(config);
            }

            ServiceConfigurations = serviceConfigurations
                                    .OrderBy(sc => sc.ServiceDependencies.Count)
                                    .ToList();
            //ServiceVersions = serviceVersions;
        }
コード例 #10
0
        private void GenerateProperyValueRules(ServiceConfiguration serviceConfiguration, XmlWriter writer, string shapeName, Shape shape)
        {
            foreach (var member in shape.Members)
            {
                var memberShape = member.Shape;
                if (!memberShape.IsPrimitiveType)
                    continue;

                if (memberShape.Min == null && memberShape.Max == null && memberShape.Pattern == null)
                    continue;

                writer.WriteStartElement("property-value-rule");

                var propertyName = string.Format("{0}.Model.{1}.{2}", serviceConfiguration.Namespace, shapeName, member.PropertyName);
                writer.WriteElementString("property", propertyName);

                if (memberShape.Min != null)
                    writer.WriteElementString("min", memberShape.Min.Value.ToString());

                if (memberShape.Max != null)
                    writer.WriteElementString("max", memberShape.Max.Value.ToString());

                if (memberShape.Pattern != null)
                {
                    try
                    {
                        // Make sure we can compile the expression
                        new System.Text.RegularExpressions.Regex(memberShape.Pattern);
                        writer.WriteElementString("pattern", memberShape.Pattern);
                    }
                    catch(Exception e)
                    {
                        Console.Error.WriteLine("Failed to compile regex {0} for property {1}: {2}", memberShape.Pattern, propertyName, e.Message);
                    }
                }

                writer.WriteEndElement();
            }
        }
コード例 #11
0
ファイル: GenerationManifest.cs プロジェクト: aws/aws-sdk-net
        /// <summary>
        /// Parses the service configuration metadata from the supplied manifest document,
        /// fixing up file references to the actual service model and customization files.
        /// Sets the ServiceConfigurations member on exit with the collection of loaded
        /// configurations.
        /// </summary>
        /// <param name="document"></param>
        /// <param name="modelsFolder"></param>
        void LoadServiceConfigurations(JsonData manifest, string coreVersion, JsonData versions, string modelsFolder)
        {
            var serviceConfigurations = new List<ServiceConfiguration>();

            var modelsNode = manifest[ModelsSectionKeys.ModelsKey];
            foreach (JsonData modelNode in modelsNode)
            {
                var activeNode = modelNode[ModelsSectionKeys.ActiveKey];
                if (activeNode != null && activeNode.IsBoolean && !(bool)activeNode) // skip models with active set to false
                    continue;

                // A new config that the api generates from
                var modelName = modelNode[ModelsSectionKeys.ModelKey].ToString();
                var config = new ServiceConfiguration
                {
                    ModelName = modelName,
                    ModelPath = DetermineModelPath(modelName, modelsFolder), // Path to the file servicename-*-.normal.json
                    Namespace = modelNode[ModelsSectionKeys.NamespaceKey] != null ? modelNode[ModelsSectionKeys.NamespaceKey].ToString() : null, // Namespace of the service if it's different from basename
                    LockedApiVersion = modelNode[ModelsSectionKeys.LockedApiVersionKey] != null ? modelNode[ModelsSectionKeys.LockedApiVersionKey].ToString() : null,
                    BaseName = modelNode[ModelsSectionKeys.BaseNameKey].ToString(), // The name that is used as the client name and base request name
                    RegionLookupName = modelNode[ModelsSectionKeys.RegionLookupNameKey].ToString(),
                    AuthenticationServiceName = modelNode[ModelsSectionKeys.AuthenticationServiceNameKey] != null ? modelNode[ModelsSectionKeys.AuthenticationServiceNameKey].ToString() : null,
                    ServiceUrl = modelNode[ModelsSectionKeys.ServiceUrlKey] != null ? modelNode[ModelsSectionKeys.ServiceUrlKey].ToString() : null,
                    DefaultRegion = modelNode[ModelsSectionKeys.DefaultRegionKey] != null ? modelNode[ModelsSectionKeys.DefaultRegionKey].ToString() : null,
                    GenerateConstructors = modelNode[ModelsSectionKeys.GenerateClientConstructorsKey] == null || (bool)modelNode[ModelsSectionKeys.GenerateClientConstructorsKey], // A way to prevent generating basic constructors
                    SupportedMobilePlatforms = modelNode[ModelsSectionKeys.PlatformsKey] == null ? new List<string>() : (from object pcf in modelNode[ModelsSectionKeys.PlatformsKey]
                                                                                                                         select pcf.ToString()).ToList(),
                    EnableXamarinComponent = modelNode.PropertyNames.Contains(ModelsSectionKeys.EnableXamarinComponent) && (bool)modelNode[ModelsSectionKeys.EnableXamarinComponent]
                };

                if (modelNode[ModelsSectionKeys.PclVariantsKey] != null)
                {
                    config.PclVariants = (from object pcf in modelNode[ModelsSectionKeys.PclVariantsKey]
                     select pcf.ToString()).ToList();
                }

                if (modelNode[ModelsSectionKeys.NugetPackageTitleSuffix] != null)
                    config.NugetPackageTitleSuffix = modelNode[ModelsSectionKeys.NugetPackageTitleSuffix].ToString();


                if (modelNode[ModelsSectionKeys.ReferenceDependenciesKey] != null)
                {
                    config.ReferenceDependencies = new Dictionary<string, List<Dependency>>();
                    foreach (KeyValuePair<string, JsonData> kvp in modelNode[ModelsSectionKeys.ReferenceDependenciesKey])
                    {
                        var platformDependencies = new List<Dependency>();
                        foreach (JsonData item in kvp.Value)
                        {
                            var platformDependency = new Dependency
                            {
                                Name = item[ModelsSectionKeys.DependencyNameKey].ToString(),
                                Version = item.PropertyNames.Contains(ModelsSectionKeys.DependencyVersionKey) ? item[ModelsSectionKeys.DependencyVersionKey].ToString() : "0.0.0.0",
                                HintPath = item[ModelsSectionKeys.DependencyHintPathKey].ToString(),
                            };
                            platformDependencies.Add(platformDependency);
                        }
                        config.ReferenceDependencies.Add(kvp.Key, platformDependencies);
                    }
                }

                if (modelNode[ModelsSectionKeys.NugetDependenciesKey] != null)
                {
                    config.NugetDependencies = new Dictionary<string, List<Dependency>>();
                    foreach (KeyValuePair<string, JsonData> kvp in modelNode[ModelsSectionKeys.NugetDependenciesKey])
                    {
                        var nugetDependencies = new List<Dependency>();
                        foreach (JsonData item in kvp.Value)
                        {
                            var nugetDependency = new Dependency
                            {
                                Name = item[ModelsSectionKeys.DependencyNameKey].ToString(),
                                Version = item[ModelsSectionKeys.DependencyVersionKey].ToString(),
                            };
                            nugetDependencies.Add(nugetDependency);
                        }
                        config.NugetDependencies.Add(kvp.Key, nugetDependencies);
                    }
                }

                config.Tags = new List<string>();
                if (modelNode[ModelsSectionKeys.TagsKey] != null)
                {
                    foreach (JsonData tag in modelNode[ModelsSectionKeys.TagsKey])
                    {
                        config.Tags.Add(tag.ToString());
                    }
                }

                // Provides a way to specify a customizations file rather than using a generated one
                config.CustomizationsPath = modelNode[ModelsSectionKeys.CustomizationFileKey] == null
                    ? DetermineCustomizationsPath(modelNode[ModelsSectionKeys.ModelKey].ToString())
                    : Path.Combine(modelsFolder, modelNode[ModelsSectionKeys.CustomizationFileKey].ToString());

                if (modelNode[ModelsSectionKeys.AppendServiceKey] != null && (bool)modelNode[ModelsSectionKeys.AppendServiceKey])
                    config.BaseName += "Service";

                if (modelNode[ModelsSectionKeys.MaxRetriesKey] != null && modelNode[ModelsSectionKeys.MaxRetriesKey].IsInt)
                    config.OverrideMaxRetries = Convert.ToInt32(modelNode[ModelsSectionKeys.MaxRetriesKey].ToString());

                if (modelNode[ModelsSectionKeys.SynopsisKey] != null)
                    config.Synopsis = (string)modelNode[ModelsSectionKeys.SynopsisKey];

                if (modelNode[ModelsSectionKeys.CoreCLRSupportKey] != null)
                    config.CoreCLRSupport = (bool)modelNode[ModelsSectionKeys.CoreCLRSupportKey];
                else
                    config.CoreCLRSupport = true;

                config.ServiceDependencies = new Dictionary<string, string>(StringComparer.Ordinal);
                if (modelNode[ModelsSectionKeys.DependenciesKey] != null && modelNode[ModelsSectionKeys.DependenciesKey].IsArray)
                {
                    foreach (var d in modelNode[ModelsSectionKeys.DependenciesKey])
                    {
                        config.ServiceDependencies.Add(d.ToString(), null);
                    }
                }

                if (modelNode[ModelsSectionKeys.UsePclProjectDependenciesKey] != null && modelNode[ModelsSectionKeys.UsePclProjectDependenciesKey].IsBoolean)
                    config.UsePclProjectDependencies = bool.Parse(modelNode[ModelsSectionKeys.UsePclProjectDependenciesKey].ToString());
                else
                    config.UsePclProjectDependencies = false;

                if (modelNode[ModelsSectionKeys.LicenseUrlKey] != null && modelNode[ModelsSectionKeys.LicenseUrlKey].IsString)
                {
                    config.LicenseUrl = modelNode[ModelsSectionKeys.LicenseUrlKey].ToString();
                    config.RequireLicenseAcceptance = true;
                }
                else
                    config.LicenseUrl = ApacheLicenseURL;

                var serviceName = config.ServiceNameRoot;
                var versionInfoJson = versions[serviceName];
                if (versionInfoJson != null)
                {
                    var dependencies = versionInfoJson["Dependencies"];
                    foreach (var name in dependencies.PropertyNames)
                    {
                        var version = dependencies[name].ToString();
                        config.ServiceDependencies[name] = version;
                    }


                    var versionText = versionInfoJson["Version"].ToString();
                    config.ServiceFileVersion = versionText;

                    if(versionInfoJson["InPreview"] != null && (bool)versionInfoJson["InPreview"])
                        config.InPreview = true;
                    else
                        config.InPreview = this.DefaultToPreview;
                }
                else
                {
                    config.ServiceDependencies["Core"] = coreVersion;
                    var versionTokens = coreVersion.Split('.');
                    config.ServiceFileVersion = string.Format("{0}.{1}.0.0", versionTokens[0], versionTokens[1]);
                    config.InPreview = this.DefaultToPreview;
                }

                // The parent model for current model, if set, the client will be generated
                // in the same namespace and share common types.
                var parentModelName = modelNode[ModelsSectionKeys.ParentBaseNameKey] != null ? modelNode[ModelsSectionKeys.ParentBaseNameKey].ToString() : null;
                if (parentModelName != null)
                {
                    try
                    {
                        config.ParentConfig = serviceConfigurations.Single(c => c.BaseName.Equals(parentModelName));
                    }
                    catch (KeyNotFoundException exception)
                    {
                        // Note : the parent model should be defined in the manifest before being referred by a child model
                        throw new KeyNotFoundException(
                            string.Format("A parent model with name {0} is not defined in the manifest", parentModelName),
                            exception); ;
                    }
                }

                serviceConfigurations.Add(config);
            }

            ServiceConfigurations = serviceConfigurations
                .OrderBy(sc => sc.ServiceDependencies.Count)
                .ToList();
            //ServiceVersions = serviceVersions;
        }
コード例 #12
0
        static bool IsExceptionPresentInParentModel(ServiceConfiguration config, string exceptionName)
        {
            if (config.IsChildConfig)
            {
                // Check to see if the exception is present in a parent model
                if (config.ParentConfig.ServiceModel.Exceptions.SingleOrDefault(
                        e => e.Name.Equals(exceptionName)) != null)
                {
                    return true;
                }
            }

            return false;
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: aws/aws-sdk-net
        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);

                if (string.IsNullOrEmpty(options.SelfServiceModel))
                {
                    HashSet<string> generatedFiles = new HashSet<string>();
					GeneratorDriver.GenerateCoreProjects(generationManifest, options);
					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();
                        foreach(var file in driver.FilesWrittenToGeneratorFolder)
                        {
                            generatedFiles.Add(file);
                        }
                    }

                    GeneratorDriver.RemoveOrphanedShapes(generatedFiles, Path.Combine(options.SdkRootFolder, @"src\Services"));

					GeneratorDriver.UpdateSolutionFiles(generationManifest, options);
					GeneratorDriver.UpdateAssemblyVersionInfo(generationManifest, options);
                    GeneratorDriver.UpdateNuGetPackagesInReadme(generationManifest, options);
					GeneratorDriver.UpdateUnitTestProjectReferences(options);
                    GeneratorDriver.UpdateCoreCLRTestDependencies(generationManifest, options);
                    GeneratorDriver.UpdateCodeAnalysisSoltion(generationManifest, options);
                }
                else
                {
                    var serviceConfig = new ServiceConfiguration
                    {
                        ModelPath = options.SelfServiceModel,
                        BaseName = options.SelfServiceBaseName,
                        AuthenticationServiceName = options.SelfServiceSigV4Name ?? options.SelfServiceBaseName.ToLower(),
                        RegionLookupName = options.SelfServiceEndpointPrefix ?? options.SelfServiceBaseName.ToLower(),
                        ServiceFileVersion = "3.1.0.0"
                    };
                    serviceConfig.ModelName = Path.GetFileName(serviceConfig.ModelPath);
                    serviceConfig.ServiceDependencies = new Dictionary<string, string> { {"Core", "3.1.0.0"} };
                    serviceConfig.GenerateConstructors = true;


                    var relativePathToCustomizations = Path.Combine("customizations", string.Format("{0}.customizations.json", options.SelfServiceBaseName.ToLowerInvariant()));
                    if (File.Exists(relativePathToCustomizations))
                    {
                        serviceConfig.CustomizationsPath = Path.GetFullPath(relativePathToCustomizations);
                        Console.WriteLine("Using customization file: {0}", serviceConfig.CustomizationsPath);
                    }
                    
                    Console.WriteLine("Processing self service {0} with model {1}.", options.SelfServiceBaseName, options.SelfServiceModel);
                    var driver = new GeneratorDriver(serviceConfig, generationManifest, options);
                    driver.Execute();

                    // Skip orphan clean for DynamoDB because of the complex nature of DynamDB and DynamoDB Streams
                    if(!serviceConfig.BaseName.StartsWith("DynamoDB"))
                    {
                        GeneratorDriver.RemoveOrphanedShapes(driver.FilesWrittenToGeneratorFolder, driver.GeneratedFilesRoot);
                    }
                    
                }
            }
            catch (Exception e)
            {
                if (options.WaitOnExit)
                {
                    Console.Error.WriteLine("Error running generator: " + e.Message);
                    Console.Error.WriteLine(e.StackTrace);
                    returnCode = -1;
                }
                else
                    throw;
            }

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

            return returnCode;
        }
コード例 #14
0
ファイル: ProjectFileCreator.cs プロジェクト: aws/aws-sdk-net
        /// <summary>
        /// Creates the platform-specific project files for the given service configuration
        /// </summary>
        /// <param name="serviceFilesRoot">The folder under which all of the source files for the service will exist</param>
        /// <param name="serviceConfiguration"></param>
        /// <param name="projectFileConfigurations"></param>
        public void Execute(string serviceFilesRoot, ServiceConfiguration serviceConfiguration, IEnumerable<ProjectFileConfiguration> projectFileConfigurations)
        {
            CreatedProjectFiles = new Dictionary<string, ProjectConfigurationData>();
            var assemblyName = "AWSSDK." + serviceConfiguration.Namespace.Split('.')[1];

            foreach (var projectFileConfiguration in projectFileConfigurations)
            {
                if (projectFileConfiguration.IsSubProfile &&
                    !(serviceConfiguration.PclVariants != null && serviceConfiguration.PclVariants.Any(p => p.Equals(projectFileConfiguration.Name))))
                {
                    // Skip sub profiles for service projects.
                    continue;
                }

                var projectType = projectFileConfiguration.Name;
                if (projectType.Equals("Unity", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (!serviceConfiguration.SupportedInUnity)
                        continue;
                }


                var projectFilename = string.Concat(assemblyName, ".", projectType, ".csproj");
                bool newProject = false;
                string projectGuid;
                if (File.Exists(Path.Combine(serviceFilesRoot, projectFilename)))
                {
                    Console.WriteLine("...updating existing project file {0}", projectFilename);
                    var projectPath = Path.Combine(serviceFilesRoot, projectFilename);
                    projectGuid = Utils.GetProjectGuid(projectPath);
                }
                else
                {
                    newProject = true;
                    projectGuid = Utils.NewProjectGuid;
                    Console.WriteLine("...creating project file {0}", projectFilename);
                }


                var templateSession = new Dictionary<string, object>();

                templateSession["Name"] = projectFileConfiguration.Name;
                templateSession["ProjectGuid"] = projectGuid;
                templateSession["RootNamespace"] = serviceConfiguration.Namespace;
                templateSession["AssemblyName"] = assemblyName;
                templateSession["SourceDirectories"] = GetProjectSourceFolders(projectFileConfiguration, serviceFilesRoot);
                templateSession["NugetPackagesLocation"] = @"..\..\..\packages\";
                templateSession["TargetFrameworkVersion"] = projectFileConfiguration.TargetFrameworkVersion;
                templateSession["DefineConstants"] = projectFileConfiguration.CompilationConstants;
                templateSession["BinSubfolder"] = projectFileConfiguration.BinSubFolder;

                var projectConfigurationData = new ProjectConfigurationData { ProjectGuid = projectGuid };
                var projectName = Path.GetFileNameWithoutExtension(projectFilename);

                if (newProject)
                    CreatedProjectFiles[projectName] = projectConfigurationData;

                var coreRuntimeProject = string.Concat(@"..\..\Core\AWSSDK.Core.", projectType, ".csproj");
                var projectReferences = new List<ProjectReference>();


                if (serviceConfiguration.ServiceDependencies != null)
                {
                    foreach (var dependency in serviceConfiguration.ServiceDependencies)
                    {
                        var pt = projectType;
                        if (!(pt.StartsWith(@"Net") || pt.StartsWith(@"Unity")) && serviceConfiguration.UsePclProjectDependencies)
                            pt = @"PCL";

                        var dependencyProjectName = "AWSSDK." + dependency.Key + "." + pt;
                        string dependencyProject;
                        if (string.Equals(dependency.Key, "Core", StringComparison.InvariantCultureIgnoreCase))
                        {
                            dependencyProject = string.Concat(@"..\..\", dependency.Key, "\\", dependencyProjectName, ".csproj");
                        }
                        else
                        {
                            dependencyProject = string.Concat(@"..\", dependency.Key, "\\", dependencyProjectName, ".csproj");
                        }

                        projectReferences.Add(new ProjectReference
                        {
                            IncludePath = dependencyProject,
                            ProjectGuid = Utils.GetProjectGuid(Path.Combine(serviceFilesRoot, dependencyProject)),
                            Name = dependencyProjectName
                        });
                    }
                }


                templateSession["ProjectReferences"] = projectReferences.OrderBy(x => x.Name).ToList();

                templateSession["UnityPath"] = Options.UnityPath;

                if (serviceConfiguration.ModelName.Equals("s3", StringComparison.OrdinalIgnoreCase) && projectType == "Net45")
                {
                    templateSession["SystemReferences"] = new List<string> { "System.Net.Http" };
                }

                if (serviceConfiguration.ReferenceDependencies != null &&
                    serviceConfiguration.ReferenceDependencies.ContainsKey(projectFileConfiguration.Name))
                {
                    templateSession["ReferenceDependencies"] = serviceConfiguration.ReferenceDependencies[projectFileConfiguration.Name];
                    templateSession["NuGetTargetFramework"] = projectFileConfiguration.NuGetTargetPlatform;
                }

                

                GenerateProjectFile(projectFileConfiguration, projectConfigurationData, templateSession, serviceFilesRoot, projectFilename);
            }

            if (serviceConfiguration.CoreCLRSupport)
                GenerateCoreCLRProjectFiles(serviceFilesRoot, serviceConfiguration, assemblyName);
            else
                Console.WriteLine("Skipping CoreCLR support for {0}", serviceConfiguration.BaseName);
        }
コード例 #15
0
        /// <summary>
        /// Creates the platform-specific project files for the given service configuration
        /// </summary>
        /// <param name="serviceFilesRoot">The folder under which all of the source files for the service will exist</param>
        /// <param name="serviceConfiguration"></param>
        /// <param name="projectFileConfigurations"></param>
        public void Execute(string serviceFilesRoot, ServiceConfiguration serviceConfiguration, IEnumerable<ProjectFileConfiguration> projectFileConfigurations)
        {
            CreatedProjectFiles = new Dictionary<string, ProjectConfigurationData>();

            foreach (var projectFileConfiguration in projectFileConfigurations)
            {
                var projectType = projectFileConfiguration.Name;

                var assemblyName = "AWSSDK." + serviceConfiguration.Namespace.Split('.')[1];
                var projectFilename = string.Concat(assemblyName, ".", projectType, ".csproj");
                bool newProject = false;
                string projectGuid;
                if (File.Exists(Path.Combine(serviceFilesRoot, projectFilename)))
                {
                    Console.WriteLine("...updating existing project file {0}", projectFilename);
                    var xdoc = new XmlDocument();
                    xdoc.Load(Path.Combine(serviceFilesRoot, projectFilename));
                    var propertyGroups = xdoc.GetElementsByTagName("PropertyGroup");
                    var element = ((XmlElement)propertyGroups[0]).GetElementsByTagName("ProjectGuid")[0];
                    if(element == null)
                    {
                        throw new ApplicationException("Failed to find project guid for existing project: " + Path.Combine(serviceFilesRoot, projectFilename));
                    }
                    projectGuid = element.InnerText;
                }
                else
                {
                    newProject = true;
                    projectGuid = NewProjectGuid;
                    Console.WriteLine("...creating project file {0}", projectFilename);
                }


                var templateSession = new Dictionary<string, object>();

                templateSession["ProjectGuid"] = projectGuid;
                templateSession["RootNamespace"] = serviceConfiguration.Namespace;
                templateSession["AssemblyName"] = assemblyName;
                templateSession["SourceDirectories"] = GetProjectSourceFolders(projectFileConfiguration, serviceFilesRoot);
                templateSession["NugetPackagesLocation"] = @"..\..\..\packages\";
                templateSession["TargetFrameworkVersion"] = projectFileConfiguration.TargetFrameworkVersion;
                templateSession["DefineConstants"] = projectFileConfiguration.CompilationConstants;
                templateSession["BinSubfolder"] = projectFileConfiguration.BinSubFolder;

                var projectConfigurationData = new ProjectConfigurationData { ProjectGuid = projectGuid };
                var projectName = Path.GetFileNameWithoutExtension(projectFilename);

                if(newProject)
                    CreatedProjectFiles[projectName] = projectConfigurationData;

                var coreRuntimeProject = string.Concat(@"..\..\Core\AWSSDK.Core.", projectType, ".csproj");
                var projectReferences = new List<ProjectReference>();


                if (serviceConfiguration.ServiceDependencies != null)
                {
                    foreach (var dependency in serviceConfiguration.ServiceDependencies)
                    {
                        var dependencyProjectName = "AWSSDK." + dependency.Key + "." + projectType;
                        string dependencyProject;
                        if (string.Equals(dependency.Key, "Core", StringComparison.InvariantCultureIgnoreCase))
                        {
                            dependencyProject = string.Concat(@"..\..\", dependency.Key, "\\", dependencyProjectName, ".csproj");
                        }
                        else
                        {
                            dependencyProject = string.Concat(@"..\", dependency.Key, "\\", dependencyProjectName, ".csproj");
                        }

                        projectReferences.Add(new ProjectReference
                        {
                            IncludePath = dependencyProject,
                            ProjectGuid = ProjectGuidFromFile(Path.Combine(serviceFilesRoot, dependencyProject)),
                            Name = dependencyProjectName
                        });
                    }
                }


                templateSession["ProjectReferences"] = projectReferences.OrderBy(x => x.Name).ToList();

                if (serviceConfiguration.ModelName.Equals("s3", StringComparison.OrdinalIgnoreCase) && projectType == "Net45")
                {
                    templateSession["SystemReferences"] = new List<string> { "System.Net.Http" };
                }

                GenerateProjectFile(projectFileConfiguration, projectConfigurationData, templateSession, serviceFilesRoot, projectFilename);
            }
        }
コード例 #16
0
ファイル: ProjectFileCreator.cs プロジェクト: aws/aws-sdk-net
        private void GenerateCoreCLRProjectFiles(string serviceFilesRoot, ServiceConfiguration serviceConfiguration, string assemblyName)
        {
            var projectFilename = string.Concat(assemblyName, ".CoreCLR.xproj");
            string projectGuid;
            if (File.Exists(Path.Combine(serviceFilesRoot, projectFilename)))
            {
                Console.WriteLine("...updating existing project file {0}", projectFilename);
                var projectPath = Path.Combine(serviceFilesRoot, projectFilename);
                projectGuid = Utils.GetProjectGuid(projectPath);
            }
            else
            {
                projectGuid = Utils.NewProjectGuid;
                Console.WriteLine("...creating project file {0}", projectFilename);
            }


            {
                var templateSession = new Dictionary<string, object>();
                templateSession["RootNamespace"] = serviceConfiguration.Namespace;
                templateSession["AssemblyName"] = assemblyName;
                templateSession["ProjectGuid"] = projectGuid;

                CoreCLRProjectFile projectFileTemplate = new CoreCLRProjectFile();
                projectFileTemplate.Session = templateSession;
                var content = projectFileTemplate.TransformText();

                GeneratorDriver.WriteFile(serviceFilesRoot, string.Empty, projectFilename, content);
            }

            {
                var templateSession = new Dictionary<string, object>();

                var dependencies = new List<string>();
                foreach (var dependency in serviceConfiguration.ServiceDependencies.Keys)
                {
                    if (string.Equals(dependency, "Core", StringComparison.InvariantCultureIgnoreCase))
                        continue;

                    dependencies.Add(dependency);
                }

                templateSession["ServiceDependencies"] = dependencies;
                templateSession["AssemblyName"] = assemblyName;

                var projectJsonTemplate = new CoreCLRProjectJson();
                projectJsonTemplate.Session = templateSession;

                var content = projectJsonTemplate.TransformText();

                GeneratorDriver.WriteFile(serviceFilesRoot, string.Empty, "project.json", content);
            }

        }
コード例 #17
0
        /// <summary>
        /// Parses the service configuration metadata from the supplied manifest document,
        /// fixing up file references to the actual service model and customization files.
        /// Sets the ServiceConfigurations member on exit with the collection of loaded
        /// configurations.
        /// </summary>
        /// <param name="document"></param>
        /// <param name="modelsFolder"></param>
        void LoadServiceConfigurations(JsonData manifest, string coreVersion, JsonData versions, string modelsFolder)
        {
            var serviceConfigurations = new List<ServiceConfiguration>();
            //var serviceVersions = new Dictionary<string, string>();

            var modelsNode = manifest[ModelsSectionKeys.ModelsKey];
            foreach (JsonData modelNode in modelsNode)
            {
                var activeNode = modelNode[ModelsSectionKeys.ActiveKey];
                if (activeNode != null && activeNode.IsBoolean && !(bool)activeNode) // skip models with active set to false
                    continue;

                // A new config that the api generates from
                var modelName = modelNode[ModelsSectionKeys.ModelKey].ToString();
                var config = new ServiceConfiguration
                {
                    ModelName = modelName,
                    ModelPath = DetermineModelPath(modelName, modelsFolder), // Path to the file servicename-*-.normal.json
                    Namespace = modelNode[ModelsSectionKeys.NamespaceKey] != null ? modelNode[ModelsSectionKeys.NamespaceKey].ToString() : null, // Namespace of the service if it's different from basename
                    LockedApiVersion = modelNode[ModelsSectionKeys.LockedApiVersionKey] != null ? modelNode[ModelsSectionKeys.LockedApiVersionKey].ToString() : null,
                    BaseName = modelNode[ModelsSectionKeys.BaseNameKey].ToString(), // The name that is used as the client name and base request name
                    RegionLookupName = modelNode[ModelsSectionKeys.RegionLookupNameKey].ToString(),
                    AuthenticationServiceName = modelNode[ModelsSectionKeys.AuthenticationServiceNameKey] != null ? modelNode[ModelsSectionKeys.AuthenticationServiceNameKey].ToString() : null,
                    ServiceUrl = modelNode[ModelsSectionKeys.ServiceUrlKey] != null ? modelNode[ModelsSectionKeys.ServiceUrlKey].ToString() : null,
                    DefaultRegion = modelNode[ModelsSectionKeys.DefaultRegionKey] != null ? modelNode[ModelsSectionKeys.DefaultRegionKey].ToString() : null,
                    GenerateConstructors = modelNode[ModelsSectionKeys.GenerateClientConstructorsKey] == null || (bool)modelNode[ModelsSectionKeys.GenerateClientConstructorsKey] // A way to prevent generating basic constructors
                };

                // Provides a way to specify a customizations file rather than using a generated one
                config.CustomizationsPath = modelNode[ModelsSectionKeys.CustomizationFileKey] == null
                    ? DetermineCustomizationsPath(modelNode[ModelsSectionKeys.ModelKey].ToString())
                    : Path.Combine(modelsFolder, modelNode[ModelsSectionKeys.CustomizationFileKey].ToString());

                if (modelNode[ModelsSectionKeys.AppendServiceKey] != null && (bool)modelNode[ModelsSectionKeys.AppendServiceKey])
                    config.BaseName += "Service";

                if (modelNode[ModelsSectionKeys.MaxRetriesKey] != null && modelNode[ModelsSectionKeys.MaxRetriesKey].IsInt)
                    config.OverrideMaxRetries = Convert.ToInt32(modelNode[ModelsSectionKeys.MaxRetriesKey].ToString());

                if (modelNode[ModelsSectionKeys.SynopsisKey] != null)
                    config.Synopsis = (string)modelNode[ModelsSectionKeys.SynopsisKey];


                config.ServiceDependencies = new Dictionary<string, string>(StringComparer.Ordinal);
                if (modelNode[ModelsSectionKeys.DependenciesKey] != null && modelNode[ModelsSectionKeys.DependenciesKey].IsArray)
                {
                    foreach (var d in modelNode[ModelsSectionKeys.DependenciesKey])
                    {
                        config.ServiceDependencies.Add(d.ToString(), null);
                    }
                }

                var serviceName = config.ServiceNameRoot;
                var versionInfoJson = versions[serviceName];
                if(versionInfoJson != null)
                {
                    var dependencies = versionInfoJson["Dependencies"];
                    foreach (var name in dependencies.PropertyNames)
                    {
                        var version = dependencies[name].ToString();
                        config.ServiceDependencies[name] = version;
                    }


                    var versionText = versionInfoJson["Version"].ToString();
                    config.ServiceFileVersion = versionText;
                }
                else
                {
                    config.ServiceDependencies["Core"] = coreVersion;
                    var versionTokens = coreVersion.Split('.');
                    config.ServiceFileVersion = string.Format("{0}.{1}.0.0", versionTokens[0], versionTokens[1]);
                }
                //serviceVersions.Add(serviceName, versionText);

                serviceConfigurations.Add(config);
            }

            ServiceConfigurations = serviceConfigurations;
            //ServiceVersions = serviceVersions;
        }
コード例 #18
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);

                if (string.IsNullOrEmpty(options.SelfServiceModel))
                {
                    HashSet <string> generatedFiles = new HashSet <string>();
                    GeneratorDriver.GenerateCoreProjects(generationManifest, options);
                    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();
                        foreach (var file in driver.FilesWrittenToGeneratorFolder)
                        {
                            generatedFiles.Add(file);
                        }
                    }

                    GeneratorDriver.RemoveOrphanedShapes(generatedFiles, Path.Combine(options.SdkRootFolder, @"src\Services"));

                    GeneratorDriver.UpdateUnitTestProjects(generationManifest, options);
                    GeneratorDriver.UpdateSolutionFiles(generationManifest, options);
                    GeneratorDriver.UpdateAssemblyVersionInfo(generationManifest, options);
                    GeneratorDriver.UpdateNuGetPackagesInReadme(generationManifest, options);
                    GeneratorDriver.UpdateCoreCLRTestDependencies(generationManifest, options);
                    GeneratorDriver.UpdateCodeAnalysisSoltion(generationManifest, options);
                }
                else
                {
                    var serviceConfig = new ServiceConfiguration
                    {
                        ModelPath = options.SelfServiceModel,
                        BaseName  = options.SelfServiceBaseName,
                        AuthenticationServiceName = options.SelfServiceSigV4Name ?? options.SelfServiceBaseName.ToLower(),
                        RegionLookupName          = options.SelfServiceEndpointPrefix ?? options.SelfServiceBaseName.ToLower(),
                        ServiceFileVersion        = "3.1.0.0"
                    };
                    serviceConfig.ModelName           = Path.GetFileName(serviceConfig.ModelPath);
                    serviceConfig.ServiceDependencies = new Dictionary <string, string> {
                        { "Core", "3.1.0.0" }
                    };
                    serviceConfig.GenerateConstructors = true;


                    var relativePathToCustomizations = Path.Combine("customizations", string.Format("{0}.customizations.json", options.SelfServiceBaseName.ToLowerInvariant()));
                    if (File.Exists(relativePathToCustomizations))
                    {
                        serviceConfig.CustomizationsPath = Path.GetFullPath(relativePathToCustomizations);
                        Console.WriteLine("Using customization file: {0}", serviceConfig.CustomizationsPath);
                    }

                    Console.WriteLine("Processing self service {0} with model {1}.", options.SelfServiceBaseName, options.SelfServiceModel);
                    var driver = new GeneratorDriver(serviceConfig, generationManifest, options);
                    driver.Execute();

                    // Skip orphan clean for DynamoDB because of the complex nature of DynamDB and DynamoDB Streams
                    if (!serviceConfig.BaseName.StartsWith("DynamoDB"))
                    {
                        GeneratorDriver.RemoveOrphanedShapes(driver.FilesWrittenToGeneratorFolder, driver.GeneratedFilesRoot);
                    }
                }
            }
            catch (Exception e)
            {
                if (options.WaitOnExit)
                {
                    Console.Error.WriteLine("Error running generator: " + e.Message);
                    Console.Error.WriteLine(e.StackTrace);
                    returnCode = -1;
                }
                else
                {
                    throw;
                }
            }

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

            return(returnCode);
        }
コード例 #19
0
        /// <summary>
        /// Creates the platform-specific project files for the given service configuration
        /// </summary>
        /// <param name="serviceFilesRoot">The folder under which all of the source files for the service will exist</param>
        /// <param name="serviceConfiguration"></param>
        /// <param name="projectFileConfigurations"></param>
        public void Execute(string serviceFilesRoot, ServiceConfiguration serviceConfiguration, IEnumerable <ProjectFileConfiguration> projectFileConfigurations)
        {
            CreatedProjectFiles = new Dictionary <string, ProjectConfigurationData>();

            foreach (var projectFileConfiguration in projectFileConfigurations)
            {
                if (projectFileConfiguration.IsSubProfile &&
                    !(serviceConfiguration.PclVariants != null && serviceConfiguration.PclVariants.Any(p => p.Equals(projectFileConfiguration.Name))))
                {
                    // Skip sub profiles for service projects.
                    continue;
                }

                var projectType = projectFileConfiguration.Name;

                var    assemblyName    = "AWSSDK." + serviceConfiguration.Namespace.Split('.')[1];
                var    projectFilename = string.Concat(assemblyName, ".", projectType, ".csproj");
                bool   newProject      = false;
                string projectGuid;
                if (File.Exists(Path.Combine(serviceFilesRoot, projectFilename)))
                {
                    Console.WriteLine("...updating existing project file {0}", projectFilename);
                    var projectPath = Path.Combine(serviceFilesRoot, projectFilename);
                    projectGuid = GetProjectGuid(projectPath);
                }
                else
                {
                    newProject  = true;
                    projectGuid = NewProjectGuid;
                    Console.WriteLine("...creating project file {0}", projectFilename);
                }


                var templateSession = new Dictionary <string, object>();

                templateSession["Name"]                   = projectFileConfiguration.Name;
                templateSession["ProjectGuid"]            = projectGuid;
                templateSession["RootNamespace"]          = serviceConfiguration.Namespace;
                templateSession["AssemblyName"]           = assemblyName;
                templateSession["SourceDirectories"]      = GetProjectSourceFolders(projectFileConfiguration, serviceFilesRoot);
                templateSession["NugetPackagesLocation"]  = @"..\..\..\packages\";
                templateSession["TargetFrameworkVersion"] = projectFileConfiguration.TargetFrameworkVersion;
                templateSession["DefineConstants"]        = projectFileConfiguration.CompilationConstants;
                templateSession["BinSubfolder"]           = projectFileConfiguration.BinSubFolder;

                var projectConfigurationData = new ProjectConfigurationData {
                    ProjectGuid = projectGuid
                };
                var projectName = Path.GetFileNameWithoutExtension(projectFilename);

                if (newProject)
                {
                    CreatedProjectFiles[projectName] = projectConfigurationData;
                }

                var coreRuntimeProject = string.Concat(@"..\..\Core\AWSSDK.Core.", projectType, ".csproj");
                var projectReferences  = new List <ProjectReference>();


                if (serviceConfiguration.ServiceDependencies != null)
                {
                    foreach (var dependency in serviceConfiguration.ServiceDependencies)
                    {
                        var    dependencyProjectName = "AWSSDK." + dependency.Key + "." + projectType;
                        string dependencyProject;
                        if (string.Equals(dependency.Key, "Core", StringComparison.InvariantCultureIgnoreCase))
                        {
                            dependencyProject = string.Concat(@"..\..\", dependency.Key, "\\", dependencyProjectName, ".csproj");
                        }
                        else
                        {
                            dependencyProject = string.Concat(@"..\", dependency.Key, "\\", dependencyProjectName, ".csproj");
                        }

                        projectReferences.Add(new ProjectReference
                        {
                            IncludePath = dependencyProject,
                            ProjectGuid = GetProjectGuid(Path.Combine(serviceFilesRoot, dependencyProject)),
                            Name        = dependencyProjectName
                        });
                    }
                }


                templateSession["ProjectReferences"] = projectReferences.OrderBy(x => x.Name).ToList();

                if (serviceConfiguration.ModelName.Equals("s3", StringComparison.OrdinalIgnoreCase) && projectType == "Net45")
                {
                    templateSession["SystemReferences"] = new List <string> {
                        "System.Net.Http"
                    };
                }

                if (serviceConfiguration.ReferenceDependencies != null &&
                    serviceConfiguration.ReferenceDependencies.ContainsKey(projectFileConfiguration.Name))
                {
                    templateSession["ReferenceDependencies"] = serviceConfiguration.ReferenceDependencies[projectFileConfiguration.Name];
                    templateSession["NuGetTargetFramework"]  = projectFileConfiguration.NuGetTargetPlatform;
                }

                GenerateProjectFile(projectFileConfiguration, projectConfigurationData, templateSession, serviceFilesRoot, projectFilename);
            }
        }
コード例 #20
0
        private ServiceConfiguration CreateServiceConfiguration(JsonData modelNode, JsonData serviceVersions, string serviceDirectoryPath, string serviceModelFileName, string servicePaginatorsFileName)
        {
            var modelFullPath      = Path.Combine(serviceDirectoryPath, serviceModelFileName);
            var paginatorsFullPath = Path.Combine(serviceDirectoryPath, servicePaginatorsFileName);

            JsonData metadata = JsonMapper.ToObject(File.ReadAllText(modelFullPath))[ServiceModel.MetadataKey];

            // A new config that the api generates from
            var modelName = Path.GetFileName(serviceDirectoryPath);
            var config    = new ServiceConfiguration
            {
                ModelName            = modelName,
                ModelPath            = modelFullPath,
                PaginatorsPath       = paginatorsFullPath,
                Namespace            = Utils.JsonDataToString(modelNode[ModelsSectionKeys.NamespaceKey]), // Namespace of the service if it's different from basename
                ClassNameOverride    = Utils.JsonDataToString(modelNode[ModelsSectionKeys.BaseNameKey]),
                DefaultRegion        = Utils.JsonDataToString(modelNode[ModelsSectionKeys.DefaultRegionKey]),
                GenerateConstructors = modelNode[ModelsSectionKeys.GenerateClientConstructorsKey] == null || (bool)modelNode[ModelsSectionKeys.GenerateClientConstructorsKey], // A way to prevent generating basic constructors
            };

            if (modelNode[ModelsSectionKeys.NugetPackageTitleSuffix] != null)
            {
                config.NugetPackageTitleSuffix = modelNode[ModelsSectionKeys.NugetPackageTitleSuffix].ToString();
            }


            if (modelNode[ModelsSectionKeys.ReferenceDependenciesKey] != null)
            {
                config.ReferenceDependencies = new Dictionary <string, List <Dependency> >();
                foreach (KeyValuePair <string, JsonData> kvp in modelNode[ModelsSectionKeys.ReferenceDependenciesKey])
                {
                    var platformDependencies = new List <Dependency>();
                    foreach (JsonData item in kvp.Value)
                    {
                        var platformDependency = new Dependency
                        {
                            Name     = item[ModelsSectionKeys.DependencyNameKey].ToString(),
                            Version  = item.PropertyNames.Contains(ModelsSectionKeys.DependencyVersionKey) ? item[ModelsSectionKeys.DependencyVersionKey].ToString() : "0.0.0.0",
                            HintPath = item[ModelsSectionKeys.DependencyHintPathKey].ToString(),
                        };
                        platformDependencies.Add(platformDependency);
                    }
                    config.ReferenceDependencies.Add(kvp.Key, platformDependencies);
                }
            }

            if (modelNode[ModelsSectionKeys.NugetDependenciesKey] != null)
            {
                config.NugetDependencies = new Dictionary <string, List <Dependency> >();
                foreach (KeyValuePair <string, JsonData> kvp in modelNode[ModelsSectionKeys.NugetDependenciesKey])
                {
                    var nugetDependencies = new List <Dependency>();
                    foreach (JsonData item in kvp.Value)
                    {
                        var nugetDependency = new Dependency
                        {
                            Name    = item[ModelsSectionKeys.DependencyNameKey].ToString(),
                            Version = item[ModelsSectionKeys.DependencyVersionKey].ToString(),
                        };
                        nugetDependencies.Add(nugetDependency);
                    }
                    config.NugetDependencies.Add(kvp.Key, nugetDependencies);
                }
            }

            config.Tags = new List <string>();
            if (modelNode[ModelsSectionKeys.TagsKey] != null)
            {
                foreach (JsonData tag in modelNode[ModelsSectionKeys.TagsKey])
                {
                    config.Tags.Add(tag.ToString());
                }
            }

            // Provides a way to specify a customizations file rather than using a generated one
            config.CustomizationsPath = modelNode[ModelsSectionKeys.CustomizationFileKey] == null
                ? DetermineCustomizationsPath(config.ServiceDirectoryName)
                : Path.Combine(serviceDirectoryPath, modelNode[ModelsSectionKeys.CustomizationFileKey].ToString());

            if (modelNode[ModelsSectionKeys.MaxRetriesKey] != null && modelNode[ModelsSectionKeys.MaxRetriesKey].IsInt)
            {
                config.OverrideMaxRetries = Convert.ToInt32(modelNode[ModelsSectionKeys.MaxRetriesKey].ToString());
            }

            if (modelNode[ModelsSectionKeys.SynopsisKey] != null)
            {
                config.Synopsis = (string)modelNode[ModelsSectionKeys.SynopsisKey];
            }

            if (modelNode[ModelsSectionKeys.NetStandardSupportKey] != null)
            {
                config.NetStandardSupport = (bool)modelNode[ModelsSectionKeys.NetStandardSupportKey];
            }
            else
            {
                config.NetStandardSupport = true;
            }

            config.ServiceDependencies = new Dictionary <string, string>(StringComparer.Ordinal);
            if (modelNode[ModelsSectionKeys.DependenciesKey] != null && modelNode[ModelsSectionKeys.DependenciesKey].IsArray)
            {
                foreach (var d in modelNode[ModelsSectionKeys.DependenciesKey])
                {
                    config.ServiceDependencies.Add(d.ToString(), null);
                }
            }

            if (modelNode[ModelsSectionKeys.LicenseUrlKey] != null && modelNode[ModelsSectionKeys.LicenseUrlKey].IsString)
            {
                config.LicenseUrl = modelNode[ModelsSectionKeys.LicenseUrlKey].ToString();
                config.RequireLicenseAcceptance = true;
            }
            else
            {
                config.LicenseUrl = ApacheLicenseURL;
            }

            var serviceName     = config.ServiceNameRoot;
            var versionInfoJson = serviceVersions[serviceName];

            if (versionInfoJson != null)
            {
                var dependencies = versionInfoJson["Dependencies"];
                foreach (var name in dependencies.PropertyNames)
                {
                    var version = dependencies[name].ToString();
                    config.ServiceDependencies[name] = version;
                }


                var versionText = versionInfoJson["Version"].ToString();
                config.ServiceFileVersion = versionText;

                var assemblyVersionOverride = versionInfoJson["AssemblyVersionOverride"];
                if (assemblyVersionOverride != null)
                {
                    config.ServiceAssemblyVersionOverride = assemblyVersionOverride.ToString();
                }

                if (versionInfoJson["InPreview"] != null && (bool)versionInfoJson["InPreview"])
                {
                    config.InPreview = true;
                }
                else
                {
                    config.InPreview = this.DefaultToPreview;
                }
            }
            else
            {
                config.ServiceDependencies["Core"] = CoreFileVersion;
                config.InPreview = this.DefaultToPreview;

                config.ServiceFileVersion = DefaultAssemblyVersion;
                var versionTokens = CoreVersion.Split('.');
                if (!DefaultAssemblyVersion.StartsWith($"{versionTokens[0]}.{versionTokens[1]}"))
                {
                    throw new NotImplementedException($"{nameof(DefaultAssemblyVersion)} should be updated to match the AWSSDK.Core minor version number.");
                }
            }

            return(config);
        }