1. 增加UDP消息通道

2. 增加主程序配置项
3. 格式化代码
This commit is contained in:
hzhuangxin01 2019-02-19 12:02:14 +08:00
parent e34633edea
commit 3aace68789
12 changed files with 2970 additions and 2846 deletions

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />

View File

@ -11,12 +11,12 @@ namespace GeneratorCode.Configure
{ {
public static class NConfig public static class NConfig
{ {
private static string _cfgFileName = @".\config.ini";
private static IniData _cfgData = null;
public delegate void ConfigChangedHandle(); public delegate void ConfigChangedHandle();
private static readonly string _cfgFileName = @".\config.ini";
private static IniData _cfgData;
public static event ConfigChangedHandle OnConfigChanged; public static event ConfigChangedHandle OnConfigChanged;
private static void ConfigChanged() private static void ConfigChanged()
@ -35,7 +35,7 @@ namespace GeneratorCode.Configure
ws.WriteLine("; 应用程序配置文件\n"); ws.WriteLine("; 应用程序配置文件\n");
} }
FileIniDataParser iniPraser = new FileIniDataParser(); var iniPraser = new FileIniDataParser();
iniPraser.Parser.Configuration.CommentString = ";"; iniPraser.Parser.Configuration.CommentString = ";";
_cfgData = iniPraser.ReadFile(_cfgFileName); _cfgData = iniPraser.ReadFile(_cfgFileName);
//Trace.WriteLine(_cfgData); //Trace.WriteLine(_cfgData);
@ -55,12 +55,12 @@ namespace GeneratorCode.Configure
//Trace.WriteLine("Directory: " + Path.GetDirectoryName(appPath)); //Trace.WriteLine("Directory: " + Path.GetDirectoryName(appPath));
//Trace.WriteLine("File: " + Path.GetFileName(appPath)); //Trace.WriteLine("File: " + Path.GetFileName(appPath));
var fw = new FileSystemWatcher() var fw = new FileSystemWatcher
{ {
NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite, NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite,
Filter = _cfgFileName, Filter = _cfgFileName,
Path = Path.GetDirectoryName(appPath), Path = Path.GetDirectoryName(appPath),
IncludeSubdirectories = false, IncludeSubdirectories = false
}; };
fw.Changed += (sender, e) => fw.Changed += (sender, e) =>
@ -99,10 +99,7 @@ namespace GeneratorCode.Configure
{ {
var ret = defValue; var ret = defValue;
if (_cfgData.Equals(null)) if (_cfgData.Equals(null)) return ret;
{
return ret;
}
try try
{ {
@ -112,7 +109,7 @@ namespace GeneratorCode.Configure
{ {
Trace.WriteLine("[" + _cfgData[secName][keyName] + "] :" + e.Message); Trace.WriteLine("[" + _cfgData[secName][keyName] + "] :" + e.Message);
ret = defValue; ret = defValue;
throw(e); throw e;
} }
return ret; return ret;

View File

@ -58,7 +58,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Configure\NConfig.cs" /> <Compile Include="Configure\NConfig.cs" />
<Compile Include="Logs\NLog.cs" /> <Compile Include="Logs\NLog.cs" />
<Compile Include="Program.cs" /> <Compile Include="MainCode.cs" />
<Compile Include="Properties\Annotations.cs" /> <Compile Include="Properties\Annotations.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TmatrixSDK\OIDPublishImageGenerator.cs" /> <Compile Include="TmatrixSDK\OIDPublishImageGenerator.cs" />

View File

@ -29,10 +29,9 @@ namespace GeneratorCode.Logs
public class NLogConfig public class NLogConfig
{ {
private object _cfgLock = new object();
public delegate void LogCfgChangedHandle(); public delegate void LogCfgChangedHandle();
public static event LogCfgChangedHandle OnLogCfgChanged; private readonly object _cfgLock = new object();
public NLogConfig() public NLogConfig()
{ {
@ -40,11 +39,6 @@ namespace GeneratorCode.Logs
NConfig.OnConfigChanged += () => { LogCfgChanged(); }; NConfig.OnConfigChanged += () => { LogCfgChanged(); };
} }
protected static void LogCfgChanged()
{
OnLogCfgChanged?.Invoke();
}
public bool LogEnable { get; set; } public bool LogEnable { get; set; }
public NLogLevel LogLevel { get; set; } public NLogLevel LogLevel { get; set; }
public NLogLevel DefaultLevel { get; set; } public NLogLevel DefaultLevel { get; set; }
@ -78,6 +72,13 @@ namespace GeneratorCode.Logs
public bool RoolbackFile { get; set; } public bool RoolbackFile { get; set; }
public int MaxFileNum { get; set; } public int MaxFileNum { get; set; }
public static event LogCfgChangedHandle OnLogCfgChanged;
protected static void LogCfgChanged()
{
OnLogCfgChanged?.Invoke();
}
public void LogConfig() public void LogConfig()
{ {
lock (_cfgLock) lock (_cfgLock)
@ -107,7 +108,8 @@ namespace GeneratorCode.Logs
if (MaxItemsCache == 0) MaxItemsCache = int.MaxValue; if (MaxItemsCache == 0) MaxItemsCache = int.MaxValue;
CacheMode = (CacheOptMode)NConfig.GetCfgValue("AsyncLogSetting", "CacheFullOpts", (int)CacheOptMode.Drop); CacheMode = (CacheOptMode) NConfig.GetCfgValue("AsyncLogSetting", "CacheFullOpts",
(int) CacheOptMode.Drop);
NumOutItems = NConfig.GetCfgValue("AsyncLogSetting", "NumItemsOutEachTime", 10); NumOutItems = NConfig.GetCfgValue("AsyncLogSetting", "NumItemsOutEachTime", 10);
} }
@ -118,14 +120,9 @@ namespace GeneratorCode.Logs
DirPath = NConfig.GetCfgValue("FileLogSetting", "Path", @""); DirPath = NConfig.GetCfgValue("FileLogSetting", "Path", @"");
if (DirPath == "" || !Directory.Exists(DirPath) || DirPath == @".\") if (DirPath == "" || !Directory.Exists(DirPath) || DirPath == @".\")
{
DirPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"\"; DirPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"\";
}
if (!Directory.Exists(DirPath)) if (!Directory.Exists(DirPath)) Directory.CreateDirectory(DirPath);
{
Directory.CreateDirectory(DirPath);
}
FileNamePre = NConfig.GetCfgValue("FileLogSetting", "FileNamePrefix", ""); FileNamePre = NConfig.GetCfgValue("FileLogSetting", "FileNamePrefix", "");
EnSplitLog = NConfig.GetCfgValue("FileLogSetting", "AutoSplitFile", true); EnSplitLog = NConfig.GetCfgValue("FileLogSetting", "AutoSplitFile", true);
@ -152,13 +149,9 @@ namespace GeneratorCode.Logs
DateTime? dt = null) DateTime? dt = null)
{ {
if (dt == null) if (dt == null)
{
LogStamp = DateTime.Now; LogStamp = DateTime.Now;
}
else else
{
LogStamp = (DateTime) dt; LogStamp = (DateTime) dt;
}
LogLevel = level; LogLevel = level;
LogContent = logContent; LogContent = logContent;
@ -181,8 +174,8 @@ namespace GeneratorCode.Logs
private static readonly ConcurrentQueue<NLogItem> _logItemCollection = new ConcurrentQueue<NLogItem>(); private static readonly ConcurrentQueue<NLogItem> _logItemCollection = new ConcurrentQueue<NLogItem>();
private static readonly object _logOutputLock = new object(); private static readonly object _logOutputLock = new object();
private static string _logFileName = ""; private static string _logFileName = "";
private static uint _logFileNum = 0; private static uint _logFileNum;
private static StreamWriter _logSw = null; private static StreamWriter _logSw;
private static void CreateLogFileHead() private static void CreateLogFileHead()
{ {
@ -190,7 +183,7 @@ namespace GeneratorCode.Logs
_logSw?.WriteLine("CreateTime: " + string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now)); _logSw?.WriteLine("CreateTime: " + string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now));
_logSw?.WriteLine("Program: " + Process.GetCurrentProcess().MainModule.FileName); _logSw?.WriteLine("Program: " + Process.GetCurrentProcess().MainModule.FileName);
_logSw?.WriteLine("PID: " + Process.GetCurrentProcess().Id); _logSw?.WriteLine("PID: " + Process.GetCurrentProcess().Id);
_logSw?.WriteLine("Split Count: " + (_logFileNum - 1).ToString()); _logSw?.WriteLine("Split Count: " + (_logFileNum - 1));
_logSw?.WriteLine("--------------------------------------------------"); _logSw?.WriteLine("--------------------------------------------------");
_logSw?.Flush(); _logSw?.Flush();
} }
@ -215,12 +208,8 @@ namespace GeneratorCode.Logs
_logFileName += ".log"; _logFileName += ".log";
if (File.Exists(_logFileName)) if (File.Exists(_logFileName))
{
if (_logCfg.EnSplitLog) if (_logCfg.EnSplitLog)
{
File.Delete(_logFileName); File.Delete(_logFileName);
}
}
_logSw = new StreamWriter(_logFileName, true); _logSw = new StreamWriter(_logFileName, true);
CreateLogFileHead(); CreateLogFileHead();
@ -261,35 +250,25 @@ namespace GeneratorCode.Logs
var tolOut = Math.Min(_logCfg.NumOutItems, _logItemCollection.Count); var tolOut = Math.Min(_logCfg.NumOutItems, _logItemCollection.Count);
foreach (var val in Enumerable.Range(1, tolOut)) foreach (var val in Enumerable.Range(1, tolOut))
{
if (_logItemCollection.TryDequeue(out var logItem)) if (_logItemCollection.TryDequeue(out var logItem))
{
LogOutput(logItem); LogOutput(logItem);
}
}
Thread.Sleep(_logCfg.SleepTime); Thread.Sleep(_logCfg.SleepTime);
// 每秒执行一次维护工作 // 每秒执行一次维护工作
if ((++cnt % (1000 / _logCfg.SleepTime)) != 0) if (++cnt % (1000 / _logCfg.SleepTime) != 0) continue;
{
continue;
}
_logSw?.Flush(); _logSw?.Flush();
if (_logCfg.EnSplitLog) if (_logCfg.EnSplitLog)
{ {
bool isNeedSplit = false; var isNeedSplit = false;
if (_logCfg.SplitByData && lastDt.Day != DateTime.Now.Day) if (_logCfg.SplitByData && lastDt.Day != DateTime.Now.Day)
{
isNeedSplit = true; isNeedSplit = true;
} else if (_logCfg.SplitBySize > 0 &&
else if (_logCfg.SplitBySize > 0 && (new FileInfo(_logFileName)).Length > _logCfg.SplitBySize * (1024 * 1024)) new FileInfo(_logFileName).Length > _logCfg.SplitBySize * 1024 * 1024)
{
isNeedSplit = true; isNeedSplit = true;
}
if (isNeedSplit) if (isNeedSplit)
{ {
@ -297,7 +276,7 @@ namespace GeneratorCode.Logs
_logSw?.Dispose(); _logSw?.Dispose();
_logSw = null; _logSw = null;
string parttn = string.Format("*[{0:d3}]_{1}", var parttn = string.Format("*[{0:d3}]_{1}",
Process.GetCurrentProcess().Id, Process.GetCurrentProcess().Id,
Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().MainModule.FileName)); Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().MainModule.FileName));
@ -318,7 +297,8 @@ namespace GeneratorCode.Logs
_logFileName += ".log"; _logFileName += ".log";
parttn += ".log"; parttn += ".log";
foreach (var f in Directory.GetFiles(_logCfg.DirPath, parttn, SearchOption.TopDirectoryOnly)) foreach (var f in Directory.GetFiles(_logCfg.DirPath, parttn,
SearchOption.TopDirectoryOnly))
{ {
File.Delete(f); File.Delete(f);
Trace.WriteLine("Delect Rollback log: " + f); Trace.WriteLine("Delect Rollback log: " + f);
@ -352,58 +332,33 @@ namespace GeneratorCode.Logs
{ {
var msg = ""; var msg = "";
if (_logCfg.ShowDate || _logCfg.ShowTime) if (_logCfg.ShowDate || _logCfg.ShowTime) msg += "[";
{
msg += "[";
}
if (_logCfg.ShowDate) if (_logCfg.ShowDate)
{ {
msg += dt.ToString("yyyy-MM-dd"); msg += dt.ToString("yyyy-MM-dd");
if (_logCfg.ShowTime) if (_logCfg.ShowTime) msg += " ";
{
msg += " ";
}
} }
if (_logCfg.ShowTime) if (_logCfg.ShowTime)
{ {
msg += dt.ToString("HH:mm:ss"); msg += dt.ToString("HH:mm:ss");
if (_logCfg.ShowMSec) if (_logCfg.ShowMSec) msg += "." + dt.ToString("fff");
{
msg += "." + dt.ToString("fff");
}
} }
if (_logCfg.ShowDate || _logCfg.ShowTime) if (_logCfg.ShowDate || _logCfg.ShowTime) msg += "]";
{
msg += "]";
}
if (_logCfg.ShowLevel) if (_logCfg.ShowLevel) msg += " [" + LogLevelToString(logLevel) + "] ";
{
msg += " [" + LogLevelToString(logLevel) + "] ";
}
if (_logCfg.ShowCodeFile) if (_logCfg.ShowCodeFile) msg += "[" + Path.GetFileName(fileName) + "] ";
{
msg += "[" + Path.GetFileName(fileName) + "] ";
}
if (_logCfg.ShowFunction) if (_logCfg.ShowFunction) msg += "- " + funName;
{
msg += "- " + funName;
}
if (_logCfg.ShowCodeFile || _logCfg.ShowFunction) if (_logCfg.ShowCodeFile || _logCfg.ShowFunction)
{
if (_logCfg.ShowCodeLine) if (_logCfg.ShowCodeLine)
{ msg += "(" + lineNo + ")";
msg += "(" + lineNo.ToString() + ")";
}
}
msg += ": " + logMsg; msg += ": " + logMsg;
@ -419,10 +374,7 @@ namespace GeneratorCode.Logs
logItem.CodeLine, logItem.CodeLine,
logItem.LogStamp); logItem.LogStamp);
if (_logCfg.ForceNewLine) if (_logCfg.ForceNewLine) msg += Environment.NewLine;
{
msg += Environment.NewLine;
}
lock (_logOutputLock) lock (_logOutputLock)
{ {
@ -436,10 +388,7 @@ namespace GeneratorCode.Logs
System.Diagnostics.Debug.WriteLine(msg); System.Diagnostics.Debug.WriteLine(msg);
} }
if (_logCfg.EnFile) if (_logCfg.EnFile) _logSw?.Write(msg);
{
_logSw?.Write(msg);
}
} }
} }
@ -457,10 +406,7 @@ namespace GeneratorCode.Logs
System.Diagnostics.Debug.WriteLine(logMsg); System.Diagnostics.Debug.WriteLine(logMsg);
} }
if (_logCfg.EnFile) if (_logCfg.EnFile) _logSw?.Write(logMsg);
{
_logSw?.Write(logMsg);
}
} }
} }
@ -475,16 +421,11 @@ namespace GeneratorCode.Logs
{ {
if (_logItemCollection.Count >= _logCfg.MaxItemsCache) if (_logItemCollection.Count >= _logCfg.MaxItemsCache)
{ {
if (_logCfg.CacheMode == CacheOptMode.Drop) if (_logCfg.CacheMode == CacheOptMode.Drop) return;
{
return;
}
else
{
NLogItem val; NLogItem val;
_logItemCollection.TryDequeue(out val); _logItemCollection.TryDequeue(out val);
} }
}
var logItem = new NLogItem(_logCfg.DefaultLevel, logMsg, fileName, funName, lineNo, DateTime.Now); var logItem = new NLogItem(_logCfg.DefaultLevel, logMsg, fileName, funName, lineNo, DateTime.Now);
_logItemCollection.Enqueue(logItem); _logItemCollection.Enqueue(logItem);
@ -508,16 +449,11 @@ namespace GeneratorCode.Logs
{ {
if (_logItemCollection.Count >= _logCfg.MaxItemsCache) if (_logItemCollection.Count >= _logCfg.MaxItemsCache)
{ {
if (_logCfg.CacheMode == CacheOptMode.Drop) if (_logCfg.CacheMode == CacheOptMode.Drop) return;
{
return;
}
else
{
NLogItem val; NLogItem val;
_logItemCollection.TryDequeue(out val); _logItemCollection.TryDequeue(out val);
} }
}
var logItem = new NLogItem(NLogLevel.Debug, logMsg, fileName, funName, lineNo, DateTime.Now); var logItem = new NLogItem(NLogLevel.Debug, logMsg, fileName, funName, lineNo, DateTime.Now);
_logItemCollection.Enqueue(logItem); _logItemCollection.Enqueue(logItem);

View File

@ -1,10 +1,11 @@
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text; using System.Text;
using System.Threading;
using GeneratorCode.Configure; using GeneratorCode.Configure;
using GeneratorCode.Logs; using GeneratorCode.Logs;
using JetBrains.Annotations;
using Newtonsoft.Json; using Newtonsoft.Json;
using TmatrixLibrary; using TmatrixLibrary;
@ -19,8 +20,8 @@ namespace GeneratorCode
image_type = new[] { false, false, false, true }; image_type = new[] { false, false, false, true };
StartPageID = 0; StartPageID = 0;
key = "S0,O000,B0000,P000-255,D2018/12/31;CCAFBQMXYPOAOCIRK52S8QC8SO4A0AGA8Y"; key = "S0,O000,B0000,P000-255,D2018/12/31;CCAFBQMXYPOAOCIRK52S8QC8SO4A0AGA8Y";
//filePath = "E:\\NetEase\\轨迹笔\\Sample\\123.pdf"; //"C:\\Works\\pdf\\123.pdf"; filePath = "E:\\NetEase\\轨迹笔\\Sample\\123.pdf"; //"C:\\Works\\pdf\\123.pdf";
filePath = "C:\\Works\\pdf\\123.pdf"; //filePath = "C:\\Works\\pdf\\123.pdf";
sessionId = "4BD5D923-47EA-4DEF-A1CD-9B85B515B191"; sessionId = "4BD5D923-47EA-4DEF-A1CD-9B85B515B191";
} }
@ -52,6 +53,63 @@ namespace GeneratorCode
public int progress { get; set; } public int progress { get; set; }
} }
public class MainConfig
{
public delegate void MainCfgChangedHandle();
private readonly object _cfgLock = new object();
public MainConfig()
{
LoadConfig();
OnMainCfgChanged += MainCfgChanged;
}
public bool Base64MsgContent { get; set; }
public int ServerPort { get; set; }
public string ServerAddr { get; set; }
public static event MainCfgChangedHandle OnMainCfgChanged;
protected static void MainCfgChanged()
{
OnMainCfgChanged?.Invoke();
}
public void LoadConfig()
{
lock (_cfgLock)
{
Base64MsgContent = NConfig.GetCfgValue("Main", "ProBase64Msg", true);
ServerPort = NConfig.GetCfgValue("Main", "ProServerPort", 10088);
ServerAddr = NConfig.GetCfgValue("Main", "ProServerAddr", "127.0.0.1");
}
}
}
public class MessageProcess
{
private readonly UdpClient _udp = new UdpClient();
public MessageProcess(MainConfig cfg)
{
var svrAddr = IPAddress.Parse(cfg.ServerAddr);
_server = new IPEndPoint(svrAddr, cfg.ServerPort);
}
private IPEndPoint _server { get; }
public void SendMessage([NotNull] string msg)
{
if (msg.Length > 0)
{
var sendData = Encoding.Default.GetBytes(msg);
_udp.Send(sendData, sendData.Length, _server);
NLog.Debug("Send: " + msg + Environment.NewLine);
}
}
}
public class RspMessage public class RspMessage
{ {
public RspMessage(string sId) public RspMessage(string sId)
@ -74,33 +132,21 @@ namespace GeneratorCode
public GenerCodeRet data { get; set; } public GenerCodeRet data { get; set; }
public string FormatRspMessage(int errCode, string readme, int prg) public string FormatRspMessage(int errCode, string readme, int prg, bool enBase64 = true)
{ {
var rsp = new RspMessage(data.sessionId, prg); var rsp = new RspMessage(data.sessionId, prg);
rsp.err = errCode; rsp.err = errCode;
rsp.msg = (Convert.ToBase64String(Encoding.Default.GetBytes(readme)));
if (enBase64)
rsp.msg = Convert.ToBase64String(Encoding.Default.GetBytes(readme));
else
rsp.msg = readme;
return JsonConvert.SerializeObject(rsp); return JsonConvert.SerializeObject(rsp);
} }
public static int SendRspMessage(string msg)
{
NLog.Debug("Send: " + msg + Environment.NewLine);
Console.WriteLine(msg);
return 0;
} }
public void ProgressMessage(int step) internal class MainCode
{
var msgContent = FormatRspMessage(0, "Progress", step);
msg = JsonConvert.SerializeObject(msgContent);
SendRspMessage(msg);
}
}
internal class Program
{ {
private static int Main(string[] args) private static int Main(string[] args)
{ {
@ -108,16 +154,13 @@ namespace GeneratorCode
NLog.NLog_Init(); NLog.NLog_Init();
GeneratorParams inParams = null; GeneratorParams inParams = null;
RspMessage rspMsg; RspMessage rspMsg;
var mainCfg = new MainConfig();
var msgProcess = new MessageProcess(mainCfg);
var tmObj = new TmatrixClass(); var tmObj = new TmatrixClass();
AppDomain.CurrentDomain.UnhandledException += (sender, e) => AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
{ {
//Trace.WriteLine("+++++++++++++++++++++++++++++++++++++++++++xajhuang1\n"); NLog.Crash("UnHandled Exception: " + e.ToString());
};
AppDomain.CurrentDomain.DomainUnload += (sender, e) =>
{
//Trace.WriteLine("+++++++++++++++++++++++++++++++++++++++++++xajhuang2\n");
}; };
AppDomain.CurrentDomain.ProcessExit += (sender, ev) => AppDomain.CurrentDomain.ProcessExit += (sender, ev) =>
@ -173,15 +216,22 @@ namespace GeneratorCode
catch (Exception e) catch (Exception e)
{ {
rspMsg = new RspMessage(""); rspMsg = new RspMessage("");
var msg = rspMsg.FormatRspMessage(10, e.Message, 0); var msg = rspMsg.FormatRspMessage(10, e.Message, 0, mainCfg.Base64MsgContent);
RspMessage.SendRspMessage(msg); msgProcess.SendMessage(msg);
NLog.Crash(string.Format("[{0}]: ", (inParams == null) ? inParams.sessionId : "UnInit") + e.Message); NLog.Crash(string.Format("[{0}]: ", inParams == null ? inParams.sessionId : "UnInit") + e.Message);
return -(int) ErrCode.ERR_JSON_DECODE; return -(int) ErrCode.ERR_JSON_DECODE;
} }
rspMsg = new RspMessage(inParams.sessionId); rspMsg = new RspMessage(inParams.sessionId);
tmObj.ProgressChange += rspMsg.ProgressMessage; tmObj.ProgressChange += step =>
{
var msgContent = rspMsg.FormatRspMessage(0, "Progress", step, mainCfg.Base64MsgContent);
var msg = JsonConvert.SerializeObject(msgContent);
msgProcess.SendMessage(msg);
};
var jsInput = JsonConvert.SerializeObject(inParams); var jsInput = JsonConvert.SerializeObject(inParams);
@ -199,8 +249,8 @@ namespace GeneratorCode
} }
catch (Exception e) catch (Exception e)
{ {
var msg = rspMsg.FormatRspMessage(7, e.Message, 0); var msg = rspMsg.FormatRspMessage(7, e.Message, 0, mainCfg.Base64MsgContent);
RspMessage.SendRspMessage(msg); msgProcess.SendMessage(msg);
NLog.Crash(e.ToString()); NLog.Crash(e.ToString());
return -(int) ErrCode.ERR_EXCEPT_THROW; return -(int) ErrCode.ERR_EXCEPT_THROW;
} }
@ -214,24 +264,27 @@ namespace GeneratorCode
if (ret.Substring(0, 1) != "0") if (ret.Substring(0, 1) != "0")
{ {
var msg = rspMsg.FormatRspMessage(int.Parse(ret.Substring(0, 1)), var msg = rspMsg.FormatRspMessage(int.Parse(ret.Substring(0, 1)),
ret.Substring(1, ret.Length - 1), tmObj.GetProgerss()); ret.Substring(1, ret.Length - 1),
tmObj.GetProgerss(),
mainCfg.Base64MsgContent);
NLog.Error(msg + Environment.NewLine); NLog.Error(msg + Environment.NewLine);
RspMessage.SendRspMessage(msg); msgProcess.SendMessage(msg);
} }
else else
{ {
var msg = rspMsg.FormatRspMessage(int.Parse(ret.Substring(0, 1)), var msg = rspMsg.FormatRspMessage(int.Parse(ret.Substring(0, 1)),
ret.Substring(1, ret.Length - 1), 100); ret.Substring(1, ret.Length - 1), 100,
mainCfg.Base64MsgContent);
NLog.Debug(msg + Environment.NewLine); NLog.Debug(msg + Environment.NewLine);
RspMessage.SendRspMessage(msg); msgProcess.SendMessage(msg);
} }
} }
catch (Exception e) catch (Exception e)
{ {
var msg = rspMsg.FormatRspMessage(8, e.Message, tmObj.GetProgerss()); var msg = rspMsg.FormatRspMessage(8, e.Message, tmObj.GetProgerss(), mainCfg.Base64MsgContent);
RspMessage.SendRspMessage(msg); msgProcess.SendMessage(msg);
NLog.Crash(e.ToString()); NLog.Crash(e.ToString());
return -(int) ErrCode.ERR_EXCEPT_THROW; return -(int) ErrCode.ERR_EXCEPT_THROW;
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,4 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下 // 有关程序集的一般信息由以下

View File

@ -1,7 +1,7 @@
using System.Runtime.InteropServices;
namespace OIDModule.Generator namespace OIDModule.Generator
{ {
using System;
using System.Runtime.InteropServices;
internal enum OIDBeginBuildState internal enum OIDBeginBuildState
{ {
eBBState_OK, eBBState_OK,
@ -9,17 +9,20 @@ namespace OIDModule.Generator
eBBState_FailToOpenImageFile, eBBState_FailToOpenImageFile,
eBBState_Unknown eBBState_Unknown
} }
internal enum OIDPrintPointType internal enum OIDPrintPointType
{ {
eOID_PrintPointType_2x2, eOID_PrintPointType_2x2,
eOID_PrintPointType_3x3, eOID_PrintPointType_3x3,
eOID_PrintPointType_4x4 eOID_PrintPointType_4x4
} }
internal enum OIDPublishImageDPIType internal enum OIDPublishImageDPIType
{ {
eOID_PublishImageDPI_600, eOID_PublishImageDPI_600,
eOID_PublishImageDPI_1200 eOID_PublishImageDPI_1200
} }
internal enum OIDPublishImageType internal enum OIDPublishImageType
{ {
eOID_PIT_Publish_Image, eOID_PIT_Publish_Image,
@ -27,6 +30,7 @@ namespace OIDModule.Generator
eOID_PIT_BG_Vertor_Image, eOID_PIT_BG_Vertor_Image,
eOID_PIT_Publish_BG_Image eOID_PIT_Publish_BG_Image
} }
internal enum OIDPublishObjectType internal enum OIDPublishObjectType
{ {
eOID_OT_ElementCode, eOID_OT_ElementCode,
@ -35,9 +39,11 @@ namespace OIDModule.Generator
internal class OIDPublishImageGenerator internal class OIDPublishImageGenerator
{ {
public bool AddObjectInfo(int nPageIndex, ulong uiObjectIndex, uint[] arPointX, uint[] arPointY, int nPointsCount, int nZOrder, int nObjectType) public bool AddObjectInfo(int nPageIndex, ulong uiObjectIndex, uint[] arPointX, uint[] arPointY,
int nPointsCount, int nZOrder, int nObjectType)
{ {
return OID_PIG_AddObjectInfo(nPageIndex, uiObjectIndex, arPointX, arPointY, nPointsCount, nZOrder, nObjectType); return OID_PIG_AddObjectInfo(nPageIndex, uiObjectIndex, arPointX, arPointY, nPointsCount, nZOrder,
nObjectType);
} }
public int BeginBuildPublishImage(char[] szBGImage, bool bExportPDFImage, int nExportPDFImageDPI) public int BeginBuildPublishImage(char[] szBGImage, bool bExportPDFImage, int nExportPDFImageDPI)
@ -50,9 +56,11 @@ namespace OIDModule.Generator
return OID_PIG_BeginBuildPublishImageByInfo(dbCMWidth, dbCMHeight); return OID_PIG_BeginBuildPublishImageByInfo(dbCMWidth, dbCMHeight);
} }
public bool BuildPublishImage(char[] szOutputFolderPath, bool bPrintIdleCode, bool bSplitBigImage, bool bMergeSplittedImages, int nPublishImageDPIType, int nPrintPointType, int nPublishImageType) public bool BuildPublishImage(char[] szOutputFolderPath, bool bPrintIdleCode, bool bSplitBigImage,
bool bMergeSplittedImages, int nPublishImageDPIType, int nPrintPointType, int nPublishImageType)
{ {
return OID_PIG_BuildPublishImage(szOutputFolderPath, bPrintIdleCode, bSplitBigImage, bMergeSplittedImages, nPublishImageDPIType, nPrintPointType, nPublishImageType); return OID_PIG_BuildPublishImage(szOutputFolderPath, bPrintIdleCode, bSplitBigImage, bMergeSplittedImages,
nPublishImageDPIType, nPrintPointType, nPublishImageType);
} }
public void EndBuildPublishImage() public void EndBuildPublishImage()
@ -65,24 +73,46 @@ namespace OIDModule.Generator
return OID_PIG_Initialize(); return OID_PIG_Initialize();
} }
[DllImport(@".\OIDPublishImageGenerator\OIDPublishImageGenerator.dll", CallingConvention=CallingConvention.StdCall)] [DllImport(@".\OIDPublishImageGenerator\OIDPublishImageGenerator.dll", CallingConvention =
private static extern bool OID_PIG_AddObjectInfo(int nPageIndex, ulong uiObjectIndex, uint[] arPointX, uint[] arPointY, int nPointsCount, int nZOrder, int nObjectType); CallingConvention.StdCall)]
[DllImport(@".\OIDPublishImageGenerator\OIDPublishImageGenerator.dll", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode)] private static extern bool OID_PIG_AddObjectInfo(int nPageIndex, ulong uiObjectIndex, uint[] arPointX,
private static extern int OID_PIG_BeginBuildPublishImage(char[] szBGImage, bool bExportPDFImage, int nExportPDFImageDPI); uint[] arPointY, int nPointsCount, int nZOrder, int nObjectType);
[DllImport(@".\OIDPublishImageGenerator\OIDPublishImageGenerator.dll", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode)]
[DllImport(@".\OIDPublishImageGenerator\OIDPublishImageGenerator.dll",
CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
private static extern int OID_PIG_BeginBuildPublishImage(char[] szBGImage, bool bExportPDFImage,
int nExportPDFImageDPI);
[DllImport(@".\OIDPublishImageGenerator\OIDPublishImageGenerator.dll",
CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
private static extern int OID_PIG_BeginBuildPublishImageByInfo(double dbCMWidth, double dbCMHeight); private static extern int OID_PIG_BeginBuildPublishImageByInfo(double dbCMWidth, double dbCMHeight);
[DllImport(@".\OIDPublishImageGenerator\OIDPublishImageGenerator.dll", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode)]
private static extern bool OID_PIG_BuildPublishImage(char[] szOutputFolderPath, bool bPrintIdleCode, bool bSplitBigImage, bool bMergeSplittedImages, int nPublishImageDPIType, int nPrintPointType, int nPublishImageType); [DllImport(@".\OIDPublishImageGenerator\OIDPublishImageGenerator.dll",
[DllImport(@".\OIDPublishImageGenerator\OIDPublishImageGenerator.dll", CallingConvention=CallingConvention.StdCall)] CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
private static extern bool OID_PIG_BuildPublishImage(char[] szOutputFolderPath, bool bPrintIdleCode,
bool bSplitBigImage, bool bMergeSplittedImages, int nPublishImageDPIType, int nPrintPointType,
int nPublishImageType);
[DllImport(@".\OIDPublishImageGenerator\OIDPublishImageGenerator.dll", CallingConvention =
CallingConvention.StdCall)]
private static extern void OID_PIG_EndBuildPublishImage(); private static extern void OID_PIG_EndBuildPublishImage();
[DllImport(@".\OIDPublishImageGenerator\OIDPublishImageGenerator.dll", CallingConvention=CallingConvention.StdCall)]
[DllImport(@".\OIDPublishImageGenerator\OIDPublishImageGenerator.dll", CallingConvention =
CallingConvention.StdCall)]
private static extern bool OID_PIG_Initialize(); private static extern bool OID_PIG_Initialize();
[DllImport(@".\OIDPublishImageGenerator\OIDPublishImageGenerator.dll", CallingConvention=CallingConvention.StdCall)]
[DllImport(@".\OIDPublishImageGenerator\OIDPublishImageGenerator.dll", CallingConvention =
CallingConvention.StdCall)]
private static extern bool OID_PIG_SetPublishPages(int[] arPageNumbers, int nPageCount); private static extern bool OID_PIG_SetPublishPages(int[] arPageNumbers, int nPageCount);
[DllImport(@".\OIDPublishImageGenerator\OIDPublishImageGenerator.dll", CallingConvention=CallingConvention.StdCall)]
[DllImport(@".\OIDPublishImageGenerator\OIDPublishImageGenerator.dll", CallingConvention =
CallingConvention.StdCall)]
private static extern bool OID_PIG_SetStartPosition(int nPageIndex, int nXStart, int nYStart); private static extern bool OID_PIG_SetStartPosition(int nPageIndex, int nXStart, int nYStart);
[DllImport(@".\OIDPublishImageGenerator\OIDPublishImageGenerator.dll", CallingConvention=CallingConvention.StdCall)]
[DllImport(@".\OIDPublishImageGenerator\OIDPublishImageGenerator.dll", CallingConvention =
CallingConvention.StdCall)]
private static extern void OID_PIG_Uninitialize(); private static extern void OID_PIG_Uninitialize();
public bool SetPublishPages(int[] arPageNumbers, int nPageCount) public bool SetPublishPages(int[] arPageNumbers, int nPageCount)
{ {
return OID_PIG_SetPublishPages(arPageNumbers, nPageCount); return OID_PIG_SetPublishPages(arPageNumbers, nPageCount);

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,16 @@
; 应用程序配置文件 ; 应用程序配置文件
;---------------------------------------
; 主要配置项
;
[Main]
; 是否对协议中的 msg 字段进行 Base64 编码
ProBase64Msg = false
; 服务器端口号
ProServerPort = 10088
; 服务器 IP 地址
ProServerAddr = 127.0.0.1
;--------------------------------------- ;---------------------------------------
; Log 相关配置 ; Log 相关配置
; ;

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="ini-parser" version="2.5.2" targetFramework="net45" /> <package id="ini-parser" version="2.5.2" targetFramework="net45" />
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net45" /> <package id="Newtonsoft.Json" version="12.0.1" targetFramework="net45" />