You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

247 lines
7.0 KiB

1 year ago
  1. using Common.Model.Config;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Configuration;
  5. using System.IdentityModel.Tokens.Jwt;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Net.Http;
  9. using System.Web;
  10. namespace JsonRx.Helper
  11. {
  12. /// <summary>
  13. /// </summary>
  14. public static class Util
  15. {
  16. /// <summary>
  17. /// </summary>
  18. /// <param name="request"></param>
  19. /// <returns></returns>
  20. public static string GetGuid(HttpRequestMessage request)
  21. {
  22. try
  23. {
  24. object uuidNumber = "";
  25. request.Properties.TryGetValue("Guid", out uuidNumber);
  26. return uuidNumber.ToString();
  27. }
  28. catch
  29. {
  30. return "";
  31. }
  32. }
  33. /// <summary>
  34. /// </summary>
  35. /// <param name="request"></param>
  36. /// <returns></returns>
  37. public static string GetUsername(HttpRequestMessage request)
  38. {
  39. try
  40. {
  41. object uuidNumber = "";
  42. request.Properties.TryGetValue("Username", out uuidNumber);
  43. return uuidNumber.ToString();
  44. }
  45. catch
  46. {
  47. return "";
  48. }
  49. }
  50. /// <summary>
  51. /// </summary>
  52. /// <param name="request"></param>
  53. /// <returns></returns>
  54. public static string GetCustomerId(HttpRequestMessage request)
  55. {
  56. try
  57. {
  58. object uuidNumber = "";
  59. request.Properties.TryGetValue("CustomerId", out uuidNumber);
  60. return uuidNumber.ToString();
  61. }
  62. catch
  63. {
  64. return "";
  65. }
  66. }
  67. public static string GetFintechUseNo(HttpRequestMessage request)
  68. {
  69. try
  70. {
  71. object uuidNumber = "";
  72. request.Properties.TryGetValue("FintechUseNo", out uuidNumber);
  73. return uuidNumber.ToString();
  74. }
  75. catch
  76. {
  77. return "";
  78. }
  79. }
  80. public static string GetAccessToken(HttpRequestMessage request)
  81. {
  82. try
  83. {
  84. object uuidNumber = "";
  85. request.Properties.TryGetValue("AccessToken", out uuidNumber);
  86. return uuidNumber.ToString();
  87. }
  88. catch
  89. {
  90. return "";
  91. }
  92. }
  93. /// <summary>
  94. /// </summary>
  95. /// <returns></returns>
  96. public static string GetUuid(HttpRequestMessage request)
  97. {
  98. // UUID number coming from http header. This header value is sending to the properties
  99. // of Request object and capturing here.
  100. try
  101. {
  102. object uuidNumber = "";
  103. request.Properties.TryGetValue("uuid", out uuidNumber);
  104. return uuidNumber.ToString();
  105. }
  106. catch
  107. {
  108. return "";
  109. }
  110. }
  111. /// <summary>
  112. /// </summary>
  113. /// <returns></returns>
  114. public static string GetScope(HttpRequestMessage request)
  115. {
  116. // UUID number coming from http header. This header value is sending to the properties
  117. // of Request object and capturing here.
  118. try
  119. {
  120. object uuidNumber = "";
  121. request.Properties.TryGetValue("scope", out uuidNumber);
  122. return uuidNumber.ToString();
  123. }
  124. catch
  125. {
  126. return "";
  127. }
  128. }
  129. /// <summary>
  130. /// </summary>
  131. /// <returns></returns>
  132. public static string GetClientId(HttpRequestMessage request)
  133. {
  134. try
  135. {
  136. object clientId = "";
  137. request.Properties.TryGetValue("clientId", out clientId);
  138. return clientId.ToString();
  139. }
  140. catch
  141. {
  142. return "";
  143. }
  144. }
  145. /// <summary>
  146. /// Since we require to choose langaue to reflect correponding kftc page and use can view
  147. /// kftc page based on langauage selected by them. This method return provided langauge
  148. /// </summary>
  149. /// <param name="request"></param>
  150. /// <returns></returns>
  151. public static string GetKFTCLanguage(HttpRequestMessage request)
  152. {
  153. try
  154. {
  155. object clientId = "";
  156. request.Properties.TryGetValue("language", out clientId);
  157. return clientId.ToString();
  158. }
  159. catch
  160. {
  161. return "";
  162. }
  163. }
  164. /// <summary>
  165. /// Since we require to choose langaue to reflect correponding kftc page and use can view
  166. /// kftc page based on langauage selected by them. This method return provided langauge
  167. /// </summary>
  168. /// <param name="request"></param>
  169. /// <returns></returns>
  170. public static string GetKFTCClientId(HttpRequestMessage request)
  171. {
  172. try
  173. {
  174. object kftcId = "";
  175. request.Properties.TryGetValue("KftcClientId", out kftcId);
  176. return kftcId.ToString();
  177. }
  178. catch
  179. {
  180. return "";
  181. }
  182. }
  183. public static string GetClientFCMId(HttpRequestMessage request)
  184. {
  185. try
  186. {
  187. object clientFcmId = "";
  188. request.Properties.TryGetValue("ClientFcmId", out clientFcmId);
  189. return clientFcmId.ToString();
  190. }
  191. catch
  192. {
  193. return "";
  194. }
  195. }
  196. public static string getJWTTokenClaim(string token, string claimName)
  197. {
  198. try
  199. {
  200. var tokenHandler = new JwtSecurityTokenHandler();
  201. var securityToken = (JwtSecurityToken)tokenHandler.ReadToken(token);
  202. var claimValue = securityToken.Claims.FirstOrDefault(c => c.Type == claimName)?.Value;
  203. return claimValue;
  204. }
  205. catch (Exception)
  206. {
  207. //TODO: Logger.Error
  208. return null;
  209. }
  210. }
  211. public static string GetDeviceType(HttpRequestMessage request)
  212. {
  213. try
  214. {
  215. object deviceType = "";
  216. request.Properties.TryGetValue("deviceType", out deviceType);
  217. return deviceType != null ? deviceType.ToString() : "IOS";
  218. }
  219. catch
  220. {
  221. return "IOS";
  222. }
  223. }
  224. public static string GetFullName(string fname, string mname, string lname)
  225. {
  226. string fullName = string.Empty;
  227. fullName = string.Format("{0} {1}", (!string.IsNullOrEmpty(mname)) ? fname + " " + mname : fname, lname);
  228. return fullName;
  229. }
  230. }
  231. }