From e6fcb147dd27a8e82d7245723767eacc085f630e Mon Sep 17 00:00:00 2001 From: DigitalPlatform Date: Mon, 12 Sep 2016 13:53:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=20dp2mserver=20=E9=A6=96?= =?UTF-8?q?=E6=AC=A1=E5=AE=89=E8=A3=85=E7=9A=84=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=8A=A8=E5=88=9B=E5=BB=BA=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=9B=AE=E5=BD=95=E4=B8=AD=20config.xml=20=E7=9A=84?= =?UTF-8?q?=E5=8A=A8=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vs/config/applicationhost.config | 6 ++--- DigitalPlatform.MessageServer/ServerInfo.cs | 22 ++++++++++++++++++ dp2MServer/Program.cs | 25 +++++++++++---------- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/.vs/config/applicationhost.config b/.vs/config/applicationhost.config index fe6aaf88..9f3e75be 100644 --- a/.vs/config/applicationhost.config +++ b/.vs/config/applicationhost.config @@ -163,7 +163,7 @@ - + @@ -187,7 +187,7 @@ - + @@ -195,7 +195,7 @@ - + diff --git a/DigitalPlatform.MessageServer/ServerInfo.cs b/DigitalPlatform.MessageServer/ServerInfo.cs index 9ab6798e..0dba4ed2 100644 --- a/DigitalPlatform.MessageServer/ServerInfo.cs +++ b/DigitalPlatform.MessageServer/ServerInfo.cs @@ -57,6 +57,28 @@ static string AutoTriggerUrl set; } + public static void CreateCfgFile(string strCfgFileName, + string strMongoDbConnStr = "", + string strMongoDbInstancePrefix = "") + { + // 默认值 + if (string.IsNullOrEmpty(strMongoDbConnStr)) + strMongoDbConnStr = "mongodb://localhost"; + if (string.IsNullOrEmpty(strMongoDbInstancePrefix)) + strMongoDbInstancePrefix = "mserver"; + + XmlDocument dom = new XmlDocument(); + dom.LoadXml(""); + + XmlElement mongoDB = dom.CreateElement("mongoDB"); + dom.DocumentElement.AppendChild(mongoDB); + + mongoDB.SetAttribute("connectionString", strMongoDbConnStr); + mongoDB.SetAttribute("instancePrefix", strMongoDbInstancePrefix); + + dom.Save(strCfgFileName); + } + public static void Initial(InitialParam param) { AutoTriggerUrl = param.AutoTriggerUrl; diff --git a/dp2MServer/Program.cs b/dp2MServer/Program.cs index e30cf48c..a67d6c3c 100644 --- a/dp2MServer/Program.cs +++ b/dp2MServer/Program.cs @@ -1,28 +1,19 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Reflection; using System.Threading.Tasks; -using System.Threading; using System.ServiceProcess; -using System.Runtime.InteropServices; using System.Diagnostics; -using System.Security.Principal; -// using System.Configuration; -using System.IO; using Owin; using Microsoft.Owin.Cors; using Microsoft.Owin.Hosting; using Microsoft.AspNet.SignalR; - -using dp2MServer.Properties; +using Microsoft.Owin; using DigitalPlatform.MessageServer; using DigitalPlatform.ServiceProcess; -using DigitalPlatform.Xml; -using Microsoft.Owin; +using System.IO; +using DigitalPlatform.IO; namespace dp2MServer { @@ -116,7 +107,17 @@ static void Main(string[] args) AutoTriggerUrl = strValue; } + string strCfgFileName = Path.Combine(DataDir, "config.xml"); + SaveConfig(); + + // 创建数据目录中的 config.xml 配置文件 + if (File.Exists(strCfgFileName) == false) + { + PathUtil.CreateDirIfNeed(Path.GetDirectoryName(strCfgFileName)); + ServerInfo.CreateCfgFile(strCfgFileName); + Console.WriteLine("首次创建配置文件 " + strCfgFileName); + } #if NO Console.WriteLine("(直接回车表示不修改当前值)"); Console.WriteLine("请输入服务器 URI: (当前值为 " + Settings.Default.ServerURI + ")");