| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- #include "StdAfx.h"
- #include "CellBranch.h"
- #include "IvrFlow.h"
- #include "FlowDataProvider.h"
- IMPLEMENT_CELL_AUTOCREATE(CCellBranch, CELL_NAME_BRANCH)
- CCellBranch::CCellBranch(void) : m_DefaultPos(0), m_VarName("")
- {
- }
- CCellBranch::CCellBranch( CCellBranch& CellBranch ) : CCellBase(CellBranch)
- {
- m_VarName = CellBranch.m_VarName;
- m_DefaultPos = CellBranch.m_DefaultPos;
- POSITION pos = CellBranch.m_BranchList.GetHeadPosition();
- while(pos != NULL)
- {
- BranchInfo *pBranch = CellBranch.m_BranchList.GetNext(pos);
- if(pBranch != NULL)
- {
- BranchInfo *pBranchTemp = new BranchInfo;
- if(pBranchTemp != NULL)
- {
- memset(pBranchTemp, 0, sizeof(BranchInfo));
- lstrcpy(pBranchTemp->Value, pBranch->Value);
- pBranchTemp->Pos = pBranch->Pos;
- m_BranchList.AddTail(pBranchTemp);
- }
- }
- }
- }
- CCellBranch::~CCellBranch(void)
- {
- __release();
- }
- /*****************************************************************
- **【函数名称】 __release
- **【函数功能】 释放资源
- **【参数】
- **【返回值】
- ****************************************************************/
- void CCellBranch::__release( void )
- {
- if(!m_BranchList.IsEmpty())
- {
- BranchInfo *pBranch = NULL;
- POSITION pos = m_BranchList.GetHeadPosition();
- while(pos != NULL)
- {
- pBranch = m_BranchList.GetNext(pos);
- if(pBranch != NULL)
- {
- delete pBranch;
- pBranch = NULL;
- }
- }
- m_BranchList.RemoveAll();
- }
- }
- /*****************************************************************
- **【函数名称】 operate
- **【函数功能】 节点执行函数
- **【参数】
- **【返回值】 下一个节点编号
- ****************************************************************/
- int CCellBranch::operate( void )
- {
- if(m_pIvrFlow == NULL)
- return CELL_OP_ERROR;
- CString Info;
- _getCellInfo(Info);
- ILogger::getInstance().log(LOG_CLASS_BUSI, LOG_LEVEL_NORMAL, _T("{Cell}: 开始执行[%s]"), Info);
- CString strVarValue = "";
- if(m_pIvrFlow->findVarValue(m_VarName, strVarValue))
- {
- POSITION pos = m_BranchList.GetHeadPosition();
- while(pos != NULL)
- {
- BranchInfo *pBranch = m_BranchList.GetNext(pos);
- if(pBranch != NULL )
- {
- if(strVarValue.Compare(pBranch->Value) == 0)
- return pBranch->Pos;
- }
- }
- }
- return m_DefaultPos;
- }
- /*****************************************************************
- **【函数名称】 copy
- **【函数功能】 拷贝自身
- **【参数】
- **【返回值】 拷贝副本
- ****************************************************************/
- CCellBase * CCellBranch::copy( void )
- {
- CCellBase * pCellBase = new CCellBranch(*this);
- return pCellBase;
- }
- /*****************************************************************
- **【函数名称】 fillData
- **【函数功能】 节点解析,填充数据
- **【参数】 Provider:数据提供器
- **【返回值】 成功true,失败false
- ****************************************************************/
- bool CCellBranch::fillData( IFlowDataProvider& Provider )
- {
- CString Data;
- do
- {
- if(!Provider.getData(CELL_ATTRIBUTE_POS, Data))
- {
- Data = _T("节点号");
- break;
- }
- else
- {
- sscanf_s(Data, _T("%d"), &m_Pos);
- if(m_Pos < 1)
- {
- Data = _T("节点号");
- break;
- }
- }
- if(!Provider.getData(CELL_ATTRIBUTE_VAR, m_VarName))
- {
- Data = _T("分支变量");
- break;
- }
- if(!Provider.getData(CELL_ATTRIBUTE_DEFAULT_POS, Data))
- {
- Data = _T("默认跳转节点");
- break;
- }
- else
- {
- sscanf_s(Data, _T("%d"), &m_DefaultPos);
- if(m_DefaultPos < 0)
- {
- Data = _T("默认跳转节点");
- break;
- }
- }
- Data.Format(_T("%s[@%s='%d']/%s"), XPATH_CELL, CELL_ATTRIBUTE_POS, m_Pos, FlOW_SUB_NODE_BRANCH);
- if(!Provider.getFlowBranch(Data, *this))
- {
- Data = _T("分支信息");
- break;
- }
- Provider.getData(CELL_ATTRIBUTE_NOTE, m_Note);
- return true;
- } while (false);
- ILogger::getInstance().log(LOG_CLASS_BUSI, LOG_LEVEL_ERROR, _T("{Cell}: 节点[%s]解析失败, '%s'错误"), CELL_NAME_BRANCH, Data);
- return false;
- }
- /*****************************************************************
- **【函数名称】 addBranch
- **【函数功能】 添加分支信息
- **【参数】 Value:分支匹配值
- Pos:跳转节点
- **【返回值】
- ****************************************************************/
- void CCellBranch::addBranch( const CString& Value, int Pos )
- {
- if(Pos < 0)
- return;
- BranchInfo *pBranch = new BranchInfo;
- if(pBranch != NULL)
- {
- memset(pBranch, 0, sizeof(BranchInfo));
- lstrcpy(pBranch->Value, Value);
- pBranch->Pos = Pos;
- m_BranchList.AddTail(pBranch);
- }
- }
|