Viewing Large Textfiles

by Administrator 25. September 2011 09:31

That's something you run into rarely and get annoyed all the time since most editors (even light weight ones like Notepad++) kick the bucket when opening files >100mb. In my case I did a little application for the game Rift and had to parse through a 400MB database file for that matter.

I was not able to open the file until cutting it down to 100mb or so. I started with Hiew which is an odd console application which can show text files but is actually more focused on binary analysis, mostly for reverse engineering. The worst thing here is that it does not integrate well enough with windows to allow copy & paste.

I next gave Large Text File Viewer a shot. The app unfortunately does not get updated anymore and supports no UTF-8 (which would have been nice for me). However apart from that it does a good job.

Great stuff.




by Administrator 25. September 2011 03:30

The video was posted on Kraftfuttermischwerk. I found the sounds actually less fascinating, but the images are really nice.


Fun Stuff

Poking around in the Team Foundation Server 2010 API

by Administrator 23. September 2011 10:01

TFS is more than just a version control system. It unites version control with item tracking, testing and other goodies. I poked around in the API to aggregrate some data for our review system.

The situation is this: We little small development cycles that deal with one particular aspect of our application. Since our team is quite small we run into issues around who needs to review what afterwards. In our last cycle we ended up with a database query that showed files changed since the start of our cycle and had to manually assign review with an Excel sheet. This was really a big waste of time, the sheet did not only list changed files but also deleted ones, the old version of renamed ones... Furthermore it's really hard to memorize why you changed a file without having a deeper look or lots of commenting.

