Index: src/libchcore/ErrorCodes.h =================================================================== diff -u -r5693271a6736f524997e3951fc7b7b6323bc6447 -rcdb4c898156398dd4f4bf8abd7c854eff42f6ae2 --- src/libchcore/ErrorCodes.h (.../ErrorCodes.h) (revision 5693271a6736f524997e3951fc7b7b6323bc6447) +++ src/libchcore/ErrorCodes.h (.../ErrorCodes.h) (revision cdb4c898156398dd4f4bf8abd7c854eff42f6ae2) @@ -69,6 +69,7 @@ eErr_CannotWriteArchive = 2506, eErr_InvalidSerializationData = 2507, eErr_CannotSetDatabaseOptions = 2508, + eErr_InvalidSerializer = 2509, // Filesystem errors (3000+) eErr_FixedDriveWithoutDriveLetter = 3000, Index: src/libchcore/ISerializerFactory.h =================================================================== diff -u -r30297d6aab17483da8e7b8323b4d17ff1a9f78d6 -rcdb4c898156398dd4f4bf8abd7c854eff42f6ae2 --- src/libchcore/ISerializerFactory.h (.../ISerializerFactory.h) (revision 30297d6aab17483da8e7b8323b4d17ff1a9f78d6) +++ src/libchcore/ISerializerFactory.h (.../ISerializerFactory.h) (revision cdb4c898156398dd4f4bf8abd7c854eff42f6ae2) @@ -28,16 +28,10 @@ class LIBCHCORE_API ISerializerFactory { public: - enum EObjectType - { - eObj_TaskManager, - eObj_Task - }; - -public: virtual ~ISerializerFactory(); - virtual ISerializerPtr CreateSerializer(EObjectType eObjType, const TString& strNameHint = _T(""), bool bForceRecreate = false) = 0; + virtual ISerializerPtr CreateTaskManagerSerializer(bool bForceRecreate = false) = 0; + virtual ISerializerPtr CreateTaskSerializer(const TString& strNameHint = _T(""), bool bForceRecreate = false) = 0; }; typedef boost::shared_ptr ISerializerFactoryPtr; Index: src/libchcore/TFakeFileSerializer.cpp =================================================================== diff -u --- src/libchcore/TFakeFileSerializer.cpp (revision 0) +++ src/libchcore/TFakeFileSerializer.cpp (revision cdb4c898156398dd4f4bf8abd7c854eff42f6ae2) @@ -0,0 +1,50 @@ +// ============================================================================ +// Copyright (C) 2001-2015 by Jozef Starosczyk +// ixen@copyhandler.com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ +#include "stdafx.h" +#include "TFakeFileSerializer.h" +#include "TCoreException.h" +#include "ErrorCodes.h" + +BEGIN_CHCORE_NAMESPACE + +TFakeFileSerializer::TFakeFileSerializer(const TSmartPath& rPath) : + m_pathFileSerializer(rPath) +{ +} + +TFakeFileSerializer::~TFakeFileSerializer() +{ +} + +chcore::TSmartPath TFakeFileSerializer::GetLocation() const +{ + return m_pathFileSerializer; +} + +chcore::ISerializerContainerPtr TFakeFileSerializer::GetContainer(const TString& /*strContainerName*/) +{ + throw TCoreException(eErr_InvalidSerializer, m_pathFileSerializer.ToString(), __LINE__, __FUNCTIONW__); +} + +void TFakeFileSerializer::Flush() +{ + throw TCoreException(eErr_InvalidSerializer, m_pathFileSerializer.ToString(), __LINE__, __FUNCTIONW__); +} + +END_CHCORE_NAMESPACE Index: src/libchcore/TFakeFileSerializer.h =================================================================== diff -u --- src/libchcore/TFakeFileSerializer.h (revision 0) +++ src/libchcore/TFakeFileSerializer.h (revision cdb4c898156398dd4f4bf8abd7c854eff42f6ae2) @@ -0,0 +1,48 @@ +// ============================================================================ +// Copyright (C) 2001-2015 by Jozef Starosczyk +// ixen@copyhandler.com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ +#ifndef __TFAKEFILESERIALIZER_H__ +#define __TFAKEFILESERIALIZER_H__ + +#include "libchcore.h" +#include "ISerializer.h" + +BEGIN_CHCORE_NAMESPACE + +class LIBCHCORE_API TFakeFileSerializer : public ISerializer +{ +public: + TFakeFileSerializer(const TSmartPath& rPath); + virtual ~TFakeFileSerializer(); + + TFakeFileSerializer(const TFakeFileSerializer& rSrc) = delete; + TFakeFileSerializer& operator=(const TFakeFileSerializer& rSrc) = delete; + + virtual TSmartPath GetLocation() const override; + virtual ISerializerContainerPtr GetContainer(const TString& strContainerName) override; + virtual void Flush() override; + +private: + TSmartPath m_pathFileSerializer; +}; + +typedef boost::shared_ptr TFakeFileSerializerPtr; + +END_CHCORE_NAMESPACE + +#endif Index: src/libchcore/TSQLiteSerializerFactory.cpp =================================================================== diff -u -r2fe97a93f21771d75901d4b6559057d1ea055104 -rcdb4c898156398dd4f4bf8abd7c854eff42f6ae2 --- src/libchcore/TSQLiteSerializerFactory.cpp (.../TSQLiteSerializerFactory.cpp) (revision 2fe97a93f21771d75901d4b6559057d1ea055104) +++ src/libchcore/TSQLiteSerializerFactory.cpp (.../TSQLiteSerializerFactory.cpp) (revision cdb4c898156398dd4f4bf8abd7c854eff42f6ae2) @@ -22,6 +22,7 @@ #include #include #include +#include #include "TSQLiteTaskSchema.h" #include "TSQLiteSerializer.h" #include "TSQLiteTaskManagerSchema.h" @@ -39,71 +40,60 @@ { } -ISerializerPtr TSQLiteSerializerFactory::CreateSerializer(EObjectType eObjType, const TString& strNameHint, bool bForceRecreate) +chcore::ISerializerPtr TSQLiteSerializerFactory::CreateTaskManagerSerializer(bool bForceRecreate) { - switch(eObjType) + TSmartPath pathTaskManager = m_pathSerializeDir + PathFromString(_T("tasks.sqlite")); + + if (bForceRecreate) { - case ISerializerFactory::eObj_Task: + if (!DeleteFile(pathTaskManager.ToString())) { - TString strName(strNameHint); - if(strName.IsEmpty()) - { - boost::uuids::random_generator gen; - boost::uuids::uuid u = gen(); - strName = boost::lexical_cast(u).c_str(); - } + DWORD dwLastError = GetLastError(); + if (dwLastError != ERROR_FILE_NOT_FOUND) + THROW_CORE_EXCEPTION_WIN32(eErr_CannotDeleteFile, dwLastError); + } + } - TSmartPath pathTask = PathFromWString(strName); - if(!pathTask.HasFileRoot()) - { - if(!strName.EndsWithNoCase(_T(".sqlite"))) - strName += _T(".sqlite"); + TSQLiteSerializerPtr spSerializer(boost::make_shared( + pathTaskManager, + boost::make_shared())); - pathTask = m_pathSerializeDir; - pathTask += PathFromWString(strName); - } + return spSerializer; +} - if(bForceRecreate) - { - if(!DeleteFile(pathTask.ToString())) - { - DWORD dwLastError = GetLastError(); - if(dwLastError != ERROR_FILE_NOT_FOUND) - THROW_CORE_EXCEPTION_WIN32(eErr_CannotDeleteFile, dwLastError); - } - } +chcore::ISerializerPtr TSQLiteSerializerFactory::CreateTaskSerializer(const TString& strNameHint, bool bForceRecreate) +{ + TString strName(strNameHint); + if (strName.IsEmpty()) + { + boost::uuids::random_generator gen; + boost::uuids::uuid u = gen(); + strName = boost::lexical_cast(u).c_str(); + } - TSQLiteSerializerPtr spSerializer(new TSQLiteSerializer( - pathTask, - TSQLiteTaskSchemaPtr(new TSQLiteTaskSchema))); + TSmartPath pathTask = PathFromWString(strName); + if (!pathTask.HasFileRoot()) + { + if (!strName.EndsWithNoCase(_T(".sqlite"))) + strName += _T(".sqlite"); - return spSerializer; - } + pathTask = m_pathSerializeDir; + pathTask += PathFromWString(strName); + } - case ISerializerFactory::eObj_TaskManager: + if (bForceRecreate) + { + if (!DeleteFile(pathTask.ToString())) { - TSmartPath pathTaskManager = m_pathSerializeDir + PathFromString(_T("tasks.sqlite")); - - if(bForceRecreate) - { - if(!DeleteFile(pathTaskManager.ToString())) - { - DWORD dwLastError = GetLastError(); - if(dwLastError != ERROR_FILE_NOT_FOUND) - THROW_CORE_EXCEPTION_WIN32(eErr_CannotDeleteFile, dwLastError); - } - } - - TSQLiteSerializerPtr spSerializer(new TSQLiteSerializer( - pathTaskManager, - TTaskManagerSchemaPtr(new TSQLiteTaskManagerSchema))); - - return spSerializer; + DWORD dwLastError = GetLastError(); + if (dwLastError != ERROR_FILE_NOT_FOUND) + THROW_CORE_EXCEPTION_WIN32(eErr_CannotDeleteFile, dwLastError); } - - default: - THROW_CORE_EXCEPTION(eErr_InvalidArgument); } + + TSQLiteSerializerPtr spSerializer(boost::make_shared(pathTask, boost::make_shared())); + + return spSerializer; } END_CHCORE_NAMESPACE Index: src/libchcore/TSQLiteSerializerFactory.h =================================================================== diff -u -r30297d6aab17483da8e7b8323b4d17ff1a9f78d6 -rcdb4c898156398dd4f4bf8abd7c854eff42f6ae2 --- src/libchcore/TSQLiteSerializerFactory.h (.../TSQLiteSerializerFactory.h) (revision 30297d6aab17483da8e7b8323b4d17ff1a9f78d6) +++ src/libchcore/TSQLiteSerializerFactory.h (.../TSQLiteSerializerFactory.h) (revision cdb4c898156398dd4f4bf8abd7c854eff42f6ae2) @@ -31,7 +31,8 @@ TSQLiteSerializerFactory(const TSmartPath& pathSerializeDir); virtual ~TSQLiteSerializerFactory(); - virtual ISerializerPtr CreateSerializer(EObjectType eObjType, const TString& strNameHint = _T(""), bool bForceRecreate = false); + virtual ISerializerPtr CreateTaskManagerSerializer(bool bForceRecreate = false) override; + virtual ISerializerPtr CreateTaskSerializer(const TString& strNameHint = _T(""), bool bForceRecreate = false) override; private: TSmartPath m_pathSerializeDir; Index: src/libchcore/TTaskManager.cpp =================================================================== diff -u -ra99c8baeb8f6c237603df46c0f5c4cf943152c09 -rcdb4c898156398dd4f4bf8abd7c854eff42f6ae2 --- src/libchcore/TTaskManager.cpp (.../TTaskManager.cpp) (revision a99c8baeb8f6c237603df46c0f5c4cf943152c09) +++ src/libchcore/TTaskManager.cpp (.../TTaskManager.cpp) (revision cdb4c898156398dd4f4bf8abd7c854eff42f6ae2) @@ -27,6 +27,7 @@ #include "TTaskInfo.h" #include #include "SerializerTrace.h" +#include "TFakeFileSerializer.h" BEGIN_CHCORE_NAMESPACE @@ -42,7 +43,7 @@ { if(!spFeedbackHandlerFactory || !spSerializerFactory) THROW_CORE_EXCEPTION(eErr_InvalidPointer); - m_spSerializer = m_spSerializerFactory->CreateSerializer(ISerializerFactory::eObj_TaskManager, _T(""), bForceRecreateSerializer); + m_spSerializer = m_spSerializerFactory->CreateTaskManagerSerializer(bForceRecreateSerializer); } TTaskManager::~TTaskManager() @@ -53,7 +54,7 @@ TTaskPtr TTaskManager::CreateTask(const TTaskDefinition& tTaskDefinition) { IFeedbackHandlerPtr spHandler = m_spFeedbackFactory->Create(); - ISerializerPtr spSerializer = m_spSerializerFactory->CreateSerializer(ISerializerFactory::eObj_Task, tTaskDefinition.GetTaskName()); + ISerializerPtr spSerializer = m_spSerializerFactory->CreateTaskSerializer(tTaskDefinition.GetTaskName()); TTaskPtr spTask(new TTask(spSerializer, spHandler)); spTask->SetLogPath(CreateTaskLogPath(tTaskDefinition.GetTaskName())); @@ -494,12 +495,23 @@ } } - typedef std::pair PairInfo; - BOOST_FOREACH(const PairInfo& rInfo, vObjects) + for(const auto& rInfo : vObjects) { IFeedbackHandlerPtr spHandler = m_spFeedbackFactory->Create(); - ISerializerPtr spSerializer(m_spSerializerFactory->CreateSerializer(ISerializerFactory::eObj_Task, rInfo.second.ToWString())); + ISerializerPtr spSerializer; + try + { + spSerializer = m_spSerializerFactory->CreateTaskSerializer(rInfo.second.ToWString()); + } + catch (const std::exception&) + { + // ignore the exception + } + + if (!spSerializer) + spSerializer = boost::make_shared(rInfo.second); + TTaskPtr spTask(new TTask(spSerializer, spHandler)); spTask->Load(); Index: src/libchcore/libchcore.vc120.vcxproj =================================================================== diff -u -r671f4b1792a20d98b186f4e0a9cc6a620dede019 -rcdb4c898156398dd4f4bf8abd7c854eff42f6ae2 --- src/libchcore/libchcore.vc120.vcxproj (.../libchcore.vc120.vcxproj) (revision 671f4b1792a20d98b186f4e0a9cc6a620dede019) +++ src/libchcore/libchcore.vc120.vcxproj (.../libchcore.vc120.vcxproj) (revision cdb4c898156398dd4f4bf8abd7c854eff42f6ae2) @@ -525,6 +525,7 @@ + @@ -685,6 +686,7 @@ true true + Index: src/libchcore/libchcore.vc120.vcxproj.filters =================================================================== diff -u -r671f4b1792a20d98b186f4e0a9cc6a620dede019 -rcdb4c898156398dd4f4bf8abd7c854eff42f6ae2 --- src/libchcore/libchcore.vc120.vcxproj.filters (.../libchcore.vc120.vcxproj.filters) (revision 671f4b1792a20d98b186f4e0a9cc6a620dede019) +++ src/libchcore/libchcore.vc120.vcxproj.filters (.../libchcore.vc120.vcxproj.filters) (revision cdb4c898156398dd4f4bf8abd7c854eff42f6ae2) @@ -54,6 +54,9 @@ {28670d3c-b5d8-4acb-91aa-c886efae641c} + + {9d121063-367c-4424-8009-12b3635e0fed} + @@ -338,6 +341,9 @@ Source Files\Feedback + + Source Files\Serialization\Fake + @@ -625,5 +631,8 @@ Source Files\Feedback + + Source Files\Serialization\Fake + \ No newline at end of file