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.

244 lines
6.4 KiB

  1. using System;
  2. using System.Configuration;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Xml.Linq;
  7. using System.Xml.Serialization;
  8. namespace Swift.API
  9. {
  10. public class Utility
  11. {
  12. public static string ReadWebConfig(string key, string defValue)
  13. {
  14. return (ConfigurationSettings.AppSettings[key] ?? defValue).ToString();
  15. }
  16. public static string ReadSession(string key, string defVal)
  17. {
  18. try
  19. {
  20. return HttpContext.Current.Session[key] == null ? defVal : HttpContext.Current.Session[key].ToString();
  21. }
  22. catch (Exception ex)
  23. {
  24. return "";
  25. }
  26. }
  27. public static void WriteSession(string key, string value)
  28. {
  29. HttpContext.Current.Session[key] = value;
  30. }
  31. public static string GetSocialWallApiAuthKey()
  32. {
  33. return ReadWebConfig("socialWallApiAuth", "");
  34. }
  35. public static string ArrayToXML(string[] arr)
  36. {
  37. XDocument doc = new XDocument();
  38. doc.Add(new XElement("root", arr.Select(x => new XElement("item", x))));
  39. return doc.ToString();
  40. }
  41. public static string GetDateInC2CFormat(string strDate)
  42. {
  43. var date = DateTime.Parse(strDate);
  44. return date.ToString("yyyyMMdd");
  45. }
  46. public static string GetDateInMGFormat(string strDate)
  47. {
  48. var date = DateTime.Parse(strDate);
  49. return date.ToString("dd.MM.yyyy 00:00:00");
  50. }
  51. public static string GetDateInCEFormat(string strDate)
  52. {
  53. var date = DateTime.Parse(strDate);
  54. return date.ToString("dd/MM/yyyy");
  55. }
  56. public static string GetDateInICFormat(string strDate)
  57. {
  58. var date = DateTime.Parse(strDate);
  59. return date.ToString("yyyyMMdd");
  60. }
  61. public static string GetDateInMGFormat(string strDate, string type)
  62. {
  63. var date = DateTime.Parse(strDate);
  64. var res = "";
  65. if (type.ToLower().Equals("t"))
  66. {
  67. res = date.ToString("dd.MM.yyyy 23:59:59");
  68. }
  69. else
  70. {
  71. res = date.ToString("dd.MM.yyyy 00:00:00");
  72. }
  73. return res;
  74. }
  75. public static string GetDateToShortString(string strDate)
  76. {
  77. var date = DateTime.Parse(strDate);
  78. return date.ToShortDateString();
  79. }
  80. public static string GetDateToSqlDate(string strDate)
  81. {
  82. var date = DateTime.Parse(strDate);
  83. return date.ToString("yyyy-MM-dd");
  84. }
  85. #region Global Bank Configs
  86. public static string GetgblUserid()
  87. {
  88. return ReadWebConfig("gbluserid", "");
  89. }
  90. public static string GetgblPassword()
  91. {
  92. return ReadWebConfig("gblpassword", "");
  93. }
  94. public static string GetgblpayoutCode()
  95. {
  96. return ReadWebConfig("gblpayagentcode", "");
  97. }
  98. public static string GetgblAgentId()
  99. {
  100. return ReadWebConfig("gblAgentID", "");
  101. }
  102. public static string GetgblCertName()
  103. {
  104. return ReadWebConfig("gblCertName", "");
  105. }
  106. public static string GetgblCertPath()
  107. {
  108. return ReadWebConfig("gblCertPath", "");
  109. }
  110. public static string GetgblCertPwd()
  111. {
  112. return ReadWebConfig("gblCertPwd", "");
  113. }
  114. #endregion Global Bank Configs
  115. public static DbResult LogRequestKFTC(string user, string methodName, string requestXml, string processId = "")
  116. {
  117. var db = new Dao();
  118. if (String.IsNullOrEmpty(requestXml))
  119. requestXml = "";
  120. var sql = String.Format("EXEC PROC_KFTC_LOGS @flag='i', @CUSTOMERID='{0}', @methodName='{1}',@requestXml=N'{2}',@processId='{3}'", user, methodName, requestXml.Replace("'", ""), processId);
  121. return db.ParseDbResult(sql);
  122. }
  123. public static DbResult LogResponseKFTC(string rowId, string responseXml, string tpErrorCode, string tpErrorMsg)
  124. {
  125. var db = new Dao();
  126. try
  127. {
  128. if (String.IsNullOrEmpty(responseXml))
  129. responseXml = "";
  130. var sql =
  131. String.Format(
  132. "EXEC PROC_KFTC_LOGS @flag='u', @rowId='{0}',@responseXml=N'{1}', @errorCode='{2}', @errorMessage=N'{3}'",
  133. rowId, responseXml.Replace("'", ""), tpErrorCode, tpErrorMsg);
  134. return db.ParseDbResult(sql);
  135. }
  136. catch (Exception)
  137. {
  138. return new DbResult();
  139. }
  140. }
  141. public static DbResult LogRequest(string user, string providerName, string methodName, string controlNo, string requestXml, string processId = "")
  142. {
  143. if (String.IsNullOrEmpty(requestXml))
  144. requestXml = "";
  145. var sql = String.Format("EXEC proc_tpApiLogs @flag='i', @user='{0}', @providerName='{1}', @methodName='{2}',@controlNo='{3}',@requestXml='{4}',@processId='{5}'", user, providerName, methodName, controlNo, requestXml.Replace("'", ""), processId);
  146. var db = new Dao();
  147. return db.ParseDbResult(sql);
  148. }
  149. public static DbResult LogResponse(string rowId, string responseXml)
  150. {
  151. try
  152. {
  153. if (String.IsNullOrEmpty(responseXml))
  154. responseXml = "";
  155. var sql = String.Format("EXEC proc_tpApiLogs @flag='u', @rowId='{0}',@responseXml='{1}'", rowId,
  156. responseXml.Replace("'", ""));
  157. var db = new Dao();
  158. return db.ParseDbResult(sql);
  159. }
  160. catch (Exception)
  161. {
  162. return new DbResult();
  163. }
  164. }
  165. public static string ObjectToXML(object input)
  166. {
  167. try
  168. {
  169. var stringwriter = new StringWriter();
  170. var serializer = new XmlSerializer(input.GetType());
  171. serializer.Serialize(stringwriter, input);
  172. return stringwriter.ToString();
  173. }
  174. catch (Exception ex)
  175. {
  176. if (ex.InnerException != null)
  177. ex = ex.InnerException;
  178. return "Could not convert: " + ex.Message;
  179. }
  180. }
  181. public static string BlankIfNull(string val)
  182. {
  183. if (!String.IsNullOrWhiteSpace(val))
  184. {
  185. return val;
  186. }
  187. return "";
  188. }
  189. public static DbResult ValidateRequest(string user, string controlNo)
  190. {
  191. var db = new Dao();
  192. var sql = "EXEC proc_tpApiLogs @flag = 'vr'";
  193. sql += ", @user = " + db.FilterString(user);
  194. sql += ", @controlNo = " + db.FilterString(controlNo);
  195. return db.ParseDbResult(sql);
  196. }
  197. public static DbResult LogResponse(string rowId, string responseXml, string tpErrorCode, string tpErrorMsg)
  198. {
  199. try
  200. {
  201. if (String.IsNullOrEmpty(responseXml))
  202. responseXml = "";
  203. var sql =
  204. String.Format(
  205. "EXEC proc_tpApiLogs @flag='u', @rowId='{0}',@responseXml='{1}', @errorCode='{2}', @errorMessage='{3}'",
  206. rowId, responseXml.Replace("'", ""), tpErrorCode, tpErrorMsg);
  207. var db = new Dao();
  208. return db.ParseDbResult(sql);
  209. }
  210. catch (Exception)
  211. {
  212. return new DbResult();
  213. }
  214. }
  215. }
  216. }