public Packets() { var servers = new Servers(); var server = new Server { Name = "test.bitpir.at" }; servers.Add(server); var channel = new Channel { Name = "#test" }; server.AddChannel(channel); channel.AddBot(bot1); channel.AddBot(bot2); bot1.AddPacket(CreatePacket(1, "Under.the.Dome.s01e01.mkv", 101)); bot1.AddPacket(CreatePacket(2, "Under.the.Dome.s01e02.mkv", 102)); bot1.AddPacket(CreatePacket(3, "Under.the.Dome.s01e03.mkv", 103)); bot1.AddPacket(CreatePacket(4, "Under.the.Dome.s01e04.mkv", 104)); bot2.AddPacket(CreatePacket(1, "Under.the.Dome.s01e01.mkv", 201)); bot2.AddPacket(CreatePacket(2, "Under.the.Dome.s01e02.mkv", 202)); bot2.AddPacket(CreatePacket(3, "Under.the.Dome.s01e03.mkv", 203)); bot2.AddPacket(CreatePacket(4, "Under.the.Dome.s01e04.mkv", 204)); bot2.AddPacket(CreatePacket(5, "Ander.the.Dome.s01e05.mkv", 205)); XG.Plugin.Webserver.Search.Packets.Servers = servers; XG.Plugin.Webserver.Search.Packets.Initialize(); }
public static void CheckAndRemoveDuplicates(Servers aServers) { IEnumerable<Server> servers = (from server in aServers.All select server).ToArray(); foreach(var obj in servers.GroupBy(obj => obj.Name).Where(list => list.Count() > 1).Select(list => list.Skip(1)).SelectMany(list => list)) { obj.Parent.Remove(obj); } IEnumerable<Channel> channels = (from server in servers from channel in server.Channels select channel).ToArray(); foreach(var obj in channels.GroupBy(obj => obj.Parent.Name + "/" + obj.Name).Where(list => list.Count() > 1).Select(list => list.Skip(1)).SelectMany(list => list)) { obj.Parent.RemoveChannel(obj); } IEnumerable<Bot> bots = (from channel in channels from bot in channel.Bots select bot).ToArray(); foreach(var obj in bots.GroupBy(obj => obj.Parent.Parent.Name + "/" + obj.Parent.Name + "/" + obj.Name).Where(list => list.Count() > 1).Select(list => list.Skip(1)).SelectMany(list => list)) { obj.Parent.RemoveBot(obj); } IEnumerable<Packet> packets = (from bot in bots from packet in bot.Packets select packet).ToArray(); foreach(var obj in packets.GroupBy(obj => obj.Parent.Parent.Parent.Name + "/" + obj.Parent.Parent.Name + "/" + obj.Parent.Name + "/" + obj.Id).Where(list => list.Count() > 1).Select(list => list.Skip(1)).SelectMany(list => list)) { obj.Parent.RemovePacket(obj); } }
public void ServerTest() { var obj = new XG.Model.Domain.Server(); obj.OnChanged += delegate { _modified = true; }; AssertModified(obj, false); obj.Name = "Test"; AssertModified(obj, true); obj.Guid = Guid.Empty; AssertModified(obj, false); obj.Connected = true; AssertModified(obj, true); var parent = new XG.Model.Domain.Servers {Guid = Guid.NewGuid()}; Assert.AreEqual(Guid.Empty, obj.ParentGuid); obj.Parent = parent; Assert.AreEqual(parent.Guid, obj.ParentGuid); obj.Parent = null; Assert.AreEqual(Guid.Empty, obj.ParentGuid); AssertModified(obj, false); }
public void ServerTest() { var obj = new XG.Model.Domain.Server(); obj.OnChanged += delegate { _modified = true; }; AssertModified(obj, false); obj.Name = "Test"; AssertModified(obj, true); obj.Guid = Guid.Empty; AssertModified(obj, false); obj.Connected = true; AssertModified(obj, true); var parent = new XG.Model.Domain.Servers { Guid = Guid.NewGuid() }; Assert.AreEqual(Guid.Empty, obj.ParentGuid); obj.Parent = parent; Assert.AreEqual(parent.Guid, obj.ParentGuid); obj.Parent = null; Assert.AreEqual(Guid.Empty, obj.ParentGuid); AssertModified(obj, false); }
public void CheckAndRemoveDuplicatesTest() { var servers = new Servers(); for (int a = 1; a <= count; a++) { servers.Add(createServer("server " + a)); } servers.Named("server " + count).Name = "server " + fakeId; Assert.AreEqual(count, servers.All.Count()); Assert.AreEqual(count * count, (from server in servers.All from channel in server.Channels select channel).Count()); Assert.AreEqual(count * count * count, (from server in servers.All from channel in server.Channels from bot in channel.Bots select bot).Count()); Assert.AreEqual(count * count * count * count, (from server in servers.All from channel in server.Channels from bot in channel.Bots from packet in bot.Packets select packet).Count()); XG.Business.Helper.Objects.CheckAndRemoveDuplicates(servers); int newCount = count - 1; Assert.AreEqual(newCount, servers.All.Count()); Assert.AreEqual(newCount * newCount, (from server in servers.All from channel in server.Channels select channel).Count()); Assert.AreEqual(newCount * newCount * newCount, (from server in servers.All from channel in server.Channels from bot in channel.Bots select bot).Count()); Assert.AreEqual(newCount * newCount * newCount * newCount, (from server in servers.All from channel in server.Channels from bot in channel.Bots from packet in bot.Packets select packet).Count()); }
void LoadObjects() { var _servers = new Servers(); var _files = new Files(); var _searches = new Searches(); var _apiKeys = new ApiKeys(); using (ISession session = _sessions.OpenSession(new TrackingNumberInterceptor())) { var servers = session.CreateQuery("FROM Server").List<Server>(); foreach (var server in servers) { _servers.Add(server); } var files = session.CreateQuery("FROM File").List<File>(); foreach (var file in files) { _files.Add(file); } var searches = session.CreateQuery("FROM Search").List<Search>(); foreach (var search in searches) { _searches.Add(search); } var apiKeys = session.CreateQuery("FROM ApiKey").List<ApiKey>(); foreach (var apiKey in apiKeys) { _apiKeys.Add(apiKey); } } Servers = _servers; Files = _files; Searches = _searches; ApiKeys = _apiKeys; _lastSave = DateTime.Now; }
void Load() { try { Servers = _db.Query<Servers>(typeof(Servers))[0]; } catch (InvalidOperationException) {} catch (Db4oRecoverableException) {} if (Servers == null) { Servers = new Servers(); _db.Store(Servers); } try { Files = _db.Query<Files>(typeof(Files))[0]; } catch (InvalidOperationException) {} catch (Db4oRecoverableException) {} if (Files == null) { Files = new Files(); _db.Store(Files); } try { Searches = _db.Query<Searches>(typeof(Searches))[0]; } catch (InvalidOperationException) {} catch (Db4oRecoverableException) {} if (Searches == null) { Searches = new Searches(); _db.Store(Searches); } try { ApiKeys = _db.Query<ApiKeys>(typeof(ApiKeys))[0]; } catch (InvalidOperationException) {} catch (Db4oRecoverableException) {} if (ApiKeys == null) { ApiKeys = new ApiKeys(); _db.Store(ApiKeys); } TryCommit(); }
void Load() { try { Servers = _db.Query<Servers>(typeof(Servers)).First(); } catch (InvalidOperationException) { Servers = new Servers(); _db.Store(Servers); } try { Files = _db.Query<Files>(typeof(Files)).First(); } catch (InvalidOperationException) { Files = new Files(); _db.Store(Files); } try { Searches = _db.Query<Searches>(typeof(Searches)).First(); } catch (InvalidOperationException) { Searches = new Searches(); _db.Store(Searches); } try { ApiKeys = _db.Query<ApiKeys>(typeof(ApiKeys)).First(); } catch (InvalidOperationException) { ApiKeys = new ApiKeys(); _db.Store(ApiKeys); } _db.Commit(); }