Tuesday, November 20, 2012

#resharper and NUGET

#Resharper one of my favorite tools for software development.  Over the years it has saved me so much time in development.

They have a new plugin out that integrates with nuget.  It can be downloaded from https://github.com/JetBrains/resharper-nuget/downloads

Here is the release information

http://blogs.jetbrains.com/dotnet/2012/11/add-packages-not-references-a-nuget-plugin-for-resharper/

Monday, November 19, 2012

Code Reviews

Listening to .NET Rocks and they quoted a survey that code review finds 80 more faults found per hour than any form of testing.  I knew there was a reason that I like code reviews so much.

Friday, September 28, 2012

Google hangouts

I have always found video chat and desktop sharing kinda clunky in the past.  But I just used Google hangouts for the first time today.  Oh my, this is the best video chant sharing tool I have ever used. 

If you have any need to talk to someone over video and share your computer screen use this.

Thursday, September 27, 2012

Snoop

Found this indispensable tool for doing wpf development called snoop.   I don't know how I lived without it. Its like having the developer tools in chrome, ie or firefox only for WPF.   I must thank team snoop for developing this.

I have two tips for using snoop.
1. If you are running visual studio in admin mode, make sure you run snoop in admin mode also otherwise it will not work.
2. If you have WPF applications with more than one window it can be a bit confusing to figure out how to inspect any window other than the main window.
To inspect non main windows
a. drag your target cursor from snoop over to the window
b. press ctrl+shift and you you are inspecting the non-main window.  Control shift also works great for selected an element you want to inspect on the screen.

I hope you find this tool as useful as I did.


Tuesday, September 18, 2012

Pandora Windows Client

While I am coding late in the night I like to listen to pandora. But I get tired of logging into pandora every time. I thought would it be nice to have a windows client for pandora instead of using my browser. So I went in search of a windows client for pandora and found this great little app. So far it is working great. Try it out.

http://www.adamhaile.net/projects/elpis/

Friday, September 14, 2012

Linked In Password theft

The recent Linked In password theft inspired me to write this post about password management.

Passwords are everywhere. We have them at the office, and at home. There are so many that no one person can remember all of them. Most people probably have credentials for web sites they don't remember using.
One way to keep track of logins and passwords easily is to use the same one on multiple sites. That makes it easier to remember one password. However if anyone ever exposes that one password, now they can go to other common web sites and try that password. So that means you are trusting some guy running a web site from his garage with the password to your bank account. They have your email and your common password. They could go to many different common web sites and access your private information. You never really know how secure people are being with your passwords. In reality companies should really not keep your real password but a hash of your password so only you really know what your password is. But who really knows what they are doing with them.
To keep things simple and keep things secure I use a free opensource program keepass. Keepass This application is small. You can even run it from a thumb drive. It will generate passwords that are different for each web site and keep them encrypted and secured. I use this in conjunction with dropbox and I am able to access my passwords on any machine. I turn off all password remembering on my browsers, that way I know only keepass has my passwords and they are safely encrypted.

So get secure and get keepass.

Wednesday, August 1, 2012

MVVM Light Messaging Property Change Message Null Reference Exception

On a current project I am using MVVM light framework within WPF.  I love the framework and it has worked great.
But, in software development there is no silver bullet.  So here is a issue I ran across when using the property change message.

Null Reference exception on the receiver.

In my publisher view model I had the following property
  public String MyProperty  
     {  
       get { return _myProperty; }  
       set  
       {  
         if (value == _myProperty) return;  
         var oldValue = _myProperty;  
         _myProperty= value;  
         RaisePropertyChanged("MyProperty", oldValue, value, true);  
       }  
     }  
     private _myProperty;  

In the reciever view Model I Registered and handled the message
 Messenger.Default.Register<PropertyChangedMessage<MyObject>>(this,HandlePropertyChanged);  
  private void HandlePropertyChanged(PropertyChangedMessage<MyObject> propertyChangedMessage)  
     {  
       if (propertyChangedMessage.PropertyName != "MyProperty") return;  
       if( propertyChangedMessage.NewValue != null)        
         JobNumber = propertyChangedMessage.NewValue;        
     }  

In the app.xaml.cs I added
DispatcherHelper.Initialize();

No more null reference exception.

Monday, July 30, 2012

Struct vs Class in C#

A while ago we had some discussions on our team on a struct vs class.  Here is a list of the differences

