×

Loading...
Ad by
  • 技多不压身,工到自然成:安省技工证书特训班,点击咨询报名!
Ad by
  • 技多不压身,工到自然成:安省技工证书特训班,点击咨询报名!

it's written using IBM net.commerce C++ and Net.Data macro language.

本文发表在 rolia.net 枫下论坛sample homepage source code:

#include "commands/au_commands.pch"

#include "commands/AddItem.h"
#include "commands/EmailMessage.h"
#include "objects/WLManager.h"
#include <sys/stat.h>

//#define BEST_BEFORE 2 //TO DEBBUG
const int BEST_BEFORE = 1500; // 25 minutes
const int BrowserCount = 22;
String wirelessBrowsers[BrowserCount] = {
"Noki", // Nokia phones and emulators
"Eric", // Ericsson WAP phones and emulators
"WapI", // Ericsson WapIDE 2.0
"MC21", // Ericsson MC218
"AUR ", // Ericsson R320
"R380", // Ericsson R380
"UP.B", // UP.Browser
"WinW", // WinWAP browser
"UPG1", // UP.SDK 4.0
"upsi", // another kind of UP.Browser
"QWAP", // QWAPPER browser
"Jigs", // JigSaw browser
"Java", // Java based browser
"Alca", // Alcatel-BE3 browser (UP based)
"MITS", // Mitsubishi browser
"MOT-", // browser (UP based)
"My S", // Ericsson devkit browser
"WAPJ", // Virtual WAPJAG www.wapjag.de
"fetc", // fetchpage.cgi Perl script from www.wapcab.de
"ALAV", // another UP based browser
"Wapa", // Wapalyzer
"ccWAP" // ccWAP simulator (www.ccwap.com)
};

class __DLL_NCA_CMD__ CommandWelcome : public NC_Command
{
static ClassName _STR_ThisClass;

public:
CommandWelcome() {};
public:
void* operator new (size_t tSize);
void operator delete (void* p );

virtual bool CheckParameters(const HttpRequest& Req, HttpResponse& Res,
NC_Environment& Env, NC_Environment& Resources);
virtual bool Process(const HttpRequest& Req, HttpResponse& Res, NC_Environment& Env);

};


ClassName CommandWelcome::_STR_ThisClass("CommandWelcome");

void* CommandWelcome::operator new (size_t tSize) { return ::operator new (tSize); }
void CommandWelcome::operator delete (void* p ) { ::operator delete(p ); }


bool CommandWelcome::CheckParameters(const HttpRequest& Req, HttpResponse& Res,
NC_Environment& Env, NC_Environment& Resources) {

//nothing to check. Just display the hard coded welcome page
return true;
}


bool CommandWelcome::Process(const HttpRequest& Req, HttpResponse& Res, NC_Environment& Env)
{
try{
Row r1; /*just an all purpose row*/
DataBase& _db = *DataBaseManager::GetCurrentDataBase();
int cookieErr = 0;
const CookieMap& cookies = Req.getCookieNVPs();
if (cookies.Get("SESSION_ID").IsEmpty()){
HttpDate expDate(2050, 03, 01, 01,01,01,00);
String aff = "affiliate";
Res.AddCookie(aff, "null", expDate);
String subid = "subid";
Res.AddCookie(subid, "null", expDate);
cookieErr = 1;
}

NVPHash NVP;
if (cookieErr == 1)
NVP.Add("cookieerr", "true");

/*
NetDataMacro page(_db, Req, Env, NVP);
page.setName("/Welcome.d2w");
page.Exec("report");
*/
User* shopper = (User*) Env.Seek(NC_Environment::_VAR_Shopper);
/*just in case, we don't want to set a guest browser, should not happen*/
if (shopper->getType()=="R") {
/*find out what PIK was used, if any. Set the PIK as a cookie */
String Sql1 = "SELECT sdfield6 from shopdem where sdfield6 is not null and sdshnbr=";
Sql1 << shopper->getRefNum();

SQL S1(_db , Sql1);
int rc = S1.getNextRow(r1);
if (rc == ERR_DB_NO_ERROR) {
String PIK = r1.getCol(1);
HttpDate expDate(2025, 01, 01, 01,01,01,00);
Res.AddCookie(PIK, String("1"), expDate);
} /*if PIK exists*/
}

// Res.setDocument(page.getDocument());
Res.setDocument(MiscAu::CallMacroPage( Req, Env, "Welcome.d2w", "report", NVP));

}
catch(const ErrorMsg_Cmd* e) {
throw e;
}
catch(...) {
MiscAu::reportError(Req, Res);
}
return true;
}


