Wednesday, May 6, 2009
New Blog
I've noticed that I tried to keep my personal life and my technical/professional life separate. However, after talking about it with my husband I discovered that the technical side of me is who I am. However it is not all I am. Therefore I decided to create a new blog that will include technical ideas, code, and projects; personal posts; and posts about my other hobbies. Not only that, but I am encouraging my husband to find his inner blogger and have made this blog a multi-author blog where he will be making a contribution here and again.
If you've been following my blog, check the new one out here : http://me.christinahelton.com/blog
Tuesday, April 14, 2009
C# - Singleton in C# Code Snippet for Visual Studio 2008
While I was working on some code I decided I was going to develop a class library that I could use in multiple projects. Of course, since this was done on a whim, I eventually had the need to move some things around and add some functionality to class that I had already created as static.
Now some people have asked why I created these classes as static. Since I am always on the hunt for ways to do things easier, better, and faster, I had made this decision based on the following from a MSDN article about static classes:
“Use a static class as a unit of organization for methods not associated with particular objects. Also, a static class can make your implementation simpler and faster because you do not have to create an object in order to call its methods. It is useful to organize the methods inside the class in a meaningful way, such as the methods of the Math class in the System namespace.”
Since these were methods that I did not feel I needed to create an instance of, it was easier for me to make them static. That way I could just say SPMethods.CreateSite(“parameters”) and be done with it.
Now the reason for some change. As I was utilizing my class library in a project, I came about an issue where I needed some more information from these static classes when they encountered an error. I had been “bubbling up” the errors using try-catch and a throw, however after some great advice from my Dad I realized that I was definitely unable to control this effectively within multiple applications with the way I had it. So that is when I decided to add some error logging capability with a little more power than the occasional “throw”.
Eventually I added some interfaces and an abstract class to handle it all. Applying it and the ability to override certain functions in my main application was easy. However when I went to apply the same class to my static class I ran into issues. I obviously couldn’t apply an abstract class to this static class. What to do now?
Enter the Singleton, a design pattern. I didn’t want to create multiple instances of these classes, however I wanted to be able to implement my new abstract class. The Singleton fixed me right up with the ability to create a single instance of my class (while following coding development patterns), utilize the methods I had created previously, and also implement my new abstract class effectively. Add some properties to each and voila I was able to pass information back and forth accordingly, log the way I wanted to, and everything was done pretty quickly. If you haven’t heard of the Singleton before, here is a blurb from an MSDN article titled Implementing a Singleton in C#:
“You are building an application in C#. You need a class that has only one instance, and you need to provide a global point of access to the instance. You want to be sure that your solution is efficient and that it takes advantage of the Microsoft .NET common language runtime features. You may also want to make sure that your solution is thread safe.”
Perfect! Now I only had to add this functionality to my classes. After adding the second one I decided there had to be an easier way to do this. That’s when I decided to look into Code Snippet behavior in Visual Studio 2008. I followed this MSDN tutorial and I was able to create a code snippet for Visual Studio 2008 in C# which I don’t mind sharing. ;)
I have the snippet in a library on CodePlex at http://vs2008csl.codeplex.com/. Click the image below to go to the download page. Instructions for unpacking the .vsi file are in the release notes, however if you want to simply view the snippet itself go to the source code tab for a nifty code viewer of all of my recent check ins.
Now this code snippet is for C# and it uses the Code Snippet Function ClassName() which apparently does not work in VB. However all it does is by default add the name of the class that I am currently in which saves me the extra step of replacing the name. I still made the class name an editable replaceable parameter, however, so if you want to change the name of the class simply type it in and press enter to fill out the code snippet accordingly. If you are not sure how to install the code snippet check out this MSDN article which explains how to use the Code Snippet Manager.
I hope this helps someone. I plan on adding more code snippets in the near future.
Wednesday, March 4, 2009
Chocolate = Code Love Haiku
I code all day long
Sometimes it can hurt my brain
Must have chocolate
--------------------------------------------------
Christina Helton, 2009
Friday, January 9, 2009
Oh What the Nerd I Am
Is it sad that I am entirely too excited about new technologies?
If you know me, I love to organize. At my home I like the house to be neat and clean where everything has a place. My favorite thing to do is buy containers for everything and hide things away in a decorative fashion.
The same is to be said about my computer. I am one of those people that keep my system organized. Yesterday I spent the entire day re-organizing my files. I re-partitioned some drives, set up my backups, and set up my syncs. It’s such a great feeling to get things in order!
I set up my computer to dual boot the Windows 7 beta this morning. I had read a lot of interesting things about the new OS, but I decided I wanted to try it out for myself, being quite the technology enthusiast I am.
So far I have had quite the good time with it. If Aliha is willing to work with me today, I will be posting more information about it today.
Want to get Windows 7? If you are a member of MSDN, check your MSDN subscriptions and downloads for your chance to download the beta. Otherwise, check the Welcome to Windows 7 page where they will be placing a link to download it. However, Lifehacker’s article today about getting into the beta states that “it’s only available to the first 2.5 million downloaders.”
Tuesday, December 2, 2008
C# - Open a Browser with a certain URL
string url = @"http://www.google.com";
Process.Start("rundll32.exe", "url.dll,FileProtocolHandler \"" + url + "\"");
Thursday, November 20, 2008
Technology Fun with Photos
I decided to play with the Deep Zoom Composer today, and it can create some pretty spifty zoomable photo album configurations. I uploaded my "album" to PhotoZoom and this is what I got (you will have to install Silverlight to see it):
Friday, October 24, 2008
Playtime: I love Linq and WPF!
public static void SignOut(User newUser)
{
WorkAchievementsDataContext db = new WorkAchievementsDataContext();
var updateUser = db.Users.First(u => u.ID == newUser.ID);
updateUser.IsLoggedOn = false;
db.SubmitChanges();
}
So entirely make my day!
Isn't that wonderful? Four lines of code and I have successfully updated my database. No connection strings, no stored procedures, it's just there in those four little lines of code! How wonderful. :)
Basically (for those that are new like myself) the lines do the following:
1) Creates an instance of the DataContext from my Linq to Sql Class.
2) Uses a lambda expression to retrieve the user that has an ID matching the one that is passed in.
3) Changes the "IsLoggedIn" field to false in my table.
4) Saves the changes to the database.
Being new at WPF and Linq, I am sure that I will find lots of fun and exciting things to play with, but for now it is time to go home.

