private AzureMethodTemplateModel GetPagingNextMethodWithInvocation(out string invocation, bool async = false)
        {
            if (IsPagingNextOperation)
            {
                invocation = Name + "SinglePage" + (async ? "Async" : "");
                return(this);
            }
            string name        = ((string)this.Extensions["nextMethodName"]).ToCamelCase();
            string group       = _namer.GetMethodGroupName((string)this.Extensions["nextMethodGroup"]);
            var    methodModel = new AzureMethodTemplateModel(
                ServiceClient.Methods.FirstOrDefault(m =>
                                                     (group == null ? m.Group == null : group.Equals(m.Group, StringComparison.OrdinalIgnoreCase)) &&
                                                     m.Name.Equals(name, StringComparison.OrdinalIgnoreCase)), ServiceClient);

            group = group.ToPascalCase();
            name  = name + "SinglePage";
            if (async)
            {
                name = name + "Async";
            }
            if (group == null || this.OperationName == methodModel.OperationName)
            {
                invocation = name;
            }
            else
            {
                invocation = string.Format(CultureInfo.InvariantCulture, "{0}.get{1}().{2}", ClientReference.Replace("this.", ""), group, name);
            }
            return(methodModel);
        }
        public string PagingGroupedParameterTransformation(bool filterRequired = false)
        {
            var builder = new IndentedStringBuilder();

            if (IsPagingOperation)
            {
                string invocation;
                AzureMethodTemplateModel nextMethod = GetPagingNextMethodWithInvocation(out invocation);
                TransformPagingGroupedParameter(builder, nextMethod, filterRequired);
            }
            return(builder.ToString());
        }
Exemple #3
0
        public override string ResponseGeneration(bool filterRequired = false)
        {
            if (this.IsPagingOperation && !this.IsPagingNextOperation)
            {
                var builder = new IndentedStringBuilder();
                builder.AppendLine("{0} response = {1}Delegate(call.execute());",
                                   ReturnTypeModel.WireResponseTypeString, this.Name);

                string invocation;
                AzureMethodTemplateModel nextMethod = GetPagingNextMethod(out invocation);

                builder.AppendLine("PagedList<{0}> result = new PagedList<{0}>(response.getBody()) {{", ((SequenceType)ReturnType.Body).ElementType.Name)
                .Indent().AppendLine("@Override")
                .AppendLine("public Page<{0}> nextPage(String {1}) throws {2}, IOException {{",
                            ((SequenceType)ReturnType.Body).ElementType.Name,
                            nextMethod.ParameterModels.First(p => p.Name.StartsWith("next", StringComparison.OrdinalIgnoreCase)).Name,
                            OperationExceptionTypeString)
                .Indent();
                TransformPagingGroupedParameter(builder, nextMethod, filterRequired);
                builder.AppendLine("return {0}({1}).getBody();",
                                   invocation, filterRequired ? nextMethod.MethodRequiredParameterInvocation : nextMethod.MethodParameterInvocation)
                .Outdent().AppendLine("}")
                .Outdent().AppendLine("};");
                return(builder.ToString());
            }
            else if (this.IsPagingNonPollingOperation)
            {
                var returnTypeBody = ReturnType.Body as AzureSequenceTypeModel;
                var builder        = new IndentedStringBuilder();
                builder.AppendLine("{0}<{1}<{2}>> response = {3}Delegate(call.execute());",
                                   ReturnTypeModel.ClientResponseType, returnTypeBody.PageImplType, returnTypeBody.ElementType.Name, this.Name.ToCamelCase());
                builder.AppendLine("{0} result = response.getBody().getItems();", this.ReturnType.Body.Name);
                return(builder.ToString());
            }
            else
            {
                return(base.ResponseGeneration());
            }
        }
        public string NextMethodParameterInvocation(bool filterRequired = false)
        {
            string invocation;
            AzureMethodTemplateModel nextMethod = GetPagingNextMethodWithInvocation(out invocation);

            if (filterRequired)
            {
                if (this.InputParameterTransformation.IsNullOrEmpty() || nextMethod.InputParameterTransformation.IsNullOrEmpty())
                {
                    return(nextMethod.MethodDefaultParameterInvocation);
                }
                var           groupedType   = this.InputParameterTransformation.First().ParameterMappings[0].InputParameter;
                var           nextGroupType = nextMethod.InputParameterTransformation.First().ParameterMappings[0].InputParameter;
                List <string> invocations   = new List <string>();
                foreach (var parameter in nextMethod.LocalParameters)
                {
                    if (parameter.IsRequired)
                    {
                        invocations.Add(parameter.Name);
                    }
                    else if (parameter.Name == nextGroupType.Name && groupedType.IsRequired)
                    {
                        invocations.Add(parameter.Name);
                    }
                    else
                    {
                        invocations.Add("null");
                    }
                }
                return(string.Join(", ", invocations));
            }
            else
            {
                return(nextMethod.MethodParameterInvocation);
            }
        }
