Exemple #1
0
 /// <summary>
 /// Normalizes client model by updating names and types to be language specific.
 /// </summary>
 /// <param name="serviceClient"></param>
 public override void NormalizeClientModel(ServiceClient serviceClient)
 {
     Settings.AddCredentials = true;
     AzureCodeGenerator.UpdateHeadMethods(serviceClient);
     AzureCodeGenerator.ParseODataExtension(serviceClient);
     AzureCodeGenerator.AddPageableMethod(serviceClient);
     AzureCodeGenerator.AddLongRunningOperations(serviceClient);
     AzureCodeGenerator.AddAzureProperties(serviceClient);
     AzureCodeGenerator.SetDefaultResponses(serviceClient);
     base.NormalizeClientModel(serviceClient);
 }
        public AzureMethodTemplateModel(Method source, ServiceClient serviceClient)
            : base(source, serviceClient)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            this.ClientRequestIdString = AzureCodeGenerator.GetClientRequestIdString(source);
            this.RequestIdString       = AzureCodeGenerator.GetRequestIdString(source);
        }
Exemple #3
0
        /// <summary>
        /// Changes paginated method signatures to return Page type.
        /// </summary>
        /// <param name="serviceClient"></param>
        /// <param name="pageClasses"></param>
        public virtual void NormalizePaginatedMethods(ServiceClient serviceClient, IDictionary<KeyValuePair<string, string>, string> pageClasses)
        {
            if (serviceClient == null)
            {
                throw new ArgumentNullException("serviceClient");
            }

            var convertedTypes = new Dictionary<IType, CompositeType>();

            foreach (var method in serviceClient.Methods.Where(m => m.Extensions.ContainsKey(AzureCodeGenerator.PageableExtension)))
            {
                string nextLinkString;
                string pageClassName = GetPagingSetting(method.Extensions, pageClasses, out nextLinkString);
                if (string.IsNullOrEmpty(pageClassName))
                {
                    continue;
                }
                var pageTypeFormat = "{0}<{1}>";
                var ipageTypeFormat = "IPage<{0}>";

                foreach (var responseStatus in method.Responses.Where(r => r.Value is CompositeType).Select(s => s.Key).ToArray())
                {
                    var compositType = (CompositeType) method.Responses[responseStatus];
                    var sequenceType = compositType.Properties.Select(p => p.Type).FirstOrDefault(t => t is SequenceType) as SequenceType;

                    // if the type is a wrapper over page-able response
                    if(sequenceType != null &&
                       compositType.Properties.Count == 2 &&
                       compositType.Properties.Any(p => p.SerializedName.Equals(nextLinkString, StringComparison.OrdinalIgnoreCase)))
                    {
                        var pagableTypeName = string.Format(CultureInfo.InvariantCulture, pageTypeFormat, pageClassName, sequenceType.ElementType.Name);
                        var ipagableTypeName = string.Format(CultureInfo.InvariantCulture, ipageTypeFormat, sequenceType.ElementType.Name);

                        CompositeType pagedResult = new CompositeType
                        {
                            Name = pagableTypeName
                        };
                        pagedResult.Extensions[AzureCodeGenerator.ExternalExtension] = true;
                        pagedResult.Extensions[AzureCodeGenerator.PageableExtension] = ipagableTypeName;

                        convertedTypes[method.Responses[responseStatus]] = pagedResult;
                        method.Responses[responseStatus] = pagedResult;
                    }
                }

                if (convertedTypes.ContainsKey(method.ReturnType))
                {
                    method.ReturnType = convertedTypes[method.ReturnType];
                }
            }

            AzureCodeGenerator.RemoveUnreferencedTypes(serviceClient, convertedTypes.Keys.Cast<CompositeType>().Select(t => t.Name));
        }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the AzureMethodTemplateModel class.
        /// </summary>
        /// <param name="source">The method current model is built for.</param>
        /// <param name="serviceClient">The service client - main point of access to the SDK.</param>
        public AzureMethodTemplateModel(Method source, ServiceClient serviceClient)
            : base(source, serviceClient)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            ParameterTemplateModels.Clear();
            source.Parameters.ForEach(p => ParameterTemplateModels.Add(new AzureParameterTemplateModel(p)));

            this.ClientRequestIdString = AzureCodeGenerator.GetClientRequestIdString(source);
            this.RequestIdString       = AzureCodeGenerator.GetRequestIdString(source);
        }
 /// <summary>
 /// Normalizes client model by updating names and types to be language specific.
 /// </summary>
 /// <param name="serviceClient"></param>
 public override void NormalizeClientModel(ServiceClient serviceClient)
 {
     //please do not change the following sequence as it may have undesirable results.
     Settings.AddCredentials = true;
     AzureCodeGenerator.UpdateHeadMethods(serviceClient);
     AzureCodeGenerator.ParseODataExtension(serviceClient);
     AzureCodeGenerator.AddPageableMethod(serviceClient);
     AzureCodeGenerator.AddAzureProperties(serviceClient);
     AzureCodeGenerator.SetDefaultResponses(serviceClient);
     base.NormalizeClientModel(serviceClient);
     AzureCodeGenerator.AddLongRunningOperations(serviceClient);
     NormalizeApiVersion(serviceClient);
     NormalizeCredentials(serviceClient);
 }