Thursday, October 03, 2013

Code Camp 2013 is on its way - November 2

The Central Penn .NET User Group has been organizing code camps for so many years. We started at HACC (Harrisburg Area Community College) and then turned to HU (Harrisburg University). Due to technical (and other) reasons, we moved to ITT Tech. Near Harrisburg Mall. ITT Tech is a wonderful place for us to conduct the code camp. We had schedule conflicts with them the last year (2012) and we did not have a code camp. We all missed it, for sure.

This time we are lucky again to have ITT Tech as our venue partner.

So guys, its official. November 2nd. Speakers (Great speakers!) are lining up. With great topics, ranging from AngularJS to SignalR.

Venue
ITT Tech
Suite 100, 449 Eisenhower Blvd., Harrisburg, PA 17111

For details, you could visit http://www.central-penn.net and click on Code Camp 2013. Please keep checking the site, as we finalize the speaker list and topics (with other details).

Sunday, June 09, 2013

Framework vs. Utilities (Level 100)

 

Where: Somewhere in earth.

When: More than a decade ago.

Me: Sir, what is a framework?

Architect/Team Lead: Oh, it is a set of utilities.

Years after, when I stumbled upon IoC (Inversion of Control)  and Dependency Injection, and articles from Martin Fowler, it dawned on me that Framework IS NOT JUST set of utilities. When I got the hang of it, I tried explaining the concepts to my fellow developers.

IoC is the one implementation which distinguishes a set of utilities from a framework. With IoC implemented properly, the Application is just part of the framework. Without IoC, Application is in control. Lets delve further.

Set of Utilities

Well, there wouldn’t be any project on earth without any set of utilities. Functions which are common across the application, which we abstract into small utility classes or functions. In this case, the Application is in control. The application decides when and how to use the utilities. For example, we go to our nearby McDonalds (or a nearby favorite fast food place). We are in control. We decide where to park our car (in spaces available of course :)), when to order, what to order, where to sit, where to hang our jackets. Got it?

Framework

UpscaleRestaurant

When we have a Framework, the application is a part of the framework. We have to register the application (or parts of the application to be used), and the framework will decide when and how to invoke our application. This concept is called Inversion of Control. Let’s suppose we go to any up-scale restaurant in New York City. Typically we have to make reservations (analogous to registering the application). THEY (the restaurant) will let us know what time is available. Once we reach there, THEY valet part our car. We wouldn’t have any idea where the car is getting parked. THEY usher us into the dining area, and get our jackets and hang it in THEIR own locker rooms. (You are getting the hang of it, rt?). Once we are done with the food, our jackets are returned and our car comes when we step outside. THEY take care of us. THEY are in control.  WE become part of their SYSTEM (analogous to the FRAMEWORK).

To know more about IoC and Dependency Injection, read this article: http://www.martinfowler.com/articles/injection.html.

Happy Programming.

Wednesday, May 29, 2013

Privacy Policy

This Application does not collect any personal information

This Application does not connect to any online service

This Application does not contain any other features that could allow users to unintentionally share their personal information.

Wednesday, May 01, 2013

.html() stripping off form tags


Recently I have been working on jQuery and KnockoutJs a bit. A bit means, a lot. :) It has been really exciting times as I have been learning lot of stuff. There are also times where I pull my hair off. :)

I have a View which is a pure html file, with no bells and whistles, except the "data-bind"s for the Knockout. And I load it using .get{} and place it in a
inside a page. Kinda SPA we have in place.

.get ("/<SomeDir>/<Somefile.html>", function(data){
 
 $("#someDiv").html(data); 
 ko.applyBindings(new ViewModel, $("#formElement")[0]);
});
See the second line after the html placement? The ko binding, that is. The application crashes on the line. While debugging, I found that $("#formElement")[0] turns out to be "undefined". "formElement" is the
tag I have which wraps the contents in the html file. I was getting this only on IE10. I have no issues in IE8 and IE9. This really started bothering me. I looked around the internet and had no clue! I started debugging again, with my ultra modern debugging tool - alert() statements :). I place an alert statement right after the html placement. As:
.get ("/<SomeDir>/<Somefile.html>", function(data){
 
 $("#someDiv").html(data);
 alert($("#someDiv").html());
 ko.applyBindings(new ViewModel, $("#formElement")[0]);
});
This retrieved the html data that we placed in. What I saw really took my skin off! I saw that the
form tag (with id as formElement) had been stripped of! Yes, stripped off. Taken off! And that meant there was no "formElement" that got loaded in the DOM and hence the crash. I went hunting for answers again. And I found that I was not alone. Eventhough there was only one link which helped me: http://forum.jquery.com/topic/is-jquery-stripping-form-tags In HTML5, you cannot have a
tag inside a
tag. So, the html() strips the
tag out, without any warning! Thats bizarre. But thats what it does. In the article/forum post mentioned above, there are three workarounds:

