MakeHelper.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Collections;
  2. using System.Text.RegularExpressions;
  3. using Common;
  4. using LitJson;
  5. using Microsoft.CodeAnalysis.CSharp.Scripting;
  6. namespace Task
  7. {
  8. public class MakeHelper
  9. {
  10. public readonly static MakeHelper Instance = new MakeHelper();
  11. private MakeHelper()
  12. { }
  13. public void Start(string QueueName)
  14. {
  15. RabbitMQClient.Instance.StartReceive(QueueName, content => DoWorks(content));
  16. }
  17. public void DoWorks(string content)
  18. {
  19. try
  20. {
  21. if (!string.IsNullOrEmpty(content))
  22. {
  23. DoQueue(content);
  24. }
  25. }
  26. catch (Exception ex)
  27. {
  28. Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex, "生成异常");
  29. }
  30. }
  31. public void DoQueue(string content)
  32. {
  33. JsonData jsonObj = JsonMapper.ToObject(content);
  34. //流水号
  35. string requestId = jsonObj["requestId"].ToString();
  36. //模板文件路径
  37. string modePath = jsonObj["modePath"].ToString();
  38. //附加数据,原样返回
  39. string attach = jsonObj["attach"].ToString();
  40. //读取模板文件内容
  41. string templateString = Function.ReadInstance("Template/" + modePath);
  42. //解析模板内容
  43. string resultString = Util.Maker.StartMake(jsonObj["data"], templateString);
  44. //MQ回调解析的结果
  45. RabbitMQClient.Instance.Push("MakeSqlCallBackQueue", requestId + "#cut#" + attach + "#cut#" + resultString);
  46. }
  47. }
  48. }