|
|
|
|
using log4net;
|
|
|
|
|
using log4net.Config;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.ServiceProcess;
|
|
|
|
|
using SuperSocket.SocketEngine;
|
|
|
|
|
using POSV.Service;
|
|
|
|
|
using POSV.WindowsService.Core.Utils;
|
|
|
|
|
using POSV.WindowsService.Logging;
|
|
|
|
|
using System.Data.SQLite;
|
|
|
|
|
|
|
|
|
|
namespace POSV.WindowsService
|
|
|
|
|
{
|
|
|
|
|
static class Program
|
|
|
|
|
{
|
|
|
|
|
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 应用程序的主入口点。
|
|
|
|
|
/// </summary>
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
//数据库去密码
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ChangePwd("");
|
|
|
|
|
NLog.LogManager.GetCurrentClassLogger().Info("sqliteNoP success");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
NLog.LogManager.GetCurrentClassLogger().Info("sqliteNoP error, already success!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//初始化配置参数
|
|
|
|
|
Global.Instance.InitConfig();
|
|
|
|
|
|
|
|
|
|
//启动定时任务
|
|
|
|
|
JobUtils.Startup();
|
|
|
|
|
|
|
|
|
|
var server = new MessagingServer();
|
|
|
|
|
|
|
|
|
|
if (System.Environment.UserInteractive)
|
|
|
|
|
{
|
|
|
|
|
string parameter = string.Concat(args);
|
|
|
|
|
switch (parameter)
|
|
|
|
|
{
|
|
|
|
|
case "--install":
|
|
|
|
|
ServiceHelper.InstallWindowsService();
|
|
|
|
|
break;
|
|
|
|
|
case "--uninstall":
|
|
|
|
|
ServiceHelper.UninstallWindowsService();
|
|
|
|
|
break;
|
|
|
|
|
case "--start":
|
|
|
|
|
ServiceHelper.StartService();
|
|
|
|
|
break;
|
|
|
|
|
case "--stop":
|
|
|
|
|
ServiceHelper.StopService();
|
|
|
|
|
break;
|
|
|
|
|
case "--console":
|
|
|
|
|
default:
|
|
|
|
|
{
|
|
|
|
|
server.DebugStartServer();
|
|
|
|
|
|
|
|
|
|
Console.ReadKey();
|
|
|
|
|
|
|
|
|
|
server.DebugStopServer();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ServiceBase[] ServicesToRun;
|
|
|
|
|
ServicesToRun = new ServiceBase[]{server};
|
|
|
|
|
ServiceBase.Run(ServicesToRun);
|
|
|
|
|
}
|
|
|
|
|
//关闭计划任务
|
|
|
|
|
JobUtils.Stop();
|
|
|
|
|
NLog.LogManager.GetCurrentClassLogger().Info("关闭计划任务");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ChangePwd(string pwd)
|
|
|
|
|
{
|
|
|
|
|
SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder();
|
|
|
|
|
builder.DataSource = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"data\msc.s3db");
|
|
|
|
|
builder.Password = "passwd";
|
|
|
|
|
builder.Version = 3;
|
|
|
|
|
builder.CacheSize = 10000;
|
|
|
|
|
builder.DefaultTimeout = 5000;
|
|
|
|
|
builder.PageSize = 4096;
|
|
|
|
|
builder.FailIfMissing = true;
|
|
|
|
|
builder.Pooling = true;
|
|
|
|
|
builder.DefaultIsolationLevel = System.Data.IsolationLevel.ReadCommitted;
|
|
|
|
|
builder.SyncMode = SynchronizationModes.Off;
|
|
|
|
|
builder.JournalMode = SQLiteJournalModeEnum.Truncate;
|
|
|
|
|
builder.UseUTF16Encoding = false;
|
|
|
|
|
|
|
|
|
|
using (SQLiteConnection connection = new SQLiteConnection(builder.ToString()))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
connection.Open();
|
|
|
|
|
connection.ChangePassword(pwd);
|
|
|
|
|
}
|
|
|
|
|
catch (SQLiteException ex)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
connection.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|