Saturday, July 31st, 2010
LINQPad is an awesome aide to .NET Developers. Written by Joseph Albahari of LinqBridge and the C# In a Nutshell series fame. LINQPad allows the developer to write, compile and run C# or VB.NET Expressions, Statements of Programs outside of Visual Studio.
Everything I am going to show you in this post can be done with Visual Studio simply by wrapping the text in a new console application, and adding references to the DLLs. However I strongly encourage you to download LINQPad and give it a go.
In the event you are using 64-bit windows and are still using LINQPad 2 you will need to download the x86 version of LINQPad 2, as all of the EVEMon assemblies are compiled for x86. If you have LINQPad 4 you don’t need to worry about.
Assuming you have EVEMon installed, the first step is to load the EVEMon.Common.dll assembly into LINQPad:
- Go ahead and fire up LINQPad ensure you have a new query window open
- Press F4 (Query -> Query Properties).
- Click the “Browse…” button at the bottom of the properties window.
- Navigate to the EVEMon install directory.
- Select “EVEMon.Common.dll”
While you have “Query Properties” open go to the “Additional Namespace Import” tab and add the following two lines:
EVEMon.Common was designed to work as part of a long running process, namely the EVEMon application sitting in your system tray from when you turn your computer on until you turn it off, as such we need load the static data from the data files.
Now we get to do some LINQ,
var allItems = from item in StaticItems.AllItems
where item.Family == ItemFamily.Ship
CPU = item.Properties[DBConstants.CPUOutputPropertyID].Value.Value,
PG = item.Properties[DBConstants.PGOutputPropertyID].Value.Value,
I could start to explain the above line by line, but there are lots of really good LINQ articles on the Internet, including one by Joseph Albahari. We will just say that the above pulls all of the ships out of EVEMon’s Items data file and selects the Name, Race, CPU, PowerGrid and Description property for each one.
Now we see my favorite aspect of LINQPad, the .Dump() extension method, simply running the following command:
Will output the data we have just queried as a nice HTML Table:
That is all I have for you for now, I am working on a project that uses this data outside of EVEMon, keep an eye on Twitter where I will hopefully be providing a link for testing in the not too far distant future.
Tuesday, November 3rd, 2009
Code outlining is a feature of supported by Visual Studio and many other editors, MSDN has some good documentation for VS2005, VS2008 and VS2010. If I were asked to explain this as briefly as possible, I would probably say:
Code Outlining is the logical partitioning of code in such a way that the user interface, or editor, is able to selectively hide the body of the content (such as a class, struct, enum or method) whilst leaving the signature or some identifying comment visible.
You can see this in action in Visual Studio 2008 with the following Screenshot:
I accidentally turned off Code Outlining today by hitting some keyboard shortcut that I didn’t know how to reverse, this lead me to discover several useful keyboard shortcuts for managing the display of your code from the keyboard.
As it turns out I managed to hit Ctrl-M followed by Ctrl-P (or just P in fact) which maps to Edit.StopOutlining, by default it seems that the Visual C# 2005 mapping scheme doesn’t provide a shortcut to enable Automatic Outlining so instead you can access the command through Edit Menu -> Outlining -> Start Automatic Outlining.
Enabled again, I get to play with code outlining from the keyboard:
- To toggle (collapse an expanded block or expand a collapsed block) the closest outlined element use Ctrl-M followed by Ctrl-M.
- To toggle everything use Ctrl-M followed by Ctrl-L (I find little use for this)
- To collapse to definitions use Ctrl-M followed by Ctrl-O
The last one is the most useful when used in conjunction with Regions as after colapsing to definitions you will get something similar to this:
You might have noticed in the first screenshot that CodeRush Xpress adds a coloured line between the beginning and end of blocks of code, this is a nice feature if you have long blocks of code, which of course you shouldn’t have.
There we go, an errant key stroke can lead to learning and blogging, who would have thought it?
Thursday, October 22nd, 2009
Windows 7 turned up in the post today. The red box is Visual Studio 2008 which is there to show that the boxes have a similar profile to the old style hard cases.
I have been running the Beta since it was first available to the general public, and I have had Windows 7 Business at work for a couple of weeks now. Bought Windows 7 Home Premium for about £45 from Tesco. One copy for the main PC which I will probably re-build at Christmas and one copy for the laptop which is re-built now. Scott Hanselman described Vista as an operating system that stabs you in the eye a thousand different ways, I would have to agree with that. Windows 7 is different, things work how you think they should and don’t seem to randomly break when you least expect it.
As for the title of this blog post, I have mostly been installing Windows 7 to Vampire Weekend which Kev introduced me to. The track M79 seems to have taken some inspiration from the Sailor’s Hornpipe better known as the Blue Peter theme tune, seems to cut off just at the moment I am expecting it to carry on into the main part of the music. Maybe there is a Mike Oldfield link in addition to the lyrical Peter Gabriel link.
If I am moved to over the course of the next couple of week I shall try and point out some of the new features available in Windows 7 that are cool. For the time being try the following hold down Alt, while still holding down Alt press “Alt Gr” (The other side of the space bar) then press Tab. For some reason you get the old XP style Alt-Tab window. Utterly pointless?
Friday, October 16th, 2009
I found this function totally accidentally when I knocked my mouse into a key when something interesting popped up on Twitter. I happened to have a variable selected like so:
The key that I knocked was the Number Pad “+” key, and it expanded the selection like this:
As any self respecting Systems Administrator would do I wondered if doing exactly the same thing repeatedly would have equal or compound effects.
Strangely enough it worked, the selection will continue to expand selecting increasingly larger sections of code. The reverse works as well if you press the Number Pad “-” key the selection will be reduced.
As I was looking for documentation on this function; I found that you could use the CamelCase select function to start selections off using Ctrl+Shift+Left (or Ctrl+Shift+Right) this will take your selection from the current cursor position to the next upper case character to the left (or right). This can be coupled with the Number Pad “+” to expand your selection from a variable to an expression, to a line then a block. Neat!
Each of these discoveries was announced with a handy little popup in the bottom right hand corner of the viewport telling me what happened, and if relevant what function was suppressed.
I am going to make a concerted effort to spend my lunch break watching some more videos on DevExpress’ training site. I got 10 minutes today and watched what appeared to be footage from a launch event or a conference which was interesting but didn’t really teach me anything specifically.
Monday, October 12th, 2009
As I mentioned in my previous entry I have started using DevExpress’s CodeRush Xpress. It is a free cut down version of CodeRush that I heard about in an episode of .NET Rocks. I have wanted add something to my Visual Studio development experience and I can’t justify the cost of either Resharper or CodeRush at the moment. There has been quite a bit of discussion about Resharper vs. CodeRush and in my experience most people I have spoken to love one and hate the other.
I hope to be able to write a series of posts about some of the features found in CodeRush Xpress which I hope will clarify their purpose and use in my mind and maybe help someone find the function they are looking for.
First off “Quick File Navigation”, this is a search function for locating a file by file name, I am finding it increasingly useful when looking through patches as it allows me to very quickly jump to a file name. Particularly as I am trying to move my projects to a one class per file so if I can remember the class name I can find the code file very quickly.
The “Quick File Navigation” dialog is accessible through the keyboard short cut Ctrl+Alt+F. Typing will filter the list box by the name of the file matching anywhere in the filename including the extension.
An additional feature for those who like me use CamelCase in their file names; if you enter your filter terms in capital letters it will search for capitalized words, in order within file names. Thus entering “AW” into the search box will also bring up the AboutWindow.cs in the above solution.
Combining the above with the Ctrl-G keyboard shortcut in Visual Studio 2008 to go to a specific line we can do the following to go to line 162 in ShipLoadoutSelectWindow.cs:
Ctrl+Alt+F → S,L,S,W → Ctrl+G → 1,6,2
DevExpress have a great training video on their tv.devexpress.com sub site.
Saturday, April 18th, 2009
I have been working on EVEMon for about two months now, taking on the responsibility of committing changes to the trunk, fixing bugs and adding new features. As a project I have been involved for several years submitting bug fixes and little features, it was down to my experiences with EVEMon that I decided to implement Subversion and Trac at work.
Unfortunately the first time it came to me to be responsible for a release, it seemed to go terribly wrong. The updated installer worked fine, and it seemed initially there were no problems with the updated code base. However BattleClinic shortly went a little mad with bug reports similar to this one:
EVEMon Version: 22.214.171.1243
.NET Runtime Version: 2.0.50727.1434
Operating System: Microsoft Windows NT 6.0.6001 Service Pack 1
Executable Path: “C:\Program Files\EVEMon\EVEMon.exe”
System.IO.FileLoadException: Could not load file or assembly ‘lgLCDNETWrapper, Version=126.96.36.199, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log for more detail. (Exception from HRESULT: 0x800736B1)
File name: ‘lgLCDNETWrapper, Version=188.8.131.52, Culture=neutral, PublicKeyToken=null’ —> System.Runtime.InteropServices.COMException (0x800736B1): The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log for more detail. (Exception from HRESULT: 0x800736B1)
at EVEMon.LogitechG15.Lcdisplay.Dispose(Boolean bDisposing)
at EVEMon.LogitechG15.Lcdisplay.Finalize() in D:\EVEMon\EveMon.LogitechG15\Lcdisplay.cs:line 70
For those who are not familiar the above is the crash report generated by EVEMon when a .NET exception is unhandled. lgLCDNETWrapper is the C++ library EVEMon uses to communicate with the Logitech G15. A similar error was generated for EVEMons other C++ component the window relocator.
Tonto Auri quickly spotted that the problem was something to do with the re-compiled C++ DLLs and switching the new DLLs with those from an older package resolved the problems. Whilst this was a fix, I wasn’t willing to just revert the changes and give up on the changes we had made to the G15 library, additionally I was concerned that we had not made changes to the window relocation code and that was causing at least one person a problem.
Quite a bit of searching about with Google and Stack Overflow resulting in finding these two little gems of information:
These two posts basically gave me the tools and the knowledge to fix EVEMon’s problems.
First I made the sudden (and “facepalm”) realization that EVEMon deployed the Visual Studio 2005 Redistributable; we had moved to Visual Studio 2008 SP1 about a month before the release of 1.2.7. I confirmed this with the Dependency Walker utility, by walking lgLCDNETWrapper.dll I was able to confirm that version 9.0.21022.8 of the Microsoft CRT Library (Microsoft.VC90.CRT) would be required.
The next trick was figuring out which re-distributables to deploy with EVEMon to ensure the end user would have all the dependencies required to use all of the features; frustratingly it seems that Microsoft only bundles the latest version of the re-distributables with Visual Studio 2008 and that was version 9.0.30729.1 which was not going to cut it.
Enter Nuonsofts excellent article providing a step by step guide on adding the required compiler flags to ensure the latest version of the CRT was bound. I did find a nice GUI resource editor that was capable of getting the manifests out in XN Resource Editor which made the process a little faster.
A little bit of hacking later the updated Visual Studio 2008 SP1 CRT DLLs and manifest file were deployed to the Microsoft.VC90.CRT folder within the EVEMon program files directory as the VC80 CRT libraries were in the past and the two C++ projects were setup to bind to the latest version with the _BIND_TO_CURRENT_CRT_VERSION=1 preprocessor definition.
A bit more poking arround with XN Resource Editor and Dependency Walker showed we were now in a far better position to have a working copy of EVEMon in the hands of our end users.
Thursday, February 5th, 2009
Having done a little experimenting with Visual Studio Extensions for WSS (VSeWSS), I wanted to start actually developing features for our intranet site. I try and add everything that is even slightly important into source control (Subversion). VSeWSS creates normal looking solutions, however when you deploy your project to a SharePoint site it created an additional directory alongside “bin” and “obj” called “pkg”.
This “pkg” folder contains the manifest.xml, soloution.xml and feature.xml files that are used to create the feature to be deployed into SharePoint. Initially I was including this folder in my commits however, I noticed that any tweaks made to feature.xml were overwritten when you deployed the package again. After some searching around I came across an article that suggests deleting the “pkg” folder under certain circumstances. From this I assume that the contents of the “pkg” folder is generated each and every time you package and deploy your solution (or indeed project), thus it does not need to be added to source control.
While writing this post I did come across another blog that suggests adding the “pkg” folder to source control. There does appear to be little advice out there regarding VSeWSS and Source Control. I would be interested to hear others experiences on the subject.
Monday, July 21st, 2008
I have had an issue today with Visual Studio 2005 and Vista today, specificly I have been unable to use the built in mini-web server that is used for debugging web projects. When you run a project from within the development environment it starts WebDev.WebServer.exe and then points an instance of Internet Explorer at http://localhost:port/path/to/default.aspx.
Now I remember this working well in the past, and indeed if I replace localhost with 127.0.0.1 it worked fine, I didn’t fancy having to type this every time I went to build and run a program. I could not find any way of configuring Visual Studio to point to the IP address rather than the host name.
Upon trying to ping localhost (fairly futile I understand but I was getting desperate) I noticed that packets were being returned over IPv6 (::1:) rather than IPv4 (127.0.0.1), my first port of call was to disable IPv6 on the NIC – which unsurprisingly didn’t work as anything to do with localhost shouldn’t use the NIC, and unlike Linux; Windows does not appear to expose the loopback adapter to the end user.
The soloution as it turns out was to remove the IPv6 record for localhost from %WINDIR%\etc\drivers\hosts. Editing this file requires an instance of notepad.exe to be running as a local administrator (i.e. press the windows key, type “cmd”, right click cmd.exe in the list and choose “Run as Administrator”. I realised had this before, in the time between then and now all trace of the problem occuring was wiped from my memory leaving only the soloution in my head. Never mind all working now!