コード例 #1
0
        private void AddQueryParametersToUri(string variableName, IndentedStringBuilder builder)
        {
            builder.AppendLine("System.Collections.Generic.List<string> _queryParameters = new System.Collections.Generic.List<string>();");
            if (LogicalParameterTemplateModels.Any(p => p.Location == ParameterLocation.Query))
            {
                foreach (var queryParameter in LogicalParameterTemplateModels
                         .Where(p => p.Location == ParameterLocation.Query).Select(p => p as AzureParameterTemplateModel))
                {
                    string queryParametersAddString =
                        "_queryParameters.Add(string.Format(\"{0}={{0}}\", System.Uri.EscapeDataString({1})));";

                    if (queryParameter.IsODataFilterExpression)
                    {
                        queryParametersAddString = @"var _odataFilter = {2}.ToString();
    if (!string.IsNullOrEmpty(_odataFilter)) 
    {{
        _queryParameters.Add(_odataFilter);
    }}";
                    }
                    else if (queryParameter.Extensions.ContainsKey(AzureExtensions.SkipUrlEncodingExtension))
                    {
                        queryParametersAddString = "_queryParameters.Add(string.Format(\"{0}={{0}}\", {1}));";
                    }

                    builder.AppendLine("if ({0} != null)", queryParameter.Name)
                    .AppendLine("{").Indent();

                    if (queryParameter.CollectionFormat == CollectionFormat.Multi)
                    {
                        builder.AppendLine("if ({0}.Count == 0)", queryParameter.Name)
                        .AppendLine("{").Indent()
                        .AppendLine(queryParametersAddString, queryParameter.SerializedName, "string.Empty").Outdent()
                        .AppendLine("}")
                        .AppendLine("else")
                        .AppendLine("{").Indent()
                        .AppendLine("foreach (var _item in {0})", queryParameter.Name)
                        .AppendLine("{").Indent()
                        .AppendLine(queryParametersAddString, queryParameter.SerializedName, "_item ?? string.Empty").Outdent()
                        .AppendLine("}").Outdent()
                        .AppendLine("}").Outdent();
                    }
                    else
                    {
                        builder.AppendLine(queryParametersAddString,
                                           queryParameter.SerializedName, queryParameter.GetFormattedReferenceValue(ClientReference), queryParameter.Name);
                    }
                    builder.Outdent()
                    .AppendLine("}");
                }
            }

            builder.AppendLine("if (_queryParameters.Count > 0)")
            .AppendLine("{").Indent()
            .AppendLine("{0} += ({0}.Contains(\"?\") ? \"&\" : \"?\") + string.Join(\"&\", _queryParameters);", variableName).Outdent()
            .AppendLine("}");
        }
コード例 #2
0
        private void ReplacePathParametersInUri(string variableName, IndentedStringBuilder builder)
        {
            foreach (var pathParameter in LogicalParameterTemplateModels.Where(p => p.Location == ParameterLocation.Path))
            {
                string replaceString = "{0} = {0}.Replace(\"{{{1}}}\", Uri.EscapeDataString({2}));";
                if (pathParameter.Extensions.ContainsKey(AzureExtensions.SkipUrlEncodingExtension))
                {
                    replaceString = "{0} = {0}.Replace(\"{{{1}}}\", {2});";
                }

                builder.AppendLine(replaceString,
                                   variableName,
                                   pathParameter.SerializedName,
                                   pathParameter.Type.ToString(ClientReference, pathParameter.Name));
            }
        }
コード例 #3
0
        public AzureMethodTemplateModel(Method source, ServiceClient serviceClient)
            : base(source, serviceClient)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            ParameterTemplateModels.Clear();
            LogicalParameterTemplateModels.Clear();
            source.Parameters.ForEach(p => ParameterTemplateModels.Add(new AzureParameterTemplateModel(p)));
            source.LogicalParameters.ForEach(p => LogicalParameterTemplateModels.Add(new AzureParameterTemplateModel(p)));
            if (MethodGroupName != ServiceClient.Name)
            {
                MethodGroupName = MethodGroupName + "Operations";
            }

            this.ClientRequestIdString = AzureExtensions.GetClientRequestIdString(source);
            this.RequestIdString       = AzureExtensions.GetRequestIdString(source);
        }