Beispiel #1
0
        private ServiceConfiguration CreateServiceConfiguration(JsonData modelNode, JsonData serviceVersions, string serviceDirectoryPath, string serviceModelFileName)
        {
            var modelFullPath = Path.Combine(serviceDirectoryPath, serviceModelFileName);

            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,
                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
                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(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.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 = 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;
                var versionTokens = CoreVersion.Split('.');
                config.ServiceFileVersion = string.Format("{0}.{1}.0.0", versionTokens[0], versionTokens[1]);
                config.InPreview          = this.DefaultToPreview;
            }

            return(config);
        }
Beispiel #2
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
                IsTestService        = modelNode[ModelsSectionKeys.TestServiceKey] != null && (bool)modelNode[ModelsSectionKeys.TestServiceKey]
            };

            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);
        }