1. Take out the "form" tag from the html file.
 This is the easiest and straightforward approach. But my case is different. I have validations in place, using jQuery UI Validation plugin. And that works only against "form"s.

2. Add a "form" tag in the beginning. Just before the opening "form" tag. Even though it would work, it seems like a hack to me. No, it is one.

 3. Use append() function instead of html(). Like,
 
$("#someDiv").html();
$("#someDiv").append(data);

Even though the 1st one is the right move, I would go with the 3rd one. Hope this would save hours of someone's life, as it did mine :) Have a wonderful programming day!

Seeding Junction Tables with EF Code First


My stint with Code First
My first stint with Code First was when I attended a code camp at Lebanon Valley. Mike Lukatchik (@mlukatchik) did a very energetic and informative session of Code First. He emphasized that code first is very useful in an agile environment. I kind of saw where it could be used, and I was very impressed with how he presented. But I should admit that Code First could be practical enough for a enterprise environment. I could almost hear the DBAs getting angry! :)

I was so impressed with Mike's presentation, that I invited him over to present the same session at the Central Penn .NET User Group's monthly meeting. Needless to say, it was one of the best presentations ever. Thanks, Mike!

What is Code First?
There are umpteen number of articles around Code First. But to give a simple answer, code first with Entity Framework is a technique where we create Entities first, instead of creating database objects. The database objects gets created by the Code First framework. If you are knew to Code First, I suggest you to take a plunge into this article -

Our Sample Entities
Now, let us dive into the core of the article. Suppose we have two entities - User and Role. And lets say, a User has more than one Role. And a Role could be shared among many Users. You are right - a Many-to-Many relationship. And, as you know, the Entities in EF are nothing but POCOs. Plain Old CLR Objects.

public class User
{
   public int UserId {get; set;}
   public  List Roles {get; set;}
}
public class Role
{
   public int RoleId {get; set;}
   public  List Users {get; set;}
}
Once you run the migration, the corresponding tables get created. Like the ones below:

--> Screen shot of tables in the database

Junction Table

Where is the relationship though, you may ask.

Well, do you see the collection of Roles entities in User entity? And do you see the collection of User entities in Role entity? The Entity Framework is smart enough to take these into account and create a "THIRD" table - a Junction table.


Note that the junction table DOES NOT have a corresponding Entity in our context. That is because we do not need it. We could use either User entity or Role entity to get the relevant collection data.

Seeding Data
Many a times, to test the application, we need seed data - test data, that is. The Configuration.cs file that EF creates, is used for placing the code to seed the data.

A Footnote:
In my new project, we use Code First. On my very first day, when my Technical Architect told me that we are using Code First,  all the slides and code from Mike's presentation poured in. Even if I didn't know the intricacies of Code First technique, I did not have a starting trouble - it just took 20 minutes of a sample code and little bit of reading to get into the groove. That was all because I had attended Mike's presentation.  Many of my programmer friends and colleagues do not see the benefit of attending a user group meeting or a code camp. Well, here is one! :) The biggest (and the lamest:)) argument I every hear is that "Oh, we wouldn't be using this technology… "… Well, you never know :)

Monday, November 05, 2012

Intellisense in VS2012 Express

I tried playing with the Visual Studio 2012 Expess for Windows 8, when I encountered thathe  Intellisense was off on my XAML window. It was on for C# though (I mean the code-behind).

All I had to do was to run the following at the VS command prompt:

devenv /resetsettings

And then just restart the Visual Studio. 

Friday, August 17, 2012

The new releases!

MS has released VS2012, Windows 8, and .NET 4.5 to MSDN subscribers! Time to grab them and get working!

Cookies, anyone?

  Our application started having integration issues early March this year. Did I say that was intermittent? To add to our confusion, we coul...