Struct VS Class

  • Structs and Classes both inherit from System.Object 
  • Structs cannot inherit from other classes. I would guess this is why there not used as often 
  • Structs live in the stack and classes lives in the heap 
  • Structs are value type and classes are reference type 
  • Structs do not require garbage collection, they go away when the method comes off the top of the stack 
  • Structs live in the stack window of the method they are declared 
  • Structs go to the heap if they are declared as member variables 
  • Structs don’t have pointers so they save memory Class have pointers so the memory address to the class in the heap takes up memory 
  • You don’t have to use the new keyword with a struct, but if you don’t the structs members will be null and not initialized 
  • Classes smaller than 16k can be more efficient as structs 
  • Structs can implement interfaces 
  • Structs constructors must have parameters public foo(string pParam1) ok but no foo() 
  • You can control the layout of the struct in memory on the stack using the StructlayoutAttribute attribute on a struct
 References
C Sharp Corner
MSDN Heap and Stack
Struct Tutorial
Struct Attribute

Friday, June 1, 2012

Using Orca to set REINSTALLMODE in your MSI to all files

My daily duties typically revolve around building in new features and developing new products in .Net. Eventually though you have to get around to that dirty job of getting what you have built out to your users.

It works on my PC sounds nice, but most clients are looking for a little more than software running on a developers PC.

So once you have built you new piece of software, you gotta get it out to the masses. One of the many ways to do this is using a MSI installer file. Being a lazy developer I am always looking for ways to spend more time building new things, and less time dealing with things like software distribution to users. For small and simple applications there is nothing simpler than a setup project in visual studio. There are other more powerful tools like Wix, but for me they have just been to complex. I am a developer and don't want to spend days figuring out the ins and outs of wix or some other installation tool. Using visual studio I can add a new project, assign the output from your primary application and you are done. The project figures out everything to be included. Configuration files, dll's, content files etc etc. This can be done in just a few minutes.

The simplicity of the Setup projects are one of the problems with them though. On a recent project I could not get my files to update. I would build a version and distribute my MSI. Some of the dll's and the configuration file would not update, even thought the install would complete. After some research I found a property called REINSTALLMODE in the MSI. This by default uses a checksum to determine if a file should update or not. Well for many reasons this did not work for me. So I decided I want to just update all files every time. This way I can ensure my users have the most up to date files. You can set this by running your msi on the command line but that is kinda clunky. I want users to be able to double click on the msi, install it and be on there merry way. No special batch files and command line arguments.

Instead of setting this property in the MSI I am going to show you how to set the Property using ORCA and editing the MSI directly.

The steps are listed below.
1. Build your MSI 2. Open your MSI in Orca. You can get orca from microsoft here You can just drag it right in from your file system.
3. Navigate to the Property table, its in the first column on the left
4. Right Click and select add row 5. Add REINSTALLMODE for name and amus for value
Now your MSI will overwrite all files, instead of by default using the checksum. Because in my experience the checksum just does not work.

Sunday, April 1, 2012

JD Edwards Dates in SQL Server

Recently I worked on a project where we had integration with JD Edwards.  In this project I got introduced to JD Edwards dates and times.  They are not stored as normal dates in .Net or SQL server.  But are numeric fields.

I needed to do a date comparison against a SQL Server date and a JDE date time.  To do this I created a user defined function.  This function converted the date and time fields in JDE to a SQL date I could use for comparison.

Below is the format of date and time fields in JDE.

Date Fields
The date fields are stored as six digit numbers with the format
CYYDDD
Where C = century after 1900.  So for the current century it would be 1, 1900 - 2000 = 1
YY is the year in the century for example 12 for 2012
DDD is the day of  the year.  For example April 1, 2012 is the 92nd day of 2012

Time Fields
Date and time fields are stored in separate columns in the JD Edwards database.
Time fields are stored in military time as
HHMMSS

HH = hour 1-24 not zero filled, so if its just after midnight you would have only MMSS
MM = minute 00-60 zero filled
SS = second 00-60 zero filled

Below is the user defined function I used to parse the date time.  The performance on this was not super great so to help it I put a Common Table Expression (CTE) in my stored proc.  This limited down the result set to speed up the conversion on a smaller number of records.

The performance seemed really bad when comparing SQL server datetime to the UDF result. Probably because it had to convert all JDE date times into SQL server datetime before it could do its comparison.

