Ejemplo n.º 1
0
        /// <summary>
        /// Generates Ruby code in form of string for deserializing polling response.
        /// </summary>
        /// <param name="variableName">Variable name which keeps the response.</param>
        /// <param name="type">Type of response.</param>
        /// <returns>Ruby code in form of string for deserializing polling response.</returns>
        public string DeserializePollingResponse(string variableName, IType type)
        {
            var builder = new IndentedStringBuilder("  ");

            string serializationLogic = GetDeserializationString(type, variableName, variableName);

            return(builder.AppendLine(serializationLogic).ToString());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns Ruby code as string which sets `next_method` property of the page with the respective next paging method
        /// and performs parameter re-assignment when required (ex. parameter grouping cases)
        /// </summary>
        public string AssignNextMethodToPage()
        {
            string            nextMethodName;
            Method            nextMethod        = null;
            PageableExtension pageableExtension = JsonConvert.DeserializeObject <PageableExtension>(Extensions[AzureExtensions.PageableExtension].ToString());

            // When pageable extension have operation name
            if (pageableExtension != null && !string.IsNullOrWhiteSpace(pageableExtension.OperationName))
            {
                nextMethod = ServiceClient.Methods.FirstOrDefault(m =>
                                                                  pageableExtension.OperationName.Equals(m.SerializedName, StringComparison.OrdinalIgnoreCase));
                nextMethodName = nextMethod.Name;
            }
            // When pageable extension does not have operation name
            else
            {
                nextMethodName = (string)Extensions["nextMethodName"];
                nextMethod     = ServiceClient.Methods.Where(m => m.Name == nextMethodName).FirstOrDefault();
            }

            IndentedStringBuilder builder = new IndentedStringBuilder("  ");

            // As there is no distinguishable property in next link parameter, we'll check to see whether any parameter contains "next" in the parameter name
            Parameter nextLinkParameter = nextMethod.Parameters.Where(p => p.Name.IndexOf("next", StringComparison.OrdinalIgnoreCase) >= 0).FirstOrDefault();

            builder.AppendLine(String.Format(CultureInfo.InvariantCulture, "page.next_method = Proc.new do |{0}|", nextLinkParameter.Name));

            // In case of parmeter grouping, next methods parameter needs to be mapped with the origin methods parameter
            IEnumerable <Parameter> origMethodGroupedParameters = Parameters.Where(p => p.Name.Contains(Name));

            if (origMethodGroupedParameters.Count() > 0)
            {
                builder.Indent();
                foreach (Parameter param in nextMethod.Parameters)
                {
                    if (param.Name.Contains(nextMethod.Name) && (param.Name.Length > nextMethod.Name.Length)) //parameter that contains the method name + postfix, it's a grouped param
                    {
                        //assigning grouped parameter passed to the lazy method, to the parameter used in the invocation to the next method
                        string argumentName = param.Name.Replace(nextMethodName, Name);
                        builder.AppendLine(string.Format(CultureInfo.InvariantCulture, "{0} = {1}", param.Name, argumentName));
                    }
                }
                builder.Outdent();
            }

            // Create AzureMethodTemplateModel from nextMethod to determine nextMethod's MethodParameterInvocation signature
            AzureMethodTemplateModel nextMethodTemplateModel = new AzureMethodTemplateModel(nextMethod, ServiceClient);

            builder.Indent().AppendLine(string.Format(CultureInfo.InvariantCulture, "{0}_async({1})", nextMethodName, nextMethodTemplateModel.MethodParameterInvocation));
            builder.Outdent().Append(String.Format(CultureInfo.InvariantCulture, "end"));

            return(builder.ToString());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns generated response or body of the auto-paginated method.
        /// </summary>
        public override string ResponseGeneration()
        {
            IndentedStringBuilder builder = new IndentedStringBuilder();

            if (ReturnType.Body != null)
            {
                if (ReturnType.Body is CompositeType)
                {
                    CompositeType compositeType = (CompositeType)ReturnType.Body;
                    if (compositeType.Extensions.ContainsKey(AzureExtensions.PageableExtension) && this.Extensions.ContainsKey("nextMethodName"))
                    {
                        bool isNextLinkMethod = this.Extensions.ContainsKey("nextLinkMethod") && (bool)this.Extensions["nextLinkMethod"];
                        bool isPageable       = (bool)compositeType.Extensions[AzureExtensions.PageableExtension];
                        if (isPageable && !isNextLinkMethod)
                        {
                            builder.AppendLine("first_page = {0}_as_lazy({1})", Name, MethodParameterInvocation);
                            builder.AppendLine("first_page.get_all_items");
                            return(builder.ToString());
                        }
                    }
                }
            }
            return(base.ResponseGeneration());
        }
 /// <summary>
 /// Returns generated response or body of the auto-paginated method.
 /// </summary>
 public override string ResponseGeneration()
 {
     IndentedStringBuilder builder = new IndentedStringBuilder();
     if (ReturnType.Body != null)
     {
         if (ReturnType.Body is CompositeType)
         {
             CompositeType compositeType = (CompositeType)ReturnType.Body;
             if (compositeType.Extensions.ContainsKey(AzureExtensions.PageableExtension) && this.Extensions.ContainsKey("nextMethodName"))
             {
                 bool isNextLinkMethod = this.Extensions.ContainsKey("nextLinkMethod") && (bool)this.Extensions["nextLinkMethod"];
                 bool isPageable = (bool)compositeType.Extensions[AzureExtensions.PageableExtension];
                 if (isPageable && !isNextLinkMethod)
                 {
                     builder.AppendLine("first_page = {0}_as_lazy({1})", Name, MethodParameterInvocation);
                     builder.AppendLine("first_page.get_all_items");
                     return builder.ToString();
                 }
             }
         }
     }
     return base.ResponseGeneration();
 }
        /// <summary>
        /// Generates Ruby code in form of string for deserializing polling response.
        /// </summary>
        /// <param name="variableName">Variable name which keeps the response.</param>
        /// <param name="type">Type of response.</param>
        /// <returns>Ruby code in form of string for deserializing polling response.</returns>
        public string DeserializePollingResponse(string variableName, IType type)
        {
            var builder = new IndentedStringBuilder("  ");

            string serializationLogic = GetDeserializationString(type, variableName, variableName);
            return builder.AppendLine(serializationLogic).ToString();
        }
        /// <summary>
        /// Returns Ruby code as string which sets `next_method` property of the page with the respective next paging method
        /// and performs parameter re-assignment when required (ex. parameter grouping cases)
        /// </summary>
        public string AssignNextMethodToPage()
        {
            string nextMethodName;
            Method nextMethod = null;
            PageableExtension pageableExtension = JsonConvert.DeserializeObject<PageableExtension>(Extensions[AzureExtensions.PageableExtension].ToString());

            // When pageable extension have operation name
            if (pageableExtension != null && !string.IsNullOrWhiteSpace(pageableExtension.OperationName))
            {
                nextMethod = ServiceClient.Methods.FirstOrDefault(m =>
                    pageableExtension.OperationName.Equals(m.SerializedName, StringComparison.OrdinalIgnoreCase));
                nextMethodName = nextMethod.Name;
            }
            // When pageable extension does not have operation name
            else
            {
                nextMethodName = (string)Extensions["nextMethodName"];
                nextMethod = ServiceClient.Methods.Where(m => m.Name == nextMethodName).FirstOrDefault();
            }

            IndentedStringBuilder builder = new IndentedStringBuilder("  ");

            // As there is no distinguishable property in next link parameter, we'll check to see whether any parameter contains "next" in the parameter name
            Parameter nextLinkParameter = nextMethod.Parameters.Where(p => p.Name.IndexOf("next", StringComparison.OrdinalIgnoreCase) >= 0).FirstOrDefault();
            builder.AppendLine(String.Format(CultureInfo.InvariantCulture, "page.next_method = Proc.new do |{0}|", nextLinkParameter.Name));

            // In case of parmeter grouping, next methods parameter needs to be mapped with the origin methods parameter
            IEnumerable<Parameter> origMethodGroupedParameters = Parameters.Where(p => p.Name.Contains(Name));
            if (origMethodGroupedParameters.Count() > 0)
            {
                builder.Indent();
                foreach (Parameter param in nextMethod.Parameters)
                {
                    if (param.Name.Contains(nextMethod.Name) && (param.Name.Length > nextMethod.Name.Length)) //parameter that contains the method name + postfix, it's a grouped param
                    {
                        //assigning grouped parameter passed to the lazy method, to the parameter used in the invocation to the next method
                        string argumentName = param.Name.Replace(nextMethodName, Name);
                        builder.AppendLine(string.Format(CultureInfo.InvariantCulture, "{0} = {1}", param.Name, argumentName));
                    }
                }
                builder.Outdent();
            }

            // Create AzureMethodTemplateModel from nextMethod to determine nextMethod's MethodParameterInvocation signature
            AzureMethodTemplateModel nextMethodTemplateModel = new AzureMethodTemplateModel(nextMethod, ServiceClient);
            builder.Indent().AppendLine(string.Format(CultureInfo.InvariantCulture, "{0}_async({1})", nextMethodName, nextMethodTemplateModel.MethodParameterInvocation));
            builder.Outdent().Append(String.Format(CultureInfo.InvariantCulture, "end"));

            return builder.ToString();
        }