SlideShare a Scribd company logo
1 of 27
DM
修改Message(Old)
先淺談舊架構
參考DM Server設計
舊架構的一支Message會這樣執行
每一支Message通常都有三個部
份,依序通過這三個類別
1. SuServiceKernel
2. ServiceImpl
3. ServiceTransactions
三個部份各別的作用
ServiceKernel
Request Xml -> Struct
Struct -> Reply Xml。
一般會針對各別的Message定義,而各別的去宣告不同的struct。
ServiceImpl
不同的Message在此大多都是重複的程式碼
宣告交易物件用try-catch將交易包起來,呼叫Transaction(用MARCO實作)
提交或取消交易(用MARCO實作)
ServiceTransactions
Struct -> Database
處理資料的邏輯與資料庫存、加入交易(用MARCO實作)取相關的code。
找找
實作檔案
Visual Studio 2005的Solution Explorer
Visual Studio 2005的Solution Explorer
DMServer>ConstDefine
SUMessageDefine.h/.cpp Message Id字串定義
SUMessageDefine_ModuleName.cpp Message Id字串定義
SystemDefine.h/SystemDefine.cpp 其它系統會用上的字串定義
SystemTemplate.h 所有舊架構的Template函數
SuMsgErrorCode.h/.cpp error code的宣告與定義(與新架構共用)
Visual Studio 2005的Solution Explorer
DMServer>ConstDefine>FablinkKgs
fKDataTime 特別為Fablink加強的KDataTime版本(與新架構共用)
fSysUtils 特別為Fablink加強的SysUtils版本(與新架構共用)
Visual Studio 2005的Solution Explorer
DMServer>Impl>oldMessage
DoStructDefine 舊架構專用的Struct(Xml -> Struct的Struce定義)
各式各樣的…struct.h(不一定有.cpp)
ImplMarco.h 舊架構專用的MARCO
SuUtility.h/.cpp 舊架構專用拿來讀取.config檔的函數,初始化時期就出現成
全域物件
Visual Studio 2005的Solution Explorer
DMServer>Impl>oldMessage
如右圖的三個區塊
• 一個.h檔
• 一個基本功能的.cpp檔
• 各別模組功能的.cpp檔
Visual Studio 2005的Solution Explorer
報工相關獨立出來的函數定義
• ServiceTransactionDiapatchLotSerial_Id2TableObj.cpp
• ServiceTransactionWriteWipDataByCount.cpp
因為函數長度
太長了
舊架構程式碼分佈
三層架構
我也不知道為什
麼要分三層
SuServiceKernel的code
(MessageId = ModuleName_MessageNameRequest)
void SuServiceKernel::DoMessageId(KFabLinkTransaction &m_Transaction)
{
//Define Reply string
MARCO_SECONDARY_SERVICE_START()
{
//Struct1 input;
//Struct2 output;
//xml -> struct
cv_ServiceImpl.ProcessFR_ModifyToolRequest(input, output);
// struct -> xml
m_Transaction.Secondary.Body.ItemsByName["ReturnCode"].AsI4 = output.ReturnCode;
m_Transaction.Secondary.Body.ItemsByName["ReturnMessage"].AsString = output.ReturnMessage;
}
MARCO_SECONDARY_SERVICE_COMPLETE()
}
KServiceImpl的code
(MessageId = ModuleName_MessageNameRequest)
void KServiceImpl::ProcessMessageId(Struct1 &m_Data, Struct2 &m_ResultData/*out*/)
{
MARCO_FABLINK_BEGIN_TRANSACTION(tx_object, tx_result, tx_error_mesage, execute_result_code)
{
execute_result_code = cv_ServiceTransactions.ProcessProcessMessageId (
m_Data, /*input*/
m_ResultData, /*output*/
tx_object,
tx_result,
tx_error_mesage
);
if ( execute_result_code != ERROR_FABLINK_SUCCESS ) //非Query的Message要加這一段
{
MARCO_FABLINK_ROLLBACK_TRANSACTION(tx_object, tx_result, tx_error_mesage);
}
}
MARCO_FABLINK_END_TRANSACTION(tx_object, tx_result, tx_error_mesage, execute_result_code)
m_ResultData.ReturnCode = execute_result_code;
m_ResultData.ReturnMessage = ErrCodeMap::ErrCodeToMsg[execute_result_code];
}
KServiceTransactions的code
(MessageId = ModuleName_MessageNameRequest)
int KServiceTransactions::ProcessMessageId(Struct1 &m_Data, Struct2 &m_ResultData/*out*/,
MARCO_DECLARE_SUB_TRANSACTION(tx_object, tx_result, tx_error_mesage))
{
MARCO_FABLINK_CHECK_ROLLBACK(tx_object, tx_result, tx_error_mesage);
int result_code = ERROR_FABLINK_SUCCESS;
// do any thing
return result_code;
}
だから
修改的時候…
(只會遇到修改)
修改Xml
ServiceKernel
修改Xml -> Struct的地方(查詢條件需要的話)
修改Struct -> Xml的地方(回傳內容需要的話)
ServiceImpl
不改
ServiceTransactions
視情況
修改邏輯
ServiceKernel
視情況
ServiceImpl
不改
ServiceTransactions
主要改這裡
資料庫加欄位
ServiceKernel
修改Xml -> Struct的地方(查詢條件需要的話)
修改Struct -> Xml的地方(回傳內容需要的話)
ServiceImpl
不改
ServiceTransactions
改KDo物件新加上去的欄位
另外還要修改Struct,找出來,改一改
新增
Message
步驟
分兩種
Query和其它
But!!
用新架構!!!
用新架構!!!
用新架構!!!
MFC程式進入點
就…簡單說一下
這個專案形式的程式進入點
Visual Studio 2005的Solution Explorer
主要是靠這兩組
DMServer>Header Files
DMServer.h
MainForm.h
DMServer>SourceFile
DMServer.cpp
MainForm.cpp
Visual Studio 2005的Solution Explorer
DMServer 執行時期的主要執行緒, 失敗了DM執行失敗
MainForm 執行時期的主視窗程式, 失敗了DM背景執行
連不上資料庫也
這樣唷!!!
依序執行
1. DMServerApp::DMServerApp()
2. BOOL DMServerApp::InitInstance() 呼叫 MainForm建構式
3. MainForm::MainForm(CWnd* pParent /*=NULL*/):
4. BOOL MainForm::OnInitDialog()
DMServerApp的初始化
DMServerApp::DMServerApp() //先執行空的建構式
BOOL DMServerApp::InitInstance()
{
MainForm dlg; //初始化MainForm
if( !dlg.cv_IsInitialSQLSuccess ){ //MainForm是否成功執行初始化Sql
return FALSE;
}
m_pMainWnd = &dlg; //系統自己加的,把MainFrom的位址取出來
INT_PTR nResponse = dlg.DoModal(); //顯示主視窗並執行
if (nResponse == IDOK){} //按下UI的「確定」
else if (nResponse == IDCANCEL){} //按下UI的「取消」
}
MainForm的初始化
//建構式
MainForm::MainForm(CWnd* pParent /*=NULL*/):
CDialog(MainForm::IDD, pParent), cv_TimerPtr(0), cv_IsInitialSQLSuccess(false),
cv_pServiceKernel(new SuServiceKernel())
{
cv_IsInitialSQLSuccess = cv_pServiceKernel->IsSqlInitialSuccess(); //先初始化資料庫
if(!cv_IsInitialSQLSuccess) //接著在外面的執行檔類別呼叫時,會判定UI初始化失敗。
{
MessageBox(...);
}
cv_pServiceKernel->OpenFablinkEvent(); //再執行FablinkEvent,否則KDo的存取動作會使DM崩潰
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); //系統設定執行檔的ICON
}
初始化成員變數
在這裡初始化比較快
MainForm的初始化
BOOL MainForm::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
KGS::VerDataName file_info = KGS::GetFileVersionInfoA();
//顯示Dialog內的文字
//設定標題
//設定 給client的query資料
//初始化Timer(更新Busy Message用的)
//之後作業系統會自動執行void MainForm::OnTimer(UINT_PTR nIDEvent))
return TRUE; // return TRUE unless you set the focus to a control
}

