using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using TmatrixLibrary; using OIDModule.Generator; namespace GeneratorCode { public class GeneratorParams { public GeneratorParams() { dpi = new int[] { 0, 0, 0, 0}; point_type = new int[] { 0, 0, 0, 0 }; image_type = new bool[] { true, true, true, true}; StartPageID = 0; key = "S0,O000,B0000,P000-255,D2018/12/31;CCAFBQMXYPOAOCIRK52S8QC8SO4A0AGA8Y"; filePath = "E:\\NetEase\\轨迹笔\\Sample\\123.pdf";//"C:\\Works\\pdf\\123.pdf"; 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 int err { get; set; } public string msg { get; set; } public GenerCodeRet data { get; set; } public RspMessage(string sId) { err = 0; msg = ""; data = new GenerCodeRet(sId, 0); } public RspMessage(string sId, int prg) { err = 0; msg = ""; data = new GenerCodeRet(sId, prg); } public string FormatRspMessage(int errCode, string readme, int prg) { RspMessage rsp = new RspMessage(data.sessionId, prg); rsp.err = errCode; rsp.msg = readme; return JsonConvert.SerializeObject(rsp); } public static int SendRspMessage(string msg) { Console.WriteLine(msg); return 0; } public void ProgressMessage(int step) { RspMessage rsp = new RspMessage(data.sessionId, step); rsp.err = 0; rsp.msg = "Progress"; msg = JsonConvert.SerializeObject(rsp); RspMessage.SendRspMessage(msg); } } class Program { enum ErrCode { ERR_INPUT_PARAMS = 1, ERR_FILE_NOTEXISTS, ERR_EXCEPT_THROW, ERR_JSON_DECODE }; static int Main(string[] args) { GeneratorParams inParams; RspMessage rspMsg; //string inputArg = // "eyJkcGkiOlswLDAsMCwwXSwicG9pbnRfdHlwZSI6WzAsMCwwLDBdLCJpbWFnZV90eXBlI" + // "jpbZmFsc2UsZmFsc2UsZmFsc2UsdHJ1ZV0sImtleSI6IlMwLE8wMDAsQjAwMDAsUDAwMC0" + // "yNTUsRDIwMTgvMTIvMzE7Q0NBRkJRTVhZUE9BT0NJUks1MlM4UUM4U080QTBBR0E4WSIsIm" + // "ZpbGVQYXRoIjoiRTpcXE5ldEVhc2VcXLnsvKOxylxcU2FtcGxlXFwxMjMucGRmIiwiU3Rhcn" + // "RQYWdlSUQiOjAsInNlc3Npb25JZCI6IjRCRDVEOTIzLTQ3RUEtNERFRi1BMUNELTlCODVCNT" + // "E1QjE5MSJ9"; //string inputArg2 = "eyJkcGkiOlswLDAsMCwwXSwicG9pbnRfdHlwZSI6WzAsMCwwLDBdLCJpb" + // "WFnZV90eXBlIjpbZmFsc2UsZmFsc2UsZmFsc2UsdHJ1ZV0sImtleSI6Il" + // "MwLE8wMDAsQjAwMDAsUDAwMC0yNTUsRDIwMTgvMTIvMzE7Q0NBRkJRTVh" + // "ZUE9BT0NJUks1MlM4UUM4U080QTBBR0E4WSIsImZpbGVQYXRoIjoiQzpc" + // "XFdvcmtzXFxwZGZcXDEyMy5wZGYiLCJTdGFydFBhZ2VJRCI6MCwic2Vzc" + // "2lvbklkIjoiNEJENUQ5MjMtNDdFQS00REVGLUExQ0QtOUI4NUI1MTVCMTkxIn0="; TmatrixClass tmObj = new TmatrixClass(); try { if (args.Length == 1) { byte[] deCode = Convert.FromBase64String(args[1]); string strParams = System.Text.Encoding.Default.GetString(deCode); inParams = JsonConvert.DeserializeObject(strParams); } else if (args.Length == 2) { byte[] deCode = Convert.FromBase64String(args[1]); string strParams = System.Text.Encoding.Default.GetString(deCode); inParams = JsonConvert.DeserializeObject(strParams); inParams.sessionId = args[0]; } else { inParams = new GeneratorParams(); } } catch (Exception e) { rspMsg = new RspMessage(""); string msg = rspMsg.FormatRspMessage(10, e.Message, 0); RspMessage.SendRspMessage(msg); return -(int)ErrCode.ERR_JSON_DECODE; } rspMsg = new RspMessage(inParams.sessionId); tmObj.ProgressChange += new TmatrixClass.ProgressChangedEvent(rspMsg.ProgressMessage); string jsInput = JsonConvert.SerializeObject(inParams); Console.WriteLine("Input:\n" + jsInput); //Console.WriteLine("Input:\n" + Convert.ToBase64String(Encoding.Default.GetBytes(jsInput))); if (!File.Exists(inParams.filePath)) { return -(int) ErrCode.ERR_FILE_NOTEXISTS; } try { tmObj.TmatrixInitialize(); } catch (Exception e) { string msg = rspMsg.FormatRspMessage(7, e.Message, 0); RspMessage.SendRspMessage(msg); return -(int)ErrCode.ERR_EXCEPT_THROW; } try { string ret = tmObj.GenerateTmatrixCode_OID4(inParams.key, inParams.filePath, inParams.StartPageID, inParams.point_type, inParams.image_type, inParams.dpi); if (ret.Substring(0, 1) != "0") { string msg = rspMsg.FormatRspMessage(Int32.Parse(ret.Substring(0, 1)), ret.Substring(1, ret.Length - 1), tmObj.GetProgerss()); RspMessage.SendRspMessage(msg); } else { string msg = rspMsg.FormatRspMessage(Int32.Parse(ret.Substring(0, 1)), ret.Substring(1, ret.Length - 1), 100); RspMessage.SendRspMessage(msg); } } catch (Exception e) { string msg = rspMsg.FormatRspMessage(8, e.Message, tmObj.GetProgerss()); RspMessage.SendRspMessage(msg); return -(int)ErrCode.ERR_EXCEPT_THROW; } try { tmObj.TmatrixUninitialize(); } catch (Exception e) { string msg = rspMsg.FormatRspMessage(9, e.Message, 0); RspMessage.SendRspMessage(msg); return -(int)ErrCode.ERR_EXCEPT_THROW; } return 0; } } }