MakeAppHelper.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System.Collections;
  2. using System.Text.RegularExpressions;
  3. using System.Web;
  4. using Common;
  5. using Customer.Source;
  6. using Infrastructure;
  7. using LitJson;
  8. using Microsoft.CodeAnalysis.CSharp.Scripting;
  9. using Model;
  10. using Services;
  11. using Util;
  12. using Util.MakeApp;
  13. namespace Tasks
  14. {
  15. public class MakeAppHelper
  16. {
  17. public readonly static MakeAppHelper Instance = new MakeAppHelper();
  18. private MakeAppHelper()
  19. { }
  20. public void Start(string QueueName)
  21. {
  22. // RabbitMQClient.Instance.StartReceive(QueueName, content => DoWorks(content));
  23. Thread th = new Thread(poscheck);
  24. th.IsBackground = true;
  25. th.Start(QueueName);
  26. }
  27. public void poscheck(object QueueName)
  28. {
  29. while (true)
  30. {
  31. string content = RedisServer.Cache.RPop<string>(QueueName.ToString());
  32. if (!string.IsNullOrEmpty(content))
  33. {
  34. DoWorks(content);
  35. Thread.Sleep(1000);
  36. }
  37. else
  38. {
  39. Thread.Sleep(2000);
  40. }
  41. }
  42. }
  43. public void DoWorks(string content)
  44. {
  45. if (!string.IsNullOrEmpty(content))
  46. {
  47. DoQueue(content);
  48. }
  49. }
  50. public string DoQueue(string content, bool push = true)
  51. {
  52. try
  53. {
  54. JsonData jsonObj = JsonMapper.ToObject(content);
  55. //流水号
  56. string requestId = jsonObj["requestId"].ToString();
  57. //附加数据,原样返回
  58. JsonData attach = JsonMapper.ToObject(jsonObj["attach"].ToString());
  59. string appKind = attach["appKind"].ToString();
  60. if (appKind.EndsWith("project_sycn"))
  61. {
  62. string kind = appKind.Substring(0, appKind.IndexOf("_"));
  63. GitHelper git = new GitHelper("AppTemplate/" + kind);
  64. if (string.IsNullOrEmpty(Function.ReadInstance(kind + "_project_sycn.txt")))
  65. {
  66. git.Clone($"https://repos.kexiaoshuang.com/omega/omega-" + kind + "-framework.git", "lichunlei", "8604515", "master");
  67. Function.WritePage("/", kind + "_project_sycn.txt", "1");
  68. }
  69. else
  70. {
  71. git.PullCode("lichunlei", "8604515", "lichunlei", "35013854@qq.com");
  72. }
  73. return "ok";
  74. }
  75. string fileName = jsonObj["data"]["fileName"].ToString();
  76. AppProject project = Newtonsoft.Json.JsonConvert.DeserializeObject<AppProject>(jsonObj["data"]["appProject"].ToString()) ?? new AppProject();
  77. AppProjectVersion version = Newtonsoft.Json.JsonConvert.DeserializeObject<AppProjectVersion>(jsonObj["data"]["appProjectVersion"].ToString()) ?? new AppProjectVersion();
  78. List<AppModule> smodules = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AppModule>>(jsonObj["data"]["appModules"].ToString()) ?? new List<AppModule>();
  79. List<AppProjectModule> modules = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AppProjectModule>>(jsonObj["data"]["appProjectModules"].ToString()) ?? new List<AppProjectModule>();
  80. List<AppProjectParam> paramList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AppProjectParam>>(jsonObj["data"]["appProjectParams"].ToString()) ?? new List<AppProjectParam>();
  81. List<AppModuleFile> fileList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AppModuleFile>>(jsonObj["data"]["appModulesFiles"].ToString()) ?? new List<AppModuleFile>();
  82. List<AppProjectPage> pages = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AppProjectPage>>(jsonObj["data"]["appProjectPages"].ToString()) ?? new List<AppProjectPage>();
  83. List<AppProjectBottom> bottoms = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AppProjectBottom>>(jsonObj["data"]["appProjectBottoms"].ToString()) ?? new List<AppProjectBottom>();
  84. if (appKind == "Android")
  85. {
  86. List<AppModuleAndroidCode> codes = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AppModuleAndroidCode>>(jsonObj["data"]["appModulesAndroidCode"].ToString()) ?? new List<AppModuleAndroidCode>();
  87. MakeAndroidCode.MakerFile(fileName, project, version, smodules, codes, modules, paramList, fileList, pages, bottoms);
  88. }
  89. else if (appKind == "ios")
  90. {
  91. List<AppModuleIosCode> codes = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AppModuleIosCode>>(jsonObj["data"]["appModulesIosCode"].ToString()) ?? new List<AppModuleIosCode>();
  92. MakeAppleCode.MakerFile(fileName, project, version, smodules, codes, modules, paramList, fileList, pages, bottoms);
  93. }
  94. return "ok";
  95. }
  96. catch (Exception ex)
  97. {
  98. Utils.WriteLog(DateTime.Now.ToString() + "--" + ex, "生成异常");
  99. return "";
  100. }
  101. }
  102. }
  103. }