The UDF


  1. CREATE FUNCTION [dbo].[ToGregorian](@julian varchar(6),@time varchar(6))
  2. RETURNS datetime AS BEGIN
  3.     DECLARE @datetime datetime,@hour int, @minute int, @second int
  4.    
  5.     IF(LEN(@time) = 6)
  6.         BEGIN
  7.             SET @hour = Convert(int,LEFT(@time,2));
  8.             SET @minute = CONVERT(int,Substring(@time,3,2));
  9.             SET @second = CONVERT(int,Substring(@time,5,2));
  10.         END
  11.     else IF(LEN(@time) = 5)
  12.         BEGIN
  13.             SET @hour = Convert(int,LEFT(@time,1));
  14.             SET @minute = CONVERT(int,Substring(@time,2,2));
  15.             SET @second = CONVERT(int,Substring(@time,4,2));
  16.         END
  17.     else
  18.         BEGIN
  19.             SET @hour = 0;
  20.             SET @minute = CONVERT(int,LEFT(@time,2));
  21.             SET @second = CONVERT(int,Substring(@time,2,2));
  22.         END
  23.    
  24.     SET @datetime = DATEADD(YEAR,100*CONVERT(INT, LEFT(@julian,1))+10*CONVERT(INT, SUBSTRING(@julian, 2,1))+CONVERT(INT, SUBSTRING(@julian,3,1)),0);                     
  25.     SET @datetime = DATEADD(DAY, CONVERT(INT,SUBSTRING(@julian, 4, 3))-1,@datetime);                   
  26.     SET @datetime = DATEADD(hour,@hour,@datetime)
  27.     SET @datetime = DATEADD(minute,@minute,@datetime);
  28.     SET @datetime = DATEADD(second,@second,@datetime);
  29.    
  30.     RETURN @datetime
  31. END

Wednesday, March 14, 2012

Stuck in zoom mode

In visual studio sometimes my mouse wheel gets stuck in zoom mode.  To fix this in the past I have shut down visual studio.  Depending on the size of your project this can take some time.

I found a simpler solution.  clrl+a to select all and the mouse wheel zoom scroll is broken no longer.


Thursday, March 8, 2012

Command Window in Visual Studio

Tired of scrolling through your solution explorer looking for that class. You know the name of it, but you making that mouse wheel work overtime to find the class in your project.

To get around this just use your Command window in visual studio.  To open the command window
1. click on the view menu on the menu at the top of visual studio, or better yet, just 
2. Go to the other windows 
3. select command window
or shortcut keys ctrl+alt+a

this will open the command window docked at the bottom of visual studio.

Inside the command window you can just type "of" and part of the file name.  The command window will give you suggestions and you can pick the class file you want.


This has been a huge time saver for me.  Try it out.


Wednesday, March 7, 2012

#region #endregion - You might have stinky code

Methods perform one and only one function. Methods with less than 15 lines of code makes me want to take a deep inhale. Getting a good whiff of that fresh smelling code.

Having more than 15 lines of code most likely mean you are doing more than one function. When I see these types of methods, I want to hide my nose under my t-shirt. Or maybe just pinch my nose closed.  Writing unit tests for run on methods that reach 100's of lines is nearly impossible. The maintainability of long stinky methods is low. Of course there are always exceptions, but short  methods are always my goal.

If your method has regions, you might have stinky code.

Applying the same idea to classes works also.  I really don't have a target for a class.  No magic number of methods or number of lines of code in a class. Your code is most likely stinky if you have one class in your library or application that has hundreds of methods and over 50 percent of code in your application.  Even more likely if the class is called main, or util.

Again in a class if you might have stinky code if you have regions.

Leaving #region out of your code leads to fresh smelling code.

No regions also means you don't have to remember those pesky shortcut keys to expand those regions any more.


Tuesday, March 6, 2012

Keyboard and mouse

As a software developer one of my most important tools is my keyboard and mouse.  It is my connection to my computer.  Most times I am thinking about what I am doing so much the keyboard is an extension of myself.  I don't really think about what I am typing, I just think about it and it goes into the computer.  The typing is nearly subconscious.

However, if you have a poor mouse or keyboard, then this subconscious work of typing the keys becomes more of a conscious decision.  You have to think about where the keys are you need to press.

Ok, so I think a lot about the keyboard and mouse that I use. I have had many over the years, and my favorite right now is the Logitech wireless wave keyboard.  The keyboard feels very natural.  I don't have to think about typing i just think and type. I really like the small receiver, not like some of the old wireless stuff I have that has long cords.  The built in wrist wrest is stylish and looks very modern. The USB receiver is super small and you don't even notice it.   The combo has many other features I am sure are nice, but I really don't use them.

I have one both at home and at the office. I have found various deals on the combo but you are most likely going to pay around $60 dollars for it.  For me who uses a keyboard for many hours each day it is certainly justifiable.



