diff --git a/irc/TechBot/TechBot.Library/ErrorCommand.cs b/irc/TechBot/TechBot.Library/ErrorCommand.cs new file mode 100644 index 00000000000..6ee2d68f865 --- /dev/null +++ b/irc/TechBot/TechBot.Library/ErrorCommand.cs @@ -0,0 +1,91 @@ +using System; +using System.Xml; + +namespace TechBot.Library +{ + public class ErrorCommand : BaseCommand, ICommand + { + private IServiceOutput serviceOutput; + private NtStatusCommand ntStatus; + private WinerrorCommand winerror; + private HresultCommand hresult; + + public ErrorCommand(IServiceOutput serviceOutput, string ntstatusXml, + string winerrorXml, string hresultXml) + { + this.serviceOutput = serviceOutput; + this.ntStatus = new NtStatusCommand(serviceOutput, + ntstatusXml); + this.winerror = new WinerrorCommand(serviceOutput, + winerrorXml); + this.hresult = new HresultCommand(serviceOutput, + hresultXml); + } + + public bool CanHandle(string commandName) + { + return CanHandle(commandName, + new string[] { "error" }); + } + + public void Handle(MessageContext context, + string commandName, + string parameters) + { + string errorText = parameters; + if (errorText.Equals(String.Empty)) + { + serviceOutput.WriteLine(context, + "Please provide an Error Code."); + return; + } + + NumberParser np = new NumberParser(); + long error = np.Parse(errorText); + if (np.Error) + { + serviceOutput.WriteLine(context, + String.Format("{0} is not a valid Error Code.", + errorText)); + return; + } + + string description = null; + if (winerror.GetWinerrorDescription(error) != null) + { + description = winerror.GetWinerrorDescription(error); + serviceOutput.WriteLine(context, + String.Format("{0} is {1}.", + error, + description)); + } + if (ntStatus.GetNtstatusDescription(error) != null) + { + description = ntStatus.GetNtstatusDescription(error); + serviceOutput.WriteLine(context, + String.Format("{0} is {1}.", + errorText, + description)); + } + if (hresult.GetHresultDescription(error) != null) + { + description = hresult.GetHresultDescription(error); + serviceOutput.WriteLine(context, + String.Format("{0} is {1}.", + errorText, + description)); + } + if(description == null) + { + serviceOutput.WriteLine(context, + String.Format("I don't know about Error Code {0}.", + errorText)); + } + } + + public string Help() + { + return "!error "; + } + } +} diff --git a/irc/TechBot/TechBot.Library/HresultCommand.cs b/irc/TechBot/TechBot.Library/HresultCommand.cs index df9ef4ead76..c17b577c912 100644 --- a/irc/TechBot/TechBot.Library/HresultCommand.cs +++ b/irc/TechBot/TechBot.Library/HresultCommand.cs @@ -67,7 +67,7 @@ namespace TechBot.Library return "!hresult "; } - private string GetHresultDescription(long hresult) + public string GetHresultDescription(long hresult) { XmlElement root = hresultXmlDocument.DocumentElement; XmlNode node = root.SelectSingleNode(String.Format("Hresult[@value='{0}']", diff --git a/irc/TechBot/TechBot.Library/NtStatusCommand.cs b/irc/TechBot/TechBot.Library/NtStatusCommand.cs index 6841156f1e5..034df26cd2a 100644 --- a/irc/TechBot/TechBot.Library/NtStatusCommand.cs +++ b/irc/TechBot/TechBot.Library/NtStatusCommand.cs @@ -67,7 +67,7 @@ namespace TechBot.Library return "!ntstatus "; } - private string GetNtstatusDescription(long ntstatus) + public string GetNtstatusDescription(long ntstatus) { XmlElement root = ntstatusXmlDocument.DocumentElement; XmlNode node = root.SelectSingleNode(String.Format("Ntstatus[@value='{0}']", diff --git a/irc/TechBot/TechBot.Library/TechBot.Library.prjx b/irc/TechBot/TechBot.Library/TechBot.Library.prjx index b2d45aca957..cf716a49996 100644 --- a/irc/TechBot/TechBot.Library/TechBot.Library.prjx +++ b/irc/TechBot/TechBot.Library/TechBot.Library.prjx @@ -12,6 +12,7 @@ + @@ -39,4 +40,4 @@ - \ No newline at end of file + diff --git a/irc/TechBot/TechBot.Library/TechBotService.cs b/irc/TechBot/TechBot.Library/TechBotService.cs index e169fc82482..1b7f95d187f 100644 --- a/irc/TechBot/TechBot.Library/TechBotService.cs +++ b/irc/TechBot/TechBot.Library/TechBotService.cs @@ -54,6 +54,10 @@ namespace TechBot.Library winerrorXml)); commands.Add(new HresultCommand(serviceOutput, hresultXml)); + commands.Add(new ErrorCommand(serviceOutput, + ntstatusXml, + winerrorXml, + hresultXml)); commands.Add(new WmCommand(serviceOutput, wmXml)); commands.Add(new SvnCommand(serviceOutput, diff --git a/irc/TechBot/TechBot.Library/WinerrorCommand.cs b/irc/TechBot/TechBot.Library/WinerrorCommand.cs index ad01acaec14..9fd79c425b1 100644 --- a/irc/TechBot/TechBot.Library/WinerrorCommand.cs +++ b/irc/TechBot/TechBot.Library/WinerrorCommand.cs @@ -67,7 +67,7 @@ namespace TechBot.Library return "!winerror "; } - private string GetWinerrorDescription(long winerror) + public string GetWinerrorDescription(long winerror) { XmlElement root = winerrorXmlDocument.DocumentElement; XmlNode node = root.SelectSingleNode(String.Format("Winerror[@value='{0}']",