Permalink
Browse files

Big commit. Fixed bugs in parser. Updated parser. Added CRUD to stati…

…stics. Added TODO's.

* Added unit tests to statistics
* implemented IDal for SQLite
  • Loading branch information...
1 parent 3ce20a5 commit f14f64c1c3e4690cedc4ca4b89b8867ce283bb22 @mslot committed Dec 16, 2012
Showing with 624 additions and 148 deletions.
  1. +2 −2 IRCSharp.ConsoleRunner/App.config
  2. +2 −1 IRCSharp.ConsoleRunner/IRCSharp.ConsoleRunner.csproj
  3. +2 −2 IRCSharp.ConsoleRunner/bin/Debug/ConsoleRunner.exe.config
  4. +2 −2 IRCSharp.ConsoleRunner/bin/Debug/ConsoleRunner.vshost.exe.config
  5. BIN IRCSharp.ConsoleRunner/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache
  6. +3 −1 IRCSharp.Kernel.Model/Query/Commandbase.cs
  7. +13 −13 IRCSharp.Kernel.Model/Query/IRCCommandQuery.cs
  8. +1 −0 IRCSharp.Kernel.Model/Query/UserdefinedCommandQuery.cs
  9. +4 −4 IRCSharp.Kernel/Bot/IRCBot.cs
  10. +1 −1 IRCSharp.Kernel/Commands/PingCommand.cs
  11. +2 −2 IRCSharp.Kernel/Parser/IRC/IRCQueryParser.cs
  12. +17 −2 IRCSharp.Kernel/Parser/IRC/ToParser.cs
  13. +2 −2 IRCSharp.Kernel/Parser/UserdefinedCommand/UserdefinedCommandParser.cs
  14. +1 −1 IRCSharp.MSMQTestProgram/Program.cs
  15. +3 −0 IRCSharp.Migrations/Statistics/InitDatabase.cs
  16. +7 −2 IRCSharp.Statistics.Kernel/Dal/IDal.cs
  17. +0 −62 IRCSharp.Statistics.Kernel/Dal/SQLCEDal.cs
  18. +274 −0 IRCSharp.Statistics.Kernel/Dal/SQLiteDal.cs
  19. +7 −2 IRCSharp.Statistics.Kernel/IRCSharp.Statistics.Kernel.csproj
  20. +12 −2 IRCSharp.Statistics.Kernel/Model/User.cs
  21. +20 −0 NUnitProjectSuite.VisualState.xml
  22. +13 −0 NUnitProjectSuite.nunit
  23. +2 −1 TODO.txt
  24. +17 −0 UnitTest.VisualState.xml
  25. +43 −9 UnitTest/IRCParser/IRCParserTest.cs
  26. +13 −10 UnitTest/Program.cs
  27. +41 −0 UnitTest/SQLiteDalTest/AddQueryTest.cs
  28. +19 −19 UnitTest/{SQLCEDalTest/AddQueryTest.cs → SQLiteDalTest/QueryTestBase.cs}
  29. +29 −0 UnitTest/SQLiteDalTest/UserMslot1DataTest.cs
  30. +30 −0 UnitTest/SQLiteDalTest/UserMslot2DataTest.cs
  31. +9 −3 UnitTest/UnitTest.csproj
  32. +4 −3 UnitTest/UserdefinedCommand/UserdefinedParserTest.cs
  33. +29 −2 UnitTest/app.config
  34. BIN UnitTest/continuoustesting.stats
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8" ?>
+<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="server" value="jubii.dk.quakenet.org"/>
@@ -8,4 +8,4 @@
<add key="name" value="rob bert"/>
<add key="channels" value="#mslot.dk"/>
</appSettings>
-</configuration>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
@@ -11,7 +11,8 @@
<RootNamespace>ConsoleRunner</RootNamespace>
<AssemblyName>ConsoleRunner</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <TargetFrameworkProfile>
+ </TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8" ?>
+<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="server" value="jubii.dk.quakenet.org"/>
@@ -8,4 +8,4 @@
<add key="name" value="rob bert"/>
<add key="channels" value="#mslot.dk"/>
</appSettings>
-</configuration>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8" ?>
+<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="server" value="jubii.dk.quakenet.org"/>
@@ -8,4 +8,4 @@
<add key="name" value="rob bert"/>
<add key="channels" value="#mslot.dk"/>
</appSettings>
-</configuration>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
@@ -9,16 +9,18 @@ public class Commandbase
{
public string From { get; set; }
public string To { get; set; }
+ public string Network { get; set; }
public Commandbase()
{
}
- public Commandbase(string from, string to)
+ public Commandbase(string from, string to, string network)
{
From = from;
To = to;
+ Network = network;
}
}
}
@@ -18,13 +18,22 @@ public IRCCommandQuery()
}
- public IRCCommandQuery(string from, string to)
- : base(from, to)
+ public IRCCommandQuery(string from, string to, string network)
+ : base(from, to, network)
{
}
- public string Nick
+ public IRCCommandQuery(string line, string network)
+ : base(String.Empty, String.Empty, network)
+ {
+ RawLine = line;
+ Command = IRCCommand.NOT_VALID_COMMAND_TYPE;
+ Prefix = String.Empty;
+ Parameter = String.Empty;
+ }
+
+ public string Nick //TODO: should this be parsed by the parser? Maybe a new parser should be added, between PrefixParser and FromParser. See diagrams in kernel projects for more details
{
get
{
@@ -36,19 +45,10 @@ public string Channel
{
get
{
- return From;
+ return To; //TODO this is not always true. It is only a channel if name is prefixed with #.
}
}
- public IRCCommandQuery(string line)
- : base(String.Empty, String.Empty)
- {
- RawLine = line;
- Command = IRCCommand.NOT_VALID_COMMAND_TYPE;
- Prefix = String.Empty;
- Parameter = String.Empty;
- }
-
public override string ToString()
{
return RawLine;
@@ -12,6 +12,7 @@ public class UserdefinedCommandQuery
public string CommandName { get; private set; }
public string From { get { return IRCQuery.From; } }
public string To { get { return IRCQuery.To; } }
+ public string Network { get { return IRCQuery.Network; } }
public UserdefinedCommandQuery(string commandName, Query.IRCCommandQuery ircQuery)
{
@@ -83,8 +83,8 @@ private void JoinChannels()
while (run && (line = _clientReader.ReadLine()) != null)
{
Console.WriteLine(line);
- Model.Query.IRCCommandQuery query = new Model.Query.IRCCommandQuery(line);
- if (Parser.IRC.IRCQueryParser.TryParse(line, out query))
+ Model.Query.IRCCommandQuery query = null;
+ if (Parser.IRC.IRCQueryParser.TryParse(_server, line, out query))
{
var incomingThread = new IRCSharp.Kernel.Threading.IncomingThread(query, _commandCollecter.CommandManager, _ircWriter);
incomingThread.Start();
@@ -107,8 +107,8 @@ private void StartListning()
while ((line = _clientReader.ReadLine()) != null)
{
Console.WriteLine(line);
- Model.Query.IRCCommandQuery query = new Model.Query.IRCCommandQuery(line);
- if (Parser.IRC.IRCQueryParser.TryParse(line, out query))
+ Model.Query.IRCCommandQuery query = null;
+ if (Parser.IRC.IRCQueryParser.TryParse(_server, line, out query))
{
var incomingThread = new IRCSharp.Kernel.Threading.IncomingThread(query, _commandCollecter.CommandManager, _ircWriter);
_messageServer.WriteMessageToConnectors(query);
@@ -13,7 +13,7 @@ public override Model.Query.IRCCommandQuery Execute(IRCSharp.Kernel.Model.Query.
string[] commands = query.Parameter.Split(':');
Model.Query.IRCCommandQuery pongQuery = null;
- Parser.IRC.IRCQueryParser.TryParse("PONG " + commands[1], out pongQuery);
+ Parser.IRC.IRCQueryParser.TryParse(query.Network, "PONG " + commands[1], out pongQuery);
return pongQuery;
}
@@ -15,11 +15,11 @@ private IRCQueryParser()
Context.CurrentState = new PrefixParser(Context);
}
- public static bool TryParse(string line, out Model.Query.IRCCommandQuery query)
+ public static bool TryParse(string network, string line, out Model.Query.IRCCommandQuery query) //TODO: remake method call. Network should not be part of this. Wrap this up in some context that holds network and line.
{
var instance = new IRCQueryParser();
instance.Context.Line = line;
- instance.Context.Query = new Model.Query.IRCCommandQuery(line);
+ instance.Context.Query = new Model.Query.IRCCommandQuery(line, network);
instance.Context.Query = query = instance.Parse();
bool errorProcessing = (instance.Context.CharCount != -1);
bool errorReachingEnd = (instance.Context.CharCount == instance.Context.Line.Length);
@@ -24,9 +24,24 @@ public int Parse()
private int ParseToString(string line)
{
- string to = line.Substring(_context.CharCount+1, _context.CharCount - line.IndexOf(' ')+1);
- _context.Query.To = to;
+ int index = line.IndexOf(' ', _context.CharCount + 1);
+ if (index == -1) //Handles queries like ":WiZ JOIN #Twilight_zone" with no spaces in the end ... Linkin Park ftw btw!!
+ index = line.Length;
+
+ if ((index - 1 - _context.CharCount) >= 0) //TODO: Clean up spaghetti code
+ {
+ string to = line.Substring(_context.CharCount + 1, index - 1 - _context.CharCount);
+
+ if (to.StartsWith("#")) //TODO: this only handles one channel, not lists of channels. Make this better! And is it correct only to check after #? What about private messages?
+ {
+ _context.Query.To = to;
+ }
+ else
+ {
+ _context.Query.To = String.Empty;
+ }
+ }
return line.IndexOf(' ', _context.CharCount);
}
}
@@ -18,12 +18,12 @@ private UserdefinedCommandParser()
}
- public static bool TryParse(string line, out Model.Query.UserdefinedCommandQuery query)
+ public static bool TryParse(string network, string line, out Model.Query.UserdefinedCommandQuery query) //TODO: remake method call. Network should not be part of this. Wrap this up in some context that holds network and line.
{
UserdefinedCommandParser parser = new UserdefinedCommandParser();
IRCSharp.Kernel.Model.Query.IRCCommandQuery ircQuery = null;
Model.Query.UserdefinedCommandQuery output = null;
- bool parsedIRCQuery = IRCSharp.Kernel.Parser.IRC.IRCQueryParser.TryParse(line, out ircQuery);
+ bool parsedIRCQuery = IRCSharp.Kernel.Parser.IRC.IRCQueryParser.TryParse(network, line, out ircQuery);
bool parsed = false;
if (ircQuery.Command == Model.Query.IRCCommand.PRIVMSG && IsUserdefinedCommand(ircQuery.Parameter))
@@ -27,7 +27,7 @@ static void ReceiveCompleted(Kernel.Model.Query.IRCCommandQuery query)
if (query.RawLine.Contains("gonggong"))
{
IRCSharp.Kernel.Model.Query.IRCCommandQuery toBot = null;
- if (IRCSharp.Kernel.Parser.IRC.IRCQueryParser.TryParse("PRIVMSG #mslot.dk :kingkong", out toBot))
+ if (IRCSharp.Kernel.Parser.IRC.IRCQueryParser.TryParse(query.Network,"PRIVMSG #mslot.dk :kingkong", out toBot))
{
Console.WriteLine("Trying to write to bot..." + query.RawLine);
_client.WriteToBot(toBot);
@@ -20,6 +20,7 @@ public override void Up()
{
Create.Table("User")
.WithColumn("nick").AsString()
+ .WithColumn("network").AsString()
.WithColumn("id").AsInt32()
.PrimaryKey()
.Unique()
@@ -37,13 +38,15 @@ public override void Up()
Create.Table("Query")
.WithColumn("rawQuery").AsString()
.WithColumn("channelId").AsInt32().NotNullable()
+ .WithColumn("userId").AsInt32().NotNullable()
.WithColumn("id").AsInt32()
.PrimaryKey()
.Unique()
.Identity();
Create.ForeignKey("fk_channel_user").FromTable("Channel").ForeignColumn("userId").ToTable("User").PrimaryColumn("id");
Create.ForeignKey("fk_query_channel").FromTable("Query").ForeignColumn("channelId").ToTable("Channel").PrimaryColumn("id");
+ Create.ForeignKey("fk_query_user").FromTable("Query").ForeignColumn("userId").ToTable("User").PrimaryColumn("id");
}
}
}
@@ -7,7 +7,12 @@ namespace IRCSharp.Statistics.Kernel.Dal
{
public interface IDal : IDisposable
{
- void AddQuery(IRCSharp.Kernel.Model.Query.IRCCommandQuery query);
- Model.User GetUser(string nick);
+ bool AddQuery(IRCSharp.Kernel.Model.Query.IRCCommandQuery query);
+ Model.User GetUser(string network, string nick, int numberOfQueries);
+ void RemoveAllQueries();
+
+ void RemoveAllChannels();
+
+ void RemoveUsers();
}
}
@@ -1,62 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace IRCSharp.Statistics.Kernel.Dal
-{
- class SQLCEDal : IDal
- {
- private System.Data.SqlServerCe.SqlCeConnection _connection = null;
-
- public SQLCEDal(string connectionString)
- {
- _connection = new System.Data.SqlServerCe.SqlCeConnection(connectionString);
- _connection.Open();
- }
-
- public void AddQuery(IRCSharp.Kernel.Model.Query.IRCCommandQuery query)
- {
- System.Data.SqlServerCe.SqlCeCommand command = _connection.CreateCommand();
- if (DoesUserExists(query))
- {
- if (DoesChannelExists(query))
- {
- //create query
- }
- else
- {
- //create channel
- //create query
- }
- }
- else
- {
- //create user
- //create channel
- //create query
- }
-
- }
-
- private bool DoesChannelExists(IRCSharp.Kernel.Model.Query.IRCCommandQuery query)
- {
- throw new NotImplementedException();
- }
-
- private bool DoesUserExists(IRCSharp.Kernel.Model.Query.IRCCommandQuery query)
- {
- throw new NotImplementedException();
- }
-
- public Model.User GetUser(string nick)
- {
- throw new NotImplementedException();
- }
-
- public void Dispose()
- {
- _connection.Dispose();
- }
- }
-}
Oops, something went wrong.

0 comments on commit f14f64c

Please sign in to comment.