Overpass Experiences The Eric Wroolie Blog

9Feb/100

The scary thing about Silverlight . . .

The scary thing about Silverlight is that you are one security threat away from losing your clients.  One thing that I’ve thought a lot with the problems on IE lately is that people who wrote “Only-for-Internet-Explorer” websites did not give their users the option to switch browsers if they felt unsafe due to all the security flaw hype.

A little common sense and a knowledge of web standards and it’s easy to write HTML that will look good and be functional in all browsers.  Still, in my experience, too many developers are choosing a platform and sticking with it—most of the time that is IE.  It’s easier to test one browser, it’s easier to tell a user to use the browser that’s probably already installed on their pc.

Flash and Silverlight are different than HTML—they are runtimes which are allowed to run inside the browser—kind of like how Java applets used to be able to.  They are executables which run compiled functionality on your computer.  They are cross-browser—but not like html is cross-browser.  When I look at a Silverlight or Flash app on my pc, it’s always the same runtime working.  Silverlight is a few years old and really starting to look like Flash—allowing Microsoft developers like me to get more fancy and provide far better functionality for our users.  Silverlight runs on Windows and Mac, but has ignored the Linux landscape (there is an open-source Silverlight runtime called Moonlight being developed for that—but I consider it a snub).

In the world of web development, I think Flash and Silverlight are “cheating” at cross-platform compatibility.  Everyone has accepted Flash (except the iPhone/iPad), but the jury is still out on Silverlight.

Silverlight and Flash are great in that they move a lot of the processing to your computer and free up resources on the server from which they originate.  But they also increase the responsibilities of they client over the server.

Security flaws are found all the time.  We all scramble around and try to fix them when they come up.  As a software developer, I like the idea that I can apply a patch to a server and be done with it.  With client driven app, I need to make sure all of my users apply the patch (and do it in a way that lets them know that the app is safe—and not to panic).  Flash could bounce back from it (“You need it for Youtube, too. You should apply the patch”), but Silverlight is too new.

I’m often seduced by the cool things that Silverlight can do.  I’ve played around with it a lot and have written several small apps (including an animated Overpass ad on my blog), but I’m not ready to jump in head-first yet. 

31Jul/090

Some thoughts on the ASP.Net MVC Framework

A few months ago, I got tired of ASP.Net.  I was tired of developers who depended on server-side controls, the Microsoft ajax implementations (as opposed to under-the-hood javascript ajax), excessive use of session and view state.  My preferred method of coding which relies more on the html than on the “runat=server” attribute, was considered old fashioned.

pics 006
Creative Commons License photo credit: paulb

So, I wanted to look at something else.  In my mind, Asp.net was getting too bloated and heavy.  I started learning Ruby on Rails.  RoR is a fantastic framework which integrates testability and maintainability.  Rails is the framework—Ruby is the language.  It’s easy to set up an Model View Controller site very quickly.  I love Rails, but I hate Ruby.  I had to lean how to do everything over again in Ruby.  It was like learning to speak a new language—even the simple things were hard.

