Skip to content

Commit

Permalink
Extracted db for injection later.
Browse files Browse the repository at this point in the history
+ Deprecated old history upgrader
  • Loading branch information
Splamy committed Oct 21, 2017
1 parent 7bda172 commit e5d4a67
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 659 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ after_success:
- cd ./TS3AudioBot/bin/Release
- ls
- zip TS3AudioBot.zip TS3AudioBot.exe TS3Client.dll Nett.dll LiteDB.dll Heijden.Dns.dll BouncyCastle.Crypto.dll x64/* x86/*
- 'export version=`./TS3AudioBot.exe --version | grep "Version: "`'
- "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"
- 'export version=`mono TS3AudioBot.exe --version | grep "Version: "`'
- "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"
- cd "$MAIN_DIR"

after_script:
Expand Down
39 changes: 24 additions & 15 deletions TS3ABotUnitTests/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using TS3AudioBot;

namespace TS3ABotUnitTests
{
using System;
Expand Down Expand Up @@ -56,8 +58,9 @@ public void HistoryFileIntergrityTest()
var data2 = new HistorySaveData(ar2, inv2.DatabaseId);
var data3 = new HistorySaveData(ar3, 103);


var hf = new HistoryManager(new HistoryManagerData { HistoryFile = testFile, FillDeletedIds = false });
var hmf = new HistoryManagerData {HistoryFile = testFile, FillDeletedIds = false};
var db = new DbStore(hmf);
var hf = new HistoryManager(hmf, db);

hf.LogAudioResource(data1);

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

hf.Dispose();
db.Dispose();

hf = new HistoryManager(new HistoryManagerData { HistoryFile = testFile, FillDeletedIds = false });
db = new DbStore(hmf);
hf = new HistoryManager(hmf, db);
lastXEntries = hf.GetLastXEntrys(1);
Assert.True(lastXEntries.Any());
lastEntry = lastXEntries.First();
Expand All @@ -82,10 +86,11 @@ public void HistoryFileIntergrityTest()
lastEntry = lastXEntries.First();
Assert.AreEqual(ar2, lastEntry.AudioResource);

hf.Dispose();
db.Dispose();

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


hf.Dispose();
db.Dispose();

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

hf.Dispose();
db.Dispose();

// recheck order
hf = new HistoryManager(new HistoryManagerData { HistoryFile = testFile, FillDeletedIds = false });
db = new DbStore(hmf);
hf = new HistoryManager(hmf, db);
lastXEntriesArray = hf.GetLastXEntrys(2).ToArray();
Assert.AreEqual(2, lastXEntriesArray.Length);
Assert.AreEqual(ar2, lastXEntriesArray[0].AudioResource);
Assert.AreEqual(ar1, lastXEntriesArray[1].AudioResource);
hf.Dispose();
db.Dispose();

// delete entry 1
hf = new HistoryManager(new HistoryManagerData { HistoryFile = testFile, FillDeletedIds = false });
db = new DbStore(hmf);
hf = new HistoryManager(hmf, db);
hf.RemoveEntry(hf.FindEntryByResource(ar1));

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

lastXEntriesArray = hf.GetLastXEntrys(3).ToArray();
Assert.AreEqual(2, lastXEntriesArray.Length);
hf.Dispose();
db.Dispose();

// delete entry 2
hf = new HistoryManager(new HistoryManagerData { HistoryFile = testFile, FillDeletedIds = false });
db = new DbStore(hmf);
hf = new HistoryManager(hmf, db);
// .. check integrity from previous store
lastXEntriesArray = hf.GetLastXEntrys(3).ToArray();
Assert.AreEqual(2, lastXEntriesArray.Length);
Expand All @@ -152,7 +161,7 @@ public void HistoryFileIntergrityTest()
lastXEntriesArray = hf.GetLastXEntrys(3).ToArray();
Assert.AreEqual(1, lastXEntriesArray.Length);
Assert.AreEqual(ar3, lastXEntriesArray[0].AudioResource);
hf.Dispose();
db.Dispose();


File.Delete(testFile);
Expand Down
71 changes: 71 additions & 0 deletions TS3AudioBot/DbStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// TS3AudioBot - An advanced Musicbot for Teamspeak 3
// Copyright (C) 2017 TS3AudioBot contributors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the Open Software License v. 3.0
//
// You should have received a copy of the Open Software License along with this
// program. If not, see <https://opensource.org/licenses/OSL-3.0>.

namespace TS3AudioBot
{
using History;
using LiteDB;
using System;
using System.IO;

public class DbStore : IDisposable
{
private const string DbMetaInformationTable = "dbmeta";

private readonly LiteDatabase database;
private readonly LiteCollection<DbMetaData> metaTable;

// TODO rework config class with config rewok
public DbStore(HistoryManagerData hmd)
{
var historyFile = new FileInfo(hmd.HistoryFile);
database = new LiteDatabase(historyFile.FullName);

metaTable = database.GetCollection<DbMetaData>(DbMetaInformationTable);
}

public DbMetaData GetMetaData(string table)
{
var meta = metaTable.FindById(table);
if (meta == null)
{
meta = new DbMetaData { Id = table, Version = 0, CustomData = null };
metaTable.Insert(meta);
}
return meta;
}

public void UpdateMetaData(DbMetaData metaData)
{
metaTable.Update(metaData);
}

public LiteCollection<T> GetCollection<T>(string name)
{
return database.GetCollection<T>(name);
}

public void CleanFile()
{
database.Shrink();
}

public void Dispose()
{
database.Dispose();
}
}

public class DbMetaData
{
public string Id { get; set; }
public int Version { get; set; }
public object CustomData { get; set; }
}
}
103 changes: 0 additions & 103 deletions TS3AudioBot/History/Deprecated/AudioLogEntry.cs

This file was deleted.

Loading

0 comments on commit e5d4a67

Please sign in to comment.