2019-02-12 03:43:15 +00:00
|
|
|
|
using System;
|
2019-02-18 11:21:24 +00:00
|
|
|
|
using System.Diagnostics;
|
2019-02-12 03:43:15 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
2019-02-18 07:56:36 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using GeneratorCode.Configure;
|
|
|
|
|
using GeneratorCode.Logs;
|
2019-02-12 03:43:15 +00:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using TmatrixLibrary;
|
|
|
|
|
|
|
|
|
|
namespace GeneratorCode
|
|
|
|
|
{
|
|
|
|
|
public class GeneratorParams
|
|
|
|
|
{
|
|
|
|
|
public GeneratorParams()
|
|
|
|
|
{
|
2019-02-12 04:05:54 +00:00
|
|
|
|
dpi = new[] { 0, 0, 0, 0 };
|
|
|
|
|
point_type = new[] { 0, 0, 0, 0 };
|
2019-02-13 02:03:46 +00:00
|
|
|
|
image_type = new[] { false, false, false, true };
|
2019-02-12 03:43:15 +00:00
|
|
|
|
StartPageID = 0;
|
|
|
|
|
key = "S0,O000,B0000,P000-255,D2018/12/31;CCAFBQMXYPOAOCIRK52S8QC8SO4A0AGA8Y";
|
2019-02-18 11:21:24 +00:00
|
|
|
|
//filePath = "E:\\NetEase\\轨迹笔\\Sample\\123.pdf"; //"C:\\Works\\pdf\\123.pdf";
|
|
|
|
|
filePath = "C:\\Works\\pdf\\123.pdf";
|
2019-02-12 03:43:15 +00:00
|
|
|
|
sessionId = "4BD5D923-47EA-4DEF-A1CD-9B85B515B191";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int[] dpi { get; set; }
|
|
|
|
|
|
|
|
|
|
public int[] point_type { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool[] image_type { get; set; }
|
|
|
|
|
|
|
|
|
|
public string key { get; set; }
|
|
|
|
|
|
|
|
|
|
public string filePath { get; set; }
|
|
|
|
|
|
|
|
|
|
public int StartPageID { get; set; }
|
|
|
|
|
|
|
|
|
|
public string sessionId { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class GenerCodeRet
|
|
|
|
|
{
|
|
|
|
|
public GenerCodeRet(string sId, int prg)
|
|
|
|
|
{
|
|
|
|
|
sessionId = sId;
|
|
|
|
|
progress = prg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string sessionId { get; set; }
|
|
|
|
|
|
|
|
|
|
public int progress { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class RspMessage
|
|
|
|
|
{
|
|
|
|
|
public RspMessage(string sId)
|
|
|
|
|
{
|
|
|
|
|
err = 0;
|
|
|
|
|
msg = "";
|
|
|
|
|
data = new GenerCodeRet(sId, 0);
|
|
|
|
|
}
|
2019-02-12 04:05:54 +00:00
|
|
|
|
|
2019-02-12 03:43:15 +00:00
|
|
|
|
public RspMessage(string sId, int prg)
|
|
|
|
|
{
|
|
|
|
|
err = 0;
|
|
|
|
|
msg = "";
|
|
|
|
|
data = new GenerCodeRet(sId, prg);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-12 04:05:54 +00:00
|
|
|
|
public int err { get; set; }
|
|
|
|
|
|
|
|
|
|
public string msg { get; set; }
|
|
|
|
|
|
|
|
|
|
public GenerCodeRet data { get; set; }
|
|
|
|
|
|
2019-02-12 03:43:15 +00:00
|
|
|
|
public string FormatRspMessage(int errCode, string readme, int prg)
|
|
|
|
|
{
|
2019-02-12 04:05:54 +00:00
|
|
|
|
var rsp = new RspMessage(data.sessionId, prg);
|
2019-02-12 03:43:15 +00:00
|
|
|
|
rsp.err = errCode;
|
2019-02-13 02:03:46 +00:00
|
|
|
|
rsp.msg = (Convert.ToBase64String(Encoding.Default.GetBytes(readme)));
|
2019-02-12 03:43:15 +00:00
|
|
|
|
|
|
|
|
|
return JsonConvert.SerializeObject(rsp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int SendRspMessage(string msg)
|
|
|
|
|
{
|
2019-02-18 11:21:24 +00:00
|
|
|
|
NLog.Debug("Send: " + msg + Environment.NewLine);
|
2019-02-12 03:43:15 +00:00
|
|
|
|
Console.WriteLine(msg);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ProgressMessage(int step)
|
|
|
|
|
{
|
2019-02-13 02:03:46 +00:00
|
|
|
|
var msgContent = FormatRspMessage(0, "Progress", step);
|
|
|
|
|
|
|
|
|
|
msg = JsonConvert.SerializeObject(msgContent);
|
2019-02-12 03:43:15 +00:00
|
|
|
|
|
2019-02-12 04:05:54 +00:00
|
|
|
|
SendRspMessage(msg);
|
2019-02-12 03:43:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-12 04:05:54 +00:00
|
|
|
|
internal class Program
|
2019-02-12 03:43:15 +00:00
|
|
|
|
{
|
2019-02-12 04:05:54 +00:00
|
|
|
|
private static int Main(string[] args)
|
2019-02-12 03:43:15 +00:00
|
|
|
|
{
|
2019-02-18 07:56:36 +00:00
|
|
|
|
NConfig.InitConfigure();
|
|
|
|
|
NLog.NLog_Init();
|
|
|
|
|
GeneratorParams inParams = null;
|
2019-02-12 03:43:15 +00:00
|
|
|
|
RspMessage rspMsg;
|
2019-02-12 04:05:54 +00:00
|
|
|
|
var tmObj = new TmatrixClass();
|
|
|
|
|
|
2019-02-18 11:21:24 +00:00
|
|
|
|
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
|
|
|
|
|
{
|
|
|
|
|
//Trace.WriteLine("+++++++++++++++++++++++++++++++++++++++++++xajhuang1\n");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
AppDomain.CurrentDomain.DomainUnload += (sender, e) =>
|
|
|
|
|
{
|
|
|
|
|
//Trace.WriteLine("+++++++++++++++++++++++++++++++++++++++++++xajhuang2\n");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
AppDomain.CurrentDomain.ProcessExit += (sender, ev) =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
tmObj.TmatrixUninitialize();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
//var msg = rspMsg.FormatRspMessage(9, e.Message, 0);
|
|
|
|
|
//RspMessage.SendRspMessage(msg);
|
|
|
|
|
NLog.Crash(e.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NLog.NLog_Finish();
|
|
|
|
|
};
|
|
|
|
|
|
2019-02-12 03:43:15 +00:00
|
|
|
|
//string inputArg =
|
|
|
|
|
// "eyJkcGkiOlswLDAsMCwwXSwicG9pbnRfdHlwZSI6WzAsMCwwLDBdLCJpbWFnZV90eXBlI" +
|
|
|
|
|
// "jpbZmFsc2UsZmFsc2UsZmFsc2UsdHJ1ZV0sImtleSI6IlMwLE8wMDAsQjAwMDAsUDAwMC0" +
|
|
|
|
|
// "yNTUsRDIwMTgvMTIvMzE7Q0NBRkJRTVhZUE9BT0NJUks1MlM4UUM4U080QTBBR0E4WSIsIm" +
|
|
|
|
|
// "ZpbGVQYXRoIjoiRTpcXE5ldEVhc2VcXLnsvKOxylxcU2FtcGxlXFwxMjMucGRmIiwiU3Rhcn" +
|
|
|
|
|
// "RQYWdlSUQiOjAsInNlc3Npb25JZCI6IjRCRDVEOTIzLTQ3RUEtNERFRi1BMUNELTlCODVCNT" +
|
|
|
|
|
// "E1QjE5MSJ9";
|
|
|
|
|
//string inputArg2 = "eyJkcGkiOlswLDAsMCwwXSwicG9pbnRfdHlwZSI6WzAsMCwwLDBdLCJpb" +
|
|
|
|
|
// "WFnZV90eXBlIjpbZmFsc2UsZmFsc2UsZmFsc2UsdHJ1ZV0sImtleSI6Il" +
|
|
|
|
|
// "MwLE8wMDAsQjAwMDAsUDAwMC0yNTUsRDIwMTgvMTIvMzE7Q0NBRkJRTVh" +
|
|
|
|
|
// "ZUE9BT0NJUks1MlM4UUM4U080QTBBR0E4WSIsImZpbGVQYXRoIjoiQzpc" +
|
|
|
|
|
// "XFdvcmtzXFxwZGZcXDEyMy5wZGYiLCJTdGFydFBhZ2VJRCI6MCwic2Vzc" +
|
|
|
|
|
// "2lvbklkIjoiNEJENUQ5MjMtNDdFQS00REVGLUExQ0QtOUI4NUI1MTVCMTkxIn0=";
|
2019-02-18 07:56:36 +00:00
|
|
|
|
|
2019-02-12 03:43:15 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (args.Length == 1)
|
|
|
|
|
{
|
2019-02-13 02:03:46 +00:00
|
|
|
|
var deCode = Convert.FromBase64String(args[0]);
|
2019-02-12 04:05:54 +00:00
|
|
|
|
var strParams = Encoding.Default.GetString(deCode);
|
2019-02-12 03:43:15 +00:00
|
|
|
|
inParams = JsonConvert.DeserializeObject<GeneratorParams>(strParams);
|
|
|
|
|
}
|
|
|
|
|
else if (args.Length == 2)
|
|
|
|
|
{
|
2019-02-12 04:05:54 +00:00
|
|
|
|
var deCode = Convert.FromBase64String(args[1]);
|
|
|
|
|
var strParams = Encoding.Default.GetString(deCode);
|
2019-02-12 03:43:15 +00:00
|
|
|
|
inParams = JsonConvert.DeserializeObject<GeneratorParams>(strParams);
|
|
|
|
|
inParams.sessionId = args[0];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
inParams = new GeneratorParams();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
rspMsg = new RspMessage("");
|
2019-02-12 04:05:54 +00:00
|
|
|
|
var msg = rspMsg.FormatRspMessage(10, e.Message, 0);
|
2019-02-12 03:43:15 +00:00
|
|
|
|
RspMessage.SendRspMessage(msg);
|
2019-02-18 07:56:36 +00:00
|
|
|
|
NLog.Crash(string.Format("[{0}]: ", (inParams == null) ? inParams.sessionId : "UnInit") + e.Message);
|
2019-02-12 04:05:54 +00:00
|
|
|
|
return -(int) ErrCode.ERR_JSON_DECODE;
|
2019-02-12 03:43:15 +00:00
|
|
|
|
}
|
2019-02-12 04:05:54 +00:00
|
|
|
|
|
2019-02-12 03:43:15 +00:00
|
|
|
|
rspMsg = new RspMessage(inParams.sessionId);
|
|
|
|
|
|
2019-02-12 04:05:54 +00:00
|
|
|
|
tmObj.ProgressChange += rspMsg.ProgressMessage;
|
2019-02-12 03:43:15 +00:00
|
|
|
|
|
2019-02-12 04:05:54 +00:00
|
|
|
|
var jsInput = JsonConvert.SerializeObject(inParams);
|
2019-02-12 03:43:15 +00:00
|
|
|
|
|
2019-02-18 11:21:24 +00:00
|
|
|
|
NLog.Debug("Input:" + jsInput + Environment.NewLine);
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(inParams.filePath))
|
|
|
|
|
{
|
|
|
|
|
NLog.Error("File Not Exists: " + inParams.filePath + Environment.NewLine);
|
|
|
|
|
return -(int) ErrCode.ERR_FILE_NOTEXISTS;
|
|
|
|
|
}
|
2019-02-12 03:43:15 +00:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
tmObj.TmatrixInitialize();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2019-02-12 04:05:54 +00:00
|
|
|
|
var msg = rspMsg.FormatRspMessage(7, e.Message, 0);
|
2019-02-12 03:43:15 +00:00
|
|
|
|
RspMessage.SendRspMessage(msg);
|
2019-02-18 11:21:24 +00:00
|
|
|
|
NLog.Crash(e.ToString());
|
2019-02-12 04:05:54 +00:00
|
|
|
|
return -(int) ErrCode.ERR_EXCEPT_THROW;
|
2019-02-12 03:43:15 +00:00
|
|
|
|
}
|
2019-02-18 11:21:24 +00:00
|
|
|
|
|
2019-02-12 03:43:15 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2019-02-12 04:05:54 +00:00
|
|
|
|
var ret = tmObj.GenerateTmatrixCode_OID4(inParams.key,
|
2019-02-12 03:43:15 +00:00
|
|
|
|
inParams.filePath, inParams.StartPageID, inParams.point_type,
|
|
|
|
|
inParams.image_type, inParams.dpi);
|
|
|
|
|
|
|
|
|
|
if (ret.Substring(0, 1) != "0")
|
|
|
|
|
{
|
2019-02-12 04:05:54 +00:00
|
|
|
|
var msg = rspMsg.FormatRspMessage(int.Parse(ret.Substring(0, 1)),
|
2019-02-12 03:43:15 +00:00
|
|
|
|
ret.Substring(1, ret.Length - 1), tmObj.GetProgerss());
|
|
|
|
|
|
2019-02-18 11:21:24 +00:00
|
|
|
|
NLog.Error(msg + Environment.NewLine);
|
2019-02-12 03:43:15 +00:00
|
|
|
|
RspMessage.SendRspMessage(msg);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-02-12 04:05:54 +00:00
|
|
|
|
var msg = rspMsg.FormatRspMessage(int.Parse(ret.Substring(0, 1)),
|
2019-02-12 03:43:15 +00:00
|
|
|
|
ret.Substring(1, ret.Length - 1), 100);
|
|
|
|
|
|
2019-02-18 11:21:24 +00:00
|
|
|
|
NLog.Debug(msg + Environment.NewLine);
|
2019-02-12 03:43:15 +00:00
|
|
|
|
RspMessage.SendRspMessage(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2019-02-12 04:05:54 +00:00
|
|
|
|
var msg = rspMsg.FormatRspMessage(8, e.Message, tmObj.GetProgerss());
|
2019-02-12 03:43:15 +00:00
|
|
|
|
RspMessage.SendRspMessage(msg);
|
2019-02-18 11:21:24 +00:00
|
|
|
|
NLog.Crash(e.ToString());
|
2019-02-12 04:05:54 +00:00
|
|
|
|
return -(int) ErrCode.ERR_EXCEPT_THROW;
|
2019-02-12 03:43:15 +00:00
|
|
|
|
}
|
2019-02-18 11:21:24 +00:00
|
|
|
|
|
2019-02-12 03:43:15 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2019-02-12 04:05:54 +00:00
|
|
|
|
|
|
|
|
|
private enum ErrCode
|
|
|
|
|
{
|
|
|
|
|
ERR_INPUT_PARAMS = 1,
|
|
|
|
|
ERR_FILE_NOTEXISTS,
|
|
|
|
|
ERR_EXCEPT_THROW,
|
|
|
|
|
ERR_JSON_DECODE
|
|
|
|
|
}
|
2019-02-12 03:43:15 +00:00
|
|
|
|
}
|
2019-02-12 04:05:54 +00:00
|
|
|
|
}
|