- Moved commands outside TechBot.Library to TechBot.Commands.Common and TechBot.Commands.MSDN except for Command base classes

- Made TechBot more configurable through .config files
- Code refactoring
- Removed automatic parameter parsing support to make everyone happy

svn path=/trunk/; revision=33586
This commit is contained in:
Marc Piulachs 2008-05-18 15:54:43 +00:00
parent 6d51a10a1b
commit ac77d9d3a6
47 changed files with 1783 additions and 489 deletions

View file

@ -0,0 +1,42 @@
using System;
using TechBot.Library;
namespace TechBot.Commands.Common
{
public abstract class BugCommand : Command
{
private string m_BugID = null;
public BugCommand()
{
}
public string BugID
{
get { return Parameters; }
set { Parameters = value; }
}
public override void ExecuteCommand()
{
if (Parameters == null)
{
Say("Please provide a valid bug number.");
}
else
{
try
{
Say(BugUrl, Int32.Parse(BugID));
}
catch (Exception)
{
Say("{0} is not a valid bug number.", BugID);
}
}
}
protected abstract string BugUrl { get; }
}
}

View file

@ -0,0 +1,66 @@
using System;
using System.Xml;
using TechBot.Library;
namespace TechBot.Commands.Common
{
[Command("hresult", Help = "!hresult <value>")]
public class HResultCommand : XmlLookupCommand
{
public HResultCommand()
{
}
public override string XmlFile
{
get { return Settings.Default.HResultXml; }
}
public override void ExecuteCommand()
{
if (Text == null)
{
Say("Please provide a valid HRESULT value.");
}
else
{
NumberParser np = new NumberParser();
long hresult = np.Parse(Text);
if (np.Error)
{
Say("{0} is not a valid HRESULT value.", Text);
return;
}
string description = GetHresultDescription(hresult);
if (description != null)
{
Say("{0} is {1}.",
Text,
description);
}
else
{
Say("I don't know about HRESULT {0}.", Text);
}
}
}
public string GetHresultDescription(long hresult)
{
XmlElement root = base.m_XmlDocument.DocumentElement;
XmlNode node = root.SelectSingleNode(String.Format("Hresult[@value='{0}']",
hresult.ToString("X8")));
if (node != null)
{
XmlAttribute text = node.Attributes["text"];
if (text == null)
throw new Exception("Node has no text attribute.");
return text.Value;
}
else
return null;
}
}
}

View file

@ -0,0 +1,66 @@
using System;
using System.Xml;
using TechBot.Library;
namespace TechBot.Commands.Common
{
[Command("ntstatus", Help = "!ntstatus <value>")]
public class NtStatusCommand : XmlLookupCommand
{
public NtStatusCommand()
{
}
public override string XmlFile
{
get { return Settings.Default.NtStatusXml; }
}
public override void ExecuteCommand()
{
if (Text == null)
{
Say("Please provide a valid NTSTATUS value.");
}
else
{
NumberParser np = new NumberParser();
long ntstatus = np.Parse(Text);
if (np.Error)
{
Say("{0} is not a valid NTSTATUS value.", Text);
return;
}
string description = GetNtstatusDescription(ntstatus);
if (description != null)
{
Say("{0} is {1}.",
Text,
description);
}
else
{
Say("I don't know about NTSTATUS {0}.", Text);
}
}
}
public string GetNtstatusDescription(long ntstatus)
{
XmlElement root = base.m_XmlDocument.DocumentElement;
XmlNode node = root.SelectSingleNode(String.Format("Ntstatus[@value='{0}']",
ntstatus.ToString("X8")));
if (node != null)
{
XmlAttribute text = node.Attributes["text"];
if (text == null)
throw new Exception("Node has no text attribute.");
return text.Value;
}
else
return null;
}
}
}

View file

