lichunlei 5 hónapja
szülő
commit
f9dca259be
4 módosított fájl, 55 hozzáadás és 5 törlés
  1. 9 2
      Common/RabbitMQClient.cs
  2. 2 2
      Program.cs
  3. 9 1
      Task/MakeHelper.cs
  4. 35 0
      Util/Maker.cs

+ 9 - 2
Common/RabbitMQClient.cs

@@ -28,12 +28,19 @@ namespace Common
         { 
             var factory = new ConnectionFactory()
             {
-                HostName = HostName,
+                // HostName = HostName,
                 UserName = UserName,
                 Password = Password,
                 VirtualHost = VirtualHostName
             };
-            _connection = factory.CreateConnection();
+            List<AmqpTcpEndpoint> p = new List<AmqpTcpEndpoint>();
+            string[] HostNames = HostName.Split(',');
+            foreach (string subHostName in HostNames)
+            {
+                string[] subHostNameData = subHostName.Split(':');
+                p.Add(new AmqpTcpEndpoint(subHostNameData[0], int.Parse(subHostNameData[1])));
+            }
+            _connection = factory.CreateConnection(p);
         }
 
         #region 单对单接收

+ 2 - 2
Program.cs

@@ -128,7 +128,7 @@ app.MapControllers();
 app.Urls.Add("http://*:8007");
 
 
-// MakeHelper.Instance.Start("MakeQueue");
-// RabbitMQClient.Instance.Conn("MakeCallBackQueue");
+RabbitMQClient.Instance.Conn("MakeQueue");
+MakeHelper.Instance.Start("MakeQueue");
 
 app.Run();

+ 9 - 1
Task/MakeHelper.cs

@@ -1,5 +1,6 @@
 using System.Collections;
 using System.Text.RegularExpressions;
+using System.Web;
 using Common;
 using Infrastructure;
 using LitJson;
@@ -49,10 +50,17 @@ namespace Tasks
             var template = templateService.GetFirst(m => m.templateName == modePath);
             if(template == null) return;
             string templateString = template.templateContent;
+            templateString = HttpUtility.UrlDecode(templateString);
             //解析模板内容
             string resultString = Util.Maker.StartMake(jsonObj["data"], templateString);
+            //生成文件
+            string path = template.makePath.Substring(0, template.makePath.LastIndexOf("/") + 1);
+            string fileName = template.makePath.Substring(template.makePath.LastIndexOf("/") + 1);
+            path = Util.Maker.replaceKeyToValue(jsonObj["data"], path);
+            fileName = Util.Maker.replaceKeyToValue(jsonObj["data"], fileName);
+            Function.WritePage(path, fileName, resultString);
             //MQ回调解析的结果
-            RabbitMQClient.Instance.Push("MakeSqlCallBackQueue", requestId + "#cut#" + attach + "#cut#" + resultString);
+            // RabbitMQClient.Instance.Push("MakeSqlCallBackQueue", requestId + "#cut#" + attach + "#cut#" + resultString);
         }
 
     }

+ 35 - 0
Util/Maker.cs

@@ -173,6 +173,41 @@ namespace Util
             return content;
         }
         #endregion
+
+        #region 读取模版数据,替换对应的标签内容
+        public static string replaceKeyToValue(JsonData jsonObj, string templateString)
+        {
+            MatchCollection mc = Regex.Matches(templateString, "<<.*?>>");
+            foreach (Match m in mc)
+            {
+                string matchValue = m.Value;
+                string key = matchValue.Replace("<<", "").Replace(">>", "");
+                string[] keyArr = key.Split('.');
+                if (keyArr.Length == 1)
+                {
+                    if (jsonObj[key] != null)
+                    {
+                        templateString = templateString.Replace(matchValue, jsonObj[key].ToString());
+                    }
+                }
+                else if (keyArr.Length == 2)
+                { 
+                    if (jsonObj[keyArr[0]] != null && jsonObj[keyArr[0]][keyArr[1]] != null)
+                    {
+                        templateString = templateString.Replace(matchValue, jsonObj[keyArr[0]][keyArr[1]].ToString());
+                    }
+                }
+                else if (keyArr.Length == 3)
+                {
+                    if (jsonObj[keyArr[0]] != null && jsonObj[keyArr[0]][keyArr[1]] != null && jsonObj[keyArr[0]][keyArr[1]][keyArr[2]] != null)
+                    {
+                        templateString = templateString.Replace(matchValue, jsonObj[keyArr[0]][keyArr[1]][keyArr[2]].ToString());
+                    }
+                }
+            }
+            return templateString;
+        }
+        #endregion
     
     }
 }