static bool X1 = NC_CommandManager::GetUniqueInstance().RegisterCommand("IBM",
"NC",
"Welcome",
1.0,
new CommandWelcome);





class __DLL_NCA_CMD__ CommandGenHmPage : public NC_Command
{
static ClassName _STR_ThisClass;

public:
CommandGenHmPage() {};
String _Merchant;
bool _IsForseOption;
bool _IsForseCmd;

public:
void* operator new (size_t tSize);
void operator delete (void* p );

virtual bool CheckParameters(const HttpRequest& Req, HttpResponse& Res,
NC_Environment& Env, NC_Environment& Resources);
virtual bool Process(const HttpRequest& Req, HttpResponse& Res, NC_Environment& Env);
virtual bool Initialize(void);
bool SetScheduler(String langCookie, int catalogCountTime);
bool InsertSchedCmd( const String& url, int catalogCountTime, bool check);

};


ClassName CommandGenHmPage::_STR_ThisClass("CommandGenHmPage");

void* CommandGenHmPage::operator new (size_t tSize) { return ::operator new (tSize); }
void CommandGenHmPage::operator delete (void* p ) { ::operator delete(p ); }


bool CommandGenHmPage::CheckParameters(const HttpRequest& Req, HttpResponse& Res,
NC_Environment& Env, NC_Environment& Resources) {

//nothing to check. Just display the hard coded GenHmPage page
return true;
}


