Пример #1
0
        private void TransformPagingGroupedParameter(IndentedStringBuilder builder, AzureMethodTemplateModel nextMethod)
        {
            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;
            }
            if (!groupedType.IsRequired)
            {
                builder.AppendLine("{0} {1} = null;", nextGroupType.Name.ToPascalCase(), nextGroupType.Name.ToCamelCase());
                builder.AppendLine("if ({0} != null) {{", groupedType.Name.ToCamelCase());
                builder.Indent();
                builder.AppendLine("{0} = new {1}();", nextGroupType.Name.ToCamelCase(), nextGroupType.Name.ToPascalCase());
            }
            else
            {
                builder.AppendLine("{1} {0} = new {1}();", nextGroupType.Name.ToCamelCase(), nextGroupType.Name.ToPascalCase());
            }
            foreach (var outParam in nextMethod.InputParameterTransformation.Select(t => t.OutputParameter))
            {
                builder.AppendLine("{0}.set{1}({2}.get{1}());", nextGroupType.Name.ToCamelCase(), outParam.Name.ToPascalCase(), groupedType.Name.ToCamelCase());
            }
            if (!groupedType.IsRequired)
            {
                builder.Outdent().AppendLine(@"}");
            }
        }
Пример #2
0
        private AzureMethodTemplateModel GetPagingNextMethod(out string invocation, bool async = false)
        {
            string name        = ((string)this.Extensions["nextMethodName"]).ToCamelCase();
            string group       = (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();
            if (group != null)
            {
                group += "Operations";
            }
            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);
        }
Пример #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 nextPageLink) throws {1}, IOException {{",
                            ((SequenceType)ReturnType.Body).ElementType.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 builder = new IndentedStringBuilder();
                builder.AppendLine("{0}<PageImpl<{1}>> response = {2}Delegate(call.execute());",
                                   ReturnTypeModel.ClientResponseType, ((SequenceType)ReturnType.Body).ElementType.Name, this.Name.ToCamelCase());
                builder.AppendLine("{0} result = response.getBody().getItems();", this.ReturnType.Body.Name);
                return(builder.ToString());
            }
            else
            {
                return(base.ResponseGeneration());
            }
        }
Пример #4
0
 public AzureResponseModel(ITypeModel body, ITypeModel headers, AzureMethodTemplateModel method)
     : this(new Response(body, headers), method)
 {
 }
Пример #5
0
 public AzureResponseModel(Response response, AzureMethodTemplateModel method)
     : base (response)
 {
     this._response = response;
     this._method = method;
 }
Пример #6
0
 public AzureResponseModel(ITypeModel body, ITypeModel headers, AzureMethodTemplateModel method)
     : this(new Response(body, headers), method)
 {
 }
Пример #7
0
 public AzureResponseModel(Response response, AzureMethodTemplateModel method)
     : base(response)
 {
     this._response = response;
     this._method   = method;
 }
Пример #8
0
 private 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;
     }
     if (filterRequired && !nextGroupType.IsRequired)
     {
         return;
     }
     if (!groupedType.IsRequired)
     {
         builder.AppendLine("{0} {1} = null;", nextGroupType.Name.ToPascalCase(), nextGroupType.Name.ToCamelCase());
         builder.AppendLine("if ({0} != null) {{", groupedType.Name.ToCamelCase());
         builder.Indent();
         builder.AppendLine("{0} = new {1}();", nextGroupType.Name.ToCamelCase(), nextGroupType.Name.ToPascalCase());
     }
     else
     { 
         builder.AppendLine("{1} {0} = new {1}();", nextGroupType.Name.ToCamelCase(), nextGroupType.Name.ToPascalCase());
     }
     foreach (var outParam in nextMethod.InputParameterTransformation.Select(t => t.OutputParameter))
     {
         builder.AppendLine("{0}.set{1}({2}.get{1}());", nextGroupType.Name.ToCamelCase(), outParam.Name.ToPascalCase(), groupedType.Name.ToCamelCase());
     }
     if (!groupedType.IsRequired)
     {
         builder.Outdent().AppendLine(@"}");
     }
 }
Пример #9
0
 private AzureMethodTemplateModel GetPagingNextMethod(out string invocation, bool async = false)
 {
     string name = ((string)this.Extensions["nextMethodName"]).ToCamelCase();
     string group = (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();
     if (group != null)
     {
         group += "Operations";
     }
     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;
 }
Пример #10
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("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(", nextPageLink", "")).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.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(", nextPageLink", "")).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 builder = new IndentedStringBuilder();
         builder.AppendLine("{0}<PageImpl<{1}>> result = {2}Delegate(response);",
                            ReturnTypeModel.ClientResponseType, ((SequenceType)ReturnType.Body).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());
 }