Index: src/ch/MainWnd.cpp =================================================================== diff -u -rb1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0 -r1342b18babc7e88850e74f46cb473a737a68f28a --- src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision b1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0) +++ src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision 1342b18babc7e88850e74f46cb473a737a68f28a) @@ -189,11 +189,11 @@ CString strTasksDir = GetTasksDirectory(); CString strTMPath = strTasksDir + _T("tasks.sqlite"); - chcore::TTaskManagerSerializerPtr spSerializer(new chcore::TTaskManagerSerializer(chcore::PathFromString(strTMPath), chcore::PathFromString(strTasksDir))); - m_spTasks.reset(new chcore::TTaskManager(spSerializer)); + chcore::TTaskManagerSerializerPtr spSerializer(new chcore::TTaskManagerSerializer( + chcore::PathFromString(strTMPath), + chcore::PathFromString(strTasksDir))); - // initialize CTaskArray - m_spTasks->Create(m_pFeedbackFactory); + m_spTasks.reset(new chcore::TTaskManager(spSerializer, m_pFeedbackFactory)); // load last state LOG_INFO(_T("Loading existing tasks...")); Index: src/libchcore/ITaskManagerSerializer.h =================================================================== diff -u -rb1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0 -r1342b18babc7e88850e74f46cb473a737a68f28a --- src/libchcore/ITaskManagerSerializer.h (.../ITaskManagerSerializer.h) (revision b1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0) +++ src/libchcore/ITaskManagerSerializer.h (.../ITaskManagerSerializer.h) (revision 1342b18babc7e88850e74f46cb473a737a68f28a) @@ -30,11 +30,12 @@ public: virtual ~ITaskManagerSerializer() {} - virtual void Setup() = 0; virtual void Store(const TTaskInfoContainer& tTasksInfo) = 0; virtual void Load(TTaskInfoContainer& tTasksInfo) = 0; - virtual ITaskSerializerPtr CreateTaskSerializer(const TSmartPath& pathSerialize) = 0; + virtual ITaskSerializerPtr CreateExistingTaskSerializer(const TSmartPath& pathSerialize) = 0; + virtual ITaskSerializerPtr CreateNewTaskSerializer(const TString& strTaskUuid) = 0; + virtual void RemoveTaskSerializer(const ITaskSerializerPtr& spTaskSerializer) = 0; }; typedef boost::shared_ptr ITaskManagerSerializerPtr; Index: src/libchcore/ITaskSerializer.h =================================================================== diff -u -rb1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0 -r1342b18babc7e88850e74f46cb473a737a68f28a --- src/libchcore/ITaskSerializer.h (.../ITaskSerializer.h) (revision b1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0) +++ src/libchcore/ITaskSerializer.h (.../ITaskSerializer.h) (revision 1342b18babc7e88850e74f46cb473a737a68f28a) @@ -29,8 +29,7 @@ public: virtual ~ITaskSerializer() {} - virtual TSmartPath GetPath() const = 0; - virtual void Setup() = 0; + virtual TSmartPath GetLocation() const = 0; }; typedef boost::shared_ptr ITaskSerializerPtr; Index: src/libchcore/TPath.cpp =================================================================== diff -u -rf18d23588f370de68d37adb285dcf5e046a8d37c -r1342b18babc7e88850e74f46cb473a737a68f28a --- src/libchcore/TPath.cpp (.../TPath.cpp) (revision f18d23588f370de68d37adb285dcf5e046a8d37c) +++ src/libchcore/TPath.cpp (.../TPath.cpp) (revision 1342b18babc7e88850e74f46cb473a737a68f28a) @@ -486,6 +486,23 @@ return false; } +bool TSmartPath::MakeAbsolutePath(const TSmartPath& rReferenceBasePath) +{ + if(!IsRelativePath()) + return false; + + bool bHasSeparator = rReferenceBasePath.EndsWithSeparator(); + if(!bHasSeparator) + PrependSeparatorIfDoesNotExist(); + else + StripSeparatorAtFront(); + + PrepareToWrite(); + m_pPath->m_strPath = rReferenceBasePath.ToString() + m_pPath->m_strPath; + + return true; +} + // ============================================================================ /// TSmartPath::AppendIfNotExists /// @date 2009/11/29 @@ -1130,6 +1147,11 @@ return (wchSeparator == _T('\\') || wchSeparator == _T('/')); } +bool TSmartPath::IsRelativePath() const +{ + return !HasDrive() && !HasServerName(); +} + // ============================================================================ /// chcore::PathFromString /// @date 2010/10/12 Index: src/libchcore/TPath.h =================================================================== diff -u -rf18d23588f370de68d37adb285dcf5e046a8d37c -r1342b18babc7e88850e74f46cb473a737a68f28a --- src/libchcore/TPath.h (.../TPath.h) (revision f18d23588f370de68d37adb285dcf5e046a8d37c) +++ src/libchcore/TPath.h (.../TPath.h) (revision 1342b18babc7e88850e74f46cb473a737a68f28a) @@ -97,11 +97,13 @@ bool IsChildOf(const TSmartPath& rPath, bool bCaseSensitive = DefaultCaseSensitivity) const; bool MakeRelativePath(const TSmartPath& rReferenceBasePath, bool bCaseSensitive = DefaultCaseSensitivity); + bool MakeAbsolutePath(const TSmartPath& rReferenceBasePath); void AppendIfNotExists(const wchar_t* pszPostfix, bool bCaseSensitive = DefaultCaseSensitivity); void CutIfExists(const wchar_t* pszPostfix, bool bCaseSensitive = DefaultCaseSensitivity); bool IsNetworkPath() const; + bool IsRelativePath() const; bool IsDrive() const; bool HasDrive() const; Index: src/libchcore/TSerializerVersion.cpp =================================================================== diff -u -rb1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0 -r1342b18babc7e88850e74f46cb473a737a68f28a --- src/libchcore/TSerializerVersion.cpp (.../TSerializerVersion.cpp) (revision b1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0) +++ src/libchcore/TSerializerVersion.cpp (.../TSerializerVersion.cpp) (revision 1342b18babc7e88850e74f46cb473a737a68f28a) @@ -30,7 +30,8 @@ using namespace sqlite; TSerializerVersion::TSerializerVersion(const TSQLiteDatabasePtr& spDatabase) : - m_spDatabase(spDatabase) + m_spDatabase(spDatabase), + m_bSetupExecuted(false) { if(!spDatabase) THROW_SERIALIZER_EXCEPTION(eErr_InvalidArgument, _T("No database provided")); @@ -42,6 +43,9 @@ void TSerializerVersion::Setup() { + if(m_bSetupExecuted) + return; + TSQLiteTransaction tTransaction(m_spDatabase); TSQLiteStatement tStatement(m_spDatabase); @@ -64,10 +68,14 @@ } tTransaction.Commit(); + + m_bSetupExecuted = true; } int TSerializerVersion::GetVersion() { + Setup(); + TSQLiteTransaction tTransaction(m_spDatabase); TSQLiteStatement tStatement(m_spDatabase); @@ -85,6 +93,8 @@ void TSerializerVersion::SetVersion(int iNewVersion) { + Setup(); + TSQLiteTransaction tTransaction(m_spDatabase); TSQLiteStatement tStatement(m_spDatabase); Index: src/libchcore/TSerializerVersion.h =================================================================== diff -u -rb1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0 -r1342b18babc7e88850e74f46cb473a737a68f28a --- src/libchcore/TSerializerVersion.h (.../TSerializerVersion.h) (revision b1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0) +++ src/libchcore/TSerializerVersion.h (.../TSerializerVersion.h) (revision 1342b18babc7e88850e74f46cb473a737a68f28a) @@ -30,16 +30,18 @@ TSerializerVersion(const sqlite::TSQLiteDatabasePtr& spDatabase); ~TSerializerVersion(); - void Setup(); - int GetVersion(); void SetVersion(int iNewVersion); +protected: + void Setup(); + private: #pragma warning(push) #pragma warning(disable: 4251) sqlite::TSQLiteDatabasePtr m_spDatabase; #pragma warning(pop) + bool m_bSetupExecuted; }; END_CHCORE_NAMESPACE Index: src/libchcore/TTask.cpp =================================================================== diff -u -r9ba9390b8f79c7a3fd1f9d6d9e92038d92222621 -r1342b18babc7e88850e74f46cb473a737a68f28a --- src/libchcore/TTask.cpp (.../TTask.cpp) (revision 9ba9390b8f79c7a3fd1f9d6d9e92038d92222621) +++ src/libchcore/TTask.cpp (.../TTask.cpp) (revision 1342b18babc7e88850e74f46cb473a737a68f28a) @@ -623,11 +623,6 @@ return m_tLocalStats.IsRunning(); } -TSmartPath TTask::GetSerializerPath() const -{ - return m_spSerializer->GetPath(); -} - chcore::TSmartPath TTask::GetLogPath() const { return m_pathLog; @@ -638,4 +633,9 @@ m_pathLog = pathLog; } +chcore::ITaskSerializerPtr TTask::GetSerializer() const +{ + return m_spSerializer; +} + END_CHCORE_NAMESPACE Index: src/libchcore/TTask.h =================================================================== diff -u -r9ba9390b8f79c7a3fd1f9d6d9e92038d92222621 -r1342b18babc7e88850e74f46cb473a737a68f28a --- src/libchcore/TTask.h (.../TTask.h) (revision 9ba9390b8f79c7a3fd1f9d6d9e92038d92222621) +++ src/libchcore/TTask.h (.../TTask.h) (revision 1342b18babc7e88850e74f46cb473a737a68f28a) @@ -122,8 +122,9 @@ void RequestStopThread(); static void OnCfgOptionChanged(const TStringSet& rsetChanges, void* pParam); - TSmartPath GetSerializerPath() const; + ITaskSerializerPtr GetSerializer() const; + private: #pragma warning(push) #pragma warning(disable: 4251) Index: src/libchcore/TTaskInfo.cpp =================================================================== diff -u -rb1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0 -r1342b18babc7e88850e74f46cb473a737a68f28a --- src/libchcore/TTaskInfo.cpp (.../TTaskInfo.cpp) (revision b1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0) +++ src/libchcore/TTaskInfo.cpp (.../TTaskInfo.cpp) (revision 1342b18babc7e88850e74f46cb473a737a68f28a) @@ -31,7 +31,7 @@ TTaskInfoEntry::TTaskInfoEntry(taskid_t tTaskID, const TSmartPath& pathTask, int iOrder, const TTaskPtr& spTask, int iModification /*= eMod_None*/) : m_tTaskID(tTaskID), - m_pathTask(pathTask), + m_pathSerializeLocation(pathTask), m_iOrder(iOrder), m_spTask(spTask), m_iModificationType(iModification) @@ -48,15 +48,15 @@ m_tTaskID = tTaskID; } -TSmartPath TTaskInfoEntry::GetTaskPath() const +TSmartPath TTaskInfoEntry::GetTaskSerializeLocation() const { - return m_pathTask; + return m_pathSerializeLocation; } -void TTaskInfoEntry::SetTaskPath(const TSmartPath& strTaskPath) +void TTaskInfoEntry::SetTaskSerializeLocation(const TSmartPath& strTaskPath) { SetModification(eMod_TaskPath, eMod_TaskPath); - m_pathTask = strTaskPath; + m_pathSerializeLocation = strTaskPath; } TTaskPtr TTaskInfoEntry::GetTask() const Index: src/libchcore/TTaskInfo.h =================================================================== diff -u -rb1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0 -r1342b18babc7e88850e74f46cb473a737a68f28a --- src/libchcore/TTaskInfo.h (.../TTaskInfo.h) (revision b1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0) +++ src/libchcore/TTaskInfo.h (.../TTaskInfo.h) (revision 1342b18babc7e88850e74f46cb473a737a68f28a) @@ -48,8 +48,8 @@ taskid_t GetTaskID() const; void SetTaskID(taskid_t tTaskID); - TSmartPath GetTaskPath() const; - void SetTaskPath(const TSmartPath& pathTask); + TSmartPath GetTaskSerializeLocation() const; + void SetTaskSerializeLocation(const TSmartPath& pathTask); TTaskPtr GetTask() const; void SetTask(const TTaskPtr& spTask); @@ -66,7 +66,7 @@ private: taskid_t m_tTaskID; - TSmartPath m_pathTask; + TSmartPath m_pathSerializeLocation; #pragma warning(push) #pragma warning(disable:4251) TTaskPtr m_spTask; Index: src/libchcore/TTaskManager.cpp =================================================================== diff -u -rb1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0 -r1342b18babc7e88850e74f46cb473a737a68f28a --- src/libchcore/TTaskManager.cpp (.../TTaskManager.cpp) (revision b1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0) +++ src/libchcore/TTaskManager.cpp (.../TTaskManager.cpp) (revision 1342b18babc7e88850e74f46cb473a737a68f28a) @@ -20,54 +20,37 @@ #include "TTaskManager.h" #include "TTask.h" -#include -#include "../libicpf/exception.h" -#include "TLogger.h" -#include #include "TTaskStatsSnapshot.h" #include "TTaskManagerStatsSnapshot.h" #include "TCoreException.h" #include "ErrorCodes.h" #include "TTaskInfo.h" -#include -#include -#include -#include BEGIN_CHCORE_NAMESPACE //////////////////////////////////////////////////////////////////////////////// // TTaskManager members -TTaskManager::TTaskManager(const ITaskManagerSerializerPtr& spSerializer) : - m_piFeedbackFactory(NULL), +TTaskManager::TTaskManager(const ITaskManagerSerializerPtr& spSerializer, IFeedbackHandlerFactory* piFeedbackHandlerFactory) : m_stNextTaskID(NoTaskID + 1), - m_spSerializer(spSerializer) + m_spSerializer(spSerializer), + m_piFeedbackFactory(piFeedbackHandlerFactory) { + if(!piFeedbackHandlerFactory) + THROW_CORE_EXCEPTION(eErr_InvalidPointer); } TTaskManager::~TTaskManager() { // NOTE: do not delete the feedback factory, since we are not responsible for releasing it } -void TTaskManager::Create(IFeedbackHandlerFactory* piFeedbackHandlerFactory) -{ - BOOST_ASSERT(piFeedbackHandlerFactory); - - m_piFeedbackFactory = piFeedbackHandlerFactory; -} - TTaskPtr TTaskManager::CreateTask(const TTaskDefinition& tTaskDefinition) { - TString strUuid = GetUuid(); - TSmartPath pathTaskSerializer = CreateTaskSerializePath(strUuid); - TSmartPath pathTaskLog = CreateTaskLogPath(strUuid); - IFeedbackHandler* piHandler = CreateNewFeedbackHandler(); - ITaskSerializerPtr spSerializer = m_spSerializer->CreateTaskSerializer(pathTaskSerializer); + ITaskSerializerPtr spSerializer = m_spSerializer->CreateNewTaskSerializer(tTaskDefinition.GetTaskName()); TTaskPtr spTask(new TTask(spSerializer, piHandler)); - spTask->SetLogPath(pathTaskLog); + spTask->SetLogPath(CreateTaskLogPath(tTaskDefinition.GetTaskName())); spTask->SetTaskDefinition(tTaskDefinition); Add(spTask); @@ -128,7 +111,7 @@ iOrder = rEntry.GetOrder() + 1; } - m_tTasks.Add(m_stNextTaskID++, spNewTask->GetSerializerPath(), iOrder, spNewTask); + m_tTasks.Add(m_stNextTaskID++, spNewTask->GetSerializer()->GetLocation(), iOrder, spNewTask); spNewTask->OnRegisterTask(); } @@ -151,7 +134,7 @@ void TTaskManager::RemoveAllFinished() { - std::vector vTasksToRemove; + std::vector vTasksSerializersToRemove; // separate scope for locking { @@ -170,16 +153,16 @@ spTask->OnUnregisterTask(); - vTasksToRemove.push_back(rEntry.GetTaskPath()); + vTasksSerializersToRemove.push_back(spTask->GetSerializer()); m_tTasks.RemoveAt(stIndex); } } } - BOOST_FOREACH(TSmartPath& spTaskPath, vTasksToRemove) + BOOST_FOREACH(ITaskSerializerPtr& spSerializer, vTasksSerializersToRemove) { // delete associated files - DeleteFile(spTaskPath.ToString()); + m_spSerializer->RemoveTaskSerializer(spSerializer); } } @@ -204,7 +187,7 @@ spTask->OnUnregisterTask(); - vTasksToRemove.push_back(rEntry.GetTaskPath()); + vTasksToRemove.push_back(rEntry.GetTaskSerializeLocation()); m_tTasks.RemoveAt(stIndex); break; } @@ -453,7 +436,6 @@ spTask->Store(); } - } void TTaskManager::Load() @@ -477,7 +459,7 @@ if(!rEntry.GetTask()) { IFeedbackHandler* piHandler = CreateNewFeedbackHandler(); - ITaskSerializerPtr spSerializer = m_spSerializer->CreateTaskSerializer(rEntry.GetTaskPath()); + ITaskSerializerPtr spSerializer = m_spSerializer->CreateExistingTaskSerializer(rEntry.GetTaskSerializeLocation()); TTaskPtr spTask(new TTask(spSerializer, piHandler)); spTask->Load(); @@ -486,24 +468,10 @@ } } } - -TString TTaskManager::GetUuid() +TSmartPath TTaskManager::CreateTaskLogPath(const TString& strTaskUuid) const { - boost::uuids::random_generator gen; - boost::uuids::uuid u = gen(); - return boost::lexical_cast(u).c_str(); -} - -TSmartPath TTaskManager::CreateTaskLogPath(const TString& strUuid) const -{ - TSmartPath pathLog = m_pathLogDir + PathFromString(TString(_T("Task-")) + strUuid + _T(".log")); + TSmartPath pathLog = m_pathLogDir + PathFromString(TString(_T("Task-")) + strTaskUuid + _T(".log")); return pathLog; } -chcore::TSmartPath TTaskManager::CreateTaskSerializePath(const TString& strUuid) const -{ - TSmartPath pathLog = m_pathLogDir + PathFromString(TString(_T("Task-")) + strUuid + _T(".sqlite")); - return pathLog; -} - END_CHCORE_NAMESPACE Index: src/libchcore/TTaskManager.h =================================================================== diff -u -rb1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0 -r1342b18babc7e88850e74f46cb473a737a68f28a --- src/libchcore/TTaskManager.h (.../TTaskManager.h) (revision b1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0) +++ src/libchcore/TTaskManager.h (.../TTaskManager.h) (revision 1342b18babc7e88850e74f46cb473a737a68f28a) @@ -37,11 +37,9 @@ class LIBCHCORE_API TTaskManager { public: - TTaskManager(const ITaskManagerSerializerPtr& spSerializer); + TTaskManager(const ITaskManagerSerializerPtr& spSerializer, IFeedbackHandlerFactory* piFeedbackHandlerFactory); ~TTaskManager(); - void Create(IFeedbackHandlerFactory* piFeedbackHandlerFactory); - void Store(); void Load(); @@ -80,9 +78,7 @@ IFeedbackHandler* CreateNewFeedbackHandler(); - TSmartPath CreateTaskLogPath(const TString& strUuid) const; - TSmartPath CreateTaskSerializePath(const TString& strUuid) const; - static TString GetUuid(); + TSmartPath CreateTaskLogPath(const TString& strTaskUuid) const; private: #pragma warning(push) Index: src/libchcore/TTaskManagerSerializer.cpp =================================================================== diff -u -rb1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0 -r1342b18babc7e88850e74f46cb473a737a68f28a --- src/libchcore/TTaskManagerSerializer.cpp (.../TTaskManagerSerializer.cpp) (revision b1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0) +++ src/libchcore/TTaskManagerSerializer.cpp (.../TTaskManagerSerializer.cpp) (revision 1342b18babc7e88850e74f46cb473a737a68f28a) @@ -26,6 +26,10 @@ #include "TTaskSerializer.h" #include "TTaskInfo.h" #include +#include +#include +#include +#include BEGIN_CHCORE_NAMESPACE @@ -44,12 +48,14 @@ void TTaskManagerSerializer::Setup() { + if(m_bSetupExecuted) + return; + TSQLiteDatabasePtr spDatabase = GetDatabase(); TSQLiteTransaction tTransaction(spDatabase); // check version of the database TSerializerVersion tVersion(spDatabase); - tVersion.Setup(); // if version is 0, then this is the fresh database with (almost) no tables inside if(tVersion.GetVersion() == 0) @@ -69,8 +75,7 @@ void TTaskManagerSerializer::Store(const TTaskInfoContainer& tTasksInfo) { - if(!m_bSetupExecuted) - Setup(); + Setup(); TSQLiteDatabasePtr spDatabase(GetDatabase()); TSQLiteTransaction tTransaction(spDatabase); @@ -98,11 +103,16 @@ for(size_t stIndex = 0; stIndex < tTasksInfo.GetCount(); ++stIndex) { const TTaskInfoEntry& rEntry = tTasksInfo.GetAt(stIndex); + + // store as relative path if possible + TSmartPath pathRelative(rEntry.GetTaskSerializeLocation()); + pathRelative.MakeRelativePath(m_pathTasksDir); + if(rEntry.IsAdded()) { tStatement.BindValue(1, rEntry.GetTaskID()); tStatement.BindValue(2, rEntry.GetOrder()); - tStatement.BindValue(3, rEntry.GetTaskPath().ToString()); + tStatement.BindValue(3, pathRelative.ToString()); tStatement.Step(); } } @@ -119,9 +129,12 @@ const TTaskInfoEntry& rEntry = tTasksInfo.GetAt(stIndex); if(rEntry.IsModified()) { + TSmartPath pathRelative(rEntry.GetTaskSerializeLocation()); + pathRelative.MakeRelativePath(m_pathTasksDir); + tStatement.BindValue(1, rEntry.GetTaskID()); tStatement.BindValue(2, rEntry.GetOrder()); - tStatement.BindValue(3, rEntry.GetTaskPath().ToString()); + tStatement.BindValue(3, pathRelative.ToString()); tStatement.Step(); } } @@ -132,8 +145,7 @@ void TTaskManagerSerializer::Load(TTaskInfoContainer& tTasksInfo) { - if(!m_bSetupExecuted) - Setup(); + Setup(); tTasksInfo.Clear(); @@ -147,9 +159,10 @@ { taskid_t tTaskID = boost::numeric_cast(tStatement.GetUInt64(0)); int iOrder = tStatement.GetInt(1); - TString strPath = tStatement.GetText(2); + TSmartPath pathTask = PathFromWString(tStatement.GetText(2)); + pathTask.MakeAbsolutePath(m_pathTasksDir); - tTasksInfo.Add(tTaskID, PathFromWString(strPath), iOrder, TTaskPtr()); + tTasksInfo.Add(tTaskID, pathTask, iOrder, TTaskPtr()); } } @@ -161,10 +174,39 @@ return m_spDatabase; } -chcore::ITaskSerializerPtr TTaskManagerSerializer::CreateTaskSerializer(const TSmartPath& pathSerialize) +chcore::ITaskSerializerPtr TTaskManagerSerializer::CreateExistingTaskSerializer(const TSmartPath& pathSerialize) { - TTaskSerializerPtr spTaskSerializer(new TTaskSerializer(pathSerialize)); + TSmartPath pathReal = pathSerialize; + if(pathSerialize.IsEmpty()) + pathReal = m_pathTasksDir + PathFromString(TString(_T("Task-") + GetUuid() + _T(".sqlite"))); + + TTaskSerializerPtr spTaskSerializer(new TTaskSerializer(pathReal)); return spTaskSerializer; } +chcore::ITaskSerializerPtr TTaskManagerSerializer::CreateNewTaskSerializer(const TString& strTaskUuid) +{ + TString strRealTaskUuid = strTaskUuid; + if(strRealTaskUuid.IsEmpty()) + strRealTaskUuid = GetUuid(); + + TSmartPath pathReal = m_pathTasksDir + PathFromString(TString(_T("Task-") + strRealTaskUuid + _T(".sqlite"))); + + TTaskSerializerPtr spTaskSerializer(new TTaskSerializer(pathReal)); + return spTaskSerializer; +} + +TString TTaskManagerSerializer::GetUuid() +{ + boost::uuids::random_generator gen; + boost::uuids::uuid u = gen(); + return boost::lexical_cast(u).c_str(); +} + +void TTaskManagerSerializer::RemoveTaskSerializer(const ITaskSerializerPtr& spTaskSerializer) +{ + TSmartPath pathTask = spTaskSerializer->GetLocation(); + DeleteFile(pathTask.ToString()); +} + END_CHCORE_NAMESPACE Index: src/libchcore/TTaskManagerSerializer.h =================================================================== diff -u -rb1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0 -r1342b18babc7e88850e74f46cb473a737a68f28a --- src/libchcore/TTaskManagerSerializer.h (.../TTaskManagerSerializer.h) (revision b1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0) +++ src/libchcore/TTaskManagerSerializer.h (.../TTaskManagerSerializer.h) (revision 1342b18babc7e88850e74f46cb473a737a68f28a) @@ -32,18 +32,22 @@ { public: TTaskManagerSerializer(const TSmartPath& pathDB, const TSmartPath& pathTasksDir); - ~TTaskManagerSerializer(); + virtual ~TTaskManagerSerializer(); - virtual ITaskSerializerPtr CreateTaskSerializer(const TSmartPath& pathSerialize); + virtual void Store(const TTaskInfoContainer& tTasksInfo); + virtual void Load(TTaskInfoContainer& tTasksInfo); - virtual void Setup(); // creates or migrates tables + virtual ITaskSerializerPtr CreateExistingTaskSerializer(const TSmartPath& pathSerialize); + virtual ITaskSerializerPtr CreateNewTaskSerializer(const TString& strTaskUuid); - void Store(const TTaskInfoContainer& tTasksInfo); - void Load(TTaskInfoContainer& tTasksInfo); + virtual void RemoveTaskSerializer(const ITaskSerializerPtr& spTaskSerializer); protected: sqlite::TSQLiteDatabasePtr GetDatabase(); + void Setup(); // creates or migrates tables + static TString GetUuid(); + private: TSmartPath m_pathDB; TSmartPath m_pathTasksDir; Index: src/libchcore/TTaskSerializer.cpp =================================================================== diff -u -rb1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0 -r1342b18babc7e88850e74f46cb473a737a68f28a --- src/libchcore/TTaskSerializer.cpp (.../TTaskSerializer.cpp) (revision b1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0) +++ src/libchcore/TTaskSerializer.cpp (.../TTaskSerializer.cpp) (revision 1342b18babc7e88850e74f46cb473a737a68f28a) @@ -33,7 +33,7 @@ } -chcore::TSmartPath chcore::TTaskSerializer::GetPath() const +chcore::TSmartPath chcore::TTaskSerializer::GetLocation() const { return m_pathDB; } Index: src/libchcore/TTaskSerializer.h =================================================================== diff -u -rb1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0 -r1342b18babc7e88850e74f46cb473a737a68f28a --- src/libchcore/TTaskSerializer.h (.../TTaskSerializer.h) (revision b1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0) +++ src/libchcore/TTaskSerializer.h (.../TTaskSerializer.h) (revision 1342b18babc7e88850e74f46cb473a737a68f28a) @@ -33,7 +33,7 @@ TTaskSerializer(const TSmartPath& pathDB); ~TTaskSerializer(); - virtual TSmartPath GetPath() const; + virtual TSmartPath GetLocation() const; virtual void Setup();