Thursday, March 15, 2007

Last.fm and ASPxCloudControl

Over the last past hour had thought how you can use Control ASPxCloudControl company Developer Express on my site. Very happy result, when just what the 15 minutes I was able to do so.

As I made? I wish to display on its Web site as a cloud of tags - his approval rating listening my artists. I am a participant in the social network Last.fm. The network brings together people of musical tastes and anything that relates to music. .In short, you create an account on Last.fm, install on your computer thick sleek client and enjoy services that offers you Last.fm.

For example, I have for several months so to come in the network and that is my Last.fm page. There you can see my tapping, compositions, artists, albums and other statistical data.

How can pull data from my account and use them? You can use RSS Feeds from the site. But little pogugliv I found that Last.fm is offering its users the opportunity to receive information in a variety of formats. All that we get on this site. Previously, you can login to it with the same username and password that at the Last.fm. And get direct links to the services provided by information flows in a variety of formats.

We are also interested in XML format. So operate on the following steps :
1) Put down ASPxCloudControl form.
2) Configure it Saxony style and glamour to your taste.
3) Put down XmlDataSource.
4) Bind Control and datasource - DataSourceID = "XmlDataSource1."
5) The data datasource ask tentatively selected our remote XML stream c artists.
6) Set datasource next simple xslt file for the transformation of the original xml file valid for control's Xml.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <Artists>
      <xsl:for-each select="//artist">
        <artist Text="{name}" Value="{playcount}" NavigateUrl="{url}" />
      </xsl:for-each>
    </Artists>
  </xsl:template>
</xsl:stylesheet>

That's all there is so simply, we have the desired result.

Tuesday, March 13, 2007

FlickrNet API and Microsoft Ajax

I had to create a simple application that I could put temporarily on the front page of my website. Application is a modern, written in the light of all the latest developments in the industry Ajax.

It seemed to me an interesting exercise annex, which after a certain period of time images on a page one picture of the set.

So, the task will split into three :

  1. Find, grouping, host set of pictures.
  2. Implement able to access the photos and receive link.
  3. Implement a mechanism to update the page one photo.

And the bottom line for all this must be make as simple as possible, without the use of third-party developers.

Preparation photos

It is tempting to implement this paragraph was version host photos side by side on the site to the directory and then simply to collect the photo, but it is ridiculous for serious developers and primitive, so we did five years ago, and then it was the rule ...

It is our view that we should not duplicate essentially nowhere ... Now, remember, if I have photos, of course there is! My almost abandoned account at flicr. Add to the existing fotkam still quite new and has received decent base of about 100 photos, which are themselves based on the freely on the remote and, more importantly free hosting.

FlickrNet API

Flickr was chosen also because there is an API for access to the site and functionality.

And even there API Kits. Of which there are FlickrNet API, which supports people from Microsoft. ( News Feeds ).

So in order to get started, we need to get the API Key. This link, you can create your own API Key to the Shared Secret. Also check your User ID.

Now we have to implement it.

Create an empty website. In Web.Config write your settings.

<configSections>
    <section name="flickrNet" type="FlickrNet.FlickrConfigurationManager,FlickrNet"/>
</configSections>
<flickrNet apiKey="YOUR API KEY" secret="YOUR SHARED SECRET" cacheDisabled="true">
</flickrNet>
<appSettings>
    <add key="UserId" value="YOUR USER ID"/>
</appSettings>

Disable the cache, not to encounter problems with the rights to publish the draft.

Creating Default.aspx where CodeBehind creating an object to work with Flickr

Flickr flickr = new Flickr();

Login

private string fTempFrob;
...
fTempFrob = flickr.AuthGetFrob();
string authUrl = flickr.AuthCalcWebUrl(AuthLevel.Read);

Get all public picture of our User Id

Photos publicPhotos = flickr.PeopleGetPublicPhotos(ConfigurationManager.AppSettings.Get("UserId"));

Store them in an array of class

private Photo[] photos;
...
photos = publicPhotos.PhotoCollection.ToPhotoArray();

All these actions are performed only once at the first Page_Load

if (!IsCallback) {
    ...
}

Now we can go at any time in our fotopodborke.

Microsoft Ajax

If you still do not have the downloading and setting. Then put form UpdatePanel, inside which lay Image. Rolling on the form also Timer, for example, ask the interval 20,000 milliseconds. At Timer1_Tick write code follow

Image1.ImageUrl = photos[rnd.Next(photos.Length)].MediumUrl;

And the Page_Load add line

private Random rnd;
...
rnd = new Random(DateTime.Now.Millisecond);

Certainly here missed some stuff in more detail you can see in MyFlickrProject.zip