- 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>

View file

@ -0,0 +1,310 @@
using System;
using System.IO;
using System.Data;
using System.Text.RegularExpressions;
using HtmlHelp;
using HtmlHelp.ChmDecoding;
using TechBot.Library;
namespace TechBot.Commands.MSDN
{
[Command("api", Help = "!api <apiname>")]
public class ApiCommand : Command
{
private bool IsVerbose = false;
private HtmlHelpSystem chm;
private string name;
public ApiCommand()
{
Run();
}
[CommandParameter("api", "The API name")]
public string API
{
get { return Parameters; }
set { Parameters = value; }
}
private void WriteIfVerbose(string message)
{
if (IsVerbose)
Say(message);
}
private void Run()
{
string CHMFilename = Path.Combine(Settings.Default.ChmPath, Settings.Default.MainChm);
chm = new HtmlHelpSystem();
chm.OpenFile(CHMFilename, null);
Console.WriteLine(String.Format("Loaded main CHM: {0}",
Path.GetFileName(CHMFilename)));
foreach (string filename in Directory.GetFiles(Settings.Default.ChmPath))
{
if (!Path.GetExtension(filename).ToLower().Equals(".chm"))
continue;
if (Path.GetFileName(filename).ToLower().Equals(Settings.Default.MainChm))
continue;
Console.WriteLine(String.Format("Loading CHM: {0}",
Path.GetFileName(filename)));
try
{
chm.MergeFile(filename);
}
catch (Exception ex)
{
Console.WriteLine(String.Format("Could not load CHM: {0}. Exception {1}",
Path.GetFileName(filename),
ex));
}
}
Console.WriteLine(String.Format("Loaded {0} CHMs",
chm.FileList.Length));
}
public override void ExecuteCommand()
{
if (Name.Trim().Equals(String.Empty))
{
Say("Please give me a keyword.");
}
else
{
Search(Name);
}
}
private bool SearchIndex(
string keyword)
{
if (chm.HasIndex)
{
IndexItem item = chm.Index.SearchIndex(keyword,
IndexType.KeywordLinks);
if (item != null && item.Topics.Count > 0)
{
WriteIfVerbose(String.Format("Keyword {0} found in index",
item.KeyWord));
IndexTopic indexTopic = item.Topics[0] as IndexTopic;
return DisplayResult( keyword,
indexTopic);
}
else
{
WriteIfVerbose(String.Format("Keyword {0} not found in index",
keyword));
return false;
}
}
else
return false;
}
private void SearchFullText(string keyword)
{
string sort = "Rating ASC";
WriteIfVerbose(String.Format("Searching fulltext database for {0}",
keyword));
bool partialMatches = false;
bool titlesOnly = true;
int maxResults = 100;
DataTable results = chm.PerformSearch(keyword,
maxResults,
partialMatches,
titlesOnly);
WriteIfVerbose(String.Format("results.Rows.Count = {0}",
results != null ?
results.Rows.Count.ToString() : "(none)"));
if (results != null && results.Rows.Count > 0)
{
results.DefaultView.Sort = sort;
if (!DisplayResult(keyword,
results))
{
Say("No result");
}
}
else
{
Say("No result");
}
}
private void Search(string keyword)
{
if (!SearchIndex(keyword))
SearchFullText(keyword);
}
private bool DisplayResult(string keyword,
IndexTopic indexTopic)
{
keyword = keyword.Trim().ToLower();
string url = indexTopic.URL;
WriteIfVerbose(String.Format("URL from index search {0}",
url));
string prototype = ExtractPrototype(url);
if (prototype == null || prototype.Trim().Equals(String.Empty))
return false;
string formattedPrototype = FormatPrototype(prototype);
Say(formattedPrototype);
return true;
}
private bool DisplayResult(string keyword,
DataTable results)
{
keyword = keyword.Trim().ToLower();
for (int i = 0; i < results.DefaultView.Count; i++)
{
DataRowView row = results.DefaultView[i];
string title = row["Title"].ToString();
WriteIfVerbose(String.Format("Examining {0}", title));
if (title.Trim().ToLower().Equals(keyword))
{
string location = row["Location"].ToString();
string rating = row["Rating"].ToString();
string url = row["Url"].ToString();
string prototype = ExtractPrototype(url);
if (prototype == null || prototype.Trim().Equals(String.Empty))
continue;
string formattedPrototype = FormatPrototype(prototype);
Say(formattedPrototype);
return true;
}
}
return false;
}
private void DisplayNoResult(MessageContext context,
string keyword)
{
TechBot.ServiceOutput.WriteLine(context,
String.Format("I don't know about keyword {0}",
keyword));
}
private string ReplaceComments(string s)
{
return Regex.Replace(s, "//(.+)\r\n", "");
}
private string ReplaceLineEndings(string s)
{
return Regex.Replace(s, "(\r\n)+", " ");
}
private string ReplaceSpaces(string s)
{
return Regex.Replace(s, @" +", " ");
}
private string ReplaceSpacesBeforeLeftParenthesis(string s)
{
return Regex.Replace(s, @"\( ", @"(");
}
private string ReplaceSpacesBeforeRightParenthesis(string s)
{
return Regex.Replace(s, @" \)", @")");
}
private string ReplaceSemicolon(string s)
{
return Regex.Replace(s, @";", @"");
}
private string FormatPrototype(string prototype)
{
string s = ReplaceComments(prototype);
s = ReplaceLineEndings(s);
s = ReplaceSpaces(s);
s = ReplaceSpacesBeforeLeftParenthesis(s);
s = ReplaceSpacesBeforeRightParenthesis(s);
s = ReplaceSemicolon(s);
return s;
}
private string ExtractPrototype(string url)
{
string page = GetPage(url);
Match match = Regex.Match(page,
"<PRE class=\"?syntax\"?>(.+)</PRE>",
RegexOptions.Multiline |
RegexOptions.Singleline);
if (match.Groups.Count > 1)
{
string prototype = match.Groups[1].ToString();
return StripHtml(StripAfterSlashPre(prototype));
}
return "";
}
private string StripAfterSlashPre(string html)
{
int index = html.IndexOf("</PRE>");
if (index != -1)
{
return html.Substring(0, index);
}
else
return html;
}
private string StripHtml(string html)
{
return Regex.Replace(html, @"<(.|\n)*?>", String.Empty);
}
private string GetPage(string url)
{
string CHMFileName = "";
string topicName = "";
string anchor = "";
CHMStream.CHMStream baseStream;
if (!chm.BaseStream.GetCHMParts(url, ref CHMFileName, ref topicName, ref anchor))
{
baseStream = chm.BaseStream;
CHMFileName = baseStream.CHMFileName;
topicName = url;
anchor = "";
}
else
{
baseStream = GetBaseStreamFromCHMFileName(CHMFileName);
}
if ((topicName == "") || (CHMFileName == "") || (baseStream == null))
{
return "";
}
return baseStream.ExtractTextFile(topicName);
}
private CHMStream.CHMStream GetBaseStreamFromCHMFileName(string CHMFileName)
{
foreach (CHMFile file in chm.FileList)
{
WriteIfVerbose(String.Format("Compare: {0} <> {1}",
file.ChmFilePath,
CHMFileName));
if (file.ChmFilePath.ToLower().Equals(CHMFileName.ToLower()))
{
return file.BaseStream;
}
}
WriteIfVerbose(String.Format("Could not find loaded CHM file in list: {0}",
CHMFileName));
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.MSDN")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Sand")]
[assembly: AssemblyProduct("TechBot.Commands.MSDN")]
[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("8a6332ce-82e3-4fbd-a799-8f4b8d025955")]
// 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,50 @@
//------------------------------------------------------------------------------
// <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.MSDN {
[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.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("C:\\IRC\\TechBot\\CHM")]
public string ChmPath {
get {
return ((string)(this["ChmPath"]));
}
set {
this["ChmPath"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("kmarch.chm")]
public string MainChm {
get {
return ((string)(this["MainChm"]));
}
set {
this["MainChm"] = value;
}
}
}
}

View file

@ -0,0 +1,12 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="TechBot.Commands.MSDN" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="ChmPath" Type="System.String" Scope="User">
<Value Profile="(Default)">C:\IRC\TechBot\CHM</Value>
</Setting>
<Setting Name="MainChm" Type="System.String" Scope="User">
<Value Profile="(Default)">kmarch.chm</Value>
</Setting>
</Settings>
</SettingsFile>

View file

@ -0,0 +1,69 @@
<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>{ADBF1ED6-A586-4707-BD59-4CD53448D0FE}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TechBot.Commands.MSDN</RootNamespace>
<AssemblyName>TechBot.Commands.MSDN</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="ApiCommand.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CHMLibrary\CHMLibrary.csproj">
<Project>{72E5CCA1-6318-4D62-964D-CB23A5C743B5}</Project>
<Name>CHMLibrary</Name>
</ProjectReference>
<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,5 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="TechBot.Commands.MSDN.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<TechBot.Commands.MSDN.Settings>
<setting name="ChmPath" serializeAs="String">
<value>C:\IRC\TechBot\CHM</value>
</setting>
<setting name="MainChm" serializeAs="String">
<value>kmarch.chm</value>
</setting>
</TechBot.Commands.MSDN.Settings>
</userSettings>
</configuration>

View file

@ -1,15 +1,27 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="IRCServerHostName" value="irc.eu.freenode.net" />
<add key="IRCServerHostPort" value="6667" />
<add key="IRCChannelNames" value="channel1;channel2" />
<add key="IRCBotName" value="MyBot" />
<add key="IRCBotPassword" value="MyPassword" />
<add key="ChmPath" value="C:\IRC\TechBot\CHM" />
<add key="MainChm" value="kmarch.chm" />
<add key="BugUrl" value="http://www.reactos.org/bugzilla/show_bug.cgi?id={0}" />
<add key="WineBugUrl" value="http://bugs.winehq.org/show_bug.cgi?id={0}" />
<add key="SambaBugUrl" value="https://bugzilla.samba.org/show_bug.cgi?id={0}" />
</appSettings>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="TechBot.Console.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<TechBot.Console.Settings>
<setting name="IRCServerHostName" serializeAs="String">
<value>irc.eu.freenode.net</value>
</setting>
<setting name="IRCChannelNames" serializeAs="String">
<value>rbuildbottest2</value>
</setting>
<setting name="IRCBotName" serializeAs="String">
<value>RBuildBot2</value>
</setting>
<setting name="IRCBotPassword" serializeAs="String">
<value>qwerty</value>
</setting>
<setting name="IRCServerHostPort" serializeAs="String">
<value>6667</value>
</setting>
</TechBot.Console.Settings>
</userSettings>
</configuration>

View file

@ -17,11 +17,10 @@ namespace TechBot.Console
public class ConsoleTechBotService : TechBotService
{
public ConsoleTechBotService(
string chmPath,
string mainChm)
: base(new ConsoleServiceOutput(), chmPath, mainChm)
public ConsoleTechBotService()
: base(new ConsoleServiceOutput())
{
System.Console.WriteLine("TechBot running console service...");
}
public override void Run()
@ -31,8 +30,7 @@ namespace TechBot.Console
while (true)
{
string s = System.Console.ReadLine();
InjectMessage(null, s);
InjectMessage(System.Console.ReadLine());
}
}
}

