Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: mslot/IRCSharp
base: fbba7316a6
...
head fork: mslot/IRCSharp
compare: e52cb2f9d4
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 11 files changed
  • 0 commit comments
  • 1 contributor
Commits on Aug 29, 2012
@mslot + Added logic to get an user by nick.
+ Added logic to add new user.
+ Added logic to add query to existing user. This could be optimized alot!
+ Added some unit tests to cover adding a single query.
b643965
Commits on Sep 10, 2012
@mslot Raven is going to be seperated into a branch for itself.
Removed SQLCE database. This is going to be setup using a migration tool.
e52cb2f
View
1  IRCSharp.Statistics.Kernel/Dal/IDal.cs
@@ -8,5 +8,6 @@ namespace IRCSharp.Statistics.Kernel.Dal
public interface IDal : IDisposable
{
void AddQuery(IRCSharp.Kernel.Model.Query.IRCCommandQuery query);
+ Model.User GetUser(string nick);
}
}
View
30 IRCSharp.Statistics.Kernel/Dal/RavenDal.cs
@@ -28,28 +28,44 @@ public void AddQuery(IRCSharp.Kernel.Model.Query.IRCCommandQuery query)
bool doesUserExist = _session.Query<Model.User>().Any(user => user.Nick == query.Nick);
if (doesUserExist)
{
- //TODO: find channel
bool doesChannelExist = _session.Query<Model.User>().Any(user => user.Nick == query.Nick && user.Channels.Any(channel => channel.ChannelName == query.Channel));
if (doesChannelExist)
{
- //TODO. With partial update -> add query to channel
- //_documentStore.DatabaseCommands.Patch("users/" + query.Nick, )
+ //TODO: With partial update -> add query to channel
+ Model.User user = GetUser(query.Nick);
+ user.AddQuery(query);
+ _session.Store(user);
}
else
{
- //if not exists, add channel, then add query, then add channel with partial update
+ Model.Channel newChannel = new Model.Channel(query.Channel);
+ newChannel.Queries.Add(query);
+ _documentStore.DatabaseCommands.Patch("users/" + query.Nick,
+ new[]
+ {
+ new Raven.Abstractions.Data.PatchRequest
+ {
+ Type = Raven.Abstractions.Data.PatchCommandType.Add,
+ Name = "Channels",
+ Value = Raven.Json.Linq.RavenJObject.FromObject(newChannel)
+ }
+ });
}
}
else
{
- //TODO: add user to user
- //TODO: add channel with query
+ Model.User newUser = new Model.User(query.Nick);
+ newUser.AddQuery(query);
+ _session.Store(newUser);
}
_session.SaveChanges();
}
+ }
- Console.WriteLine("Collecting stats from: " + query.RawLine);
+ public Model.User GetUser(string nick)
+ {
+ return _session.Load<Model.User>(nick);
}
public void Dispose()
View
52 IRCSharp.Statistics.Kernel/Dal/SQLCEDal.cs
@@ -0,0 +1,52 @@
+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
+ }
+
+ }
+
+ public Model.User GetUser(string nick)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void Dispose()
+ {
+ _connection.Dispose();
+ }
+ }
+}
View
8 IRCSharp.Statistics.Kernel/IRCSharp.Statistics.Kernel.csproj
@@ -87,6 +87,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
+ <Reference Include="System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@@ -96,13 +97,18 @@
<ItemGroup>
<Compile Include="Dal\IDal.cs" />
<Compile Include="Dal\RavenDal.cs" />
+ <Compile Include="Dal\SQLCEDal.cs" />
<Compile Include="Manager\StatisticsManager.cs" />
<Compile Include="Model\Channel.cs" />
<Compile Include="Model\User.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Repository\StatisticsRepository.cs" />
</ItemGroup>
- <ItemGroup />
+ <ItemGroup>
+ <Content Include="Statistics.sdf">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Content>
+ </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IRCSharp.Kernel.Model\IRCSharp.Kernel.Model.csproj">
<Project>{8258F2F1-039A-4C9E-8046-7E7FC447DDB6}</Project>
View
11 IRCSharp.Statistics.Kernel/Model/Channel.cs
@@ -9,7 +9,7 @@ public class Channel : IEquatable<Channel>
{
public List<IRCSharp.Kernel.Model.Query.IRCCommandQuery> Queries = new List<IRCSharp.Kernel.Model.Query.IRCCommandQuery>();
public string ChannelName { get; private set; }
- public string Network { get; private set; }
+ public string Network { get; private set; } //TODO: implement network
public string FullPath { get { return Network + "/" + ChannelName; } }
public string Id { get; private set; }
@@ -21,7 +21,14 @@ public Channel(string channelName)
public override bool Equals(object obj)
{
- return this.Equals((Channel)obj);
+ if (obj is Channel)
+ {
+ return this.Equals((Channel)obj);
+ }
+ else
+ {
+ return false;
+ }
}
public bool Equals(Channel other)
View
4 IRCSharp.Statistics.Kernel/Model/User.cs
@@ -23,7 +23,7 @@ public void AddQuery(IRCSharp.Kernel.Model.Query.IRCCommandQuery query)
foreach (Channel channel in Channels)
{
- if (channel.ChannelName == query.To)
+ if (channel.ChannelName == query.To) //TODO: is To an channel? Is it a comma seperated list of channels and users?
{
channel.Queries.Add(query);
found = true;
@@ -33,7 +33,7 @@ public void AddQuery(IRCSharp.Kernel.Model.Query.IRCCommandQuery query)
if (!found)
{
- var newChannel = new Channel(channelName: query.To);
+ var newChannel = new Channel(channelName: query.To); //TODO: this could be a seperated list of users and channels. This should be handled! We should check of To is a channel!!
newChannel.Queries.Add(query);
Channels.Add(newChannel);
}
View
BIN  IRCSharp.Statistics.Kernel/Statistics.sdf
Binary file not shown
View
2  TODO.txt
@@ -5,4 +5,4 @@ Dette er en intern dansk TODO liste jeg har lavet for at holde styr over hvad de
3. Lav en SIMPEL logging motor som skriver til DB og mail.
4. Lave s� userdefined commands og response commands bliver lagt i seperate mapper i dlls mappen.
5. Netsplit handling.
- 6. Handling mass quering bot.
+ 6. H�ndtering af mass quering.
View
12 UnitTest/RavenDal/AddQueryTest.cs
@@ -85,11 +85,17 @@ public IEnumerable<IRCSharp.Kernel.Model.Query.IRCCommandQuery> GenerateQueries(
public void AddFirstGeneratedQueries()
{
var generatedQueries = GenerateQueries();
- using (IRCSharp.Statistics.Kernel.Dal.IDal _dal = new IRCSharp.Statistics.Kernel.Dal.RavenDal(@"C:\data\StatisticsRavenDalTest", useEmbeddedHttpServer: false, runInMemory: true))
+ IRCSharp.Kernel.Model.Query.IRCCommandQuery firstQuery = generatedQueries.First();
+ using (IRCSharp.Statistics.Kernel.Dal.IDal _dal = new IRCSharp.Statistics.Kernel.Dal.RavenDal(@"C:\data\StatisticsRavenDalTest",
+ useEmbeddedHttpServer: false,
+ runInMemory: true)
+ )
{
- _dal.AddQuery(generatedQueries.First());
- _dal.AddQuery(generatedQueries.First());
+ _dal.AddQuery(firstQuery);
+ IRCSharp.Statistics.Kernel.Model.User user = _dal.GetUser(firstQuery.Nick);
+ Assert.NotNull(user);
}
+
}
}
}
View
92 UnitTest/SQLCEDal/AddQueryTest.cs
@@ -0,0 +1,92 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+
+namespace UnitTest.SQLCEDal
+{
+ [TestFixture]
+ class AddQueryTest
+ {
+ public IEnumerable<IRCSharp.Kernel.Model.Query.IRCCommandQuery> GenerateQueries()
+ {
+ LinkedList<IRCSharp.Kernel.Model.Query.IRCCommandQuery> queries = new LinkedList<IRCSharp.Kernel.Model.Query.IRCCommandQuery>();
+ List<string> rawQueries = new List<string> {
+ ":mslot1!~mslot1@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
+ ":mslot1!~mslot1@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
+ ":mslot1!~mslot1@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
+ ":mslot1!~mslot1@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
+ ":mslot1!~mslot1@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
+ ":mslot1!~mslot1@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
+ ":mslot1!~mslot1@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
+ ":mslot1!~mslot1@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
+ ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
+ ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
+ ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
+ ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
+ ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
+ ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
+ ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #mslot.dk :!command arg1 arg2 arg3",
+ ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #c :!command arg1 arg2 arg3",
+ ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #c :!command arg1 arg2 arg3",
+ ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #c :!command arg1 arg2 arg3",
+ ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #c :!command arg1 arg2 arg3",
+ ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #c :!command arg1 arg2 arg3",
+ ":mslot2!~mslot2@56344eba.rev.stofanet.dk PRIVMSG #c :!command arg1 arg2 arg3",
+ ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #c :!command arg1 arg2 arg3",
+ ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
+ ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
+ ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
+ ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
+ ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
+ ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
+ ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
+ ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
+ ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
+ ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
+ ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
+ ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
+ ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
+ ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
+ ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #r :!command arg1 arg2 arg3",
+ ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
+ ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
+ ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
+ ":mslot3!~mslot3@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
+ ":mslot4!~mslot4@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
+ ":mslot4!~mslot4@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
+ ":mslot4!~mslot4@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
+ ":mslot4!~mslot4@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
+ ":mslot4!~mslot4@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
+ ":mslot4!~mslot4@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
+ ":mslot4!~mslot4@56344eba.rev.stofanet.dk PRIVMSG #lol :!command arg1 arg2 arg3",
+ ":mslot4!~mslot4@56344eba.rev.stofanet.dk PRIVMSG #3 :!command arg1 arg2 arg3",
+ ":mslot4!~mslot4@56344eba.rev.stofanet.dk PRIVMSG #3 :!command arg1 arg2 arg3",
+ ":mslot4!~mslot4@56344eba.rev.stofanet.dk PRIVMSG #3 :!command arg1 arg2 arg3",
+ ":mslot!~mslot@56344eba.rev.stofanet.dk PRIVMSG #error :!command arg1 arg2 arg3",
+ ":mslot!~mslot@56344eba.rev.stofanet.dk PRIVMSG #error :!command arg1 arg2 arg3",
+ ":mslot!~mslot@56344eba.rev.stofanet.dk PRIVMSG #error :!command arg1 arg2 arg3",
+ ":mslot!~mslot@56344eba.rev.stofanet.dk PRIVMSG #error :!command arg1 arg2 arg3"
+ };
+
+ foreach (string rawQuery in rawQueries)
+ {
+ IRCSharp.Kernel.Model.Query.IRCCommandQuery query = null;
+ bool parsed = IRCSharp.Kernel.Parser.IRC.IRCQueryParser.TryParse(rawQuery, out query);
+ queries.AddLast(query);
+ }
+
+ return queries;
+ }
+
+
+ [Test]
+ public void AddFirstGeneratedQueries()
+ {
+ var generatedQueries = GenerateQueries();
+ IRCSharp.Kernel.Model.Query.IRCCommandQuery firstQuery = generatedQueries.First();
+
+ }
+ }
+}
View
1  UnitTest/UnitTest.csproj
@@ -50,6 +50,7 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RavenDal\AddQueryTest.cs" />
+ <Compile Include="SQLCEDal\AddQueryTest.cs" />
<Compile Include="UserdefinedCommand\UserdefinedParserTest.cs" />
</ItemGroup>
<ItemGroup>

No commit comments for this range

Something went wrong with that request. Please try again.