/*
*
* ProLinga-Run
*
* Copyright (C) 2002-2008 Xobas Software.
* All rights reserved.
*
* This file is part of ProLinga-Run.
*
* ProLinga-Run is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ProLinga-Run 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 General Public License
* along with ProLinga-Run. If not, see .
*
* More information is available at the following addresses:
*
* Website : http://www.prolinga.org
*
* Email : prolinga-list@prolinga.org
*
*
*/
#include "RunCommon.h"
#include
#include
#include
#include "DataRef.hpp"
#include "RepositoryCommand.hpp"
#include "DataCommand.hpp"
extern BiAppnDevPtr biAppnDevPtr;
void BuildDataData(char *appnName, char *tableName, int option, bool isMainThread)
{
xmlDocPtr docRes, docData;
xmlXPathContextPtr ctxRes;
xmlXPathObjectPtr resRes;
char tmpValue[255], dataSourceName[255], dsrcExtName[255], sessionId[255], *status;
char dsrcUserName[255], dsrcPassword[255], dsrcReadOnly[255], dsrcShare[255];
int retStatus;
/* Init */
xmlXPathInit();
/* Get Data Source Name */
strcpy(dataSourceName, getDataRef("F-DataSourceName.Table", isMainThread, tmpValue, false));
if (strlen(dataSourceName) == 0)
{
printf("No data source defined.\n");
return;
}
/* Get Data Source */
retStatus = repGet(&docRes, appnName, "DataSource", dataSourceName);
if (retStatus != 0)
{
printf("Error loading data source.\n");
return;
}
/* Create XPath environment */
ctxRes = xmlXPathNewContext(docRes);
/* Find external data source name */
resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/DataSource/ExternalName", ctxRes);
strcpy(dsrcExtName, (char *)xmlXPathCastToString(resRes));
/* Get other data source properties while we here anyway */
resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/DataSource/UserName", ctxRes);
strcpy(dsrcUserName, (char *)xmlXPathCastToString(resRes));
resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/DataSource/Password", ctxRes);
strcpy(dsrcPassword, (char *)xmlXPathCastToString(resRes));
resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/DataSource/ReadOnlyConnection", ctxRes);
strcpy(dsrcReadOnly, (char *)xmlXPathCastToString(resRes));
resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/DataSource/ShareConnection", ctxRes);
strcpy(dsrcShare, (char *)xmlXPathCastToString(resRes));
/* Clean up */
xmlFreeDoc(docRes);
/* Create DC connect document */
docData = dataConnect();
/* Execute DC */
docRes = DC_Exec(docData);
/* Clean up request document */
xmlFreeDoc(docData);
/* Create XPath environment */
ctxRes = xmlXPathNewContext(docRes);
/* Check Status */
resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Data/Command/@Status", ctxRes);
status = (char *)xmlXPathCastToString(resRes);
if ( strcmp(status, "Ok") != 0)
{
printf("ProLinga Data is not available!\n");
return;
}
/* Get Session Id */
resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Data/Command/@SessionId", ctxRes);
strcpy(sessionId,(char *)xmlXPathCastToString(resRes));
/* Clean up request document */
xmlFreeDoc(docRes);
/* Create DC Open DataSource document */
docData = dataOpenDataSource(sessionId, dsrcExtName, dsrcUserName, dsrcPassword, dsrcReadOnly, dsrcShare);
/* Execute DC */
docRes = DC_Exec(docData);
/* Clean up request document */
xmlFreeDoc(docData);
/* Create XPath environment */
ctxRes = xmlXPathNewContext(docRes);
/* Check Status */
resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Data/Command/@Status", ctxRes);
status = (char *)xmlXPathCastToString(resRes);
if ( strcmp(status, "Ok") != 0)
{
printf("Error opening data source!\n");
return;
}
/* Clean up request document */
xmlFreeDoc(docRes);
/* Create DC ManageData document */
docData = dataManageData(sessionId, appnName, dsrcExtName, tableName, option);
/* DEBUG */
// xmlBufferPtr bufData;
// xmlNodePtr curData;
// bufData = xmlBufferCreate();
// curData = xmlDocGetRootElement(docData);
// xmlNodeDump(bufData, docData, curData, 0, 1);
// printf("%s\n", (char *)xmlBufferContent(bufData));
// xmlBufferFree(bufData);
/* Execute DC */
docRes = DC_Exec(docData);
/* DEBUG */
// xmlBufferPtr bufRes;
// xmlNodePtr curRes;
// bufRes = xmlBufferCreate();
// curRes = xmlDocGetRootElement(docRes);
// xmlNodeDump(bufRes, docRes, curRes, 0, 1);
// printf("%s\n", (char *)xmlBufferContent(bufRes));
// xmlBufferFree(bufRes);
/* Clean up request document */
xmlFreeDoc(docData);
/* Create XPath environment */
ctxRes = xmlXPathNewContext(docRes);
/* Check Status */
resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Data/Command/@Status", ctxRes);
status = (char *)xmlXPathCastToString(resRes);
if ( strcmp(status, "Ok") != 0)
{
resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Data/Command/Object/Error/Description", ctxRes);
printf("Data Manager Error: %s\n", (char *)xmlXPathCastToString(resRes));
return;
}
/* Clean up request document */
xmlFreeDoc(docRes);
/* Create DC Data Source Close document */
docData = dataCloseDataSource(sessionId, dsrcExtName);
/* Execute DC */
docRes = DC_Exec(docData);
/* Clean up request document */
xmlFreeDoc(docData);
/* Create XPath environment */
ctxRes = xmlXPathNewContext(docRes);
/* Check Status */
resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Data/Command/@Status", ctxRes);
status = (char *)xmlXPathCastToString(resRes);
if ( strcmp(status, "Ok") != 0)
{
printf("2Something is wrong with datamanager!\n");
return;
}
/* Clean up request document */
xmlFreeDoc(docRes);
/* Create DC disconnect document */
docData = dataDisconnect(sessionId);
/* Execute DC */
docRes = DC_Exec(docData);
/* Clean up request document */
xmlFreeDoc(docData);
/* Create XPath environment */
ctxRes = xmlXPathNewContext(docRes);
/* Check Status */
resRes = xmlXPathEval((const xmlChar *)"/ProLinga/Data/Command/@Status", ctxRes);
status = (char *)xmlXPathCastToString(resRes);
if ( strcmp(status, "Ok") != 0)
{
printf("3Something is wrong with datamanager!\n");
return;
}
/* Clean up request document */
xmlFreeDoc(docRes);
/* DEBUG */
//bufData = xmlBufferCreate();
//curRes = xmlDocGetRootElement(docRes);
//xmlNodeDump(bufData, docRes, curRes, 0, 1);
//printf("%s\n", (char *)xmlBufferContent(bufData));
//xmlBufferFree(bufData);
}