bool CommandGenHmPage::Process(const HttpRequest& Req, HttpResponse& Res, NC_Environment& Env)
{
try {

// Handle Wireless Browsers and redirect to mobile.edeal.com
const String browser = Req.getHTTP_USER_AGENT();
String::Iterator I = browser.getIterator();

for (int i = 0; i < BrowserCount; i++){
I.Begin();
I.Seek(wirelessBrowsers[i]);
if(I.Len() != I.Pos()){
Res.setLocation("http://mobile.edeal.com", 0);
return true;
}
}

String wlname = Req.getNVPs().Get("wlname", _STR_EMPTY_);
String wl = _STR_EMPTY_;
DataBase& _db = *DataBaseManager::GetCurrentDataBase();

if (wlname.IsEmpty() == true) {
wlname = "www.edeal.com"; //default is www.edeal.com i.e 151
wl = WLM_OPTION(Req, "MerchantRefNum");
}
else{
wl = WLM_GETWLID(wlname);

if (wl == "151") { // maybe we got the default value, how hany visitor visiting the marketplace? not many!!

String sqlStringAlias = "";
sqlStringAlias << "Select ual_redirecturl from UrlAlias where ual_url = " << sq(wlname);
SQL _sqlAlias(_db, sqlStringAlias);
Row rowAlias;
if (_sqlAlias.getNextRow(rowAlias) == ERR_DB_NO_ERROR)
{
String redirectUrl = rowAlias.getCol("ual_redirecturl").Trim();
NVPHash NVP;
NVP.Add("redURL", redirectUrl);
MiscAu::Redirect(Res, Req, "redURL", NVP);
return true;
}

}

}

String cmdForce = Req.getNVPs().Get("force", _STR_EMPTY_);


// get language preferences
String langId = Req.getNVPs().Get("LangID", _STR_EMPTY_);
if (langId.IsEmpty()) langId = Req.getCookieNVPs().Get("LangID");

String langPref = "en_us";

if (!langId.IsEmpty() && langId.ToLower()!="1") langPref = "fr_ca";

String cachePostFix = "";

if (langPref != "en_us") {
cachePostFix = langPref.Trim();
}

//reverse lookup the hostname to the wl ID
_Merchant = wl;
bool force = false;
if (WLM_OPTION(wl, "ForceHomePage")=="1") {
_IsForseOption =true;
}
else {
_IsForseOption =false;
}
if (cmdForce.IsEmpty()) {
_IsForseCmd = false;
}
else {
_IsForseCmd =true;
}
if (_IsForseCmd || _IsForseOption ) {
force = true;
}

// count_time is Catalog count time in seconds
int count_time = (atoi(WLM_OPTION(Req, "CountTime").c_str()) * 60);
if(count_time <= 0)
count_time = BEST_BEFORE; // default is 25 minutes

String idxname = "./idx";
if (!force) { //only do this for sites that allow cache
// check if the file exist and is fresh.
//String idxname = "./idxcache/idx";
idxname << wl << cachePostFix << ".html";

FILE* idxFile = fopen(idxname.c_str(), "r");
if (idxFile != NULL) { // if file exist

struct _stat bufStat;
_fstat(idxFile->_file, &bufStat);
time_t curtime;
time( &curtime );


long elapsed_time = difftime( curtime, bufStat.st_mtime );
//debug << "elapsed time:"<<elapsed_time<<endl;

if (elapsed_time >= count_time && WLM_OPTION(Req, "NoCtCnt") != "Y") {
SetScheduler(langId, count_time);
}
//debug << "count time:"<<count_time<<endl;

String cachedPage;
char fileBuf[1001];
int bytesRead = 0;

while (!feof(idxFile)) {
bytesRead = fread(fileBuf, sizeof(char) , 1000, idxFile);
fileBuf[bytesRead] = '\0'; // terminate the str using null
cachedPage << String(fileBuf);
}

Res.setDocument(cachedPage);
fclose(idxFile); // close the file and return and do not refresh the file.
return true;
}
} //only if cache is allowed for the wl


// Generate the new page for the client if the home cache page does not exist


// make a record for catalog count shedule
if(WLM_OPTION(Req, "NoCtCnt") != "Y")
SetScheduler(langId, count_time); //if this store accessed in normal way

if (_IsForseCmd) {
//if this store accessed by designer during creation.

NVPHash nvp_empty;
HttpRequest LocalReq;
LocalReq = Req;
NameValuePairMap& NVPMap = LocalReq.getNVPs();
NVPMap.setUnique("merchant",_Merchant);
NVPMap.setUnique("cache","0");
NC_RegistrationID ID("IBM", "NC", "CountCateg", 1.0);
HttpResponse LocalRes;
LocalReq.setInternalUser("bla");
const ErrorMsg_Cmd* Err = NC_CommandManager::Call(LocalReq, LocalRes, Env, ID);
if (Err != NULL) // Otherwise, just return a failure.
{
error<<indent<< "Error: Failed to call CountCateg";
MiscAu::FatalDump(Req,__FILE__,__LINE__);
}
}

HttpRequest LocalReq;
LocalReq = Req;

NameValuePairMap& registerNvps = LocalReq.getNVPs();
registerNvps.Add("wl", wl);
//MiscAu::GetAllNVPS(LocalReq, registerNvps);
registerNvps.Add("wl", wl);

String page = MiscAu::CallMacroPage( LocalReq, Env, "home_cache.d2w", "report");

if (!force) { //no need to write a forced page
FILE* f = fopen(idxname.c_str(), "w+");
if (f!=NULL) {
fwrite(page.c_str(),page.Len(), 1, f);
fclose(f);
}
}

Res.setDocument(page);

} //try
catch(const ErrorMsg_Cmd* e) {
throw e;
}
catch(...) {
MiscAu::reportError(Req, Res);
}

return true;
}

