Commit bb5d445d 刘韬

添加动态变换端口, 新端口记录到注册表

1 个父辈 f5152a5a
using System;
using Microsoft.Win32;
using System;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Windows.Forms;
namespace ScanCodeServer
{
......@@ -9,22 +11,37 @@ namespace ScanCodeServer
private static WebServiceHost _serviceHost;
public static bool IsOpen { private set; get; }
static WebWork service = new WebWork();
static int errcount = 0;
public static void Open(string url)
{
var u = new Uri(url);
try
{
WebWork service = new WebWork();
_serviceHost = new WebServiceHost(service, new Uri(url));
_serviceHost = new WebServiceHost(service, u);
_serviceHost.Open();
Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\ScanCodeServer\\", "port", u.Port);
Common.log.Info("Web服务已开启,URL=" + url);
IsOpen = true;
}
catch (AddressAlreadyInUseException ex)
{
Common.log.Info("端口:"+ u.Port + " 被占用");
errcount++;
if (errcount > 20)
{
Environment.Exit(99);
return;
}
Random a = new Random((int)DateTime.Now.Ticks);
var nu = "http://0.0.0.0:"+ a.Next(40000, 60000)+"/";
Open(nu);
}
catch (Exception ex)
{
Common.log.Error("WebService Open", ex);
IsOpen = false;
Environment.Exit(98);
}
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!