Showing posts with label software. Show all posts
Showing posts with label software. Show all posts

Sep 27, 2012

Aggregating Shared Google Reader Posts in the Google+ Era

Ever since Google overhauled the reader and removed the original share button I was searching for a way to get to my shared items in the RSS form. None of the online suggested solutions was acceptable for me so I figured, since I already have ASP.NET hosting, that creating a new site, that would tap into the Google+ API and parse the shared posts as RSS would be the way to go. Fortunately that was very easy to accomplish with a blank ASP.NET MVC solution, some NuGet packages for JSON and REST and a bit of API reference browsing. So, behold the code:

 

 

It should be however noted that you need to create a Google API key in their API console.

Now I can finally access my google reader shared items via RSS feed... Again... Hooray!

Apr 14, 2011

C# gotcha

Consider you have the following code:

SomeClass reference = null;
Console.WriteLine(reference.Echo("echo"));

Your first thought might be “NullReferenceException”. Ha, think again! What if you have an class defining an extension method like this:



public static class SomeClassExt
{
public static string Echo(this SomeClass x, string str)
{
return str;
}
}

You have been warned :)

Feb 10, 2011

MVC – Unit Testing JsonResult Actions

Today I had to write a unit test for a Asp.net MVC controller that returned a JsonResult. The Controller’s code looked somewhat like this:


[HttpPost]
public JsonResult JsonData(Query query)
{
// ... process query, get total_row_cnt and rows
return Json(new { total_row_cnt = rowCount, rows });
}

I often return anonymous types as JsonResult, just because I don’t want to have additional return model classes for JavaScript that are used only by one controller action and nowhere else.


And what about unit testing such actions? Sure JsonResult exposes a property called Data (of type object), that contains the argument passed to the Controller’s Json() call. If the type of the Data is known you can easily cast it to the known type and do further processing. But what if you pass an anonymous type as data to the JsonResult? How can you verify the results then?


Well you have the following options:


  • convert the anonymous type to a class,

  • directly use reflection on the returned object (magic strings!),

  • or make use of C# 4 dynamics!


The first two options are trivial, and I’m going to discuss only the last option. Simply casting the JsonResult.Data won’t do, since the type object does not implement the necessary infrastructure. I decided to implement a wrapper class that implements DynamicObject. Since anonymous types can offer only readonly properties all I had to do was to override the TryGetMember method. So here is the implementation:



using System;
using System.Dynamic;
using System.Reflection;

public sealed class AnonymusDynamicGetWrapper : DynamicObject
{
private readonly Type _subjectType;
private readonly object _subject;
public static dynamic Create(object subject)
{
return new AnonymusDynamicGetWrapper(subject);
}
private AnonymusDynamicGetWrapper(object subject)
{
_subject = subject;
_subjectType = subject.GetType();
}

public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = null;
var propertyInfo = _subjectType.GetProperty(binder.Name);
if (propertyInfo == null) return false;
var getter = propertyInfo.GetGetMethod();
if (getter == null) return false;
result = getter.Invoke(_subject, null);
return true;
}
}

And finally the unit test method:




[TestMethod]
public void Simple_Data_Test()
{
// ... setup the test, controller and query
var data = controller.JsonData(query).Data;
var rowCnt = AnonymusDynamicGetWrapper.Create(data).total_row_cnt
Assert.AreEqual(25, rowCnt);
}

Nov 24, 2010

KOTO - KO Tournament Organiser

I recently released my KnockOut Tournament Organiser (short. KOTO) application to the public. The application can be used to help you organise any kind of knockout elimination tournament events (karate, tennis, ...)




Features

  • Intuitive entry form, requiring minimal effort

  • Automatic draw (random, custom)

  • Simple billing system (global entry fee, customizable per category)

  • Draw printing and export to XSLX (customizable XLSX template)

  • Diploma printing (customizable XLSX template)

  • Various printable reports, fully customizable via CSS

  • Automatic version updates
  • The software has been actively developed, maintained and used for the organization of all official karate competitions hosted by the Karate Federation of Slovenia in the past 6 years.

    Requirements: Windows XP +, Microsoft Office 2007 +, .NET Framework 3.5

    If you want to evaluate the application feel free to contact me.