Introduction
I created a sample project for checking the GMail account of a user and notify him / her using a task bar notifier and also using a Microsoft Agent. The users can also log via a web proxy as I did this work.
The ones who have not been set up a web proxy can happily remove the web proxy authentication part of the code.
I used ‘AxInterop.HTTSLib
’ library for connecting to the GMail server and getting the HttpWebRequest
& HttpWebResponse
.
I also used ‘AxInterop.AgentObjects
’ lib for calling the Microsoft Agent. You have to paste the ‘James.acs’ file in:
‘C:\WINDOWS\msagent\chars’
folder. You also need to keep it in the Resources folder. For the time being, I used the default character, that is merlin, in the source. Anyway, the use of James char is also in the source. Please refer to it for more information.
The proxy enabled version can also be used in a non proxy environment - type anything as the proxy username & password. Then try it.
Background + Prerequisites
You should have pre installed the .NET version 1.1 for testing of this code. It's freely available from the Microsoft site.
Download .NET 1.1 redistributable package from here.
And also the Microsoft Agent core components from Microsoft @ free to speak the character and show it you have to install those tools.
Please refer to this link and this one for details of the HTTP classes.
And use http://www.microsoft.com site for more information on Agent technology and Visual Studio .NET 2003.
Using the Code
Please create the HTML comment web pages using .NET IDE. Then you can view the entire solution comments via it or manually.
Please note that this is my first article, so there may be few reading problems.
But I used the Camel notation in my code as much as possible.
Also look at the task bar notification area icon. You can view the state by moving the cursor on to that icon, and by double clicking on that, you can exit from the application.
Please check the comments that I provided in the code.
request = dynamic_cast<HTTPWEBREQUEST*>(WebRequest::Create(
"https://mail.google.com/mail/feed/atom"));
WebProxy* myProxy = new WebProxy();
myProxy = dynamic_cast<WEBPROXY*>(request->Proxy);
myProxy->Credentials = new NetworkCredential(sProxyUserName, sProxyPwd);
request->Proxy = myProxy;
request->Credentials = new NetworkCredential(sGMailUserName, sGMailPwd);
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);
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;
}
break;
}
}
The handling of the Microsoft Agent has been done using this block of code. But at first, you should paste the James.acs file in the ‘C:\WINDOWS\msagent\chars’ folder.
String* sBaseDir = System::Environment::CurrentDirectory;
String* sCharPath = String::Concat(sBaseDir, "\\Resources\\James.acs");
this->axAgent1->Characters->Load("james", sCharPath);
Interop::AgentObjects::IAgentCtlCharacters* get_chars =
this->axAgent1->get_Characters();
Interop::AgentObjects::IAgentCtlCharacter* schar =
get_chars->Character("james");
this->speaker = schar;
I created a new thread to handle the Agent on the Application, and on the destructor of the AgentReader
class, I destroy the speaker COM Object.
agentObj = new AgentReader(speaker, sReplyXML);
Thread * AgentTrd = new Thread( new ThreadStart(agentObj,
&AgentReader::MainAgentHandler));
AgentTrd->Start();
Points of Interest
I learned about how to cast variables or objects in Visual C++ .NET way in this project.
I also created Agent object in the VC++ code. To do it, I used this article from CodeProject.
I also tried some way of TTS engine support. I commented that part of the code for the time being. So you can try that too in your experiments and keep me posted about the results.
Thanks!
Additional Resources