Exemple #5
0
        protected virtual void TransformPagingGroupedParameter(IndentedStringBuilder builder, AzureMethodTemplateModel nextMethod, bool filterRequired = false)
        {
            if (this.InputParameterTransformation.IsNullOrEmpty())
            {
                return;
            }
            var groupedType   = this.InputParameterTransformation.First().ParameterMappings[0].InputParameter;
            var nextGroupType = nextMethod.InputParameterTransformation.First().ParameterMappings[0].InputParameter;

            if (nextGroupType.Name == groupedType.Name)
            {
                return;
            }
            var nextGroupTypeName = _namer.GetTypeName(nextGroupType.Name);

            if (filterRequired && !nextGroupType.IsRequired)
            {
                return;
            }
            if (!groupedType.IsRequired)
            {
                builder.AppendLine("{0} {1} = null;", nextGroupTypeName, nextGroupType.Name.ToCamelCase());
                builder.AppendLine("if ({0} != null) {{", groupedType.Name.ToCamelCase());
                builder.Indent();
                builder.AppendLine("{0} = new {1}();", nextGroupType.Name.ToCamelCase(), nextGroupTypeName);
            }
            else
            {
                builder.AppendLine("{1} {0} = new {1}();", nextGroupType.Name.ToCamelCase(), nextGroupTypeName);
            }
            foreach (var outParam in nextMethod.InputParameterTransformation.Select(t => t.OutputParameter))
            {
                builder.AppendLine("{0}.with{1}({2}.{3}());", nextGroupType.Name.ToCamelCase(), outParam.Name.ToPascalCase(), groupedType.Name.ToCamelCase(), outParam.Name.ToCamelCase());
            }
            if (!groupedType.IsRequired)
            {
                builder.Outdent().AppendLine(@"}");
            }
        }
