public async Task <HttpResponseMessage> Invoke(OperationInfo info)
        {
            if (!IsValidHost())
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid request domain"));
            }

            HyakUtils.CSMUrl = HyakUtils.CSMUrl ?? Utils.GetCSMUrl(Request.RequestUri.Host);

            // escaping "#" as it may appear in some resource names
            info.Url = info.Url.Replace("#", "%23");

            var executeRequest = new HttpRequestMessage(new HttpMethod(info.HttpMethod), info.Url + (info.Url.IndexOf("?api-version=", StringComparison.Ordinal) != -1 ? string.Empty : "?api-version=" + info.ApiVersion) + (string.IsNullOrEmpty(info.QueryString) ? string.Empty : info.QueryString));

            if (info.RequestBody != null)
            {
                executeRequest.Content = new StringContent(info.RequestBody.ToString(), Encoding.UTF8, "application/json");
            }

            return(await _armRepository.InvokeAsync(Request, executeRequest));
        }
 private void LogCsmType(OperationInfo info)
 {
     try
     {
         if (info == null || info.Url == null || info.Url.IndexOf("/providers/", StringComparison.OrdinalIgnoreCase) == -1) return;
         var path = info.Url.Substring(info.Url.IndexOf("/providers/", StringComparison.OrdinalIgnoreCase));
         var sb = new StringBuilder();
         var parts = path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
         for (var i = 1; i < parts.Length; i++)
         {
             if (i == 1 || i == 2 || i % 2 == 0)
                 sb.AppendFormat("{0}/", parts[i]);
         }
         var csmType = sb.ToString().Trim(new[] { '/' });
         TelemetryHelper.LogInfo(new CsmTypeEvent { Type = csmType, HttpMethod = info.HttpMethod });
     }
     catch (Exception e)
     {
         TelemetryHelper.LogException(e);
     }
 }
        public async Task<HttpResponseMessage> Invoke(OperationInfo info)
        {
            // escaping "#" as it may appear in some resource names
            info.Url = info.Url.Replace("#", "%23");
            HyakUtils.CSMUrl = HyakUtils.CSMUrl ?? Utils.GetCSMUrl(Request.RequestUri.Host);
            LogCsmType(info);
            using (var client = GetClient(Utils.GetCSMUrl(Request.RequestUri.Host)))
            {
                var request = new HttpRequestMessage(new System.Net.Http.HttpMethod(info.HttpMethod), info.Url + (info.Url.IndexOf("?api-version=") != -1 ? string.Empty : "?api-version=" + info.ApiVersion) + (string.IsNullOrEmpty(info.QueryString) ? string.Empty : info.QueryString));
                if (info.RequestBody != null)
                {
                    request.Content = new StringContent(info.RequestBody.ToString(), Encoding.UTF8, "application/json");
                }

                return await Utils.Execute(client.SendAsync(request));
            }
        }