What I wanted to achieve is a report that shows changes associated with a specific work item (and it's sub items) or an iteration. These should be grouped users who checked in the change. So in the best case it is possible to give the list of user a to user b to review (and vice versa).

To consume the API I added three references to my application:

TFS Api References

All these assemblies are located in the Visual Studio\Common7\IDE\ReferenceAssemblies\v2.0 folder.

The first thing to do is hooking up with the collection you are querying. A collection is a container for projects that acts as a security boundry.The collection is specified by the url passed into the following call. When omitting it, the default collection is assumed (like it is in this case).

TfsTeamProjectCollection collection = new TfsTeamProjectCollection( new Uri( "http://hrsdusdevsql:8080/tfs" ), new UICredentialsProvider() );

The credentials are handled via integrated security. So if you want to run some kind of automated task you can use the runas command to get authentication working.

To query work item related data, you first obtain a reference to the work item store:

WorkItemStore store = collection.GetService<WorkItemStore>();

The store allows different kind of queries. Here is an example of a SQL query that obtains the work items in a given iteration path:

IEnumerable<WorkItem> GetIterationPathItems (WorkItemStore workItemStore,string iterationPath)
   WorkItemCollection wiCollection = workItemStore.Query( "SELECT * FROM WorkItems WHERE [System.IterationPath] = '" + iterationPath + "'" ); 
   foreach (WorkItem workItem in wiCollection)
      yield return workItem;

As you can imagine you can get quite fancy with SQL queries. This is probably what is used when building team/single user queries in Visual Studio.

The following is an example of how to retrieve a work item with it's child items:

IEnumerable<WorkItem> GetChildWorkItems (WorkItemStore workItemStore, WorkItem parentWorkItem)
   yield return parentWorkItem;

   foreach (WorkItemLink childLink in parentWorkItem.WorkItemLinks)
      if( childLink.LinkTypeEnd.Name == "Child" )
         WorkItem childItem = workItemStore.GetWorkItem( childLink.TargetId );
         foreach( WorkItem subItem in GetChildWorkItems( workItemStore, childItem ) )
            yield return subItem;
         yield return childItem;

Once the work items are identified it's time to find changelists associated with them. The following code builds a list of unique changesets associated with a list of work items:

IList<Changeset> changeSets = new List<Changeset>();
foreach( WorkItem workItem in workItems )
  foreach( ExternalLink externalLink in workItem.Links.OfType<ExternalLink>() )
     if( externalLink.LinkedArtifactUri.StartsWith( "vstfs:///VersionControl/Changeset/" ) )
        int changeSetId = int.Parse (externalLink.LinkedArtifactUri.Substring( externalLink.LinkedArtifactUri.LastIndexOf( "/" ) + 1 ));
        if( !changeSets.Any( changeSet => changeSet.ChangesetId == changeSetId ) )
           changeSets.Add( versionControl.GetChangeset( changeSetId ) );

In a final step I iterate over the files that are part of the identified changesets.

Dictionary<string, IList<string>> changes = new Dictionary<string, IList<string>>();
foreach( Changeset changeSet in changeSets )
  if( !changes.ContainsKey( changeSet.Committer ) )
     changes.Add( changeSet.Committer, new List<string>() );

  foreach( Change change in changeSet.Changes )
     if( !changes[ changeSet.Committer ].Contains( change.Item.ServerItem ) )
        changes[ changeSet.Committer ].Add( change.Item.ServerItem );

The dictionary will contain the files grouped by the committers. This is mostly what I wanted. What this code does not handle yet is rename / delete operations and some smarter filtering of files. Perhaps solution files/folders should be excluded.

I just wanted to paste some code to get you started with the TFS API in case you need to. I must say it's really easy to do your first steps here. I did my baby steps with the raw database and found this to be a real junkyeard. The API is much cleaner and easier to understand.



Taking SQL Server Database Offline Hangs

by Administrator 22. September 2011 02:50

... happened to me yesterday and was really annoying. I wanted to take a TFS database offline and then bring it back on to get rid of rogue locks and found out that taking it offline took more than 10 minutes without success. The database was still shown as being online, but I was not able to connect to it.

Showed the following error:

Msg 952, Level 16, State 1, Line 1
Database 'xxx' is in transition. Try the statement later.

After some googling I found this post on MSDN.

Taking a database offline has one nuisance pretty much to what happens when you restore a backup. Open connections/running commands prevent the thing from happening. While in the newer version of SQL Management Studio you can drop existing connections when restoring a backup, there is no frontend support for doing such a thing when taking databases offline. This is extremely annyoing, because sometimes the reason why you do take a db offline is an urgency anyway.

To get everything working again, I followed the script at the bottom of the post:

lets you find the processes that execute actions on the database you want to drop. Then you can use the KILL command to kill the processes preventing you from taking your database offline. Right after killing the process, perform your action again:

Please note that this is not a clear way to do it. You will rollback transactions and might lose data depending on who was connected to your db with what application.

Tags: ,


Comments enabled again

by Administrator 20. September 2011 18:06

Ok, I decided to give comments another chance. I tried moderated comments twice and found out that there is more spam than I am willing to filter through each day. I'm trying it with the Commentor addon now - let's see if it does the job.

I will check tomorrow, if there's any spam. If I see big amounts of spam passing the filter I will turn off comments again :-/

Tags: ,


HTML5 Boilerplate

by Administrator 20. September 2011 09:36

The latest episode of the Changelog Podcast with guest Paul Irish mentioned some really interesting web development related projects. One I have not heard about before was the HTML 5 Boilerplate which is a collection of snippets, tools and files to use as a starting point when creating HTML 5 projects. Especially the normalize.css included appears very useful since it mitigates browser incompatibilities coming from deviating default css styles.

Tags: , , ,


Automatically creating a PDF from a Word Document

by Administrator 20. September 2011 08:55

I needed this for a little tool tha embeds word documents in our WIKI. We use ScrewTurn Wiki as our development WIKI and wanted to have a solution to publish some user stories to it. I found the extension FileContentFormatter that allows you to embed PDFs directly into articles - so the only missing piece was to convert the document to a PDF. Luckily there is a WSH script called Doc2Pdf that does the job via automation. I did not even have to install the mentioned convertet, probably because it's part of my office installation.

ScrewTurn's database design is really simple (probably because the wiki can also run on the plain file system. Adding attachments or whole pages is just a matter of 3-4 insert statements.

Tags: , ,


A Universal Call for Liberty

by Administrator 18. September 2011 04:19

I heard the sound from the video in the current Compod episode and felt the urge to see the whole thing. This is completely outstanding. I remember having seen the movie The Great Dictator as a child, what I did not remember was that there were such deep moments in it. Perhaps I'll watch it next time it's on TV.

Perhaps some one knows, where the music comes from. Please drop me a mail if you know.

Tags: ,

Fun Stuff

Accessing Private Parts of an Object in C#

by Administrator 13. September 2011 02:50

You'll find some posts on the .NET where heated discussions happen about whether you need such a functionality. The only reason I see where it makes sense is unit testing or when you've got some sort of third party library it no way to have an essential change the let's you get to the data we need. Unit tests however are the most common scenario. Though one could argue that you should design your classes in a way that unit tests should be easy via public properties/methods however in reality you come across problems where the complexity of dispersed objects graphs who's only reason of existence is to allow granular unit tests just waste precious time.

There are some good ways to deal with such problems:

  • One good way is to inherit from the object you are testing and install public accessors for protected methods/properties or add logging / mocking capabilities by overriding. This can either be done manually or with the help of a good mocking framework (e.g. RhinoMocks). RhinoMocks offers a feature called Partial Mocking that allows to shadow existing members of a class with new functionality. 
  • Another ways is to mark your properties / methods as protected internal (which can be combined with virtual). In this approach, the assembly that the class resides in and other assemblies that have been defined via the InternalsVisibleTo attribute can access such class members as if they were public. The drawback here is, that you somehow distort the principle of object orientation by exposing implementation details.
  • If the above two are no option for you, you may check out the ExposedObject project on codeplex. The idea behind the class is to wrap the class you want to peek inside into a wrapper object that gets to the internal stuff via reflection. The implementation is based on C# 4.0 dynamic features and really interesting.

Tags: , ,


Injecting Code into Silverlight Applications Part II

by Administrator 10. September 2011 17:50

Andrei Kashcha pointed me to his blog where he used another approach to get a step into silverlight applications. This one is debugger based (my suggestion was to repackage the xap with some .NET love :P) and reveals some interesting insights. Check out this post for more information.

The blog appears to be new - I hope there's more posts of such quality coming.




About the author

for comments and suggestions contact:


Month List