I’m constantly amazed by the insightfulness of ReSharper’s suggested refactorings (ReSharper is a Visual Studio Addin from JetBrains I use with C#). Today, I’ve been working on a threading problem where I’m getting crashes based on what seems like not proper locking across threads (they usually show up as some type of ugly update object or enum error).

My code starts like this:

 

public static List<DbProgressReport> DbProgressReportProperty { get; set; }
 
(more…)

So, you have a simple class that has a bunch public properties and you want to be able to use ToString() on it to show some data?  It’s easy.  All you have to do is override the ToString() class inside your C# code.

So, here is an example class that does that.

public class DbProgressReport
{
public string ScopeNameProgress { get; set; }
public string SourceOrDestination { get; set; }
public string TableName { get; set; }
public int TotalRecords { get; set; }
public int ChangesApplied { get; set; }
public int ChangesFailed { get; set; }
public int ChangesPending { get; set; }
public int Deletes { get; set; }
public int Inserts { get; set; }
public int TotalChanges { get; set; }
public int Updates { get; set; }
public DateTime LastChangeDate { get; set; }

public override string ToString()
{
string readableDbProgressReport =
string.Format(
"{0} ScopeName {1},Table {2},TotalRecords {3}"
SourceOrDestination, ScopeNameProgress, TableName);

return readableDbProgressReport;
}
...

Now, all you have to do when accessing this class is use the ToString property.

That is:

DbProgressReport dbProgressReport = 
new DbProgressReport("source","scopename","tablename");
string str = dbProgressReport.ToString();

and the output will be:

source ScopeName scopename,  Table tablename

Simple as that!

Hope this helps.

So, you want to add a couple extra parameters to an existing method in Visual Studio, while not having to change all your existing code to call the new method signature?  It’s easy with CodeRush from Devexpress.  In this post, I’ll start with a simple method and add some parameters to it, then do the magic refactor.

Here is the starting code.

public static int SynchronizeScopesAsyncStart(
int dbSyncPairId, string schemaName,
string connectionStringLeft,
string scopeLeft, string connectionStringRight,
string scopeRight, bool skipDbLogging)
{...

(more…)

In my previous post (http://peterkellner.net/2010/07/10/installing-umbraco-to-win7-step-by-step/), I detailed the steps to use WebPI to install a fresh version of Umbraco on a Windows 7 Ultimate 64 bit system.  Now that I’ve done that, and played with it for a few hours, I’d like to start again with a fresh (no RunWay) set of data to play with.

I posted on the Umbraco forums and got some tips, but I thought I’d document the process here because I’m sure I’m going to be doing this again and thought it best to have some notes I can go back to (and that might help others newbie’s to Umbraco while I’m at it).

(more…)

I’m planning on launching some small consumer software products in the next couple months and to support this effort, I need to have a CMS, Forums Software, Store Front (Credit Card Processing) and Wiki solutions up and running.  Since I’m a .Net guy, my first choice is to use Microsoft .Net technology, but if I don’t find anything there that suits me, off to the LAMP stack I go.  It’s important to me that all of these are tied together with a single sign-on.  It always irritates me when you go to a site and they make you first log in to the site, the create a separate login for forums.  I will avoid that experience for my customers and users.

 

My Research

My research first started with Google/Bing type searches.  That really leads me to many choices.  Actually too many.  Next, I go to my friend network.  The first obvious person I turn to is Scott Cate because he seems to always have the best advice on this kind of thing. The guy is plugged into everything!

Scott give me a very strong recommendation to look at Umbraco.  He says he is personally involved in writing code for that CMS, it’s very extensible, has a great admin UI and bottom line, is just good stuff.  So, Off I go to http://umbraco.org.

 

(more…)

For the last few days, I’ve been using DevExpress CodeRush and am finding some very useful refactorings.  Many I’m not blogging about, but there are a few that I really like.  In this post, I’m going to show just two of those refactorings that have been making my code much nicer and easier to write.  One is the “Introduce Using” refactoring, and the other is “Convert to Lambda Expression”.

Before I go into the details, I’d just like to disclose that when I was first writing the Silicon Valley Code Camp web site, I was an asp.net and c# newby.  I’m not claiming wizard status now, but I have to admit that when I go back and look at some of the code I wrote back then (including what I’m showing below before the refactoring), it’s a little embarrassing.  Silicon Valley Code Camp for me as “when I’m not doing real work” web site so I don’t really have the time to go back and clean things up.  Now, with CodeRush, it’s easy to clean things up when I see them with very little effort.

(more…)

I’ve recently started using CodeRush with Visual Studio 2010 and am so far very impressed with the convenience it adds to coding.  One thing that is very clear is that the creators of CodeRush are real programmers and look very hard for patterns that us developers are constantly doing.  As I run into these things that get my attention, I plan on blogging them.  Some are just earth shattering, and others, just nice to have.  This particular one is a nice to have.

So, say you have code like this:

 

var sessionAttendeeOds = 
new SessionAttendeeODS();
listSessionAttendees =
sessionAttendeeOds.GetByUsername(Context.User.Identity.Name);
 
(more…)

MSDN has a very nice article on how to create a windows service that hosts a Windows Communication Foundation (WCF) service.  It explains all the details of doing this in a step by step fashion.  One thing that I often find missing from these articles is the actual Visual Studio project that I can download and play with.  What I usually do is put that together myself (which I’m sure is the author’s intent).

To save anyone some time who wants to do the same thing, I’ve created a VS2010 project from the example, added a very simple Windows C# console application that consumes the service, as well as made some small changes in a very nice Windows Presentation Foundation (WPF) calculator project so that the calculator does it operations inside the windows service rather than in the calculator itself.

In this article, I’ve attached the source code (with my small changes and additions) for you to work with and change as you like.

(more…)

Last week, while at Microsoft’s TechEd 2010, Mehul Harry, Technical Evangalist for Developer Express, interviewed me about our upcoming Silicon Valley Code Camp (of which Dev Express is a platinum sponsor).  There was huge giveaway (for an expensive motorcycle) in the next booth so it was really noisy.  Mehul had the recorder about 6 inches from my nose which made me pretty nervous.  I think I’m moving my head so much because I was trying to get away, but there was not place to go.

Here is the link:  http://tv.devexpress.com/#TechEd10PeterKellner.movie

 

(more…)

Yesterday, I spent the day building what I think are stantions (piles of blocks held together by mortar) to hold a house 5 feet above the ground.  Through twitter, I saw a bunch of people from all over the country that were going to TechEd 2010 in New Orleans a day early to help in a Habitat for Humanity project.  The group had created a web page called http://geekgive.org/Charity/habitat.  I’ve always wanted to help on one of those type projects but never really figured out how to.  This seemed like the perfect opportunity, and also, since some of my friends from around the country would be there also, I thought it would be a great time to catch up.  What a great time and a great feeling to help.

As everyone knows, New Orleans was devastated after the kill hurricane went through.  Many houses were just totally demolished.  These Habitat for Humanity houses are designed to sit 5 feet above the ground on steel re-enforced concrete blocks.  They can withstand 125 MPH steady winds with 200 MPH gusts.

(more…)

After my second year at engineering school (Cornell University), I spent the summer working in a dream job as an intern at the world famous Ford Design Center in Dearborn Michigan.  The group I worked in was an elite group of engineers whose responsibilities were to figure out better ways to build the cars that would come out in 5 years.  Literally, the sky was the limit for what we could do or propose doing.  I remember one evening walking around the cars made of clay with Charlie Haddad who was the director of our engineering group.  Charlie suggested I look at each car and think about what could be better.  I remember him saying “just clear you mind and think, spend real time on it, don’t make it a passing thought”.  Today, while staying at the Sheraton Hotel in New Orleans this week for Teched 2010,  I believe I’ve seen one of Charlie’s students work.  Let me explain more.

(more…)

For quite some time now, when I download file using IE8, the file finishes downloading and there is no pop up that allows me to open the containing folder, or open the file itself.  I’ve had to navigate to the folder where I selected the download to go, then open it from there.  This has been very annoying.  I’ve looked around the internet for the reason for this with no luck.

(more…)

 

Should Your Application Run In The Cloud

I’m back and sitting in Steve Evans Session, Should Your Application Run In The Cloud.  He’s now explaining how computers, since the stone age, have been running in hosted facilities where you had to worry about things like fire suppression.  Steve is explaining the advantages of cloud computing.

Upfront costs are cheap ($.10 –> $1./hr)

DSC_0419

 

Let’s Build a Ruby on Rails App Together

Kristen Hazard of SunToucher presented the basics of Rails starting from the beginning.  She points out that most of the content at this event is .Net, but that doesn’t mean people are interested in other topics.  Kristen let’s us know she’s totally excited about Ruby and Rails. She goes from creating a complete rails app by simply creating a simple command line, all the way through deploying the ruby app to a server with just a simple command also.  Below show just what Kristen thinks of Ruby on Rails.

DSC_0414

One more class on my agenda, GIT!

I love code camps!  This is my first time to San Luis Obispo’s Central Coast Code Camp and I’m really enjoying it.  It started last night with the presenters dinner at a great local steak house.  Steve Evans, one of the camp organizers who invited me to this speakers dinner, got sponsors to pay for our food, go Steve!  Steve has organized the night before at our code camp (Silicon Valley Code Camp) speakers presentation for the past 2 years and I hope he continue that for years to come.

Steve and Scott At Presenters Dinner

(Steve Evans, One of the organizers and Scott Stanfield, CEO of Vertigo and presenter of HTML5 here)

Following a good night sleep, camp began early, 8:30 was registration.

 

ccccreg

Moving on to the opening ceremony…

DSC_0383 DSC_0384 DSC_0387 DSC_0388 

Justin Couto President of Couto Solutions took care of business letting everyone know the lay of the land with the rest of us paying close attention.

The first class started at 9AM. I attended Scott Stanfields’s presentation on HTML5 (pictured below).

  DSC_0394 

Then, I presented on OData and hopefully helped explain some of the Microsoft Acronyms (WCF Data Services, Astoria, ADO.NET Data Services, RIA Services, etc.)  I build a twitter feed against a twitter call, and also build a simple WCF Data Service against our Silicon Valley Code Camp SqlServer Database and showed over 250 sessions that have been delivered.

Well, off to lunch now.  I always plan on posting more, but likely, I’ll just post my session powerpoint and that will be it.  So far, having a great time and thanks to all the organizers for putting on such a great event.

One of the very cool new features in Visual Studio 2010 is the ability to “Pin” a variable you are watching, right in the place you want to see it.  It’s always been a hassle to have to add a “Watch” and keep track of it among all your other watch variables.  I guess I shouldn’t really complain because I’ve always really like the debug capabilities in Visual Studio, but I have to say, this new “Pin” is really nice.

(more…)

* I’m adding this comment after the post has been written to let anyone coming here know of another great post that goes further to explain no only what I’ve done here, but also two other ways including Mock and using Json Serialization.  The Post is written by Ashic Mahtab, aka “HeartattacK” on the forums.  His well written and informative article is here:  ASP.NET MVC – Unit Testing JsonResult Returning Anonymous Types.

This post will show how to return a simple Json result from an ASP.NET MVC 2.0 web project.  It will show how to test that result inside a unit test and essentially pick apart the Json, just like a JavaScript (or other client) would do.  It seems like it should be very simple (and indeed, once you see the answer it is), however there are lots of length discussions on the forums about this with all kinds of positives and negatives.  The one I based my solution on is from Stack Overflow and is here..  My personal length discussion that did not really yield a satisfactory answer is here.

If you follow my method, you’ll be able to unit test a JsonResult created by an MVC asp.net web application.

(more…)

Over the past couple years, the focus of the web development I’ve been doing involves building highly flexible, highly scalable and straight forward web sites to implement and maintain Line of Business (LOB) applications.  As you can probably tell from my posts, I’m very “practical” focused, and at the same time have a desire to build awesome web applications.

The technology pairing I’ve chosen is Microsoft’s .Net platform with MVC on the server, and ExtJS on the client.  Though it’s possible to still use ExtJS with standard html/aspx pages, I’ve found the best combination is to use 100% JavaScript on the client (ExtJS) and have all the server side technology be 100% service based.  I’ve used LINQ2SQL extensively as well as Entity Framework in the latest Visual Studio 2010 release.

The learning curve was quite steep to actually be able to efficiently build highly flexible, highly scalable applications using these technologies, but now that I know it, I wouldn’t have it any other way.

I’m considering putting together a series of 4 Day Classes around the country (or even world) that would basically teach people the methods and patterns I’ve learned and essentially leap frog a development team into being able to quickly do what it has taken me years to figure out.  I’ve been fortunate enough to know the top 1% instructors and I’m sure with the right incentive, can get them to join me in both putting together these classes as well as teaching them.

(more…)

In this post, we will show and explain a small TSQL Sql Server 2008 procedure that deletes all rows in a table that are older than some specified date.  That is, say the table has 10,000,000 rows in it the accumulated over the past 2 years. 

Say you want to delete all but the last 30 days of activity.  If you just simply say DELETE FROM table WHERE id>10000, you will cause this to happen in one transaction and likely, you will get an error.  That’s the best case.  The worst case is your system tries to do this, eventually consumes all the resources in your computer and crashes your server.

(more…)

In this post, we’ll go briefly the process of how you would update all rows in a SQL Server 2008 table such that a particular date column will be moved back 1 hour in time.  This is actually pretty simple, but being that I typically do my work in the ORM layer (that is LINQ2SQL or Entity Framework), I just don’t do much of this.  The process I’m going to follow is first to use Microsoft SQL Server Management Studio to make sure I know what I’m doing with the Sql Server 2008 functions, then add it to an UPDATE statement.

(more…)

In this post, I’m going to simply document the process of updating my MIcrosoft Office 2007.  As almost anyone knows who has not been hiding under a rock, Microsoft Office 2010 has been in the works for quite a while.  I know there are several launch events and formal release events coming up so I don’t mean to imply you can buy it now.  If you are on MSDN (Microsoft’s developer network) I believe you should be able to download it now.

You can read about the changes here:  http://blogs.technet.com/office2010/

 

(more…)

© 2005 PeterKellner.net. All Rights Reserved