标准化错误代码
This commit is contained in:
parent
1ce879d762
commit
8f2c87b3b7
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
// Created : 02-14-2019
|
||||
//
|
||||
// Last Modified By : 黄昕 <hzhuangxin01@corp.netease.com>
|
||||
// Last Modified On : 02-26-2019
|
||||
// Last Modified On : 03-04-2019
|
||||
// ***********************************************************************
|
||||
// <copyright file="MainCode.cs" company="NetEase">
|
||||
// Copyright © 2019
|
||||
|
@ -26,77 +26,77 @@ using TmatrixLibrary;
|
|||
namespace GeneratorCode
|
||||
{
|
||||
/// <summary>
|
||||
/// Class GeneratorParams.
|
||||
/// Class GeneratorParams.
|
||||
/// </summary>
|
||||
[JsonObject(MemberSerialization.OptOut)]
|
||||
public class GeneratorParams
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GeneratorParams" /> class.
|
||||
/// Initializes a new instance of the <see cref="GeneratorParams" /> class.
|
||||
/// </summary>
|
||||
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";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the dpi.
|
||||
/// Gets or sets the dpi.
|
||||
/// </summary>
|
||||
/// <value>The dpi.</value>
|
||||
public int[] dpi { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the file path.
|
||||
/// Gets or sets the file path.
|
||||
/// </summary>
|
||||
/// <value>The file path.</value>
|
||||
public string filePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type of the image.
|
||||
/// Gets or sets the type of the image.
|
||||
/// </summary>
|
||||
/// <value>The type of the image.</value>
|
||||
public bool[] imageType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the key.
|
||||
/// Gets or sets the key.
|
||||
/// </summary>
|
||||
/// <value>The key.</value>
|
||||
public string key { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type of the point.
|
||||
/// Gets or sets the type of the point.
|
||||
/// </summary>
|
||||
/// <value>The type of the point.</value>
|
||||
public int[] pointType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the session identifier.
|
||||
/// Gets or sets the session identifier.
|
||||
/// </summary>
|
||||
/// <value>The session identifier.</value>
|
||||
[JsonIgnore]
|
||||
public string sessionId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the start page identifier.
|
||||
/// Gets or sets the start page identifier.
|
||||
/// </summary>
|
||||
/// <value>The start page identifier.</value>
|
||||
public int startPageId { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class GenerCodeRet.
|
||||
/// Class GenerCodeRet.
|
||||
/// </summary>
|
||||
public class GenerCodeRet
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GenerCodeRet" /> class.
|
||||
/// Initializes a new instance of the <see cref="GenerCodeRet" /> class.
|
||||
/// </summary>
|
||||
/// <param name="sId">The s identifier.</param>
|
||||
/// <param name="prg">The PRG.</param>
|
||||
|
@ -107,35 +107,35 @@ namespace GeneratorCode
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the progress.
|
||||
/// Gets or sets the progress.
|
||||
/// </summary>
|
||||
/// <value>The progress.</value>
|
||||
public int progress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the session identifier.
|
||||
/// Gets or sets the session identifier.
|
||||
/// </summary>
|
||||
/// <value>The session identifier.</value>
|
||||
public string sessionId { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class MainConfig.
|
||||
/// Class MainConfig.
|
||||
/// </summary>
|
||||
public class MainConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Delegate MainCfgChangedHandle
|
||||
/// Delegate MainCfgChangedHandle
|
||||
/// </summary>
|
||||
public delegate void MainCfgChangedHandle();
|
||||
|
||||
/// <summary>
|
||||
/// The CFG lock
|
||||
/// The CFG lock
|
||||
/// </summary>
|
||||
private readonly object _cfgLock = new object();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MainConfig" /> class.
|
||||
/// Initializes a new instance of the <see cref="MainConfig" /> class.
|
||||
/// </summary>
|
||||
public MainConfig()
|
||||
{
|
||||
|
@ -144,30 +144,30 @@ namespace GeneratorCode
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether [base64 MSG content].
|
||||
/// Gets or sets a value indicating whether [base64 MSG content].
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if [base64 MSG content]; otherwise, <c>false</c>.</value>
|
||||
public bool Base64MsgContent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the server addr.
|
||||
/// Gets or sets the server addr.
|
||||
/// </summary>
|
||||
/// <value>The server addr.</value>
|
||||
public string ServerAddr { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the server port.
|
||||
/// Gets or sets the server port.
|
||||
/// </summary>
|
||||
/// <value>The server port.</value>
|
||||
public int ServerPort { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when [on main CFG changed].
|
||||
/// Occurs when [on main CFG changed].
|
||||
/// </summary>
|
||||
public static event MainCfgChangedHandle OnMainCfgChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Loads the configuration.
|
||||
/// Loads the configuration.
|
||||
/// </summary>
|
||||
public void LoadConfig()
|
||||
{
|
||||
|
@ -180,7 +180,7 @@ namespace GeneratorCode
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mains the CFG changed.
|
||||
/// Mains the CFG changed.
|
||||
/// </summary>
|
||||
protected static void MainCfgChanged()
|
||||
{
|
||||
|
@ -189,17 +189,17 @@ namespace GeneratorCode
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class MessageProcess.
|
||||
/// Class MessageProcess.
|
||||
/// </summary>
|
||||
public class MessageProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// The UDP
|
||||
/// The UDP
|
||||
/// </summary>
|
||||
private readonly UdpClient _udp = new UdpClient();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MessageProcess" /> class.
|
||||
/// Initializes a new instance of the <see cref="MessageProcess" /> class.
|
||||
/// </summary>
|
||||
/// <param name="cfg">The CFG.</param>
|
||||
public MessageProcess(MainConfig cfg)
|
||||
|
@ -209,13 +209,13 @@ namespace GeneratorCode
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the server.
|
||||
/// Gets the server.
|
||||
/// </summary>
|
||||
/// <value>The server.</value>
|
||||
private IPEndPoint _server { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Sends the message.
|
||||
/// Sends the message.
|
||||
/// </summary>
|
||||
/// <param name="msg">The MSG.</param>
|
||||
public void SendMessage([NotNull] string msg)
|
||||
|
@ -230,12 +230,12 @@ namespace GeneratorCode
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class RspMessage.
|
||||
/// Class RspMessage.
|
||||
/// </summary>
|
||||
public class RspMessage
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RspMessage" /> class.
|
||||
/// Initializes a new instance of the <see cref="RspMessage" /> class.
|
||||
/// </summary>
|
||||
/// <param name="sId">The s identifier.</param>
|
||||
public RspMessage(string sId)
|
||||
|
@ -246,7 +246,7 @@ namespace GeneratorCode
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RspMessage" /> class.
|
||||
/// Initializes a new instance of the <see cref="RspMessage" /> class.
|
||||
/// </summary>
|
||||
/// <param name="sId">The s identifier.</param>
|
||||
/// <param name="prg">The PRG.</param>
|
||||
|
@ -258,25 +258,25 @@ namespace GeneratorCode
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the data.
|
||||
/// Gets or sets the data.
|
||||
/// </summary>
|
||||
/// <value>The data.</value>
|
||||
public GenerCodeRet data { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the error.
|
||||
/// Gets or sets the error.
|
||||
/// </summary>
|
||||
/// <value>The error.</value>
|
||||
public int err { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the MSG.
|
||||
/// Gets or sets the MSG.
|
||||
/// </summary>
|
||||
/// <value>The MSG.</value>
|
||||
public string msg { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Formats the RSP message.
|
||||
/// Formats the RSP message.
|
||||
/// </summary>
|
||||
/// <param name="errCode">The error code.</param>
|
||||
/// <param name="readme">The readme.</param>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class MainCode.
|
||||
/// Class MainCode.
|
||||
/// </summary>
|
||||
internal class MainCode
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the entry point of the application.
|
||||
/// Gets the offical error code.
|
||||
/// </summary>
|
||||
/// <param name="err">The error.</param>
|
||||
/// <returns>System.Int32.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines the entry point of the application.
|
||||
/// </summary>
|
||||
/// <param name="args">The arguments.</param>
|
||||
/// <returns>System.Int32.</returns>
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enum ErrCode
|
||||
/// Enum ErrCode
|
||||
/// </summary>
|
||||
private enum ErrCode
|
||||
{
|
||||
/// <summary>
|
||||
/// The error input parameters
|
||||
/// The error succesed
|
||||
/// </summary>
|
||||
ErrInputParams = 1,
|
||||
ErrSuccesed = 0,
|
||||
|
||||
/// <summary>
|
||||
/// The error file notexists
|
||||
/// The error size more than780
|
||||
/// </summary>
|
||||
ErrFileNotexists,
|
||||
ErrSizeMoreThan780 = 105,
|
||||
|
||||
/// <summary>
|
||||
/// The error except throw
|
||||
/// The error size more than6242
|
||||
/// </summary>
|
||||
ErrExceptThrow,
|
||||
ErrSizeMoreThan6242 = 106,
|
||||
|
||||
/// <summary>
|
||||
/// The error json decode
|
||||
/// The error start page
|
||||
/// </summary>
|
||||
ErrJsonDecode
|
||||
ErrStartPage = 110,
|
||||
|
||||
/// <summary>
|
||||
/// The error input parameters
|
||||
/// </summary>
|
||||
ErrInputParams = 122,
|
||||
|
||||
/// <summary>
|
||||
/// The error key tampered
|
||||
/// </summary>
|
||||
ErrKeyTampered = 123,
|
||||
|
||||
/// <summary>
|
||||
/// The error key old style
|
||||
/// </summary>
|
||||
ErrKeyOldStyle = 124,
|
||||
|
||||
/// <summary>
|
||||
/// The error key expired
|
||||
/// </summary>
|
||||
ErrKeyExpired = 125,
|
||||
|
||||
/// <summary>
|
||||
/// The error page not enough
|
||||
/// </summary>
|
||||
ErrPageNotEnough = 126,
|
||||
|
||||
/// <summary>
|
||||
/// The error file not exists
|
||||
/// </summary>
|
||||
ErrFileNotExists = 127,
|
||||
|
||||
/// <summary>
|
||||
/// The error except throw
|
||||
/// </summary>
|
||||
ErrExceptThrow = 128,
|
||||
|
||||
/// <summary>
|
||||
/// The error json decode
|
||||
/// </summary>
|
||||
ErrJsonDecode = 129,
|
||||
|
||||
/// <summary>
|
||||
/// The error unknown code
|
||||
/// </summary>
|
||||
ErrUnknownCode = 130
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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];
|
||||
|
|
Loading…
Reference in New Issue