// ============================================================================ // Copyright (C) 2001-2016 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 "TTaskManagerWrapper.h" #include "resource.h" #include "../libictranslate/ResourceManager.h" #include "../libchcore/TBaseException.h" #include "CfgProperties.h" #include "ch.h" #include "../libchengine/TConfigSerializers.h" TTaskManagerWrapper::TTaskManagerWrapper(const chengine::TTaskManagerPtr& spTaskManager) : m_spTaskManager(spTaskManager) { } chengine::TTaskPtr TTaskManagerWrapper::CreateTask(chengine::TTaskDefinition& rTaskDefinition) { UpdateFileNamingFormat(rTaskDefinition.GetConfiguration()); CString strMessage; try { // create task with the above definition chengine::TTaskPtr spTask = m_spTaskManager->CreateTask(rTaskDefinition); // add to task list and start processing spTask->BeginProcessing(); return spTask; } catch(const chcore::TBaseException& e) { const size_t stMaxError = 1024; wchar_t szError[ stMaxError ]; e.GetErrorInfo(szError, stMaxError); strMessage = szError; } catch(const std::exception& e) { strMessage = e.what(); } ictranslate::CResourceManager& rResourceManager = ictranslate::CResourceManager::Acquire(); ictranslate::CFormat fmt; fmt.SetFormat(rResourceManager.LoadString(IDS_TASK_CREATE_FAILED)); fmt.SetParam(_T("%reason"), strMessage); AfxMessageBox(fmt, MB_OK | MB_ICONERROR); return nullptr; } void TTaskManagerWrapper::UpdateFileNamingFormat(chengine::TConfig& rTaskConfig) { ictranslate::CResourceManager& rResourceManager = ictranslate::CResourceManager::Acquire(); CString strFirstCopyFormat; CString strSubsequentCopyFormat; bool bUseCustomNaming = GetPropValue(GetConfig()); if(bUseCustomNaming) { strFirstCopyFormat = GetPropValue(GetConfig()); strSubsequentCopyFormat = GetPropValue(GetConfig()); } else { strFirstCopyFormat = rResourceManager.LoadString(IDS_FIRSTCOPY_STRING); strSubsequentCopyFormat = rResourceManager.LoadString(IDS_NEXTCOPY_STRING); } // load resource strings chengine::SetTaskPropValue(rTaskConfig, (PCTSTR)strFirstCopyFormat); chengine::SetTaskPropValue(rTaskConfig, (PCTSTR)strSubsequentCopyFormat); }