Monthly Archives: May 2012

Origin client

There is one thing I hate more than the ending of Mass Effect 3… yep, you can guess it from the title…

How any major software/game company can produce a piece of c.r.a.p. like that I don’t know. The developers that wrote it must really be ashamed of themselves. You can’t be proud of something that virtually never works properly.

Somewhere after some recent update on either the Origin client or some Windows security patch I have been having major issues with this software. I use Windows 7 pro 64-bit. In the beginning the origin client manages to log in fine the first time I booted up my pc after getting back from work. Then if I leave it idle for a while doing other chores and stuff like supper and I come back nothing in and through the Origin client can connect any more. It gives a stupid error just saying it cannot connect to the Origin network. If I deliberately use a wrong password it does give an error that the username/password is incorrect. Trying the right username/password just keeps on giving the errors. I suspect it is timing out internally or there is some kind of resource/memory leak (just a raw suspicion)

The strange thing is my previous old computer I still use for general stuff and which physically stands next to the main pc connects fine using the Origin client. It still runs Windows XP  but it’s too old/slow to handle games. Both machines are connected to the exact same physical network switch. I installed Origin on this machine out of frustration just to see if the Origin network still works.

Using the ‘Reconnect’/’Go online’ option does not work. Neither does restarting the Origin client itself, or rebooting or flushing the dns (ipconfig trick) or netsh winsock reset statement or pulling the power on my network switch or disabled my firewall or run as ‘Admin’. Checked for any errors in the Windows Event logs (none). I’ve reinstalled the Origin client multiple times. Even downloaded a special version of the client they created for people with launching game issues. Nothing helps. I’ve searched the BioWare/EA forums for similar issues – lots of things that are similar but nothing that actually helps.

If the Origin client was a horse I would have taken it outside and shot it… Emptied whatever gun’s magazine I had on it!! If I had any more spare ammunition I would have reloaded and emptied that on it too!!!

If any one knows of a way to fix this issue please shout! Better yet, if EA can fix this piece of shitty software that would be wonderful! Best would be if we can play ME3 (SP/MP) without it altogether!!! Steam got some new respect from my side! At least it ‘works’ (despite it also having some issues when it started). It’s a big shame ME3 could not have been released on Steam.

Note: I even sent a copy of the error log file to EA support and they haven’t even bother to respond/acknowledge receipt of the message. So much for ‘client support’

Update: My Origin connection problems magically ended when I changed my machine’s IP address from dynamic to static…. go figure… (plus I reverted back to 2.5.8 version as well.)

Provide “Export to CSV” functionality on an ASP.Net page

I don’t do (or particularly like) ASP.Net development often but recently had to quickly add some ‘Export to CSV’ functionality of a displayed table to a page. Personally I would have just used ‘copy and paste’ to do it (the export) but since the user isn’t in the habit of thinking for themselves I had to create new functionality which turn out to be very nice – and even opens the door for some future more advanced functionality.

Anyway, to achieve this is really easy if you use the HttpContext.Current.Response class and add an attachment ‘header’ to your page. The header must be named ‘content-disposition‘ and ContentType ‘text/csv‘. See the following methods I created to simply take a DataSet and convert it to ‘CSV file’:

