Tag Archives: C#

TechEd Demo Video Available Online

As previously announced I presented a session at TechEd Australia 2013 and anyone who came along will know I had some challenges with the demo component of my talk on the day. I thought it would be great to actually show you all how the demo *should* have run on the day, so to that end I’ve recorded a screencast that runs through the entire demo with a few tips and tricks along the way. I recommend you run it full screen!

You can also grab the sourcecode from this demo here: https://github.com/sjwaight/techedau2013

The video is available on YouTube here: http://youtu.be/QQO3r0myTd4 (and is embedded below).

Tagged , , , , ,

Portable Azure Mobile Services DTOs when using Xamarin and C#

As part of an upcoming talk I am giving I am spending a lot of time working on a demo that shows how to do push notifications cross-device. One concept that is really drummed in when working in this space is that building reusable C# is key to leveraging the savings from building Windows Phone, iOS, Android apps this way.

A C# Azure Mobile Services client library exists for each of the platforms and it’s really easy to use your standard C# classes as Data Transfer Objects (DTOs) for storage in Azure as a result. One item that tripped me up on Android and iOS was that I found I could write data to the cloud easily and while I could get a set of resulting objects back their properties were either null or in their default state. Not useful!

This is how my class looked – I had arrived at this after using DataMember and JsonProperty objects and finding, at first appearances, that I didn’t need either for the code to actually work. I was wrong :).

public class Task : IBusinessEntity
{
     public Task () {}

     public int ID { get; set; }
     public string Name { get; set; }
     public string Notes { get; set; }
     public bool Done { get; set; }
     public string Assignee { get; set; }
}

The challenge in decorating the above class with DataMember is that this class isn’t actually natively supported on Windows Phone – you will get a NotSupportedException the first time your application attempts to run any code that uses this class. The suggested fix in the Exception is to utilise the JsonProperty attribute instead which doesn’t actually work on Android or iOS deployment. So… this is the fix I came up with – it’s not pretty but it is leveraging one way to build portable C# code (note there is no default symbol defined for iOS builds which doesn’t help!) Behold…

public class Task : IBusinessEntity
{
    public Task () {}

    public int ID { get; set; }

#if !WINDOWS_PHONE
    [DataMember(Name = "name")]
#endif
    public string Name { get; set; }

#if !WINDOWS_PHONE
    [DataMember(Name = "notes")]
#endif
    public string Notes { get; set; }

#if !WINDOWS_PHONE
    [DataMember(Name = "done")]
#endif
    public bool Done { get; set; }

#if !WINDOWS_PHONE
    [DataMember(Name = "assignee")]
#endif
    public string Assignee { get; set; }
}

I think you’ll find that compiler pre-processor directives like this will quickly become your friend when writing C# to target multiple platforms.

Tagged , , , , , ,

Debug iOS App from Visual Studio with Xamarin extension using the iPhone Simulator.

This is a really quick and easy tip for those starting out doing iOS development with Xamarin (and specifically with the Visual Studio extensions). If you don’t have access to an iOS device and want to debug on the Simulator that ships with Xcode make sure you do the following:

Set the “Platform” to “iPhoneSimulator” for the project.

1. Select the Solutions Configuration menu (allows you typically to choose Debug or Release) and is next to the “Start” debug button.
2. In the Configuration Manager for your iOS App select “Platform” and change to “iPhoneSimulator” (highlighted below).
3. Save the changes and you should now be able to debug.

Selecting iPhoneSimulator

I scratched my head on this for a while ;).

BTW, did I say how cool it is that you can develop Android and iOS apps from right inside Visual Studio? You still need a Mac and Xcode for iOS but Android is there for the taking (you can even edit the axml layout files directly inside Visual Studio!)

Tagged , , , ,

TFS As A Service (TFSPreview.com) – Connect to and Query Using C#

Having worked with every version of Team Foundation Server (TFS) since its inception I was keen to see what API support “TFSPreview.com” has. The good news is that (at time of blogging) the API accessibility is all there, is free and aligns with the on-premise API and client object model.

I’ve always felt the strongly-typed client object model and library is a strength of the TFS offering over many of its competitors and the classes that compose it provide some good extensibility possibilities – I’ve been on a project where all “Requirements” work item types from an MSF Agile project were exported via the API to a Word document and formatted for presentation to the customer (and we could re-run it any time!)

This past week has seen the RTM availability for a bunch of Microsoft products including Visual Studio and Team Foundation Server 2012, which means that an RTM set of the TFS Client Object Model assemblies are now available. After grabbing them I fired up Visual Studio, added in the correct references and was able to connect to our TFS Preview instance and perform some query magic.

Here’s an (incomplete) sample of how easy it is!


// Add the namespaces.  Make sure it's version 11.0.0.0!
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client; 

// some time later in your code...
// this code assumes the user who owns the current thread has previously authorised against the server
using (TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("https://yourinstance.tfspreview.com/defaultcollection"), new TfsClientCredentials()))
{
     var workItemService = tpc.GetService<WorkItemStore>();

     var queryString = "Select [State], [Title] From WorkItems Where [System.TeamProject] = @TeamProject and [Work Item Type] = @Type and [Assigned to] = @Me";

     var variables = new Dictionary()
                         {
                             {"Type","Task"},
                             {"TeamProject", "YOURPROJECT"}
                         };

     var query = new Query(workItemService, queryString, variables);
     WorkItemCollection results = query.RunQuery();
}

So the above is just a simple and incomplete example – but it will connect and return results for you. The TFS extensibility options are pretty wide and varied as can be seen on MSDN! I’ll post more stuff up here over time as I work through my planned use of this server (a custom team board in our office… too big perhaps, but hey…).

If you don’t have a TFSPreview account I’d recommend getting one and having a play – Microsoft has said the platform will be free through until the end of 2012 so I’d say there’s no better way to try it out than that. They are also shipping updates for the platform every 3 weeks which will be ahead of the on-premise version which will get quarterly updates (based on the TFSPreview updates). Get in and get informed.

Tagged , , , , , , , ,