Skip to content

Commit e5d4a67

Browse files
committed
Extracted db for injection later.
+ Deprecated old history upgrader
1 parent 7bda172 commit e5d4a67

File tree

8 files changed

+115
-659
lines changed

8 files changed

+115
-659
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ after_success:
4141
- cd ./TS3AudioBot/bin/Release
4242
- ls
4343
- zip TS3AudioBot.zip TS3AudioBot.exe TS3Client.dll Nett.dll LiteDB.dll Heijden.Dns.dll BouncyCastle.Crypto.dll x64/* x86/*
44-
- 'export version=`./TS3AudioBot.exe --version | grep "Version: "`'
45-
- "curl -I -H \"Content-Type: application/zip\" -X PUT \"http://splamy.de/api/nightly/ts3ab/${TRAVIS_BRANCH}?token=${uploadkey}&filename=TS3AudioBot.zip&commit=${TRAVIS_COMMIT}&version=${version}\" --upload-file ./TS3AudioBot.zip"
44+
- 'export version=`mono TS3AudioBot.exe --version | grep "Version: "`'
45+
- "curl -I -H \"Content-Type: application/zip\" -X PUT \"http://splamy.de/api/nightly/ts3ab/${TRAVIS_BRANCH}?token=${uploadkey}&filename=TS3AudioBot.zip&commit=${TRAVIS_COMMIT}&version=${version:9}\" --upload-file ./TS3AudioBot.zip"
4646
- cd "$MAIN_DIR"
4747

4848
after_script:

TS3ABotUnitTests/UnitTests.cs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
using TS3AudioBot;
18+
1719
namespace TS3ABotUnitTests
1820
{
1921
using System;
@@ -56,8 +58,9 @@ public void HistoryFileIntergrityTest()
5658
var data2 = new HistorySaveData(ar2, inv2.DatabaseId);
5759
var data3 = new HistorySaveData(ar3, 103);
5860

59-
60-
var hf = new HistoryManager(new HistoryManagerData { HistoryFile = testFile, FillDeletedIds = false });
61+
var hmf = new HistoryManagerData {HistoryFile = testFile, FillDeletedIds = false};
62+
var db = new DbStore(hmf);
63+
var hf = new HistoryManager(hmf, db);
6164

6265
hf.LogAudioResource(data1);
6366

@@ -66,9 +69,10 @@ public void HistoryFileIntergrityTest()
6669
var lastEntry = lastXEntries.First();
6770
Assert.AreEqual(ar1, lastEntry.AudioResource);
6871

69-
hf.Dispose();
72+
db.Dispose();
7073

71-
hf = new HistoryManager(new HistoryManagerData { HistoryFile = testFile, FillDeletedIds = false });
74+
db = new DbStore(hmf);
75+
hf = new HistoryManager(hmf, db);
7276
lastXEntries = hf.GetLastXEntrys(1);
7377
Assert.True(lastXEntries.Any());
7478
lastEntry = lastXEntries.First();
@@ -82,10 +86,11 @@ public void HistoryFileIntergrityTest()
8286
lastEntry = lastXEntries.First();
8387
Assert.AreEqual(ar2, lastEntry.AudioResource);
8488

85-
hf.Dispose();
89+
db.Dispose();
8690

8791
// store and order check
88-
hf = new HistoryManager(new HistoryManagerData { HistoryFile = testFile, FillDeletedIds = false });
92+
db = new DbStore(hmf);
93+
hf = new HistoryManager(hmf, db);
8994
var lastXEntriesArray = hf.GetLastXEntrys(2).ToArray();
9095
Assert.AreEqual(2, lastXEntriesArray.Length);
9196
Assert.AreEqual(ar2, lastXEntriesArray[0].AudioResource);
@@ -96,10 +101,11 @@ public void HistoryFileIntergrityTest()
96101
hf.LogAudioResource(new HistorySaveData(ale1.AudioResource, 42));
97102

98103

99-
hf.Dispose();
104+
db.Dispose();
100105

101106
// check entry renaming
102-
hf = new HistoryManager(new HistoryManagerData { HistoryFile = testFile, FillDeletedIds = false });
107+
db = new DbStore(hmf);
108+
hf = new HistoryManager(hmf, db);
103109
lastXEntriesArray = hf.GetLastXEntrys(2).ToArray();
104110
Assert.AreEqual(2, lastXEntriesArray.Length);
105111
Assert.AreEqual(ar1, lastXEntriesArray[0].AudioResource);
@@ -116,18 +122,20 @@ public void HistoryFileIntergrityTest()
116122
hf.RenameEntry(ale2, "me_ar2_exxxxxtra_loong1");
117123
hf.LogAudioResource(new HistorySaveData(ale2.AudioResource, 42));
118124

119-
hf.Dispose();
125+
db.Dispose();
120126

121127
// recheck order
122-
hf = new HistoryManager(new HistoryManagerData { HistoryFile = testFile, FillDeletedIds = false });
128+
db = new DbStore(hmf);
129+
hf = new HistoryManager(hmf, db);
123130
lastXEntriesArray = hf.GetLastXEntrys(2).ToArray();
124131
Assert.AreEqual(2, lastXEntriesArray.Length);
125132
Assert.AreEqual(ar2, lastXEntriesArray[0].AudioResource);
126133
Assert.AreEqual(ar1, lastXEntriesArray[1].AudioResource);
127-
hf.Dispose();
134+
db.Dispose();
128135

129136
// delete entry 1
130-
hf = new HistoryManager(new HistoryManagerData { HistoryFile = testFile, FillDeletedIds = false });
137+
db = new DbStore(hmf);
138+
hf = new HistoryManager(hmf, db);
131139
hf.RemoveEntry(hf.FindEntryByResource(ar1));
132140

133141
lastXEntriesArray = hf.GetLastXEntrys(3).ToArray();
@@ -138,10 +146,11 @@ public void HistoryFileIntergrityTest()
138146

139147
lastXEntriesArray = hf.GetLastXEntrys(3).ToArray();
140148
Assert.AreEqual(2, lastXEntriesArray.Length);
141-
hf.Dispose();
149+
db.Dispose();
142150

143151
// delete entry 2
144-
hf = new HistoryManager(new HistoryManagerData { HistoryFile = testFile, FillDeletedIds = false });
152+
db = new DbStore(hmf);
153+
hf = new HistoryManager(hmf, db);
145154
// .. check integrity from previous store
146155
lastXEntriesArray = hf.GetLastXEntrys(3).ToArray();
147156
Assert.AreEqual(2, lastXEntriesArray.Length);
@@ -152,7 +161,7 @@ public void HistoryFileIntergrityTest()
152161
lastXEntriesArray = hf.GetLastXEntrys(3).ToArray();
153162
Assert.AreEqual(1, lastXEntriesArray.Length);
154163
Assert.AreEqual(ar3, lastXEntriesArray[0].AudioResource);
155-
hf.Dispose();
164+
db.Dispose();
156165

157166

158167
File.Delete(testFile);

TS3AudioBot/DbStore.cs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// TS3AudioBot - An advanced Musicbot for Teamspeak 3
2+
// Copyright (C) 2017 TS3AudioBot contributors
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the Open Software License v. 3.0
6+
//
7+
// You should have received a copy of the Open Software License along with this
8+
// program. If not, see <https://opensource.org/licenses/OSL-3.0>.
9+
10+
namespace TS3AudioBot
11+
{
12+
using History;
13+
using LiteDB;
14+
using System;
15+
using System.IO;
16+
17+
public class DbStore : IDisposable
18+
{
19+
private const string DbMetaInformationTable = "dbmeta";
20+
21+
private readonly LiteDatabase database;
22+
private readonly LiteCollection<DbMetaData> metaTable;
23+
24+
// TODO rework config class with config rewok
25+
public DbStore(HistoryManagerData hmd)
26+
{
27+
var historyFile = new FileInfo(hmd.HistoryFile);
28+
database = new LiteDatabase(historyFile.FullName);
29+
30+
metaTable = database.GetCollection<DbMetaData>(DbMetaInformationTable);
31+
}
32+
33+
public DbMetaData GetMetaData(string table)
34+
{
35+
var meta = metaTable.FindById(table);
36+
if (meta == null)
37+
{
38+
meta = new DbMetaData { Id = table, Version = 0, CustomData = null };
39+
metaTable.Insert(meta);
40+
}
41+
return meta;
42+
}
43+
44+
public void UpdateMetaData(DbMetaData metaData)
45+
{
46+
metaTable.Update(metaData);
47+
}
48+
49+
public LiteCollection<T> GetCollection<T>(string name)
50+
{
51+
return database.GetCollection<T>(name);
52+
}
53+
54+
public void CleanFile()
55+
{
56+
database.Shrink();
57+
}
58+
59+
public void Dispose()
60+
{
61+
database.Dispose();
62+
}
63+
}
64+
65+
public class DbMetaData
66+
{
67+
public string Id { get; set; }
68+
public int Version { get; set; }
69+
public object CustomData { get; set; }
70+
}
71+
}

TS3AudioBot/History/Deprecated/AudioLogEntry.cs

Lines changed: 0 additions & 103 deletions
This file was deleted.

0 commit comments

Comments
 (0)