public class CSVExportUtils
{
    public void ExportDataSetToCSV(string title, DataSet ds, string columnNamesCSV = "")
    {
        string attachment = "attachment; filename=" + title.Replace(",", "").Replace(".", "") + ".csv";
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.ClearHeaders();
        HttpContext.Current.Response.ClearContent();
        HttpContext.Current.Response.AddHeader("content-disposition", attachment);
        HttpContext.Current.Response.ContentType = "text/csv";
        HttpContext.Current.Response.AddHeader("Pragma", "public");
        if (columnNamesCSV.Length == 0)
        {
            WriteColumnName(ds);
            foreach (DataRow r in ds.Tables[0].Rows)
            {
                if (ds.Tables[0].Columns.Count > 0)
                {
                    string value = r[0].ToString();
                    if (value.Contains(","))
                        value = "\"" + value + "\"";
                    HttpContext.Current.Response.Write(value);
                    for (int i = 1; i < ds.Tables[0].Columns.Count; i++)
                    {
                        value = r[i].ToString();
                        if (value.Contains(","))
                            value = "\"" + value + "\"";
                        HttpContext.Current.Response.Write("," + value);
                    }
                }
                HttpContext.Current.Response.Write(Environment.NewLine);
            }
        }
        else
        {
            HttpContext.Current.Response.Write(columnNamesCSV);
            HttpContext.Current.Response.Write(Environment.NewLine);
            string[] columns = columnNamesCSV.Split(',');
            foreach (DataRow r in ds.Tables[0].Rows)
            {
                string value = r[columns[0]].ToString();
                if (value.Contains(","))
                    value = "\"" + value + "\"";
                HttpContext.Current.Response.Write(value);
                for (int i = 1; i < columns.Length; i++)
                {
                    value = r[columns[i]].ToString();
                    if (value.Contains(","))
                        value = "\"" + value + "\"";
                    HttpContext.Current.Response.Write("," + value);
                }
                HttpContext.Current.Response.Write(Environment.NewLine);
            }
        }

        HttpContext.Current.Response.End();
    }
    private static void WriteColumnName(DataSet ds)
    {
        StringBuilder sb = new StringBuilder();
        if (ds.Tables[0].Columns.Count > 0)
        {
            string value = ds.Tables[0].Columns[0].Caption;
            if (value.Contains(","))
                value = "\"" + value + "\"";
            HttpContext.Current.Response.Write(value);
            for (int i = 1; i < ds.Tables[0].Columns.Count; i++)
            {
                value = ds.Tables[0].Columns[i].Caption;
                if (value.Contains(","))
                    value = "\"" + value + "\"";
                HttpContext.Current.Response.Write("," + value);
            }
        }
        HttpContext.Current.Response.Write(Environment.NewLine);
    }
}

This method also allows you to specify the fields you want to export – or alternatively it just use the ones in the DataSet. For example, you can use it like this:

if (Request.QueryString["csvexport"] != null)
{
    CSVExportUtils csvExportUtils = new CSVExportUtils();
    csvExportUtils.ExportDataSetToCSV(fileName, dataSet, "Field1,Field2,...");
}

The calling page can then simply have a hyperlink like this:

SomePage.aspx?csvexport=Yes

Death to desktop development

Well, perhaps that is what Microsoft is trying to achieve with its latest move to remove all desktop development functionality from its Express versions of Visual Studio. Yes, you can still create desktop apps in the ‘pro’ version but at something like $500 it isn’t cheap for hobbyist op someone that is still learning.  Lately they have been making all kind of wild and ridiculous decisions trying to push their new ‘Retro’, eh I mean ‘Metro’ interface down our throats. I for one don’t like this new interface ‘on the desktop’ at all and I’m definitely not the only one!

Just looking at the comments in articles like these you can get the impression that more and more people (developers) are really not liking this new direction that ‘they’ are taking. It is one thing to create something new and exciting but another to actively alienate/irritate your existing followers just to try and push them into a new direction (which might or might not suit them). Is this rush to try and play ‘catch-up’ with ‘the fruit company’ so important that they actually are shooting themselves in the foot? Yes, that is right, they are actively playing the catch-up game but is loosing it with every move they are trying. Not a good move if you want to survive in the end. As big as they are (once) ‘they’ are now in the ‘failing’ game – as Adam Savage would say – Failure is always an option. Microsoft is now ‘living’ that lotto!

Was good knowing ya: RIP Microsoft 1975-2012

Passing a ‘Method’ as parameter in C#

This is actually nothing new but sometimes you might still need a quick reference for to remember how to do this quickly… Say you have a generic class that does something like generating a report and display it somehow (or save or whatever the class do) and want all the ‘calling classes’ to just pass the ‘Method’ that it must ‘run’ in order to generate the report. Yes there are probably nice and fancy tools these days that could also do it if you have the mulla for it…

A solution is to use Anonymous methods that has been with C# (.Net) since version 3 of something.

