FreeMind Conversion With C# & LINQPad

So I’ve recently been put on a project that requires me to investigate the source code for a bunch of existing applications and provide recommendations/estimates for updating them to include some new functionality. In order to accomplish this, I have to somehow organize my thoughts/notes in such a way that I can provide estimates for the amount of work it would be to perform the upgrades. In this particular case, there are 3 small .Net 2.0 (C#) applications and one beast of a C++ application.

My approach is generally to go through the code at a reasonably high level, taking as many notes as I can about what I see. Generally, this works out to be pretty high level observations about how things are organized, how coupled the classes may be, how many hard-coded values there are that may cause problems when trying to extend components. Things like that.

After I’ve got that, and I have a basic understanding of how the solutions behave/work (along with an understanding of what the upgrades are going to be) I can start to break down the upgrade details into manageable pieces. These pieces are small enough that I can hold all the different things that would need to change in my head at once (in general). This way (even though we all know how flawed estimation can be) I can give at least a somewhat reasonable guess as to the amount of work involved.

This may be a function of how I think but I have found that I tend to conceive of these tasks in a hierarchical fashion. That is to say, I start at a high level piece of functionality (user logins for example) and break it down into more pieces. For example if the task was to add profile pictures to users for a web application, that may involve file uploads, file type validation, or fetching the user photo from a service like Gravatar.

In order to keep track of all this, I have found that mind-mapping tools are a great help. On my last few projects where I have been doing this sort of estimation work, I have used the open source tool FreeMind (which I have become very fond of). It allows you to create the hierarchy of ideas in a navigable tree structure very easily and quickly.

Example Mind Map

Example Mind Map

You can easily navigate between nodes (using the arrow keys), insert a new sibling node (enter) or insert a child node (insert), all using the keyboard. Holding down ctrl and using the arrow keys lets you move nodes around as well.

This is great for getting your thoughts in order but eventually you are going to have to transfer these ideas into some other tool, be it excel or some sort of ticketing system. For this project our estimates are all going into a series of spreadsheets, so I need a nice way to get a flattened view of this data while still preserving the hierarchical information. For another project, I wanted to parse out some additional information I had encoded in the node text (such as estimated hours) and upload the nodes as tickets to the ticketing system we use at work (Assembla).

Since the FreeMind file format (.mm) is just an xml document, it is quite easy to parse this information and programmatically do what you want with it. In a past project, I parsed the XML file in a C# application which I then used to make web requests to create tickets in Assembla with the information I wanted. This was quite convenient since once you get a mind map with over 200 nodes, no one wants to enter that into a ticketing system by hand*. The way I did that was pretty cavalier and quite an ugly mess so I’d like to clean that up a bit.

What I have done for my current project is just utilized the amazing tool LINQPad to write some C# queries to parse the FreeMind file and generate a tab-indented text file (the tabs indicating the hierarchy) that I can then copy into excel and visually represent my hierarchy of ideas. If you don’t know what LINQPad is I would suggest you go check it out, it’s a a really handy tool for writing quick little C# snippets/programs/LINQ queries.

I use XML parsing facilities built into .Net (XDocument, XElement, etc.) and a couple simple classes and LINQ queries to build a set of nested “Node” objects which contain the text for the node and a child collection of nodes (providing the hierarchy). Running the code on the mind map featured previously yields a tab indented structure similar to the following:

User Profile Pictures

Select Image From Gallery

Retrieve Images From Server
Display Gallery
Associate Gallery Image With Profile

Upload Image From Computer

Upload File
Save File To Profile Data

Use Gravatar Image

Choose Email For Gravatar Image
Load Image From Generated Gravatar URL

The code that I used to generate this example is as follows:

Now what I would like to be able to do is generalize the parsing of the mind map and the processing of the node hierarchy in such a way that it can be used for multiple applications. I need to think on it a little more about how exactly I am going to do that but I anticipate a future blog post once I am able to wrap my head around it. Hopefully I can release a nice compact library that people can easily use (that will probably have to wait until after my vacation).

*It should be noted that you can upload a csv file or something similar to the Assembla website, however, it isn’t possible to include ticket relationships (parent/child structure) as far as I am aware.

Advertisements

Go To A Conference!

I don’t care who you are (or what you do), do yourself a favour: go to a conference!

Seriously.

Even if you have no skills whatsoever, go to the local conference on the latest knitting techniques, I guarantee you will learn something. It probably won’t even be about knitting.

I recently attended GOTO Chicago, a software development conference in (you guess it), Chicago. It was amazing. There were 2 days of talks and 2 days of training (all of which I attended). The speakers were world-class, giving valuable/engaging presentations: there was probably only 1 presentation I’d rate as not being worth it. Everything from fighting cancer with Lisp, to writing databases in Clojure and the power/failure of incentives. Great variety of speakers/topics from across the spectrum of software development.

Now, none of the talks really taught me how to utilize any specific new technologies or anything, but that’s not the point. It made me aware of a whole bunch of stuff (you should see my list of things to google). Most of the things I scribbled down to look up later were not the focus of any talk, they were tid-bits that came up as the speakers were talking: books to read, tools to check out, libraries to investigate.

That’s all well and good, but that’s not where you get the true value out of a conference. The variety of different subjects, technologies, and speakers made me think. I saw how other people tackled problems similar to those that I have faced, as well as problems I have never seen before. All of this forces you to re-evaluate your approaches (past, present and future) and makes you better at whatever it is that you do. So often we get into the grind of our daily work lives that we don’t often take time to reflect on either what we are doing or how we are doing it. I find that the time spent at a conference both give me time to think about these things and forces me to really evaluate how it is that I do my job (whatever that may be).

Now, that’s all great but I still don’t think that is the most valuable part of a conference. For me, the single most important reason to go to a conference is people. When you go to a conference generally what you end up with is a whole bunch of really smart people (both speakers and attendees) in the same room(s) for a couple days. This is where the magic happens.

When you are at a conference you have a unique opportunity to talk with prominent figures in a field, as well as a whole bunch of people who actually care about the topic at hand. Where else do you get to sit down at a table next to an prominent figure and have a casual conversation? I got to chat with Corey Haines while he was franticly trying to fix a mail sending vulnerability on one of his websites. I think that is pretty cool.

There is so much to be learned from these conversations. Both related to the topic at hand and otherwise. I’ve missed entire presentations before because I was caught up in a conversation about life in general with one of the keynote speakers from a conference I attended last year. That hour and a half made me a better person and a better developer and I wouldn’t trade it for anything.

It makes it really easy to engage with people when you all share some sort of common interest in the conference topics. While in Chicago, myself and a colleague met a couple guys who went to University with one of the guys who competed on Top Chef. They invited us to join them for dinner one evening at his restaurant The Frog & Snail. It was amazing, one of the best meals I have had in a long time and an experience I never would have had if we hadn’t talked to anyone. It is one of the more memorable experiences from my trip yet it really had little to do with the conference itself. You will meet interesting people and you will have a great time if you let yourself.

Go to a conference and meet some people.

Talk.

Learn.

Grow.

PowerShell Console “Select Mode”?!

It’s 2013 and one of my resolutions was to actually get off my ass and start blogging here and there about things I have learned, problems I’ve solved, or just whatever I feel like. So far I have been failing at this miserably, given that 2013 started over a month ago but I’m going to defer to the cliche “better late than never”.

So today I was doing some moving around of a bunch of files and whatnot on a remote computer and I thought to myself, “this is painful, I should script this”. So I did. I wrote a PowerShell script to loop through a bunch of folders, get their contents and move them to another directory for processing. Simple right? It should have been, but I suck at PowerShell so I have to look up every single command ands it’s parameters all the time. I just can’t seem to remember the crazy names they have for everything. That aside, after a few tries I managed to get what I wanted and all was well and good, on my development machine.

When I went to run my script on the remote computer, I found that it would randomly start hanging and not proceed to move to subsequent directories. I would check every once and a while to see the progress of the script (I printed out completed folders to the console), and often found that it would have stopped processing after the first couple items and I had wasted an hour or two doing nothing. Frustrating.

I tried changing the way my script worked, and at one point I thought I had fixed it, but then I checked a short while later and it stopped again. I was almost ready to give up when one of my coworkers stopped by and inquired as to what my problem was. I told him and he responded with “Oh you’re in select mode, the script pauses when you are in select mode”. Select mode? What the hell is select mode and how can you tell? “Oh the title bar says Select, just right click to get out of it”.

At this point, I was both relieved and furious. I had wasted a significant amount of time trying to debug my script when it was the stupid console window that was the problem. When I would click on the console window to focus it on the screen I would often accidentally select some empty space on the window which would put the console window into “Select Mode” which pauses script execution. Nothing was wrong with my script.

I have never run into this problem before because I hate the default windows powershell console, I use Console2, however, on the remote machine I had to use the default console application that comes with PowerShell.

No console application I have ever used before has this feature (that I am aware of) so it wasn’t even something that was on my radar for troubleshooting. To start with, it is very non-obvious that you are even in “Select Mode” when using the PowerShell command prompt (just a simple “Select” added to the title bar). Not only this, but you have to already know what “Select Mode” means, i.e., that it suspends the execution of the script. I feel like the console could indicate that it was paused in a more obvious manner, perhaps by saying “Execution Paused” or something equally informative, instead of “Selected”. I also think a change in color of the window or the title bar would be appropriate to indicate a state change.

SelectPowershell

Suffice to say, if it appears your PowerShell script is hanging while trying to run it using the standard PowerShell console, make sure you aren’t in “Select Mode”. If you are, right click your problems away.