More Related Content

More from Chris Wang

MVC Design in Web backend Server
MVC Design in Web backend ServerMVC Design in Web backend Server
MVC Design in Web backend ServerChris Wang
 
Bug afx ini-line122
Bug afx ini-line122Bug afx ini-line122
Bug afx ini-line122Chris Wang
 
物件的值莫名奇妙被改掉
物件的值莫名奇妙被改掉物件的值莫名奇妙被改掉
物件的值莫名奇妙被改掉Chris Wang
 
VC6 font setup tips
VC6 font setup tipsVC6 font setup tips
VC6 font setup tipsChris Wang
 
MFC tips for single document
MFC tips for single documentMFC tips for single document
MFC tips for single documentChris Wang
 
CString of MFC skills
CString of MFC skillsCString of MFC skills
CString of MFC skillsChris Wang
 
應用於液晶電視中動態背光調光技術之演算法與系統整合實現 論文口試投影片
應用於液晶電視中動態背光調光技術之演算法與系統整合實現 論文口試投影片應用於液晶電視中動態背光調光技術之演算法與系統整合實現 論文口試投影片
應用於液晶電視中動態背光調光技術之演算法與系統整合實現 論文口試投影片Chris Wang
 
偷偷學習 Python3
偷偷學習 Python3偷偷學習 Python3
偷偷學習 Python3Chris Wang
 