Reporter r = new Reporter();
r.Report = delegate
{
string stuff = "example report yada yada yada";
return stuff;
}
r.Show();

The generic class that provides the ‘generic’ functionality can then look something like this using a defined delegate so it knows what output it will receive when ‘running’ the method.

public delegate string RefreshActionDelegate();
class Reporter
{
    public RefreshActionDelegate Report { get; set; }

    public Show()
    {
       if (Report != null)
       {
          string theContent = Report();
          DoSomethingWithContent(theContent);
       }
    }
}

This is just a quick example but it shows how you can use the main ‘generic’ class from multiple places each time just passing a different ‘Method’ with its own functionality.

GenDB

I’v been involved for many years with helping, developing, working with an uncle of mine’s genealogical research – at least the ‘IT’ side of things. Over this time I developed more than one solution to house a database for storing all the relevant data gathered – first an Access database and later stand-alone application using either the old Access database or newer sql express. Lately I’ve been trying to find a way to get away from the clumsiness of having a separate piece of software installed to get a database. It just makes setting up and maintaining an application so much more difficult – since the type of person using these applications are usually very close to ‘computer-illiterate’ or just doesn’t care ‘how it it works’ but rather just ‘that it to works’.

So I’ve been working to create something that does not require a traditional database but is still easy to maintain and troubleshoot if needs be. I choose to use a plain and simple xml file. You might start to think that this is bad idea because of various reasons like loosing all the features built into professional database systems. But you would be wrong for the ‘wrong’ reasons 🙂 . Let me explain. For the purpose of this system the requirements are different from what you would expect when using a ‘traditional’ database. Consider this – for this little ‘system’ the following are applicable:

  • Single user, single machine use only
  • The volume of data is ‘low’. I can’t imagine someone want to put millions of persons’s information in this little application. I have an actual working example with the information of 11000+ people and the performance is really good.
  • No need for fancy transactionality, relational integrity and other jargon users don’t understand anyway (at the database/file level). The app itself (dal/object level) takes care of it.
  • backups are as easy as simply copying a singe file to some other location
  • although xml is well structured and for ‘computer’ use even a normal user can open the file and view it as text to read it. Of course, they can also easily break it by editing it manually…
  • Fewer components to maintain. No security fixes/service packs of sub components of which most parts are not even used at all. That is the ‘price’ you pay for using a technology that has to cater for lots of different possible ways to use it.
So the little application I created is a plain and simple C# Windows application. All it requires is the ‘client-side’ .Net 4 framework (not even the full thing) which is relatively small these days. It is still really a ‘proof-of-concept’ application but is fully functional and usable.
Summary of the features:
  • Enter/view details of persons (like names, surnames, dates and places of birth/christening/death, parents and children, marriages, history, photos and even unlimited separate notes)
  • View a family tree for a person – both predecessors and descendants  plus a summary of each person (birth/death/marriages). Up to 7 generations (up and down) are allowed but for practical reasons it is better to specify less.
  • There are several built-in reports (too many to name now). Since they are all html based they are easy to export and share with others.
  • Searching for persons (of course)
  • Comparing details of multiple persons (even a graphical view of living-years so you can see who lived around the same time)
  • Mark selected persons as ‘favourites’ so you can more easily find them again.
  • You can have multiple ‘databases’ (files) – simple got to settings and select another file.
  • the .gfdb file extension is associated with the application meaning you can simply double-click  such a file in Windows Explorer/Desktop and it will be opened with the application.
  • Since we mostly use the ‘de Villiers/Pama System‘ genealogical numbering system in South Africa there is some support to automatically generate these numbers based on a person marked as the progenitor.
It also features bilingual ‘run-time’ support which is something you don’t find often in applications. At the moment it support both English and Afrikaans.
Data format
I did consider GEDCOM and even GEDXML at some time but both have ‘issues’ of their own. GEDCOM is a text flat file format that is not very user friendly and easy to ‘break’. It is very widely used though. GEDXML is not really a standard format at all. They started working on it and abandoned it after a while – not sure why.
‘My’ format is not really a standard on its own – I’m not claiming it to be super or fantastic. It is plain and simple and works for my purposes.
Installer

