Permalink
Browse files

+ 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.
  • Loading branch information...
1 parent fbba731 commit b643965bb6cb8517a8edd9e48ab4eb6f0e41d526 @mslot committed Aug 29, 2012
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
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
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);
}
+
}
}
}

0 comments on commit b643965

Please sign in to comment.