Here is a link to it on amazon.
http://www.amazon.com/Logitech-Wireless-Combo-Keyboard-920-002555/dp/B003VAHYNC/ref=sr_1_1?ie=UTF8&qid=1331091048&sr=8-1

Monday, February 27, 2012

Automated TFS Testing

TFS is a great tool for doing automated testing. Last year I did a presentation and the twin cities code camp on automated testing using TFS. 

Using automated testing you can take a task that would take a QA analyst days to complete in just a few minutes. 

In this demo I show how to create an web performance test and also how to create your own web test plugins to extend the functionality that Microsoft gives you out of the box.


Friday, February 24, 2012

Visual Studio Themes

I spend up to 40 hours per week staring at visual studio. Visual studio is the best IDE for development in the industry.  However, there is always room for improvement.  And I am always looking for ways to be that lazy coder and make things easier and faster.  

One simple tool I use to accomplish this is to change my visual studio themes.  Its really easy to change and saves eye strain, and just is a way to personalize my Visual Studio experience.  

Of course you can always create your own themes, but being lazy I would rather have some one else create them for me.  And of course I don't really want to pay for them either.  Luckily someone has put together an cool site where users can upload and share there visual studio themes.  

When you download your themes you can make your life easy by putting them in the folder
C:\Users\[your user name goes here]\Documents\Visual Studio 2010\Settings

The site is simple, and easy to find your favorite Visual Studio theme.  I personal favorite is humane studio.  http://studiostyl.es/schemes/humane-studio


To install your downloaded theme in visual studio 
1. From the tools menu in visual studio select import and export settings
2. Import selected environment settings
3. Click next

4. you can choose to backup settings here, I usually don't


5. Click on browse to choose your settings

 6. pick your downloaded theme

7. Finish and your visual studio experience is customized.


Tuesday, February 21, 2012

MVVM Light

On a recent WPF project I had to choose a pattern to follow.  After researching WPF patterns I landed on MVVM.  I evaluated more traditional routes such as using the classic code behind event driven pattern taken from ASP.net.  However MVVM offers benefits that the code behind model just cant match.

Following the MVVM pattern your application is
- Testable the #1 reason to use this.  Ever try to write a unit test against a
- Blendable, or at least it can be based on the framework you use
- Decoupled design
- Simpler code, less code

After deciding that MVVM was the way to go, I had to decide on a framework.  I looked at a bunch, but they all seemed very complex to implement.  And I was working on a pretty simple application.  Wasting hours implementing enterprise type design did not make sense for this application.  Based on this criteria I decided on MVVM light.  It was easy to understand, and implement.  And had all of the key pieces I needed to implement the MVVM patter, but no more.
http://mvvmlight.codeplex.com/

NUGET
Of course you can get MVVM light through nuget in visual studio.  I cannot say enough good things about nuget, every Microsoft developer should use this!
http://nuget.org/

MVVM 
This is not just a Microsoft pattern, but it works well with xaml based applications.
http://en.wikipedia.org/wiki/Model_View_ViewModel

I will follow up with more details and a sample project for MVVM.




Thursday, February 16, 2012

UI Mockup Software

Writing software is not the hard part, its understanding what the users want.  You can build great software, but if its not what the users want, you cannot turn your hard work into success. One method I find works well is creating screen mock ups.

I have tried many tools to do GUI mock ups.  Many of them tend to be two complex. I have tried Microsoft Sketch flow, Power Point, Photo Shop.  To me they were all to complex.  I was looking for a tool that I could use quickly.  My goal was not to make it look like the real thing. But to make sure I was building what the users want.  I so far have found two different tools I love for doing wire frame mock ups.

Balsomiq
The first tool I fell in love with was Balsamiq http://www.balsamiq.com/.  This was super easy to use and kept users out of worrying what type of font they wanted. The only problem is the freeware stuff is online only and you cannot save.   If you have the money this is all you need.

Pencil Project
The Other tool that I use is Pencil.  http://pencil.evolus.vn/en-US/Home.aspx  This works great and is free.  You can run it through fire fox or install it on your pc.  I usually use chrome and dont have firefox installed so I opted for the installed version.


Tuesday, February 14, 2012

Visio Crashing on windows 7

I was having a problem with Visio 2010 crashing on my Windows 7 64 bit PC.  After searching I found that the send to blue tooth com plugin was causing it to crash.  I found about this here.

Visio Blue Tooth Plug In

To disable this in Visio 2010
1. For Vista or Windows 7 you will need to open Visio in as Administrator. To do this Hold the shift button and right click on the Visio shortcut on your start button.

2. go to the file tab and select options

3. click on manage

4. Click Remove


5. After the remove your screen should look like this