.NET


I’m going to show you how to convert a List<T> object into a properly formatted XML string you can use to POST to a HTTP endpoint.

First, let me show you my C# POCO classes:

   1: [Serializable()]

   2: public class GameMatch

   3: {

   4:     public GameMatch()

   5:     {

   6:         Summoners = new List<Summoner>();

   7:     }

   8:  

   9:     public int GameId { get; set; }

  10:     public string MethodType { get; set; }

  11:     public int GameLength { get; set; }

  12:     public string GameMode { get; set; }

  13:     public string GameType { get; set; }

  14:     public int IpEarned { get; set; }

  15:     public int IpTotal { get; set; }

  16:  

  17:     public List<Summoner> Summoners { get; set; }

  18: }

  19:  

  20: [Serializable()]

  21: public class Summoner

  22: {

  23:     public Summoner()

  24:     {

  25:         Items = new List<Item>();

  26:     }

  27:  

  28:     public List<Item> Items { get; set; } //DONE

  29:  

  30:     public int ProfileIconId { get; set; } //DONE

  31:     public string SummonerName { get; set; } //DONE

  32:     public int Level { get; set; } //DONE

  33:     public int ChampionLevel { get; set; } //DONE

  34:     public bool BotPlayer { get; set; } //DONE

  35:         

  36:     public int Wins { get; set; } //DONE

  37:     public int Losses { get; set; } //DONE

  38:     public int Leaves { get; set; } //DONE

  39:  

  40:     public int NeutralCreepsKilled { get; set; } //DONE

  41:     public int MinionsKilled { get; set; } //DONE

  42:     public int ChampionsKilled { get; set; } //DONE

  43:     public int Assists { get; set; } //DONE

  44:     public int LargestMultiKill { get; set; } //DONE

  45:         

  46:     public string SkinName { get; set; } //DONE

  47:     public int SummonerSpell1Id { get; set; } //DONE

  48:     public int SummonerSpell2Id { get; set; } //DONE

  49:  

  50:     public int DamageDealt { get; set; } //DONE

  51:     public int PhysicalDamageDealt { get; set; } //DONE

  52:     public int MagicDamageDealt { get; set; } //DONE

  53:     public int LargestCriticalStrike { get; set; } //DONE

  54:     public int HealingDone { get; set; } //DONE

  55:  

  56:     public int PhysicalDamageTaken { get; set; } //DONE

  57:     public int DamageTaken { get; set; } //DONE

  58:     public int MagicDamageTaken { get; set; } //DONE

  59:  

  60:     public int GoldEarned { get; set; } //DONE

  61:     public int TimeSpentDead { get; set; } //DONE

  62:  

  63:         

  64:         

  65:     public int InhibitorsDestroyed { get; set; } //DONE

  66:     public int TurretsDestroyed { get; set; } //DONE

  67:         

  68:     public int Deaths { get; set; } //DONE

  69:     public int LargestKillingSpree { get; set; } //DONE

  70:     public int Lose { get; set; } // Maybe this means, 1 = lost; 0 = won? Look into it.

  71: }

  72:  

  73: [Serializable()]

  74: public class Item

  75: {

  76:     public int ItemId { get; set; }

  77: }

 

Simple easy to understand POCO classes with automatic properties.

Next, to serialize them all we need to do is use a XmlTextWriter and XmlSerialWriter

   1: List<GameMatch> parsedMatches = LogParser.Parse(path);

   2:  

   3: StringWriter stringWriter = new StringWriter();

   4: XmlDocument xmlDoc = new XmlDocument();

   5:  

   6: XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);

   7:  

   8: XmlSerializer serializer = new XmlSerializer(typeof(List<GameMatch>));

   9:  

  10: serializer.Serialize(xmlWriter, parsedMatches);

  11:  

  12: string xmlResult = stringWriter.ToString();

  13:  

  14: xmlDoc.LoadXml(xmlResult);

At this point stringWriter.ToString() will return a pure string of the XML representation of your List<T> object.

Hope this helps!


Hey there. Today I took a gander at my DreamInCode library I released for .NET and decided to merge it over to Github.

https://github.com/sergiotapia/DreamInCode.Net

The source code is very easy to follow and hopefully I managed to clean out a lot of the cruft and over engineering I managed to cram in the previous version.

This time it’s simple, clean and barebones.

Continue Reading


Typical.

Internet Explorer just keeps biting us web developers in the ass and we have no choice but to find work arounds.

After toying around with SignalR on my MVC3 application, I tested things out in IE 8. Surprise surpise. It didn’t work.

When you run your application in Internet Explorer you’ll see this dreaded icon on the bottom left.

Continue Reading


This post is based on Scott Hanselman’s SignalR post – but tweaked for MVC3. Source.

This is getting my vote for Tool of The Year™ 2011.

As it’s description states in their GitHub page:

Async signaling library for ASP.NET to help build real-time, multi-user interactive web applications.

In a nutshell SignalR lets you communicate with clients on your website in real time. Imagine Comet implementation without all the fuss. Dead easy to setup, dead easy to work with, fast as holy hell. Yes – I’m excited.

I’m going to show you how to build a small chat application using SignalR in an MVC3 application.

Continue Reading


Today I’m going to show you how to create an editor template for DateTime objects in your model.

This is what we’re aiming for. A label for our input, and when the input has focus we should display a nice DatePicker widget kindly provided for free by the excellent jQueryUI library.

Our end result.

Continue Reading


I’m sure there are many ways to skin this proverbial cat, but I’ve worked on it for a bit and I feel I like this approach. It’s easy to modify, easy to follow along with and allows for some cool GUI manipulations. Well, as far as you can get with Windows Forms anyway.

Here’s a screenshot of how it looks when someone tries to act smart and corrupt our precious database!

app Screenshot

Here’s how to do it.

Continue Reading