TapCloudSaveTracker.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using System.Collections.Generic;
  3. using Newtonsoft.Json;
  4. using TapSDK.Core.Standalone.Internal.Openlog;
  5. namespace TapSDK.CloudSave.Standalone
  6. {
  7. internal class TapCloudSaveTracker
  8. {
  9. private const string ACTION_INIT = "init";
  10. private const string ACTION_START = "start";
  11. private const string ACTION_SUCCESS = "success";
  12. private const string ACTION_FAIL = "fail";
  13. private static TapCloudSaveTracker instance;
  14. private TapOpenlogStandalone openlog;
  15. private TapCloudSaveTracker()
  16. {
  17. openlog = new TapOpenlogStandalone("TapCloudSave", TapTapCloudSave.Version);
  18. }
  19. public static TapCloudSaveTracker Instance
  20. {
  21. get
  22. {
  23. if (instance == null)
  24. {
  25. instance = new TapCloudSaveTracker();
  26. }
  27. return instance;
  28. }
  29. }
  30. internal void TrackInit()
  31. {
  32. ReportLog(ACTION_INIT);
  33. }
  34. internal void TrackStart(string funcNace, string seesionId)
  35. {
  36. Dictionary<string, string> parameters = new Dictionary<string, string>
  37. {
  38. { "func_name", funcNace },
  39. { "session_id", seesionId },
  40. };
  41. ReportLog(
  42. ACTION_START,
  43. new Dictionary<string, string>()
  44. {
  45. { "args", JsonConvert.SerializeObject(parameters) },
  46. }
  47. );
  48. }
  49. internal void TrackSuccess(string funcNace, string seesionId)
  50. {
  51. Dictionary<string, string> parameters = new Dictionary<string, string>
  52. {
  53. { "func_name", funcNace },
  54. { "session_id", seesionId },
  55. };
  56. ReportLog(
  57. ACTION_SUCCESS,
  58. new Dictionary<string, string>()
  59. {
  60. { "args", JsonConvert.SerializeObject(parameters) },
  61. }
  62. );
  63. }
  64. internal void TrackFailure(
  65. string funcNace,
  66. string seesionId,
  67. int errorCode = -1,
  68. string errorMessage = null
  69. )
  70. {
  71. Dictionary<string, string> parameters = new Dictionary<string, string>
  72. {
  73. { "func_name", funcNace },
  74. { "session_id", seesionId },
  75. { "error_code", errorCode.ToString() },
  76. { "error_msg", errorMessage },
  77. };
  78. ReportLog(
  79. ACTION_FAIL,
  80. new Dictionary<string, string>()
  81. {
  82. { "args", JsonConvert.SerializeObject(parameters) },
  83. }
  84. );
  85. }
  86. private void ReportLog(string action, Dictionary<string, string> parameters = null)
  87. {
  88. openlog.LogBusiness(action, parameters);
  89. }
  90. }
  91. }