Cerulean SkyDrive cloud filesystem

Cerulean revolves around an instance of the SkyDrive class. The public interface is simple.

public void Authenticate(string username, string password) 
public string LoadString(string path) 
public void SaveString(string filepath, string content[, bool blocking = false]) 
public void Delete(string path) 
public event System.EventHandler FileSystemChanged

You don’t need to create an instance, the Singleton pattern is implemented. Use SkyDrive.Instance.

Pass credentials to Authenticate. If it succeeds, the filesystem is read asynchronously into cache and when this is ready the FileSystemChanged event fires. If authentication fails there is an exception which you must handle at the application level because it’s asynchronous.

Using SaveString to create a file on a path that doesn’t exist causes the path to be created. If you need this call to block (eg saving state before being swapped out) specify a value of true for the optional third parameter.

Delete can delete a file or a folder and all its files and subfolders.

LoadString returns the content of a file as a string.

The absence of methods for saving binary data is intentional. WP7 serialisation is heavily geared toward XML for which SaveString and LoadString are well adapted.

The supplied sample app authenticates, creates a file on a path two folders deep and then reads the content of the file before deleting it again. Here’s the code from the app. Asynchronous code is curiously backward. Authenticate appears last in the code but executes first.

      System.EventHandler d1 = null;
      string filepath = "/Cerulean/testfolder/test.txt";
      d1 = (s1, e1) =>
        //unhook the handler so it only fires once (SaveString updates the filesystem model)
        SkyDrive.Instance.FileSystemChanged -= d1;
        //create a file with some recognisable content
        SkyDrive.Instance.SaveString(filepath, "This is a test of folder and file creation.", true);
        //read the file from SkyDrive and emit the content to the output pane for inspection
        Debug.WriteLine("FileSystemChanged: {0}", SkyDrive.Instance.LoadString(filepath));
        //delete the file but not the path on SkyDrive
      SkyDrive.Instance.FileSystemChanged += d1;
      App.Current.UnhandledException += new EventHandler<ApplicationUnhandledExceptionEventArgs>(Current_UnhandledException);
      SkyDrive.Instance.Authenticate("username@live.com", "password");
      //The FileSystemChanged event won't fire unless authentication succeeds and the filesystem is read.
      //Authenticate throws UnauthorizedAccessException when it fails. This is asynchronous so handle it
      //at the application level and marshall onto the UI thread.

Last edited Nov 26, 2011 at 12:46 PM by PeterWone, version 12


Birbilis Nov 13, 2013 at 8:34 AM 
So is it ok to use strings to load/save images etc?

venetasoft Mar 10, 2012 at 1:31 AM 
Could you please add a progress event for both upload and download operations ?
Official LiveSDK has it but it is bugged (does not work).