| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896 |
- using System;
- using System.Data;
- using System.Linq;
- using System.Net;
- using System.ServiceModel;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Windows.Forms;
- using System.Xml.Linq;
- using Curtain.DataAccess;
- using Curtain.Log;
- using Dongke.IBOSS.PRD.Basics.BaseResources;
- using Dongke.IBOSS.PRD.Basics.DataAccess;
- using Dongke.IBOSS.PRD.Basics.Library;
- using Dongke.IBOSS.PRD.WCF.Services;
- namespace Dongke.IBOSS.PRD.WCF.Hosting
- {
- public partial class ConfigMain : Form
- {
- private bool _isClose = false;
- private SynchronizationContext _syncContext;
- private string _formTitle = "[{0}]" + Constant.M_SYSTEM_NAME + "服务器端配置及服务-{1}";
- public ServiceHostCollection ServiceHosts
- {
- get;
- private set;
- }
- public ConfigMain()
- {
- InitializeComponent();
- txtExePath.Text = System.AppDomain.CurrentDomain.BaseDirectory;
- _syncContext = SynchronizationContext.Current;
- //ServiceInvoker.ServiceDoingEvent += DKIMSSWCFService_ServiceDoingEvent;
- //ServiceInvoker.ServiceDoneEvent += DKIMSSWCFService_ServiceDoneEvent;
- //ServiceInvoker.ServiceExceptionEvent += DKIMSSWCFService_ServiceExceptionEvent;
- Logger.DefaultLogDirectory = "Log";
- // 启动内存回收(每小时)
- timer1.Interval = 1000 * 60 * 60;
- timer1.Start();
- }
- #region 事件
- private void ConfigMain_Load(object sender, EventArgs e)
- {
- try
- {
- GetPublishConfig();
- GetProgramSetting();
- // 获取数据库配置信息
- GetDBSetting();
- GetLocalIPAddress();
- GetInternetIPAddress();
- this.butSopt.Enabled = false;
- this.tsmiStop.Enabled = false;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- /// <summary>
- /// 启动服务方法
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void butStart_Click(object sender, EventArgs e)
- {
- try
- {
- Application.DoEvents();
- this.txtLogInfo.Text = "服务开始准备启动!" + Environment.NewLine;
- IsCheckInfo();
- SetProgramSetting();
- WCFStart();
- GetLocalIPAddress();
- GetInternetIPAddress();
- MessageBox.Show("服务器WCF服务启动成功。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.butStart.Enabled = false;
- this.butSopt.Enabled = true;
- this.tsmiStart.Enabled = false;
- this.tsmiStop.Enabled = true;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message.ToString());
- LogFileOperation.Error(ConfigConst.LogFileName, ex.ToString());
- }
- }
- /// <summary>
- /// 服务重新启动方法
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void butReStart_Click(object sender, EventArgs e)
- {
- try
- {
- Application.DoEvents();
- this.txtLogInfo.Text = "服务开始准备重新启动。" + Environment.NewLine;
- IsCheckInfo();
- SetProgramSetting();
- WCFStart();
- GetLocalIPAddress();
- GetInternetIPAddress();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message.ToString());
- LogFileOperation.Error(ConfigConst.LogFileName, ex.ToString());
- }
- }
- /// <summary>
- /// 服务停止方法
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void butSopt_Click(object sender, EventArgs e)
- {
- try
- {
- Application.DoEvents();
- this.txtLogInfo.Text = "服务开始准备关闭。" + Environment.NewLine;
- WCFStop();
- MessageBox.Show("服务器WCF服务停止成功。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.butStart.Enabled = true;
- this.butSopt.Enabled = false;
- this.tsmiStart.Enabled = true;
- this.tsmiStop.Enabled = false;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message.ToString());
- LogFileOperation.Error(ConfigConst.LogFileName, ex.ToString());
- }
- }
- /// <summary>
- /// 显示日志方法
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void butShowLog_Click(object sender, EventArgs e)
- {
- try
- {
- var logBity = LogFileOperation.ReadFile(ConfigConst.LogFileName);
- this.txtLogInfo.Text = System.Text.Encoding.UTF8.GetString(logBity);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- /// <summary>
- /// 清空日志方法
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void butClearLog_Click(object sender, EventArgs e)
- {
- try
- {
- this.txtLogInfo.Clear();
- LogFileOperation.DeleteLogFile(ConfigConst.LogFileName);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- /// <summary>
- /// 关闭窗体
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void butClose_Click(object sender, EventArgs e)
- {
- //DialogResult exitDialogResult = MessageBox.Show("退出本服务程序,服务器的WCF服务将会停止。\r\n确定要退出本服务程序吗?",
- // this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
- //if (exitDialogResult == DialogResult.Yes)
- //{
- // if (this.ServiceHosts != null)
- // {
- // DialogResult dialogResult = MessageBox.Show("WCF服务正在运行中,是否强行停止?",
- // this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
- // if (dialogResult == DialogResult.Yes)
- // {
- // this.WCFStop();
- // }
- // else
- // {
- // return;
- // }
- // }
- // this._isClose = true;
- // this.Close();
- //}
- //else
- //{
- // return;
- //}
- if (this.ServiceHosts != null)
- {
- DialogResult dialogResult = MessageBox.Show("WCF服务正在运行中,退出后服务将会停止。\r\n确定要退出本服务程序?",
- this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
- if (dialogResult == DialogResult.OK)
- {
- this.WCFStop();
- this._isClose = true;
- this.Close();
- }
- else
- {
- return;
- }
- }
- else
- {
- DialogResult exitDialogResult = MessageBox.Show("确定要退出本服务程序?",
- this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
- if (exitDialogResult == DialogResult.OK)
- {
- this._isClose = true;
- this.Close();
- }
- else
- {
- return;
- }
- }
- }
- /// <summary>
- /// 窗体关闭验证
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ConfigMain_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (this._isClose)
- {
- if (this.ServiceHosts != null)
- {
- e.Cancel = true;
- this._isClose = false;
- MessageBox.Show("请先停止WCF服务,然后再退出本程序。");
- this.Visible = true;
- this.WindowState = FormWindowState.Normal;
- }
- else
- {
- e.Cancel = false;
- this.notifyIcon1.Visible = false;
- }
- }
- else
- {
- e.Cancel = true;
- this.WindowState = FormWindowState.Minimized;
- this.Visible = false;
- }
- }
- /// <summary>
- /// 保存数据库配置
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnDBSave_Click(object sender, EventArgs e)
- {
- try
- {
- INIUtility.Instance(INIUtility.IniFile.Config).WriteIniData("DBSetting", "DBIP", this.txtDBIP.Text.Trim());
- INIUtility.Instance(INIUtility.IniFile.Config).WriteIniData("DBSetting", "DBPort", this.txtDBPort.Text.Trim());
- INIUtility.Instance(INIUtility.IniFile.Config).WriteIniData("DBSetting", "SID", this.txtSID.Text.Trim());
- INIUtility.Instance(INIUtility.IniFile.Config).WriteIniData("DBSetting", "DBUser", this.txtUser.Text.Trim());
- //INIUtility.Instance(INIUtility.IniFile.Config).WriteIniData("DBSetting", "DBPassword", this.txtPassword.Text.Trim());
- try
- {
- string password = Encryption.EncryptDES(this.txtPassword.Text.Trim(), Constant.S_ENCRYPTION_KEY);
- INIUtility.Instance(INIUtility.IniFile.Config).WriteIniData("DBSetting", "DBPassword", password);
- }
- catch
- {
- }
- // 更改连接串
- DataManager.ConnectionString = string.Format(DataManager.ConnectionStringFormat,
- this.txtDBIP.Text.Trim(),
- this.txtDBPort.Text.Trim(),
- this.txtSID.Text.Trim(),
- this.txtUser.Text.Trim(),
- this.txtPassword.Text.Trim()
- );
- DataAccess.DefaultDataBaseType = Curtain.DataAccess.DataBaseType.Oracle;
- DataAccess.DefaultConnectionString = DataManager.ConnectionString;
- MessageBox.Show("数据库配置保存成功。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- catch (Exception ex)
- {
- MessageBox.Show("数据库配置保存失败。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- LogFileOperation.Error(ConfigConst.LogFileName, ex.ToString());
- }
- }
- /// <summary>
- /// 连接测试
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnDBTest_Click(object sender, EventArgs e)
- {
- #region 校验
- if (string.IsNullOrEmpty(this.txtDBIP.Text.Trim()))
- {
- MessageBox.Show("请输入数据库IP地址!");
- this.txtDBIP.Focus();
- return;
- }
- else if (string.IsNullOrEmpty(this.txtDBPort.Text.Trim()))
- {
- MessageBox.Show("请输入数据库端口号!");
- this.txtDBPort.Focus();
- return;
- }
- else if (string.IsNullOrEmpty(this.txtSID.Text.Trim()))
- {
- MessageBox.Show("请输入数据库SID!");
- this.txtSID.Focus();
- return;
- }
- else if (string.IsNullOrEmpty(this.txtUser.Text.Trim()))
- {
- MessageBox.Show("请输入用户名!");
- this.txtUser.Focus();
- return;
- }
- else if (string.IsNullOrEmpty(this.txtPassword.Text.Trim()))
- {
- MessageBox.Show("请输入密码!");
- this.txtPassword.Focus();
- return;
- }
- //string strIpRegEdp = @"^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$";
- //Regex regEdpIP = new Regex(strIpRegEdp, RegexOptions.None);
- //if (!regEdpIP.IsMatch(this.txtDBIP.Text.Trim()))
- //{
- // MessageBox.Show("数据库IP地址不符合IP规则!");
- // this.txtDBIP.Focus();
- // return;
- //}
- #endregion
- // 连接串
- string conStr = string.Format(DataManager.ConnectionStringFormat,
- this.txtDBIP.Text.Trim(),
- this.txtDBPort.Text.Trim(),
- this.txtSID.Text.Trim(),
- this.txtUser.Text.Trim(),
- this.txtPassword.Text.Trim()
- );
- //IDBConnection oracleConn = ClsDbFactory.CreateDBConnection(DataBaseType.ORACLE, conStr);
- //try
- //{
- // oracleConn.Open();
- // string sql = "select 1 from dual";
- // DataSet returnDataSet = oracleConn.GetSqlResultToDs(sql);
- // DialogResult dialogResult = MessageBox.Show("数据库连接测试成功。\r\n是否保存数据库配置?",
- // this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- // if (DialogResult.Yes == dialogResult)
- // {
- // this.btnDBSave_Click(sender, e);
- // }
- //}
- //catch (Exception ex)
- //{
- // MessageBox.Show("数据库连接测试失败。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- // LogFileOperation.Error(ConfigConst.LogFileName, ex.ToString());
- //}
- //finally
- //{
- // if (oracleConn.ConnState == ConnectionState.Open)
- // {
- // oracleConn.Close();
- // }
- //}
- IDataAccess dataAccess = null;
- try
- {
- dataAccess = DataAccess.Create(Curtain.DataAccess.DataBaseType.Oracle, conStr);
- dataAccess.ExecuteScalar("select sysdate from dual");
- DialogResult dialogResult = MessageBox.Show("数据库连接测试成功。\r\n是否保存数据库配置?",
- this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- if (DialogResult.Yes == dialogResult)
- {
- this.btnDBSave_Click(sender, e);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("数据库连接测试失败。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- LogFileOperation.Error(ConfigConst.LogFileName, ex.ToString());
- }
- finally
- {
- dataAccess?.Close();
- }
- }
- #endregion
- #region 自定义方法
- /// <summary>
- /// 获取系统配置相关信息
- /// </summary>
- public void GetPublishConfig()
- {
- try
- {
- ConfigConst.StartupPath = System.Windows.Forms.Application.StartupPath;
- #region 获取对应的配置信息
- ConfigConst.LogControl = false;
- //if (System.Configuration.ConfigurationManager.AppSettings["LogControl"] != null)
- //{
- // ConfigConst.LogControl = System.Configuration.ConfigurationManager.AppSettings["LogControl"].ToString().Trim().ToUpper().Equals("TRUE") ? true : false;
- ConfigConst.LogControl = INIUtility.Instance(INIUtility.IniFile.Config).ReadIniData("LogSetting", "LogControl").ToUpper().Equals("TRUE") ? true : false;
- //}
- ///日志文件
- //if (System.Configuration.ConfigurationManager.AppSettings["LogFileName"] != null)
- //{
- // ConfigConst.LogFileName = System.Configuration.ConfigurationManager.AppSettings["LogFileName"].Trim();
- ConfigConst.LogFileName = INIUtility.Instance(INIUtility.IniFile.Config).ReadIniData("LogSetting", "LogFileName");
- //}
- //配置文件名称
- //if (System.Configuration.ConfigurationManager.AppSettings["ConfigFileName"] != null)
- //{
- // ConfigConst.ConfigFileName = System.Configuration.ConfigurationManager.AppSettings["ConfigFileName"].Trim();
- //}
- #endregion
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 获取程序所需要的配置信息并显示在对应的控件中
- /// </summary>
- public void GetProgramSetting()
- {
- this.txtWcfIp.Text = INIUtility.Instance(INIUtility.IniFile.Config).ReadIniData("WCFSetting", "WCFIP");//System.Configuration.ConfigurationManager.AppSettings["WCFIP"].Trim();
- this.txtWcfPort.Text = INIUtility.Instance(INIUtility.IniFile.Config).ReadIniData("WCFSetting", "WCFPort");//System.Configuration.ConfigurationManager.AppSettings["WCFPort"].Trim();
- this.txtServerName.Text = INIUtility.Instance(INIUtility.IniFile.Config).ReadIniData("WCFSetting", "ServerName");
- string v = INIUtility.Instance(INIUtility.IniFile.Config).ReadIniData("VersionSetting", "ClientVersion");
- this.Text = string.Format(this._formTitle, this.txtServerName.Text, v);
- this.notifyIcon1.Text = "【" + this.txtServerName.Text + "】" + Constant.M_SYSTEM_NAME + "-" + v;//this.Text;
- }
- /// <summary>
- /// 根据XML节点名称获取对应的数据
- /// </summary>
- /// <param name="pXMLOperate"></param>
- /// <param name="pNodeName"></param>
- /// <returns></returns>
- public string GetXElementName(XDocument pXDocument, string pNodeName)
- {
- try
- {
- XElement xelemnt = (from p in pXDocument.Root.Elements() where p.Name == pNodeName select p).FirstOrDefault();
- if (xelemnt == null)
- return "";
- return xelemnt.Value;
- }
- catch (Exception ex)
- {
- LogFileOperation.Error(ConfigConst.LogFileName, ex.ToString());
- throw ex;
- }
- }
- /// <summary>
- /// 获取XML中对应的节点
- /// </summary>
- /// <param name="pXDocument"></param>
- /// <param name="pNodeName"></param>
- /// <returns></returns>
- public XElement GetFirstNode(XDocument pXDocument, string pNodeName)
- {
- try
- {
- XElement xelemnt = (from p in pXDocument.Root.Elements() where p.Name == pNodeName select p).FirstOrDefault();
- return xelemnt;
- }
- catch (Exception ex)
- {
- LogFileOperation.Error(ConfigConst.LogFileName, ex.ToString());
- throw ex;
- }
- }
- /// <summary>
- /// 保存数据的验证处理
- /// </summary>
- public void IsCheckInfo()
- {
- string strWcfIp = this.txtWcfIp.Text.Trim();
- if (string.IsNullOrEmpty(strWcfIp))
- {
- throw new Exception("WCF服务的主机IP地址不能为空。");
- }
- string strIpRegEdp = @"^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$";
- Regex regEdpIP = new Regex(strIpRegEdp, RegexOptions.None);
- if (!regEdpIP.IsMatch(strWcfIp))
- {
- throw new Exception("WCF服务的主机IP地址不符合IP地址规则。");
- }
- string strWcfPort = this.txtWcfPort.Text.Trim();
- if (string.IsNullOrEmpty(strWcfPort))
- {
- throw new Exception("WCF服务的主机端口号不能为空。");
- }
- var strPortRegEdp = @"/^[1-9]$|(^[1-9][0-9]$)|(^[1-9][0-9][0-9]$)|(^[1-9][0-9][0-9][0-9]$)|(^[1-6][0-5][0-5][0-3][0-5]$)/";
- Regex regEdpPort = new Regex(strPortRegEdp, RegexOptions.None);
- if (!regEdpPort.IsMatch(strWcfPort))
- {
- throw new Exception("WCF服务的主机端口号不符合端口号规则。");
- }
- }
- /// <summary>
- /// 保存设置到XML文件
- /// </summary>
- public void SetProgramSetting()
- {
- INIUtility.Instance(INIUtility.IniFile.Config).WriteIniData("WCFSetting", "WCFIP", this.txtWcfIp.Text.Trim());
- INIUtility.Instance(INIUtility.IniFile.Config).WriteIniData("WCFSetting", "WCFPort", this.txtWcfPort.Text.Trim());
- }
- /// <summary>
- /// 添加数据到XML集合中
- /// </summary>
- /// <param name="pXMLOperate"></param>
- /// <param name="pNodeName"></param>
- /// <param name="pNameValue"></param>
- public void SetXElementName(XDocument pXDocument, string pNodeName, string pNameValue)
- {
- try
- {
- XElement xmlElem = GetFirstNode(pXDocument, pNodeName);
- if (xmlElem != null)
- {
- xmlElem.Value = pNameValue;
- }
- else
- {
- XElement tempXElem = new XElement(pNodeName);
- tempXElem.Value = pNameValue;
- pXDocument.Root.Add(tempXElem);
- }
- }
- catch (Exception ex)
- {
- LogFileOperation.Error(ConfigConst.LogFileName, ex.ToString());
- throw ex;
- }
- }
- public void WCFStart()
- {
- try
- {
- if (this.ServiceHosts != null)
- {
- this.ServiceHosts.Dispose();
- this.ServiceHosts = null;
- }
- this.ServiceHosts = new ServiceHostCollection();
- this.ServiceHosts.IP = this.txtWcfIp.Text.Trim();
- this.ServiceHosts.Port = this.txtWcfPort.Text.Trim();
- this.ServiceHosts.Init();
- foreach (ServiceHost host in ServiceHosts)
- {
- host.Opening += host_Opening;
- host.Opened += host_Opened;
- host.Closing += host_Closing;
- host.Closed += host_Closed;
- }
- ServiceHostOpen();
- }
- catch (Exception ex)
- {
- LogFileOperation.Error(ConfigConst.LogFileName, ex.ToString());
- throw ex;
- }
- }
- public void ServiceHostOpen()
- {
- try
- {
- foreach (ServiceHost host in ServiceHosts)
- {
- //
- //可以增加对控制
- //
- host.Open();
- }
- }
- catch (Exception ex)
- {
- LogFileOperation.Error(ConfigConst.LogFileName, ex.ToString());
- throw ex;
- }
- }
- public void WCFStop()
- {
- try
- {
- if (this.ServiceHosts != null)
- {
- this.ServiceHosts.Dispose();
- this.ServiceHosts = null;
- }
- }
- catch (Exception ex)
- {
- LogFileOperation.Error(ConfigConst.LogFileName, ex.ToString());
- throw ex;
- }
- }
- void host_Opening(object sender, EventArgs e)
- {
- SendOrPostCallback callback = delegate(object state)
- {
- string strInfo = "服务" + (sender as ServiceHost).BaseAddresses[0] + "打开中......";
- LogFileOperation.Fatal(ConfigConst.LogFileName, strInfo);
- this.txtLogInfo.Text += strInfo + Environment.NewLine;
- };
- _syncContext.Post(callback, null);
- }
- void host_Opened(object sender, EventArgs e)
- {
- SendOrPostCallback callback = delegate(object state)
- {
- string strInfo = "服务" + (sender as ServiceHost).BaseAddresses[0] + "打开完毕。";
- LogFileOperation.Fatal(ConfigConst.LogFileName, strInfo);
- this.txtLogInfo.Text += strInfo + Environment.NewLine;
- };
- _syncContext.Post(callback, null);
- }
- void host_Closed(object sender, EventArgs e)
- {
- SendOrPostCallback callback = delegate(object state)
- {
- string strInfo = "服务" + (sender as ServiceHost).BaseAddresses[0] + "关闭完毕。";
- LogFileOperation.Fatal(ConfigConst.LogFileName, strInfo);
- this.txtLogInfo.Text += strInfo + Environment.NewLine;
- };
- _syncContext.Post(callback, null);
- }
- void host_Closing(object sender, EventArgs e)
- {
- SendOrPostCallback callback = delegate(object state)
- {
- string strInfo = "服务" + (sender as ServiceHost).BaseAddresses[0] + "关闭中......";
- LogFileOperation.Fatal(ConfigConst.LogFileName, strInfo);
- this.txtLogInfo.Text += strInfo + Environment.NewLine;
- };
- _syncContext.Post(callback, null);
- }
- /// <summary>
- /// 服务开始
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void DKIMSSWCFService_ServiceDoingEvent(object sender, ServiceEventArgs e)
- {
- SendOrPostCallback callback = delegate(object state)
- {
- string strInfo = "服务" + e.MethodName + " 服务开始。 ";
- LogFileOperation.Fatal(ConfigConst.LogFileName, strInfo);
- };
- _syncContext.Post(callback, null);
- }
- /// <summary>
- /// 服务结束
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void DKIMSSWCFService_ServiceDoneEvent(object sender, ServiceEventArgs e)
- {
- SendOrPostCallback callback = delegate(object state)
- {
- string strInfo = "服务" + e.MethodName + " 服务结束。 ";
- LogFileOperation.Fatal(ConfigConst.LogFileName, strInfo);
- };
- _syncContext.Post(callback, null);
- }
- /// <summary>
- /// 服务异常
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void DKIMSSWCFService_ServiceExceptionEvent(object sender, ServiceEventArgs e)
- {
- //_syncContext.Post(state => txtDoing.Text += e.MethodName + " has Exception ... " + "\r\n", null);
- SendOrPostCallback callback = delegate(object state)
- {
- string strInfo = "服务" + e.MethodName + " 服务异常。 ";
- LogFileOperation.Fatal(ConfigConst.LogFileName, strInfo);
- };
- _syncContext.Post(callback, null);
- }
- /// <summary>
- /// 获取数据库配置
- /// </summary>
- private void GetDBSetting()
- {
- this.txtDBIP.Text = INIUtility.Instance(INIUtility.IniFile.Config).ReadIniData("DBSetting", "DBIP");
- this.txtDBPort.Text = INIUtility.Instance(INIUtility.IniFile.Config).ReadIniData("DBSetting", "DBPort");
- this.txtSID.Text = INIUtility.Instance(INIUtility.IniFile.Config).ReadIniData("DBSetting", "SID");
- this.txtUser.Text = INIUtility.Instance(INIUtility.IniFile.Config).ReadIniData("DBSetting", "DBUser");
- this.txtPassword.Text = INIUtility.Instance(INIUtility.IniFile.Config).ReadIniData("DBSetting", "DBPassword");
- //try
- //{
- // this.txtPassword.Text = Encryption.DecryptDES(this.txtPassword.Text.Trim(), Constant.SECRET_KEY);
- //}
- //catch
- //{
- //}
- string password = null;
- try
- {
- password = Encryption.DecryptDES(this.txtPassword.Text.Trim(), Constant.S_ENCRYPTION_KEY);
- }
- catch
- {
- }
- this.txtPassword.Text = password;
- // 更改连接串
- DataManager.ConnectionString = string.Format(DataManager.ConnectionStringFormat,
- this.txtDBIP.Text.Trim(),
- this.txtDBPort.Text.Trim(),
- this.txtSID.Text.Trim(),
- this.txtUser.Text.Trim(),
- this.txtPassword.Text.Trim()
- );
- DataAccess.DefaultDataBaseType = Curtain.DataAccess.DataBaseType.Oracle;
- DataAccess.DefaultConnectionString = DataManager.ConnectionString;
- }
- /// <summary>
- /// 内网地址
- /// </summary>
- private void GetLocalIPAddress()
- {
- string localIP = null;
- try
- {
- IPHostEntry ipHost = System.Net.Dns.GetHostEntry(Dns.GetHostName());// Dns.Resolve(Dns.GetHostName()); ;
- localIP = "unknown";
- foreach (var item in ipHost.AddressList)
- {
- localIP = item.ToString();
- //判断IP是否合法
- if (System.Text.RegularExpressions.Regex.IsMatch(localIP, "[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"))
- {
- break;
- }
- }
-
- this.lblLocalIPAddress.Text = localIP;
- }
- catch
- {
- this.lblLocalIPAddress.Text = "unknown";
- }
- }
- /// <summary>
- /// 外网地址
- /// </summary>
- private void GetInternetIPAddress()
- {
- //string internetAddress = "";
- //try
- //{
- // using (WebClient webClient = new WebClient())
- // {
- // internetAddress = webClient.DownloadString("http://www.coridc.com/ip");//从外部网页获得IP地址
- // //判断IP是否合法
- // if (!System.Text.RegularExpressions.Regex.IsMatch(internetAddress, "[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"))
- // {
- // internetAddress = webClient.DownloadString("http://fw.qq.com/ipaddress");//从腾讯提供的API中获得IP地址
- // }
- // }
- // this.lblInternetIPAddress.Text = internetAddress;
- //}
- //catch
- //{
- // this.lblInternetIPAddress.Text = "unknown";
- //}
- this.lblInternetIPAddress.Text = "unknown";
- }
- #endregion
- private void notifyIcon1_DoubleClick(object sender, EventArgs e)
- {
- if (!this.Visible)
- {
- this.Visible = true;
- //this.WindowState = FormWindowState.Normal;
- }
- this.WindowState = FormWindowState.Normal;
- this.Activate();
- }
- private void 回收ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- try
- {
- GC.Collect();
- }
- catch
- {
- }
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- try
- {
- GC.Collect();
- }
- catch
- {
- }
- }
- private void btnServerName_Click(object sender, EventArgs e)
- {
- INIUtility.Instance(INIUtility.IniFile.Config).WriteIniData("WCFSetting", "ServerName", this.txtServerName.Text.Trim());
- string v = INIUtility.Instance(INIUtility.IniFile.Config).ReadIniData("VersionSetting", "ClientVersion");
- this.Text = string.Format(this._formTitle, this.txtServerName.Text, v);
- this.notifyIcon1.Text = "【" + this.txtServerName.Text + "】" + Constant.M_SYSTEM_NAME + "-" + v;//this.Text;
- }
- private void btnOpen_Click(object sender, EventArgs e)
- {
- System.Diagnostics.Process.Start(txtExePath.Text);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- F_LicCode lc = new F_LicCode(this.txtSID.Text);
- lc.ShowDialog();
- }
- }
- }
|