1Transit for them All (Exclusively for WP7)

A few days ago we released 1Transit. Softly. It is an exclusive Windows Phone 7 transit application that is a bundle of simple but robust and hopefully useful features.

Features Like

The application serves data for over 20 transit agencies across North America. Yes, built for travel.

We wanted you to be able to find things fast. Thus, the searching is fast. Something we like to showoff to our friends.

No your eyes do not fool you. Those are live updates that you can receive for transit stops around you. We implemented a bookmarking (aka pinning in the Windows world) feature too, so that you can get these updates with only a touch.

Not impressed? Try it for yourself and maybe you will be. Fingers crossed.

Coming Soon

We have put much weight behind this application and we’ll be building on the current version. In the coming updates we are looking to,

  • Utilize location to enrich the experience,
  • Provide schedules and maps of routes,
  • Implement live updates of vehicle locations,
  • Add support for more agencies.

Coming Sooner

Yes, 1Transit is exclusive for WP7 but we have been working on a version for our fellow smartphone users on Android and iOS. Stay tuned for that.


Serialization and Isolated Storage in WP7

Reading XML in and out from the provided Isolated Storage is important and quite simple, as the following code snippets illustrate. I have the methods constrained to a generic so that I can use this across all the WP7 applications that I am writing.

To write, the Isolated Storage allocated is called on by IsolatedStorageFile.GetUserStoreForApplication() where objects, XMLized by XmlSerializer serializer are written by the XmlWriter writer. The code is pretty telling, I think, so I’ll spare you the explanation.

public static void Write<T>(T obj, string fileName)
{
    XmlWriterSettings writerSettings =
            new XmlWriterSettings
            {
                Indent = true,
                IndentChars = "\t"
            };

    try
    {
        var store = IsolatedStorageFile.GetUserStoreForApplication();
        IsolatedStorageFileStream stream = store.OpenFile(fileName, FileMode.Create);

        XmlSerializer serializer = new XmlSerializer(typeof(T));

        using (XmlWriter xmlWriter = XmlWriter.Create(stream, writerSettings))
        {
            serializer.Serialize(xmlWriter, obj);
        }

        stream.Close();
    }
    catch (Exception emAll)
    {
        throw emAll;
    }
}

To read XMLized objects from storage, the following function is sufficient and pretty self explanatory. Again, the function is constrained to generic objects so that you can go crazy on what types you want to use it with.

public static T Read<T>(string fileName)
 {
     try
     {
         var store = IsolatedStorageFile.GetUserStoreForApplication();
         IsolatedStorageFileStream stream = store.OpenFile(fileName, FileMode.Open);

         XmlSerializer serializer = new XmlSerializer(typeof(T));
         return (T)serializer.Deserialize(stream);
    }
    catch (Exception emAll)
    {
        throw emAll;
    }
} 

Of course, you will have to modify Exception handling to suit your needs, these are only generalized samples. Also, the code can be improved, so write back with improvements that you might have come up with.


Follow

Get every new post delivered to your Inbox.

Join 256 other followers