Rob Kraft's Software Development Blog

Software Development Insights

Archive for April, 2011

Dramatically improve build times with new hardware

Posted by robkraft on April 30, 2011

Ok, so I gave away the punch line in the article title, but I wanted to share my joy at the big difference we experienced in build times when we got a new build server.  Our old build server was running 4 VMs, and one of those VMs contained our build process which we tried to run 3 times per day, along with unit tests and other build jobs.  The average compile time for our C# code was 50 minutes.  This was tolerable when
everything going well and we are not approaching a release deadline.  But we are now approaching a release deadline and we are in the midst of renaming a lot of projects and DLLs which is causing an unusually large number of build failures.  I was spending more than half of my day each day running builds.  We finally bought a new computer, not really a server, just a power tower PC and moved our main build VM to that
machine.  The build times went from 50 minutes down to 16 minutes on average.   This allows us to find problems more quickly, get the bugs fixed more quickly, and we are already even responding to bugs found in QA more quickly.  If we had known the build times would have improved so dramatically we would have done this 6 months ago.

We still haven’t even defragged the hard drive in the VM, or increased its disk space. We hope to do both next week and I expect a small gain, but nothing like we experienced with the new hardware.  So don’t go cheap on the hardware!  Saving time is saving money!

Advertisements

Posted in Dev Environment | 1 Comment »

How to tell Visual Studio 2010 to open files in the correct window when you double-click

Posted by robkraft on April 28, 2011

I tend to tolerate minor annoyances in order to focus on more important tasks I want to accomplish. Recently though I finally got tired of my documents opening in the wrong window in Visual Studio when I double-clicked on them. Generally this occurs when I do a find across all files, and the find results pane is docked in a shorter window at the bottom of Visual Studio 2010. When I double-click on one of the lines in the Find Results pane, it opens the intended document in the same lower window, not the larger window on top where I generally view the source code I am interested in. It took me a little while to resolve this and to tell Visual Studio to open the windows in the top pane instead of the bottom pane. The fix is simply to select ‘Reset Window Layout’ from the Windows menu in Visual Studio 2010. I guess that menu option could also be called “Make Visual Studio open documents correctly again.”. I don’t know why my window layout began misbehaving in the first place.

Posted in Visual Studio 2010 | 17 Comments »

How to edit your application icons for the application list and tile for Windows Phone 7

Posted by robkraft on April 26, 2011

I hoped to find a totally freeware version of an icon I could use for my Windows Phone 7
application somewhere on the Internet.  I am not a graphics guy and I don’t expect my application to make enough money to justify hiring an artist.  I did find a PNG file that was good enough, but it only came in one size (48X48), not the 62×62 and 173×173 dimensions I needed for the phone.  I decided to try to resize the PNG but it did not resize well by default.  I decided to try again using Paint.Net.  I chose the “Nearest Neighbor” resampling option in the Resize dialog and fortunately this gave me a nicer looking large PNG than the default resampling
options had.

Posted in Windows Phone 7 | Leave a Comment »

How to make your own application icons for Windows Phone 7

Posted by robkraft on April 25, 2011

I searched around the Internet for 48×48 PNG images that I could use for Application Bar Icons on my Windows Phone 7.  I was hoping to find an icon that represented “menu”, but I did not.  Finally, I decided to try to edit something I felt was close and I am glad I did because it was very easy to do.  I obtained a free icon editor called IcoFX from download.com (I almost always download from download.com because they have already ran virus checks against the files they host).  I then opened an existing image and began making the minor edits I desired for my new image.  I made sure that the image was a “True Color”, or “32bit” image.   I saved it as an .ico, then used the Export Image option from the File menu of IcoFX to export it to a .PNG.

Posted in Windows Phone 7 | Leave a Comment »

How to capture screen shots for Windows Phone 7

Posted by robkraft on April 24, 2011

To publish an application to the Windows Phone 7 store you must provide at least one screen capture of your application. I believe the best method to do this is to run your application in the emulator and use the “snipping tool” in Windows 7.

  • Set the zoom size of the emulator to 100%.
  • If the full screen does not fit on your monitor, rotate the emulator 90 degrees to take the screen shot.
  • If your application supports both portrait and landscape orientation, but you want a portrait image, change your code to only support portrait mode long enough to take a screen capture.
  • Use the “Window snip” from the snipping tool and save the image as PNG.
  • Use Paint.Net to rotate the image back to vertical if you had to rotate it for your screen capture.

Posted in Windows Phone 7 | Leave a Comment »

MVVM Rocks! It helped me past a PivotControl bug.

Posted by robkraft on April 24, 2011

MVVM rocks! I thought I would be spending many hours to convert my PivotControl UI to a simple Page UI after I discovered that some PivotControl features don’t work. But the switch took me less than an hour to create 4 new pages and get them all functional. Changing the UI was simple because all of my logic was in my viewmodel. When I bound new forms to my ViewModel to replace the previous PivotControl form, everything just worked. Score a victory for MVVM!
The PivotControl feature that does not work that I needed was the ability to set the Index of the PivotControl and allow the ViewModel to cause navigation to the specified Index. Unfortunately, as of April 2011 in Visual Studio 2010 with Phone 7 it does not matter what value you provide to the SelectedIndex or SelectedItem in the PivotControl, you can only cause the PivotControl to display starting with index zero. I expect this bug will be fixed in the next release of the PivotControl.

Posted in Windows Phone 7 | Leave a Comment »

Use string.Format instead of string concatenation

Posted by robkraft on April 15, 2011

