`
dato0123
  • 浏览: 913668 次
文章分类
社区版块
存档分类
最新评论

一个RSS阅读器类

 
阅读更多


classCFeedItem
{//RSS条目
public:
CFeedItem();
virtual~CFeedItem();
public:
CStringm_strAuthor;
//作者
CStringm_strCategory;//类别
CStringm_strDescription;//描述信息
CStringm_strLink;//链接地址
CStringm_strPubDate;//发布日期
CStringm_strSubject;//主题
CStringm_strTitle;//标题
CStringm_strReadStatus;//是否已读
}
;


classCFeedSource
{//RSS源
public:
CFeedSource();
virtual~CFeedSource();

public:
CStringm_strCopyright;
//版权
CStringm_strDescription;//描述信息
CStringm_strGenerator;//生产者
CStringm_strLanguage;//语言
CStringm_strLastBuildDate;//上次构建日期
CStringm_strLink;//链接地址
CStringm_strTitle;//标题
CStringm_strTtl;
CStringm_strWebMaster;
//管理员
CStringm_strImageDescription;//图片描述信息
CStringm_strImageHeight;//图片高度
CStringm_strImageWidth;//图片宽度
CStringm_strImageLink;//图片链接地址
CStringm_strImageTitle;//图片标题
CStringm_strImageUrl;//图片Url
CStringm_strVersion;//图片版本
}
;


classCFeed
{//RSS种子
public:
CFeed();
CFeed(CStringstrXMLFile);
virtual~CFeed();
public:
staticvoidRefreshAll();
staticvoidMarkItemRead(CStringstrLink);
staticvoidDeleteFeedSource(CStringstrLink);
staticvoidDeleteListArray(CStringArray&strLinkArray);
staticvoidGetFeedSourceList(CStringArray&strTitleArray,CStringArray&strLinkArray);
voidLoadLocal(CString&strLink);
voidBuildFromFile(CStringstrXMLFile);
CFeedSourcem_source;
//FeedSource
CArray<CFeedItem,CFeedItem>m_item;//FeedItem
BOOLm_bAdded;
voidSave(BOOLbSaveSource=TRUE);
private:
staticCStringEscapeQuote(CStringstrValue);
staticCStringGetModuleFileDir();
staticCStringGetFieldValue(FieldsPtrfields,longnIndex);
staticCStringGetComError(_com_error&e);
staticBOOLExecuteSQL(_ConnectionPtr&pCnn,CString&strSQL,CString&strMsg);
voidGetVersion(MSXML2::IXMLDOMNode*pNode);
voidIterateChildNodes(MSXML2::IXMLDOMNode*pNode);
voidBuildImage(MSXML2::IXMLDOMNode*pNode);
voidBuildItem(MSXML2::IXMLDOMNode*pNode);
MSXML2::IXMLDOMDocument2
*m_pDoc;//XMLDOMDocument
intm_nDepth;
}
;




//FeedSource.cpp:implementationoftheCFeedSourceclass.
//
/**///////////////////////////////////////////////////////////////////////

#include
"stdafx.h"
#include
"AgileReader.h"
#include
"FeedSource.h"

#ifdef_DEBUG
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#definenewDEBUG_NEW
#endif

/**///////////////////////////////////////////////////////////////////////
//Construction/Destruction
/**///////////////////////////////////////////////////////////////////////
CFeedItem::CFeedItem()
{
}


CFeedItem::
~CFeedItem()
{
}


CFeedSource::CFeedSource()
{

}


CFeedSource::
~CFeedSource()
{

}


CFeed::CFeed()
{
m_pDoc
=NULL;
m_nDepth
=0;
m_bAdded
=FALSE;
}


CFeed::CFeed(CStringstrXMLFile)
{
m_pDoc
=NULL;
m_nDepth
=0;
m_bAdded
=FALSE;
BuildFromFile(strXMLFile);
}


CFeed::
~CFeed()
{

}


/**//////////////////////////////////////////////////////////////////////////////
//BuildXMLFeedInformationfromanXMLFile
//
//strXMLFile:ParsedinXMLFileName
//ThisfunctionwillbuildFeedObjectfromscratchbyparsingXMLFeedInformation
//Resultisstoredinm_sourceandm_itemobjects
//
voidCFeed::BuildFromFile(CStringstrXMLFile)
{
CStringstrTmpFile
=GetModuleFileDir()+_T("//AgileReader.xml");

//Step0.DownloadXMLFile
if(URLDownloadToFile(NULL,strXMLFile,strTmpFile,0,NULL)!=S_OK)
{//下载XML文件
AfxMessageBox(_T("Failedtodownload")+strXMLFile);
return;
}



//Step1.OpenXMLDocument,ifopenfails,thenreturn
if(m_pDoc!=NULL)
{
m_pDoc
->Release();
m_pDoc
=NULL;
}

if(SUCCEEDED(CoCreateInstance(MSXML2::CLSID_DOMDocument,
NULL,
CLSCTX_INPROC_SERVER,
MSXML2::IID_IXMLDOMDocument,
reinterpret_cast
<void**>(&m_pDoc))))

m_pDoc
->put_async(VARIANT_FALSE);
if(m_pDoc->load(_bstr_t(strTmpFile))==VARIANT_FALSE)
{//加载XML文档
//FailedtoloadXMLDocument,reporterrormessage
AfxMessageBox(_T("FailedtoloadXMLDocument"));
return;
}


//Step2.Getversionpropertyifitisavailable
//Step3.Iteratetochannelnode,getthefollowingchilditems
//title
//link
//description
//language
//copyright
//webMaster
//lastBuildDate
//ttl
//generator
//Thengotoimagenode,getthefollowingitems
//title
//url
//link
//width
//height
//description

//Step4.gotoitemnode,getthefollowingitems
//title
//description
//link
//author
//category
//pubDate
//subject
MSXML2::IXMLDOMNode*pNode=NULL;
if(SUCCEEDED(m_pDoc->QueryInterface(MSXML2::IID_IXMLDOMNode,
reinterpret_cast
<void**>(&pNode))))
{
IterateChildNodes(pNode);
pNode
->Release();
pNode
=NULL;
}


//Wearenotusingsmartpointer,sowehavetoreleaseitoutself
if(m_pDoc)
{
m_pDoc
->Release();
m_pDoc
=NULL;
}

}


/**//////////////////////////////////////////////////////////////////////////////
//GetFeedVersionInformation
//
voidCFeed::GetVersion(MSXML2::IXMLDOMNode*pNode)
{
}


/**//////////////////////////////////////////////////////////////////////////////
//IterateChildNode
//
voidCFeed::IterateChildNodes(MSXML2::IXMLDOMNode*pNode)
{//迭代访问所有子节点
BSTRbstrNodeName;

if(pNode)
{
m_nDepth
++;
CStringstrOutput;
pNode
->get_nodeName(&bstrNodeName);

//
//Findoutthenodetype(asastring).
//
BSTRbstrNodeType;
pNode
->get_nodeTypeString(&bstrNodeType);
CStringstrType;
strType
=CString(bstrNodeType);
SysFreeString(bstrNodeType);

MSXML2::DOMNodeTypeeEnum;
pNode
->get_nodeType(&eEnum);

CStringstrValue;
BSTRbstrValue;
switch(eEnum)
{
caseMSXML2::NODE_TEXT:
{
//TextstringintheXMLdocument
BSTRbstrValue;
pNode
->get_text(&bstrValue);
strOutput
=CString(bstrValue);
SysFreeString(bstrValue);
break;
}

caseMSXML2::NODE_COMMENT:
{
//CommentintheXMLdocument
VARIANTvValue;
pNode
->get_nodeValue(&vValue);
VariantClear(
&vValue);
break;
}

caseMSXML2::NODE_PROCESSING_INSTRUCTION:
{
//Processinginstruction
strOutput=CString(bstrNodeName);
break;
}

caseMSXML2::NODE_ELEMENT:
{
//Element
strOutput=CString(bstrNodeName);
if(strOutput==_T("rss"))
{
GetVersion(pNode);
}

elseif(strOutput==_T("copyright"))
{
pNode
->get_text(&bstrValue);
m_source.m_strCopyright
=CString(bstrValue);
}

elseif(strOutput==_T("title")&&m_nDepth==4)
{
pNode
->get_text(&bstrValue);
m_source.m_strTitle
=CString(bstrValue);
}

elseif(strOutput==_T("link")&&m_nDepth==4)
{
pNode
->get_text(&bstrValue);
m_source.m_strLink
=CString(bstrValue);
}

elseif(strOutput==_T("description")&&m_nDepth==4)
{
pNode
->get_text(&bstrValue);
m_source.m_strDescription
=CString(bstrValue);
}

elseif(strOutput==_T("language"))
{
pNode
->get_text(&bstrValue);
m_source.m_strLanguage
=CString(bstrValue);
}

elseif(strOutput==_T("webMaster"))
{
pNode
->get_text(&bstrValue);
m_source.m_strWebMaster
=CString(bstrValue);
}

elseif(strOutput==_T("lastBuildDate"))
{
pNode
->get_text(&bstrValue);
m_source.m_strLastBuildDate
=CString(bstrValue);
}

elseif(strOutput==_T("ttl"))
{
pNode
->get_text(&bstrValue);
m_source.m_strTtl
=CString(bstrValue);
}

elseif(strOutput==_T("generator"))
{
pNode
->get_text(&bstrValue);
m_source.m_strGenerator
=CString(bstrValue);
}

elseif(strOutput==_T("image"))
{
BuildImage(pNode);
}

elseif(strOutput==_T("item"))
{
BuildItem(pNode);
}

break;
}

caseMSXML2::NODE_DOCUMENT:
{
//Document
strOutput=CString(bstrNodeName)+_T("-")+CString(strType);
break;
}

caseMSXML2::NODE_DOCUMENT_TYPE:
{
//DocumentType
strOutput=CString(bstrNodeName)+_T("-")+CString(strType);
break;
}

caseMSXML2::NODE_DOCUMENT_FRAGMENT:
{
//DocumentFragment
strOutput=CString(bstrNodeName)+_T("-")+CString(strType);
break;
}

caseMSXML2::NODE_NOTATION:
{
//Notation
strOutput=CString(bstrNodeName)+_T("-")+CString(strType);
break;
}

caseMSXML2::NODE_ENTITY:
{
//Entity
strOutput=CString(bstrNodeName)+_T("-")+CString(strType);
break;
}

caseMSXML2::NODE_ENTITY_REFERENCE:
{
//EntityReference
strOutput=CString(bstrNodeName)+_T("-")+CString(strType);
}

caseMSXML2::NODE_CDATA_SECTION:
{
//CDatasection
strOutput=CString(bstrNodeName)+_T("-")+CString(strType);
}

}

SysFreeString(bstrNodeName);
}


//
//Anychildnodesofthisnodeneeddisplayingtoo.
//
MSXML2::IXMLDOMNode*pNext=NULL;
MSXML2::IXMLDOMNode
*pChild;
pNode
->get_firstChild(&pChild);
while(pChild)
{//递归遍历子节点
IterateChildNodes(pChild);
pChild
->get_nextSibling(&pNext);
pChild
->Release();
pChild
=pNext;
}

m_nDepth
--;//递归深度减
}


/**//////////////////////////////////////////////////////////////////////////////
//BuildImageSection
//
voidCFeed::BuildImage(MSXML2::IXMLDOMNode*pNode)
{
MSXML2::IXMLDOMNode
*pNext=NULL;
MSXML2::IXMLDOMNode
*pChild;
CStringstrOutput;
BSTRbstrNodeName;
BSTRbstrValue;
pNode
->get_firstChild(&pChild);
while(pChild)
{
pChild
->get_nodeName(&bstrNodeName);
strOutput
=CString(bstrNodeName);
if(strOutput==_T("title"))
{
pChild
->get_text(&bstrValue);
m_source.m_strImageTitle
=CString(bstrValue);
}

elseif(strOutput==_T("url"))
{
pChild
->get_text(&bstrValue);
m_source.m_strImageUrl
=CString(bstrValue);
}

elseif(strOutput==_T("link"))
{
pChild
->get_text(&bstrValue);
m_source.m_strImageLink
=CString(bstrValue);
}

elseif(strOutput==_T("width"))
{
pChild
->get_text(&bstrValue);
m_source.m_strImageWidth
=CString(bstrValue);
}

elseif(strOutput==_T("height"))
{
pChild
->get_text(&bstrValue);
m_source.m_strImageHeight
=CString(bstrValue);
}

elseif(strOutput==_T("description"))
{
pChild
->get_text(&bstrValue);
m_source.m_strImageDescription
=CString(bstrValue);
}


pChild
->get_nextSibling(&pNext);
pChild
->Release();
pChild
=pNext;
}

}


/**//////////////////////////////////////////////////////////////////////////////
//BuildItemSection
//
voidCFeed::BuildItem(MSXML2::IXMLDOMNode*pNode)
{
MSXML2::IXMLDOMNode
*pNext=NULL;
MSXML2::IXMLDOMNode
*pChild;
CStringstrOutput;
BSTRbstrNodeName;
CFeedItemitem;
BSTRbstrValue;
pNode
->get_firstChild(&pChild);
while(pChild)
{
pChild
->get_nodeName(&bstrNodeName);
strOutput
=CString(bstrNodeName);
if(strOutput==_T("title"))
{
pChild
->get_text(&bstrValue);
item.m_strTitle
=CString(bstrValue);
}

elseif(strOutput==_T("description"))
{
pChild
->get_text(&bstrValue);
item.m_strDescription
=CString(bstrValue);
}

elseif(strOutput==_T("link"))
{
pChild
->get_text(&bstrValue);
item.m_strLink
=CString(bstrValue);
}

elseif(strOutput==_T("author"))
{
pChild
->get_text(&bstrValue);
item.m_strAuthor
=CString(bstrValue);
}

elseif(strOutput==_T("category"))
{
pChild
->get_text(&bstrValue);
item.m_strCategory
=CString(bstrValue);
}

elseif(strOutput==_T("pubDate"))
{
pChild
->get_text(&bstrValue);
item.m_strPubDate
=CString(bstrValue);
}

elseif(strOutput==_T("subject"))
{
pChild
->get_text(&bstrValue);
item.m_strSubject
=CString(bstrValue);
}


pChild
->get_nextSibling(&pNext);
pChild
->Release();
pChild
=pNext;
}

m_item.Add(item);
}


/**//////////////////////////////////////////////////////////////////////////////
//SaveFeedInformationintoDatabase
//
voidCFeed::Save(BOOLbSaveSource/**//*=TRUE*/)
{//保持RSS种子信息倒数据库种
_ConnectionPtrpCnn=NULL;
CStringstrSQL;
CStringstrMsg;
intnIndex;

//Step1.Createobject
pCnn.CreateInstance(__uuidof(Connection));
if(pCnn==NULL)
{
AfxMessageBox(_T(
"Cannotcreateconnectionobject,pleaseinstallMDAC!"));
return;
}


//Step2.Openconnection
try
{
CStringstrCnn;
strCnn.Format(_T(
"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=%s//AgileReader.mdb;JetOLEDB:DatabasePassword=philips;"),GetModuleFileDir());
pCnn
->Open(_bstr_t(strCnn),"","",adConnectUnspecified);
}

catch(_com_error&e)
{
AfxMessageBox(_T(
"Cannotopenconnection:/n")+GetComError(e));
pCnn.Release();
return;
}


//Step3.ExecuteInsertStatementonFeedSource
//Indoubleclickcase,wedon'twanttosavethis
if(bSaveSource)
{
strSQL.Format(_T(
"insertintoFeedSource(FeedLink,description,title,version,copyright,generator,feedlanguage,lastbuilddate,ttl,webmaster,imagedescription,imageheight,imagewidth,imagelink,imagetitle,imageurl)values('%s','%s','%s','%s','%s','%s','%s','%s',%d,'%s','%s','%s','%s','%s','%s','%s')"),
EscapeQuote(m_source.m_strLink),
EscapeQuote(m_source.m_strDescription),
EscapeQuote(m_source.m_strTitle),
_T(
"2.0"),
EscapeQuote(m_source.m_strCopyright),
EscapeQuote(m_source.m_strGenerator),
EscapeQuote(m_source.m_strLanguage),
EscapeQuote(m_source.m_strLastBuildDate),
EscapeQuote(m_source.m_strTtl),
EscapeQuote(m_source.m_strWebMaster),
EscapeQuote(m_source.m_strImageDescription),
EscapeQuote(m_source.m_strImageHeight),
EscapeQuote(m_source.m_strImageWidth),
EscapeQuote(m_source.m_strImageLink),
EscapeQuote(m_source.m_strImageTitle),
EscapeQuote(m_source.m_strImageUrl));
if(!ExecuteSQL(pCnn,strSQL,strMsg))
{
//AfxMessageBox(strMsg+strSQL);
}

else
{
m_bAdded
=TRUE;
}

}


//Step4.ExecuteInsertStatementonFeedItem
for(nIndex=0;nIndex<m_item.GetSize();nIndex++)
{
strSQL.Format(_T(
"insertintoFeedItem(FeedLink,title,link,description,pubdate,author,category,subject)values('%s','%s','%s','%s','%s','%s','%s','%s')"),
EscapeQuote(m_source.m_strLink),
EscapeQuote(m_item[nIndex].m_strTitle),
EscapeQuote(m_item[nIndex].m_strLink),
EscapeQuote(m_item[nIndex].m_strDescription),
EscapeQuote(m_item[nIndex].m_strPubDate),
EscapeQuote(m_item[nIndex].m_strAuthor),
EscapeQuote(m_item[nIndex].m_strCategory),
EscapeQuote(m_item[nIndex].m_strSubject)
);
if(!ExecuteSQL(pCnn,strSQL,strMsg))
{
//AfxMessageBox(strMsg+strSQL);
}

}


pCnn.Release();
}


/**//////////////////////////////////////////////////////////////////////////////
//ExecuteSQLStatementandreturnerrormessageifany
//
BOOLCFeed::ExecuteSQL(_ConnectionPtr&pCnn,CString&strSQL,CString&strMsg)
{
try
{
pCnn
->Execute(_bstr_t(strSQL),NULL,adCmdText);
}

catch(_com_error&e)
{
strMsg
=GetComError(e);
returnFALSE;
}

returnTRUE;
}


/**//////////////////////////////////////////////////////////////////////////////
//RetrieveComErrorInformation
//
CStringCFeed::GetComError(_com_error&e)
{
CStringstrMsg;

_bstr_tbstrSource(e.Source());
_bstr_tbstrDescription(e.Description());

strMsg.Format(_T(
"Code=%08lx/nCodemeaning=%s/nSource=%s/nDescription=%s"),
e.Error(),
e.ErrorMessage(),
(LPCSTR)bstrSource,
(LPCSTR)bstrDescription);
returnstrMsg;
}


/**//////////////////////////////////////////////////////////////////////////////
//LoadFeedInformationfromdatabase
//
voidCFeed::LoadLocal(CString&strLink)
{//从数据库中读取RSS种子信息
_ConnectionPtrpCnn=NULL;
CStringstrSQL;
CStringstrMsg;
_RecordsetPtrrs
=NULL;

//Step1.Createobject
pCnn.CreateInstance(__uuidof(Connection));
if(pCnn==NULL)
{
AfxMessageBox(_T(
"Cannotcreateconnectionobject,pleaseinstallMDAC!"));
return;
}


//Step2.Openconnection
try
{
CStringstrCnn;
strCnn.Format(_T(
"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=%s//AgileReader.mdb;JetOLEDB:DatabasePassword=philips;"),GetModuleFileDir());
pCnn
->Open(_bstr_t(strCnn),"","",adConnectUnspecified);
}

catch(_com_error&e)
{
AfxMessageBox(_T(
"Cannotopenconnection:/n")+GetComError(e));
pCnn.Release();
return;
}


//Step3.ReadFeedSourceandpopulateitintom_sourceobject
strSQL.Format(_T("select*fromFeedSourcewhereFeedLink='%s'"),strLink);
try
{
rs
=pCnn->Execute(_bstr_t(strSQL),NULL,adCmdText);
if(rs!=NULL&&rs->adoEOF!=TRUE)
{
m_source.m_strLink
=strLink;
m_source.m_strDescription
=GetFieldValue(rs->Fields,1);
m_source.m_strTitle
=GetFieldValue(rs->Fields,2);
m_source.m_strVersion
=GetFieldValue(rs->Fields,3);
m_source.m_strCopyright
=GetFieldValue(rs->Fields,4);
m_source.m_strGenerator
=GetFieldValue(rs->Fields,5);
m_source.m_strLanguage
=GetFieldValue(rs->Fields,6);
m_source.m_strLastBuildDate
=GetFieldValue(rs->Fields,7);
m_source.m_strTtl
=GetFieldValue(rs->Fields,8);
m_source.m_strWebMaster
=GetFieldValue(rs->Fields,9);
m_source.m_strImageDescription
=GetFieldValue(rs->Fields,10);
m_source.m_strImageHeight
=GetFieldValue(rs->Fields,11);
m_source.m_strImageWidth
=GetFieldValue(rs->Fields,12);
m_source.m_strImageLink
=GetFieldValue(rs->Fields,13);
m_source.m_strImageTitle
=GetFieldValue(rs->Fields,14);
m_source.m_strImageUrl
=GetFieldValue(rs->Fields,15);
}

}

catch(_com_error&e)
{
AfxMessageBox(GetComError(e));
}

rs.Release();
rs
=NULL;

//Step4.ReadFeedItemandpopulateitintom_itemobject
strSQL.Format(_T("select*fromFeedItemwhereFeedLink='%s'orderbypubDatedesc,titleasc"),strLink);
try
{
rs
=pCnn->Execute(_bstr_t(strSQL),NULL,adCmdText);
while(rs!=NULL&&rs->adoEOF!=TRUE)
{
if(rs->adoEOF)
{
break;
}

CFeedItemitem;
item.m_strTitle
=GetFieldValue(rs->Fields,1);
item.m_strLink
=GetFieldValue(rs->Fields,2);
item.m_strDescription
=GetFieldValue(rs->Fields,3);
item.m_strPubDate
=GetFieldValue(rs->Fields,4);
item.m_strAuthor
=GetFieldValue(rs->Fields,5);
item.m_strCategory
=GetFieldValue(rs->Fields,6);
item.m_strSubject
=GetFieldValue(rs->Fields,7);
item.m_strReadStatus
=GetFieldValue(rs->Fields,8);
m_item.Add(item);
rs
->MoveNext();
if(rs->adoEOF)
{
break;
}

}

}

catch(_com_error&e)
{
AfxMessageBox(GetComError(e));
}

rs.Release();
rs
=NULL;

pCnn.Release();
pCnn
=NULL;
}


/**//////////////////////////////////////////////////////////////////////////////
//GetFieldValue
//
CStringCFeed::GetFieldValue(FieldsPtrfields,longnIndex)
{
_variant_tvt
=fields->GetItem(nIndex)->Value;
if(vt.vt==VT_NULL||vt.vt==VT_EMPTY)
{
return_T("");
}

returnCString((char*)_bstr_t(vt));
}


voidCFeed::GetFeedSourceList(CStringArray&strTitleArray,CStringArray&strLinkArray)
{
_ConnectionPtrpCnn
=NULL;
CStringstrSQL;
CStringstrMsg;
_RecordsetPtrrs
=NULL;

//Step1.Createobject
pCnn.CreateInstance(__uuidof(Connection));
if(pCnn==NULL)
{
AfxMessageBox(_T(
"Cannotcreateconnectionobject,pleaseinstallMDAC!"));
return;
}


//Step2.Openconnection
try
{
CStringstrCnn;
strCnn.Format(_T(
"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=%s//AgileReader.mdb;JetOLEDB:DatabasePassword=philips;"),GetModuleFileDir());
pCnn
->Open(_bstr_t(strCnn),"","",adConnectUnspecified);
}

catch(_com_error&e)
{
AfxMessageBox(_T(
"Cannotopenconnection:/n")+GetComError(e));
pCnn.Release();
return;
}


//Step3.ReadFeedSourceandpopulateitintom_sourceobject
strSQL=_T("selectdistincttitle,FeedLinkfromFeedSourceorderbytitle");
try
{
rs
=pCnn->Execute(_bstr_t(strSQL),NULL,adCmdText);
while(rs!=NULL&&rs->adoEOF!=TRUE&&rs->BOF!=TRUE)
{
if(rs->adoEOF)
{
break;
}

strTitleArray.Add(GetFieldValue(rs
->Fields,0));
strLinkArray.Add(GetFieldValue(rs
->Fields,1));
rs
->MoveNext();
}

}

catch(_com_error&e)
{
AfxMessageBox(GetComError(e));
}

rs.Release();
rs
=NULL;
pCnn.Release();
}


/**//////////////////////////////////////////////////////////////////////////////
//GetModuleFilePath
//
CStringCFeed::GetModuleFileDir()
{//获取模块文件路径
DWORDdwLength,dwSize;
TCHARszFileName[MAX_PATH];
CStringstrFileName;
intnPos;

dwSize
=sizeof(szFileName)/sizeof(szFileName[0]);
dwLength
=::GetModuleFileName(AfxGetInstanceHandle(),szFileName,dwSize);
if(dwLength<=0)
{
return_T("");
}


strFileName
=szFileName;
nPos
=strFileName.ReverseFind('//');
returnstrFileName.Left(nPos);
}


/**//////////////////////////////////////////////////////////////////////////////
//EscapeSingleQuote
//
CStringCFeed::EscapeQuote(CStringstrValue)
{
strValue.Replace(_T(
"'"),_T("''"));
returnstrValue;
}


/**//////////////////////////////////////////////////////////////////////////////
//DeletelistfromDatabase
//
voidCFeed::DeleteListArray(CStringArray&strLinkArray)
{
_ConnectionPtrpCnn
=NULL;
CStringstrSQL;
CStringstrMsg;
intnIndex;

//Step1.Createobject
pCnn.CreateInstance(__uuidof(Connection));
if(pCnn==NULL)
{
AfxMessageBox(_T(
"Cannotcreateconnectionobject,pleaseinstallMDAC!"));
return;
}


//Step2.Openconnection
try
{
CStringstrCnn;
strCnn.Format(_T(
"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=%s//AgileReader.mdb;JetOLEDB:DatabasePassword=philips;"),GetModuleFileDir());
pCnn
->Open(_bstr_t(strCnn),"","",adConnectUnspecified);
}

catch(_com_error&e)
{
AfxMessageBox(_T(
"Cannotopenconnection:/n")+GetComError(e));
pCnn.Release();
return;
}


//Step3.DeleteLinkfromFeedListtable
for(nIndex=0;nIndex<strLinkArray.GetSize();nIndex++)
{
strSQL.Format(_T(
"deletefromFeedItemwherelink='%s'"),EscapeQuote(strLinkArray[nIndex]));
ExecuteSQL(pCnn,strSQL,strMsg);
}


//Step4.Done!
pCnn.Release();
}


/**//////////////////////////////////////////////////////////////////////////////
//DeleteFeedSource
//
voidCFeed::DeleteFeedSource(CStringstrLink)
{
_ConnectionPtrpCnn
=NULL;
CStringstrSQL;
CStringstrMsg;

//Step1.Createobject
pCnn.CreateInstance(__uuidof(Connection));
if(pCnn==NULL)
{
AfxMessageBox(_T(
"Cannotcreateconnectionobject,pleaseinstallMDAC!"));
return;
}


//Step2.Openconnection
try
{
CStringstrCnn;
strCnn.Format(_T(
"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=%s//AgileReader.mdb;JetOLEDB:DatabasePassword=philips;"),GetModuleFileDir());
pCnn
->Open(_bstr_t(strCnn),"","",adConnectUnspecified);
}

catch(_com_error&e)
{
AfxMessageBox(_T(
"Cannotopenconnection:/n")+GetComError(e));
pCnn.Release();
return;
}


//Step3.DeleteLinkfromFeedListtable
strSQL.Format(_T("deletefromFeedSourcewhereFeedLink='%s'"),EscapeQuote(strLink));
ExecuteSQL(pCnn,strSQL,strMsg);

//Step4.Done!
pCnn.Release();
}


/**//////////////////////////////////////////////////////////////////////////////
//Markanitemasread
//
voidCFeed::MarkItemRead(CStringstrLink)
{//标记Rss条目为已读状态
_ConnectionPtrpCnn=NULL;
CStringstrSQL;
CStringstrMsg;

//Step1.Createobject
pCnn.CreateInstance(__uuidof(Connection));
if(pCnn==NULL)
{
AfxMessageBox(_T(
"Cannotcreateconnectionobject,pleaseinstallMDAC!"));
return;
}


//Step2.Openconnection
try
{
CStringstrCnn;
strCnn.Format(_T(
"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=%s//AgileReader.mdb;JetOLEDB:DatabasePassword=philips;"),GetModuleFileDir());
pCnn
->Open(_bstr_t(strCnn),"","",adConnectUnspecified);
}

catch(_com_error&e)
{
AfxMessageBox(_T(
"Cannotopenconnection:/n")+GetComError(e));
pCnn.Release();
return;
}


//Step3.DeleteLinkfromFeedListtable
strSQL.Format(_T("updateFeedItemsetreadstatus=1wherelink='%s'"),EscapeQuote(strLink));
ExecuteSQL(pCnn,strSQL,strMsg);

//Step4.Done!
pCnn.Release();
}


/**//////////////////////////////////////////////////////////////////////////////
//RefreshAllSubScriptions
//
voidCFeed::RefreshAll()
{//刷新订阅信息
_ConnectionPtrpCnn=NULL;
CStringstrSQL;
CStringstrMsg;
CStringArraystrLinkArray;
_RecordsetPtrrs
=NULL;

//Step1.Createobject
pCnn.CreateInstance(__uuidof(Connection));
if(pCnn==NULL)
{
AfxMessageBox(_T(
"Cannotcreateconnectionobject,pleaseinstallMDAC!"));
return;
}


//Step2.Openconnection
try
{
CStringstrCnn;
strCnn.Format(_T(
"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=%s//AgileReader.mdb;JetOLEDB:DatabasePassword=philips;"),GetModuleFileDir());
pCnn
->Open(_bstr_t(strCnn),"","",adConnectUnspecified);
}

catch(_com_error&e)
{
AfxMessageBox(_T(
"Cannotopenconnection:/n")+GetComError(e));
pCnn.Release();
return;
}


//Step3.Getallthesubscriptions
strSQL=_T("selectFeedLinkfromFeedSource");
try
{
rs
=pCnn->Execute(_bstr_t(strSQL),NULL,adCmdText);
while(rs!=NULL&&rs->adoEOF!=TRUE)
{
if(rs->adoEOF)
{
break;
}

strLinkArray.Add(GetFieldValue(rs
->Fields,0));
rs
->MoveNext();
}

}

catch(_com_error&e)
{
AfxMessageBox(GetComError(e));
}

rs.Release();
rs
=NULL;

//Step4.Refreaheachlink
for(intnIndex=0;nIndex<strLinkArray.GetSize();nIndex++)
{
CFeedfeed(strLinkArray.GetAt(nIndex));
feed.m_source.m_strLink
=strLinkArray.GetAt(nIndex);
feed.Save();
}


//Step5.Done!
pCnn.Release();
}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics