Selaa lähdekoodia

Merge branch 'develop' of http://192.168.1.222:3000/duhongyu/HeBi12345_API into develop

# Conflicts:
#	CallCenterCommon/CallCenter.QuartzService/QuartzWorker.cs
duhongyu 3 vuotta sitten
vanhempi
commit
ab14a3f603

+ 25 - 0
CallCenterApi/CallCenterApi.Common/CommonHelper.cs

@@ -6,6 +6,7 @@ using CallCenter.Utility;
6 6
 using System.Text.RegularExpressions;
7 7
 using System.Net;
8 8
 using System.IO;
9
+using System.Net.NetworkInformation;
9 10
 
10 11
 namespace CallCenterApi.Common
11 12
 {
@@ -299,5 +300,29 @@ namespace CallCenterApi.Common
299 300
             string signcode = EncryptHelper.MD5Encrypt(controller.ToLower() + "/" + action.ToLower() + "+" + EncryptHelper.SHA1Encrypt(sign + "+" + DateTime.Now.ToString("yyyyMMdd")));
300 301
             return signcode;
301 302
         }
303
+
304
+        /// <summary>
305
+        /// 判断IP是否被占用
306
+        /// </summary>
307
+        /// <param name="port"></param>
308
+        /// <returns></returns>
309
+        public static bool PortInUse(int port)
310
+        {
311
+            bool inUse = false;
312
+
313
+            IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
314
+            IPEndPoint[] ipEndPoints = ipProperties.GetActiveTcpListeners();
315
+
316
+            foreach (IPEndPoint endPoint in ipEndPoints)
317
+            {
318
+                if (endPoint.Port == port)
319
+                {
320
+                    inUse = true;
321
+                    break;
322
+                }
323
+            }
324
+
325
+            return inUse;
326
+        }
302 327
     }
303 328
 }

+ 3 - 0
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Configs/system.config

@@ -131,4 +131,7 @@
131 131
   <add key="AREACODE" value="410600" />
132 132
 
133 133
 <add key="Affairs" value="0" />
134
+
135
+  <!-- 定时任务端口 -->
136
+  <add key="quartz_port" value="556" />
134 137
 </appSettings>

+ 27 - 6
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Global.asax.cs

@@ -1,10 +1,10 @@
1 1
 using CallCenter.QuartzService;
2 2
 using CallCenter.Utility;
3 3
 using CallCenterApi.Common;
4
-using CallCenterApi.Interface.Models.Common;
5 4
 using System;
6 5
 using System.Collections.Generic;
7 6
 using System.Linq;
7
+using System.Threading.Tasks;
8 8
 using System.Web;
9 9
 using System.Web.Mvc;
10 10
 using System.Web.Routing;
@@ -22,12 +22,33 @@ namespace CallCenterApi.Interface
22 22
             RouteConfig.RegisterRoutes(RouteTable.Routes);
23 23
             //clq 增加异常日志记录 自定义 HandleErrorAttribute
24 24
             FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
25
-            _worker = new QuartzWorker();
26
-            var PushWorkorder = new PushWorkorder();
27
-            _worker.AddWork(PushWorkorder);
28
-            _worker.Start();
25
+
26
+            int port = Int32.Parse(Configs.GetValue("quartz_port"));
27
+            Task.Run(() =>
28
+            {
29
+                //IIS直接更新dll有可能end事件晚于start事件,因此延迟1分钟启动定时任务
30
+                Task.Delay(TimeSpan.FromMinutes(1)).Wait();
31
+                if (!CommonHelper.PortInUse(port))
32
+                {
33
+                    _worker = new QuartzWorker(port);
34
+                    _worker.AddWork(new PushWorkorder());
35
+                    _worker.Start();
36
+                }
37
+
38
+            }).ContinueWith(p =>
39
+            {
40
+                System.Diagnostics.Debug.WriteLine(DateTime.Now);
41
+            });
29 42
         }
30
-     
43
+
44
+        protected void Application_End()
45
+        {
46
+            if (_worker != null)
47
+            {
48
+                _worker.Stop();
49
+            }
50
+        }
51
+
31 52
 
32 53
         protected void Application_AuthenticateRequest(object sender, EventArgs e)
33 54
         {

+ 2 - 2
CallCenterCommon/CallCenter.QuartzService/QuartzWorker.cs

@@ -8,7 +8,7 @@ namespace CallCenter.QuartzService
8 8
     public class QuartzWorker
9 9
     {
10 10
         readonly IScheduler _scheduler;
11
-        public QuartzWorker()
11
+        public QuartzWorker(int port)
12 12
         {
13 13
             var properties = new NameValueCollection();
14 14
             //properties["quartz.scheduler.instanceName"] = "RemoteServerSchedulerClient";
@@ -19,7 +19,7 @@ namespace CallCenter.QuartzService
19 19
 
20 20
             // 远程输出配置
21 21
             properties["quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Quartz";
22
-            properties["quartz.scheduler.exporter.port"] = "6764";
22
+            properties["quartz.scheduler.exporter.port"] = port.ToString();
23 23
             properties["quartz.scheduler.exporter.bindName"] = "QuartzScheduler";
24 24
             properties["quartz.scheduler.exporter.channelType"] = "tcp";
25 25