diff --git a/DemoCoreWeb.ClientApi/WebApiClientAuto.cs b/DemoCoreWeb.ClientApi/WebApiClientAuto.cs index 1836e564..e2f66f34 100644 --- a/DemoCoreWeb.ClientApi/WebApiClientAuto.cs +++ b/DemoCoreWeb.ClientApi/WebApiClientAuto.cs @@ -146,7 +146,7 @@ public System.DateOnly GetDateOnlyMin(Action h var requestUri = "api/Entities/"+id; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Delete, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -1843,7 +1843,7 @@ public DemoWebApi.DemoData.Client.Company GetCompany(long id, Action GetMims(DemoWebApi.DemoData var content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, "application/json"); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -1961,7 +1961,7 @@ public DemoWebApi.DemoData.Client.MyGeneric GetMyGeneri var content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, "application/json"); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -2021,7 +2021,7 @@ public DemoWebApi.DemoData.Client.MyGeneric GetMyGeneri var content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, "application/json"); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -2073,7 +2073,7 @@ public DemoWebApi.DemoData.Client.Company GetNullCompany(Action h var requestUri = "api/Heroes/"+id; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Delete, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -2511,7 +2511,7 @@ public DemoWebApi.Controllers.Client.Hero[] GetAsyncHeroes(Action h var requestUri = "api/Numbers/byte?d="+d; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -3007,7 +3007,7 @@ public byte GetByteWithRange(byte d, Action hand var content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, "application/json"); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -3115,7 +3115,7 @@ public sbyte Post(sbyte d, Action ha var content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, "application/json"); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -3169,7 +3169,7 @@ public short Post(short d, Action ha var content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, "application/json"); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -3223,7 +3223,7 @@ public ushort Post(ushort d, Action var content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, "application/json"); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -3277,7 +3277,7 @@ public int Post(int d, Action handle var content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, "application/json"); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -3331,7 +3331,7 @@ public long Post(long d, Action hand var content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, "application/json"); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -3385,7 +3385,7 @@ public ulong Post(ulong d, Action ha var content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, "application/json"); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -3440,7 +3440,7 @@ public System.Numerics.BigInteger PostBigInteger(System.Numerics.BigInteger bigI var content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, "application/json"); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -3496,7 +3496,7 @@ public string PostBigIntegralAsStringForJs(string bigIntegral, Action take, int skip, string order, var requestUri = "api/StringData/AthletheSearch?"+(take.HasValue?"take="+take.Value.ToString():String.Empty)+"&skip="+skip+"&order="+(order == null ? "" : Uri.EscapeDataString(order))+"&sort="+(sort == null ? "" : Uri.EscapeDataString(sort))+"&search="+(search == null ? "" : Uri.EscapeDataString(search)); using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4127,7 +4127,7 @@ public string GetABCDE(Action handle var requestUri = "api/StringData/String"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4175,7 +4175,7 @@ public string GetEmptyString(Action var requestUri = "api/StringData/EmptyString"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4225,7 +4225,7 @@ public string GetNullString(Action h var requestUri = "api/StringData/NullString"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4284,7 +4284,7 @@ public System.Net.Http.HttpResponseMessage GetActionResult(Action handleHea var requestUri = "api/SuperDemo/bool"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4489,7 +4489,7 @@ public byte Getbyte(Action handleHea var requestUri = "api/SuperDemo/byte"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4535,7 +4535,7 @@ public byte[] GetByteArray(Action ha var requestUri = "api/SuperDemo/ByteArray"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4582,7 +4582,7 @@ public char GetChar(Action handleHea var requestUri = "api/SuperDemo/char"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4629,7 +4629,7 @@ public char GetChar(Action handleHea var requestUri = "api/SuperDemo/Collection"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4676,7 +4676,7 @@ public DemoWebApi.DemoData.Client.Days GetDay(DemoWebApi.DemoData.Client.Days d, var requestUri = "api/SuperDemo/enumGet?d="+d; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4722,7 +4722,7 @@ public decimal GetDecimal(Action han var requestUri = "api/SuperDemo/decimal"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4771,7 +4771,7 @@ public decimal[] GetDecimalArrayQ(decimal[] a, Action $"a={Uri.EscapeDataString(k.ToString())}")); using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4818,7 +4818,7 @@ public decimal GetDecimalSquare(decimal d, Action var requestUri = "api/SuperDemo/DecimalZero"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4910,7 +4910,7 @@ public System.Collections.Generic.IDictionary GetDictionary(Acti var requestUri = "api/SuperDemo/StringStringDic"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4956,7 +4956,7 @@ public System.Collections.Generic.IDictionary GetDictionary(Acti var requestUri = "api/SuperDemo/StringPersonDic"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -5003,7 +5003,7 @@ public System.Collections.Generic.IDictionary GetDictionary(Acti var requestUri = "api/SuperDemo/StringPersonDic2"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -5049,7 +5049,7 @@ public double Getdouble(Action handl var requestUri = "api/SuperDemo/doulbe"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -5095,7 +5095,7 @@ public double GetDoubleZero(Action h var requestUri = "api/SuperDemo/DoubleZero"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -5143,7 +5143,7 @@ public DemoWebApi.DemoData.Client.Days[] GetEnumArrayDays(System.Collections.Gen var requestUri = "api/SuperDemo/enumArrayDays?"+String.Join("&", a.Select(k => $"a={Uri.EscapeDataString(k.ToString())}")); using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -5191,7 +5191,7 @@ public System.DayOfWeek[] GetEnumArrayQ2(System.Collections.Generic.List $"a={Uri.EscapeDataString(k.ToString())}")); using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -5237,7 +5237,7 @@ public float GetFloatZero(Action han var requestUri = "api/SuperDemo/FloatZero"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -5282,7 +5282,7 @@ public float GetFloatZero(Action han var requestUri = "api/SuperDemo/ICollection"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -5328,7 +5328,7 @@ public float GetFloatZero(Action han var requestUri = "api/SuperDemo/IList"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -5375,7 +5375,7 @@ public async Task GetInt2DAsync(Action var requestUri = "api/SuperDemo/int2dJagged"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -5471,7 +5471,7 @@ public int[] GetIntArray(Action hand var requestUri = "api/SuperDemo/intArray"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -5521,7 +5521,7 @@ public int[] GetIntArrayQ(int[] a, Action $"a={Uri.EscapeDataString(k.ToString())}")); using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -5571,7 +5571,7 @@ public long[] GetIntArrayQ2(System.Collections.Generic.IEnumerable a, Acti var requestUri = "api/SuperDemo/intArrayQ2?"+String.Join("&", a.Select(k => $"a={Uri.EscapeDataString(k.ToString())}")); using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -5617,7 +5617,7 @@ public int GetIntSquare(int d, Action GetNullableDecimal(bool hasValue, Action handleH var requestUri = "api/SuperDemo/short"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -6137,7 +6137,7 @@ public string[] GetStringArrayQ(string[] a, Action $"a={Uri.EscapeDataString(k.ToString())}")); using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -6187,7 +6187,7 @@ public string[] GetStringArrayQ2(System.Collections.Generic.List a, Acti var requestUri = "api/SuperDemo/stringArrayQ2?"+String.Join("&", a.Select(k => $"a={Uri.EscapeDataString(k.ToString())}")); using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -6226,7 +6226,7 @@ public System.Net.Http.HttpResponseMessage GetTextStream(Action handleHea var requestUri = "api/SuperDemo/uint"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -6305,7 +6305,7 @@ public ulong Getulong(Action handleH var requestUri = "api/SuperDemo/ulong"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -6349,7 +6349,7 @@ public ushort GetUShort(Action handl var requestUri = "api/SuperDemo/ushort"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -6382,7 +6382,7 @@ public System.Net.Http.HttpResponseMessage PostActionResult(Action PostWithQueryButEmptyBody(string s, int i, Acti var content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, "application/json"); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -7251,7 +7251,7 @@ public string AthletheSearch(System.Nullable take, int skip, string order, var requestUri = "api/TextData/AthletheSearch?"+(take.HasValue?"take="+take.Value.ToString():String.Empty)+"&skip="+skip+"&order="+(order == null ? "" : Uri.EscapeDataString(order))+"&sort="+(sort == null ? "" : Uri.EscapeDataString(sort))+"&search="+(search == null ? "" : Uri.EscapeDataString(search)); using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -7297,7 +7297,7 @@ public string GetABCDE(Action handle var requestUri = "api/TextData/String"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -7345,7 +7345,7 @@ public string GetEmptyString(Action var requestUri = "api/TextData/EmptyString"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -7395,7 +7395,7 @@ public string GetNullableString(Action h var requestUri = "api/TextData/NullString"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -7522,7 +7522,7 @@ public void A1TupleArray(System.Tuple[] idAndOrderArray, Actio var content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, "application/json"); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -7572,7 +7572,7 @@ public void A2TupleIEnumerable(System.Collections.Generic.IEnumerable GetTuple1(Action GetTuple2(Action GetTuple3(Action GetTuple4(Action GetTuple5(Action GetTuple6(Actio var requestUri = "api/Tuple/Tuple6"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -8067,7 +8067,7 @@ public System.Tuple GetTuple7 var requestUri = "api/Tuple/Tuple7"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -8117,7 +8117,7 @@ public System.Tuple GetTuple7 var requestUri = "api/Tuple/Tuple8"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -8175,7 +8175,7 @@ public DemoWebApi.DemoData.Client.Person LinkPeopleCompany2(System.Tuple tuple, Action tuple, Action tuple, Action tuple, Action var content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, "application/json"); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -8864,7 +8864,7 @@ public string PostTuple5(System.Tuple tuple var content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, "application/json"); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -8920,7 +8920,7 @@ public string PostTuple6(System.Tuple ha var requestUri = "api/Values/"+id; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Delete, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -9138,7 +9138,7 @@ public System.Collections.Generic.IEnumerable Get(Action han var requestUri = "api/Values/"+id; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -9330,7 +9330,7 @@ public System.Collections.Generic.IEnumerable Get2(Action h var requestUri = "api/Entities/"+id; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Delete, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -1581,7 +1581,7 @@ public DemoWebApi.DemoData.Client.Company GetCompany(long id, Action GetMims(DemoWebApi.DemoData var content = System.Net.Http.Json.JsonContent.Create(p, mediaType: null, jsonSerializerSettings); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -1677,7 +1677,7 @@ public DemoWebApi.DemoData.Client.MyGeneric GetMyGeneri var content = System.Net.Http.Json.JsonContent.Create(s, mediaType: null, jsonSerializerSettings); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -1725,7 +1725,7 @@ public DemoWebApi.DemoData.Client.MyGeneric GetMyGeneri var content = System.Net.Http.Json.JsonContent.Create(s, mediaType: null, jsonSerializerSettings); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -1771,7 +1771,7 @@ public DemoWebApi.DemoData.Client.Company GetNullCompany(Action h var requestUri = "api/Heroes/"+id; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Delete, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -2154,7 +2154,7 @@ public DemoWebApi.Controllers.Client.Hero[] GetAsyncHeroes(Action h var requestUri = "api/Numbers/byte?d="+d; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -2578,7 +2578,7 @@ public byte GetByteWithRange(byte d, Action hand var content = System.Net.Http.Json.JsonContent.Create(d, mediaType: null, jsonSerializerSettings); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -2670,7 +2670,7 @@ public sbyte Post(sbyte d, Action ha var content = System.Net.Http.Json.JsonContent.Create(d, mediaType: null, jsonSerializerSettings); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -2716,7 +2716,7 @@ public short Post(short d, Action ha var content = System.Net.Http.Json.JsonContent.Create(d, mediaType: null, jsonSerializerSettings); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -2762,7 +2762,7 @@ public ushort Post(ushort d, Action var content = System.Net.Http.Json.JsonContent.Create(d, mediaType: null, jsonSerializerSettings); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -2808,7 +2808,7 @@ public int Post(int d, Action handle var content = System.Net.Http.Json.JsonContent.Create(d, mediaType: null, jsonSerializerSettings); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -2854,7 +2854,7 @@ public long Post(long d, Action hand var content = System.Net.Http.Json.JsonContent.Create(d, mediaType: null, jsonSerializerSettings); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -2900,7 +2900,7 @@ public ulong Post(ulong d, Action ha var content = System.Net.Http.Json.JsonContent.Create(d, mediaType: null, jsonSerializerSettings); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -2946,7 +2946,7 @@ public System.Numerics.BigInteger PostBigInteger(System.Numerics.BigInteger bigI var content = System.Net.Http.Json.JsonContent.Create(bigInteger, mediaType: null, jsonSerializerSettings); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -2994,7 +2994,7 @@ public string PostBigIntegralAsStringForJs(string bigIntegral, Action take, int skip, string order, var requestUri = "api/StringData/AthletheSearch?"+(take.HasValue?"take="+take.Value.ToString():String.Empty)+"&skip="+skip+"&order="+(order == null ? "" : Uri.EscapeDataString(order))+"&sort="+(sort == null ? "" : Uri.EscapeDataString(sort))+"&search="+(search == null ? "" : Uri.EscapeDataString(search)); using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -3530,7 +3530,7 @@ public string GetABCDE(Action handle var requestUri = "api/StringData/String"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -3576,7 +3576,7 @@ public string GetEmptyString(Action var requestUri = "api/StringData/EmptyString"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -3624,7 +3624,7 @@ public string GetNullString(Action h var requestUri = "api/StringData/NullString"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -3680,7 +3680,7 @@ public System.Net.Http.HttpResponseMessage GetActionResult(Action handleHea var requestUri = "api/SuperDemo/bool"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -3882,7 +3882,7 @@ public byte Getbyte(Action handleHea var requestUri = "api/SuperDemo/byte"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -3925,7 +3925,7 @@ public byte[] GetByteArray(Action ha var requestUri = "api/SuperDemo/ByteArray"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -3968,7 +3968,7 @@ public char GetChar(Action handleHea var requestUri = "api/SuperDemo/char"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4011,7 +4011,7 @@ public char GetChar(Action handleHea var requestUri = "api/SuperDemo/Collection"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4054,7 +4054,7 @@ public DemoWebApi.DemoData.Client.Days GetDay(DemoWebApi.DemoData.Client.Days d, var requestUri = "api/SuperDemo/enumGet?d="+d; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4096,7 +4096,7 @@ public decimal GetDecimal(Action han var requestUri = "api/SuperDemo/decimal"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4139,7 +4139,7 @@ public decimal[] GetDecimalArrayQ(decimal[] a, Action $"a={Uri.EscapeDataString(k.ToString())}")); using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4182,7 +4182,7 @@ public decimal GetDecimalSquare(decimal d, Action var requestUri = "api/SuperDemo/DecimalZero"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4266,7 +4266,7 @@ public System.Collections.Generic.IDictionary GetDictionary(Acti var requestUri = "api/SuperDemo/StringStringDic"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4308,7 +4308,7 @@ public System.Collections.Generic.IDictionary GetDictionary(Acti var requestUri = "api/SuperDemo/StringPersonDic"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4351,7 +4351,7 @@ public System.Collections.Generic.IDictionary GetDictionary(Acti var requestUri = "api/SuperDemo/StringPersonDic2"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4394,7 +4394,7 @@ public double Getdouble(Action handl var requestUri = "api/SuperDemo/doulbe"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4436,7 +4436,7 @@ public double GetDoubleZero(Action h var requestUri = "api/SuperDemo/DoubleZero"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4479,7 +4479,7 @@ public DemoWebApi.DemoData.Client.Days[] GetEnumArrayDays(System.Collections.Gen var requestUri = "api/SuperDemo/enumArrayDays?"+String.Join("&", a.Select(k => $"a={Uri.EscapeDataString(k.ToString())}")); using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4523,7 +4523,7 @@ public System.DayOfWeek[] GetEnumArrayQ2(System.Collections.Generic.List $"a={Uri.EscapeDataString(k.ToString())}")); using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4566,7 +4566,7 @@ public float GetFloatZero(Action han var requestUri = "api/SuperDemo/FloatZero"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4608,7 +4608,7 @@ public float GetFloatZero(Action han var requestUri = "api/SuperDemo/ICollection"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4650,7 +4650,7 @@ public float GetFloatZero(Action han var requestUri = "api/SuperDemo/IList"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4693,7 +4693,7 @@ public async Task GetInt2DAsync(Action var requestUri = "api/SuperDemo/int2dJagged"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4781,7 +4781,7 @@ public int[] GetIntArray(Action hand var requestUri = "api/SuperDemo/intArray"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4825,7 +4825,7 @@ public int[] GetIntArrayQ(int[] a, Action $"a={Uri.EscapeDataString(k.ToString())}")); using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4869,7 +4869,7 @@ public long[] GetIntArrayQ2(System.Collections.Generic.IEnumerable a, Acti var requestUri = "api/SuperDemo/intArrayQ2?"+String.Join("&", a.Select(k => $"a={Uri.EscapeDataString(k.ToString())}")); using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -4912,7 +4912,7 @@ public int GetIntSquare(int d, Action GetNullableDecimal(bool hasValue, Action handleH var requestUri = "api/SuperDemo/short"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -5387,7 +5387,7 @@ public string[] GetStringArrayQ(string[] a, Action $"a={Uri.EscapeDataString(k.ToString())}")); using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -5431,7 +5431,7 @@ public string[] GetStringArrayQ2(System.Collections.Generic.List a, Acti var requestUri = "api/SuperDemo/stringArrayQ2?"+String.Join("&", a.Select(k => $"a={Uri.EscapeDataString(k.ToString())}")); using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -5466,7 +5466,7 @@ public System.Net.Http.HttpResponseMessage GetTextStream(Action handleHea var requestUri = "api/SuperDemo/uint"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -5542,7 +5542,7 @@ public ulong Getulong(Action handleH var requestUri = "api/SuperDemo/ulong"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -5584,7 +5584,7 @@ public ushort GetUShort(Action handl var requestUri = "api/SuperDemo/ushort"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -5616,7 +5616,7 @@ public System.Net.Http.HttpResponseMessage PostActionResult(Action PostWithQueryButEmptyBody(string s, int i, Acti var content = System.Net.Http.Json.JsonContent.Create(s, mediaType: null, jsonSerializerSettings); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -6342,7 +6342,7 @@ public string AthletheSearch(System.Nullable take, int skip, string order, var requestUri = "api/TextData/AthletheSearch?"+(take.HasValue?"take="+take.Value.ToString():String.Empty)+"&skip="+skip+"&order="+(order == null ? "" : Uri.EscapeDataString(order))+"&sort="+(sort == null ? "" : Uri.EscapeDataString(sort))+"&search="+(search == null ? "" : Uri.EscapeDataString(search)); using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -6388,7 +6388,7 @@ public string GetABCDE(Action handle var requestUri = "api/TextData/String"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -6434,7 +6434,7 @@ public string GetEmptyString(Action var requestUri = "api/TextData/EmptyString"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -6482,7 +6482,7 @@ public string GetNullableString(Action h var requestUri = "api/TextData/NullString"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -6596,7 +6596,7 @@ public void A1TupleArray(System.Tuple[] idAndOrderArray, Actio var content = System.Net.Http.Json.JsonContent.Create(idAndOrderArray, mediaType: null, jsonSerializerSettings); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -6638,7 +6638,7 @@ public void A2TupleIEnumerable(System.Collections.Generic.IEnumerable GetTuple1(Action GetTuple2(Action GetTuple3(Action GetTuple4(Action GetTuple5(Action GetTuple6(Actio var requestUri = "api/Tuple/Tuple6"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -7083,7 +7083,7 @@ public System.Tuple GetTuple7 var requestUri = "api/Tuple/Tuple7"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -7127,7 +7127,7 @@ public System.Tuple GetTuple7 var requestUri = "api/Tuple/Tuple8"; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -7175,7 +7175,7 @@ public DemoWebApi.DemoData.Client.Person LinkPeopleCompany2(System.Tuple tuple, Action tuple, Action tuple, Action tuple, Action var content = System.Net.Http.Json.JsonContent.Create(tuple, mediaType: null, jsonSerializerSettings); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -7756,7 +7756,7 @@ public string PostTuple5(System.Tuple tuple var content = System.Net.Http.Json.JsonContent.Create(tuple, mediaType: null, jsonSerializerSettings); httpRequestMessage.Content = content; handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -7806,7 +7806,7 @@ public string PostTuple6(System.Tuple ha var requestUri = "api/Values/"+id; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Delete, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -8008,7 +8008,7 @@ public System.Collections.Generic.IEnumerable Get(Action han var requestUri = "api/Values/"+id; using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); handleHeaders?.Invoke(httpRequestMessage.Headers); - var responseMessage = client.Send(httpRequestMessage); + var responseMessage = client.SendAsync(httpRequestMessage).Result; try { responseMessage.EnsureSuccessStatusCodeEx(); @@ -8188,7 +8188,7 @@ public System.Collections.Generic.IEnumerable Get2(Action - /// Generate a client function upon ApiDescription for C# - /// - internal sealed class ClientApiFunctionGen - { - readonly WebApiDescription description; - readonly string methodName; - Type returnType; - readonly bool returnTypeIsStream; - readonly bool returnTypeIsDynamicObject; - - /// - /// Decorated by NotNullAttribute - /// - readonly bool returnTypeDecoratedWithNotNullable; - readonly bool returnTypeDecoratedWithMaybeNullable; - CodeMemberMethod clientMethod; - readonly Poco2Client.Poco2CsGen poco2CsGen; - readonly bool forAsync; - readonly bool stringAsString; - readonly string statementOfEnsureSuccessStatusCode; - readonly CodeGenSettings codeGenSettings; - readonly CodeGenOutputs codeGenOutputsSettings; - readonly System.Reflection.ParameterInfo[] parameterInfoArray; - readonly IDictionary> attribueCommentDic; - - ClientApiFunctionGen(WebApiDescription webApiDescription, Poco2Client.Poco2CsGen poco2CsGen, CodeGenSettings codeGenSettings, bool forAsync) - { - this.description = webApiDescription; - this.poco2CsGen = poco2CsGen; - this.codeGenSettings = codeGenSettings; - this.codeGenOutputsSettings = codeGenSettings.ClientApiOutputs; - this.forAsync = forAsync; - this.stringAsString = codeGenOutputsSettings.StringAsString; - statementOfEnsureSuccessStatusCode = codeGenOutputsSettings.UseEnsureSuccessStatusCodeEx ? "EnsureSuccessStatusCodeEx" : "EnsureSuccessStatusCode"; - methodName = webApiDescription.ActionDescriptor.ActionName; - if (methodName.EndsWith("Async", StringComparison.Ordinal)) - { - methodName = methodName.Substring(0, methodName.Length - 5); - } - - Type returnTypeOfProducesResponseType = GetTypeTextOfResponse2xx(description.ActionDescriptor.CustomAttributes); - returnType = returnTypeOfProducesResponseType ?? (webApiDescription.ResponseDescription?.ResponseType ?? webApiDescription.ActionDescriptor.ReturnType); - - returnTypeIsStream = returnType != null && ((returnType.FullName == typeNameOfHttpResponseMessage) - || (returnType.FullName == typeOfIHttpActionResult) - || (returnType.FullName == typeOfIActionResult) - || (returnType.FullName == typeOfActionResult) - || (returnType.FullName.StartsWith("System.Threading.Tasks.Task`1[[Microsoft.AspNetCore.Mvc.IActionResult", StringComparison.Ordinal)) // .net core is not translating Task properly. - || (returnType.FullName.StartsWith("System.Threading.Tasks.Task`1[[Microsoft.AspNetCore.Mvc.IHttpActionResult", StringComparison.Ordinal)) - || (returnType.FullName.StartsWith("System.Threading.Tasks.Task`1[[Microsoft.AspNetCore.Mvc.ActionResult", StringComparison.Ordinal)) - ); - - returnTypeIsDynamicObject = returnType != null && returnType.FullName != null && returnType.FullName.StartsWith("System.Threading.Tasks.Task`1[[System.Object", StringComparison.Ordinal); - - MethodInfo methodInfo = webApiDescription.ActionDescriptor.ControllerDescriptor.ControllerType.GetMethod(webApiDescription.ActionDescriptor.MethodName, webApiDescription.ActionDescriptor.MethodParameterTypes); - if (methodInfo != null) - { - parameterInfoArray = methodInfo.GetParameters(); - if (codeGenOutputsSettings.MaybeNullAttributeOnMethod) - { - returnTypeDecoratedWithMaybeNullable = returnType != null && Attribute.IsDefined(methodInfo.ReturnParameter, typeof(System.Diagnostics.CodeAnalysis.MaybeNullAttribute)); - } - else if (codeGenOutputsSettings.NotNullAttributeOnMethod) - { - returnTypeDecoratedWithNotNullable = returnType != null && Attribute.IsDefined(methodInfo.ReturnParameter, typeof(System.Diagnostics.CodeAnalysis.NotNullAttribute)); - } - } - - AnnotationCommentGenerator annotationCommentGenerator = new AnnotationCommentGenerator(); - attribueCommentDic = annotationCommentGenerator.Get(); - } - - const string typeOfIHttpActionResult = "System.Web.Http.IHttpActionResult"; - const string typeOfIActionResult = "Microsoft.AspNetCore.Mvc.IActionResult"; //for .net core 2.1 - const string typeOfActionResult = "Microsoft.AspNetCore.Mvc.ActionResult"; //for .net core 2.1 - - static readonly Type typeOfChar = typeof(char); - - public static CodeMemberMethod Create(WebApiDescription webApiDescription, Poco2Client.Poco2CsGen poco2CsGen, CodeGenSettings codeGenOutputsSettings, bool forAsync) - { - ClientApiFunctionGen gen = new ClientApiFunctionGen(webApiDescription, poco2CsGen, codeGenOutputsSettings, forAsync); - return gen.CreateApiFunction(); - } - - /// - /// Candidate could be custom POCO, or custom POCO wrapped in IActionResult, ActionResult etc. - /// - /// - void AddCustomPocoTypeForCs(Type candidateType) - { - if (candidateType == null) - { - return; - } - - var assemblyFilename = candidateType.Assembly.GetName().Name; - string controllerAssemblyName = description.ActionDescriptor.ControllerDescriptor.ControllerType.Assembly.GetName().Name; - poco2CsGen.CheckOrAdd(candidateType, controllerAssemblyName != assemblyFilename); - } - - CodeMemberMethod CreateApiFunction() - { - AddCustomPocoTypeForCs(returnType); - //create method - clientMethod = forAsync ? CreateMethodBasicForAsync() : CreateMethodBasic(); + /// + /// Generate a client function upon ApiDescription for C# + /// + internal sealed class ClientApiFunctionGen + { + readonly WebApiDescription description; + readonly string methodName; + Type returnType; + readonly bool returnTypeIsStream; + readonly bool returnTypeIsDynamicObject; + + /// + /// Decorated by NotNullAttribute + /// + readonly bool returnTypeDecoratedWithNotNullable; + readonly bool returnTypeDecoratedWithMaybeNullable; + CodeMemberMethod clientMethod; + readonly Poco2Client.Poco2CsGen poco2CsGen; + readonly bool forAsync; + readonly bool stringAsString; + readonly string statementOfEnsureSuccessStatusCode; + readonly CodeGenSettings codeGenSettings; + readonly CodeGenOutputs codeGenOutputsSettings; + readonly System.Reflection.ParameterInfo[] parameterInfoArray; + readonly IDictionary> attribueCommentDic; + + ClientApiFunctionGen(WebApiDescription webApiDescription, Poco2Client.Poco2CsGen poco2CsGen, CodeGenSettings codeGenSettings, bool forAsync) + { + this.description = webApiDescription; + this.poco2CsGen = poco2CsGen; + this.codeGenSettings = codeGenSettings; + this.codeGenOutputsSettings = codeGenSettings.ClientApiOutputs; + this.forAsync = forAsync; + this.stringAsString = codeGenOutputsSettings.StringAsString; + statementOfEnsureSuccessStatusCode = codeGenOutputsSettings.UseEnsureSuccessStatusCodeEx ? "EnsureSuccessStatusCodeEx" : "EnsureSuccessStatusCode"; + methodName = webApiDescription.ActionDescriptor.ActionName; + if (methodName.EndsWith("Async", StringComparison.Ordinal)) + { + methodName = methodName.Substring(0, methodName.Length - 5); + } + + Type returnTypeOfProducesResponseType = GetTypeTextOfResponse2xx(description.ActionDescriptor.CustomAttributes); + returnType = returnTypeOfProducesResponseType ?? (webApiDescription.ResponseDescription?.ResponseType ?? webApiDescription.ActionDescriptor.ReturnType); + + returnTypeIsStream = returnType != null && ((returnType.FullName == typeNameOfHttpResponseMessage) + || (returnType.FullName == typeOfIHttpActionResult) + || (returnType.FullName == typeOfIActionResult) + || (returnType.FullName == typeOfActionResult) + || (returnType.FullName.StartsWith("System.Threading.Tasks.Task`1[[Microsoft.AspNetCore.Mvc.IActionResult", StringComparison.Ordinal)) // .net core is not translating Task properly. + || (returnType.FullName.StartsWith("System.Threading.Tasks.Task`1[[Microsoft.AspNetCore.Mvc.IHttpActionResult", StringComparison.Ordinal)) + || (returnType.FullName.StartsWith("System.Threading.Tasks.Task`1[[Microsoft.AspNetCore.Mvc.ActionResult", StringComparison.Ordinal)) + ); + + returnTypeIsDynamicObject = returnType != null && returnType.FullName != null && returnType.FullName.StartsWith("System.Threading.Tasks.Task`1[[System.Object", StringComparison.Ordinal); + + MethodInfo methodInfo = webApiDescription.ActionDescriptor.ControllerDescriptor.ControllerType.GetMethod(webApiDescription.ActionDescriptor.MethodName, webApiDescription.ActionDescriptor.MethodParameterTypes); + if (methodInfo != null) + { + parameterInfoArray = methodInfo.GetParameters(); + if (codeGenOutputsSettings.MaybeNullAttributeOnMethod) + { + returnTypeDecoratedWithMaybeNullable = returnType != null && Attribute.IsDefined(methodInfo.ReturnParameter, typeof(System.Diagnostics.CodeAnalysis.MaybeNullAttribute)); + } + else if (codeGenOutputsSettings.NotNullAttributeOnMethod) + { + returnTypeDecoratedWithNotNullable = returnType != null && Attribute.IsDefined(methodInfo.ReturnParameter, typeof(System.Diagnostics.CodeAnalysis.NotNullAttribute)); + } + } + + AnnotationCommentGenerator annotationCommentGenerator = new AnnotationCommentGenerator(); + attribueCommentDic = annotationCommentGenerator.Get(); + } + + const string typeOfIHttpActionResult = "System.Web.Http.IHttpActionResult"; + const string typeOfIActionResult = "Microsoft.AspNetCore.Mvc.IActionResult"; //for .net core 2.1 + const string typeOfActionResult = "Microsoft.AspNetCore.Mvc.ActionResult"; //for .net core 2.1 + + static readonly Type typeOfChar = typeof(char); + + public static CodeMemberMethod Create(WebApiDescription webApiDescription, Poco2Client.Poco2CsGen poco2CsGen, CodeGenSettings codeGenOutputsSettings, bool forAsync) + { + ClientApiFunctionGen gen = new ClientApiFunctionGen(webApiDescription, poco2CsGen, codeGenOutputsSettings, forAsync); + return gen.CreateApiFunction(); + } + + /// + /// Candidate could be custom POCO, or custom POCO wrapped in IActionResult, ActionResult etc. + /// + /// + void AddCustomPocoTypeForCs(Type candidateType) + { + if (candidateType == null) + { + return; + } + + var assemblyFilename = candidateType.Assembly.GetName().Name; + string controllerAssemblyName = description.ActionDescriptor.ControllerDescriptor.ControllerType.Assembly.GetName().Name; + poco2CsGen.CheckOrAdd(candidateType, controllerAssemblyName != assemblyFilename); + } + + CodeMemberMethod CreateApiFunction() + { + AddCustomPocoTypeForCs(returnType); + //create method + clientMethod = forAsync ? CreateMethodBasicForAsync() : CreateMethodBasic(); #if DEBUG - if (methodName == "GetByteWithRange") - { - Console.WriteLine("GetByteWithRange"); - } + if (methodName == "GetByteWithRange") + { + Console.WriteLine("GetByteWithRange"); + } #endif - CreateDocComments(); - if (codeGenOutputsSettings.MaybeNullAttributeOnMethod && returnTypeDecoratedWithMaybeNullable) - { - clientMethod.ReturnTypeCustomAttributes.Add(new CodeAttributeDeclaration("System.Diagnostics.CodeAnalysis.MaybeNullAttribute")); - } - else if (codeGenOutputsSettings.NotNullAttributeOnMethod && returnTypeDecoratedWithNotNullable) - { - clientMethod.ReturnTypeCustomAttributes.Add(new CodeAttributeDeclaration("System.Diagnostics.CodeAnalysis.NotNullAttribute")); - } - - System.Globalization.TextInfo textInfo = new System.Globalization.CultureInfo("en-US", false).TextInfo; - switch (description.HttpMethod) - { - case "GET": - case "DELETE": - RenderGetOrDeleteImplementation(textInfo.ToTitleCase(description.HttpMethod.ToLower(CultureInfo.CurrentCulture))); - break; - case "POST": - case "PUT": - case "PATCH": - RenderPostOrPutImplementation(textInfo.ToTitleCase(description.HttpMethod.ToLower(CultureInfo.CurrentCulture))); - break; - default: - Trace.TraceWarning("This HTTP method {0} is not yet supported", description.HttpMethod); - break; - } - - return clientMethod; - } - - CodeMemberMethod CreateMethodBasic() - { - return new CodeMemberMethod() - { - Attributes = MemberAttributes.Public | MemberAttributes.Final, - Name = methodName, - ReturnType = poco2CsGen.TranslateToClientTypeReference(returnType), - }; - } - - CodeMemberMethod CreateMethodBasicForAsync() - { - return new CodeMemberMethod() - { - Attributes = MemberAttributes.Public | MemberAttributes.Final, - Name = methodName + "Async", - ReturnType = returnType == null ? new CodeTypeReference("async Task") - : new CodeTypeReference("async Task", poco2CsGen.TranslateToClientTypeReference(returnType)), - }; - } - - void CreateDocComments() - { - void CreateDocComment(string elementName, string doc) - { - if (string.IsNullOrWhiteSpace(doc)) - return; - - clientMethod.Comments.Add(new CodeCommentStatement("<" + elementName + ">" + doc + "", true)); - } - - void CreateParamDocComment(string paramName, string doc) - { - List ss = new(); - if (!String.IsNullOrWhiteSpace(doc)) - { - ss.Add(doc); - } - - if (codeGenOutputsSettings.DataAnnotationsToComments) - { - ParameterInfo parameterInfo = parameterInfoArray.SingleOrDefault(p => p?.Name == paramName); - IEnumerable customAttributes = parameterInfo.GetCustomAttributes(); - foreach (Attribute a in customAttributes) - { - if (attribueCommentDic.TryGetValue(a.GetType(), out Func textGenerator)) - { - ss.Add(textGenerator(a)); - } - } - } - - if (ss.Count == 0) - { - return; - } - - if (ss.Count == 1) - { - clientMethod.Comments.Add(new CodeCommentStatement("" + ss[0] + "", true)); - } - else - { - clientMethod.Comments.Add(new CodeCommentStatement("" + ss[0], true)); - for (int i = 1; i < ss.Count; i++) - { - clientMethod.Comments.Add(new CodeCommentStatement(ss[i], true)); - } - - clientMethod.Comments.Add(new CodeCommentStatement("", true)); - } - } - - clientMethod.Comments.Add(new CodeCommentStatement("", true)); - string methodFullName = description.ActionDescriptor.MethodFullName; - if (description.ParameterDescriptions.Length > 0) - { - methodFullName += "(" + description.ParameterDescriptions.Select(d => - { - string typeText; - if (TypeHelper.IsDotNetSimpleType(d.ParameterDescriptor.ParameterType)) - { - typeText = d.ParameterDescriptor.ParameterType.FullName; - } - else if (d.ParameterDescriptor.ParameterType.IsGenericType) - { - typeText = poco2CsGen.TranslateToClientTypeReferenceTextForDocComment(d.ParameterDescriptor.ParameterType); - } - else if (d.ParameterDescriptor.ParameterType.IsArray) - { - typeText = poco2CsGen.TranslateToClientTypeReferenceTextForDocComment(d.ParameterDescriptor.ParameterType); - } - else - { - typeText = d.ParameterDescriptor.ParameterType.FullName; - }; - - return typeText; - }).Aggregate((c, n) => c + "," + n) + ")"; - - Console.WriteLine("FullName: " + methodFullName); - } - - Fonlow.DocComment.docMember methodComments = null; - if (WebApiDocSingleton.Instance.Lookup != null) - { - methodComments = WebApiDocSingleton.Instance.Lookup.GetMember("M:" + methodFullName); - string[] noIndent = Fonlow.DocComment.StringFunctions.TrimIndentedMultiLineTextToArray(Fonlow.DocComment.DocCommentHelper.GetSummary(methodComments)); - if (noIndent != null) - { - foreach (string item in noIndent) - { - clientMethod.Comments.Add(new CodeCommentStatement(item, true)); - } - } - } - - clientMethod.Comments.Add(new CodeCommentStatement(description.HttpMethod + " " + description.RelativePath, true)); - string[] methodAttributesAsComments = WebApiClientGenCore.Abstract.AspNetAttributesHelper.CreateDocCommentBasedOnAttributes(description.ActionDescriptor.CustomAttributes); - if (methodAttributesAsComments.Length > 0) - { - foreach (string item in methodAttributesAsComments) - { - clientMethod.Comments.Add(new CodeCommentStatement(item, true)); - } - } - - clientMethod.Comments.Add(new CodeCommentStatement("", true)); - foreach (ParameterDescription pd in description.ParameterDescriptions) - { - string parameterComment = Fonlow.DocComment.DocCommentHelper.GetParameterComment(methodComments, pd.Name); - CreateParamDocComment(pd.Name, parameterComment); - } - - string returnComment = Fonlow.DocComment.DocCommentHelper.GetReturnComment(methodComments); - if (returnComment != null) - { - CreateDocComment("returns", returnComment); - } - } - - /// - /// - /// - /// GET, DELETE, POST, PUT - void RenderGetOrDeleteImplementation(string httpMethod) - { - CodeParameterDeclarationExpression[] parameters = description.ParameterDescriptions.Where(p => p.ParameterDescriptor.ParameterBinder == ParameterBinder.FromUri - || p.ParameterDescriptor.ParameterBinder == ParameterBinder.FromQuery || p.ParameterDescriptor.ParameterBinder == ParameterBinder.None) - .Select(d => - { - AddCustomPocoTypeForCs(d.ParameterDescriptor.ParameterType); - CodeParameterDeclarationExpression exp = new CodeParameterDeclarationExpression(poco2CsGen.TranslateToClientTypeReference(d.ParameterDescriptor.ParameterType), d.Name); - exp.UserData.Add(Fonlow.TypeScriptCodeDom.UserDataKeys.ParameterDescriptor, d.ParameterDescriptor); - return exp; - }).ToArray(); - - clientMethod.Parameters.AddRange(parameters); - - if (codeGenOutputsSettings.CancellationTokenEnabled) - { - clientMethod.Parameters.Add(new CodeParameterDeclarationExpression("System.Threading.CancellationToken", "cancellationToken")); - } - - if (codeGenOutputsSettings.HandleHttpRequestHeaders) - { - clientMethod.Parameters.Add(new CodeParameterDeclarationExpression("Action", "handleHeaders = null")); - } - - string jsUriQuery = UriQueryHelper.CreateUriQuery(description.RelativePath, description.ParameterDescriptions); - string uriText = string.IsNullOrWhiteSpace(jsUriQuery) ? $"\"{description.RelativePath}\"" : RemoveTrialEmptyString($"\"{jsUriQuery}\""); - - - clientMethod.Statements.Add(new CodeVariableDeclarationStatement( - new CodeTypeReference("var"), "requestUri", - new CodeSnippetExpression(uriText))); - - clientMethod.Statements.Add(new CodeSnippetStatement(ThreeTabs + $"using var httpRequestMessage = new HttpRequestMessage(HttpMethod.{httpMethod}, requestUri);")); - - if (codeGenOutputsSettings.HandleHttpRequestHeaders) - { - clientMethod.Statements.Add(new CodeSnippetStatement("\t\t\thandleHeaders?.Invoke(httpRequestMessage.Headers);")); - } - - AddResponseMessageSendAsync(clientMethod); - - CodeVariableReferenceExpression resultReference = new CodeVariableReferenceExpression("responseMessage"); - - //Statement: result.EnsureSuccessStatusCode(); - if (returnTypeIsStream) - { - clientMethod.Statements.Add(new CodeMethodInvokeExpression(resultReference, statementOfEnsureSuccessStatusCode)); - - if (returnType != null) - { - AddReturnStatement(clientMethod.Statements); - } - } - else - { - CodeTryCatchFinallyStatement try1 = new CodeTryCatchFinallyStatement(); - try1.TryStatements.Add(new CodeMethodInvokeExpression(resultReference, statementOfEnsureSuccessStatusCode)); - clientMethod.Statements.Add(try1); - - //Statement: return something; - if (returnType != null) - { - AddReturnStatement(try1.TryStatements); - } - - try1.FinallyStatements.Add(new CodeMethodInvokeExpression(resultReference, "Dispose")); - } - } - - void RenderPostOrPutImplementation(string httpMethod) - { - //Create function parameters in prototype - CodeParameterDeclarationExpression[] parameters = description.ParameterDescriptions.Where(p => p.ParameterDescriptor.ParameterBinder == ParameterBinder.FromUri - || p.ParameterDescriptor.ParameterBinder == ParameterBinder.FromQuery || p.ParameterDescriptor.ParameterBinder == ParameterBinder.FromBody - || p.ParameterDescriptor.ParameterBinder == ParameterBinder.None).Select(d => - { - AddCustomPocoTypeForCs(d.ParameterDescriptor.ParameterType); - CodeParameterDeclarationExpression exp = new CodeParameterDeclarationExpression(poco2CsGen.TranslateToClientTypeReference(d.ParameterDescriptor.ParameterType), d.Name); - exp.UserData.Add(Fonlow.TypeScriptCodeDom.UserDataKeys.ParameterDescriptor, d.ParameterDescriptor); - return exp; - } - ).ToArray(); - clientMethod.Parameters.AddRange(parameters); - - if (codeGenOutputsSettings.CancellationTokenEnabled) - { - clientMethod.Parameters.Add(new CodeParameterDeclarationExpression("System.Threading.CancellationToken", "cancellationToken")); - } - - if (codeGenOutputsSettings.HandleHttpRequestHeaders) - { - clientMethod.Parameters.Add(new CodeParameterDeclarationExpression("Action", "handleHeaders = null")); - } - - ParameterDescription[] fromBodyParameterDescriptions = description.ParameterDescriptions.Where(d => d.ParameterDescriptor.ParameterBinder == ParameterBinder.FromBody - || (TypeHelper.IsComplexType(d.ParameterDescriptor.ParameterType) && (!(d.ParameterDescriptor.ParameterBinder == ParameterBinder.FromUri) || (d.ParameterDescriptor.ParameterBinder == ParameterBinder.None)))).ToArray(); - if (fromBodyParameterDescriptions.Length > 1) - { - throw new CodeGenException("Bad Api Definition") - { - Description = String.Format("This API function {0} has more than 1 FromBody bindings in parameters", description.ActionDescriptor.ActionName) - }; - } - - ParameterDescription singleFromBodyParameterDescription = fromBodyParameterDescriptions.FirstOrDefault(); - bool hasBody = singleFromBodyParameterDescription != null; - - void AddRequestUriWithQueryAssignmentStatement() - { - - string jsUriQuery = UriQueryHelper.CreateUriQuery(description.RelativePath, description.ParameterDescriptions); - string uriText = jsUriQuery == null ? $"\"{description.RelativePath}\"" : RemoveTrialEmptyString($"\"{jsUriQuery}\""); - - clientMethod.Statements.Add(new CodeVariableDeclarationStatement( - new CodeTypeReference("var"), "requestUri", - new CodeSnippetExpression(uriText))); - } - - AddRequestUriWithQueryAssignmentStatement(); - - clientMethod.Statements.Add(new CodeSnippetStatement( - ThreeTabs + $"using var httpRequestMessage = new HttpRequestMessage(HttpMethod.{httpMethod}, requestUri);")); - - if (hasBody) - { - if (codeGenOutputsSettings.UseSystemTextJson) - { - clientMethod.Statements.Add(new CodeSnippetStatement(ThreeTabs + $"var content = System.Net.Http.Json.JsonContent.Create({singleFromBodyParameterDescription.ParameterDescriptor.ParameterName}, mediaType: null, jsonSerializerSettings);")); - } - else - { - clientMethod.Statements.Add(new CodeSnippetStatement( - $"\t\t\tusing var requestWriter = new System.IO.StringWriter();{Environment.NewLine}\t\t\tvar requestSerializer = JsonSerializer.Create(jsonSerializerSettings);" - )); - clientMethod.Statements.Add(new CodeMethodInvokeExpression(new CodeSnippetExpression("requestSerializer"), "Serialize", - new CodeSnippetExpression("requestWriter"), - new CodeSnippetExpression(singleFromBodyParameterDescription.ParameterDescriptor.ParameterName))); - - - clientMethod.Statements.Add(new CodeSnippetStatement( - "\t\t\tvar content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, \"application/json\");" - )); - } - - clientMethod.Statements.Add(new CodeSnippetStatement("\t\t\thttpRequestMessage.Content = content;")); - if (codeGenOutputsSettings.HandleHttpRequestHeaders) - { - clientMethod.Statements.Add(new CodeSnippetStatement("\t\t\thandleHeaders?.Invoke(httpRequestMessage.Headers);")); - } - } - - AddResponseMessageSendAsync(clientMethod); - - CodeVariableReferenceExpression resultReference = new CodeVariableReferenceExpression("responseMessage"); - - if (returnTypeIsStream) - { - clientMethod.Statements.Add(new CodeMethodInvokeExpression(resultReference, statementOfEnsureSuccessStatusCode)); - - //Statement: return something; - if (returnType != null) - { - AddReturnStatement(clientMethod.Statements); - } - } - else - { - CodeTryCatchFinallyStatement try1 = new CodeTryCatchFinallyStatement(); - clientMethod.Statements.Add(try1); - try1.TryStatements.Add(new CodeMethodInvokeExpression(resultReference, statementOfEnsureSuccessStatusCode)); - - //Statement: return something; - if (returnType != null) - { - AddReturnStatement(try1.TryStatements); - } - - try1.FinallyStatements.Add(new CodeMethodInvokeExpression(resultReference, "Dispose")); - } - - if (singleFromBodyParameterDescription != null && !codeGenOutputsSettings.UseSystemTextJson) - { - //Add3TEndBacket(clientMethod); - } - - } - - static string ThreeTabs => "\t\t\t"; - - void AddResponseMessageSendAsync(CodeMemberMethod method) - { - string cancellationToken = codeGenOutputsSettings.CancellationTokenEnabled ? ", cancellationToken" : String.Empty; - method.Statements.Add(new CodeVariableDeclarationStatement( - new CodeTypeReference("var"), "responseMessage", forAsync ? new CodeSnippetExpression($"await client.SendAsync(httpRequestMessage{cancellationToken})") : new CodeSnippetExpression($"client.Send(httpRequestMessage{cancellationToken})"))); - } - - static void AddNewtonSoftJsonTextReader(CodeStatementCollection statementCollection) - { - statementCollection.Add(new CodeSnippetStatement("\t\t\t\tusing JsonReader jsonReader = new JsonTextReader(new System.IO.StreamReader(stream));")); - } - - void AddNewtonSoftJsonSerializerDeserialize(CodeStatementCollection statementCollection) - { - statementCollection.Add(new CodeSnippetStatement($"\t\t\t\treturn serializer.Deserialize<{poco2CsGen.TranslateTypeToCSharp(returnType)}>(jsonReader);")); - } - - static void AddNewtonSoftJsonSerializer(CodeStatementCollection statementCollection) - { - statementCollection.Add(new CodeVariableDeclarationStatement( - new CodeTypeReference("var"), "serializer", new CodeSnippetExpression("JsonSerializer.Create(jsonSerializerSettings)"))); - } - - void DeserializeContentStream(CodeStatementCollection statementCollection) - { - statementCollection.Add(new CodeMethodReturnStatement(new CodeMethodInvokeExpression( - new CodeMethodReferenceExpression( - new CodeVariableReferenceExpression("JsonSerializer"), "Deserialize", poco2CsGen.TranslateToClientTypeReference(returnType)), - new CodeSnippetExpression("stream"), new CodeSnippetExpression("jsonSerializerSettings")))); - } - - void AddResponseMessageRead(CodeStatementCollection statementCollection) - { - if (TypeHelper.IsStringType(returnType) || returnType.IsClass || TypeHelper.IsNullablePrimitive(returnType)) //ASP.NET Core return null as empty body with status code 204, whether to produce JSON or plain text. - { - statementCollection.Add(new CodeSnippetStatement("\t\t\t\tif (responseMessage.StatusCode == System.Net.HttpStatusCode.NoContent) { return null; }")); - } - - statementCollection.Add(new CodeSnippetStatement(forAsync - ? "\t\t\t\tvar stream = await responseMessage.Content.ReadAsStreamAsync();" - : "\t\t\t\tvar stream = responseMessage.Content.ReadAsStream();")); - } - - const string typeNameOfHttpResponseMessage = "System.Net.Http.HttpResponseMessage"; - - void AddReturnStatement(CodeStatementCollection statementCollection) - { - if (returnTypeIsStream) - { - statementCollection.Add(new CodeMethodReturnStatement(new CodeSnippetExpression("responseMessage"))); - return; - } - else if (returnTypeIsDynamicObject) // .NET Core ApiExplorer could get return type out of Task<> in most cases, however, not for dynamic and anynomous, while .NET Framework ApiExplorer is fine. - { - AddResponseMessageRead(statementCollection); - if (codeGenOutputsSettings.UseSystemTextJson) - { - DeserializeContentStream(statementCollection); - } - else - { - AddNewtonSoftJsonTextReader(statementCollection); - AddNewtonSoftJsonSerializer(statementCollection); - statementCollection.Add(new CodeSnippetStatement($"\t\t\t\treturn serializer.Deserialize<{poco2CsGen.TranslateTypeToCSharp(returnType)}>(jsonReader);")); - } - - return; - } - else if (returnType.IsGenericType) - { - Type genericTypeDefinition = returnType.GetGenericTypeDefinition(); - if (genericTypeDefinition == typeof(System.Threading.Tasks.Task<>)) - { - statementCollection.Add(new CodeMethodReturnStatement(new CodeSnippetExpression("responseMessage"))); - Trace.TraceWarning("There could be something to improve: " + returnType.GenericTypeArguments[0].ToString()); - return; - } - } - - AddResponseMessageRead(statementCollection); - - if (returnType != null && TypeHelper.IsStringType(returnType)) - { - if (this.stringAsString) - { - statementCollection.Add(new CodeSnippetStatement("\t\t\t\tusing System.IO.StreamReader streamReader = new System.IO.StreamReader(stream);")); - statementCollection.Add(new CodeMethodReturnStatement(new CodeSnippetExpression("streamReader.ReadToEnd();"))); - } - else - { - if (codeGenOutputsSettings.UseSystemTextJson) - { - statementCollection.Add(new CodeMethodReturnStatement(new CodeMethodInvokeExpression( - new CodeMethodReferenceExpression( - new CodeVariableReferenceExpression("JsonSerializer"), "Deserialize", new CodeTypeReference(typeof(System.String))), - new CodeSnippetExpression("contentString"), - new CodeSnippetExpression("jsonSerializerSettings")))); - } - else - { - AddNewtonSoftJsonTextReader(statementCollection); - statementCollection.Add(new CodeMethodReturnStatement(new CodeSnippetExpression("jsonReader.ReadAsString()"))); - } - } - } - else if (returnType == typeOfChar) - { - if (codeGenOutputsSettings.UseSystemTextJson) - { - DeserializeContentStream(statementCollection); - } - else - { - AddNewtonSoftJsonTextReader(statementCollection); - AddNewtonSoftJsonSerializer(statementCollection); - statementCollection.Add(new CodeMethodReturnStatement(new CodeSnippetExpression("serializer.Deserialize(jsonReader)"))); - } - } - else if (returnType.IsPrimitive) - { - if (codeGenOutputsSettings.UseSystemTextJson) - { - DeserializeContentStream(statementCollection); - } - else - { - AddNewtonSoftJsonTextReader(statementCollection); - statementCollection.Add(new CodeMethodReturnStatement(new CodeSnippetExpression(String.Format("{0}.Parse(jsonReader.ReadAsString())", returnType.FullName)))); - } - } - else if (returnType.IsGenericType || TypeHelper.IsComplexType(returnType) || returnType.IsEnum) - { - if (codeGenOutputsSettings.UseSystemTextJson) - { - DeserializeContentStream(statementCollection); - } - else - { - AddNewtonSoftJsonTextReader(statementCollection); - //Add4TStartBacket(statementCollection); - AddNewtonSoftJsonSerializer(statementCollection); - AddNewtonSoftJsonSerializerDeserialize(statementCollection); - //Add4TEndBacket(statementCollection); - } - } - else - { - Trace.TraceWarning("This type is not yet supported: {0}", returnType.FullName); - } - } - - private static string RemoveTrialEmptyString(string s) - { - int p = s.IndexOf("+\"\"", StringComparison.Ordinal); - if (p >= 0) - { - return s.Remove(p, 3); - } - - int p2 = s.IndexOf("))\"", StringComparison.Ordinal); - if (p2 >= 0) - { - return s.Remove(p2 + 2, 1); - } - - return s; - } - - /// - /// If the API function use ProducesResponseTypeAttribute and 200-202 to define the return type, then get the return type as full type name, - /// Null if no such definition . - /// - /// - /// - static Type GetTypeTextOfResponse2xx(Attribute[] customAttributes) - { - foreach (Attribute c in customAttributes) - { - Microsoft.AspNetCore.Mvc.ProducesResponseTypeAttribute responseAttribute = c as Microsoft.AspNetCore.Mvc.ProducesResponseTypeAttribute; - if (responseAttribute != null) - { - if (responseAttribute.StatusCode >= 200 && responseAttribute.StatusCode <= 202) - { - return responseAttribute.Type; - } - } - } - - return null; - } - - - } + CreateDocComments(); + if (codeGenOutputsSettings.MaybeNullAttributeOnMethod && returnTypeDecoratedWithMaybeNullable) + { + clientMethod.ReturnTypeCustomAttributes.Add(new CodeAttributeDeclaration("System.Diagnostics.CodeAnalysis.MaybeNullAttribute")); + } + else if (codeGenOutputsSettings.NotNullAttributeOnMethod && returnTypeDecoratedWithNotNullable) + { + clientMethod.ReturnTypeCustomAttributes.Add(new CodeAttributeDeclaration("System.Diagnostics.CodeAnalysis.NotNullAttribute")); + } + + System.Globalization.TextInfo textInfo = new System.Globalization.CultureInfo("en-US", false).TextInfo; + switch (description.HttpMethod) + { + case "GET": + case "DELETE": + RenderGetOrDeleteImplementation(textInfo.ToTitleCase(description.HttpMethod.ToLower(CultureInfo.CurrentCulture))); + break; + case "POST": + case "PUT": + case "PATCH": + RenderPostOrPutImplementation(textInfo.ToTitleCase(description.HttpMethod.ToLower(CultureInfo.CurrentCulture))); + break; + default: + Trace.TraceWarning("This HTTP method {0} is not yet supported", description.HttpMethod); + break; + } + + return clientMethod; + } + + CodeMemberMethod CreateMethodBasic() + { + return new CodeMemberMethod() + { + Attributes = MemberAttributes.Public | MemberAttributes.Final, + Name = methodName, + ReturnType = poco2CsGen.TranslateToClientTypeReference(returnType), + }; + } + + CodeMemberMethod CreateMethodBasicForAsync() + { + return new CodeMemberMethod() + { + Attributes = MemberAttributes.Public | MemberAttributes.Final, + Name = methodName + "Async", + ReturnType = returnType == null ? new CodeTypeReference("async Task") + : new CodeTypeReference("async Task", poco2CsGen.TranslateToClientTypeReference(returnType)), + }; + } + + void CreateDocComments() + { + void CreateDocComment(string elementName, string doc) + { + if (string.IsNullOrWhiteSpace(doc)) + return; + + clientMethod.Comments.Add(new CodeCommentStatement("<" + elementName + ">" + doc + "", true)); + } + + void CreateParamDocComment(string paramName, string doc) + { + List ss = new(); + if (!String.IsNullOrWhiteSpace(doc)) + { + ss.Add(doc); + } + + if (codeGenOutputsSettings.DataAnnotationsToComments) + { + ParameterInfo parameterInfo = parameterInfoArray.SingleOrDefault(p => p?.Name == paramName); + IEnumerable customAttributes = parameterInfo.GetCustomAttributes(); + foreach (Attribute a in customAttributes) + { + if (attribueCommentDic.TryGetValue(a.GetType(), out Func textGenerator)) + { + ss.Add(textGenerator(a)); + } + } + } + + if (ss.Count == 0) + { + return; + } + + if (ss.Count == 1) + { + clientMethod.Comments.Add(new CodeCommentStatement("" + ss[0] + "", true)); + } + else + { + clientMethod.Comments.Add(new CodeCommentStatement("" + ss[0], true)); + for (int i = 1; i < ss.Count; i++) + { + clientMethod.Comments.Add(new CodeCommentStatement(ss[i], true)); + } + + clientMethod.Comments.Add(new CodeCommentStatement("", true)); + } + } + + clientMethod.Comments.Add(new CodeCommentStatement("", true)); + string methodFullName = description.ActionDescriptor.MethodFullName; + if (description.ParameterDescriptions.Length > 0) + { + methodFullName += "(" + description.ParameterDescriptions.Select(d => + { + string typeText; + if (TypeHelper.IsDotNetSimpleType(d.ParameterDescriptor.ParameterType)) + { + typeText = d.ParameterDescriptor.ParameterType.FullName; + } + else if (d.ParameterDescriptor.ParameterType.IsGenericType) + { + typeText = poco2CsGen.TranslateToClientTypeReferenceTextForDocComment(d.ParameterDescriptor.ParameterType); + } + else if (d.ParameterDescriptor.ParameterType.IsArray) + { + typeText = poco2CsGen.TranslateToClientTypeReferenceTextForDocComment(d.ParameterDescriptor.ParameterType); + } + else + { + typeText = d.ParameterDescriptor.ParameterType.FullName; + }; + + return typeText; + }).Aggregate((c, n) => c + "," + n) + ")"; + + Console.WriteLine("FullName: " + methodFullName); + } + + Fonlow.DocComment.docMember methodComments = null; + if (WebApiDocSingleton.Instance.Lookup != null) + { + methodComments = WebApiDocSingleton.Instance.Lookup.GetMember("M:" + methodFullName); + string[] noIndent = Fonlow.DocComment.StringFunctions.TrimIndentedMultiLineTextToArray(Fonlow.DocComment.DocCommentHelper.GetSummary(methodComments)); + if (noIndent != null) + { + foreach (string item in noIndent) + { + clientMethod.Comments.Add(new CodeCommentStatement(item, true)); + } + } + } + + clientMethod.Comments.Add(new CodeCommentStatement(description.HttpMethod + " " + description.RelativePath, true)); + string[] methodAttributesAsComments = WebApiClientGenCore.Abstract.AspNetAttributesHelper.CreateDocCommentBasedOnAttributes(description.ActionDescriptor.CustomAttributes); + if (methodAttributesAsComments.Length > 0) + { + foreach (string item in methodAttributesAsComments) + { + clientMethod.Comments.Add(new CodeCommentStatement(item, true)); + } + } + + clientMethod.Comments.Add(new CodeCommentStatement("", true)); + foreach (ParameterDescription pd in description.ParameterDescriptions) + { + string parameterComment = Fonlow.DocComment.DocCommentHelper.GetParameterComment(methodComments, pd.Name); + CreateParamDocComment(pd.Name, parameterComment); + } + + string returnComment = Fonlow.DocComment.DocCommentHelper.GetReturnComment(methodComments); + if (returnComment != null) + { + CreateDocComment("returns", returnComment); + } + } + + /// + /// + /// + /// GET, DELETE, POST, PUT + void RenderGetOrDeleteImplementation(string httpMethod) + { + CodeParameterDeclarationExpression[] parameters = description.ParameterDescriptions.Where(p => p.ParameterDescriptor.ParameterBinder == ParameterBinder.FromUri + || p.ParameterDescriptor.ParameterBinder == ParameterBinder.FromQuery || p.ParameterDescriptor.ParameterBinder == ParameterBinder.None) + .Select(d => + { + AddCustomPocoTypeForCs(d.ParameterDescriptor.ParameterType); + CodeParameterDeclarationExpression exp = new CodeParameterDeclarationExpression(poco2CsGen.TranslateToClientTypeReference(d.ParameterDescriptor.ParameterType), d.Name); + exp.UserData.Add(Fonlow.TypeScriptCodeDom.UserDataKeys.ParameterDescriptor, d.ParameterDescriptor); + return exp; + }).ToArray(); + + clientMethod.Parameters.AddRange(parameters); + + if (codeGenOutputsSettings.CancellationTokenEnabled) + { + clientMethod.Parameters.Add(new CodeParameterDeclarationExpression("System.Threading.CancellationToken", "cancellationToken")); + } + + if (codeGenOutputsSettings.HandleHttpRequestHeaders) + { + clientMethod.Parameters.Add(new CodeParameterDeclarationExpression("Action", "handleHeaders = null")); + } + + string jsUriQuery = UriQueryHelper.CreateUriQuery(description.RelativePath, description.ParameterDescriptions); + string uriText = string.IsNullOrWhiteSpace(jsUriQuery) ? $"\"{description.RelativePath}\"" : RemoveTrialEmptyString($"\"{jsUriQuery}\""); + + + clientMethod.Statements.Add(new CodeVariableDeclarationStatement( + new CodeTypeReference("var"), "requestUri", + new CodeSnippetExpression(uriText))); + + clientMethod.Statements.Add(new CodeSnippetStatement(ThreeTabs + $"using var httpRequestMessage = new HttpRequestMessage(HttpMethod.{httpMethod}, requestUri);")); + + if (codeGenOutputsSettings.HandleHttpRequestHeaders) + { + clientMethod.Statements.Add(new CodeSnippetStatement("\t\t\thandleHeaders?.Invoke(httpRequestMessage.Headers);")); + } + + AddResponseMessageSendAsync(clientMethod); + + CodeVariableReferenceExpression resultReference = new CodeVariableReferenceExpression("responseMessage"); + + //Statement: result.EnsureSuccessStatusCode(); + if (returnTypeIsStream) + { + clientMethod.Statements.Add(new CodeMethodInvokeExpression(resultReference, statementOfEnsureSuccessStatusCode)); + + if (returnType != null) + { + AddReturnStatement(clientMethod.Statements); + } + } + else + { + CodeTryCatchFinallyStatement try1 = new CodeTryCatchFinallyStatement(); + try1.TryStatements.Add(new CodeMethodInvokeExpression(resultReference, statementOfEnsureSuccessStatusCode)); + clientMethod.Statements.Add(try1); + + //Statement: return something; + if (returnType != null) + { + AddReturnStatement(try1.TryStatements); + } + + try1.FinallyStatements.Add(new CodeMethodInvokeExpression(resultReference, "Dispose")); + } + } + + void RenderPostOrPutImplementation(string httpMethod) + { + //Create function parameters in prototype + CodeParameterDeclarationExpression[] parameters = description.ParameterDescriptions.Where(p => p.ParameterDescriptor.ParameterBinder == ParameterBinder.FromUri + || p.ParameterDescriptor.ParameterBinder == ParameterBinder.FromQuery || p.ParameterDescriptor.ParameterBinder == ParameterBinder.FromBody + || p.ParameterDescriptor.ParameterBinder == ParameterBinder.None).Select(d => + { + AddCustomPocoTypeForCs(d.ParameterDescriptor.ParameterType); + CodeParameterDeclarationExpression exp = new CodeParameterDeclarationExpression(poco2CsGen.TranslateToClientTypeReference(d.ParameterDescriptor.ParameterType), d.Name); + exp.UserData.Add(Fonlow.TypeScriptCodeDom.UserDataKeys.ParameterDescriptor, d.ParameterDescriptor); + return exp; + } + ).ToArray(); + clientMethod.Parameters.AddRange(parameters); + + if (codeGenOutputsSettings.CancellationTokenEnabled) + { + clientMethod.Parameters.Add(new CodeParameterDeclarationExpression("System.Threading.CancellationToken", "cancellationToken")); + } + + if (codeGenOutputsSettings.HandleHttpRequestHeaders) + { + clientMethod.Parameters.Add(new CodeParameterDeclarationExpression("Action", "handleHeaders = null")); + } + + ParameterDescription[] fromBodyParameterDescriptions = description.ParameterDescriptions.Where(d => d.ParameterDescriptor.ParameterBinder == ParameterBinder.FromBody + || (TypeHelper.IsComplexType(d.ParameterDescriptor.ParameterType) && (!(d.ParameterDescriptor.ParameterBinder == ParameterBinder.FromUri) || (d.ParameterDescriptor.ParameterBinder == ParameterBinder.None)))).ToArray(); + if (fromBodyParameterDescriptions.Length > 1) + { + throw new CodeGenException("Bad Api Definition") + { + Description = String.Format("This API function {0} has more than 1 FromBody bindings in parameters", description.ActionDescriptor.ActionName) + }; + } + + ParameterDescription singleFromBodyParameterDescription = fromBodyParameterDescriptions.FirstOrDefault(); + bool hasBody = singleFromBodyParameterDescription != null; + + void AddRequestUriWithQueryAssignmentStatement() + { + + string jsUriQuery = UriQueryHelper.CreateUriQuery(description.RelativePath, description.ParameterDescriptions); + string uriText = jsUriQuery == null ? $"\"{description.RelativePath}\"" : RemoveTrialEmptyString($"\"{jsUriQuery}\""); + + clientMethod.Statements.Add(new CodeVariableDeclarationStatement( + new CodeTypeReference("var"), "requestUri", + new CodeSnippetExpression(uriText))); + } + + AddRequestUriWithQueryAssignmentStatement(); + + clientMethod.Statements.Add(new CodeSnippetStatement( + ThreeTabs + $"using var httpRequestMessage = new HttpRequestMessage(HttpMethod.{httpMethod}, requestUri);")); + + if (hasBody) + { + if (codeGenOutputsSettings.UseSystemTextJson) + { + clientMethod.Statements.Add(new CodeSnippetStatement(ThreeTabs + $"var content = System.Net.Http.Json.JsonContent.Create({singleFromBodyParameterDescription.ParameterDescriptor.ParameterName}, mediaType: null, jsonSerializerSettings);")); + } + else + { + clientMethod.Statements.Add(new CodeSnippetStatement( + $"\t\t\tusing var requestWriter = new System.IO.StringWriter();{Environment.NewLine}\t\t\tvar requestSerializer = JsonSerializer.Create(jsonSerializerSettings);" + )); + clientMethod.Statements.Add(new CodeMethodInvokeExpression(new CodeSnippetExpression("requestSerializer"), "Serialize", + new CodeSnippetExpression("requestWriter"), + new CodeSnippetExpression(singleFromBodyParameterDescription.ParameterDescriptor.ParameterName))); + + + clientMethod.Statements.Add(new CodeSnippetStatement( + "\t\t\tvar content = new StringContent(requestWriter.ToString(), System.Text.Encoding.UTF8, \"application/json\");" + )); + } + + clientMethod.Statements.Add(new CodeSnippetStatement("\t\t\thttpRequestMessage.Content = content;")); + if (codeGenOutputsSettings.HandleHttpRequestHeaders) + { + clientMethod.Statements.Add(new CodeSnippetStatement("\t\t\thandleHeaders?.Invoke(httpRequestMessage.Headers);")); + } + } + + AddResponseMessageSendAsync(clientMethod); + + CodeVariableReferenceExpression resultReference = new CodeVariableReferenceExpression("responseMessage"); + + if (returnTypeIsStream) + { + clientMethod.Statements.Add(new CodeMethodInvokeExpression(resultReference, statementOfEnsureSuccessStatusCode)); + + //Statement: return something; + if (returnType != null) + { + AddReturnStatement(clientMethod.Statements); + } + } + else + { + CodeTryCatchFinallyStatement try1 = new CodeTryCatchFinallyStatement(); + clientMethod.Statements.Add(try1); + try1.TryStatements.Add(new CodeMethodInvokeExpression(resultReference, statementOfEnsureSuccessStatusCode)); + + //Statement: return something; + if (returnType != null) + { + AddReturnStatement(try1.TryStatements); + } + + try1.FinallyStatements.Add(new CodeMethodInvokeExpression(resultReference, "Dispose")); + } + + if (singleFromBodyParameterDescription != null && !codeGenOutputsSettings.UseSystemTextJson) + { + //Add3TEndBacket(clientMethod); + } + + } + + static string ThreeTabs => "\t\t\t"; + + void AddResponseMessageSendAsync(CodeMemberMethod method) + { + string cancellationToken = codeGenOutputsSettings.CancellationTokenEnabled ? ", cancellationToken" : String.Empty; + method.Statements.Add(new CodeVariableDeclarationStatement( + new CodeTypeReference("var"), "responseMessage", forAsync ? new CodeSnippetExpression($"await client.SendAsync(httpRequestMessage{cancellationToken})") : new CodeSnippetExpression($"client.SendAsync(httpRequestMessage{cancellationToken}).Result"))); // reverse to the old way because of https://github.com/dotnet/runtime/issues/104716 + } + + static void AddNewtonSoftJsonTextReader(CodeStatementCollection statementCollection) + { + statementCollection.Add(new CodeSnippetStatement("\t\t\t\tusing JsonReader jsonReader = new JsonTextReader(new System.IO.StreamReader(stream));")); + } + + void AddNewtonSoftJsonSerializerDeserialize(CodeStatementCollection statementCollection) + { + statementCollection.Add(new CodeSnippetStatement($"\t\t\t\treturn serializer.Deserialize<{poco2CsGen.TranslateTypeToCSharp(returnType)}>(jsonReader);")); + } + + static void AddNewtonSoftJsonSerializer(CodeStatementCollection statementCollection) + { + statementCollection.Add(new CodeVariableDeclarationStatement( + new CodeTypeReference("var"), "serializer", new CodeSnippetExpression("JsonSerializer.Create(jsonSerializerSettings)"))); + } + + void DeserializeContentStream(CodeStatementCollection statementCollection) + { + statementCollection.Add(new CodeMethodReturnStatement(new CodeMethodInvokeExpression( + new CodeMethodReferenceExpression( + new CodeVariableReferenceExpression("JsonSerializer"), "Deserialize", poco2CsGen.TranslateToClientTypeReference(returnType)), + new CodeSnippetExpression("stream"), new CodeSnippetExpression("jsonSerializerSettings")))); + } + + void AddResponseMessageRead(CodeStatementCollection statementCollection) + { + if (TypeHelper.IsStringType(returnType) || returnType.IsClass || TypeHelper.IsNullablePrimitive(returnType)) //ASP.NET Core return null as empty body with status code 204, whether to produce JSON or plain text. + { + statementCollection.Add(new CodeSnippetStatement("\t\t\t\tif (responseMessage.StatusCode == System.Net.HttpStatusCode.NoContent) { return null; }")); + } + + statementCollection.Add(new CodeSnippetStatement(forAsync + ? "\t\t\t\tvar stream = await responseMessage.Content.ReadAsStreamAsync();" + : "\t\t\t\tvar stream = responseMessage.Content.ReadAsStream();")); + } + + const string typeNameOfHttpResponseMessage = "System.Net.Http.HttpResponseMessage"; + + void AddReturnStatement(CodeStatementCollection statementCollection) + { + if (returnTypeIsStream) + { + statementCollection.Add(new CodeMethodReturnStatement(new CodeSnippetExpression("responseMessage"))); + return; + } + else if (returnTypeIsDynamicObject) // .NET Core ApiExplorer could get return type out of Task<> in most cases, however, not for dynamic and anynomous, while .NET Framework ApiExplorer is fine. + { + AddResponseMessageRead(statementCollection); + if (codeGenOutputsSettings.UseSystemTextJson) + { + DeserializeContentStream(statementCollection); + } + else + { + AddNewtonSoftJsonTextReader(statementCollection); + AddNewtonSoftJsonSerializer(statementCollection); + statementCollection.Add(new CodeSnippetStatement($"\t\t\t\treturn serializer.Deserialize<{poco2CsGen.TranslateTypeToCSharp(returnType)}>(jsonReader);")); + } + + return; + } + else if (returnType.IsGenericType) + { + Type genericTypeDefinition = returnType.GetGenericTypeDefinition(); + if (genericTypeDefinition == typeof(System.Threading.Tasks.Task<>)) + { + statementCollection.Add(new CodeMethodReturnStatement(new CodeSnippetExpression("responseMessage"))); + Trace.TraceWarning("There could be something to improve: " + returnType.GenericTypeArguments[0].ToString()); + return; + } + } + + AddResponseMessageRead(statementCollection); + + if (returnType != null && TypeHelper.IsStringType(returnType)) + { + if (this.stringAsString) + { + statementCollection.Add(new CodeSnippetStatement("\t\t\t\tusing System.IO.StreamReader streamReader = new System.IO.StreamReader(stream);")); + statementCollection.Add(new CodeMethodReturnStatement(new CodeSnippetExpression("streamReader.ReadToEnd();"))); + } + else + { + if (codeGenOutputsSettings.UseSystemTextJson) + { + statementCollection.Add(new CodeMethodReturnStatement(new CodeMethodInvokeExpression( + new CodeMethodReferenceExpression( + new CodeVariableReferenceExpression("JsonSerializer"), "Deserialize", new CodeTypeReference(typeof(System.String))), + new CodeSnippetExpression("contentString"), + new CodeSnippetExpression("jsonSerializerSettings")))); + } + else + { + AddNewtonSoftJsonTextReader(statementCollection); + statementCollection.Add(new CodeMethodReturnStatement(new CodeSnippetExpression("jsonReader.ReadAsString()"))); + } + } + } + else if (returnType == typeOfChar) + { + if (codeGenOutputsSettings.UseSystemTextJson) + { + DeserializeContentStream(statementCollection); + } + else + { + AddNewtonSoftJsonTextReader(statementCollection); + AddNewtonSoftJsonSerializer(statementCollection); + statementCollection.Add(new CodeMethodReturnStatement(new CodeSnippetExpression("serializer.Deserialize(jsonReader)"))); + } + } + else if (returnType.IsPrimitive) + { + if (codeGenOutputsSettings.UseSystemTextJson) + { + DeserializeContentStream(statementCollection); + } + else + { + AddNewtonSoftJsonTextReader(statementCollection); + statementCollection.Add(new CodeMethodReturnStatement(new CodeSnippetExpression(String.Format("{0}.Parse(jsonReader.ReadAsString())", returnType.FullName)))); + } + } + else if (returnType.IsGenericType || TypeHelper.IsComplexType(returnType) || returnType.IsEnum) + { + if (codeGenOutputsSettings.UseSystemTextJson) + { + DeserializeContentStream(statementCollection); + } + else + { + AddNewtonSoftJsonTextReader(statementCollection); + //Add4TStartBacket(statementCollection); + AddNewtonSoftJsonSerializer(statementCollection); + AddNewtonSoftJsonSerializerDeserialize(statementCollection); + //Add4TEndBacket(statementCollection); + } + } + else + { + Trace.TraceWarning("This type is not yet supported: {0}", returnType.FullName); + } + } + + private static string RemoveTrialEmptyString(string s) + { + int p = s.IndexOf("+\"\"", StringComparison.Ordinal); + if (p >= 0) + { + return s.Remove(p, 3); + } + + int p2 = s.IndexOf("))\"", StringComparison.Ordinal); + if (p2 >= 0) + { + return s.Remove(p2 + 2, 1); + } + + return s; + } + + /// + /// If the API function use ProducesResponseTypeAttribute and 200-202 to define the return type, then get the return type as full type name, + /// Null if no such definition . + /// + /// + /// + static Type GetTypeTextOfResponse2xx(Attribute[] customAttributes) + { + foreach (Attribute c in customAttributes) + { + Microsoft.AspNetCore.Mvc.ProducesResponseTypeAttribute responseAttribute = c as Microsoft.AspNetCore.Mvc.ProducesResponseTypeAttribute; + if (responseAttribute != null) + { + if (responseAttribute.StatusCode >= 200 && responseAttribute.StatusCode <= 202) + { + return responseAttribute.Type; + } + } + } + + return null; + } + + + } } diff --git a/WebApiClientGenCore/WebApiClientGenCore.csproj b/WebApiClientGenCore/WebApiClientGenCore.csproj index 331f57e2..4aeee8a1 100644 --- a/WebApiClientGenCore/WebApiClientGenCore.csproj +++ b/WebApiClientGenCore/WebApiClientGenCore.csproj @@ -5,14 +5,14 @@ Fonlow.CodeDom.Web true Fonlow.WebApiClientGenCore - 7.8.1 + 7.8.2 Generate strongly typed client API in C# or TypeScript for .NET Core Web API. Strongly Typed Client API Generator generates C# and TypeScript codes of strongly typed client API similar to what generated by SvcUtil.exe of WCF, provided you have access to the ASP.NET Web API source codes or assemblies. Then you may provide or publish either the source codes in C# and TypeScript or the compiled client API library to other developers who are developing client programs of your Web API. The TypeScript outputs support jQuery, Angular 2+, AXIOS and Aurelia. Copyright © Zijian Huang 2015-$([System.DateTime]::Now.Year) https://github.com/zijianhuang/webapiclientgen ASP API Web Client webapi rest restful aspnet aspnetwebapi httpclient .net core aspnetcore jquery angular - Simplified C# codes of client API utilizing new features after .NET 5 and .NET 8. Support LengthAttribute. + For https://github.com/dotnet/runtime/issues/104716, for synchronous HttpClient Send, uses HttpClient.SendAsync().Result. true en