mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 16:36:33 +00:00
Add !error command which checks NtStatus, Winerror and hResult.
svn path=/trunk/; revision=20585
This commit is contained in:
parent
9edfccb5e4
commit
a61ec9018b
6 changed files with 100 additions and 4 deletions
91
irc/TechBot/TechBot.Library/ErrorCommand.cs
Normal file
91
irc/TechBot/TechBot.Library/ErrorCommand.cs
Normal file
|
@ -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 <value>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -67,7 +67,7 @@ namespace TechBot.Library
|
||||||
return "!hresult <value>";
|
return "!hresult <value>";
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetHresultDescription(long hresult)
|
public string GetHresultDescription(long hresult)
|
||||||
{
|
{
|
||||||
XmlElement root = hresultXmlDocument.DocumentElement;
|
XmlElement root = hresultXmlDocument.DocumentElement;
|
||||||
XmlNode node = root.SelectSingleNode(String.Format("Hresult[@value='{0}']",
|
XmlNode node = root.SelectSingleNode(String.Format("Hresult[@value='{0}']",
|
||||||
|
|
|
@ -67,7 +67,7 @@ namespace TechBot.Library
|
||||||
return "!ntstatus <value>";
|
return "!ntstatus <value>";
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetNtstatusDescription(long ntstatus)
|
public string GetNtstatusDescription(long ntstatus)
|
||||||
{
|
{
|
||||||
XmlElement root = ntstatusXmlDocument.DocumentElement;
|
XmlElement root = ntstatusXmlDocument.DocumentElement;
|
||||||
XmlNode node = root.SelectSingleNode(String.Format("Ntstatus[@value='{0}']",
|
XmlNode node = root.SelectSingleNode(String.Format("Ntstatus[@value='{0}']",
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
<File name=".\NumberParser.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
|
<File name=".\NumberParser.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
|
||||||
<File name=".\HresultCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
|
<File name=".\HresultCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
|
||||||
<File name=".\WinerrorCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
|
<File name=".\WinerrorCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
|
||||||
|
<File name=".\ErrorCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
|
||||||
<File name=".\SvnCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
|
<File name=".\SvnCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
|
||||||
<File name=".\BugCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
|
<File name=".\BugCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
|
||||||
<File name=".\WmCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
|
<File name=".\WmCommand.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
|
||||||
|
@ -39,4 +40,4 @@
|
||||||
<Output directory="..\bin\Release" assembly="TechBot.Library" executeScript="" executeBeforeBuild="" executeAfterBuild="" executeBeforeBuildArguments="" executeAfterBuildArguments="" />
|
<Output directory="..\bin\Release" assembly="TechBot.Library" executeScript="" executeBeforeBuild="" executeAfterBuild="" executeBeforeBuildArguments="" executeAfterBuildArguments="" />
|
||||||
</Configuration>
|
</Configuration>
|
||||||
</Configurations>
|
</Configurations>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -54,6 +54,10 @@ namespace TechBot.Library
|
||||||
winerrorXml));
|
winerrorXml));
|
||||||
commands.Add(new HresultCommand(serviceOutput,
|
commands.Add(new HresultCommand(serviceOutput,
|
||||||
hresultXml));
|
hresultXml));
|
||||||
|
commands.Add(new ErrorCommand(serviceOutput,
|
||||||
|
ntstatusXml,
|
||||||
|
winerrorXml,
|
||||||
|
hresultXml));
|
||||||
commands.Add(new WmCommand(serviceOutput,
|
commands.Add(new WmCommand(serviceOutput,
|
||||||
wmXml));
|
wmXml));
|
||||||
commands.Add(new SvnCommand(serviceOutput,
|
commands.Add(new SvnCommand(serviceOutput,
|
||||||
|
|
|
@ -67,7 +67,7 @@ namespace TechBot.Library
|
||||||
return "!winerror <value>";
|
return "!winerror <value>";
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetWinerrorDescription(long winerror)
|
public string GetWinerrorDescription(long winerror)
|
||||||
{
|
{
|
||||||
XmlElement root = winerrorXmlDocument.DocumentElement;
|
XmlElement root = winerrorXmlDocument.DocumentElement;
|
||||||
XmlNode node = root.SelectSingleNode(String.Format("Winerror[@value='{0}']",
|
XmlNode node = root.SelectSingleNode(String.Format("Winerror[@value='{0}']",
|
||||||
|
|
Loading…
Reference in a new issue