I recently learned a good reason for writing my C# code like this:

return string.Format("{0} was deposited in your account.", amount);

instead of

return amount + " was deposited in your account.";

Both return the same result when the string is in English, but if you want your code to support other languages, then you need to be aware that the sentence structure of another language may not match English and that using string.Format gives the language translator more control over the format of the entire message. The English sentence, “The man went to the store”, may sound like, “To the store went the man” for speakers of languages that put the subject of the sentence at the end. Many bilingual speakers find these differences to be a major challenge to speaking new languages fluently. To myself, the message “$100 was deposited in your account.” sounds like good English, but in another language that may sound like “Was deposited amount of $100 to your account.”.

When you write your code using concantenation, you are forcing the translator to place part of the sentence where you would place it in your native language. But, if you use string.Format, and convert your string to a resource to support localization, the translator can fully control the translation.

return string.Format(AppResources.DepositSuccessful, amount);
en-US = AppResources.DepositSuccessful = "{0} was deposited in your account."
es-SP = AppResources.DepositSuccessful = "Fue depositado {0} en su cuenta."

Disclaimer – I am not fluent in Spanish so my translation might sound terrible to Spanish speakers. My apologies.

Posted in Code Design | Leave a Comment »

How to programmatically switch to a new pivot item in Windows Phone 7

Posted by robkraft on April 3, 2011

I hope the title of my article does not mislead you, but I just learned today that you cannot programmatically change which pivot item is displayed in the pivot control from your C# code. Apparently this is a known bug:
http://stackoverflow.com/questions/4541020/pivotcontrol-item-changing-behavior-in-silverlight-windows-phone-7.

Unfortunately for me this is a fairly devasting problem because my whole user interface (UI) is based on the Pivot Control and I needed my search function in the application to send me to a specific PivotItem. But code like this does not work:

PivotControl.SelectedIndex = 3;

I spent an hour or two before I started writing my application trying to decide if a Pivot Control or non Pivot based UI would work best. Had I known that the pivotcontrol was not working as expected, I certainly would have not used it. Fortunately I have also been writing unit tests and using MVVM on this project which is going to make putting an entirely different UI on the application relatively simple. I estimate 2 to 8 hours. Of course since I only work on this on the evenings and weekends the calendar time is going to cost me a week.

I am using the latest Microsoft Phone Developer SDK (release in February 2011). Hopefully the next SDK will fix this bug.

Posted in Code Design, Silverlight, Visual Studio 2010 | 3 Comments »

How to prevent foreign language subfolders in Silverlight projects

Posted by robkraft on April 2, 2011

I like to keep my folders and libraries clean, and one thing I find annoying is the generation of subfolders and DLLs for to support foreign languages when I have no interest in providing that support in my application.  Specifically, when I am developing Silverlight applications I notice many subfolders like ar, bg, zh-hans, sr-cryl-cs, and es.  If you want to keep your compile from generating those subfolders, you can do this by deleting all the foreign language subfolders that were created by the installation of Silverlight.
This can be tedious, especially if you want to delete them on several machines.  So I created this simple batch file to do it for me.  You may need to change the silverlight folder, and there will probably be additional langauges added, but this may provide you a starter batch file.

c:
cd\
cd "program files\microsoft silverlight\4.0.60129.0\"
rd ar /S /Q
rd bg /S /Q
rd ca /S /Q
rd cs /S /Q
rd da /S /Q
rd de /S /Q
rd el /S /Q
rd es /S /Q
rd et /S /Q
rd eu /S /Q
rd fi /S /Q
rd fr /S /Q
rd he /S /Q
rd hr /S /Q
rd hu /S /Q
rd id /S /Q
rd it /S /Q
rd ja /S /Q
rd ko /S /Q
rd lt /S /Q
rd lv /S /Q
rd ms /S /Q
rd nl /S /Q
rd ru /S /Q
rd zh-hans /S /Q
rd zh-hant /S /Q
rd no /S /Q
rd pl /S /Q
rd pt /S /Q
rd pt-br /S /Q
rd ro /S /Q
rd sk /S /Q
rd sl /S /Q
rd sr-cyrl-cs /S /Q
rd sr-latn-cs /S /Q
rd sv /S /Q
rd th /S /Q
rd tr /S /Q
rd uk /S /Q
rd vi /S /Q

cd\
cd "Program Files\Microsoft SDKs\Silverlight\v4.0\Libraries\Client\"
rd ar /S /Q
rd bg /S /Q
rd ca /S /Q
rd cs /S /Q
rd da /S /Q
rd de /S /Q
rd el /S /Q
rd es /S /Q
rd et /S /Q
rd eu /S /Q
rd fi /S /Q
rd fr /S /Q
rd he /S /Q
rd hr /S /Q
rd hu /S /Q
rd id /S /Q
rd it /S /Q
rd ja /S /Q
rd ko /S /Q
rd lt /S /Q
rd lv /S /Q
rd ms /S /Q
rd nl /S /Q
rd ru /S /Q
rd zh-hans /S /Q
rd zh-hant /S /Q
rd no /S /Q
rd pl /S /Q
rd pt /S /Q
rd pt-br /S /Q
rd ro /S /Q
rd sk /S /Q
rd sl /S /Q
rd sr-cyrl-cs /S /Q
rd sr-latn-cs /S /Q
rd sv /S /Q
rd th /S /Q
rd tr /S /Q
rd uk /S /Q
rd vi /S /Q

Posted in Dev Environment, Silverlight | Leave a Comment »