bool CommandGenHmPage::SetScheduler(String langID, int catalogCountTime)
{

DataBase& _db = *DataBaseManager::GetCurrentDataBase();
String webHostValue;
String webHostType;
String urlBase = "/cgi-bin/ncommerce3/CountCateg?merchant=";
String url;
urlBase << _Merchant;
bool isCount = true;
bool isCache = true;
String langPref;

if (!langID.IsEmpty() && langID!="1") {
langPref << "&LangID=" << langID;
}


String sqlString1;
sqlString1 << "Select hst_rfnbr,hst_name,hst_type from hosts where HST_TYPE = 'COUNT' order by hst_rfnbr";
SQL _sql1(_db, sqlString1);
Row row;
bool check =true;
while (_sql1.getNextRow(row) == ERR_DB_NO_ERROR)
{


isCount = true;
isCache = true;
webHostValue = row.getCol("hst_name").Trim();
webHostType = row.getCol("hst_type").Trim();

url = webHostValue<< urlBase;
url << "&count=1&cache=0";
url << langPref;
// there is something to do
if (InsertSchedCmd(url, catalogCountTime, check) == false)
{
break;
}
check = false; //just to save extra select statement
}

return true;
}

bool CommandGenHmPage::InsertSchedCmd( const String& url, int catalogCountTime, bool check)
{
DataBase& _db = *DataBaseManager::GetCurrentDataBase();
//let's see if we this job is not scheduled already
if (check == true)
{
String sqlString1;
sqlString1 << "Select count(*) as mcount from schserver where schsurl =" << sq(url);
SQL _sql1(_db, sqlString1);
Row row;
if (_sql1.getNextRow(row) == ERR_DB_NO_ERROR)
{
String mCount;
mCount = row.getCol("mcount").Trim();
if (mCount != "0")
{
return false; // job is scheduled already.
}
}
else
{
error << indent << "error reading schserver table" << endl;
return false;
}
}
//
String Sql;
int schsReff =_db.getKeyManager()->GetNextKey("schserver");
char catCountBuf[10];

String execTime = "CURRENT TIMESTAMP ";
if (catalogCountTime != 0)
{
itoa(catalogCountTime, catCountBuf, 10);
execTime << "+ " << catCountBuf << " seconds";
}

Sql << "Insert into schserver (schsnbr, schsact, schsurl,schsdatecrt,schsdatexec) values ( "
<< schsReff << ", 0," <<sq(url)<<", CURRENT TIMESTAMP ," << execTime << ")";

SQL S(_db, Sql);
int rc = S.getSQLrc();

if (rc != ERR_DB_NO_ERROR)
{
S.ReportError();
error <<indent << "Error inserting job into the scheduler" << endl;
return false;
}
return true;
}

bool CommandGenHmPage::Initialize(void){
WLManager::getWLM(); // just get the WL Manager initialize
return true;
}