Exemple #6
0
 public override string SuccessCallback(bool filterRequired = false)
 {
     if (this.IsPagingOperation)
     {
         var builder = new IndentedStringBuilder();
         builder.AppendLine("{0} result = {1}Delegate(response);",
                            ReturnTypeModel.WireResponseTypeString, this.Name);
         builder.AppendLine("if (serviceCallback != null) {").Indent();
         builder.AppendLine("serviceCallback.load(result.getBody().getItems());");
         builder.AppendLine("if (result.getBody().getNextPageLink() != null").Indent().Indent()
         .AppendLine("&& serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) {").Outdent();
         string invocation;
         AzureMethodTemplateModel nextMethod = GetPagingNextMethod(out invocation, true);
         TransformPagingGroupedParameter(builder, nextMethod, filterRequired);
         var nextCall = string.Format(CultureInfo.InvariantCulture, "{0}(result.getBody().getNextPageLink(), {1});",
                                      invocation,
                                      filterRequired ? nextMethod.MethodRequiredParameterInvocationWithCallback : nextMethod.MethodParameterInvocationWithCallback);
         builder.AppendLine(nextCall.Replace(
                                string.Format(", {0}", nextMethod.ParameterModels.First(p => p.Name.StartsWith("next", StringComparison.OrdinalIgnoreCase)).Name),
                                "")).Outdent();
         builder.AppendLine("} else {").Indent();
         if (ReturnType.Headers == null)
         {
             builder.AppendLine("serviceCallback.success(new {0}<>(serviceCallback.get(), result.getResponse()));", ReturnTypeModel.ClientResponseType);
         }
         else
         {
             builder.AppendLine("serviceCallback.success(new {0}<>(serviceCallback.get(), result.getHeaders(), result.getResponse()));", ReturnTypeModel.ClientResponseType);
         }
         builder.Outdent().AppendLine("}").Outdent().AppendLine("}");
         if (ReturnType.Headers == null)
         {
             builder.AppendLine("serviceCall.success(new {0}<>(result.getBody().getItems(), response));", ReturnTypeModel.ClientResponseType);
         }
         else
         {
             builder.AppendLine("serviceCall.success(new {0}<>(result.getBody().getItems(), result.getHeaders(), result.getResponse()));", ReturnTypeModel.ClientResponseType);
         }
         return(builder.ToString());
     }
     else if (this.IsPagingNextOperation)
     {
         var builder = new IndentedStringBuilder();
         builder.AppendLine("{0} result = {1}Delegate(response);", ReturnTypeModel.WireResponseTypeString, this.Name);
         builder.AppendLine("serviceCallback.load(result.getBody().getItems());");
         builder.AppendLine("if (result.getBody().getNextPageLink() != null").Indent().Indent();
         builder.AppendLine("&& serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) {").Outdent();
         var nextCall = string.Format(CultureInfo.InvariantCulture, "{0}Async(result.getBody().getNextPageLink(), {1});",
                                      this.Name,
                                      filterRequired ? MethodRequiredParameterInvocationWithCallback : MethodParameterInvocationWithCallback);
         builder.AppendLine(nextCall.Replace(
                                string.Format(", {0}", ParameterModels.First(p => p.Name.StartsWith("next", StringComparison.OrdinalIgnoreCase)).Name),
                                "")).Outdent();
         builder.AppendLine("} else {").Indent();
         if (ReturnType.Headers == null)
         {
             builder.AppendLine("serviceCallback.success(new {0}<>(serviceCallback.get(), result.getResponse()));", ReturnTypeModel.ClientResponseType);
         }
         else
         {
             builder.AppendLine("serviceCallback.success(new {0}<>(serviceCallback.get(), result.getHeaders(), result.getResponse()));", ReturnTypeModel.ClientResponseType);
         }
         builder.Outdent().AppendLine("}");
         return(builder.ToString());
     }
     else if (this.IsPagingNonPollingOperation)
     {
         var returnTypeBody = ReturnType.Body as AzureSequenceTypeModel;
         var builder        = new IndentedStringBuilder();
         builder.AppendLine("{0}<{1}<{2}>> result = {3}Delegate(response);",
                            ReturnTypeModel.ClientResponseType, returnTypeBody.PageImplType, returnTypeBody.ElementType.Name, this.Name.ToCamelCase());
         if (ReturnType.Headers == null)
         {
             builder.AppendLine("serviceCallback.success(new {0}<>(result.getBody().getItems(), result.getResponse()));", ReturnTypeModel.ClientResponseType);
         }
         else
         {
             builder.AppendLine("serviceCallback.success(new {0}<>(result.getBody().getItems(), result.getHeaders(), result.getResponse()));", ReturnTypeModel.ClientResponseType);
         }
         return(builder.ToString());
     }
     return(base.SuccessCallback());
 }
 protected override void TransformPagingGroupedParameter(IndentedStringBuilder builder, AzureMethodTemplateModel nextMethod, bool filterRequired = false)
 {
     if (this.InputParameterTransformation.IsNullOrEmpty() || nextMethod.InputParameterTransformation.IsNullOrEmpty())
     {
         return;
     }
     var groupedType = this.InputParameterTransformation.First().ParameterMappings[0].InputParameter;
     var nextGroupType = nextMethod.InputParameterTransformation.First().ParameterMappings[0].InputParameter;
     if (nextGroupType.Name == groupedType.Name)
     {
         return;
     }
     var nextGroupTypeName = _namer.GetTypeName(nextGroupType.Name) + "Inner";
     if (filterRequired && !groupedType.IsRequired)
     {
         return;
     }
     if (!groupedType.IsRequired)
     {
         builder.AppendLine("{0} {1} = null;", nextGroupTypeName, nextGroupType.Name.ToCamelCase());
         builder.AppendLine("if ({0} != null) {{", groupedType.Name.ToCamelCase());
         builder.Indent();
         builder.AppendLine("{0} = new {1}();", nextGroupType.Name.ToCamelCase(), nextGroupTypeName);
     }
     else
     {
         builder.AppendLine("{1} {0} = new {1}();", nextGroupType.Name.ToCamelCase(), nextGroupTypeName);
     }
     foreach (var outParam in nextMethod.InputParameterTransformation.Select(t => t.OutputParameter))
     {
         builder.AppendLine("{0}.with{1}({2}.{3}());", nextGroupType.Name.ToCamelCase(), outParam.Name.ToPascalCase(), groupedType.Name.ToCamelCase(), outParam.Name.ToCamelCase());
     }
     if (!groupedType.IsRequired)
     {
         builder.Outdent().AppendLine(@"}");
     }
 }
 private AzureMethodTemplateModel GetPagingNextMethodWithInvocation(out string invocation, bool async = false)
 {
     if (IsPagingNextOperation)
     {
         invocation = Name + "SinglePage" + (async ? "Async" : "");
         return this;
     }
     string name = ((string)this.Extensions["nextMethodName"]).ToCamelCase();
     string group = _namer.GetMethodGroupName((string)this.Extensions["nextMethodGroup"]);
     var methodModel = new AzureMethodTemplateModel(
         ServiceClient.Methods.FirstOrDefault(m =>
             (group == null ? m.Group == null : group.Equals(m.Group, StringComparison.OrdinalIgnoreCase))
             && m.Name.Equals(name, StringComparison.OrdinalIgnoreCase)), ServiceClient);
     group = group.ToPascalCase();
     name = name + "SinglePage";
     if (async)
     {
         name = name + "Async";
     }
     if (group == null || this.OperationName == methodModel.OperationName)
     {
         invocation = name;
     }
     else
     {
         invocation = string.Format(CultureInfo.InvariantCulture, "{0}.get{1}().{2}", ClientReference.Replace("this.", ""), group, name);
     }
     return methodModel;
 }
Exemple #9
0
 public AzureResponseModel(ITypeModel body, ITypeModel headers, AzureMethodTemplateModel method)
     : this(new Response(body, headers), method)
 {
 }
Exemple #10
0
 public AzureResponseModel(Response response, AzureMethodTemplateModel method)
     : base (response)
 {
     this._response = response;
     this._method = method;
 }