Grab a copy of the installer here and let me know what you think. The zip file contains an example gfdb file containing some (fictional) Star Wars character information to illustrate how the application work.

Update: Version 1.1 available here.

Another Update: Version 1.2 available here

Formatting C# code in WordPress post

If you are like me working with C# a lot and trying to post articles on your WordPress site you might like this: Alex Gorbatchev’s SyntaxHighlighter

Example source code listing

[ sourcecode language=”csharp” ]
void Stuff
{

int moreStuff = 0;

}
[ /sourcecode ]

Would look like this:

void Stuff
{
    int moreStuff = 0;
}

I haven’t tested it with all possible language features but at least it is a start!

Not a good day to be a chair…

Ok this could be hilarious if it was even more funny… Forbes named the top ‘worse’ CEO’s of all companies and Microsoft is at the top (or is that bottom…). I’m sure some investors would not be impressed.

Lets hope the chairs at Redmond have all their life cover up to date. This could be the end….

Too old to be a ‘software engineer’?

One of the newsletters (emails) I subscribe to recently had an entry about the issue ‘Is Software Engineering Dead?’ – by Steve Jones. This is so true…

Let me ‘copy’ the editorial here:

Is Software Engineering dead? It’s a premise that’s in this article from Bloomberg. It calls the job a career dead end where job prospects decline after one reaches 35 years of age. I think that’s a naive view of the industry, despite the quotes from Craig Barrett and Mark Zuckerberg. While the best of the best might peak in their careers at the same age as many athletes, that doesn’t imply that the career choice is a poor one.

There’s a discussion on Slashdot as well, and I was struck by a few of the comments, which seem to suggest that if you are still just a “software engineer” at age 40, you aren’t very good at your job. It seems that some people seem to think that everyone in this business is constantly looking to move to a new job and advance into management or they aren’t successful . I saw analogies with other industries thinking that same thing, that experienced people would not still be doing the same job after 20 years.

That seems crazy to me. So many people in various industries continue to improve at their jobs, and do the same work for decades. Carpenters, doctors, accountants, all continue to improve their skills over time, and while some may more into management or open their own firms, many will continue to do their same jobs until they retire. And they’ll enjoy their careers.

I don’t deny that ageism exists, and that older programmers often can’t, or won’t, work as many hours as younger ones, but that doesn’t mean they aren’t worth their salaries. Good, experienced programmers produce better code, with fewer bugs. Once managers learn that working more hours doesn’t equal better code, or even more code, the entire industry will start producing better applications.

Steve Jones from SQLServerCentral.com

Well now, without giving away my age too easily.. (cough cough) I’m afraid I’m this piece is very relevant to me too. I’ve been in the software/development/computer/IT industry for many many years (~16+ year) and I still enjoy the basics of software development – but I’ll admit I’m not doing as much as I use to and definitely not as many different things, including new stuff all the time. So is it possible to go on as a ‘software engineer for ages over (say) 35? The perception out there seems to be you have to move into ‘management’ or so in order to ‘progress’ in your career. Trouble is I’m not a ‘peoples’ person and I don’t like managing them either. Is that wrong? Should I be forced to do something I don’t like and probably won’t be good at? Flip-side – Is it wrong to stay with something you like for your whole career? Certainly the market don’t appreciate you – since it doesn’t count how many years experience you have, at a certain point you just don’t get paid any more than before. Personally I think that is an insult and that ‘we’ are worth more not just because of the years of good experiences we have but also the bad things we learned ‘not to’ do. Perhaps there is a place for a more ‘mentoring’ role – which is different from managing a person.

I must admit that lately in my ‘day job’ I’ve been more into ‘administrating’ (BizTalk) than actually developing. This too is sort of just another part of software engineering as it requires me to find clever and original ideas to do my job as other ‘developers’ keep on finding interesting ways of breaking the things I have to administrate. In my personal time in non working hours I still work on ‘pet’ projects mostly around genealogy projects. Some things in life do get better with age – like red wine…

Lets drink to that… (responsibly of course) 😉

Linq – group by multiple fields

