1
0

Upload manager changes and events

This commit is contained in:
Scott E. Graves
2017-02-25 21:35:59 -06:00
parent ced91ecaa9
commit 0d16d224db
13 changed files with 138 additions and 56 deletions

View File

@@ -1,5 +1,6 @@
#include "stdafx.h"
#include "DebugConsumer.h"
#include "EventSystem.h"
using namespace Sia::Api;

View File

@@ -1,10 +1,11 @@
#pragma once
#include <SiaCommon.h>
#include <EventSystem.h>
NS_BEGIN(Sia)
NS_BEGIN(Api)
class CEvent;
class AFX_EXT_CLASS CDebugConsumer
{
public:

View File

@@ -0,0 +1,20 @@
#include "stdafx.h"
#include "LoggingConsumer.h"
#include "EventSystem.h"
using namespace Sia::Api;
CLoggingConsumer::CLoggingConsumer()
{
CEventSystem::EventSystem.AddEventConsumer([=](const CEvent& event) {this->ProcessEvent(event); });
}
CLoggingConsumer::~CLoggingConsumer()
{
}
void CLoggingConsumer::ProcessEvent(const CEvent& eventData)
{
}

View File

@@ -0,0 +1,20 @@
#pragma once
#include <SiaCommon.h>
NS_BEGIN(Sia)
NS_BEGIN(Api)
class CEvent;
class AFX_EXT_CLASS CLoggingConsumer
{
public:
CLoggingConsumer();
public:
~CLoggingConsumer();
private:
void ProcessEvent(const CEvent& eventData);
};
NS_END(2)

View File

@@ -206,6 +206,7 @@
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="EventSystem.cpp" />
<ClCompile Include="LoggingConsumer.cpp" />
<ClCompile Include="SiaApi.cpp" />
<ClCompile Include="SiaCommon.cpp" />
<ClCompile Include="SiaConsensus.cpp" />
@@ -233,6 +234,7 @@
<ClInclude Include="DebugConsumer.h" />
<ClInclude Include="EventSystem.h" />
<ClInclude Include="json.hpp" />
<ClInclude Include="LoggingConsumer.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="SiaApi.h" />
<ClInclude Include="SiaCommon.h" />

View File

@@ -66,6 +66,9 @@
<ClCompile Include="DebugConsumer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="LoggingConsumer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="SiaDrive.Api.def">
@@ -112,6 +115,9 @@
<ClInclude Include="DebugConsumer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="LoggingConsumer.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="SiaDrive.Api.rc">

View File

@@ -336,7 +336,8 @@ UploadError CUploadManager::AddOrUpdate(const String& siaPath, String filePath)
// start again later
std::lock_guard<std::mutex> l(_uploadMutex);
// TODO Handle SQLite::Exception
try
{
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<unsigned>(UploadStatus::Uploading));
@@ -393,6 +394,12 @@ UploadError CUploadManager::AddOrUpdate(const String& siaPath, String filePath)
}
}
}
catch (SQLite::Exception e)
{
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DatabaseExceptionOccurred(e)));
ret = UploadError::DatabaseError;
}
}
else
{
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(SourceFileNotFound(siaPath, filePath)));

View File

@@ -0,0 +1,9 @@
#pragma once
#include <SiaCommon.h>
NS_BEGIN(Sia)
NS_BEGIN(Api)
NS_END(2)

View File

@@ -193,6 +193,7 @@
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="EventSystemEvents.h" />
<ClInclude Include="ntray.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="SiaDriveApp.h" />

View File

@@ -36,6 +36,9 @@
<ClInclude Include="ntray.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="EventSystemEvents.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="SiaDriveDlg.cpp">

View File

@@ -20,6 +20,11 @@ END_MESSAGE_MAP()
// CSiaDriveApp construction
#ifdef _DEBUG
const Sia::Api::CDebugConsumer CSiaDriveApp::_debugConsumer;
#endif
const Sia::Api::CLoggingConsumer CSiaDriveApp::_loggingConsumer;
CSiaDriveApp::CSiaDriveApp()
{
// support Restart Manager

View File

@@ -9,6 +9,8 @@
#endif
#include "resource.h" // main symbols
#include "DebugConsumer.h"
#include "LoggingConsumer.h"
// CSiaDriveApp:
@@ -25,8 +27,13 @@ public:
virtual BOOL InitInstance();
// Implementation
DECLARE_MESSAGE_MAP()
private:
#ifdef _DEBUG
static const Sia::Api::CDebugConsumer _debugConsumer;
#endif
static const Sia::Api::CLoggingConsumer _loggingConsumer;
};
extern CSiaDriveApp theApp;

View File

@@ -78,7 +78,7 @@ namespace UnitTests
}
};
TEST_CLASS(UnitTests)
TEST_CLASS(UploadManagerTest)
{
private:
const SiaHostConfig hostConfig = { L"127.0.0.1", 9988, TEST_SERVER_VERSION };
@@ -108,7 +108,7 @@ namespace UnitTests
CEventSystem::EventSystem.Stop();
}
TEST_METHOD(AddOrUpdateNoExisting)
TEST_METHOD(AddNewFile)
{
siad->Start(SiadTestType::UploadFile);
try
@@ -154,7 +154,7 @@ namespace UnitTests
}
};
std::unique_ptr<CMockSiad> UnitTests::siad;
CDebugConsumer UnitTests::_debugConsumer;
CEventAccumulator UnitTests::_eventAccumulator;
std::unique_ptr<CMockSiad> UploadManagerTest::siad;
CDebugConsumer UploadManagerTest::_debugConsumer;
CEventAccumulator UploadManagerTest::_eventAccumulator;
}