From f5e1c66dbc14da20e54c9922a32d8a12e9131ff5 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Thu, 23 Feb 2017 13:45:49 -0600 Subject: [PATCH] Event system and debug consumer added --- SiaDrive.Api/DebugConsumer.cpp | 18 +++ SiaDrive.Api/DebugConsumer.h | 20 +++ SiaDrive.Api/EventSystem.cpp | 66 +++++++- SiaDrive.Api/EventSystem.h | 24 ++- SiaDrive.Api/SiaDrive.Api.vcxproj | 2 + SiaDrive.Api/SiaDrive.Api.vcxproj.filters | 6 + SiaDrive.Api/UploadManager.cpp | 130 ++++++++++------ SiaDrive.Api/UploadManager.h | 179 ++++++++++++++++++++-- SiaDrive.Api/stdafx.h | 4 +- SiaDrive.sln | 6 +- UnitTests/UploadManagerTest.cpp | 8 + 11 files changed, 400 insertions(+), 63 deletions(-) create mode 100644 SiaDrive.Api/DebugConsumer.cpp create mode 100644 SiaDrive.Api/DebugConsumer.h diff --git a/SiaDrive.Api/DebugConsumer.cpp b/SiaDrive.Api/DebugConsumer.cpp new file mode 100644 index 0000000..83bdc17 --- /dev/null +++ b/SiaDrive.Api/DebugConsumer.cpp @@ -0,0 +1,18 @@ +#include "stdafx.h" +#include "DebugConsumer.h" + +using namespace Sia::Api; + +CDebugConsumer::CDebugConsumer() +{ + CEventSystem::EventSystem.AddEventConsumer([this](const CEvent& event) { this->ProcessEvent(event); }); +} + +CDebugConsumer::~CDebugConsumer() +{ +} + +void CDebugConsumer::ProcessEvent(const CEvent& eventData) +{ + OutputDebugString(eventData.GetSingleLineMessage().c_str()); +} diff --git a/SiaDrive.Api/DebugConsumer.h b/SiaDrive.Api/DebugConsumer.h new file mode 100644 index 0000000..553fa0a --- /dev/null +++ b/SiaDrive.Api/DebugConsumer.h @@ -0,0 +1,20 @@ +#pragma once +#include +#include + +NS_BEGIN(Sia) +NS_BEGIN(Api) + +class AFX_EXT_CLASS CDebugConsumer +{ +public: + CDebugConsumer(); + +public: + ~CDebugConsumer(); + +private: + void ProcessEvent(const CEvent& eventData); +}; + +NS_END(2); diff --git a/SiaDrive.Api/EventSystem.cpp b/SiaDrive.Api/EventSystem.cpp index 9f7cf5c..bf0e429 100644 --- a/SiaDrive.Api/EventSystem.cpp +++ b/SiaDrive.Api/EventSystem.cpp @@ -5,15 +5,77 @@ using namespace Sia::Api; CEventSystem CEventSystem::EventSystem; -CEventSystem::CEventSystem() +CEventSystem::CEventSystem() : + _stopEvent(INVALID_HANDLE_VALUE) { } CEventSystem::~CEventSystem() { + Stop(); + ::CloseHandle(_stopEvent); } -void CEventSystem::NotifyEvent(const CEvent& eventData) +void CEventSystem::ProcessEvents() { + while (::WaitForSingleObject(_stopEvent, 10) == WAIT_TIMEOUT) + { + CEventPtr eventData; + do + { + { + std::lock_guard l(_eventMutex); + if (_eventQueue.size()) + { + eventData = _eventQueue.front(); + _eventQueue.pop_front(); + } + else + { + eventData.reset(); + } + } + if (eventData) + { + for (auto& v : _eventConsumers) + { + v(*eventData); + } + } + } while (eventData); + } } + +void CEventSystem::NotifyEvent(CEventPtr eventData) +{ + std::lock_guard l(_eventMutex); + _eventQueue.push_back(eventData); +} + +void CEventSystem::AddEventConsumer(std::function consumer) +{ + if (!_processThread) + { + _eventConsumers.push_back(consumer); + } +} + +void CEventSystem::Start() +{ + if (!_processThread) + { + _stopEvent = ::CreateEvent(nullptr, FALSE, FALSE, nullptr); + _processThread.reset(new std::thread([this]() {ProcessEvents(); })); + } +} + +void CEventSystem::Stop() +{ + if (_processThread) + { + ::SetEvent(_stopEvent); + _processThread->join(); + _processThread.reset(); + } +} \ No newline at end of file diff --git a/SiaDrive.Api/EventSystem.h b/SiaDrive.Api/EventSystem.h index 02af3f6..52df753 100644 --- a/SiaDrive.Api/EventSystem.h +++ b/SiaDrive.Api/EventSystem.h @@ -6,9 +6,18 @@ NS_BEGIN(Api) class AFX_EXT_CLASS CEvent { +public: + virtual ~CEvent() {} +public: + virtual String GetSingleLineMessage() const = 0; }; +typedef std::shared_ptr CEventPtr; + +#define CreateSystemEvent(E) CEventPtr(new E) +#define CreateSystemEventConsumer(E) [=](const CEvent&) -> void { E(e); } + // Singleton class AFX_EXT_CLASS CEventSystem { @@ -25,10 +34,23 @@ public: CEventSystem& operator=(CEventSystem&&) = delete; CEventSystem& operator=(const CEventSystem&) = delete; +private: + HANDLE _stopEvent; + std::deque _eventQueue; + std::deque> _eventConsumers; + std::mutex _eventMutex; + std::unique_ptr _processThread; + public: static CEventSystem EventSystem; +private: + void ProcessEvents(); + public: - void NotifyEvent(const CEvent& eventData); + void AddEventConsumer(std::function consumer); + void NotifyEvent(CEventPtr eventData); + void Start(); + void Stop(); }; NS_END(2) diff --git a/SiaDrive.Api/SiaDrive.Api.vcxproj b/SiaDrive.Api/SiaDrive.Api.vcxproj index 653f122..06e20e9 100644 --- a/SiaDrive.Api/SiaDrive.Api.vcxproj +++ b/SiaDrive.Api/SiaDrive.Api.vcxproj @@ -190,6 +190,7 @@ + false @@ -229,6 +230,7 @@ + diff --git a/SiaDrive.Api/SiaDrive.Api.vcxproj.filters b/SiaDrive.Api/SiaDrive.Api.vcxproj.filters index 684f922..c5b1042 100644 --- a/SiaDrive.Api/SiaDrive.Api.vcxproj.filters +++ b/SiaDrive.Api/SiaDrive.Api.vcxproj.filters @@ -63,6 +63,9 @@ Source Files + + Source Files + @@ -106,6 +109,9 @@ Header Files + + Header Files + diff --git a/SiaDrive.Api/UploadManager.cpp b/SiaDrive.Api/UploadManager.cpp index 9b756cc..a54aa9b 100644 --- a/SiaDrive.Api/UploadManager.cpp +++ b/SiaDrive.Api/UploadManager.cpp @@ -31,6 +31,36 @@ static void CreateTableIfNotFound(SQLite::Database* database, const String& tabl database->exec(CW2A(sqlCreate.c_str())); } +String CUploadManager::UploadStatusToString(const UploadStatus& uploadStatus) +{ + switch (uploadStatus) + { + case UploadStatus::Complete: + return L"Complete"; + + case UploadStatus::Copying: + return L"Copying"; + + case UploadStatus::Error: + return L"Error"; + + case UploadStatus::Modified: + return L"Modified"; + + case UploadStatus::NotFound: + return L"Not Found"; + + case UploadStatus::Queued: + return L"Queued"; + + case UploadStatus::Uploading: + return L"Uploading"; + + default: + return L"!!Not Defined!!"; + } +} + CUploadManager::CUploadManager(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig) : CAutoThread(siaCurl, siaDriveConfig), _uploadDatabase(siaDriveConfig->GetRenter_UploadDbFilePath(), SQLite::OPEN_CREATE | SQLite::OPEN_READWRITE), @@ -50,33 +80,33 @@ CUploadManager::~CUploadManager() void CUploadManager::FileUploadAction(const String& siaPath, const String& filePath, const String& tempSourcePath, const String& siaDriveFilePath) { - CEventSystem::EventSystem.NotifyEvent(CreatingTemporarySiaDriveFile(siaPath, filePath, tempSourcePath)); + CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(CreatingTemporarySiaDriveFile(siaPath, filePath, tempSourcePath))); if (RetryableAction(::CopyFile(filePath.c_str(), tempSourcePath.c_str(), FALSE), DEFAULT_RETRY_COUNT, DEFAULT_RETRY_DELAY_MS)) { // Delete existing '.siadrive' file, if found // !!Should never come here. If so, there was a problem with startup clean-up if (!RetryDeleteFileIfExists(siaDriveFilePath)) { - CEventSystem::EventSystem.NotifyEvent(DeleteSiaDriveFileFailed(siaPath, filePath, siaDriveFilePath)); + CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DeleteSiaDriveFileFailed(siaPath, filePath, siaDriveFilePath))); } // Rename '.siadrive.temp' to '.siadrive' - CEventSystem::EventSystem.NotifyEvent(RenamingTemporarySiaDriveFile(siaPath, filePath, tempSourcePath, siaDriveFilePath)); + CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(RenamingTemporarySiaDriveFile(siaPath, filePath, tempSourcePath, siaDriveFilePath))); if (RetryableAction(::MoveFile(tempSourcePath.c_str(), siaDriveFilePath.c_str()), DEFAULT_RETRY_COUNT, DEFAULT_RETRY_DELAY_MS)) { // TODO Change status to 'Queued' } else { - CEventSystem::EventSystem.NotifyEvent(RenamingTemporarySiaDriveFileFailed(siaPath, filePath, tempSourcePath, siaDriveFilePath)); + CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(RenamingTemporarySiaDriveFileFailed(siaPath, filePath, tempSourcePath, siaDriveFilePath))); if (!RetryDeleteFileIfExists(tempSourcePath)) { - CEventSystem::EventSystem.NotifyEvent(DeleteTemporarySiaDriveFileFailed(siaPath, filePath, tempSourcePath)); + CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DeleteTemporarySiaDriveFileFailed(siaPath, filePath, tempSourcePath))); } if (!RetryDeleteFileIfExists(siaDriveFilePath)) { - CEventSystem::EventSystem.NotifyEvent(DeleteSiaDriveFileFailed(siaPath, filePath, siaDriveFilePath)); + CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DeleteSiaDriveFileFailed(siaPath, filePath, siaDriveFilePath))); } // Requeue @@ -85,13 +115,13 @@ void CUploadManager::FileUploadAction(const String& siaPath, const String& fileP } else { - CEventSystem::EventSystem.NotifyEvent(CreatingTemporarySiaDriveFileFailed(siaPath, filePath, tempSourcePath)); + CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(CreatingTemporarySiaDriveFileFailed(siaPath, filePath, tempSourcePath))); // If temp copy fails, try to delete // If partial copy and file is unable to be deleted, log warning if (!RetryDeleteFileIfExists(tempSourcePath)) { - CEventSystem::EventSystem.NotifyEvent(DeleteTemporarySiaDriveFileFailed(siaPath, filePath, tempSourcePath)); + CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DeleteTemporarySiaDriveFileFailed(siaPath, filePath, tempSourcePath))); } // Requeue @@ -247,6 +277,7 @@ UploadStatus CUploadManager::GetUploadStatus(const String& siaPath) UploadError CUploadManager::AddOrUpdate(const String& siaPath, String filePath) { UploadError ret = UploadError::Success; + // Relative to absolute and grab parent folder of source String rootPath; { @@ -262,50 +293,57 @@ UploadError CUploadManager::AddOrUpdate(const String& siaPath, String filePath) rootPath = temp; } - // Lock here - if file is modified again before a prior upload is complete, delete it and - // start again later - std::lock_guard l(_uploadMutex); - - SQLite::Statement query(_uploadDatabase, QUERY_UPLOADS_BY_SIA_PATH_AND_2_STATUS); - query.bind("@sia_path", CW2A(siaPath.c_str()).m_psz); - query.bind("@status1", static_cast(UploadStatus::Uploading)); - query.bind("@status2", static_cast(UploadStatus::Modified)); - // Check copying - if (query.executeStep()) + if (::PathFileExists(filePath.c_str())) { - UploadStatus uploadStatus = static_cast(static_cast(query.getColumn(2))); - CEventSystem::EventSystem.NotifyEvent(ExistingUploadFound(siaPath, filePath, uploadStatus)); - if (uploadStatus == UploadStatus::Uploading) + // Lock here - if file is modified again before a prior upload is complete, delete it and + // start again later + std::lock_guard l(_uploadMutex); + + SQLite::Statement query(_uploadDatabase, QUERY_UPLOADS_BY_SIA_PATH_AND_2_STATUS); + query.bind("@sia_path", CW2A(siaPath.c_str()).m_psz); + query.bind("@status1", static_cast(UploadStatus::Uploading)); + query.bind("@status2", static_cast(UploadStatus::Modified)); + // Check copying + if (query.executeStep()) { - // set to modified - // update file path + UploadStatus uploadStatus = static_cast(static_cast(query.getColumn(2))); + CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(ExistingUploadFound(siaPath, filePath, uploadStatus))); + if (uploadStatus == UploadStatus::Uploading) + { + // set to modified + // update file path + } + } + else + { + // Strip drive specification (i.e. C:\) + // TODO If mount to drive is ever enabled, this will need to change + String siaDriveFileName = GenerateSha256(&filePath[3]) + L".siadrive"; + + String siaDriveFilePath; + siaDriveFilePath.resize(MAX_PATH + 1); + PathCombine(&siaDriveFilePath[0], rootPath.c_str(), siaDriveFileName.c_str()); + + String tempSourcePath; + tempSourcePath.resize(MAX_PATH + 1); + PathCombine(&tempSourcePath[0], rootPath.c_str(), (siaDriveFileName + L".temp").c_str()); + + // Add to db + /*SQLite::Statement addOrUpdate(_uploadDatabase, ADD_UPDATE_UPLOAD); + addOrUpdate.bind("@sia_path", CW2A(siaPath.c_str()).m_psz); + addOrUpdate.bind("@file_path", CW2A(filePath.c_str()).m_psz); + addOrUpdate.bind("@siadrive_path", CW2A(siaDriveFilePath.c_str()).m_psz); + addOrUpdate.bind("@status", static_cast(UploadStatus::Copying));*/ + + // Queue file upload operation + std::lock_guard l2(_fileQueueMutex); + _fileQueue.push_back([=]() { this->FileUploadAction(siaPath, filePath, tempSourcePath, siaDriveFilePath); }); + CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(NewUploadAdded(siaPath, filePath, siaDriveFilePath))); } } else { - // Strip drive specification (i.e. C:\) - // TODO If mount to drive is ever enabled, this will need to change - String siaDriveFileName = GenerateSha256(&filePath[3]) + L".siadrive"; - - String siaDriveFilePath; - siaDriveFilePath.resize(MAX_PATH + 1); - PathCombine(&siaDriveFilePath[0], rootPath.c_str(), siaDriveFileName.c_str()); - - String tempSourcePath; - tempSourcePath.resize(MAX_PATH + 1); - PathCombine(&tempSourcePath[0], rootPath.c_str(), (siaDriveFileName + L".temp").c_str()); - - // Add to db - /*SQLite::Statement addOrUpdate(_uploadDatabase, ADD_UPDATE_UPLOAD); - addOrUpdate.bind("@sia_path", CW2A(siaPath.c_str()).m_psz); - addOrUpdate.bind("@file_path", CW2A(filePath.c_str()).m_psz); - addOrUpdate.bind("@siadrive_path", CW2A(siaDriveFilePath.c_str()).m_psz); - addOrUpdate.bind("@status", static_cast(UploadStatus::Copying));*/ - - // Queue file upload operation - std::lock_guard l2(_fileQueueMutex); - _fileQueue.push_back([=]() { this->FileUploadAction(siaPath, filePath, tempSourcePath, siaDriveFilePath); }); - CEventSystem::EventSystem.NotifyEvent(NewUploadAdded(siaPath, filePath, siaDriveFilePath)); + ret = UploadError::SourceFileNotFound; } return ret; diff --git a/SiaDrive.Api/UploadManager.h b/SiaDrive.Api/UploadManager.h index 38050e9..ed83048 100644 --- a/SiaDrive.Api/UploadManager.h +++ b/SiaDrive.Api/UploadManager.h @@ -24,7 +24,8 @@ public: enum class _UploadError { - Success + Success, + SourceFileNotFound }; private: @@ -58,6 +59,9 @@ protected: virtual void AutoThreadCallback(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig) override; void FileThreadCallback(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig); +public: + static String UploadStatusToString(const _UploadStatus& uploadStatus); + public: _UploadStatus GetUploadStatus(const String& siaPath); _UploadError AddOrUpdate(const String& siaPath, String filePath); @@ -74,8 +78,28 @@ class CreatingTemporarySiaDriveFile : public CEvent { public: - CreatingTemporarySiaDriveFile(const String& siaPath, const String& filePath, const String& tempSourcePath) + CreatingTemporarySiaDriveFile(const String& siaPath, const String& filePath, const String& tempSourcePath) : + _siaPath(siaPath), + _filePath(filePath), + _tempSourcePath(tempSourcePath) { + + } + +public: + virtual ~CreatingTemporarySiaDriveFile() + { + } + +private: + const String _siaPath; + const String _filePath; + const String _tempSourcePath; + +public: + virtual String GetSingleLineMessage() const override + { + return L"CreatingTemporarySiaDriveFile\n\tSP|" + _siaPath + L"\n\tFP|" + _filePath + L"\n\tTSP|" + _tempSourcePath; } }; @@ -83,70 +107,207 @@ class CreatingTemporarySiaDriveFileFailed : public CEvent { public: - CreatingTemporarySiaDriveFileFailed(const String& siaPath, const String& filePath, const String& tempSourcePath) + CreatingTemporarySiaDriveFileFailed(const String& siaPath, const String& filePath, const String& tempSourcePath) : + _siaPath(siaPath), + _filePath(filePath), + _tempSourcePath(tempSourcePath) { } + +public: + virtual ~CreatingTemporarySiaDriveFileFailed() + { + } + +private: + const String _siaPath; + const String _filePath; + const String _tempSourcePath; + +public: + virtual String GetSingleLineMessage() const override + { + return L"CreatingTemporarySiaDriveFileFailed\n\tSP|" + _siaPath + L"\n\tFP|" + _filePath + L"\n\tTSP|" + _tempSourcePath; + } }; class DeleteSiaDriveFileFailed : public CEvent { public: - DeleteSiaDriveFileFailed(const String& siaPath, const String& filePath, const String& siaDriveFilePath) + DeleteSiaDriveFileFailed(const String& siaPath, const String& filePath, const String& siaDriveFilePath) : + _siaPath(siaPath), + _filePath(filePath), + _siaDriveFilePath(siaDriveFilePath) { } + +public: + virtual ~DeleteSiaDriveFileFailed() + { + } + +private: + const String _siaPath; + const String _filePath; + const String _siaDriveFilePath; + +public: + virtual String GetSingleLineMessage() const override + { + return L"DeleteSiaDriveFileFailed\n\tSP|" + _siaPath + L"\n\tFP|" + _filePath + L"\n\tSDP|" + _siaDriveFilePath; + } }; class DeleteTemporarySiaDriveFileFailed : public CEvent { public: - DeleteTemporarySiaDriveFileFailed(const String& siaPath, const String& filePath, const String& tempSourcePath) + DeleteTemporarySiaDriveFileFailed(const String& siaPath, const String& filePath, const String& tempSourcePath) : + _siaPath(siaPath), + _filePath(filePath), + _tempSourcePath(tempSourcePath) { } + +public: + virtual ~DeleteTemporarySiaDriveFileFailed() + { + } + +private: + const String _siaPath; + const String _filePath; + const String _tempSourcePath; + +public: + virtual String GetSingleLineMessage() const override + { + return L"DeleteTemporarySiaDriveFileFailed\n\tSP|" + _siaPath + L"\n\tFP|" + _filePath + L"\n\tTSP|" + _tempSourcePath; + } }; class RenamingTemporarySiaDriveFile : public CEvent { public: - RenamingTemporarySiaDriveFile(const String& siaPath, const String& filePath, const String& tempSourcePath, const String& siaDriveFilePath) + RenamingTemporarySiaDriveFile(const String& siaPath, const String& filePath, const String& tempSourcePath, const String& siaDriveFilePath) : + _siaPath(siaPath), + _filePath(filePath), + _tempSourcePath(tempSourcePath), + _siaDriveFilePath(siaDriveFilePath) { } + +public: + virtual ~RenamingTemporarySiaDriveFile() + { + } + +private: + const String _siaPath; + const String _filePath; + const String _tempSourcePath; + const String _siaDriveFilePath; + +public: + virtual String GetSingleLineMessage() const override + { + return L"RenamingTemporarySiaDriveFile\n\tSP|" + _siaPath + L"\n\tFP|" + _filePath + L"\n\tTSP|" + _tempSourcePath + L"\n\tSDP|" + _siaDriveFilePath; + } }; class RenamingTemporarySiaDriveFileFailed : public CEvent { public: - RenamingTemporarySiaDriveFileFailed(const String& siaPath, const String& filePath, const String& tempSourcePath, const String& siaDriveFilePath) + RenamingTemporarySiaDriveFileFailed(const String& siaPath, const String& filePath, const String& tempSourcePath, const String& siaDriveFilePath) : + _siaPath(siaPath), + _filePath(filePath), + _tempSourcePath(tempSourcePath), + _siaDriveFilePath(siaDriveFilePath) { } + +public: + virtual ~RenamingTemporarySiaDriveFileFailed() + { + } + +private: + const String _siaPath; + const String _filePath; + const String _tempSourcePath; + const String _siaDriveFilePath; + +public: + virtual String GetSingleLineMessage() const override + { + return L"RenamingTemporarySiaDriveFileFailed\n\tSP|" + _siaPath + L"\n\tFP|" + _filePath + L"\n\tTSP|" + _tempSourcePath + L"\n\tSDP|" + _siaDriveFilePath; + } }; class ExistingUploadFound : public CEvent { public: - ExistingUploadFound(const String& siaPath, const String& filePath, const UploadStatus& uploadStatus) + ExistingUploadFound(const String& siaPath, const String& filePath, const UploadStatus& uploadStatus) : + _siaPath(siaPath), + _filePath(filePath), + _uploadStatus(uploadStatus) { } + +public: + virtual ~ExistingUploadFound() + { + } + +private: + const String _siaPath; + const String _filePath; + const UploadStatus _uploadStatus; + +public: + virtual String GetSingleLineMessage() const override + { + return L"ExistingUploadFound\n\tSP|" + _siaPath + L"\n\tFP|" + _filePath + L"\n\tST|" + CUploadManager::UploadStatusToString(_uploadStatus); + } }; class NewUploadAdded : public CEvent { public: - NewUploadAdded(const String& siaPath, const String& filePath, const String& siaDriveFilePath) + NewUploadAdded(const String& siaPath, const String& filePath, const String& siaDriveFilePath) : + _siaPath(siaPath), + _filePath(filePath), + _siaDriveFilePath(siaDriveFilePath) { } + +public: + virtual ~NewUploadAdded() + { + } + +private: + const String _siaPath; + const String _filePath; + const String _siaDriveFilePath; + +public: + virtual String GetSingleLineMessage() const override + { + return L"NewUploadAdded\n\tSP|" + _siaPath + L"\n\tFP|" + _filePath + L"\n\tSDP|" + _siaDriveFilePath; + } }; NS_END(2) \ No newline at end of file diff --git a/SiaDrive.Api/stdafx.h b/SiaDrive.Api/stdafx.h index 5c2360a..2421e5f 100644 --- a/SiaDrive.Api/stdafx.h +++ b/SiaDrive.Api/stdafx.h @@ -38,4 +38,6 @@ #include // MFC socket extensions -#include \ No newline at end of file +#include +#include +#include \ No newline at end of file diff --git a/SiaDrive.sln b/SiaDrive.sln index fa987b3..b63fc19 100644 --- a/SiaDrive.sln +++ b/SiaDrive.sln @@ -734,8 +734,7 @@ Global {B3DF927F-A1CE-4F50-A621-A4C3A06E4F8A}.RelWithDebInfo|x64.Build.0 = Release|x64 {B3DF927F-A1CE-4F50-A621-A4C3A06E4F8A}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 {B3DF927F-A1CE-4F50-A621-A4C3A06E4F8A}.RelWithDebInfo|x86.Build.0 = Release|Win32 - {BE7EE71D-6608-36DD-9687-D84AAE20C0A3}.Debug|x64.ActiveCfg = Debug|x64 - {BE7EE71D-6608-36DD-9687-D84AAE20C0A3}.Debug|x64.Build.0 = Debug|x64 + {BE7EE71D-6608-36DD-9687-D84AAE20C0A3}.Debug|x64.ActiveCfg = Debug|Win32 {BE7EE71D-6608-36DD-9687-D84AAE20C0A3}.Debug|x86.ActiveCfg = Debug|Win32 {BE7EE71D-6608-36DD-9687-D84AAE20C0A3}.Debug|x86.Build.0 = Debug|Win32 {BE7EE71D-6608-36DD-9687-D84AAE20C0A3}.DLL Debug - DLL OpenSSL - DLL LibSSH2|x64.ActiveCfg = Release|Win32 @@ -859,8 +858,7 @@ Global {BE7EE71D-6608-36DD-9687-D84AAE20C0A3}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|Win32 {BE7EE71D-6608-36DD-9687-D84AAE20C0A3}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|Win32 {BE7EE71D-6608-36DD-9687-D84AAE20C0A3}.RelWithDebInfo|x86.Build.0 = RelWithDebInfo|Win32 - {92EF9CAE-3F0C-31D5-9556-62586CC5072D}.Debug|x64.ActiveCfg = Debug|x64 - {92EF9CAE-3F0C-31D5-9556-62586CC5072D}.Debug|x64.Build.0 = Debug|x64 + {92EF9CAE-3F0C-31D5-9556-62586CC5072D}.Debug|x64.ActiveCfg = Debug|Win32 {92EF9CAE-3F0C-31D5-9556-62586CC5072D}.Debug|x86.ActiveCfg = Debug|Win32 {92EF9CAE-3F0C-31D5-9556-62586CC5072D}.Debug|x86.Build.0 = Debug|Win32 {92EF9CAE-3F0C-31D5-9556-62586CC5072D}.DLL Debug - DLL OpenSSL - DLL LibSSH2|x64.ActiveCfg = Release|Win32 diff --git a/UnitTests/UploadManagerTest.cpp b/UnitTests/UploadManagerTest.cpp index 1a6cbdf..564cb0b 100644 --- a/UnitTests/UploadManagerTest.cpp +++ b/UnitTests/UploadManagerTest.cpp @@ -5,6 +5,7 @@ #include "MockSiad.h" #include "SiaDriveConfig.h" #include "UnitTestConfig.h" +#include using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Sia::Api; @@ -16,8 +17,14 @@ namespace UnitTests private: const SiaHostConfig hostConfig = { TEST_SERVER_AND_PORT, TEST_SERVER_VERSION }; static std::unique_ptr siad; + static CDebugConsumer _debugConsumer; public: + TEST_CLASS_INITIALIZE(ClassInit) + { + CEventSystem::EventSystem.Start(); + } + TEST_METHOD_INITIALIZE(Initialize) { // Always delete DB before next test @@ -62,4 +69,5 @@ namespace UnitTests }; std::unique_ptr UnitTests::siad; + CDebugConsumer UnitTests::_debugConsumer; } \ No newline at end of file