Seems this is an issue that multiple people have asked around at several occasions.

The question is how to use a Linq query where you want to group on more than one ‘field’

Turns out it is really not that hard. Thanks to ‘Anonymous’ methods that was also introduced ‘yay back’ it is as simple as the following example. Lets say you have a list of values like these:

Person 1: Age = 25, Gender = M, HighScore = 123
Person 2: Age = 21, Gender = F, HighScore = 99
Person 3: Age = 27, Gender = M, HighScore = 140
Person 4: Age = 19, Gender = M, HighScore = 131
Person 5: Age = 25, Gender = M, HighScore = 119
Person 6: Age = 22, Gender = M, HighScore = 108
Person 7: Age = 27, Gender = M, HighScore = 152
Person 8: Age = 21, Gender = M, HighScore = 98
Person 9: Age = 22, Gender = M, HighScore = 101
Person 10: Age = 25, Gender = M, HighScore = 167
Person 11: Age = 22, Gender = F, HighScore = 105
… etc

To get a simple report on average high score by Age and Gender you’ll have to use a query like this:

foreach(var entry in (from p in Persons
group p by new {  Age = p.Age, Gender = p.Gender } into g
orderby g.Key.Age, g.Key.Gender
select new
{
Age = g.Key.Age,
Gender = g.Key.Gender,
Avg = g.Average(pavg=>p.HighScore)
} ))

{

Console.WriteLine(“Age: {0}, Gender: {1}, Avg: {2}”, entry.Age, entry.Gender, entry.Avg);

}

Perhaps it might have simpler if you could simply have stated : “group p by p.Age, p.Gender” but unfortunately this is not supported. Then again this allows you to be more creative in defining the anonymous type so you can manipulate the data even more. Perhaps in the next version of Linq… if there is ever one…

 

Fun in the sandpit.. or not

Just a few comments (just my thoughts) about the whole ARM version of Windows 8 that won’t allow 3rd part browsers (desktop apps).

In  a way this is not Microsoft’s fault as the underlying architecture (processor) is totally different meaning applications (the actual binaries) need to be written to support this – and that is up to the developers of the app. Then again, Microsoft is creating the operating system which ‘host’ the applications and provide the API’s that the applications should use. It all depends on ‘how’ the applications are written how tightly they are tied to the underlying infrastructure. In an ideal world the OS should provide ‘ALL’ the API’s that any applications might need so they never need to be even aware of the actual hardware they are running on. I’m not sure is that is the case for Firefox or Chrome (they might have their own optimized code to better make use of specific hardware… but I don’t know).

The other problem is that Microsoft is trying to move away from the whole Windows API (at least the i386/Win32 stuff) which is a problem for ‘real’ applications (a I would have called them). Microsoft has been busy for years to try and create a new ‘middleware’ layer they call ‘.Net framework’ that should ‘shield’ applications from hardware details. Unfortunately very few of the larger application providers has ever taken .Net seriously (including some MS departments themselves).

Perhaps a simpler metaphor could explain this ‘issue’ better. Say we see the ‘OS’ as a sandbox (like a real one kids play in…). The applications are the toys. The users are the children playing in/with the sand (and yes, kids sometimes through their toys out the… you know…). Now MS is trying to make a new sandbox with a different type of sand but the toys weren’t made to work with that kind of sand (ye ye its fictional). The guys making the ‘toys’ are now complaining that their ‘toys’ won’t work in that sandbox which mean the kids there won’t be able to play with them. Big deal! So what? Perhaps the toy makers must just make their own damn sandbox (which they already have/or are in the process of making). As things look now there won’t be too many kids in this new sandbox anyway (my opinion) and it will fail miserably (since that other fruit company already has a new BIG and exciting sandpit where all the new ‘cool’ and ‘hip’ kids hang out…

Seems to me there will be a whole lot of toys and sand being thrown around soon with a lot of kids ending up with sand in their faces/mouths so no one is gona be ending on a happy note. Perhaps its time someone clean out their own sandpit of all the ‘bad’ stuff in there already before they think of getting a new one… hehe Jus saying….