Archive for September, 2007

A Silverlight Project Template

Saturday, September 29th, 2007

A full description of what you need to do to add Silverlight to a web page is described in the Silverlight QuickStart Guide at

http://silverlight.net/quickstarts/silverlight10/FileSetup.aspx

I used the default Silverlight Project item in Visual Studio (Visual Studio 2008 beta 2 and Silverlight 1.1 Alpha Refresh) to generate the following example files which I’m calling a Silverlight Template.

Silverlight Template Files

TestPage.html is the main entry point for the web page.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=“http://www.w3.org/1999/xhtml” >
<!– saved from url=(0014)about:internet –>
<head>
    <title>Silverlight Project Test Page </title>

    <script type=“text/javascript” src=“Silverlight.js”></script>
    <script type=“text/javascript” src=“TestPage.html.js”></script>
    <style type=“text/css”>
        .silverlightHost { width: 640px; height: 480px; }
    </style>
</head>

<body>
    <div id=“SilverlightControlHost” class=“silverlightHost” >
        <script type=“text/javascript”>
            createSilverlight();
        </script>
    </div>
</body>
</html>

It references Silverlight.js and TestPage.html.js and embeds the Silverlight control on the page.

Silverlight.js is a Javascript helper file that enables Silverlight content to be viewed on multiple platforms and handles everything from checking if the correct version of Silverlight is installed to ensuring that the control is inserted correctly. It is available from the Silverlight Software Development Kit (SDK) and copied into the project location when using Visual Studio.

TestPage.html.js is an auto-generated Javascript file which contains the function createSilverlight.

// JScript source code

//contains calls to silverlight.js, example below loads Page.xaml
function createSilverlight()
{
        Silverlight.createObjectEx({
                source: “Page.xaml”,
                parentElement: document.getElementById(“SilverlightControlHost”),
                id: “SilverlightControl”,
                properties: {
                        width: “100%”,
                        height: “100%”,
                        version: “1.1″,
                        enableHtmlAccess: “true”
                },
                events: {}
        });

        // Give the keyboard focus to the Silverlight control by default
    document.body.onload = function() {
      var silverlightControl = document.getElementById(‘SilverlightControl’);
      if (silverlightControl)
      silverlightControl.focus();
    }

}

The createSilverlight method is called to insert the Silverlight control onto the web page. If you want to insert more than one Silverlight control onto a web page there are instructions in the Silverlight QuickStart guide mentioned above or there is another approach described at

http://blog.paranoidferret.com/index.php/…/how-to-embed-silverlight-into-a-webpage/

And last, but not least, we have the XAML file which describes the content of the Silverlight control

<canvas x:Name=“parentCanvas”
        xmlns=“http://schemas.microsoft.com/client/2007″
        xmlns:x=“http://schemas.microsoft.com/winfx/2006/xaml”
        Loaded=“Page_Loaded”
        x:Class=“Silverlight_Template.Page;assembly=ClientBin/Silverlight_Template.dll”
        Width=“640″
        Height=“480″
        Background=“Black”
        >

</canvas>

This sample is using C# for the code behind so there is an associated DLL (created by building the project) which is located in the ClientBin sub-directory (relative the the HTML file not the XAML file).

Start Slide Show with PicLens Lite PicLens

Amazon MP3

Thursday, September 27th, 2007

Noticed that Amazon have recently launched their own music downloading service, to compete with iTunes from Apple.

http://amazon.com/gp/dmusic/…

Will Amazon succeed when companies like Virgin Digital recently decided to close their doors?

The Virgin Digital site will finally close on October 19 see more detail at

http://www.virgindigital.co.uk

The point of note, with the new Amazon venture, is the fact that music tracks which they have available (more than 2 million songs) are completely free of any Digital Rights Management (DRM) control.

DRM is a digital padlock which is used to prevent copying of the downloaded material and can also be used to ensure that the material can only be played on a specific device.

Music which is free of DRM makes it more appealing to a wider audience and with the backing of a large company such as Amazon, which can ensure competitive prices versus iTunes, looks certain to be a success.

However, the price per track still seems on the high side to me even at a rate of the quoted $0.89 - $0.99 per track. Why not retail at $0.50 ?

ShakeIT

Wednesday, September 26th, 2007

I was interested to come across this media player, from PASEN which can be shaken (but not stirred), to shuffle through pictures, music and menu items.

In addition to the usual features expected in todays media player devices, the ShakeIT uses a motion sensor that detects the “shake” that allows you to select menu items etc..

I’m not sure whether this would work well while jogging, so perhaps this is why it can also be used as a pedometer which will incorporate a program to calculate the distance you’ve travelled and how many calories you’ve used.

All the details at

http://en.pasen.it/news.php

It started me wondering what would be the most innovative use for a motion sensor or acclerometer device?

A Minimal Plugin for Wordpress

Saturday, September 22nd, 2007

I recently found a need to access data held in a Wordpress database. Although I could have written code that accessed the database directly, I decided to write a plugin so that I could use the in-built Wordpress functions.

Writing a Wordpress plugin is fairly straightforward and I would recommend reading information provided at wordpress.org for writing plugins

http://codex.wordpress.org/Writing_a_Plugin
http://codex.wordpress.org/Function_Reference

However, if it’s of any interest, here are my efforts at creating a minimal plugin. A minimal plugin is presented which can be re-used, essentially as a starting point, for creating various different plugins, and is the minimum structure required when creating a plugin for Wordpress.

