Monday, December 24, 2007

Google PicasaWeb API Example

Google has launched Picasa Web Albums Data API in march 2007 . Last week , I developed some code using this new API which is part GData API family. In case you are still wondering what GData APIs consists of then check out the official homepage.

Here are some of the things you can do with the Picasa Web Albums Data API:

  • Include your public photos in your own web page, and allow users to comment on them (and have the comments stored in Picasa Web Albums).
  • Write a plugin to manage your albums and photos from a desktop or mobile phone client.
  • Create a custom screensaver to display your Picasa Web Albums photos on your computer.

Google is providing client libraries to help you write GData client applications in a variety of languages like java, python, c#, php, javascript. I will show how easy it is to query PicasaWeb and download entire albums for a user using the .net client library for GData.

Download the GData .NET Client Library

Now, create a new Console Application project for c#. Add a reference to GData.Client, Gdata.Extenstion and GData.Photos Dlls from the output directory of the first project.

Now the stage is ready.

Here is the code for a function which takes User name and name of the album as arguments and download all the pictures from this album.

code listing

private static void DownAlbum(string UserN, string AlbumN)
{
string fileName;
Uri uriPath;
WebClient HttpClient = new WebClient();
// Three important elements of PicasaWeb API are
// PhotoQuery, PicasaService and PicasaFeed
PhotoQuery query = new PhotoQuery();
query.Uri = new Uri(PhotoQuery.CreatePicasaUri(UserN, AlbumN));
PicasaService service = new PicasaService("Sams PicasaWeb Explorer");
PicasaFeed feed = (PicasaFeed)service.Query(query);

Directory.SetCurrentDirectory("c:\\");
foreach (AtomEntry aentry in feed.Entries)
{
uriPath = new Uri(aentry.Content.Src.ToString());
fileName = uriPic.LocalPath.Substring(uriPath.LocalPath.LastIndexOf('/')+1);
try {
Console.WriteLine("Downloading: " + fileName);
HttpClient.DownloadFile(aentry.Content.Src.ToString(), fileName);
Console.WriteLine("Download Complete");
}
catch (WebException we)
{ Console.WriteLine(we.Message); }
}

Code is easy to understand. I am using HttpClient.DownloadFile() to download file from picasaweb server. To improve readability I have not included error handling code here.

[Source code]

Monday, September 3, 2007

A project on OMR in C#

Last week, We decided that this semester's college project should be on Optical Mark Recognization. A OMR system is a idle tool for collecting and analysing data from paper and web surveys, tests, assessments, evaluations and other forms.
After googling and burning mid night oil for 3 days, I have found that the following things are required
1) OMR sheets -- OMR forms are typically multiple choice sheets, which may or may not be made of special paper and ink.
2) Scanner -- Since I want to develop a software based system, it should support a wide variety of scanners.
3) Recognization engine -- Image processing and analysis has to be done here, and data collected should be forwarded for further processing.
4) OMR Sheets management system
a) Development of sheet designs
b) Master sheet or Answer sheet
c) Score calculation and analysis

PS: More points may be added later.

Now, I have decided to build the Recognization Engine first and my colleagues will help in developing the rest of the system.
I have developed some graphics intensive apps. Softwares with impressive uncoventional UI ( latest one using WPF and Expression Blend posted
here) and also small 2-D games . It was never required before to play directly with the pixels of a image.

Friday, July 27, 2007

VS 2008 'orcas' beta 2 released

I'm very pleased to announce that the Beta 2 release of VS 2008 and .NET 3.5 Beta2 is now available for download. You can download the Visual Studio 2008 product here. You can alternatively download the smaller VS 2008 Express Editions here.

MSDN Library for Visual Studio 2008 Beta 2 can be downloaded from this link .

I will spend next few days to grasp the changes in this new release. And come up with new posts soon.

Thursday, July 26, 2007

VS 2008 'orcas' beta 2 will be available in few days

I have been waiting for this release since many days !

Microsoft will announce Thursday morning the release of Visual Studio 2008 Beta 2. According to Scott Guthrie, the general manager of Microsoft's Developer Division, the release will be nearly feature complete and will likely be the last major release before the product is released to manufacturing in preparation for its launch on February 27, 2008.

Monday, July 9, 2007

Reading a XML file using JScript


My current project required me to consume and display data from a xml file. XML! hey microsoft has made programmer's life easy by providing various xml classes. But i was asked to use same old scripting languages. I started with javascript and then XMLDOM. Document Object Model, yeah we all have heard about it since last decade. Now let me show how you can also make use of XMLDOM using JScript

Requirements :
1. MSXML 3.0 or above
2. Text editor like notepad
3. Internet Explorer 4.0 or later
4. A XML file, Products.xml is included in the attached file


Note: If u have windows xp or 2003 installed on ur system , then dont worry about the above requirements.

var dom = new ActiveXObject("msxml2.DOMDocument.3.0");

First create a instance of msxml DOM object.Above code will work for MSXML 3.0 or above as "Msxml2.DOMDocument.3.0" is ProgID for MSXML 3.0.
For those who are still wondering, MSXML is the Microsoft XML Core Services.

dom.load("products.xml");

once this is done we can use various DOM methods and properties to access and manipulate the XML data.

var oNodes = dom.selectNodes("//Product[0]/*");

var node = oNodes.nextNode; alert(node.text);


This was my first experience with JScript and also MSXML. Also attached a hello world test file to get you started with MSXML DOM. Do write to me about any queries.


Tuesday, March 20, 2007

Microsoft Expression Blend in Action - A sample application

This is my first application using Microsoft Expression Blend and Windows Presentation Foundation. This app gets and display Cricket Scores from CricInfo RSS feed.
The User Interface has been entirely developed using Expression Blend and very little code has been written using Visual Studio.net 2005.

