MSGraph.Autorest/custom/Module.cs

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
 
namespace Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph
{
    /// <summary>A class that contains the module-common code and data.</summary>
    public partial class Module
    {
        partial void AfterCreatePipeline(global::System.Management.Automation.InvocationInfo invocationInfo, ref Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.HttpPipeline pipeline)
        {
            pipeline.Append(SendAsync);
        }
 
        public async System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> SendAsync(System.Net.Http.HttpRequestMessage request, Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.IEventListener callback, Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.ISendAsync next)
        {
            string search = "Search=";
            string splitter = "&";
            string query = request.RequestUri.Query;
            int start = query.IndexOf(search, System.StringComparison.OrdinalIgnoreCase);
            int end = 0;
 
            if (start >= 0 && query.Length > start + search.Length -1)
            {
                start += search.Length;
 
                end = query.IndexOf(splitter, start, System.StringComparison.OrdinalIgnoreCase);
                if (start == end)
                {
                    return await next.SendAsync(request, callback);
                }
                if (end == -1)
                {
                    end = query.Length;
                }
                search = query.Substring(start, end - start);
                //Remove " in search query
                search = System.Text.RegularExpressions.Regex.Replace(search, "^%22|%22$", "");
                 
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.Append(query.Substring(0, start));
                sb.Append("\"");
                sb.Append(search);
                sb.Append("\"");
                sb.Append(query.Substring(end));
                System.UriBuilder ub = new System.UriBuilder(request.RequestUri);
                ub.Query = sb.ToString();
                request.RequestUri = ub.Uri;
            }
 
            return await next.SendAsync(request, callback);
        }
    }
}