|
@@ -125,7 +125,12 @@ void CCenterSettingEntity::OnStarted()
|
|
|
|
|
|
m_nConnectFailCount = 0;
|
|
|
LOG_ASSERT(IsServerConnectedNow());
|
|
|
- auto rc = m_pConnection->BeginPollConfig();
|
|
|
+
|
|
|
+ CSystemStaticInfo info;
|
|
|
+ auto rc = GetFunction()->GetSystemStaticInfo(info);
|
|
|
+ assert(rc == Error_Succeed);
|
|
|
+
|
|
|
+ rc = m_pConnection->BeginPollConfig(info);
|
|
|
return rc;
|
|
|
}
|
|
|
|
|
@@ -138,20 +143,14 @@ void CCenterSettingEntity::OnStarted()
|
|
|
//if (rc == Error_Succeed)
|
|
|
// LogEvent(Severity_Middle, EVENT_MOD_CENTERSETTING_DOWNOK, "集中配置同步成功");
|
|
|
|
|
|
- if (m_spDownloadCall != NULL)
|
|
|
- {
|
|
|
- Dbg("download call completed!");
|
|
|
- m_spDownloadCall->Answer(rc);
|
|
|
- m_spDownloadCall.Clear();
|
|
|
- }
|
|
|
-
|
|
|
+ ReturnAndClearDownloadContext(rc);
|
|
|
return rc;
|
|
|
}
|
|
|
|
|
|
ErrorCodeEnum CCenterSettingEntity::DownloadCenterSetting(
|
|
|
SpReqAnsContext<CenterSettingService_Download_Req, CenterSettingService_Download_Ans>::Pointer sp)
|
|
|
{
|
|
|
- if (m_spDownloadCall != nullptr)
|
|
|
+ if (IsDownloadPending())
|
|
|
{
|
|
|
Dbg("last download call not complet");
|
|
|
sp->Answer(Error_Duplication);
|
|
@@ -190,6 +189,470 @@ void CCenterSettingEntity::OnStarted()
|
|
|
pTransactionContext->SendAnswer(error);
|
|
|
}
|
|
|
|
|
|
+ void CCenterSettingEntity::EditWebUrl(SpReqAnsContext<CenterSettingService_EditWebUrl_Req, CenterSettingService_EditWebUrl_Ans>::Pointer ctx)
|
|
|
+ {
|
|
|
+ ErrorCodeEnum result(Error_Unexpect);
|
|
|
+ ctx->Ans.result = 0;
|
|
|
+ ctx->Ans.msg = "";
|
|
|
+
|
|
|
+ switch (ctx->Req.operation) {
|
|
|
+ case 1: //new
|
|
|
+ {
|
|
|
+ CSmartPointer<IConfigInfo> pConfig;
|
|
|
+ GetFunction()->OpenConfig(Config_Cache, pConfig);
|
|
|
+ int count(0);
|
|
|
+ bool newCreate = true;
|
|
|
+ pConfig->ReadConfigValueInt("CustomWebUrl", "Count", count);
|
|
|
+ int newIndex(count + 1);
|
|
|
+ for (int i = 1; i <= count; ++i) {
|
|
|
+ CustomWebUrlConfig item;
|
|
|
+ CSimpleStringA strSection = CSimpleStringA::Format("CustomWebUrl%d", i);
|
|
|
+ pConfig->ReadConfigValue(strSection, "FultureUrl", item.strFutureUrl);
|
|
|
+ pConfig->ReadConfigValue(strSection, "AdUrl", item.strAdUrl);
|
|
|
+ pConfig->ReadConfigValue(strSection, "Remark", item.strRemark);
|
|
|
+ pConfig->ReadConfigValueInt(strSection, "Env", item.useEnv);
|
|
|
+ pConfig->ReadConfigValueInt(strSection, "Status", item.curStatus);
|
|
|
+ if (!item.IsValid()) {
|
|
|
+ newIndex = i;
|
|
|
+ newCreate = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ CSimpleStringA strNewSection = CSimpleStringA::Format("CustomWebUrl%d", newIndex);
|
|
|
+ pConfig->WriteConfigValue(strNewSection, "FultureUrl", ctx->Req.futureUrl);
|
|
|
+ pConfig->WriteConfigValue(strNewSection, "AdUrl", ctx->Req.adUrl);
|
|
|
+ CSimpleStringA strRemark(ctx->Req.remark);
|
|
|
+ if (strRemark.IsNullOrEmpty()) {
|
|
|
+ if (ctx->Req.env == 1) strRemark = "DEV:";
|
|
|
+ else if(ctx->Req.env == 2) strRemark = "ST:";
|
|
|
+ if (ctx->Req.env == 3) strRemark = "UAT:";
|
|
|
+ strRemark += ctx->Req.futureUrl;
|
|
|
+ }
|
|
|
+ pConfig->WriteConfigValue(strNewSection, "Remark", strRemark);
|
|
|
+ pConfig->WriteConfigValueInt(strNewSection, "Env", ctx->Req.env);
|
|
|
+ pConfig->WriteConfigValueInt(strNewSection, "Status", WEBURL_STATUS_PROVIDE);
|
|
|
+ if (ctx->Req.setDefault) {
|
|
|
+ pConfig->WriteConfigValueInt("CustomWebUrl", "Current", newIndex);
|
|
|
+ }
|
|
|
+ if (newCreate) {
|
|
|
+ pConfig->WriteConfigValueInt("CustomWebUrl", "Count", newIndex);
|
|
|
+ }
|
|
|
+
|
|
|
+ ctx->Ans.addition = newIndex;
|
|
|
+ result = Error_Succeed;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 2: //delete
|
|
|
+ {
|
|
|
+ if (ctx->Req.index >= WEBURL_ITEM_INDEX_CENTERSETTING) {
|
|
|
+ result = Error_NoPrivilege;
|
|
|
+ } else {
|
|
|
+ CSmartPointer<IConfigInfo> pConfig;
|
|
|
+ GetFunction()->OpenConfig(Config_Cache, pConfig);
|
|
|
+ int oldStatus(0);
|
|
|
+ CSimpleStringA strSection = CSimpleStringA::Format("CustomWebUrl%d", ctx->Req.index);
|
|
|
+ pConfig->ReadConfigValueInt(strSection, "Status", oldStatus);
|
|
|
+ pConfig->WriteConfigValueInt(strSection, "Status", WEBURL_STATUS_DEPRECATE);
|
|
|
+ int currentUsing(0);
|
|
|
+ pConfig->ReadConfigValueInt("CustomWebUrl", "Current", currentUsing);
|
|
|
+ if (ctx->Req.index == currentUsing) {
|
|
|
+ pConfig->WriteConfigValueInt("CustomWebUrl", "Current", 0);
|
|
|
+ }
|
|
|
+ result = Error_Succeed;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 3: //update
|
|
|
+ {
|
|
|
+ if (ctx->Req.index >= WEBURL_ITEM_INDEX_CENTERSETTING) { //如果当前是集中配置文件
|
|
|
+ CSmartPointer<IConfigInfo> pConfig;
|
|
|
+ GetFunction()->OpenConfig(Config_Cache, pConfig);
|
|
|
+ int currentUsing(0);
|
|
|
+ pConfig->ReadConfigValueInt("CustomWebUrl", "Current", currentUsing);
|
|
|
+ if (currentUsing != 0 && ctx->Req.setDefault) {
|
|
|
+ pConfig->WriteConfigValueInt("CustomWebUrl", "Current", 0);
|
|
|
+ result = Error_Succeed;
|
|
|
+ } else {
|
|
|
+ result = Error_NoPrivilege;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ CSmartPointer<IConfigInfo> pConfig;
|
|
|
+ GetFunction()->OpenConfig(Config_Cache, pConfig);
|
|
|
+ CSimpleStringA strExistedSection = CSimpleStringA::Format("CustomWebUrl%d", ctx->Req.index);
|
|
|
+ pConfig->WriteConfigValue(strExistedSection, "FultureUrl", ctx->Req.futureUrl);
|
|
|
+ pConfig->WriteConfigValue(strExistedSection, "AdUrl", ctx->Req.adUrl);
|
|
|
+ CSimpleStringA strRemark(ctx->Req.remark);
|
|
|
+ if (strRemark.IsNullOrEmpty()) {
|
|
|
+ if (ctx->Req.env == 1) strRemark = "DEV:";
|
|
|
+ else if (ctx->Req.env == 2) strRemark = "ST:";
|
|
|
+ if (ctx->Req.env == 3) strRemark = "UAT:";
|
|
|
+ strRemark += ctx->Req.futureUrl;
|
|
|
+ }
|
|
|
+ pConfig->WriteConfigValue(strExistedSection, "Remark", strRemark);
|
|
|
+ pConfig->WriteConfigValueInt(strExistedSection, "Env", ctx->Req.env);
|
|
|
+ pConfig->WriteConfigValueInt(strExistedSection, "Status", WEBURL_STATUS_PROVIDE);
|
|
|
+ if (ctx->Req.setDefault) {
|
|
|
+ pConfig->WriteConfigValueInt("CustomWebUrl", "Current", ctx->Req.index);
|
|
|
+ }
|
|
|
+ ctx->Ans.addition = ctx->Req.index;
|
|
|
+ result = Error_Succeed;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ result = Error_NotSupport;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ ctx->Answer(result);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ void CCenterSettingEntity::GetWebUrlList(SpReqAnsContext<CenterSettingService_GetWebUrlList_Req, CenterSettingService_GetWebUrlList_Ans>::Pointer ctx)
|
|
|
+ {
|
|
|
+ ErrorCodeEnum result(Error_Succeed);
|
|
|
+ CSmartPointer<IConfigInfo> pConfig;
|
|
|
+ GetFunction()->OpenConfig(Config_Cache, pConfig);
|
|
|
+ int cnt(0), curIndex(0), realCnt(0);
|
|
|
+ bool hasDefaultFromCustom(false);
|
|
|
+ pConfig->ReadConfigValueInt("CustomWebUrl", "Count", cnt);
|
|
|
+ int currentUsing(0);
|
|
|
+ pConfig->ReadConfigValueInt("CustomWebUrl", "Current", currentUsing);
|
|
|
+
|
|
|
+ CAutoArray< CustomWebUrlConfig> configs(cnt);
|
|
|
+ Dbg("custom count: %d", cnt);
|
|
|
+ for (int i = 1; i <= cnt; ++i) {
|
|
|
+ CustomWebUrlConfig& item = configs[i - 1];
|
|
|
+ item.configFrom = WEBURL_CONFIG_CUSTOM;
|
|
|
+ item.index = i;
|
|
|
+ CSimpleStringA strSection = CSimpleStringA::Format("CustomWebUrl%d", i);
|
|
|
+ pConfig->ReadConfigValue(strSection, "FultureUrl", item.strFutureUrl);
|
|
|
+ pConfig->ReadConfigValue(strSection, "AdUrl", item.strAdUrl);
|
|
|
+ pConfig->ReadConfigValue(strSection, "Remark", item.strRemark);
|
|
|
+ pConfig->ReadConfigValueInt(strSection, "Env", item.useEnv);
|
|
|
+ pConfig->ReadConfigValueInt(strSection, "Status", item.curStatus);
|
|
|
+ if (item.IsValid()) {
|
|
|
+ realCnt++;
|
|
|
+ if (currentUsing == i) {
|
|
|
+ hasDefaultFromCustom = true;
|
|
|
+ item.curStatus = WEBURL_STATUS_DEFAULT;
|
|
|
+ } else {
|
|
|
+ item.curStatus = WEBURL_STATUS_PROVIDE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ CustomWebUrlConfig defaultOne;
|
|
|
+ ErrorCodeEnum resultFromFetch = GetWebUrlInfoFromCenterSettings(defaultOne);
|
|
|
+ if (resultFromFetch == Error_Succeed) {
|
|
|
+ Dbg("add centersettings config");
|
|
|
+ realCnt += 1;
|
|
|
+ if (!hasDefaultFromCustom) {
|
|
|
+ defaultOne.curStatus = WEBURL_STATUS_DEFAULT;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Dbg("total count: %d", realCnt);
|
|
|
+
|
|
|
+ ctx->Ans.index.Init(realCnt);
|
|
|
+ ctx->Ans.futureUrl.Init(realCnt);
|
|
|
+ ctx->Ans.adUrl.Init(realCnt);
|
|
|
+ ctx->Ans.remark.Init(realCnt);
|
|
|
+ ctx->Ans.env.Init(realCnt);
|
|
|
+ ctx->Ans.type.Init(realCnt);
|
|
|
+ ctx->Ans.status.Init(realCnt);
|
|
|
+
|
|
|
+ if (resultFromFetch == Error_Succeed) {
|
|
|
+ ctx->Ans.index[curIndex] = WEBURL_ITEM_INDEX_CENTERSETTING;
|
|
|
+ ctx->Ans.futureUrl[curIndex] = defaultOne.strFutureUrl;
|
|
|
+ ctx->Ans.adUrl[curIndex] = defaultOne.strAdUrl;
|
|
|
+ ctx->Ans.remark[curIndex] = defaultOne.strRemark;
|
|
|
+ ctx->Ans.env[curIndex] = defaultOne.useEnv;
|
|
|
+ ctx->Ans.type[curIndex] = defaultOne.configFrom;
|
|
|
+ ctx->Ans.status[curIndex] = defaultOne.curStatus;
|
|
|
+ curIndex++;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < configs.GetCount(); ++i) {
|
|
|
+ CustomWebUrlConfig& item = configs[i];
|
|
|
+ if (item.IsValid()) {
|
|
|
+ ctx->Ans.index[curIndex] = item.index;
|
|
|
+ ctx->Ans.futureUrl[curIndex] = item.strFutureUrl;
|
|
|
+ ctx->Ans.adUrl[curIndex] = item.strAdUrl;
|
|
|
+ ctx->Ans.remark[curIndex] = item.strRemark;
|
|
|
+ ctx->Ans.env[curIndex] = item.useEnv;
|
|
|
+ ctx->Ans.type[curIndex] = item.configFrom;
|
|
|
+ ctx->Ans.status[curIndex] = item.curStatus;
|
|
|
+ curIndex++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ctx->Answer(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ void CCenterSettingEntity::GetActiveCustomUrl(
|
|
|
+ SpReqAnsContext<CenterSettingService_GetActiveCustomUrl_Req, CenterSettingService_GetActiveCustomUrl_Ans>::Pointer ctx)
|
|
|
+ {
|
|
|
+ ErrorCodeEnum result(Error_Succeed);
|
|
|
+ CSmartPointer<IConfigInfo> pConfig;
|
|
|
+ GetFunction()->OpenConfig(Config_Cache, pConfig);
|
|
|
+ int cnt(0), currentUsing(0);
|
|
|
+ pConfig->ReadConfigValueInt("CustomWebUrl", "Count", cnt);
|
|
|
+ pConfig->ReadConfigValueInt("CustomWebUrl", "Current", currentUsing);
|
|
|
+
|
|
|
+ if (cnt == 0 || currentUsing == 0) {
|
|
|
+ result = Error_NotConfig;
|
|
|
+ } else {
|
|
|
+ CSimpleStringA strSection = CSimpleStringA::Format("CustomWebUrl%d", currentUsing);
|
|
|
+ pConfig->ReadConfigValue(strSection, "FultureUrl", ctx->Ans.fultureUrl);
|
|
|
+ pConfig->ReadConfigValue(strSection, "AdUrl", ctx->Ans.adUrl);
|
|
|
+
|
|
|
+ if (!ctx->Ans.fultureUrl.IsNullOrEmpty()) {
|
|
|
+ result = Error_Succeed;
|
|
|
+ } else {
|
|
|
+ result = Error_CheckSum;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ctx->Answer(result);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ void CCenterSettingEntity::EditTerminalBackupInfo(SpReqAnsContext<CenterSettingService_EditTerminalBackupInfo_Req, CenterSettingService_EditTerminalBackupInfo_Ans>::Pointer ctx)
|
|
|
+ {
|
|
|
+ ErrorCodeEnum result(Error_Succeed);
|
|
|
+ CSimpleStringA errMsg(true);
|
|
|
+ ErrorCodeEnum tmpResult(Error_Succeed);
|
|
|
+
|
|
|
+ switch (ctx->Req.operation) {
|
|
|
+ case 1: //new
|
|
|
+ {
|
|
|
+ CSmartPointer<IConfigInfo> pConfig;
|
|
|
+ GetFunction()->OpenConfig(Config_Cache, pConfig);
|
|
|
+ int count(0);
|
|
|
+ bool newCreate = true;
|
|
|
+ pConfig->ReadConfigValueInt("TerminalBackup", "Count", count);
|
|
|
+ int newIndex(count + 1);
|
|
|
+ for (int i = 1; i <= count; ++i) {
|
|
|
+ CustomWebUrlConfig item;
|
|
|
+ CSimpleStringA strSection = CSimpleStringA::Format("TerminalBackup%d", i);
|
|
|
+ pConfig->ReadConfigValue(strSection, "TerminalNo", item.strFutureUrl);
|
|
|
+ pConfig->ReadConfigValue(strSection, "ServerIP", item.strAdUrl);
|
|
|
+ pConfig->ReadConfigValue(strSection, "Remark", item.strRemark);
|
|
|
+ pConfig->ReadConfigValueInt(strSection, "Env", item.useEnv);
|
|
|
+ pConfig->ReadConfigValueInt(strSection, "Status", item.curStatus);
|
|
|
+ if (!item.IsValid()) {
|
|
|
+ newIndex = i;
|
|
|
+ newCreate = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ CSimpleStringA strNewSection = CSimpleStringA::Format("TerminalBackup%d", newIndex);
|
|
|
+ pConfig->WriteConfigValue(strNewSection, "TerminalNo", ctx->Req.terminalNo);
|
|
|
+ pConfig->WriteConfigValue(strNewSection, "ServerIP", ctx->Req.branchIP);
|
|
|
+ CSimpleStringA strRemark(ctx->Req.remark);
|
|
|
+ if (strRemark.IsNullOrEmpty()) {
|
|
|
+ if (ctx->Req.env == 1) strRemark = "DEV:";
|
|
|
+ else if (ctx->Req.env == 2) strRemark = "ST:";
|
|
|
+ if (ctx->Req.env == 3) strRemark = "UAT:";
|
|
|
+ strRemark += ctx->Req.terminalNo;
|
|
|
+ }
|
|
|
+ pConfig->WriteConfigValue(strNewSection, "Remark", strRemark);
|
|
|
+ pConfig->WriteConfigValueInt(strNewSection, "Env", ctx->Req.env);
|
|
|
+ pConfig->WriteConfigValueInt(strNewSection, "Status", WEBURL_STATUS_PROVIDE);
|
|
|
+ if (ctx->Req.setDefault) {
|
|
|
+ tmpResult = UpdateTerminalInfoAtChange(ctx->Req.terminalNo);
|
|
|
+ if (!(tmpResult == Error_Succeed || tmpResult == Error_AlreadyExist)) {
|
|
|
+ pConfig->WriteConfigValueInt(strNewSection, "Status", WEBURL_STATUS_DEPRECATE);
|
|
|
+ errMsg = CSimpleStringA::Format("更新终端号信息失败!");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (newCreate) {
|
|
|
+ pConfig->WriteConfigValueInt("TerminalBackup", "Count", newIndex);
|
|
|
+ }
|
|
|
+ ctx->Ans.addition = (int)ConfirmCenterSettingsFileAndUpdateIfNecessary(ctx->Req.branchIP);
|
|
|
+ result = Error_Succeed;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 2: //delete
|
|
|
+ {
|
|
|
+ CSmartPointer<IConfigInfo> pConfig;
|
|
|
+ GetFunction()->OpenConfig(Config_Cache, pConfig);
|
|
|
+ CSimpleStringA strSection = CSimpleStringA::Format("TerminalBackup%d", ctx->Req.index);
|
|
|
+ int oldStatus(0);
|
|
|
+ pConfig->ReadConfigValueInt(strSection, "Status", oldStatus);
|
|
|
+ pConfig->WriteConfigValueInt(strSection, "Status", WEBURL_STATUS_DEPRECATE);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 3: //update
|
|
|
+ {
|
|
|
+ CSmartPointer<IConfigInfo> pConfig;
|
|
|
+ GetFunction()->OpenConfig(Config_Cache, pConfig);
|
|
|
+ CSimpleStringA strExistedSection = CSimpleStringA::Format("TerminalBackup%d", ctx->Req.index);
|
|
|
+
|
|
|
+ if (ctx->Req.setDefault) {
|
|
|
+ tmpResult = UpdateTerminalInfoAtChange(ctx->Req.terminalNo);
|
|
|
+ if (!(tmpResult == Error_Succeed || tmpResult == Error_AlreadyExist)) {
|
|
|
+ errMsg = CSimpleStringA::Format("更新终端号信息失败!");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ pConfig->WriteConfigValue(strExistedSection, "TerminalNo", ctx->Req.terminalNo);
|
|
|
+ pConfig->WriteConfigValue(strExistedSection, "ServerIP", ctx->Req.branchIP);
|
|
|
+ CSimpleStringA strRemark(ctx->Req.remark);
|
|
|
+ if (strRemark.IsNullOrEmpty()) {
|
|
|
+ if (ctx->Req.env == 1) strRemark = "DEV:";
|
|
|
+ else if (ctx->Req.env == 2) strRemark = "ST:";
|
|
|
+ if (ctx->Req.env == 3) strRemark = "UAT:";
|
|
|
+ strRemark += ctx->Req.terminalNo;
|
|
|
+ }
|
|
|
+ pConfig->WriteConfigValue(strExistedSection, "Remark", strRemark);
|
|
|
+ pConfig->WriteConfigValueInt(strExistedSection, "Env", ctx->Req.env);
|
|
|
+ pConfig->WriteConfigValueInt(strExistedSection, "Status", WEBURL_STATUS_PROVIDE);
|
|
|
+
|
|
|
+ ctx->Ans.addition = (int)ConfirmCenterSettingsFileAndUpdateIfNecessary(ctx->Req.branchIP);
|
|
|
+ result = Error_Succeed;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ result = Error_NotSupport;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ ctx->Ans.result = tmpResult;
|
|
|
+ ctx->Ans.msg = errMsg;
|
|
|
+ ctx->Answer(result);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ void CCenterSettingEntity::GetTerminalBackupInfoList(SpReqAnsContext<CenterSettingService_GetTerminalBackupInfoList_Req, CenterSettingService_GetTerminalBackupInfoList_Ans>::Pointer ctx)
|
|
|
+ {
|
|
|
+ ErrorCodeEnum result(Error_Succeed);
|
|
|
+ CSmartPointer<IConfigInfo> pConfig;
|
|
|
+ GetFunction()->OpenConfig(Config_Cache, pConfig);
|
|
|
+ int cnt(0), curIndex(0), realCnt(0);
|
|
|
+ bool hasDefaultFromCustom(false);
|
|
|
+ pConfig->ReadConfigValueInt("TerminalBackup", "Count", cnt);
|
|
|
+ CAutoArray< CustomWebUrlConfig> configs(cnt);
|
|
|
+ Dbg("custom count: %d", cnt);
|
|
|
+ for (int i = 1; i <= cnt; ++i) {
|
|
|
+ CustomWebUrlConfig& item = configs[i - 1];
|
|
|
+ item.configFrom = WEBURL_CONFIG_CUSTOM;
|
|
|
+ item.index = i;
|
|
|
+ CSimpleStringA strSection = CSimpleStringA::Format("TerminalBackup%d", i);
|
|
|
+ pConfig->ReadConfigValue(strSection, "TerminalNo", item.strFutureUrl);
|
|
|
+ pConfig->ReadConfigValue(strSection, "ServerIP", item.strAdUrl);
|
|
|
+ pConfig->ReadConfigValue(strSection, "Remark", item.strRemark);
|
|
|
+ pConfig->ReadConfigValueInt(strSection, "Env", item.useEnv);
|
|
|
+ pConfig->ReadConfigValueInt(strSection, "Status", item.curStatus);
|
|
|
+ if (item.IsValid()) {
|
|
|
+ realCnt++;
|
|
|
+ DWORD dwMask(0);
|
|
|
+ if (IsParamCurrentUsed(item.strFutureUrl, item.strAdUrl, dwMask)) {
|
|
|
+ hasDefaultFromCustom = true;
|
|
|
+ item.curStatus = WEBURL_STATUS_DEFAULT;
|
|
|
+ } else {
|
|
|
+ item.curStatus = WEBURL_STATUS_PROVIDE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ErrorCodeEnum resultFromFetch(Error_NotInit);
|
|
|
+ CustomWebUrlConfig defaultOne;
|
|
|
+ if (!hasDefaultFromCustom) {
|
|
|
+ resultFromFetch = GetParamCurrentUseing(defaultOne);
|
|
|
+ if (resultFromFetch == Error_Succeed) {
|
|
|
+ Dbg("add root config");
|
|
|
+ realCnt += 1;
|
|
|
+ defaultOne.curStatus = WEBURL_STATUS_DEFAULT;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Dbg("total count: %d", realCnt);
|
|
|
+
|
|
|
+ ctx->Ans.index.Init(realCnt);
|
|
|
+ ctx->Ans.terminalNo.Init(realCnt);
|
|
|
+ ctx->Ans.branchIP.Init(realCnt);
|
|
|
+ ctx->Ans.remark.Init(realCnt);
|
|
|
+ ctx->Ans.env.Init(realCnt);
|
|
|
+ ctx->Ans.status.Init(realCnt);
|
|
|
+
|
|
|
+ if (resultFromFetch == Error_Succeed) {
|
|
|
+ ctx->Ans.index[curIndex] = defaultOne.index;
|
|
|
+ ctx->Ans.terminalNo[curIndex] = defaultOne.strFutureUrl;
|
|
|
+ ctx->Ans.branchIP[curIndex] = defaultOne.strAdUrl;
|
|
|
+ ctx->Ans.remark[curIndex] = defaultOne.strRemark;
|
|
|
+ ctx->Ans.env[curIndex] = defaultOne.useEnv;
|
|
|
+ ctx->Ans.status[curIndex] = defaultOne.curStatus;
|
|
|
+
|
|
|
+ Dbg("index: %d", ctx->Ans.index[curIndex]);
|
|
|
+ Dbg("terminalNo: %s", ctx->Ans.terminalNo[curIndex].GetData());
|
|
|
+ Dbg("branchIP: %s", ctx->Ans.branchIP[curIndex].GetData());
|
|
|
+ Dbg("remark: %s", ctx->Ans.remark[curIndex].GetData());
|
|
|
+ Dbg("env: %d", ctx->Ans.env[curIndex]);
|
|
|
+ Dbg("status: %d", ctx->Ans.status[curIndex]);
|
|
|
+
|
|
|
+ curIndex++;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < configs.GetCount(); ++i) {
|
|
|
+ CustomWebUrlConfig& item = configs[i];
|
|
|
+ if (item.IsValid()) {
|
|
|
+ ctx->Ans.index[curIndex] = item.index;
|
|
|
+ ctx->Ans.terminalNo[curIndex] = item.strFutureUrl;
|
|
|
+ ctx->Ans.branchIP[curIndex] = item.strAdUrl;
|
|
|
+ ctx->Ans.remark[curIndex] = item.strRemark;
|
|
|
+ ctx->Ans.env[curIndex] = item.useEnv;
|
|
|
+ ctx->Ans.status[curIndex] = item.curStatus;
|
|
|
+ curIndex++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ctx->Answer(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ void CCenterSettingEntity::DownloadCenterFiles(SpReqAnsContext<CenterSettingService_DownloadCenterFiles_Req, CenterSettingService_DownloadCenterFiles_Ans>::Pointer ctx)
|
|
|
+ {
|
|
|
+ if (IsDownloadPending()) {
|
|
|
+ Dbg("%s: last download call not complet", __FUNCTION__);
|
|
|
+ ctx->Answer(Error_Duplication);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ctx->Req.strAddr == NULL || strlen(ctx->Req.strAddr) == 0 || ctx->Req.nPort <= 0) {
|
|
|
+ ctx->Answer(Error_Param);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ m_spDownloadCallEx = ctx;
|
|
|
+
|
|
|
+ SecureClientRelease();
|
|
|
+ m_pConnection = new CCenterSettingConn(this);
|
|
|
+
|
|
|
+ if (!m_pConnection->Connect(ctx->Req.strAddr, ctx->Req.nPort, 3)) {
|
|
|
+ SecureClientRelease();
|
|
|
+ ReturnAndClearDownloadContext(Error_NetBroken);
|
|
|
+ } else {
|
|
|
+ Dbg("custom download from server %s:%d", ctx->Req.strAddr.GetData(), ctx->Req.nPort, 3);
|
|
|
+ if (ctx->Req.deleteIfExist) {
|
|
|
+ Dbg("Remove CenterSettings file!");
|
|
|
+ RemoveAllCenterSettingFiles();
|
|
|
+ }
|
|
|
+
|
|
|
+ CSystemStaticInfo info;
|
|
|
+ GetFunction()->GetSystemStaticInfo(info);
|
|
|
+ if (!ctx->Req.additional1.IsNullOrEmpty()) {
|
|
|
+ Dbg("Render TeminalNo from %s to %s", info.strTerminalID.GetData(), ctx->Req.additional1.GetData());
|
|
|
+ info.strTerminalID = ctx->Req.additional1;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 该接口永远返回成功,所以没有做判断 [Gifur@2021127]*/
|
|
|
+ ErrorCodeEnum ret = m_pConnection->BeginPollConfig(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
ErrorCodeEnum CCenterSettingEntity::GetSyncInfo(unsigned int& dwSyncTime, CSimpleStringA& strSyncHash, CSimpleStringA& strSyncFile)
|
|
|
{
|
|
|
if (m_SyncFileInfo.find((const char*)m_strCurSiteExtName) != m_SyncFileInfo.end())
|
|
@@ -236,6 +699,28 @@ void CCenterSettingEntity::OnStarted()
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ ErrorCodeEnum CCenterSettingEntity::GetWebUrlInfoFromCenterSettings(CustomWebUrlConfig& config)
|
|
|
+ {
|
|
|
+ CSmartPointer<IConfigInfo> spCerConfig;
|
|
|
+ ErrorCodeEnum err = GetFunction()->OpenConfig(Config_CenterSetting, spCerConfig);
|
|
|
+ SpIniMappingTable table;
|
|
|
+ CSimpleStringA entityName("Chromium");
|
|
|
+ // clean cache every time
|
|
|
+ table.AddEntryString(entityName, "UserMgrUrlFulture", config.strFutureUrl, "");
|
|
|
+ table.AddEntryString(entityName, "UserMgrAd", config.strAdUrl, "");
|
|
|
+ err = table.Load(spCerConfig);
|
|
|
+ if (err == Error_Succeed) {
|
|
|
+ config.configFrom = WEBURL_CONFIG_CENTESETTING;
|
|
|
+ config.curStatus = WEBURL_STATUS_PROVIDE;
|
|
|
+ config.useEnv = WEBURL_ENV_ALL;
|
|
|
+ config.strRemark = "Default Config From CenterSettings";
|
|
|
+ }
|
|
|
+ if (config.strFutureUrl.IsNullOrEmpty()) {
|
|
|
+ err = Error_NotConfig;
|
|
|
+ }
|
|
|
+ return err;
|
|
|
+ }
|
|
|
+
|
|
|
bool CCenterSettingEntity::SecureClientConnect(ConnectServerType type, LPCTSTR serverIP, int port)
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
@@ -294,7 +779,181 @@ void CCenterSettingEntity::OnStarted()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ ErrorCodeEnum CCenterSettingEntity::UpdateTerminalInfoAtChange(const CSimpleStringA& newTerminalInfo)
|
|
|
+ {
|
|
|
+ ErrorCodeEnum result(Error_Succeed);
|
|
|
+
|
|
|
+ CSystemStaticInfo sysInfo;
|
|
|
+ result = GetFunction()->GetSystemStaticInfo(sysInfo);
|
|
|
+ if (result == Error_Succeed) {
|
|
|
+ if (sysInfo.strTerminalID == newTerminalInfo) {
|
|
|
+ result = Error_AlreadyExist;
|
|
|
+ } else {
|
|
|
+ CSimpleStringA strTemp = CSimpleStringA::Format("更新终端号信息:%s -> %s", sysInfo.strTerminalID.GetData(), newTerminalInfo.GetData());
|
|
|
+ LogWarn(Severity_High, Error_Debug, EVENT_CENTERSETTING_CHANGE_ROOT_TERMINALNO, strTemp);
|
|
|
+ CSimpleStringA strRootCfgPath, rootPath;
|
|
|
+ ErrorCodeEnum ec = GetFunction()->GetPath("HardwareCfg", strRootCfgPath);
|
|
|
+ rootPath = strRootCfgPath;
|
|
|
+ rootPath += SPLIT_SLASH_STR;
|
|
|
+ rootPath += "root.ini";
|
|
|
+
|
|
|
+ inifile_write_str(rootPath, "Terminal", "TerminalNo", newTerminalInfo);
|
|
|
+ inifile_write_str(rootPath, "Terminal", "LastTerminalNo", sysInfo.strTerminalID);
|
|
|
+
|
|
|
+ char tmp[32] = {'\0'};
|
|
|
+ inifile_read_str_s("Terminal", "TerminalNo", "", tmp, 31, rootPath);
|
|
|
+ CSimpleStringA strConfirmTerminalNo(tmp);
|
|
|
+ if (strConfirmTerminalNo != newTerminalInfo) {
|
|
|
+ Dbg("Update TeminalNo failed: read returned: %s, write into: %s", strConfirmTerminalNo.GetData(), newTerminalInfo.GetData());
|
|
|
+ result = Error_FailVerify;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ bool CCenterSettingEntity::IsParamCurrentUsed(const CSimpleStringA& strTerminalInfo, const CSimpleStringA& strServerIP, DWORD& outMask)
|
|
|
+ {
|
|
|
+ bool result(true);
|
|
|
+ outMask = 0;
|
|
|
+
|
|
|
+ CSystemStaticInfo sysInfo;
|
|
|
+ GetFunction()->GetSystemStaticInfo(sysInfo);
|
|
|
+ if (sysInfo.strTerminalID.IsNullOrEmpty() || sysInfo.strTerminalID != strTerminalInfo) {
|
|
|
+ result = false;
|
|
|
+ } else {
|
|
|
+ outMask |= 0x1;
|
|
|
+ }
|
|
|
+
|
|
|
+ CSmartPointer<IConfigInfo> pConfig;
|
|
|
+ CSimpleStringA strServer;
|
|
|
+ GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
|
|
|
+ pConfig->ReadConfigValue("CenterSetting", "Server", strServer);
|
|
|
+ CAutoArray<CSimpleStringA> ipPorts = strServer.Split(' ');
|
|
|
+ if (strServer.IsNullOrEmpty() || ipPorts.GetCount() != 2 || ipPorts[0] != strServerIP) {
|
|
|
+ result = false;
|
|
|
+ } else {
|
|
|
+ outMask |= 0x2;
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ ErrorCodeEnum CCenterSettingEntity::GetParamCurrentUseing(CustomWebUrlConfig& config)
|
|
|
+ {
|
|
|
+ ErrorCodeEnum result(Error_Succeed);
|
|
|
+
|
|
|
+ CSystemStaticInfo sysInfo;
|
|
|
+ result = GetFunction()->GetSystemStaticInfo(sysInfo);
|
|
|
+ config.strFutureUrl = sysInfo.strTerminalID;
|
|
|
+
|
|
|
+ CSmartPointer<IConfigInfo> pConfig;
|
|
|
+ CSimpleStringA strServer;
|
|
|
+ result = GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
|
|
|
+ result = pConfig->ReadConfigValue("CenterSetting", "Server", strServer);
|
|
|
+ CAutoArray<CSimpleStringA> ipPorts = strServer.Split(' ');
|
|
|
+ if (ipPorts.GetCount() == 2) {
|
|
|
+ config.strAdUrl = ipPorts[0];
|
|
|
+ } else {
|
|
|
+ config.strAdUrl = "";
|
|
|
+ }
|
|
|
+ config.index = WEBURL_ITEM_INDEX_CENTERSETTING;
|
|
|
+ config.configFrom = WEBURL_CONFIG_CENTESETTING;
|
|
|
+ config.curStatus = WEBURL_STATUS_PROVIDE;
|
|
|
+ config.useEnv = WEBURL_ENV_ALL;
|
|
|
+ config.strRemark = "root.ini&CenterSetting";
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ void CCenterSettingEntity::RemoveAllCenterSettingFiles()
|
|
|
+ {
|
|
|
+ CSimpleStringA strEntityCfgPath;
|
|
|
+ GetFunction()->GetPath("Cfg", strEntityCfgPath);
|
|
|
+ array_header_t* subs = fileutil_get_sub_files_a(strEntityCfgPath);
|
|
|
+ if (subs) {
|
|
|
+ regex_t reg;
|
|
|
+ CSimpleStringA pattern = "CenterSetting\.[a-zA-Z0-9_\\(\\)\\-]*\.ini";
|
|
|
+ int ret = regcomp(®, pattern, REG_EXTENDED | REG_NOSUB);
|
|
|
+ if (ret) {
|
|
|
+ char ebuff[256];
|
|
|
+ regerror(ret, ®, ebuff, 256);
|
|
|
+ Dbg("regex failed: %s", ebuff);
|
|
|
+ } else {
|
|
|
+ Dbg("pattern: %s", pattern.GetData());
|
|
|
+ for (int i = 0; i < subs->nelts; ++i) {
|
|
|
+ char* filenamePath = ARRAY_IDX(subs, i, char*);
|
|
|
+ char* filename = &filenamePath[strEntityCfgPath.GetLength() + 1];
|
|
|
+ ret = regexec(®, filename, 0, NULL, 0);
|
|
|
+ if (0 == ret) {
|
|
|
+ Dbg("filename %s matched and remove it.", filename);
|
|
|
+ fileutil_delete_file(filenamePath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ toolkit_array_free2(subs);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (m_pConnection != NULL) {
|
|
|
+ m_pConnection->DeleteErrorFiles(strEntityCfgPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ErrorCodeEnum CCenterSettingEntity::ConfirmCenterSettingsFileAndUpdateIfNecessary(const CSimpleStringA& serverIP)
|
|
|
+ {
|
|
|
+ CSmartPointer<IConfigInfo> pConfig;
|
|
|
+ CSimpleStringA strServer;
|
|
|
+ ErrorCodeEnum result = GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
|
|
|
+ result = pConfig->ReadConfigValue("CenterSetting", "Server", strServer);
|
|
|
+ CAutoArray<CSimpleStringA> ipPorts = strServer.Split(' ');
|
|
|
+ if (strServer.IsNullOrEmpty() || ipPorts.GetCount() !=2 || ipPorts[0] != serverIP) {
|
|
|
+ result = Error_FailVerify;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ void CCenterSettingService::Handle_EditWebUrl(SpReqAnsContext<CenterSettingService_EditWebUrl_Req, CenterSettingService_EditWebUrl_Ans>::Pointer ctx)
|
|
|
+ {
|
|
|
+ LOG_FUNCTION();
|
|
|
+ m_pEntity->EditWebUrl(ctx);
|
|
|
+ }
|
|
|
+
|
|
|
+ void CCenterSettingService::Handle_GetWebUrlList(SpReqAnsContext<CenterSettingService_GetWebUrlList_Req, CenterSettingService_GetWebUrlList_Ans>::Pointer ctx)
|
|
|
+ {
|
|
|
+ LOG_FUNCTION();
|
|
|
+ m_pEntity->GetWebUrlList(ctx);
|
|
|
+ }
|
|
|
+
|
|
|
+ void CCenterSettingService::Handle_GetActiveCustomUrl(SpReqAnsContext<CenterSettingService_GetActiveCustomUrl_Req, CenterSettingService_GetActiveCustomUrl_Ans>::Pointer ctx)
|
|
|
+ {
|
|
|
+ LOG_FUNCTION();
|
|
|
+ m_pEntity->GetActiveCustomUrl(ctx);
|
|
|
+ }
|
|
|
+
|
|
|
+ void CCenterSettingService::Handle_EditTerminalBackupInfo(SpReqAnsContext<CenterSettingService_EditTerminalBackupInfo_Req, CenterSettingService_EditTerminalBackupInfo_Ans>::Pointer ctx)
|
|
|
+ {
|
|
|
+ LOG_FUNCTION();
|
|
|
+ m_pEntity->EditTerminalBackupInfo(ctx);
|
|
|
+ }
|
|
|
+
|
|
|
+ void CCenterSettingService::Handle_GetTerminalBackupInfoList(SpReqAnsContext<CenterSettingService_GetTerminalBackupInfoList_Req, CenterSettingService_GetTerminalBackupInfoList_Ans>::Pointer ctx)
|
|
|
+ {
|
|
|
+ LOG_FUNCTION();
|
|
|
+ m_pEntity->GetTerminalBackupInfoList(ctx);
|
|
|
+ }
|
|
|
+
|
|
|
+ void CCenterSettingService::Handle_DownloadCenterFiles(SpReqAnsContext<CenterSettingService_DownloadCenterFiles_Req, CenterSettingService_DownloadCenterFiles_Ans>::Pointer ctx)
|
|
|
+ {
|
|
|
+ LOG_FUNCTION();
|
|
|
+ m_pEntity->DownloadCenterFiles(ctx);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
SP_BEGIN_ENTITY_MAP()
|
|
|
SP_ENTITY(CCenterSettingEntity)
|
|
|
SP_END_ENTITY_MAP()
|
|
|
|
|
|
+
|
|
|
+
|