protected void RequestApply(HttpClientDataTalk client, HttpClientComponentRequestSettingElement setting) { var url = string.Concat(setting.UriBase, setting.Route); client.Url = url; client.Method = setting.Action; }
protected void HeadersApply(HttpClientDataTalk client, HttpClientComponentHeaderSettingElement setting) { if (string.IsNullOrEmpty(setting.Accept) == false) { client.Accept = setting.Accept; } if (string.IsNullOrEmpty(setting.ContentType) == false) { client.ContentType = setting.ContentType; } if (string.IsNullOrEmpty(setting.ContentLength) == false) { client.ContentLength = Convert.ToInt32(setting.ContentLength); } if (string.IsNullOrEmpty(setting.Timeout) == false) { client.Timeout = Convert.ToInt32(setting.Timeout); } if (string.IsNullOrEmpty(setting.Custom) == false) { HeaderCustomApply(client, setting.Custom); } }
private ICollection <ProviderContractMap> GetProviderContractMap(long[] contractMapKey, int currentRetryFailAttemtp) { ICollection <ProviderContractMap> ret; // Get from Soa using (var client = new HttpClientDataTalk()) { var bodySettingName = "msaprovidercontractmapdetail"; var request = HttpClientComponentSettingProvider.GetRequestSetting($"msaprovidercontractmap{AppConfig.CurrentEnvironment}"); var headers = HttpClientComponentSettingProvider.GetHeaderSetting("msa"); var body = HttpClientComponentSettingProvider.GetBodySetting(bodySettingName); RequestApply(client, request); HeadersApply(client, headers); HeaderCustomApply(client, $"Authorization: Bearer {AccessToken()}"); BodyApply(client, body.Content); client.Body += Serialize <long[]>((contractMapKey ?? new long[] { 0 }).ToArray()); try { client.Execute(); ret = ResponseData <ICollection <ProviderContractMap> >(client.Result); } catch (Exception ex) { if (SleepAndRetry(ref currentRetryFailAttemtp)) { return(GetProviderContractMap(contractMapKey, currentRetryFailAttemtp)); } throw new Exception($"{request}", ex); } } return(ret); }
private ICollection <MemberDemographicModel> GetDemographicDetail(IEnumerable <long> memberIdList, int currentRetryFailAttemtp) { ICollection <MemberDemographicModel> ret; // Get from Soa using (var client = new HttpClientDataTalk()) { var request = HttpClientComponentSettingProvider.GetRequestSetting($"msademographicdetail{AppConfig.CurrentEnvironment}"); var headers = HttpClientComponentSettingProvider.GetHeaderSetting("msa"); //var body = HttpClientComponentSettingProvider.GetBodySetting("msademographicdetail"); RequestApply(client, request); HeadersApply(client, headers); HeaderCustomApply(client, $"Authorization: Bearer {AccessToken()}"); //BodyApply(client, body.Content); client.Body += Serialize <long[]>((memberIdList ?? new long[] { 0 }).ToArray()); try { client.Execute(); ret = ResponseData <ICollection <MemberDemographicModel> >(client.Result); } catch (Exception ex) { if (SleepAndRetry(ref currentRetryFailAttemtp)) { return(GetDemographicDetail(memberIdList, currentRetryFailAttemtp)); } throw new Exception($"{request}", ex); } } return(ret); }
private ICollection <ProviderDetailModel> GetProviders(long[] providerKeyList, int currentRetryFailAttemtp) { ICollection <ProviderDetailModel> ret; // Get from Soa using (var client = new HttpClientDataTalk()) { var bodySettingName = "msaproviderdetail"; var request = HttpClientComponentSettingProvider.GetRequestSetting($"msaproviderdetail{AppConfig.CurrentEnvironment}"); var headers = HttpClientComponentSettingProvider.GetHeaderSetting("msa"); var body = HttpClientComponentSettingProvider.GetBodySetting(bodySettingName); RequestApply(client, request); HeadersApply(client, headers); HeaderCustomApply(client, $"Authorization: Bearer {AccessToken()}"); BodyApply(client, Serialize <long[]>(body.Content, "ProviderKeys", providerKeyList)); try { client.Execute(); ret = ResponseData <ICollection <ProviderDetailModel> >(client.Result); } catch (Exception ex) { if (SleepAndRetry(ref currentRetryFailAttemtp)) { return(GetProviders(providerKeyList, currentRetryFailAttemtp)); } throw new Exception($"{request}", ex); } } return(ret); }
private ICollection <SoaEligibility> GetEligibilities(int currentRetryFailAttemtp) { ICollection <SoaEligibility> ret; // Get from Soa using (var client = new HttpClientDataTalk()) { const string bodySettingName = "msadeltaeligibility"; var request = HttpClientComponentSettingProvider.GetRequestSetting($"msaeligibility{AppConfig.CurrentEnvironment}"); var headers = HttpClientComponentSettingProvider.GetHeaderSetting("msa"); var body = HttpClientComponentSettingProvider.GetBodySetting(bodySettingName); RequestApply(client, request); HeadersApply(client, headers); HeaderCustomApply(client, $"Authorization: Bearer {AccessToken()}"); BodyApply(client, Serialize <long[]>(body.Content, "MemberNumbers", MemberIdList)); try { client.Execute(); ret = ResponseData <ICollection <SoaEligibility> >(client.Result); } catch (Exception ex) { if (SleepAndRetry(ref currentRetryFailAttemtp)) { return(GetEligibilities(currentRetryFailAttemtp)); } throw new Exception($"{request}", ex); } } return(ret); }
private string GetToken(HttpClientDataTalk client, out double expiredInSeconds) { dynamic obj = Newtonsoft.Json.JsonConvert.DeserializeObject <ExpandoObject>(client.Result); expiredInSeconds = obj.expires_in; return(obj.access_token); }
public string GetToken(string tokenEnv, out double expiredInSeconds) { string token = string.Empty; using (var client = new HttpClientDataTalk()) { var request = HttpClientComponentSettingProvider.GetRequestSetting(tokenEnv); var headers = HttpClientComponentSettingProvider.GetHeaderSetting("token"); var body = HttpClientComponentSettingProvider.GetBodySetting("token"); RequestApply(client, request); HeadersApply(client, headers); BodyApply(client, body.Content); try { client.Execute(); token = GetToken(client, out expiredInSeconds); } catch (Exception) { throw; } } return(token); }
protected void BodyApply(HttpClientDataTalk client, string Content) { Body = Content; if (string.IsNullOrEmpty(Content)) { return; } client.Body = GetTokenRequestBodyInput(Content); }
protected void HeaderCustomApply(HttpClientDataTalk client, string customHeader) { var headers = new List <string>(); headers.AddRange(customHeader.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries)); foreach (var header in headers) { var attrs = header.Split(new char[] { '=' }); if (attrs.Length == 1) { attrs = header.Split(new char[] { ':' }); } client.Headers.Add(attrs[0], attrs[1]); } }
protected void HeaderCustomApply(HttpClientDataTalk client, string customHeader) { //ArgusRXIntegration.ProgressNotification.Notification.Notify($"SOA Request -> Header: {customHeader}"); var headers = new List <string>(); headers.AddRange(customHeader.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries)); foreach (var header in headers) { var attrs = header.Split(new char[] { '=' }); if (attrs.Length == 1) { attrs = header.Split(new char[] { ':' }); } client.Headers.Add(attrs[0], attrs[1]); } }