Przeglądaj źródła

定时任务端口处理

zhoufan 3 lat temu
rodzic
commit
ca42ef7312

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

@@ -7,6 +7,7 @@ using System.Text.RegularExpressions;
7 7
 using System.Net;
8 8
 using System.IO;
9 9
 using System.Collections.Generic;
10
+using System.Net.NetworkInformation;
10 11
 
11 12
 namespace CallCenterApi.Common
12 13
 {
@@ -273,6 +274,11 @@ namespace CallCenterApi.Common
273 274
             }
274 275
         }
275 276
 
277
+        /// <summary>
278
+        /// 网络文件是否存在
279
+        /// </summary>
280
+        /// <param name="url"></param>
281
+        /// <returns></returns>
276 282
         public static bool FileIsExist(string url)
277 283
         {
278 284
             try
@@ -338,5 +344,29 @@ namespace CallCenterApi.Common
338 344
 
339 345
             return Params.ToJson();
340 346
         }
347
+
348
+        /// <summary>
349
+        /// 判断IP是否被占用
350
+        /// </summary>
351
+        /// <param name="port"></param>
352
+        /// <returns></returns>
353
+        public static bool PortInUse(int port)
354
+        {
355
+            bool inUse = false;
356
+
357
+            IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
358
+            IPEndPoint[] ipEndPoints = ipProperties.GetActiveTcpListeners();
359
+
360
+            foreach (IPEndPoint endPoint in ipEndPoints)
361
+            {
362
+                if (endPoint.Port == port)
363
+                {
364
+                    inUse = true;
365
+                    break;
366
+                }
367
+            }
368
+
369
+            return inUse;
370
+        }
341 371
     }
342 372
 }

+ 5 - 1
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Configs/system.config

@@ -118,5 +118,9 @@
118 118
   <add key="APP_SECRET" value="900a640b37e84a8c88ffc83d6f3500f6" />
119 119
   <add key="Rmwurl" value="http://liuyan-api.people.com.cn/api" />
120 120
 
121
-  <add key="AppUrl" value="http://111.6.36.62:8001" />       
121
+  <add key="AppUrl" value="http://111.6.36.62:8001" />    
122
+
123
+
124
+  <!--定时任务端口号-->
125
+  <add key="quartz_port" value="6674" />
122 126
 </appSettings>

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

@@ -22,12 +22,15 @@ namespace CallCenterApi.Interface
22 22
             RouteConfig.RegisterRoutes(RouteTable.Routes);
23 23
             //clq 增加异常日志记录 自定义 HandleErrorAttribute
24 24
             FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
25
-            _worker = new QuartzWorker();
26
-            _worker.AddWork(new SatisfactionClose());
27
-            _worker.AddWork(new ZhengWuDuiJie());
28
-            _worker.AddWork(new Peoplewebsite());
29
-            //_worker.AddWork(new PushWorkorder());
30
-            _worker.Start();
25
+            if (!CommonHelper.PortInUse(Int32.Parse(Configs.GetValue("quartz_port"))))
26
+            {
27
+                _worker = new QuartzWorker();
28
+                _worker.AddWork(new SatisfactionClose());
29
+                _worker.AddWork(new ZhengWuDuiJie());
30
+                _worker.AddWork(new Peoplewebsite());
31
+                //_worker.AddWork(new PushWorkorder());
32
+                _worker.Start();
33
+            }
31 34
         }
32 35
         protected void Application_End()
33 36
         {

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

@@ -2,6 +2,7 @@
2 2
 using Quartz.Impl;
3 3
 using Quartz.Impl.Triggers;
4 4
 using Quartz;
5
+using CallCenter.Utility;
5 6
 
6 7
 namespace CallCenter.QuartzService
7 8
 {
@@ -19,7 +20,7 @@ namespace CallCenter.QuartzService
19 20
 
20 21
             // 远程输出配置
21 22
             properties["quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Quartz";
22
-            properties["quartz.scheduler.exporter.port"] = "6674";
23
+            properties["quartz.scheduler.exporter.port"] = Configs.GetValue("quartz_port");
23 24
             properties["quartz.scheduler.exporter.bindName"] = "QuartzScheduler";
24 25
             properties["quartz.scheduler.exporter.channelType"] = "tcp";
25 26