From aef6edc4c0efedee062f27c1bbd8897e73d7ae25 Mon Sep 17 00:00:00 2001 From: Sean Date: Mon, 7 Apr 2025 16:01:12 -0400 Subject: [PATCH] Make the service client portable with the new version on raspberry pi 5. --- .../Service/MarketDataServiceClient.cs | 40 ++++++------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/MarketDataLib/Service/MarketDataServiceClient.cs b/MarketDataLib/Service/MarketDataServiceClient.cs index dc0a3b2..3e31971 100644 --- a/MarketDataLib/Service/MarketDataServiceClient.cs +++ b/MarketDataLib/Service/MarketDataServiceClient.cs @@ -1,5 +1,6 @@ using MarketData.MarketDataModel; using MarketData.MarketDataModel.GainLoss; +using MarketData.Utils; using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -110,6 +111,7 @@ namespace MarketData.Service sb.Append("/api/Authorization/GetToken?").Append("user=").Append(user); sb.Append("&password=").Append(password); String json = httpClient.GetStringAsync(sb.ToString()).Result; + json=ToConformimgJson(json); String accessToken = JsonConvert.DeserializeObject(json); return new ServiceResult(accessToken); } @@ -121,6 +123,7 @@ namespace MarketData.Service } } } + // ********************************************************** C O N S U M E R P R I C E I N D E X ************************************************* public ServiceResult GetDistinctConsumerPriceIndices() { @@ -156,7 +159,6 @@ namespace MarketData.Service StringBuilder sb = new StringBuilder(); sb.Append("/api/PriceIndex/GetConsumerPriceIndex?").Append("token=").Append(accessToken).Append("&").Append("indexCode=").Append(HttpUtility.UrlEncode(indexCode)); String json = httpClient.GetStringAsync(sb.ToString()).Result; - List priceIndices = JsonConvert.DeserializeObject>(json); return new ServiceResult(priceIndices); } @@ -240,29 +242,6 @@ namespace MarketData.Service } } // ************************************************************************************************************************************************ - //public ServiceResult GetPortfolioTradesWithCombinedLots(String symbol) - //{ - // lock(this) - // { - // try - // { - // if(!IsNetworkAvailable())return new ServiceResult(false,"No network."); - // if (!IsAuthorized()) return new ServiceResult(false,"Unauthorized."); - // StringBuilder sb = new StringBuilder(); - // sb.Append("/api/Portfolio/GetPortfolioTradesWithCombinedLots?").Append("token=").Append(accessToken).Append("&").Append("symbol=").Append(symbol); - // String json = httpClient.GetStringAsync(sb.ToString()).Result; - // List portfolioTrades= JsonConvert.DeserializeObject>(json); - // return new ServiceResult(portfolioTrades); - // } - // catch (Exception exception) - // { - // exceptions.Add(exception); - // Debug.WriteLine(exception.ToString()); - // return new ServiceResult(false,exception.ToString()); - // } - // } - //} - public ServiceResult GetStopLimit(String symbol) { lock(this) @@ -457,7 +436,7 @@ namespace MarketData.Service if(!IsNetworkAvailable())return new ServiceResult(false,"No network."); if (!IsAuthorized()) return new ServiceResult(false,"Unauthorized."); StringBuilder sb = new StringBuilder(); - sb.Append("/api/GainLoss/GetGainLossWithDetail?").Append("token=").Append(accessToken).Append("&selectedDate=").Append(selectedDate.ToShortDateString()).Append("&").Append("account=").Append(account); + sb.Append("/api/GainLoss/GetGainLossWithDetailByDateAndAccount?").Append("token=").Append(accessToken).Append("&selectedDate=").Append(selectedDate.ToShortDateString()).Append("&").Append("account=").Append(account); String json = httpClient.GetStringAsync(sb.ToString()).Result; List gainLossSummaryDetail = JsonConvert.DeserializeObject>(json); return new ServiceResult(gainLossSummaryDetail); @@ -480,7 +459,7 @@ namespace MarketData.Service if(!IsNetworkAvailable())return new ServiceResult(false,"No network."); if (!IsAuthorized()) return new ServiceResult(false,"Unauthorized."); StringBuilder sb = new StringBuilder(); - sb.Append("/api/GainLoss/GetGainLossWithDetail?").Append("token=").Append(accessToken).Append("&selectedDate=").Append(selectedDate.ToShortDateString()); + sb.Append("/api/GainLoss/GetGainLossWithDetailByDate?").Append("token=").Append(accessToken).Append("&selectedDate=").Append(selectedDate.ToShortDateString()); String json = httpClient.GetStringAsync(sb.ToString()).Result; List gainLossSummaryDetail = JsonConvert.DeserializeObject>(json); return new ServiceResult(gainLossSummaryDetail); @@ -619,6 +598,13 @@ namespace MarketData.Service if(Connectivity.ConnectionProfiles.Contains(ConnectionProfile.WiFi))return true; return false; } - + private static String ToConformimgJson(String json) + { + if(String.IsNullOrEmpty(json))return json; + if(json.StartsWith("\"") && json.EndsWith("\""))return json; + if(json.StartsWith("[") && json.EndsWith("]"))return json; + if(json.StartsWith("{") && json.EndsWith("}"))return json; + return Utility.AddQuotes(json); + } } }