Then, I looked at the ASP.net MVC framework that was released earlier this year.  The MVC framework is like Rails for ASP.  It keeps aspects of ASP.Net that I really like (like master pages and C#) and moves away from the bulky server-side, viewstate heavy, controls (like the DataGrid) that slow down ASP.Net performance.

My faith in ASP.Net is restored.  My brief foray into the hip and trendy world of Ruby development has given way to working on Microsoft code again.

I’ve been using the MVC framework in a few projects now.  I’ve started writing a Chinese Dictionary application (using the CEDict database) and am enjoying every minute of it.  I don’t know if I’ll every put this site live, but coding it is helping me learn the finer points of the framework.

There are some great MVC tutorials here:

http://www.asp.net/mvc/learn/

The best video tutorial (to start off with) is “Creating a Movie Database Application with ASP.NET MVC”.

5Jul/091

Nike+ API Revisited

One of the highest traffic posts I get on this blog is the brief post on accessing the Nike+ API with C#. I'm pretty proud of that post, but I don't keep up with how the API works.Running Shoes

The Nike+ API is not published, so it's not public.  It can change at any time.

If you are interested in the Nike+ iPod API, there is a much more up-to-date blog you may want to have a look at.  It's called Running Tracker.  I've been subscribed to the RSS feed of this site.  They've created a cross-platform desktop application to examine the data stored with Nike.  I know about their API changes through Running Tracker.

If you have come to this site about the API, by all means, use the code if you can-- but also check out the Running Tracker site as it is more up-to-date on the subject than I have been.  Their application doesn't use C#, but it might be able to help you out with more information.

Creative Commons License photo credit: marksteelenz

9Feb/095

Nike+ in Subversion . . . again

I've uploaded my Nike+ API to a new SVN repository. Previously, I used Google Code, but it required people to register with Google and I couldn't find the way to open it up to anonymous users.

So, here it is again. I have it on my own server in a repository:

https://svn.overpass-software.com/svn/nikeplus/trunk

I didn't run (or go to work) at all last week because of the heavy snow and a bout of the flu. I should be ready to head out this morning, but I think I broke a toe yesterday. I walked right into a door jam barefoot in the house and now they are starting to swell up. I sound like someone who is always looking for excuses, but he Reading Half Marathon is 7 weeks away, and I'm already registered.

Update 12 Oct 2009: Since this post was written, I have moved the code to the Google Code repository at https://nikepluscsharp.googlecode.com/svn/trunk. Use your Google username and password to access it. It is not a complete working app and will require some C# knowledge to see what it does.

28Jan/091

Nike+ C# code

A lot of people are emailing me with problems they are having downloading the Nike+ api code from Google Code.  In order to access it, you need a google api login and password.  This sucks, I know.

I will try to find a more open svn repository for this.  I use some for Overpass, but don't really want to mix my pet project with it.  For the meantime, here is the project as it stands now.  If you are finding this post at a day later than 28 January 2009, you might want to look for a future post where I give more up to date source code. 

The is mostly the API, so don't expect a nice GUI.  However, I have included a windows app which I use for quick tests.  I also have some unit tests, but these need to be maintained a little better.  My plan was to work on this a bit more before releasing it, but a lot of people seem to be looking for something like this.

http://www.wroolie.co.uk/files/Nike+.zip

There is no rocket science here.  The only difficult bit is connecting to Nike+.  You can lift the code from this project if you want to.  Ideally, see if you can access the SVN repository.  If you add anything cool to it, please let me know.  I mostly work on this when I have a few spare minutes here and there (and I don't have much of those), so it would be nice to see it grow or see if it is used anywhere interesting.

8Jan/090

Nike+ API on Google Code

I've been working on this API off and on for a while now.

I have a Google Code repository where it is hosted.

I've put the code at https://nikepluscsharp.googlecode.com/svn/trunk

The unit tests are working quite the way I would like them to.  I mentioned this in a post I did last year and never put any real projects up.

The (so far) very blank project pages are located at:

http://code.google.com/p/nikepluscsharp/

Any problems you see with the code, please let me know.

16Sep/080

Nike+ code will soon be on Google Code

I've got some emails and comments from people looking for my api wrapper for the Nike+ Api and have been sending it out to whoever wants it. I hope it is proving useful.

Last night I finally for around to setting up a project on code.google.com to make the source code more available and open to modification by others.

I'll post the URL and svn repository location when I finish uploading everything in the next few days.

5May/0812

Connecting to the Nike+ API with C#

A few months ago, I started writing some small personal apps which take information from the Nike+ service. Nike+ is the gadget I attach to my IPod and my running shoes which tracks details about my runs. It tracks things like distance, time, what I'm listening to, etc. When I sync the ipod, this information gets uploaded to the Nike+ website where I can see a couple of flash-heavy graphs of my running progress. Ideally, I would like to use this data myself--so I looked for an API.

I only found one example of an API referrence. This is a Wordpress plugin written in PHP (http://www.ear-fung.us/apps/nikeplus/). There is very little documentation on the API out there. What I've been able to do involved a lot of trial and error to figure out how to get it working.

API Overview

Basically, the API (like most web-based APIs) includes a list of URLs which return an XML string. The first url will return an authentication cookie which all of the other urls use.

Here are the URLs:

URL Description
https://secure-nikeplus.nike.com/nikeplus/v1/services/widget/generate_pin.jhtml?
login=<Username>&password=<Password>
Authenticates the user. Once this information is passed in, a cookie is put on the client and used for the other calls. I'll outline how to get around this later.
http://secure-nikeplus.nike.com/nikeplus/v1/services/app/get_user_data.jhtml Gets all of the data about the user (Name, Gender, Country, etc)
https://secure-nikeplus.nike.com/nikeplus/v1/services/app/goal_list.jhtml List of goals for the user.
https://secure-nikeplus.nike.com/nikeplus/v1/services/app/run_list.jhtml A list of all runs with basic summary information. This can get pretty long.
https://secure-nikeplus.nike.com/nikeplus/v1/services/app/get_run.jhtml?id=<RunNumber> A more detailed view of a specific run using the run number from the run list.
https://secure-nikeplus.nike.com/nikeplus/v1/services/widget/get_challenges_for_user.jhtml List of the Challenges the user has.
https://secure-nikeplus.nike.com/nikeplus/v1/services/app/personal_records.jhtml Lists all personal records for the user.

Authenticating

The biggest problem I had when using these urls was how to deal with the cookie information. Since I wanted something that would sit outside the browser (like a sidebar gadget or a web component), I didn't want to worry about only hosting one session at a time. So I captured the cookie information and fed it back to the server for each additional call.

        public  bool Authenticate()
        {

            //get the login URL (which I include app.config)
            string authURI = String.Format(ConfigurationSettings.AppSettings["CreateSession"].ToString()+"?login={0}&password={1}",
                    _userName, _passWord);

            //Make the call to initiate the connection
            WebRequest objRequest = System.Net.HttpWebRequest.Create(authURI);

            //Read the response
            WebResponse objResponse = objRequest.GetResponse();

            //a cookie will be returned for authentication-- catch it here
            _authenticationCookie = objResponse.Headers["SET-COOKIE"].ToString();

            StreamReader webResponse = new StreamReader(objResponse.GetResponseStream());

            XmlDocument dataDoc = new XmlDocument();
            dataDoc.LoadXml(webResponse.ReadToEnd());

            if (dataDoc.SelectSingleNode("//status").InnerText == "success")
            {
                return true;
            }
            else
            {
                return false;
            }

        }


 

The xml that's returned is pretty simple, it returns a status node. The important thing it returns is the cookie.

I basically capture the cookie information in the "SET-COOKIE" information which gets passed in with the http header. I store this in a class variable so I can send it in with later calls.

Retrieving Data

Now that I've authenticated, all I need to do is pass the cookie details back to the api with each subsequent request.

        private XmlDocument getAdditionalDetails(string uri)
        {
            WebRequest objRequest = System.Net.HttpWebRequest.Create(uri);

            //return the authorization cookie
            objRequest.Headers.Add("Cookie", _authenticationCookie);

            WebResponse objResponse = objRequest.GetResponse();

            StreamReader webResponse = new StreamReader(objResponse.GetResponseStream());

            XmlDocument dataDoc = new XmlDocument();
            dataDoc.LoadXml(webResponse.ReadToEnd());

            return dataDoc;
        }

 

I do this by using the Headers.Add() function. I pass back the same information I retrieved on the initial request. I am no longer dependent on cookies at all. Now, I can read the xml in the application.

Reading the Data

The API does not have any published schemas. However, these are very easy to decipher once you read them. I've actually written an entire API wrapper which assigns these xml values to an object model. This is probably overkill, however. An example of the run list xml is below:

<?xml version="1.0" encoding="UTF-8"?>
<plusService>
  <status>success</status>
  <runList>
    <run id="888888">
      <startTime>2006-10-07T10:03:31+01:00</startTime>
      <distance>6.8276</distance>
      <duration>2035266</duration>
      <syncTime>2006-10-07T09:51:46+00:00</syncTime>
      <calories>631</calories>
      <name><![CDATA[]]></name>
      <description><![CDATA[]]></description>
    </run>
    <run id="99999999">
      <startTime>2006-10-10T08:26:10+01:00</startTime>
      <distance>4.51</distance>
      <duration>1331531</duration>
      <syncTime>2006-10-10T07:54:38+00:00</syncTime>
      <calories>417</calories>
      <name><![CDATA[]]></name>
      <description><![CDATA[]]></description>
    </run>
. . .

Summary

I will admit that I should have used all of the time I spent playing with this api to actually be out running. Still it was fun to get it working. I only used the data for small projects. I hope that someone creates some decent gadgets for the Vista or Google Desktop sidebars from this.

If you would like my actual API wrapper code, drop me an email and I can send you what I've done. I've written the proper object oriented classes along with unit tests, etc. However, once you can get the xml data, you have all you need.

I hope this helps someone out there. Like I said, this is not documented anywhere else, so it could possibly change in the future (so keep your apps flexible).

31Mar/080

MyGeneration – a timesaver

Code Generators are nothing new. I played around with Codesmith back before they started charging $200 for it and have looked into some of the codegen tools on sourceforge but was generally unimpressed. Most lacked enough documentation to really customise anything.

I even tried some of the high-end tools like Tier Developer which costs $1k and provided everything but the kitchen sink. You can download it for the trial, but it requires a steep learning curve to customise and you actually get a salesman call you up on the phone.

If you've never used a code generator, it's basically an application that spits out code based on collections you pass it. Most of the time, it's a database structure. You design your database, point your code generator at it, and select which tables you want to use. The template will create some output files for you based on what you select. For example, I selected five tables and used a code generator to create my CRUD stored proc files. I select a directory to output to and the code generators put the files there. I can then run these files against a database or include them in a Visual Studio database project. Since this is a one-shot generation, I can freely modify these files after they've been created.

I first looked at MyGeneration a few months ago. Like most of the cool new tools, I thought about all the cool things I could do with it-- then I moved on to something else.

Today I started automating some of my Model classes using it. So I got to really use it in anger. Here are the things I really like about it:

    1. It's free.
    2. There is a huge template library
    3. Tempates can be written in VBScript-- so no new languages to learn.

Every time I look through a template library for a code generator, I get some really ambitious code. Everyone wants to generate all of your stored procs, data access layers, business objects, and test cases. I usually just want something simple like business logic layer. With this tool, it's easy to write your own.

In a few hours, I wrote code to generate all of my interfaces and model objects. Since it was vbs, it was just like writing a classic asp page. I just looped through all the tables and created the beginning of my business objects:

<%

'******************************Class File*************************************
%>
#region headerblock
// Filename : <%=tableName%>.cs
// Change history
// date            version: author : description of change
// <%=Now()%>    <%=vbtab%>0.1    <%=vbtab%><%=input.Item("txtDeveloperName")%>    <%=vbtab%>Object Created

#endregion

using System;
using System.Data;
using System.Collections;

namespace <%= TrimSpaces(namespace) %>
{
    public class <%=tableName %> : I<%=tableName %>
    {

        public <%= tableName %>()
        {

        }

        #region Internals
        <% For Each objColumn in objTable.Columns %>
            private <%=objColumn.LanguageType%> <%=InternalVariableName(objColumn,true)%>;<%Next%>
        #endregion

        #region Properties
        <% For Each objColumn in objTable.Columns
        %>
            public <%=objColumn.LanguageType%> <%=InternalVariableName(objColumn,false)%> {
                get
                {
                    return  <%=InternalVariableName(objColumn,true)%>;
                }
                set
                {
                     <%=InternalVariableName(objColumn,true)%> = value;
                }
            }
        <%Next%>
        #endregion

    }
}
<%
    call SaveFile(tableName,input.item("txtPath"))

%>

One of the most tedious aspects of creating a model project is generating this code. Sure, I need to modify this further and I will probably normalise the database further--but this gives me a decent start and saves a few hours. I can also use this to generate the very basic unit tests (ie. can I create the object? Do all of the properties match?, etc).

It's definitely a tool to check out. It's a lot more fun to create your own template (or modify an existing one) than it is to use what's given to you.

You can find MyGeneration at : http://www.mygenerationsoftware.com

I was tempted to title this post "Talking 'bout MyGeneration" but I fought back the urge.




27Aug/070

Hanselman’s Ultimate Toolkit Post

For the past few years, Scott Hanselman has been posting his list of Ultimate Developer tools on his blog. If you are into .Net development, it is definitely worth a look. Check out http://www.hanselman.com/tools.

Some of the tools he mentions are tools that I've started using over the past year. Others are tools I plan on using very soon. My favourite tools to date are Fiddler, Web Developer for Firefox, and WatIn Test Recorder. Most of the items on the list are freeware or open source and none are available as part of the standard Microsoft Suite of controls.