|
|
using Common.Model.Config; using System; using System.Collections.Generic; using System.Configuration; using System.Globalization; using System.IdentityModel.Tokens.Jwt; using System.IO; using System.Linq; using System.Net.Http; using System.Security.Cryptography; using System.Text; using System.Web;
namespace JsonRx.Helper { /// <summary>
/// </summary>
public static class Util { /// <summary>
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public static string GetGuid(HttpRequestMessage request) { try { object uuidNumber = ""; request.Properties.TryGetValue("Guid", out uuidNumber); return uuidNumber.ToString(); } catch { return ""; } }
/// <summary>
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public static string GetUsername(HttpRequestMessage request) { try { object uuidNumber = ""; request.Properties.TryGetValue("Username", out uuidNumber); return uuidNumber.ToString(); } catch { return ""; } }
/// <summary>
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public static string GetCustomerId(HttpRequestMessage request) { try { object uuidNumber = ""; request.Properties.TryGetValue("CustomerId", out uuidNumber); return uuidNumber.ToString(); } catch { return ""; } }
public static string GetFintechUseNo(HttpRequestMessage request) { try { object uuidNumber = ""; request.Properties.TryGetValue("FintechUseNo", out uuidNumber); return uuidNumber.ToString(); } catch { return ""; } }
public static string GetAccessToken(HttpRequestMessage request) { try { object uuidNumber = ""; request.Properties.TryGetValue("AccessToken", out uuidNumber); return uuidNumber.ToString(); } catch { return ""; } }
/// <summary>
/// </summary>
/// <returns></returns>
public static string GetUuid(HttpRequestMessage request) { // UUID number coming from http header. This header value is sending to the properties
// of Request object and capturing here.
try { object uuidNumber = ""; request.Properties.TryGetValue("uuid", out uuidNumber); return uuidNumber.ToString(); } catch { return ""; } }
/// <summary>
/// </summary>
/// <returns></returns>
public static string GetScope(HttpRequestMessage request) { // UUID number coming from http header. This header value is sending to the properties
// of Request object and capturing here.
try { object uuidNumber = ""; request.Properties.TryGetValue("scope", out uuidNumber); return uuidNumber.ToString(); } catch { return ""; } }
/// <summary>
/// </summary>
/// <returns></returns>
public static string GetClientId(HttpRequestMessage request) { try { object clientId = ""; request.Properties.TryGetValue("clientId", out clientId); return clientId.ToString(); } catch { return ""; } }
/// <summary>
/// Since we require to choose langaue to reflect correponding kftc page and use can view
/// kftc page based on langauage selected by them. This method return provided langauge
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public static string GetKFTCLanguage(HttpRequestMessage request) { try { object clientId = ""; request.Properties.TryGetValue("language", out clientId); return clientId.ToString(); } catch { return ""; } }
/// <summary>
/// Since we require to choose langaue to reflect correponding kftc page and use can view
/// kftc page based on langauage selected by them. This method return provided langauge
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public static string GetKFTCClientId(HttpRequestMessage request) { try { object kftcId = ""; request.Properties.TryGetValue("KftcClientId", out kftcId); return kftcId.ToString(); } catch { return ""; } }
public static string GetClientFCMId(HttpRequestMessage request) { try { object clientFcmId = ""; request.Properties.TryGetValue("ClientFcmId", out clientFcmId); return clientFcmId.ToString(); } catch { return ""; } }
public static string getJWTTokenClaim(string token, string claimName) { try { var tokenHandler = new JwtSecurityTokenHandler(); var securityToken = (JwtSecurityToken)tokenHandler.ReadToken(token); var claimValue = securityToken.Claims.FirstOrDefault(c => c.Type == claimName)?.Value; return claimValue; } catch (Exception) { //TODO: Logger.Error
return null; } }
public static string GetDeviceType(HttpRequestMessage request) { try { object deviceType = ""; request.Properties.TryGetValue("deviceType", out deviceType); return deviceType != null ? deviceType.ToString() : "IOS"; } catch { return "IOS"; } }
public static string GetFullName(string fname, string mname, string lname) { string fullName = string.Empty;
fullName = string.Format("{0} {1}", (!string.IsNullOrEmpty(mname)) ? fname + " " + mname : fname, lname); return fullName; }
}
public static class StringHelper { private static CultureInfo ci = new CultureInfo("en-US"); //Convert all first latter
public static string ToTitleCase(this string str) { str = str.ToLower(); var strArray = str.Split(' '); if (strArray.Length > 1) { strArray[0] = ci.TextInfo.ToTitleCase(strArray[0]); return string.Join(" ", strArray); } return ci.TextInfo.ToTitleCase(str); }
public static string ToTitleCase(this string str, TitleCase tcase) { str = str.ToLower(); switch (tcase) { case TitleCase.First: var strArray = str.Split(' '); if (strArray.Length > 1) { strArray[0] = ci.TextInfo.ToTitleCase(strArray[0]); return string.Join(" ", strArray); } break; case TitleCase.All: return ci.TextInfo.ToTitleCase(str); default: break; } return ci.TextInfo.ToTitleCase(str); }
}
public enum TitleCase { First, All }
}
|