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.

300 lines
8.4 KiB

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