示例#1
0
 private void PopulateAdditionalProperties(CodeModel codeModel)
 {
     if (Settings.Instance.AddCredentials)
     {
         if (!codeModel.Properties.Any(p => p.ModelType.IsPrimaryType(KnownPrimaryType.Credentials)))
         {
             codeModel.Insert(New <Property>(new
             {
                 Name           = "credentials",
                 SerializedName = "credentials",
                 ModelType      = New <PrimaryType>(KnownPrimaryType.Credentials),
                 IsRequired     = true,
                 Documentation  = "Subscription credentials which uniquely identify client subscription."
             }));
         }
     }
 }
示例#2
0
        /// <summary>
        /// Creates azure specific properties.
        /// </summary>
        /// <param name="codeModelient"></param>
        public static void AddAzureProperties(CodeModel codeModel)
        {
            if (codeModel == null)
            {
                throw new ArgumentNullException("codeModel");
            }

            var apiVersion = codeModel.Properties
                             .FirstOrDefault(p => ApiVersion.EqualsIgnoreCase(p.SerializedName));

            if (apiVersion != null)
            {
                apiVersion.DefaultValue = codeModel.ApiVersion;
                apiVersion.IsReadOnly   = true;
                apiVersion.IsRequired   = false;
            }

            var subscriptionId =
                codeModel.Properties.FirstOrDefault(
                    p => p.Name.EqualsIgnoreCase("subscriptionId"));

            if (subscriptionId != null)
            {
                subscriptionId.IsRequired = true;
            }

            var acceptLanguage = codeModel.Properties
                                 .FirstOrDefault(p => AcceptLanguage.EqualsIgnoreCase(p.SerializedName));

            if (acceptLanguage == null)
            {
                acceptLanguage = New <Property>(new
                {
                    Name           = AcceptLanguage,
                    Documentation  = "Gets or sets the preferred language for the response.",
                    SerializedName = AcceptLanguage,
                    DefaultValue   = "en-US"
                });
                codeModel.Add(acceptLanguage);
            }
            acceptLanguage.IsReadOnly = false;
            acceptLanguage.IsRequired = false;
            acceptLanguage.ModelType  = New <PrimaryType>(KnownPrimaryType.String);
            codeModel.Methods
            .Where(m => !m.Parameters.Any(p => AcceptLanguage.EqualsIgnoreCase(p.SerializedName)))
            .ForEach(m2 => m2.Add(New <Parameter>(new
            {
                ClientProperty = acceptLanguage,
                Location       = ParameterLocation.Header
            }).LoadFrom(acceptLanguage)));

            codeModel.Insert(New <Property>(new
            {
                Name           = "Credentials",
                SerializedName = "credentials",
                ModelType      = New <PrimaryType>(KnownPrimaryType.Credentials),
                IsRequired     = true,
                IsReadOnly     = true,
                Documentation  = "Credentials needed for the client to connect to Azure."
            }));

            codeModel.Add(New <Property>(new
            {
                Name           = "LongRunningOperationRetryTimeout",
                SerializedName = "longRunningOperationRetryTimeout",
                ModelType      = New <PrimaryType>(KnownPrimaryType.Int),
                Documentation  = "Gets or sets the retry timeout in seconds for Long Running Operations. Default value is 30.",
                DefaultValue   = "30"
            }));

            codeModel.Add(New <Property>(new
            {
                Name           = "GenerateClientRequestId",
                SerializedName = "generateClientRequestId",
                ModelType      = New <PrimaryType>(KnownPrimaryType.Boolean),
                Documentation  = "When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true.",
                DefaultValue   = "true"
            }));
        }