Browse Source

定时任务端口处理

zhoufan 3 years ago
parent
commit
ca42ef7312

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

7
 using System.Net;
7
 using System.Net;
8
 using System.IO;
8
 using System.IO;
9
 using System.Collections.Generic;
9
 using System.Collections.Generic;
10
+using System.Net.NetworkInformation;
10
 
11
 
11
 namespace CallCenterApi.Common
12
 namespace CallCenterApi.Common
12
 {
13
 {
273
             }
274
             }
274
         }
275
         }
275
 
276
 
277
+        /// <summary>
278
+        /// 网络文件是否存在
279
+        /// </summary>
280
+        /// <param name="url"></param>
281
+        /// <returns></returns>
276
         public static bool FileIsExist(string url)
282
         public static bool FileIsExist(string url)
277
         {
283
         {
278
             try
284
             try
338
 
344
 
339
             return Params.ToJson();
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
   <add key="APP_SECRET" value="900a640b37e84a8c88ffc83d6f3500f6" />
118
   <add key="APP_SECRET" value="900a640b37e84a8c88ffc83d6f3500f6" />
119
   <add key="Rmwurl" value="http://liuyan-api.people.com.cn/api" />
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
 </appSettings>
126
 </appSettings>

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

22
             RouteConfig.RegisterRoutes(RouteTable.Routes);
22
             RouteConfig.RegisterRoutes(RouteTable.Routes);
23
             //clq 增加异常日志记录 自定义 HandleErrorAttribute
23
             //clq 增加异常日志记录 自定义 HandleErrorAttribute
24
             FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
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
         protected void Application_End()
35
         protected void Application_End()
33
         {
36
         {

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

2
 using Quartz.Impl;
2
 using Quartz.Impl;
3
 using Quartz.Impl.Triggers;
3
 using Quartz.Impl.Triggers;
4
 using Quartz;
4
 using Quartz;
5
+using CallCenter.Utility;
5
 
6
 
6
 namespace CallCenter.QuartzService
7
 namespace CallCenter.QuartzService
7
 {
8
 {
19
 
20
 
20
             // 远程输出配置
21
             // 远程输出配置
21
             properties["quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Quartz";
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
             properties["quartz.scheduler.exporter.bindName"] = "QuartzScheduler";
24
             properties["quartz.scheduler.exporter.bindName"] = "QuartzScheduler";
24
             properties["quartz.scheduler.exporter.channelType"] = "tcp";
25
             properties["quartz.scheduler.exporter.channelType"] = "tcp";
25
 
26