思考 Vuex 發送 API 的架構
思考 Vuex 發送 API 的架構思考 Vuex 發送 API 的架構
思考 Vuex 發送 API 的架構Chris Wang
 
從 Flux 認識 vuex
從 Flux 認識 vuex從 Flux 認識 vuex
從 Flux 認識 vuexChris Wang
 
Information architecture reading ch7
Information architecture reading ch7Information architecture reading ch7
Information architecture reading ch7Chris Wang
 
Cppunit下載、編譯、使用與困難排除
Cppunit下載、編譯、使用與困難排除Cppunit下載、編譯、使用與困難排除
Cppunit下載、編譯、使用與困難排除Chris Wang
 
如何寫好程式
如何寫好程式如何寫好程式
如何寫好程式Chris Wang
 
迷路的浪漫
迷路的浪漫迷路的浪漫
迷路的浪漫Chris Wang
 
Win32 api看視窗運作
Win32 api看視窗運作Win32 api看視窗運作
Win32 api看視窗運作Chris Wang
 

More from Chris Wang (16)

MVC Design in Web backend Server
MVC Design in Web backend ServerMVC Design in Web backend Server
MVC Design in Web backend Server
 
Bug afx ini-line122
Bug afx ini-line122Bug afx ini-line122
Bug afx ini-line122
 
物件的值莫名奇妙被改掉
物件的值莫名奇妙被改掉物件的值莫名奇妙被改掉
物件的值莫名奇妙被改掉
 
VC6 font setup tips
VC6 font setup tipsVC6 font setup tips
VC6 font setup tips
 
MFC tips for single document
MFC tips for single documentMFC tips for single document
MFC tips for single document
 
CString of MFC skills
CString of MFC skillsCString of MFC skills
CString of MFC skills
 
應用於液晶電視中動態背光調光技術之演算法與系統整合實現 論文口試投影片
應用於液晶電視中動態背光調光技術之演算法與系統整合實現 論文口試投影片應用於液晶電視中動態背光調光技術之演算法與系統整合實現 論文口試投影片
應用於液晶電視中動態背光調光技術之演算法與系統整合實現 論文口試投影片
 
偷偷學習 Python3
偷偷學習 Python3偷偷學習 Python3
偷偷學習 Python3
 
思考 Vuex 發送 API 的架構
思考 Vuex 發送 API 的架構思考 Vuex 發送 API 的架構
思考 Vuex 發送 API 的架構
 
從 Flux 認識 vuex
從 Flux 認識 vuex從 Flux 認識 vuex
從 Flux 認識 vuex
 
Information architecture reading ch7
Information architecture reading ch7Information architecture reading ch7
Information architecture reading ch7
 
用Vue改dom
用Vue改dom用Vue改dom
用Vue改dom
 
Cppunit下載、編譯、使用與困難排除
Cppunit下載、編譯、使用與困難排除Cppunit下載、編譯、使用與困難排除
Cppunit下載、編譯、使用與困難排除
 
如何寫好程式
如何寫好程式如何寫好程式
如何寫好程式
 
迷路的浪漫
迷路的浪漫迷路的浪漫
迷路的浪漫
 
Win32 api看視窗運作
Win32 api看視窗運作Win32 api看視窗運作
Win32 api看視窗運作
 

Dm create message old