桌面 GMail 提醒系统






3.27/5 (13投票s)
收到邮件时提醒 GMail 用户
引言
我创建了一个示例项目,用于检查用户的 GMail 帐户,并使用任务栏通知器和 Microsoft Agent 通知他/她。用户也可以通过 Web 代理登录,就像我做的那样。
那些尚未设置 Web 代理的人可以愉快地删除代码中 Web 代理身份验证的部分。
我使用“AxInterop.HTTSLib
”库来连接 GMail 服务器并获取 HttpWebRequest
& HttpWebResponse
。
我也使用了“AxInterop.AgentObjects
”库来调用 Microsoft Agent。您必须将“James.acs”文件粘贴到
‘C:\WINDOWS\msagent\chars’
文件夹中。您还需要将其保存在 Resources 文件夹中。目前,我在源代码中使用了默认角色,即 merlin。无论如何,源代码中也使用了 James 角色。请参考它以获取更多信息。
支持代理的版本也可以在非代理环境中使用 - 输入任何内容作为代理用户名和密码。然后试试。
背景 + 先决条件
您应该预先安装 .NET 1.1 版本以测试此代码。它可从 Microsoft 网站免费获得。
从此处下载 .NET 1.1 可再发行包。
还有来自 Microsoft 的 Microsoft Agent 核心组件 @ 免费,您需要安装这些工具才能让角色说话并显示它。
并使用 http://www.microsoft.com 网站获取有关 Agent 技术和 Visual Studio .NET 2003 的更多信息。
Using the Code
请使用 .NET IDE 创建 HTML 注释网页。然后您可以通过它或手动查看整个解决方案的注释。
请注意,这是我的第一篇文章,因此可能会有一些阅读问题。
但我尽可能在我的代码中使用 Camel 命名法。
另请查看任务栏通知区域图标。您可以通过将光标移到该图标上来查看状态,并且通过双击它,您可以从应用程序退出。
请检查我在代码中提供的注释。
//create the web request to get the XML from the GMail server.
//WebRequest* myReq = WebRequest::Create();
request = dynamic_cast<HTTPWEBREQUEST*>(WebRequest::Create(
"https://mail.google.com/mail/feed/atom"));
WebProxy* myProxy = new WebProxy();
myProxy = dynamic_cast<WEBPROXY*>(request->Proxy);
//set proxy username & password (credential)
myProxy->Credentials = new NetworkCredential(sProxyUserName, sProxyPwd);
request->Proxy = myProxy;
//set GMail username & password (credential)
request->Credentials = new NetworkCredential(sGMailUserName, sGMailPwd);
//get the response from the GMail server
resp = dynamic_cast<HTTPWEBRESPONSE*>(request->GetResponse());
if (request->HaveResponse)
{
resp = dynamic_cast<HTTPWEBRESPONSE*>(request->GetResponse());
str = resp->GetResponseStream();
while(true)
{
iReadBytes = str->Read(mybuf, 0, mybuf->Length);
sReplyXMLSub =
System::Text::Encoding::UTF8->GetString(mybuf, 0, iReadBytes);
if(iReadBytes == 0)
break;
sReplyXML = String::Concat(sReplyXML, sReplyXMLSub);
}
sReplyXML->Trim();
xmlDoc->LoadXml(sReplyXML);
//xmlDoc->Save("UserXML.xml");
XmlNodeReader* reader = new XmlNodeReader(xmlDoc);
while ( reader->Read() )
{
switch ( reader->NodeType )
{
case XmlNodeType::Element:
if(String::Equals("fullcount", reader->Name))
{
Unreaded = reader->ReadString();
sFullCount = String::Concat("You have ",
Unreaded, " Mails in your inbox");
agentObj->AgentCaller(sFullCount);
notifyIcon1->Text = sFullCount;
/*Enable the class for test the Text to Voice engine support.
but u may want a build environment to test this part.*/
//MailReader = new GMailReader(unlabel);
//MailReader->Show();
}
break;
}
}
Microsoft Agent 的处理已使用此代码块完成。但首先,您应该将 James.acs 文件粘贴到 'C:\WINDOWS\msagent\chars' 文件夹中。
String* sBaseDir = System::Environment::CurrentDirectory;
//place the character in the Resources folder
String* sCharPath = String::Concat(sBaseDir, "\\Resources\\James.acs");
//load the James character
this->axAgent1->Characters->Load("james", sCharPath);
Interop::AgentObjects::IAgentCtlCharacters* get_chars =
this->axAgent1->get_Characters();
Interop::AgentObjects::IAgentCtlCharacter* schar =
get_chars->Character("james");
//cast it to a IAgentCtlCharacter to get the maximum use
this->speaker = schar;
我创建了一个新线程来处理应用程序上的 Agent,并在 AgentReader
类的析构函数中,我销毁了 speaker COM 对象。
agentObj = new AgentReader(speaker, sReplyXML);
//add the object to the thread.
Thread * AgentTrd = new Thread( new ThreadStart(agentObj,
&AgentReader::MainAgentHandler));
AgentTrd->Start();
关注点
我在这项目中学习了如何在 Visual C++ .NET 中转换变量或对象。
我也在 VC++ 代码中创建了 Agent 对象。为此,我使用了来自 CodeProject 的 这篇文章。
我也尝试了一些 TTS 引擎支持的方法。我暂时注释了代码的这部分。因此,您也可以在您的实验中尝试一下,并随时向我汇报结果。
谢谢!