Here are the three main features i worked on

1) Connection to XML source and dispalying the data

2) Transparent Window and cool UI elements

3) updating a control's property using DispatcherTimer

Connecting to the xml data source is straight forward in Microsoft Expression Blend. Select XML Source in the Data panel. Add XML data Source Dialog box will appear. Type the URL of the the RSS feed and press OK button. Now create a new grid and a the desired node on to grid.
select the control to be data bounded .

The main application window is made transparent by setting allowtransparancy

AllowTransparancy = true;

This will also hide the menubar and then the window could not be moved.

How to solve this problem

Select Window in Object and TimeLine Panel and then select events in the properties panel.
Now type OnMouseLeftButtonDown at MouseButtonDown and press Enter key.
This will load the project in Microsoft Visual Studio.net 2005 and the OnMouseLeftButtonDown event will be automatically added .

Here's the code to fix this so you can move the window.

override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
DragMove();
}

Updating UI controls property uisng DispatcherTimer

I thought that it would look nice if we could display the time when the score card information was last updated. Its wasy to guess that this task requries a Timer object.


Windows Presentation Foundation comes with DispatcherTimer Class. This is a timer that is integrated into the Dispatcher queue which is processed at a specified interval of time and at a specified priority.


Reasons for using a DispatcherTimer opposed to a System.Timers.Timer are that the DispatcherTimer runs on the same thread as the Dispatcher and a DispatcherPriority can be set on the DispatcherTimer.


dispatcherTimer = new DispatcherTimer();
// Score should be updated every 30 seconds -:)
dispatcherTimer.Interval = new TimeSpan(0, 0, 30);
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Start();


After developing this app, i must say WPF and Expression Blend rocks!

Wednesday, March 7, 2007

Visual Studio 2005 SP1 for Vista is officially released

Tim Sneath reported that the final release of the Visual Studio 2005 update for Windows Vista is now available. This update fixes most of the issues that you may have faced with running Microsoft Visual Studio 2005 on Windows Vista. Install Visual Studio 2005, the Service Pack 1 update, and then the Windows Vista update to get a fully-supported developer environment.
There's also an interesting interview with Soma (the VP responsible for the Developer Division here) on Microsoft Presspass. The questions are a little soft (the interview is posted on our press relations site, after all!) but it's a good review of where the developer platform is today and the focus areas for the developer tools and platform part of the business.

Monday, March 5, 2007

New tutorial site for newbies and kids by microsoft

Microsoft Corporation unveiled a new tutorial website yesterday. It is to help people with no programming experience learn to build Windows applications or Web sites using Microsoft Visual Studio 2005 .
The new Beginning Developer Learning Center offers such developers 45 lessons and 31 short “how-to” videos on programming using Visual Studio 2005 Express Edition products, Microsoft said.



It starts with the very basics, and guides you through step-by-step to becoming a fully-fledged developer.It is suitable for students that have no prior knowledge of programming.
All lessons in the Beginner Developer Learning Center are organized into two development tracks (Windows Development and Web Development). They are further classified into Tiers or levels of difficulty.
To view all the lesson available, click on Learning Path.


Since last 2-3 years Microsoft has been providing tools and services for students and non-developers.

Adding a Proxy server to your code can never be so easy !

Today i have created a small console program which uses multiple proxy servers to fetch data from www.google.com.

HttpWebRequest.Proxy Property is used to specify the proxy server through which the rquest is posted.




download source code: http://www.divshare.com/download/188899-47e

Posting to a webpage and using it's response

HttpWebRequest and HttpWebResponse - here are the two classes to simulate the web browser funtionality in smart client applications.
We can use the following method when we had to call a web page which return the result as Xml.

public static string GetHttpRequest(StringBuilder data, string sourcePath)
{
Stream aStream = null;
try
{
//Send POST request web page
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sourcePath);
req.Method = "POST";
// Content type is xml
req.ContentType = "text/xml";
req.Credentials = CredentialCache.DefaultCredentials;
if (data.Length > 0)
{
req.ContentLength = data.Length;
StreamWriter sw = new StreamWriter(req.GetRequestStream());
sw.Write(data.ToString());
sw.Flush();
sw.Close();
}
// Create The Response Object And Fill It By Sending The Request;
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
aStream = response.GetResponseStream();
StreamReader sr = new StreamReader(aStream);
StringBuilder sbOutput = new StringBuilder();
char[] buffer = new char[1024];
int r;
while ((r = sr.Read(buffer, 0, buffer.Length)) > 0)
sbOutput.Append(buffer, 0, r);
return sbOutput.ToString();
}
catch (WebException ex)
{
//TODO: handle exception
}
catch (Exception ex)
{
//TODO: handle exception
}
finally
{
aStream.Close();
}
return string.Empty;
}

Sunday, March 4, 2007

web automation - Fetch / Send HTTP Post data to a Web Server

Since last two days i am googling for how to fetch and post data on websites using the standard .net aplication.
Such applications will be helpful in many scenarios . Examples of application using the above technique
1) Website Testing
2) Website Downloader
3) Stress testing of Server and Websites
4) Data pulling from websites - like fetching usage data from BSNL Data One server -:)

Wednesday, February 28, 2007

My first post

Wouldn't you know it. I finally decide to create a blog and work on my first post.
I've finally decided to enter the blogosphere. I've been a long-time reader and have wanted to start a blog for a while. The reason I've waited is that I wanted to make sure I wasn't one of those "one blog wonders." You know, the person that writes one blog entry and then you never hear from them again. Well, after thinking about ways to mitigate that, I've decided that I have no way to guarantee that I won't be one of those, but I promise to try not to be.