diff --git a/GeneratorCode/Configure/NConfig.cs b/GeneratorCode/Configure/NConfig.cs index 33e696a..079090b 100644 --- a/GeneratorCode/Configure/NConfig.cs +++ b/GeneratorCode/Configure/NConfig.cs @@ -64,7 +64,14 @@ namespace GeneratorCode.Configure try { - ret = (T) Convert.ChangeType(_cfgData[segName][keyName], typeof(T)); + string val; + + + if (_cfgData.TryGetKey(segName + _cfgData.SectionKeySeparator + keyName, out val)) + { + ret = (T)Convert.ChangeType(val, typeof(T)); + } + } catch (Exception e) { diff --git a/GeneratorCode/MainCode.cs b/GeneratorCode/MainCode.cs index 7d3e60d..8777786 100644 --- a/GeneratorCode/MainCode.cs +++ b/GeneratorCode/MainCode.cs @@ -4,7 +4,7 @@ // Created : 02-14-2019 // // Last Modified By : 黄昕 -// Last Modified On : 02-26-2019 +// Last Modified On : 03-04-2019 // *********************************************************************** // // Copyright © 2019 @@ -26,77 +26,77 @@ using TmatrixLibrary; namespace GeneratorCode { /// - /// Class GeneratorParams. + /// Class GeneratorParams. /// [JsonObject(MemberSerialization.OptOut)] public class GeneratorParams { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public GeneratorParams() { dpi = new[] {0, 0, 0, 0}; - pointType = new[] {0, 0, 0, 0}; - imageType = new[] {false, false, false, true}; + pointType = new[] {0, 0, 0, 0}; + imageType = new[] {false, false, false, true}; startPageId = 0; key = "S0,O000,B0000,P000-255,D2018/12/31;CCAFBQMXYPOAOCIRK52S8QC8SO4A0AGA8Y"; - //filePath = "E:\\NetEase\\轨迹笔\\Sample\\123.pdf"; //"C:\\Works\\pdf\\123.pdf"; - filePath = "C:\\Works\\pdf\\123.pdf"; + filePath = "E:\\NetEase\\轨迹笔\\Sample\\123.pdf"; //"C:\\Works\\pdf\\123.pdf"; + //filePath = "C:\\Works\\pdf\\123.pdf"; sessionId = "4BD5D923-47EA-4DEF-A1CD-9B85B515B191"; } /// - /// Gets or sets the dpi. + /// Gets or sets the dpi. /// /// The dpi. public int[] dpi { get; set; } /// - /// Gets or sets the file path. + /// Gets or sets the file path. /// /// The file path. public string filePath { get; set; } /// - /// Gets or sets the type of the image. + /// Gets or sets the type of the image. /// /// The type of the image. public bool[] imageType { get; set; } /// - /// Gets or sets the key. + /// Gets or sets the key. /// /// The key. public string key { get; set; } /// - /// Gets or sets the type of the point. + /// Gets or sets the type of the point. /// /// The type of the point. public int[] pointType { get; set; } /// - /// Gets or sets the session identifier. + /// Gets or sets the session identifier. /// /// The session identifier. [JsonIgnore] public string sessionId { get; set; } /// - /// Gets or sets the start page identifier. + /// Gets or sets the start page identifier. /// /// The start page identifier. public int startPageId { get; set; } } /// - /// Class GenerCodeRet. + /// Class GenerCodeRet. /// public class GenerCodeRet { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The s identifier. /// The PRG. @@ -107,35 +107,35 @@ namespace GeneratorCode } /// - /// Gets or sets the progress. + /// Gets or sets the progress. /// /// The progress. public int progress { get; set; } /// - /// Gets or sets the session identifier. + /// Gets or sets the session identifier. /// /// The session identifier. public string sessionId { get; set; } } /// - /// Class MainConfig. + /// Class MainConfig. /// public class MainConfig { /// - /// Delegate MainCfgChangedHandle + /// Delegate MainCfgChangedHandle /// public delegate void MainCfgChangedHandle(); /// - /// The CFG lock + /// The CFG lock /// private readonly object _cfgLock = new object(); /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public MainConfig() { @@ -144,30 +144,30 @@ namespace GeneratorCode } /// - /// Gets or sets a value indicating whether [base64 MSG content]. + /// Gets or sets a value indicating whether [base64 MSG content]. /// /// true if [base64 MSG content]; otherwise, false. public bool Base64MsgContent { get; set; } /// - /// Gets or sets the server addr. + /// Gets or sets the server addr. /// /// The server addr. public string ServerAddr { get; set; } /// - /// Gets or sets the server port. + /// Gets or sets the server port. /// /// The server port. public int ServerPort { get; set; } /// - /// Occurs when [on main CFG changed]. + /// Occurs when [on main CFG changed]. /// public static event MainCfgChangedHandle OnMainCfgChanged; /// - /// Loads the configuration. + /// Loads the configuration. /// public void LoadConfig() { @@ -180,7 +180,7 @@ namespace GeneratorCode } /// - /// Mains the CFG changed. + /// Mains the CFG changed. /// protected static void MainCfgChanged() { @@ -189,17 +189,17 @@ namespace GeneratorCode } /// - /// Class MessageProcess. + /// Class MessageProcess. /// public class MessageProcess { /// - /// The UDP + /// The UDP /// private readonly UdpClient _udp = new UdpClient(); /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The CFG. public MessageProcess(MainConfig cfg) @@ -209,13 +209,13 @@ namespace GeneratorCode } /// - /// Gets the server. + /// Gets the server. /// /// The server. private IPEndPoint _server { get; } /// - /// Sends the message. + /// Sends the message. /// /// The MSG. public void SendMessage([NotNull] string msg) @@ -230,12 +230,12 @@ namespace GeneratorCode } /// - /// Class RspMessage. + /// Class RspMessage. /// public class RspMessage { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The s identifier. public RspMessage(string sId) @@ -246,7 +246,7 @@ namespace GeneratorCode } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The s identifier. /// The PRG. @@ -258,25 +258,25 @@ namespace GeneratorCode } /// - /// Gets or sets the data. + /// Gets or sets the data. /// /// The data. public GenerCodeRet data { get; set; } /// - /// Gets or sets the error. + /// Gets or sets the error. /// /// The error. public int err { get; set; } /// - /// Gets or sets the MSG. + /// Gets or sets the MSG. /// /// The MSG. public string msg { get; set; } /// - /// Formats the RSP message. + /// Formats the RSP message. /// /// The error code. /// The readme. @@ -289,21 +289,65 @@ namespace GeneratorCode rsp.err = errCode; if (enBase64) + { rsp.msg = Convert.ToBase64String(Encoding.Default.GetBytes(readme)); + } else + { rsp.msg = readme; + } return JsonConvert.SerializeObject(rsp); } } /// - /// Class MainCode. + /// Class MainCode. /// internal class MainCode { /// - /// Defines the entry point of the application. + /// Gets the offical error code. + /// + /// The error. + /// System.Int32. + private static int GetOfficalErrCode([NotNull] string err = "0") + { + switch (err) + { + case "0": + return (int) ErrCode.ErrSuccesed; + + case "1": + return (int) ErrCode.ErrKeyTampered; + + case "2": + return (int) ErrCode.ErrKeyOldStyle; + + case "3": + return (int) ErrCode.ErrKeyExpired; + + case "4": + return (int) ErrCode.ErrFileNotExists; + + case "5": + return (int) ErrCode.ErrStartPage; + + case "6": + return (int) ErrCode.ErrPageNotEnough; + + case "7": + return (int) ErrCode.ErrSizeMoreThan780; + + case "8": + return (int) ErrCode.ErrSizeMoreThan6242; + } + + return (int) ErrCode.ErrUnknownCode; + } + + /// + /// Defines the entry point of the application. /// /// The arguments. /// System.Int32. @@ -338,20 +382,6 @@ namespace GeneratorCode NLog.NLog_Finish(); }; - //string inputArg = - // "eyJkcGkiOlswLDAsMCwwXSwicG9pbnRfdHlwZSI6WzAsMCwwLDBdLCJpbWFnZV90eXBlI" + - // "jpbZmFsc2UsZmFsc2UsZmFsc2UsdHJ1ZV0sImtleSI6IlMwLE8wMDAsQjAwMDAsUDAwMC0" + - // "yNTUsRDIwMTgvMTIvMzE7Q0NBRkJRTVhZUE9BT0NJUks1MlM4UUM4U080QTBBR0E4WSIsIm" + - // "ZpbGVQYXRoIjoiRTpcXE5ldEVhc2VcXLnsvKOxylxcU2FtcGxlXFwxMjMucGRmIiwiU3Rhcn" + - // "RQYWdlSUQiOjAsInNlc3Npb25JZCI6IjRCRDVEOTIzLTQ3RUEtNERFRi1BMUNELTlCODVCNT" + - // "E1QjE5MSJ9"; - //string inputArg2 = "eyJkcGkiOlswLDAsMCwwXSwicG9pbnRfdHlwZSI6WzAsMCwwLDBdLCJpb" + - // "WFnZV90eXBlIjpbZmFsc2UsZmFsc2UsZmFsc2UsdHJ1ZV0sImtleSI6Il" + - // "MwLE8wMDAsQjAwMDAsUDAwMC0yNTUsRDIwMTgvMTIvMzE7Q0NBRkJRTVh" + - // "ZUE9BT0NJUks1MlM4UUM4U080QTBBR0E4WSIsImZpbGVQYXRoIjoiQzpc" + - // "XFdvcmtzXFxwZGZcXDEyMy5wZGYiLCJTdGFydFBhZ2VJRCI6MCwic2Vzc" + - // "2lvbklkIjoiNEJENUQ5MjMtNDdFQS00REVGLUExQ0QtOUI4NUI1MTVCMTkxIn0="; - try { if (args.Length == 1) @@ -380,7 +410,7 @@ namespace GeneratorCode if (inParams != null) NLog.Crash(string.Format("[{0}]: ", inParams.sessionId) + e.Message); - return -(int) ErrCode.ErrJsonDecode; + return (int) ErrCode.ErrJsonDecode; } rspMsg = new RspMessage(inParams.sessionId); @@ -401,7 +431,7 @@ namespace GeneratorCode if (!File.Exists(inParams.filePath)) { NLog.Error("File Not Exists: " + inParams.filePath + Environment.NewLine); - return -(int) ErrCode.ErrFileNotexists; + return (int) ErrCode.ErrFileNotExists; } try @@ -413,7 +443,7 @@ namespace GeneratorCode var msg = rspMsg.FormatRspMessage(7, e.Message, 0, mainCfg.Base64MsgContent); msgProcess.SendMessage(msg); NLog.Crash(e.ToString()); - return -(int) ErrCode.ErrExceptThrow; + return (int) ErrCode.ErrExceptThrow; } try @@ -422,7 +452,9 @@ namespace GeneratorCode inParams.filePath, inParams.startPageId, inParams.pointType, inParams.imageType, inParams.dpi); - if (ret.Substring(0, 1) != "0") + var errCode = GetOfficalErrCode(ret.Substring(0, 1)); + + if (errCode != 0) { var msg = rspMsg.FormatRspMessage(int.Parse(ret.Substring(0, 1)), ret.Substring(1, ret.Length - 1), @@ -441,42 +473,87 @@ namespace GeneratorCode NLog.Debug(msg + Environment.NewLine); msgProcess.SendMessage(msg); } + + return errCode; } catch (Exception e) { var msg = rspMsg.FormatRspMessage(8, e.Message, tmObj.GetProgerss(), mainCfg.Base64MsgContent); msgProcess.SendMessage(msg); NLog.Crash(e.ToString()); - return -(int) ErrCode.ErrExceptThrow; + return (int) ErrCode.ErrExceptThrow; } - - return 0; } /// - /// Enum ErrCode + /// Enum ErrCode /// private enum ErrCode { /// - /// The error input parameters + /// The error succesed /// - ErrInputParams = 1, + ErrSuccesed = 0, /// - /// The error file notexists + /// The error size more than780 /// - ErrFileNotexists, + ErrSizeMoreThan780 = 105, /// - /// The error except throw + /// The error size more than6242 /// - ErrExceptThrow, + ErrSizeMoreThan6242 = 106, /// - /// The error json decode + /// The error start page /// - ErrJsonDecode + ErrStartPage = 110, + + /// + /// The error input parameters + /// + ErrInputParams = 122, + + /// + /// The error key tampered + /// + ErrKeyTampered = 123, + + /// + /// The error key old style + /// + ErrKeyOldStyle = 124, + + /// + /// The error key expired + /// + ErrKeyExpired = 125, + + /// + /// The error page not enough + /// + ErrPageNotEnough = 126, + + /// + /// The error file not exists + /// + ErrFileNotExists = 127, + + /// + /// The error except throw + /// + ErrExceptThrow = 128, + + /// + /// The error json decode + /// + ErrJsonDecode = 129, + + /// + /// The error unknown code + /// + ErrUnknownCode = 130 } } } \ No newline at end of file diff --git a/GeneratorCode/TmatrixSDK/TmatrixClass.cs b/GeneratorCode/TmatrixSDK/TmatrixClass.cs index 762ddc4..4498fea 100644 --- a/GeneratorCode/TmatrixSDK/TmatrixClass.cs +++ b/GeneratorCode/TmatrixSDK/TmatrixClass.cs @@ -1058,13 +1058,13 @@ namespace TmatrixLibrary str = TmatrixKeyCheck_OID4(KeyStr); if (str.Substring(0, 1) != "0") return str; - if (PDFFileName == "") return "1Please select PDF file first !"; + if (PDFFileName == "") return "4Please select PDF file first !"; if (StartPageID < int.Parse(gsPID1) || StartPageID > int.Parse(gsPID2)) - return "2Start page ID must be located between " + gsPID1 + " ~ " + gsPID2; + return "5Start page ID must be located between " + gsPID1 + " ~ " + gsPID2; gPageNum = GetPDFPageNumber(PDFFileName); if (gPageNum + StartPageID - 1 > int.Parse(gsPID2)) - return "3Not enough code page for this PDF to generate !"; + return "6Not enough code page for this PDF to generate !"; SetProgress(1); @@ -1207,11 +1207,11 @@ namespace TmatrixLibrary case 1: case 2: if (num16 <= 780 && num17 <= 780) break; - return "4PDF page size's width or height > 780mm !"; + return "7PDF page size's width or height > 780mm !"; case 3: if (num16 <= 0x1862 && num17 <= 0x1862) break; - return "5PDF page size's width or height > 6242mm !"; + return "8PDF page size's width or height > 6242mm !"; } var numArray3 = new uint[5];