Search code examples
c#.net-4.0windows-8calendarwindows-live

How to read/extract the calendar entries returned by the GetAsync() in the Live SDK?


I am trying to get all the calendars a user has. The code I am using is:

LiveConnectClient liveClient = new LiveConnectClient( App.Session );
LiveOperationResult operationResult = await liveClient.GetAsync( "me/calendars" );
dynamic result = operationResult.Result; 

When looking with the debugger into result I can see the calendars (keys and values). However I am having a problem extracting the information from this DynamicDictionary.


Solution

  • I managed to solve the issue and the code to do it (with some debug messages) is as follows:

    try
    {
        LiveConnectClient liveClient = new LiveConnectClient( App.Session );
        LiveOperationResult operationResult = await liveClient.GetAsync( "me/calendars" );
        dynamic result = operationResult.Result;
    
        List<object> data = null;
        IDictionary<string, object> calendar = null;
    
        string msg = "Calendar names: ";
        Debug.WriteLine( msg );
    
        if ( operationResult.Result.ContainsKey( "data" ) )
        {
            data = (List<object>)operationResult.Result[ "data" ];
            for ( int i = 0 ; i < data.Count ; i++ )
            {
                calendar = (IDictionary<string, object>)data[ i ];
                if ( calendar.ContainsKey( "name" ) )
                {
                    string Name = (string)calendar[ "name" ];
                    string ID   = (string)calendar[ "id" ];
                    msg = string.Format( "Name = {0}, ID = {1}", Name, ID );
                    Debug.WriteLine( msg );
                }
            }
        }
    }
    catch ( LiveConnectException exception )
    {
        Debug.WriteLine( "Error getting calendar info: " + exception.Message );
    }