@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("TechBot.Commands.Common")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Sand")]
[assembly: AssemblyProduct("TechBot.Commands.Common")]
[assembly: AssemblyCopyright("Copyright © Sand 2008")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5d39d6f8-37fb-423b-ba88-1d5d8e5a1317")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View file

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
using TechBot.Library;
namespace TechBot.Commands.Common
{
[Command("rosbug", Help = "!rosbug <number>", Description = "Will give you a link to the reqested ReactOS bug")]
class ReactOSBugUrl : BugCommand
{
public ReactOSBugUrl()
{
}
protected override string BugUrl
{
get { return "http://www.reactos.org/bugzilla/show_bug.cgi?id={0}"; }
}
}
}

View file

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
using TechBot.Library;
namespace TechBot.Commands.Common
{
[Command("sambabug", Help = "!sambabug <number>", Description = "Will give you a link to the reqested Samba bug")]
class SambaBugUrl : BugCommand
{
public SambaBugUrl()
{
}
protected override string BugUrl
{
get { return "https://bugzilla.samba.org/show_bug.cgi?id={0}"; }
}
}
}

View file

@ -0,0 +1,71 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.1433
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace TechBot.Commands.Common {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "8.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("C:\\Ros\\current\\irc\\TechBot\\Resources\\ntstatus.xml")]
public string NtStatusXml {
get {
return ((string)(this["NtStatusXml"]));
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("C:\\Ros\\current\\irc\\TechBot\\Resources\\winerror.xml")]
public string WinErrorXml {
get {
return ((string)(this["WinErrorXml"]));
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("C:\\Ros\\current\\irc\\TechBot\\Resources\\hresult.xml")]
public string HResultXml {
get {
return ((string)(this["HResultXml"]));
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("C:\\Ros\\current\\irc\\TechBot\\Resources\\wm.xml")]
public string WMXml {
get {
return ((string)(this["WMXml"]));
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("svn://svn.reactos.org/trunk/reactos")]
public string SVNRoot {
get {
return ((string)(this["SVNRoot"]));
}
}
}
}

View file

@ -0,0 +1,28 @@
namespace TechBot.Commands.Common {
// This class allows you to handle specific events on the settings class:
// The SettingChanging event is raised before a setting's value is changed.
// The PropertyChanged event is raised after a setting's value is changed.
// The SettingsLoaded event is raised after the setting values are loaded.
// The SettingsSaving event is raised before the setting values are saved.
internal sealed partial class Settings {
public Settings() {
// // To add event handlers for saving and changing settings, uncomment the lines below:
//
// this.SettingChanging += this.SettingChangingEventHandler;
//
// this.SettingsSaving += this.SettingsSavingEventHandler;
//
}
private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
// Add code to handle the SettingChangingEvent event here.
}
private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
// Add code to handle the SettingsSaving event here.
}
}
}

View file

@ -0,0 +1,21 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="TechBot.Commands.Common" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="NtStatusXml" Type="System.String" Scope="Application">
<Value Profile="(Default)">C:\Ros\current\irc\TechBot\Resources\ntstatus.xml</Value>
</Setting>
<Setting Name="WinErrorXml" Type="System.String" Scope="Application">
<Value Profile="(Default)">C:\Ros\current\irc\TechBot\Resources\winerror.xml</Value>
</Setting>
<Setting Name="HResultXml" Type="System.String" Scope="Application">
<Value Profile="(Default)">C:\Ros\current\irc\TechBot\Resources\hresult.xml</Value>
</Setting>
<Setting Name="WMXml" Type="System.String" Scope="Application">
<Value Profile="(Default)">C:\Ros\current\irc\TechBot\Resources\wm.xml</Value>
</Setting>
<Setting Name="SVNRoot" Type="System.String" Scope="Application">
<Value Profile="(Default)">svn://svn.reactos.org/trunk/reactos</Value>
</Setting>
</Settings>
</SettingsFile>

View file

@ -0,0 +1,22 @@
using System;
using TechBot.Library;
namespace TechBot.Commands.Common
{
[Command("svn", Help = "!svn" , Description="Where the ROS SVN repository is located")]
public class SvnCommand : Command
{
private string m_SvnRoot;
public SvnCommand()
{
m_SvnRoot = Settings.Default.SVNRoot;
}
public override void ExecuteCommand()
{
Say("svn co {0}", m_SvnRoot);
}
}
}

View file

@ -0,0 +1,74 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{041B5F06-BF97-4981-B024-3A7B6DD9F6AE}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TechBot.Commands.Common</RootNamespace>
<AssemblyName>TechBot.Commands.Common</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Base\BugCommand.cs" />
<Compile Include="HResultCommand.cs" />
<Compile Include="NtStatusCommand.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReactOSBugUrl.cs" />
<Compile Include="SambaBugUrl.cs" />
<Compile Include="Settings.cs" />
<Compile Include="Settings.Designer.cs">
<DependentUpon>Settings.settings</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="SvnCommand.cs" />
<Compile Include="WineBugUrl.cs" />
<Compile Include="WinerrorCommand.cs" />
<Compile Include="WMCommand.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TechBot.Library\TechBot.Library.csproj">
<Project>{1114F34D-F388-4F38-AE27-C0EE1B10B777}</Project>
<Name>TechBot.Library</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View file

@ -0,0 +1,94 @@
using System;
using System.Xml;
using TechBot.Library;
namespace TechBot.Commands.Common
{
[Command("wm" , Help = "!wm <value> or !wm <name>")]
public class WMCommand : XmlCommand
{
public WMCommand()
{
}
public override string XmlFile
{
get { return Settings.Default.WMXml; }
}
[CommandParameter("wm", "The windows message to check" , DefaultParameter = true)]
public string WMText
{
get { return Parameters; }
set { Parameters = value; }
}
public override void ExecuteCommand()
{
if (WMText == null)
{
Say("Please provide a valid window message value or name.");
}
else
{
NumberParser np = new NumberParser();
long wm = np.Parse(WMText);
string output;
if (np.Error)
{
// Assume "!wm <name>" form.
output = GetWmNumber(WMText);
}
else
{
output = GetWmDescription(wm);
}
if (output != null)
{
Say("{0} is {1}.",
WMText,
output);
}
else
{
Say("I don't know about window message {0}.", WMText);
}
}
}
private string GetWmDescription(long wm)
{
XmlElement root = base.m_XmlDocument.DocumentElement;
XmlNode node = root.SelectSingleNode(String.Format("WindowMessage[@value='{0}']",
wm));
if (node != null)
{
XmlAttribute text = node.Attributes["text"];
if (text == null)
throw new Exception("Node has no text attribute.");
return text.Value;
}
else
return null;
}
private string GetWmNumber(string wmName)
{
XmlElement root = base.m_XmlDocument.DocumentElement;
XmlNode node = root.SelectSingleNode(String.Format("WindowMessage[@text='{0}']",
wmName));
if (node != null)
{
XmlAttribute value = node.Attributes["value"];
if (value == null)
throw new Exception("Node has no value attribute.");
return value.Value;
}
else
return null;
}
}
}

View file

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
using TechBot.Library;
namespace TechBot.Commands.Common
{
[Command("winebug", Help = "!winebug <number>" , Description="Will give you a link to the reqested Wine bug")]
class WineBugUrl : BugCommand
{
public WineBugUrl()
{
}
protected override string BugUrl
{
get { return "http://bugs.winehq.org/show_bug.cgi?id={0}"; }
}
}
}

View file

@ -0,0 +1,66 @@
using System;
using System.Xml;
using TechBot.Library;
namespace TechBot.Commands.Common
{
[Command("winerror", Help = "!winerror <value>")]
public class WinErrorCommand : XmlLookupCommand
{
public WinErrorCommand()
{
}
public override string XmlFile
{
get { return Settings.Default.WinErrorXml; }
}
public override void ExecuteCommand()
{
if (Text == null)
{
Say("Please provide a valid System Error Code value.");
}
else
{
NumberParser np = new NumberParser();
long winerror = np.Parse(Text);
if (np.Error)
{
Say("{0} is not a valid System Error Code value.", Text);
return;
}
string description = GetWinerrorDescription(winerror);
if (description != null)
{
Say("{0} is {1}.",
Text,
description);
}
else
{
Say("I don't know about System Error Code {0}.", Text);
}
}
}
public string GetWinerrorDescription(long winerror)
{
XmlElement root = base.m_XmlDocument.DocumentElement;
XmlNode node = root.SelectSingleNode(String.Format("Winerror[@value='{0}']",
Text));
if (node != null)
{
XmlAttribute text = node.Attributes["text"];
if (text == null)
throw new Exception("Node has no text attribute.");
return text.Value;
}
else
return null;
}
}
}

View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="TechBot.Commands.Common.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<TechBot.Commands.Common.Settings>
<setting name="NtStatusXml" serializeAs="String">
<value>C:\Ros\current\irc\TechBot\Resources\ntstatus.xml</value>
</setting>
<setting name="WinErrorXml" serializeAs="String">
<value>C:\Ros\current\irc\TechBot\Resources\winerror.xml</value>
</setting>
<setting name="HResultXml" serializeAs="String">
<value>C:\Ros\current\irc\TechBot\Resources\hresult.xml</value>
</setting>
<setting name="WMXml" serializeAs="String">
<value>C:\Ros\current\irc\TechBot\Resources\wm.xml</value>
</setting>
<setting name="SVNRoot" serializeAs="String">
<value>svn://svn.reactos.org/trunk/reactos</value>
</setting>
</TechBot.Commands.Common.Settings>
</applicationSettings>
</configuration>