Add !error command which checks NtStatus, Winerror and hResult.
authorMaarten Bosma <maarten@bosma.de>
Thu, 5 Jan 2006 17:52:39 +0000 (17:52 +0000)
committerMaarten Bosma <maarten@bosma.de>
Thu, 5 Jan 2006 17:52:39 +0000 (17:52 +0000)
svn path=/trunk/; revision=20585

irc/TechBot/TechBot.Library/ErrorCommand.cs [new file with mode: 0644]
irc/TechBot/TechBot.Library/HresultCommand.cs
irc/TechBot/TechBot.Library/NtStatusCommand.cs
irc/TechBot/TechBot.Library/TechBot.Library.prjx
irc/TechBot/TechBot.Library/TechBotService.cs
irc/TechBot/TechBot.Library/WinerrorCommand.cs

diff --git a/irc/TechBot/TechBot.Library/ErrorCommand.cs b/irc/TechBot/TechBot.Library/ErrorCommand.cs
new file mode 100644 (file)
index 0000000..6ee2d68
--- /dev/null
@@ -0,0 +1,91 @@
+using System;\r
+using System.Xml;\r
+\r
+namespace TechBot.Library\r
+{\r
+       public class ErrorCommand : BaseCommand, ICommand\r
+       {\r
+               private IServiceOutput serviceOutput;\r
+               private NtStatusCommand ntStatus;\r
+               private WinerrorCommand winerror;\r
+               private HresultCommand hresult;\r
+\r
+               public ErrorCommand(IServiceOutput serviceOutput, string ntstatusXml,\r
+                                                                       string winerrorXml, string hresultXml)\r
+               {\r
+                       this.serviceOutput = serviceOutput;\r
+                       this.ntStatus = new NtStatusCommand(serviceOutput,\r
+                                                                                        ntstatusXml);\r
+                       this.winerror = new WinerrorCommand(serviceOutput,\r
+                                                                                       winerrorXml);\r
+                       this.hresult = new HresultCommand(serviceOutput,\r
+                                                                                       hresultXml);\r
+               }\r
+               \r
+               public bool CanHandle(string commandName)\r
+               {\r
+                       return CanHandle(commandName,\r
+                                        new string[] { "error" });\r
+               }\r
+\r
+               public void Handle(MessageContext context,\r
+                                  string commandName,\r
+                                  string parameters)\r
+               {\r
+                       string errorText = parameters;\r
+                       if (errorText.Equals(String.Empty))\r
+                       {\r
+                               serviceOutput.WriteLine(context,\r
+                                                       "Please provide an Error Code.");\r
+                               return;\r
+                       }\r
+\r
+                       NumberParser np = new NumberParser();\r
+                       long error = np.Parse(errorText);\r
+                       if (np.Error)\r
+                       {\r
+                               serviceOutput.WriteLine(context,\r
+                                                       String.Format("{0} is not a valid Error Code.",\r
+                                                                                                         errorText));\r
+                               return;\r
+                       }\r
+\r
+                       string description = null;\r
+                       if (winerror.GetWinerrorDescription(error) != null)\r
+                       {\r
+                               description = winerror.GetWinerrorDescription(error);\r
+                               serviceOutput.WriteLine(context,\r
+                                                       String.Format("{0} is {1}.",\r
+                                                                                                         error,\r
+                                                                     description));\r
+                       }\r
+                       if (ntStatus.GetNtstatusDescription(error) != null)\r
+                       {\r
+                               description = ntStatus.GetNtstatusDescription(error);\r
+                               serviceOutput.WriteLine(context,\r
+                                                                               String.Format("{0} is {1}.",\r
+                                                                                                         errorText,\r
+                                                                                                         description));\r
+                       }\r
+                       if (hresult.GetHresultDescription(error) != null)\r
+                       {\r
+                               description = hresult.GetHresultDescription(error);\r
+                               serviceOutput.WriteLine(context,\r
+                                                                               String.Format("{0} is {1}.",\r
+                                                                                                         errorText,\r
+                                                                                                         description));\r
+                       }\r
+                       if(description == null)\r
+                       {\r
+                               serviceOutput.WriteLine(context,\r
+                                                                               String.Format("I don't know about Error Code {0}.",\r
+                                                                                                         errorText));\r
+                       }\r
+               }\r
+               \r
+               public string Help()\r
+               {\r
+                       return "!error <value>";\r
+               }\r
+       }\r
+}\r
index df9ef4e..c17b577 100644 (file)
@@ -67,7 +67,7 @@ namespace TechBot.Library
                        return "!hresult <value>";\r
                }\r
                \r
-               private string GetHresultDescription(long hresult)\r
+               public string GetHresultDescription(long hresult)\r
                {\r
                        XmlElement root = hresultXmlDocument.DocumentElement;\r
                        XmlNode node = root.SelectSingleNode(String.Format("Hresult[@value='{0}']",\r
index 6841156..034df26 100644 (file)
@@ -67,7 +67,7 @@ namespace TechBot.Library
                        return "!ntstatus <value>";\r
                }\r
                \r
-               private string GetNtstatusDescription(long ntstatus)\r
+               public string GetNtstatusDescription(long ntstatus)\r
                {\r
                        XmlElement root = ntstatusXmlDocument.DocumentElement;\r
                        XmlNode node = root.SelectSingleNode(String.Format("Ntstatus[@value='{0}']",\r
index b2d45ac..cf716a4 100644 (file)
@@ -12,6 +12,7 @@
     <File name=".\NumberParser.cs" subtype="Code" buildaction="Compile" dependson="" data="" />\r
     <File name=".\HresultCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />\r
     <File name=".\WinerrorCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />\r
+    <File name=".\ErrorCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />\r
     <File name=".\SvnCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />\r
     <File name=".\BugCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />\r
     <File name=".\WmCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />\r
@@ -39,4 +40,4 @@
       <Output directory="..\bin\Release" assembly="TechBot.Library" executeScript="" executeBeforeBuild="" executeAfterBuild="" executeBeforeBuildArguments="" executeAfterBuildArguments="" />\r
     </Configuration>\r
   </Configurations>\r
-</Project>
\ No newline at end of file
+</Project>\r
index e169fc8..1b7f95d 100644 (file)
@@ -54,6 +54,10 @@ namespace TechBot.Library
                                                         winerrorXml));\r
                        commands.Add(new HresultCommand(serviceOutput,\r
                                                        hresultXml));\r
+                       commands.Add(new ErrorCommand(serviceOutput,\r
+                                                                                       ntstatusXml,\r
+                                                                                       winerrorXml,\r
+                                                                                       hresultXml));\r
                        commands.Add(new WmCommand(serviceOutput,\r
                                                   wmXml));\r
                        commands.Add(new SvnCommand(serviceOutput,\r
index ad01aca..9fd79c4 100644 (file)
@@ -67,7 +67,7 @@ namespace TechBot.Library
                        return "!winerror <value>";\r
                }\r
                \r
-               private string GetWinerrorDescription(long winerror)\r
+               public string GetWinerrorDescription(long winerror)\r
                {\r
                        XmlElement root = winerrorXmlDocument.DocumentElement;\r
                        XmlNode node = root.SelectSingleNode(String.Format("Winerror[@value='{0}']",\r