Author: gedmurphy Date: Tue Apr 22 07:05:37 2008 New Revision: 33096
URL: http://svn.reactos.org/svn/reactos?rev=33096&view=rev Log: More reworking of the translator assembly. It's much more extensible now.
Added: trunk/tools/Message Translator/MsgTrans.Library/CustomCommand.cs Modified: trunk/tools/Message Translator/MsgTrans.Library/BugCommand.cs trunk/tools/Message Translator/MsgTrans.Library/Command.cs trunk/tools/Message Translator/MsgTrans.Library/ErrorCommand.cs trunk/tools/Message Translator/MsgTrans.Library/HresultCommand.cs trunk/tools/Message Translator/MsgTrans.Library/MsgTrans.Library.csproj trunk/tools/Message Translator/MsgTrans.Library/MsgTrans.cs trunk/tools/Message Translator/MsgTrans.Library/NtStatusCommand.cs trunk/tools/Message Translator/MsgTrans.Library/WinerrorCommand.cs
Modified: trunk/tools/Message Translator/MsgTrans.Library/BugCommand.cs URL: http://svn.reactos.org/svn/reactos/trunk/tools/Message%20Translator/MsgTrans... ============================================================================== --- trunk/tools/Message Translator/MsgTrans.Library/BugCommand.cs [iso-8859-1] (original) +++ trunk/tools/Message Translator/MsgTrans.Library/BugCommand.cs [iso-8859-1] Tue Apr 22 07:05:37 2008 @@ -2,7 +2,7 @@
namespace MsgTrans.Library { - public abstract class BugCommand : Command//, ICommand + public class BugCommand : Command { string bugUrl;
@@ -11,6 +11,11 @@ : base(msgTrans) { this.bugUrl = bugUrl; + } + + public override string[] AvailableCommands + { + get { return new string[] { "bug" }; } }
public override bool Handle(MessageContext context,
Modified: trunk/tools/Message Translator/MsgTrans.Library/Command.cs URL: http://svn.reactos.org/svn/reactos/trunk/tools/Message%20Translator/MsgTrans... ============================================================================== --- trunk/tools/Message Translator/MsgTrans.Library/Command.cs [iso-8859-1] (original) +++ trunk/tools/Message Translator/MsgTrans.Library/Command.cs [iso-8859-1] Tue Apr 22 07:05:37 2008 @@ -51,6 +51,20 @@ this.msgTrans = msgTrans; }
+ protected void AddMessage(MessageType msgType, + long dec, + string hex, + string code, + string msg) + { + MsgType = msgType; + Number = dec; + Hex = hex; + Code = code; + Message = msg; + MsgTrans.Messages.Add(this); + } + public abstract bool Handle(MessageContext context, string commandName, string parameters);
Added: trunk/tools/Message Translator/MsgTrans.Library/CustomCommand.cs URL: http://svn.reactos.org/svn/reactos/trunk/tools/Message%20Translator/MsgTrans... ============================================================================== --- trunk/tools/Message Translator/MsgTrans.Library/CustomCommand.cs (added) +++ trunk/tools/Message Translator/MsgTrans.Library/CustomCommand.cs [iso-8859-1] Tue Apr 22 07:05:37 2008 @@ -1,0 +1,157 @@ +using System; + +namespace MsgTrans.Library +{ + public class CustomCommand : Command + { + public CustomCommand(MessageTranslator msgTrans) + : base(msgTrans) + { + } + + public override string[] AvailableCommands + { + get { return new string[] { "custom" }; } + } + + private int GetSeverity(long error) + { + return (int)((error >> 30) & 0x3); + } + + private bool IsCustomer(long error) + { + return (error & 0x20000000) != 0; + } + + private bool IsReserved(long error) + { + return (error & 0x10000000) != 0; + } + + private int GetFacility(long error) + { + return (int)((error >> 16) & 0xFFF); + } + + private short GetCode(long error) + { + return (short)((error >> 0) & 0xFFFF); + } + + private string FormatSeverity(long error) + { + int severity = GetSeverity(error); + switch (severity) + { + case 0: return "SUCCESS"; + case 1: return "INFORMATIONAL"; + case 2: return "WARNING"; + case 3: return "ERROR"; + } + return null; + } + + private string FormatFacility(long error) + { + int facility = GetFacility(error); + return facility.ToString(); + } + + private string FormatCode(long error) + { + int code = GetCode(error); + return code.ToString(); + } + + public override bool Handle(MessageContext context, + string commandName, + string parameters) + { + string originalErrorText = parameters.Trim(); + if (originalErrorText.Equals(String.Empty)) + { + MsgTrans.MsgOutput.MsgOut(context, + "Please provide an Error Code."); + return false; + } + + string errorText = originalErrorText; + + NumberParser np = new NumberParser(); + if (!np.Parse(errorText)) + { + MsgTrans.MsgOutput.MsgOut(context, + String.Format("{0} is not a valid Error Code.", + originalErrorText)); + return false; + } + + //ArrayList descriptions = new ArrayList(); + + // Error is out of bounds + if ((ulong)np.Decimal > uint.MaxValue) + { + // Do nothing + } + // Error is outside of the range [0, 65535]: it cannot be a plain Win32 error code + else if ((ulong)np.Decimal > ushort.MaxValue) + { + // Customer bit is set: custom error code + if (IsCustomer(np.Decimal)) + { + string description = String.Format("[custom, severity {0}, facility {1}, code {2}]", + FormatSeverity(np.Decimal), + FormatFacility(np.Decimal), + FormatCode(np.Decimal)); + AddMessage(MessageType.Custom, + np.Decimal, + np.Hex, + description, + null); + } + // Reserved bit is set: HRESULT_FROM_NT(ntstatus) + else if (IsReserved(np.Decimal)) + { + int status = (int)(np.Decimal & 0xCFFFFFFF); + + string description;// = ntStatus.GetNtstatusDescription(status); + + //if (description == null) + description = status.ToString("X"); + + description = String.Format("HRESULT_FROM_NT({0})", description); + + AddMessage(MessageType.Custom, + np.Decimal, + np.Hex, + description, + null); + } + // Win32 facility: HRESULT_FROM_WIN32(winerror) + else if (GetFacility(np.Decimal) == 7) + { + // Must be an error code + if (GetSeverity(np.Decimal) == 2) + { + short err = GetCode(np.Decimal); + string description;// = winerror.GetWinerrorDescription(err); + + //if (description == null) + description = err.ToString("D"); + + description = String.Format("HRESULT_FROM_WIN32({0})", description); + + AddMessage(MessageType.Custom, + np.Decimal, + np.Hex, + description, + null); + } + } + } + + return true; + } + } +}
Modified: trunk/tools/Message Translator/MsgTrans.Library/ErrorCommand.cs URL: http://svn.reactos.org/svn/reactos/trunk/tools/Message%20Translator/MsgTrans... ============================================================================== --- trunk/tools/Message Translator/MsgTrans.Library/ErrorCommand.cs [iso-8859-1] (original) +++ trunk/tools/Message Translator/MsgTrans.Library/ErrorCommand.cs [iso-8859-1] Tue Apr 22 07:05:37 2008 @@ -10,6 +10,7 @@ private NtStatusCommand ntStatus; private WinerrorCommand winerror; private HResultCommand hresult; + private CustomCommand custom; private List<Command> errorCommands = new List<Command>();
public ErrorCommand(MessageTranslator msgTrans, @@ -18,9 +19,10 @@ string hresultXml) : base(msgTrans) { - ntStatus = new NtStatusCommand(msgTrans, ntstatusXml); - winerror = new WinerrorCommand(msgTrans, winerrorXml); - hresult = new HResultCommand(msgTrans, hresultXml); + errorCommands.Add(new NtStatusCommand(msgTrans, ntstatusXml)); + errorCommands.Add(new WinerrorCommand(msgTrans, winerrorXml)); + errorCommands.Add(new HResultCommand(msgTrans, hresultXml)); + errorCommands.Add(new CustomCommand(msgTrans)); }
public override string[] AvailableCommands @@ -28,187 +30,19 @@ get { return new string[] { "error" }; } }
- private static int GetSeverity(long error) - { - return (int)((error >> 30) & 0x3); - } - - private static bool IsCustomer(long error) - { - return (error & 0x20000000) != 0; - } - - private static bool IsReserved(long error) - { - return (error & 0x10000000) != 0; - } - - private static int GetFacility(long error) - { - return (int)((error >> 16) & 0xFFF); - } - - private static short GetCode(long error) - { - return (short)((error >> 0) & 0xFFFF); - } - - private static string FormatSeverity(long error) - { - int severity = GetSeverity(error); - switch (severity) - { - case 0: return "SUCCESS"; - case 1: return "INFORMATIONAL"; - case 2: return "WARNING"; - case 3: return "ERROR"; - } - return null; - } - - private static string FormatFacility(long error) - { - int facility = GetFacility(error); - return facility.ToString(); - } - - private static string FormatCode(long error) - { - int code = GetCode(error); - return code.ToString(); - } - - private void AddErrorCommand(MessageType msgType, - long dec, - string hex, - string code, - string msg) - { - MsgType = msgType; - Number = dec; - Hex = hex; - Code = code; - Message = msg; - MsgTrans.Messages.Add(this); - } - public override bool Handle(MessageContext context, string commandName, string parameters) { - string originalErrorText = parameters.Trim(); - if (originalErrorText.Equals(String.Empty)) - { - MsgTrans.MsgOutput.MsgOut(context, - "Please provide an Error Code."); - return false; - } - - string errorText = originalErrorText; + string errorText = parameters.Trim();
retry: - NumberParser np = new NumberParser(); - if (!np.Parse(errorText)) + + foreach (Command command in errorCommands) { - MsgTrans.MsgOutput.MsgOut(context, - String.Format("{0} is not a valid Error Code.", - originalErrorText)); - return false; - } - - ArrayList descriptions = new ArrayList(); - - // Error is out of bounds - if ((ulong)np.Decimal > uint.MaxValue) - { - // Do nothing - } - // Error is outside of the range [0, 65535]: it cannot be a plain Win32 error code - else if ((ulong)np.Decimal > ushort.MaxValue) - { - // Customer bit is set: custom error code - if (IsCustomer(np.Decimal)) - { - string description = String.Format("[custom, severity {0}, facility {1}, code {2}]", - FormatSeverity(np.Decimal), - FormatFacility(np.Decimal), - FormatCode(np.Decimal)); - AddErrorCommand(MessageType.Custom, - np.Decimal, - np.Hex, - description, - null); - } - // Reserved bit is set: HRESULT_FROM_NT(ntstatus) - else if (IsReserved(np.Decimal)) - { - int status = (int)(np.Decimal & 0xCFFFFFFF); - string description = ntStatus.GetNtstatusDescription(status); - - if (description == null) - description = status.ToString("X"); - - description = String.Format("HRESULT_FROM_NT({0})", description); - - AddErrorCommand(MessageType.Custom, - np.Decimal, - np.Hex, - description, - null); - } - // Win32 facility: HRESULT_FROM_WIN32(winerror) - else if (GetFacility(np.Decimal) == 7) - { - // Must be an error code - if (GetSeverity(np.Decimal) == 2) - { - short err = GetCode(np.Decimal); - string description = winerror.GetWinerrorDescription(err); - - if (description == null) - description = err.ToString("D"); - - description = String.Format("HRESULT_FROM_WIN32({0})", description); - - AddErrorCommand(MessageType.Custom, - np.Decimal, - np.Hex, - description, - null); - } - } - } - - string winerrorDescription = winerror.GetWinerrorDescription(np.Decimal); - if (winerrorDescription != null) - { - string message = new System.ComponentModel.Win32Exception(Convert.ToInt32(np.Decimal)).Message; - - AddErrorCommand(MessageType.WinError, - np.Decimal, - np.Hex, - winerrorDescription, - message); - } - - string ntstatusDescription = ntStatus.GetNtstatusDescription(np.Decimal); - if (ntstatusDescription != null) - { - AddErrorCommand(MessageType.NTStatus, - np.Decimal, - np.Hex, - ntstatusDescription, - null); - } - - string hresultDescription = hresult.GetHresultDescription(np.Decimal); - if (hresultDescription != null) - { - AddErrorCommand(MessageType.HResult, - np.Decimal, - np.Hex, - hresultDescription, - null); + command.Handle(context, + commandName, + errorText); }
if (MsgTrans.Messages.Count == 0) @@ -222,16 +56,16 @@
MsgTrans.MsgOutput.MsgOut(context, String.Format("I don't know about Error Code {0}.", - originalErrorText)); + parameters.Trim())); return false; } - + return true; }
public override string Help() { - return "!error <value>"; + return "error <value>"; } } }
Modified: trunk/tools/Message Translator/MsgTrans.Library/HresultCommand.cs URL: http://svn.reactos.org/svn/reactos/trunk/tools/Message%20Translator/MsgTrans... ============================================================================== --- trunk/tools/Message Translator/MsgTrans.Library/HresultCommand.cs [iso-8859-1] (original) +++ trunk/tools/Message Translator/MsgTrans.Library/HresultCommand.cs [iso-8859-1] Tue Apr 22 07:05:37 2008 @@ -21,6 +21,17 @@ string commandName, string parameters) { + /* + string hresultDescription = hresult.GetHresultDescription(np.Decimal); + if (hresultDescription != null) + { + AddErrorCommand(MessageType.HResult, + np.Decimal, + np.Hex, + hresultDescription, + null); + } + */ string hresultText = parameters; if (hresultText.Equals(String.Empty)) { @@ -44,14 +55,16 @@ Number = np.Decimal; Code = description; return true; - } + }/* else { MsgTrans.MsgOutput.MsgOut(context, String.Format("I don't know about HRESULT {0}.", hresultText)); return false; - } + }*/ + + return false; }
public override string Help()
Modified: trunk/tools/Message Translator/MsgTrans.Library/MsgTrans.Library.csproj URL: http://svn.reactos.org/svn/reactos/trunk/tools/Message%20Translator/MsgTrans... ============================================================================== --- trunk/tools/Message Translator/MsgTrans.Library/MsgTrans.Library.csproj [iso-8859-1] (original) +++ trunk/tools/Message Translator/MsgTrans.Library/MsgTrans.Library.csproj [iso-8859-1] Tue Apr 22 07:05:37 2008 @@ -46,6 +46,7 @@ <ItemGroup> <Compile Include="BugUrlCommandl.cs" /> <Compile Include="BugCommand.cs" /> + <Compile Include="CustomCommand.cs" /> <Compile Include="XmlCommand.cs" /> <Compile Include="ErrorCommand.cs" /> <Compile Include="HresultCommand.cs" />
Modified: trunk/tools/Message Translator/MsgTrans.Library/MsgTrans.cs URL: http://svn.reactos.org/svn/reactos/trunk/tools/Message%20Translator/MsgTrans... ============================================================================== --- trunk/tools/Message Translator/MsgTrans.Library/MsgTrans.cs [iso-8859-1] (original) +++ trunk/tools/Message Translator/MsgTrans.Library/MsgTrans.cs [iso-8859-1] Tue Apr 22 07:05:37 2008 @@ -58,7 +58,7 @@ { get { return msgOutput; } } - public IList<Command> Messages + public List<Command> Messages { get { return messages; } } @@ -78,7 +78,7 @@ winerrorXml, hresultXml)); commands.Add(new WMCommand(this, wmXml)); - commands.Add(new BugUrl(this, bugUrl)); + commands.Add(new BugCommand(this, bugUrl)); }
public bool ParseCommandMessage(MessageContext context,
Modified: trunk/tools/Message Translator/MsgTrans.Library/NtStatusCommand.cs URL: http://svn.reactos.org/svn/reactos/trunk/tools/Message%20Translator/MsgTrans... ============================================================================== --- trunk/tools/Message Translator/MsgTrans.Library/NtStatusCommand.cs [iso-8859-1] (original) +++ trunk/tools/Message Translator/MsgTrans.Library/NtStatusCommand.cs [iso-8859-1] Tue Apr 22 07:05:37 2008 @@ -40,10 +40,14 @@ string description = GetNtstatusDescription(np.Decimal); if (description != null) { - Number = np.Decimal; - Code = description; + AddMessage(MessageType.NTStatus, + np.Decimal, + np.Hex, + description, + null); + return true; - } + }/* else { MsgTrans.MsgOutput.MsgOut(context, @@ -51,7 +55,9 @@ ntstatusText));
return false; - } + }*/ + + return false; }
public override string Help()
Modified: trunk/tools/Message Translator/MsgTrans.Library/WinerrorCommand.cs URL: http://svn.reactos.org/svn/reactos/trunk/tools/Message%20Translator/MsgTrans... ============================================================================== --- trunk/tools/Message Translator/MsgTrans.Library/WinerrorCommand.cs [iso-8859-1] (original) +++ trunk/tools/Message Translator/MsgTrans.Library/WinerrorCommand.cs [iso-8859-1] Tue Apr 22 07:05:37 2008 @@ -20,6 +20,7 @@ string commandName, string parameters) { + string winerrorText = parameters; if (winerrorText.Equals(String.Empty)) { @@ -40,17 +41,25 @@ string description = GetWinerrorDescription(np.Decimal); if (description != null) { - Number = np.Decimal; - Code = description; + string message = new System.ComponentModel.Win32Exception(Convert.ToInt32(np.Decimal)).Message; + + AddMessage(MessageType.WinError, + np.Decimal, + np.Hex, + description, + message); + return true; - } + }/* else { MsgTrans.MsgOutput.MsgOut(context, String.Format("I don't know about System Error Code {0}.", winerrorText)); return false; - } + }*/ + + return false; }
public override string Help()