using System.Collections; using System.Text.RegularExpressions; using System.Web; using Common; using Customer.Source; using Infrastructure; using LitJson; using Microsoft.CodeAnalysis.CSharp.Scripting; using Model; using Services; using Util; using Util.MakeApp; namespace Tasks { public class MakeAppHelper { public readonly static MakeAppHelper Instance = new MakeAppHelper(); private MakeAppHelper() { } public void Start(string QueueName) { // RabbitMQClient.Instance.StartReceive(QueueName, content => DoWorks(content)); Thread th = new Thread(poscheck); th.IsBackground = true; th.Start(QueueName); } public void poscheck(object QueueName) { while (true) { string content = RedisServer.Cache.RPop(QueueName.ToString()); if (!string.IsNullOrEmpty(content)) { DoWorks(content); Thread.Sleep(1000); } else { Thread.Sleep(2000); } } } public void DoWorks(string content) { if (!string.IsNullOrEmpty(content)) { DoQueue(content); } } public string DoQueue(string content, bool push = true) { try { JsonData jsonObj = JsonMapper.ToObject(content); //流水号 string requestId = jsonObj["requestId"].ToString(); //附加数据,原样返回 JsonData attach = JsonMapper.ToObject(jsonObj["attach"].ToString()); string appKind = attach["appKind"].ToString(); if (appKind.EndsWith("project_sycn")) { string kind = appKind.Substring(0, appKind.IndexOf("_")); GitHelper git = new GitHelper("AppTemplate/" + kind); if (string.IsNullOrEmpty(Function.ReadInstance(kind + "_project_sycn.txt"))) { git.Clone($"https://repos.kexiaoshuang.com/omega/omega-" + kind + "-framework.git", "lichunlei", "8604515", "master"); Function.WritePage("/", kind + "_project_sycn.txt", "1"); } else { git.PullCode("lichunlei", "8604515", "lichunlei", "35013854@qq.com"); } return "ok"; } string fileName = jsonObj["data"]["fileName"].ToString(); AppProject project = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonObj["data"]["appProject"].ToString()) ?? new AppProject(); AppProjectVersion version = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonObj["data"]["appProjectVersion"].ToString()) ?? new AppProjectVersion(); List smodules = Newtonsoft.Json.JsonConvert.DeserializeObject>(jsonObj["data"]["appModules"].ToString()) ?? new List(); List modules = Newtonsoft.Json.JsonConvert.DeserializeObject>(jsonObj["data"]["appProjectModules"].ToString()) ?? new List(); List paramList = Newtonsoft.Json.JsonConvert.DeserializeObject>(jsonObj["data"]["appProjectParams"].ToString()) ?? new List(); List fileList = Newtonsoft.Json.JsonConvert.DeserializeObject>(jsonObj["data"]["appModulesFiles"].ToString()) ?? new List(); List pages = Newtonsoft.Json.JsonConvert.DeserializeObject>(jsonObj["data"]["appProjectPages"].ToString()) ?? new List(); List bottoms = Newtonsoft.Json.JsonConvert.DeserializeObject>(jsonObj["data"]["appProjectBottoms"].ToString()) ?? new List(); if (appKind == "Android") { List codes = Newtonsoft.Json.JsonConvert.DeserializeObject>(jsonObj["data"]["appModulesAndroidCode"].ToString()) ?? new List(); MakeAndroidCode.MakerFile(fileName, project, version, smodules, codes, modules, paramList, fileList, pages, bottoms); } else if (appKind == "ios") { List codes = Newtonsoft.Json.JsonConvert.DeserializeObject>(jsonObj["data"]["appModulesIosCode"].ToString()) ?? new List(); MakeAppleCode.MakerFile(fileName, project, version, smodules, codes, modules, paramList, fileList, pages, bottoms); } return "ok"; } catch (Exception ex) { Utils.WriteLog(DateTime.Now.ToString() + "--" + ex, "生成异常"); return ""; } } } }