View file

@ -6,232 +6,21 @@ namespace TechBot.Console
{
class MainClass
{
private static void VerifyRequiredOption(string optionName,
string optionValue)
{
if (optionValue == null)
{
throw new Exception(String.Format("Option '{0}' not set.",
optionName));
}
}
private static string IRCServerHostName
{
get
{
string optionName = "IRCServerHostName";
string s = ConfigurationSettings.AppSettings[optionName];
VerifyRequiredOption(optionName,
s);
return s;
}
}
private static int IRCServerHostPort
{
get
{
string optionName = "IRCServerHostPort";
string s = ConfigurationSettings.AppSettings[optionName];
VerifyRequiredOption(optionName,
s);
return Int32.Parse(s);
}
}
private static string IRCChannelNames
{
get
{
string optionName = "IRCChannelNames";
string s = ConfigurationSettings.AppSettings[optionName];
VerifyRequiredOption(optionName,
s);
return s;
}
}
private static string IRCBotName
{
get
{
string optionName = "IRCBotName";
string s = ConfigurationSettings.AppSettings[optionName];
VerifyRequiredOption(optionName,
s);
return s;
}
}
private static string IRCBotPassword
{
get
{
string optionName = "IRCBotPassword";
string s = ConfigurationSettings.AppSettings[optionName];
VerifyRequiredOption(optionName,
s);
return s;
}
}
private static string ChmPath
{
get
{
string optionName = "ChmPath";
string s = ConfigurationSettings.AppSettings[optionName];
VerifyRequiredOption(optionName,
s);
return s;
}
}
private static string MainChm
{
get
{
string optionName = "MainChm";
string s = ConfigurationSettings.AppSettings[optionName];
VerifyRequiredOption(optionName,
s);
return s;
}
}
private static string NtstatusXml
{
get
{
string optionName = "NtstatusXml";
string s = ConfigurationSettings.AppSettings[optionName];
VerifyRequiredOption(optionName,
s);
return s;
}
}
private static string WinerrorXml
{
get
{
string optionName = "WinerrorXml";
string s = ConfigurationSettings.AppSettings[optionName];
VerifyRequiredOption(optionName,
s);
return s;
}
}
private static string HresultXml
{
get
{
string optionName = "HresultXml";
string s = ConfigurationSettings.AppSettings[optionName];
VerifyRequiredOption(optionName,
s);
return s;
}
}
private static string WmXml
{
get
{
string optionName = "WmXml";
string s = ConfigurationSettings.AppSettings[optionName];
VerifyRequiredOption(optionName,
s);
return s;
}
}
private static string SvnCommand
{
get
{
string optionName = "SvnCommand";
string s = ConfigurationSettings.AppSettings[optionName];
VerifyRequiredOption(optionName,
s);
return s;
}
}
private static string BugUrl
{
get
{
string optionName = "BugUrl";
string s = ConfigurationSettings.AppSettings[optionName];
VerifyRequiredOption(optionName,
s);
return s;
}
}
private static string WineBugUrl
{
get
{
string optionName = "WineBugUrl";
string s = ConfigurationSettings.AppSettings[optionName];
VerifyRequiredOption(optionName,
s);
return s;
}
}
private static string SambaBugUrl
{
get
{
string optionName = "SambaBugUrl";
string s = ConfigurationSettings.AppSettings[optionName];
VerifyRequiredOption(optionName,
s);
return s;
}
}
//private static void RunIrcService()
//{
// IrcTechBotService ircService = new IrcTechBotService(IRCServerHostName,
// IRCServerHostPort,
// IRCChannelNames,
// IRCBotName,
// IRCBotPassword,
// ChmPath,
// MainChm);
// ircService.Run();
//}
public static void Main(string[] args)
{
TechBotService m_TechBot = null;
if (args.Length > 0 && args[0].ToLower().Equals("irc"))
{
m_TechBot = new IrcTechBotService(IRCServerHostName,
IRCServerHostPort,
IRCChannelNames,
IRCBotName,
IRCBotPassword,
ChmPath,
MainChm);
m_TechBot = new IrcTechBotService(Settings.Default.IRCServerHostName,
Settings.Default.IRCServerHostPort,
Settings.Default.IRCChannelNames,
Settings.Default.IRCBotName,
Settings.Default.IRCBotPassword);
}
else
{
System.Console.WriteLine("TechBot running console service...");
m_TechBot = new ConsoleTechBotService(
ChmPath,
MainChm);
m_TechBot = new ConsoleTechBotService();
}
m_TechBot.Run();

View file

@ -0,0 +1,86 @@
//------------------------------------------------------------------------------
// <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.Console {
[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.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("irc.eu.freenode.net")]
public string IRCServerHostName {
get {
return ((string)(this["IRCServerHostName"]));
}
set {
this["IRCServerHostName"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("rbuildbottest2")]
public string IRCChannelNames {
get {
return ((string)(this["IRCChannelNames"]));
}
set {
this["IRCChannelNames"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("RBuildBot2")]
public string IRCBotName {
get {
return ((string)(this["IRCBotName"]));
}
set {
this["IRCBotName"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("qwerty")]
public string IRCBotPassword {
get {
return ((string)(this["IRCBotPassword"]));
}
set {
this["IRCBotPassword"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("6667")]
public int IRCServerHostPort {
get {
return ((int)(this["IRCServerHostPort"]));
}
set {
this["IRCServerHostPort"] = value;
}
}
}
}

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.Console" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="IRCServerHostName" Type="System.String" Scope="User">
<Value Profile="(Default)">irc.eu.freenode.net</Value>
</Setting>
<Setting Name="IRCChannelNames" Type="System.String" Scope="User">
<Value Profile="(Default)">rbuildbottest2</Value>
</Setting>
<Setting Name="IRCBotName" Type="System.String" Scope="User">
<Value Profile="(Default)">RBuildBot2</Value>
</Setting>
<Setting Name="IRCBotPassword" Type="System.String" Scope="User">
<Value Profile="(Default)">qwerty</Value>
</Setting>
<Setting Name="IRCServerHostPort" Type="System.Int32" Scope="User">
<Value Profile="(Default)">6667</Value>
</Setting>
</Settings>
</SettingsFile>

View file

@ -40,11 +40,24 @@
<Compile Include="AssemblyInfo.cs" />
<Compile Include="ConsoleTechBotService.cs" />
<Compile Include="Main.cs" />
<Compile Include="Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TechBot.Commands.Common\TechBot.Commands.Common.csproj">
<Project>{041B5F06-BF97-4981-B024-3A7B6DD9F6AE}</Project>
<Name>TechBot.Commands.Common</Name>
</ProjectReference>
<ProjectReference Include="..\TechBot.Commands.RBuild\TechBot.Commands.RBuild.csproj">
<Project>{D676FEDE-62DD-4B4D-94C6-308598E827F9}</Project>
<Name>TechBot.Commands.RBuild</Name>
</ProjectReference>
<ProjectReference Include="..\TechBot.IRCLibrary\TechBot.IRCLibrary.csproj">
<Project>{D2A57931-DF04-4BC3-BD11-75DF4F3B0A88}</Project>
<Name>TechBot.IRCLibrary</Name>
@ -55,7 +68,11 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="app.config" />
<None Include="Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />

View file

@ -50,6 +50,9 @@
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="TechBot.IRCLibrary.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<TechBot.IRCLibrary.Settings>
<setting name="CommandPrefix" serializeAs="String">
<value>@</value>
</setting>
</TechBot.IRCLibrary.Settings>
</userSettings>
</configuration>

View file

@ -13,6 +13,7 @@ namespace TechBot.Library
private string m_name = "";
private string m_description = "";
private bool m_Required = true;
private bool m_Default = false;
#endregion
#region Public Properties
@ -26,6 +27,12 @@ namespace TechBot.Library
public bool Required { get { return m_Required; } }
public bool DefaultParameter
{
get { return m_Default; }
set { m_Default = value; }
}
#endregion
#region Constructors

View file

@ -1,4 +1,5 @@
using System;
using System.Text.RegularExpressions;
namespace TechBot.Library
{
@ -6,6 +7,7 @@ namespace TechBot.Library
{
protected TechBotService m_TechBotService = null;
protected MessageContext m_Context = null;
protected string m_Params = null;
public TechBotService TechBot
{
@ -30,10 +32,15 @@ namespace TechBot.Library
}
}
public void ParseParameters(string paramaters)
public string Parameters
{
ParametersParser parser = new ParametersParser(paramaters, this);
parser.Parse();
get { return m_Params; }
set { m_Params = value; }
}
protected virtual void Say()
{
TechBot.ServiceOutput.WriteLine(Context, string.Empty);
}
protected virtual void Say(string message)
@ -47,5 +54,13 @@ namespace TechBot.Library
}
public abstract void ExecuteCommand();
public virtual void Initialize()
{
}
public virtual void DeInitialize()
{
}
}
}

View file

@ -6,13 +6,12 @@ namespace TechBot.Library
{
public abstract class XmlLookupCommand : XmlCommand
{
private string m_Text = null;
protected string m_Text = null;
[CommandParameter("text", "The value to check")]
public string Text
public virtual string Text
{
get { return m_Text; }
set { m_Text = value; }
get { return Parameters; }
set { Parameters = value; }
}
}
}

View file

@ -1,9 +1,10 @@
using System;
using System.Reflection;
using System.Collections;
namespace TechBot.Library
{
[Command("help", Help = "!help")]
[Command("help", Help = "!help or !help -name:[CommandName]", Description = "Shows this help , type 'help -name:[CommandName]'")]
public class HelpCommand : Command
{
private string m_CommandName = null;
@ -15,8 +16,8 @@ namespace TechBot.Library
[CommandParameter("Name", "The command name to show help")]
public string CommandName
{
get { return m_CommandName; }
set { m_CommandName = value; }
get { return Parameters; }
set { Parameters = value; }
}
public override void ExecuteCommand()
@ -27,7 +28,8 @@ namespace TechBot.Library
foreach (CommandBuilder command in TechBot.Commands)
{
Say("!{0} - {1}",
Say("{0}{1} - {2}",
Settings.Default.CommandPrefix,
command.Name,
command.Description);
}
@ -43,7 +45,29 @@ namespace TechBot.Library
else
{
Say("Command '{0}' help:", CommandName);
Say("");
Say();
Say(cmdBuilder.Description);
Say();
Say(cmdBuilder.Help);
Say();
Say("Parameters :");
Say();
PropertyInfo[] propertyInfoArray = cmdBuilder.Type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo propertyInfo in propertyInfoArray)
{
CommandParameterAttribute[] commandAttributes = (CommandParameterAttribute[])
Attribute.GetCustomAttributes(propertyInfo, typeof(CommandParameterAttribute));
foreach (CommandParameterAttribute parameter in commandAttributes)
{
Say("\t-{0}: [{1}]",
parameter.Name,
parameter.Description);
}
}
Say();
}
}
}

View file

@ -28,6 +28,8 @@ namespace TechBot.Library
{
Assembly assPlugin = Assembly.LoadFile(sFile);
Console.WriteLine("Loading plugins from : {0}", assPlugin.Location);
if (assPlugin != null)
{
foreach (Type pluginType in assPlugin.GetTypes())
@ -36,6 +38,12 @@ namespace TechBot.Library
{
if (pluginType.IsAbstract == false)
{
CommandBuilder cmdBuilder = new CommandBuilder(pluginType);
Console.WriteLine("{0}:{1}",
cmdBuilder.Name,
cmdBuilder.Description);
//Add it to the list.
Commands.Add(new CommandBuilder(pluginType));
}

View file

@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.832
// Runtime Version:2.0.50727.1433
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@ -67,5 +67,14 @@ namespace TechBot.Library {
return ((string)(this["SVNRoot"]));
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("@")]
public string CommandPrefix {
get {
return ((string)(this["CommandPrefix"]));
}
}
}
}

View file

@ -17,5 +17,8 @@
<Setting Name="SVNRoot" Type="System.String" Scope="Application">
<Value Profile="(Default)">svn://svn.reactos.org/trunk/reactos</Value>
</Setting>
<Setting Name="CommandPrefix" Type="System.String" Scope="Application">
<Value Profile="(Default)">@</Value>
</Setting>
</Settings>
</SettingsFile>

View file

@ -48,19 +48,9 @@
<Compile Include="Factory\CommandFactory.cs" />
<Compile Include="Commands\Base\Command.cs" />
<Compile Include="Commands\Base\XmlCommand.cs" />
<Compile Include="Commands\BugCommand.cs" />
<Compile Include="Commands\HelpCommand.cs" />
<Compile Include="Commands\HResultCommand.cs" />
<Compile Include="Commands\NtStatusCommand.cs" />
<Compile Include="Commands\ReactOSBugUrl.cs" />
<Compile Include="Commands\SambaBugUrl.cs" />
<Compile Include="Commands\SvnCommand.cs" />
<Compile Include="Commands\WineBugUrl.cs" />
<Compile Include="Commands\WinerrorCommand.cs" />
<Compile Include="Commands\WMCommand.cs" />
<Compile Include="MessageContext.cs" />
<Compile Include="NumberParser.cs" />
<Compile Include="ParametersParser.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServiceOutput.cs" />
<Compile Include="Settings.cs" />
@ -78,10 +68,6 @@
<Reference Include="System.XML" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CHMLibrary\CHMLibrary.csproj">
<Project>{72E5CCA1-6318-4D62-964D-CB23A5C743B5}</Project>
<Name>CHMLibrary</Name>
</ProjectReference>
<ProjectReference Include="..\TechBot.IRCLibrary\TechBot.IRCLibrary.csproj">
<Project>{D2A57931-DF04-4BC3-BD11-75DF4F3B0A88}</Project>
<Name>TechBot.IRCLibrary</Name>

View file

@ -14,6 +14,7 @@ namespace TechBot.Library
{
if (context is ChannelMessageContext)
{
Thread.Sleep (500);
ChannelMessageContext channelContext = context as ChannelMessageContext;
channelContext.Channel.Talk(message);
}
@ -37,8 +38,6 @@ namespace TechBot.Library
private string channelnames;
private string botname;
private string password;
private string chmPath;
private string mainChm;
private IrcClient m_IrcClient;
private ArrayList channels = new ArrayList();
private bool isStopped = false;
@ -47,10 +46,8 @@ namespace TechBot.Library
int port,
string channelnames,
string botname,
string password,
string chmPath,
string mainChm)
: base (new IrcServiceOutput() , chmPath , mainChm)
string password)
: base (new IrcServiceOutput())
{
this.hostname = hostname;
this.port = port;
@ -60,8 +57,6 @@ namespace TechBot.Library
this.password = null;
else
this.password = password;
this.chmPath = chmPath;
this.mainChm = mainChm;
}
public override void Run()

View file

@ -11,17 +11,11 @@ namespace TechBot.Library
{
public abstract class TechBotService
{
protected IServiceOutput serviceOutput;
private string chmPath;
private string mainChm;
protected IServiceOutput m_ServiceOutput;
public TechBotService(IServiceOutput serviceOutput,
string chmPath,
string mainChm)
public TechBotService(IServiceOutput serviceOutput)
{
this.serviceOutput = serviceOutput;
this.chmPath = chmPath;
this.mainChm = mainChm;
m_ServiceOutput = serviceOutput;
}
public virtual void Run()
@ -31,7 +25,7 @@ namespace TechBot.Library
public IServiceOutput ServiceOutput
{
get { return serviceOutput; }
get { return m_ServiceOutput; }
}
public CommandBuilderCollection Commands
@ -47,7 +41,12 @@ namespace TechBot.Library
private bool IsCommandMessage(string message)
{
return message.StartsWith("!");
return message.StartsWith(Settings.Default.CommandPrefix);
}
public void InjectMessage(string message)
{
ParseCommandMessage(null, message);
}
public void ParseCommandMessage(MessageContext context,
@ -77,8 +76,22 @@ namespace TechBot.Library
cmd.TechBot = this;
cmd.Context = context;
cmd.ParseParameters(message);
cmd.Parameters = commandParams;
try
{
cmd.Initialize();
cmd.ExecuteCommand();
cmd.DeInitialize();
}
catch (Exception e)
{
ServiceOutput.WriteLine(context, string.Format("Uops! Just crashed with exception '{0}' at {1}",
e.Message,
e.Source));
ServiceOutput.WriteLine(context, e.StackTrace);
}
return;
}

View file

@ -22,6 +22,9 @@
<setting name="SVNRoot" serializeAs="String">
<value>svn://svn.reactos.org/trunk/reactos</value>
</setting>
<setting name="CommandPrefix" serializeAs="String">
<value>@</value>
</setting>
</TechBot.Library.Settings>
</applicationSettings>
</configuration>

View file

@ -13,6 +13,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechBot.IRCLibrary", "TechB
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechBot.Library", "TechBot.Library\TechBot.Library.csproj", "{1114F34D-F388-4F38-AE27-C0EE1B10B777}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechBot.Commands.Common", "TechBot.Commands.Common\TechBot.Commands.Common.csproj", "{041B5F06-BF97-4981-B024-3A7B6DD9F6AE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechBot.Commands.MSDN", "TechBot.Commands.MSDN\TechBot.Commands.MSDN.csproj", "{ADBF1ED6-A586-4707-BD59-4CD53448D0FE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechBot.Commands.RBuild", "TechBot.Commands.RBuild\TechBot.Commands.RBuild.csproj", "{D676FEDE-62DD-4B4D-94C6-308598E827F9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -43,6 +49,18 @@ Global
{1114F34D-F388-4F38-AE27-C0EE1B10B777}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1114F34D-F388-4F38-AE27-C0EE1B10B777}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1114F34D-F388-4F38-AE27-C0EE1B10B777}.Release|Any CPU.Build.0 = Release|Any CPU
{041B5F06-BF97-4981-B024-3A7B6DD9F6AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{041B5F06-BF97-4981-B024-3A7B6DD9F6AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{041B5F06-BF97-4981-B024-3A7B6DD9F6AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{041B5F06-BF97-4981-B024-3A7B6DD9F6AE}.Release|Any CPU.Build.0 = Release|Any CPU
{ADBF1ED6-A586-4707-BD59-4CD53448D0FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ADBF1ED6-A586-4707-BD59-4CD53448D0FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ADBF1ED6-A586-4707-BD59-4CD53448D0FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ADBF1ED6-A586-4707-BD59-4CD53448D0FE}.Release|Any CPU.Build.0 = Release|Any CPU
{D676FEDE-62DD-4B4D-94C6-308598E827F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D676FEDE-62DD-4B4D-94C6-308598E827F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D676FEDE-62DD-4B4D-94C6-308598E827F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D676FEDE-62DD-4B4D-94C6-308598E827F9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="TechBot.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<appSettings>
<add key="IRCServerHostName" value="irc.eu.freenode.net" />
<add key="IRCServerHostPort" value="6667" />
@ -17,4 +22,23 @@
<add key="WineBugUrl" value="http://bugs.winehq.org/show_bug.cgi?id={0}" />
<add key="SambaBugUrl" value="https://bugzilla.samba.org/show_bug.cgi?id={0}" />
</appSettings>
<userSettings>
<TechBot.Settings>
<setting name="IRCServerHostName" serializeAs="String">
<value>irc.eu.freenode.net</value>
</setting>
<setting name="IRCChannelNames" serializeAs="String">
<value>rbuildbottest</value>
</setting>
<setting name="IRCBotName" serializeAs="String">
<value>RBuildBot</value>
</setting>
<setting name="IRCBotPassword" serializeAs="String">
<value>qwerty</value>
</setting>
<setting name="IRCServerHostPort" serializeAs="String">
<value>6667</value>
</setting>
</TechBot.Settings>
</userSettings>
</configuration>

View file

@ -7,65 +7,24 @@ namespace TechBot
{
public class ServiceThread
{
private string IRCServerHostName;
private int IRCServerHostPort;
private string IRCChannelNames;
private string IRCBotName;
private string IRCBotPassword;
private string ChmPath;
private string MainChm;
private string NtstatusXml;
private string HresultXml;
private string WmXml;
private string WinerrorXml;
private string SvnCommand;
private string BugUrl, WineBugUrl, SambaBugUrl;
private EventLog eventLog;
private EventLog m_EventLog;
public ServiceThread(EventLog eventLog)
{
this.eventLog = eventLog;
}
private void SetupConfiguration()
{
IRCServerHostName = ConfigurationSettings.AppSettings["IRCServerHostName"];
IRCServerHostPort = Int32.Parse(ConfigurationSettings.AppSettings["IRCServerHostPort"]);
IRCChannelNames = ConfigurationSettings.AppSettings["IRCChannelNames"];
IRCBotName = ConfigurationSettings.AppSettings["IRCBotName"];
IRCBotPassword = ConfigurationSettings.AppSettings["IRCBotPassword"];
ChmPath = ConfigurationSettings.AppSettings["ChmPath"];
MainChm = ConfigurationSettings.AppSettings["MainChm"];
NtstatusXml = ConfigurationSettings.AppSettings["NtstatusXml"];
HresultXml = ConfigurationSettings.AppSettings["HresultXml"];
WmXml = ConfigurationSettings.AppSettings["WmXml"];
WinerrorXml = ConfigurationSettings.AppSettings["WinerrorXml"];
SvnCommand = ConfigurationSettings.AppSettings["SvnCommand"];
BugUrl = ConfigurationSettings.AppSettings["BugUrl"];
WineBugUrl = ConfigurationSettings.AppSettings["WineBugUrl"];
SambaBugUrl = ConfigurationSettings.AppSettings["SambaBugUrl"];
m_EventLog = eventLog;
}
public void Run()
{
SetupConfiguration();
System.Console.WriteLine("TechBot irc service...");
IrcTechBotService ircService = new IrcTechBotService(IRCServerHostName,
IRCServerHostPort,
IRCChannelNames,
IRCBotName,
IRCBotPassword,
ChmPath,
MainChm);
//NtstatusXml,
//WinerrorXml,
//HresultXml,
//WmXml,
//SvnCommand,
//BugUrl,
//WineBugUrl,
//SambaBugUrl);
IrcTechBotService ircService = new IrcTechBotService(
Settings.Default.IRCServerHostName,
Settings.Default.IRCServerHostPort,
Settings.Default.IRCChannelNames,
Settings.Default.IRCBotName,
Settings.Default.IRCBotPassword);
ircService.Run();
}
@ -77,7 +36,7 @@ namespace TechBot
}
catch (Exception ex)
{
eventLog.WriteEntry(String.Format("Ex. {0}", ex));
m_EventLog.WriteEntry(String.Format("Ex. {0}", ex));
}
}
}

86
irc/TechBot/TechBot/Settings.Designer.cs generated Normal file
View file

@ -0,0 +1,86 @@
//------------------------------------------------------------------------------
// <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 {
[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.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("irc.eu.freenode.net")]
public string IRCServerHostName {
get {
return ((string)(this["IRCServerHostName"]));
}
set {
this["IRCServerHostName"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("rbuildbottest")]
public string IRCChannelNames {
get {
return ((string)(this["IRCChannelNames"]));
}
set {
this["IRCChannelNames"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("RBuildBot")]
public string IRCBotName {
get {
return ((string)(this["IRCBotName"]));
}
set {
this["IRCBotName"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("qwerty")]
public string IRCBotPassword {
get {
return ((string)(this["IRCBotPassword"]));
}
set {
this["IRCBotPassword"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("6667")]
public int IRCServerHostPort {
get {
return ((int)(this["IRCServerHostPort"]));
}
set {
this["IRCServerHostPort"] = value;
}
}
}
}

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" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="IRCServerHostName" Type="System.String" Scope="User">
<Value Profile="(Default)">irc.eu.freenode.net</Value>
</Setting>
<Setting Name="IRCChannelNames" Type="System.String" Scope="User">
<Value Profile="(Default)">rbuildbottest</Value>
</Setting>
<Setting Name="IRCBotName" Type="System.String" Scope="User">
<Value Profile="(Default)">RBuildBot</Value>
</Setting>
<Setting Name="IRCBotPassword" Type="System.String" Scope="User">
<Value Profile="(Default)">qwerty</Value>
</Setting>
<Setting Name="IRCServerHostPort" Type="System.Int32" Scope="User">
<Value Profile="(Default)">6667</Value>
</Setting>
</Settings>
</SettingsFile>

View file

@ -39,6 +39,10 @@
-->
<ItemGroup>
<None Include="App.config" />
<None Include="Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
@ -46,6 +50,11 @@
<SubType>Component</SubType>
</Compile>
<Compile Include="ServiceThread.cs" />
<Compile Include="Settings.Designer.cs">
<DependentUpon>Settings.settings</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="TechBotService.cs">
<SubType>Component</SubType>
</Compile>