I created a file, called minimal_plugin.php, containing the following code and placed it in my wordpress plugins directory. (wordpress/wp-content/plugins). The plugin, called Minimal Plugin is then available in the list of plugins:

Minimal Plugin

When this plugin is activated, a menu item Minimal Plugin is added to the Wordpress Dashboard:

Dashboard

The code consists of 2 functions

function minimal_addMenu() is used to add a menu item and is called by

add_action(‘admin_menu’, ‘minimal_addMenu’);

which adds the menu item to the dashboard admin page.

function minimal_adminMenu() defines what is displayed on the page under the Minimal Plugin tab. This can also used to call available internal Wordpress functions that allow you to access details available in the database.

In addition, information is used from the comments section

/*
Plugin Name: Minimal Plugin
Plugin URI: http://somewhere/
Description: Minimal Plugin
Author: Minimal
Version: 0.0.1
Author URI: http://somewhere/
*/

Here is the complete code listing

<?php
/*
Plugin Name: Minimal Plugin
Plugin URI: http://somewhere/
Description: Minimal Plugin
Author: Minimal
Version: 0.0.1
Author URI: http://somewhere/

Last update: 09/20/07 (09/20/07)

Functions:
minimal_adminMenu: where all the work is done

Copyright 2006-2007 Minimal

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
$minimal_version = ‘v0.0.1′; // the current version

// more details at …
// http://codex.wordpress.org/Writing_a_Plugin
// http://codex.wordpress.org/Function_Reference

function minimal_addMenu()
{
        if ( function_exists(‘add_submenu_page’) )
        {
                add_submenu_page(‘index.php’, ‘Minimal Plugin Template’, ‘Minimal Plugin’, 1, basename(__FILE__),‘minimal_adminMenu’);
        }
}

function minimal_adminMenu()
{
global $minimal_version;
        echo(‘<div class="wrap">’);
        echo(“<h2>Minimal Plugin - version $minimal_version</h2><br /><br />”);
        echo(‘</div>’);
}

add_action(‘admin_menu’, ‘minimal_addMenu’);

?>

Start Slide Show with PicLens Lite PicLens

Windows Live ID - Web Authentication

Wednesday, September 19th, 2007

The Windows Live ID Service is the identity and authentication mechanism provided by Windows Live. Currently there are over 380,000,000 users that have Windows Live ID credentials.

Mentioned during a session at the recent MixUK, the Windows Live ID Web Authentication 1.0 SDK provides an easy-to-use authentication system that allows that allows the Windows Live ID service to verify the identity of visitors to a Web site. One advantage of this approach is that a user doesn’t have to use separate login mechanisms for each site that they visit.

Windows Live ID provides you with a unique, site-specific identifier for each Windows Live user who signs in to your site. Web Authentication also enables you to incorporate Windows Live controls into your site.

Web Authentication works by sending your users to the Windows Live ID sign-in page by means of a specially formatted link. The service then directs them back to your Web site along with a unique, site-specific identifier that you can use to manage personalized content, assign user rights, and perform other tasks for the authenticated user.

Sign-in and account management is performed by Windows Live ID, so you don’t have to worry about implementing these details. Windows Live ID profile data is not shared with your site.

Full details about the Windows Live ID SDK is available from the Microsoft MSDN web-site at:

http://msdn2.microsoft.com/en-us/library/bb404787.aspx

In general, the tasks required when implementing Web Authentication include:

  • Register the application
  • Display the Sign In link on the web-page
  • Decrypt the token returned by Window Live ID to obtain the users unique identifier
  • Manage personalized content and settings for your user, based on the site’s security policies
  • Sign the user out

The best place to start is by obtaining one of the sample applications which are provided in a number of different languages including:

  • ASP.NET (c#)
  • Java
  • Perl
  • PHP
  • Python
  • Ruby

These samples can be obtained from:

http://msdn2.microsoft.com/en-us/library/bb676635.aspx

and here’s the python sample in action …

Python Sample

In addition to making sure I had the correct version of python (2.5) installed on my server !! I found it necessary to install the Python Cryptography Toolkit which I obtained from

http://www.voidspace.org.uk/python/modules.shtml#pycrypto

To implement Windows Live ID, you must register your Web site with Microsoft® as an application and receive an application ID for use with the service.

This is straightforward to do from the Windows Live ID Application page at

https://msm.live.com/app/default.aspx

Get an Application ID

You need to enter the following details

The application name is a unique and friendly name that you use to refer to your application.

The return URL is the URL of the page on your Web site to which the Windows Live ID authentication service redirects users (along with the authentication token) after they have successfully signed in, signed out, or cleared their cookies. You must create a page on your site corresponding to the return URL, to handle the response from the authentication service

The secret key is a shared secret between you and Windows Live ID. Windows Live ID uses this key to encrypt and sign all tokens that it sends to your site. You should choose a secret key that is difficult to guess and create security procedures to manage this key.

and you’re all set - the application ID you get is a 16-character string that represents your application which you’ll use later.

To test out the system, I simply extended the python sample to run from a web-site (which I specified when registering the application) and needed to change the Application-Key.xml file which was supplied as part of the python sample, with details of my registered application.

In summary, I found it quick and easy to set up a simple test application using the Window Live ID Web authentication process which I can use in the future across my collection of web-sites as a single mechanism for user authentication.

As mentioned earlier in-depth information is available directly from Microsoft at

http://msdn2.microsoft.com/en-us/library/bb676635.aspx

Start Slide Show with PicLens Lite PicLens

17 queries. 4.051 seconds. Powered by WordPress