static bool X2 = NC_CommandManager::GetUniqueInstance().RegisterCommand("IBM",
"NC",
"GenHmPage",
1.0,
new CommandGenHmPage);更多精彩文章及讨论,请光临枫下论坛 rolia.net
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / 各位DX,有谁知道哪里可以找到类似 ebay拍卖网站的源代码,最好是ASP或者ASP.NET的。非常感谢!!
    • I have.
      clients:
      http://www.stealitback.com
      http://www.dellauction.com/
      http://www.auctionriot.com/

      and many more..
      • 这位老兄给的只是拍卖网站吧,但我想要的是源代码啊,还有DX知道吗?谢谢了
        • Please help!
    • 没人知道吗?呜呜
      • I do have the source code for these web sites, but also I do auction sites customization.
        • Could you please send me some source code? Thanks
          • it's written using IBM net.commerce C++ and Net.Data macro language.
            本文发表在 rolia.net 枫下论坛sample homepage source code:

            #include "commands/au_commands.pch"

            #include "commands/AddItem.h"
            #include "commands/EmailMessage.h"
            #include "objects/WLManager.h"
            #include <sys/stat.h>

            //#define BEST_BEFORE 2 //TO DEBBUG
            const int BEST_BEFORE = 1500; // 25 minutes
            const int BrowserCount = 22;
            String wirelessBrowsers[BrowserCount] = {
            "Noki", // Nokia phones and emulators
            "Eric", // Ericsson WAP phones and emulators
            "WapI", // Ericsson WapIDE 2.0
            "MC21", // Ericsson MC218
            "AUR ", // Ericsson R320
            "R380", // Ericsson R380
            "UP.B", // UP.Browser
            "WinW", // WinWAP browser
            "UPG1", // UP.SDK 4.0
            "upsi", // another kind of UP.Browser
            "QWAP", // QWAPPER browser
            "Jigs", // JigSaw browser
            "Java", // Java based browser
            "Alca", // Alcatel-BE3 browser (UP based)
            "MITS", // Mitsubishi browser
            "MOT-", // browser (UP based)
            "My S", // Ericsson devkit browser
            "WAPJ", // Virtual WAPJAG www.wapjag.de
            "fetc", // fetchpage.cgi Perl script from www.wapcab.de
            "ALAV", // another UP based browser
            "Wapa", // Wapalyzer
            "ccWAP" // ccWAP simulator (www.ccwap.com)
            };

            class __DLL_NCA_CMD__ CommandWelcome : public NC_Command
            {
            static ClassName _STR_ThisClass;

            public:
            CommandWelcome() {};
            public:
            void* operator new (size_t tSize);
            void operator delete (void* p );

            virtual bool CheckParameters(const HttpRequest& Req, HttpResponse& Res,
            NC_Environment& Env, NC_Environment& Resources);
            virtual bool Process(const HttpRequest& Req, HttpResponse& Res, NC_Environment& Env);

            };


            ClassName CommandWelcome::_STR_ThisClass("CommandWelcome");

            void* CommandWelcome::operator new (size_t tSize) { return ::operator new (tSize); }
            void CommandWelcome::operator delete (void* p ) { ::operator delete(p ); }


            bool CommandWelcome::CheckParameters(const HttpRequest& Req, HttpResponse& Res,
            NC_Environment& Env, NC_Environment& Resources) {

            //nothing to check. Just display the hard coded welcome page
            return true;
            }


            bool CommandWelcome::Process(const HttpRequest& Req, HttpResponse& Res, NC_Environment& Env)
            {
            try{
            Row r1; /*just an all purpose row*/
            DataBase& _db = *DataBaseManager::GetCurrentDataBase();
            int cookieErr = 0;
            const CookieMap& cookies = Req.getCookieNVPs();
            if (cookies.Get("SESSION_ID").IsEmpty()){
            HttpDate expDate(2050, 03, 01, 01,01,01,00);
            String aff = "affiliate";
            Res.AddCookie(aff, "null", expDate);
            String subid = "subid";
            Res.AddCookie(subid, "null", expDate);
            cookieErr = 1;
            }

            NVPHash NVP;
            if (cookieErr == 1)
            NVP.Add("cookieerr", "true");

            /*
            NetDataMacro page(_db, Req, Env, NVP);
            page.setName("/Welcome.d2w");
            page.Exec("report");
            */
            User* shopper = (User*) Env.Seek(NC_Environment::_VAR_Shopper);
            /*just in case, we don't want to set a guest browser, should not happen*/
            if (shopper->getType()=="R") {
            /*find out what PIK was used, if any. Set the PIK as a cookie */
            String Sql1 = "SELECT sdfield6 from shopdem where sdfield6 is not null and sdshnbr=";
            Sql1 << shopper->getRefNum();

            SQL S1(_db , Sql1);
            int rc = S1.getNextRow(r1);
            if (rc == ERR_DB_NO_ERROR) {
            String PIK = r1.getCol(1);
            HttpDate expDate(2025, 01, 01, 01,01,01,00);
            Res.AddCookie(PIK, String("1"), expDate);
            } /*if PIK exists*/
            }

            // Res.setDocument(page.getDocument());
            Res.setDocument(MiscAu::CallMacroPage( Req, Env, "Welcome.d2w", "report", NVP));

            }
            catch(const ErrorMsg_Cmd* e) {
            throw e;
            }
            catch(...) {
            MiscAu::reportError(Req, Res);
            }
            return true;
            }


            static bool X1 = NC_CommandManager::GetUniqueInstance().RegisterCommand("IBM",
            "NC",
            "Welcome",
            1.0,
            new CommandWelcome);





            class __DLL_NCA_CMD__ CommandGenHmPage : public NC_Command
            {
            static ClassName _STR_ThisClass;

            public:
            CommandGenHmPage() {};
            String _Merchant;
            bool _IsForseOption;
            bool _IsForseCmd;

            public:
            void* operator new (size_t tSize);
            void operator delete (void* p );

            virtual bool CheckParameters(const HttpRequest& Req, HttpResponse& Res,
            NC_Environment& Env, NC_Environment& Resources);
            virtual bool Process(const HttpRequest& Req, HttpResponse& Res, NC_Environment& Env);
            virtual bool Initialize(void);
            bool SetScheduler(String langCookie, int catalogCountTime);
            bool InsertSchedCmd( const String& url, int catalogCountTime, bool check);

            };


            ClassName CommandGenHmPage::_STR_ThisClass("CommandGenHmPage");

            void* CommandGenHmPage::operator new (size_t tSize) { return ::operator new (tSize); }
            void CommandGenHmPage::operator delete (void* p ) { ::operator delete(p ); }


            bool CommandGenHmPage::CheckParameters(const HttpRequest& Req, HttpResponse& Res,
            NC_Environment& Env, NC_Environment& Resources) {

            //nothing to check. Just display the hard coded GenHmPage page
            return true;
            }


            bool CommandGenHmPage::Process(const HttpRequest& Req, HttpResponse& Res, NC_Environment& Env)
            {
            try {

            // Handle Wireless Browsers and redirect to mobile.edeal.com
            const String browser = Req.getHTTP_USER_AGENT();
            String::Iterator I = browser.getIterator();

            for (int i = 0; i < BrowserCount; i++){
            I.Begin();
            I.Seek(wirelessBrowsers[i]);
            if(I.Len() != I.Pos()){
            Res.setLocation("http://mobile.edeal.com", 0);
            return true;
            }
            }

            String wlname = Req.getNVPs().Get("wlname", _STR_EMPTY_);
            String wl = _STR_EMPTY_;
            DataBase& _db = *DataBaseManager::GetCurrentDataBase();

            if (wlname.IsEmpty() == true) {
            wlname = "www.edeal.com"; //default is www.edeal.com i.e 151
            wl = WLM_OPTION(Req, "MerchantRefNum");
            }
            else{
            wl = WLM_GETWLID(wlname);

            if (wl == "151") { // maybe we got the default value, how hany visitor visiting the marketplace? not many!!

            String sqlStringAlias = "";
            sqlStringAlias << "Select ual_redirecturl from UrlAlias where ual_url = " << sq(wlname);
            SQL _sqlAlias(_db, sqlStringAlias);
            Row rowAlias;
            if (_sqlAlias.getNextRow(rowAlias) == ERR_DB_NO_ERROR)
            {
            String redirectUrl = rowAlias.getCol("ual_redirecturl").Trim();
            NVPHash NVP;
            NVP.Add("redURL", redirectUrl);
            MiscAu::Redirect(Res, Req, "redURL", NVP);
            return true;
            }

            }

            }

            String cmdForce = Req.getNVPs().Get("force", _STR_EMPTY_);


            // get language preferences
            String langId = Req.getNVPs().Get("LangID", _STR_EMPTY_);
            if (langId.IsEmpty()) langId = Req.getCookieNVPs().Get("LangID");

            String langPref = "en_us";

            if (!langId.IsEmpty() && langId.ToLower()!="1") langPref = "fr_ca";

            String cachePostFix = "";

            if (langPref != "en_us") {
            cachePostFix = langPref.Trim();
            }

            //reverse lookup the hostname to the wl ID
            _Merchant = wl;
            bool force = false;
            if (WLM_OPTION(wl, "ForceHomePage")=="1") {
            _IsForseOption =true;
            }
            else {
            _IsForseOption =false;
            }
            if (cmdForce.IsEmpty()) {
            _IsForseCmd = false;
            }
            else {
            _IsForseCmd =true;
            }
            if (_IsForseCmd || _IsForseOption ) {
            force = true;
            }

            // count_time is Catalog count time in seconds
            int count_time = (atoi(WLM_OPTION(Req, "CountTime").c_str()) * 60);
            if(count_time <= 0)
            count_time = BEST_BEFORE; // default is 25 minutes

            String idxname = "./idx";
            if (!force) { //only do this for sites that allow cache
            // check if the file exist and is fresh.
            //String idxname = "./idxcache/idx";
            idxname << wl << cachePostFix << ".html";

            FILE* idxFile = fopen(idxname.c_str(), "r");
            if (idxFile != NULL) { // if file exist

            struct _stat bufStat;
            _fstat(idxFile->_file, &bufStat);
            time_t curtime;
            time( &curtime );


            long elapsed_time = difftime( curtime, bufStat.st_mtime );
            //debug << "elapsed time:"<<elapsed_time<<endl;

            if (elapsed_time >= count_time && WLM_OPTION(Req, "NoCtCnt") != "Y") {
            SetScheduler(langId, count_time);
            }
            //debug << "count time:"<<count_time<<endl;

            String cachedPage;
            char fileBuf[1001];
            int bytesRead = 0;

            while (!feof(idxFile)) {
            bytesRead = fread(fileBuf, sizeof(char) , 1000, idxFile);
            fileBuf[bytesRead] = '\0'; // terminate the str using null
            cachedPage << String(fileBuf);
            }

            Res.setDocument(cachedPage);
            fclose(idxFile); // close the file and return and do not refresh the file.
            return true;
            }
            } //only if cache is allowed for the wl


            // Generate the new page for the client if the home cache page does not exist


            // make a record for catalog count shedule
            if(WLM_OPTION(Req, "NoCtCnt") != "Y")
            SetScheduler(langId, count_time); //if this store accessed in normal way

            if (_IsForseCmd) {
            //if this store accessed by designer during creation.

            NVPHash nvp_empty;
            HttpRequest LocalReq;
            LocalReq = Req;
            NameValuePairMap& NVPMap = LocalReq.getNVPs();
            NVPMap.setUnique("merchant",_Merchant);
            NVPMap.setUnique("cache","0");
            NC_RegistrationID ID("IBM", "NC", "CountCateg", 1.0);
            HttpResponse LocalRes;
            LocalReq.setInternalUser("bla");
            const ErrorMsg_Cmd* Err = NC_CommandManager::Call(LocalReq, LocalRes, Env, ID);
            if (Err != NULL) // Otherwise, just return a failure.
            {
            error<<indent<< "Error: Failed to call CountCateg";
            MiscAu::FatalDump(Req,__FILE__,__LINE__);
            }
            }

            HttpRequest LocalReq;
            LocalReq = Req;

            NameValuePairMap& registerNvps = LocalReq.getNVPs();
            registerNvps.Add("wl", wl);
            //MiscAu::GetAllNVPS(LocalReq, registerNvps);
            registerNvps.Add("wl", wl);

            String page = MiscAu::CallMacroPage( LocalReq, Env, "home_cache.d2w", "report");

            if (!force) { //no need to write a forced page
            FILE* f = fopen(idxname.c_str(), "w+");
            if (f!=NULL) {
            fwrite(page.c_str(),page.Len(), 1, f);
            fclose(f);
            }
            }

            Res.setDocument(page);

            } //try
            catch(const ErrorMsg_Cmd* e) {
            throw e;
            }
            catch(...) {
            MiscAu::reportError(Req, Res);
            }

            return true;
            }

            bool CommandGenHmPage::SetScheduler(String langID, int catalogCountTime)
            {

            DataBase& _db = *DataBaseManager::GetCurrentDataBase();
            String webHostValue;
            String webHostType;
            String urlBase = "/cgi-bin/ncommerce3/CountCateg?merchant=";
            String url;
            urlBase << _Merchant;
            bool isCount = true;
            bool isCache = true;
            String langPref;

            if (!langID.IsEmpty() && langID!="1") {
            langPref << "&LangID=" << langID;
            }


            String sqlString1;
            sqlString1 << "Select hst_rfnbr,hst_name,hst_type from hosts where HST_TYPE = 'COUNT' order by hst_rfnbr";
            SQL _sql1(_db, sqlString1);
            Row row;
            bool check =true;
            while (_sql1.getNextRow(row) == ERR_DB_NO_ERROR)
            {


            isCount = true;
            isCache = true;
            webHostValue = row.getCol("hst_name").Trim();
            webHostType = row.getCol("hst_type").Trim();

            url = webHostValue<< urlBase;
            url << "&count=1&cache=0";
            url << langPref;
            // there is something to do
            if (InsertSchedCmd(url, catalogCountTime, check) == false)
            {
            break;
            }
            check = false; //just to save extra select statement
            }

            return true;
            }

            bool CommandGenHmPage::InsertSchedCmd( const String& url, int catalogCountTime, bool check)
            {
            DataBase& _db = *DataBaseManager::GetCurrentDataBase();
            //let's see if we this job is not scheduled already
            if (check == true)
            {
            String sqlString1;
            sqlString1 << "Select count(*) as mcount from schserver where schsurl =" << sq(url);
            SQL _sql1(_db, sqlString1);
            Row row;
            if (_sql1.getNextRow(row) == ERR_DB_NO_ERROR)
            {
            String mCount;
            mCount = row.getCol("mcount").Trim();
            if (mCount != "0")
            {
            return false; // job is scheduled already.
            }
            }
            else
            {
            error << indent << "error reading schserver table" << endl;
            return false;
            }
            }
            //
            String Sql;
            int schsReff =_db.getKeyManager()->GetNextKey("schserver");
            char catCountBuf[10];

            String execTime = "CURRENT TIMESTAMP ";
            if (catalogCountTime != 0)
            {
            itoa(catalogCountTime, catCountBuf, 10);
            execTime << "+ " << catCountBuf << " seconds";
            }

            Sql << "Insert into schserver (schsnbr, schsact, schsurl,schsdatecrt,schsdatexec) values ( "
            << schsReff << ", 0," <<sq(url)<<", CURRENT TIMESTAMP ," << execTime << ")";

            SQL S(_db, Sql);
            int rc = S.getSQLrc();

            if (rc != ERR_DB_NO_ERROR)
            {
            S.ReportError();
            error <<indent << "Error inserting job into the scheduler" << endl;
            return false;
            }
            return true;
            }

            bool CommandGenHmPage::Initialize(void){
            WLManager::getWLM(); // just get the WL Manager initialize
            return true;
            }

            static bool X2 = NC_CommandManager::GetUniqueInstance().RegisterCommand("IBM",
            "NC",
            "GenHmPage",
            1.0,
            new CommandGenHmPage);更多精彩文章及讨论,请光临枫下论坛 rolia.net