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.

139 lines
4.0 KiB

  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using OT.COM.LogisticsUtil;
  4. using OT.COM.SignalerMessage;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Text;
  10. namespace CounsellorBL
  11. {
  12. public class ServiceBase : MessageBase
  13. {
  14. public const string SERVICE = "service";
  15. protected Dictionary<string, object> _dicInitData = null;
  16. public virtual CResponseMessage Init(CRequestMessage i_crm)
  17. {
  18. CResponseMessage crm = null;
  19. string sMsg = null;
  20. try
  21. {
  22. do
  23. {
  24. if (null == i_crm)
  25. {
  26. sMsg = BaseExceptionWord.ex000047; //NO INIT DATA
  27. break;
  28. }
  29. _dicInitData = i_crm.DATA;
  30. crm = new CSuccessResponseMessage(null, i_crm);
  31. }
  32. while (false);
  33. }
  34. catch (Exception ex)
  35. {
  36. sMsg = new Util().GetLastExceptionMsg(ex);
  37. }
  38. if (null != sMsg)
  39. {
  40. crm = new CErrorResponseMessage(sMsg, null);
  41. }
  42. return crm;
  43. }
  44. public CResponseMessage Entry(CRequestMessage i_crm)
  45. {
  46. string sMsg = null;
  47. CResponseMessage crm = null;
  48. try
  49. {
  50. do
  51. {
  52. // Find Native Method
  53. string sFunctionName = i_crm.TYPE;
  54. if (null == sFunctionName)
  55. {
  56. //sMsg = string.Format("NO METHOD - {0}", sFunctionName);
  57. sMsg = BaseExceptionWord.ex000051; //NO METHOD
  58. break;
  59. }
  60. MethodInfo mi = this.GetType().GetMethod(sFunctionName);
  61. if (null == mi)
  62. {
  63. //sMsg = string.Format("NO MATCH METHOD - {0}", sFunctionName);
  64. sMsg = BaseExceptionWord.ex000052; //NO MATCH METHOD
  65. break;
  66. }
  67. object[] ao = { i_crm };
  68. crm = (CResponseMessage)mi.Invoke(this, ao);
  69. }
  70. while (false);
  71. }
  72. catch (Exception ex)
  73. {
  74. sMsg = new Util().GetLastExceptionMsg(ex);
  75. }
  76. if (null != sMsg)
  77. {
  78. crm = new CErrorResponseMessage(sMsg, i_crm);
  79. }
  80. return crm;
  81. }
  82. public string MakeDebugFullDump(string i_sMsg, CRequestMessage i_crm)
  83. {
  84. string sRes = Environment.NewLine;
  85. sRes += "**** Start Dump **************************" + Environment.NewLine;
  86. sRes += string.Format("Custom Message:{0}", i_sMsg) + Environment.NewLine;
  87. sRes += string.Format("Parameter Json:{0}", JsonConvert.SerializeObject(i_crm)) + Environment.NewLine;
  88. sRes += "Call Stack Dump:" + Environment.NewLine;
  89. sRes += Environment.StackTrace + Environment.NewLine;
  90. sRes += "*****End Dump *************************" + Environment.NewLine;
  91. return sRes;
  92. }
  93. public string JProperty2Dic(JObject i_jpData, ref Dictionary<string, object> io_dicData)
  94. {
  95. string sRes = null;
  96. Dictionary<string, object> dicRes = new Dictionary<string, object>();
  97. try
  98. {
  99. foreach (JProperty property in i_jpData.Properties())
  100. {
  101. JToken jv = property.Value;
  102. dicRes.Add(property.Name, jv.Value<string>());
  103. }
  104. }
  105. catch (Exception ex)
  106. {
  107. sRes = new Util().GetLastExceptionMsg(ex);
  108. }
  109. io_dicData = dicRes;
  110. return sRes;
  111. }
  112. }
  113. }