Archive for the ‘Development’ Category

LINQ: Using SqlMetal with VS Express

Posted in Development, LiNQ
Post date: January 15, 2008

There are quite a few of us that don’t have the luxury of sitting with Visual Studio 2008 and rightfully so many of us make use of the Express editions. Heres the problem though: What happens you want to generate a DBML file for a database that does not reside on your local machine and you cannot access the mdf and ldf files directly?

You use SqlMetal! SqlMetal is the tool used by LiNQ and VS to generate your DBML files. The good news is that you can use this manually! To generate the DBML file for a database on the server you simply to the following:

Step 1:
Open a command prompt and navigate to “C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\”

Step 2:
Make sure you have a connectionstring handy to copy

Step 3:
Run the following command at the prompt –> SqlMetal /conn:”connectionStringHere” /dbml:DatabaseName.dbml

And thats it! Obviously where I’ve entered “connectionStringHere” you need to enter your connection string between the inverted commas and where I’ve said DatabaseName.dbml you can enter the name you want for you DBML file.

Once this is done you can simply include this DBML in your Express Project and all the will generated as per normal procedure. What does confuse me however is why Microsoft gives us this file but doesn’t implement its full use in the express editions. It makes no sense to me!

A beginners intro to Extension Methods in C# 3.5

Posted in Development
Post date: December 24, 2007

Extension methods are something new to the .Net 3.5 framework and an extremely valuable add-on!

Have you ever had a situation where you have been given a sealed class and desperately needed to add a method? Extension methods allow to add your own custom methods to any class! As a small example: imagine to want to add a method to the standard .Net String class. Normally you would never be able to do this.

Lets say we want to add a method to the string class to convert a string to an integer.

Step 1:

Create a Static Class:

namespace ExtensionNamespace
{
public static class Extensions
{
}
}

The reason behind creating a static class is that your functions should always be available without having to instatiate the class in which your methods reside.

Step 2:

Create your static Method:

namespace ExtensionNamespace
{
public static class Extensions
{
public static int ToInt(this string stringName)
{
//declare integer
int _intToReturn = -1;

//convert string to Integer
_intToReturn = Int32.Parse(stringName);

//return integer
return _intToReturn;
}
}
}

The access identifier on the method should always be public and static for the same reasons mentioned above. You need to then specify your return type for this method which in this case would be an “int”. The “ToInt” is the my name for this method. when specifying the input parameters for the method you are also specifying which class this method will be extending. Here we are extending the String class. You must *always* prefix the first parameter with the word “this”.

Once thats done its up to you to write the code for your method. obviously the code I have written above is extremely basic and so does not follow best practice so pay no attention to it. It is the structure of the method that you should focus on.

Step 3:

Implementing your extension:

When you want to use this extension, simply include the namespace in the code file you’re using. So in this case, at the top of your code page, specify the following using statement:

“using ExtensionNamespace;”

Then we simply declare a string for use and view its methods and viola! There it is!
ExtJPG.jpg

Tips on developing Facebook Applications

Posted in Development
Post date: November 18, 2007

We recently had the Johannesburg Facebook Developers Garage and I made extensive notes during the different speakers presentations. Since they gave them to us I’m use they won’t mind me sharing them. Naturally I will give credit where credit is due so if anyone minds me sharing what they said, please contact me via the post and I will remove the content. That being said I doubt it’ll happen. It was a very informative evening and some tips came up that all serious facebook developers should ernestly consider. I absolutely loved every single presentation and no-one bored me in the slightest, so if I don’t have any of your content here its because I want to focus this post solely on application considerations and not statistics.

Grant Fleming (Fontera)

——————————-

First off, before I say anything, here’s a link to a video taken of his presentation at the event: MyVideo Link.

For me personally Grant’s presentation was probably the most informative. He raised many very important points.:

1) Come up with a good, descriptive and catchy name for your application!

2) Make your applications useful as well as fun.

3) Be careful with invites, Facebook can and will BAN you if you’re not careful. So don’t spam the developer forums and other people’s posts.

4) Make sure you interact with your users. Listen to what they have to say and remember that they are ultimately your customers.

5) If you expect your app to work well, host the application outside of South Africa. We all know how expensive bandwidth is here and for example, Fontera’s applications moved over 4 Terabytes in one month!!!!

6) Although it may not seem good, if you are having scalability issues it is actually a good thing, depending on how quickly you sort it out. If you’re app faces too much downtime users will remove it more often than not.

7) Try not to make too many successive API calls as the FB API can be slow at times.

8) Make sure that you know all the POST variables of the FB API. This can come in very handy!

9) Make use of the Developer forums on Facebook. If you’re battling with something, chances are that 7 other developers have just overcome that problem!

10) Database Management is a serious activity if you want a serious FB application. Make sure the database is well indexed! If needed, de-normalize your database.

11) Remember to monetize your application. Make use of Advertising such as social media and Video Egg. This can generate much needed income!

Tyler Reed (Younique)

——————————-

Now here’s a young guy with passion for waht he does and how he does it. Definitely the most lively and enteraining presentation of the evening!

1) Understand your target user market for your application and what they want/need.

2) Try make use of technologies such as AJAX as this immediately impresses most people and it is generally extremely useful.

3) Install Google Analytics to track your traffic.

4) Interact with your users as much as possible.

5) Try keep your application’s interaction as interesting as possible.

6) Be prepared for scalability issues for your application.

7) Get your application out into the community as soon as possible! You think your idea is amazing, problem is 500 other developers might have exactly the same idea!

8) Once your application is available then worry about presentation of it and non essential stuff like that.

If you want to see Tyler’s presentation then check it out here: http://www.slideshare.net/tylerreed/facebook-m-xit-me

Eben de Wit (Microsoft)

——————————-

I’m sure he was expecting it but he got slightly bashed for being from Microsoft, either way, he still had a great presentation. He demonstrated a new application from MS called PopFly. It is currently in Alpha but looks promising for people who want to create applications but why aren’t developers. This is bascially a click and drag interface, then once you’re done, you simply export it to facebook and then its available. It is hosted on the PopFly website so check it out for useage restrictions as I’m sure there have to be some form of restrictions.

PopFly

Juan Roldan (Mentez)

——————————-

Juan was the final speaker for the evening and gave one of the most thought provoking presentation. Very interesting stuff, for this you HAD to be there to understand. I will try summarize what I got out of it but he was great!

1) You must be commited to your application.

2) Have your motivations clear for why you love this application and why you think its relevant.

3) Make sure you application has a target market!

4) Try think of something unique and useful. Something users will access/need on a daily basis. This is where his talk got interesting! You “demonstrated” brainstorming by asking a single question. “What is half of thirteen?”. The stuff we came up with was insane and nothing to do with numbers at all!

5) Target advertisers in your application to generate revenue. Example: Guy created an application whereby you could mark where in the world you had been. A few months later we sold the application for over 4 million US $ to a flight agency/airline.

6) Never fear Failure. The worst that can happen is that you fail, all you do then is try again!

7) When starting with your application, include a lot of local content BUT think globally for future use.

8) Build a separate website for your application.

9) When you initially start advertising your app to friends and family, target “champions”. Get someone influencial to use your application because if they use it, people who look up to them will use the application!

10) Try and make your application accessible from mobile devices.

11) Create tutorials for using the application if needed.

12) Always make the application using the English Language as it truely is the “universal” language.

All in all, it was an amaing evening and I would like to thank Armand and Arno for organizing everything and setting it up. It is much appreciated!

On a personal side note, I will be attending the Johannesburg Microsoft DevChat tomorrow discussing Visual Studio 2008 and its impending release and its new features. I cannot wait as I also get to spend the day with some old colleagues from the greatest company I’ve worked for thus far (www.signify.co.za). So to Johan and Gavin, see you in the morning!

LiNQ to SQL Introduction

Posted in Development, LiNQ
Post date: September 25, 2007

I finally got around to installing Visual Studio Orcas Beta 2 again. Recently I wanted to start looking into making use of O/RM (Object relational mapping) for a private project I was starting up at home.

First I tried to install NHibernate and use that but since I was too lazy to figure out exactly how it worked I moved onto ActiveRecord. That was going well till I actually tried to run the damn project. ActiveRecord for some reason would not connect to my database. After checking everything and posting on the ActiveRecord forums nothing was resolved. It is strange though as the connectionstring ActiveRecord was using was being used for a standard SqlConnection which worked perfectly.

I have no decided to move my focus from third party “plug-ins” to a Microsoft Beta. For those of you have no heard of or read about LINQ then take a seat and get ready.

LiNQ (Language Integrated Query)


The LINQ Project is a codename for a set of extensions to the .NET Framework that encompass language-integrated query, set, and transform operations. It extends C# and Visual Basic with native language syntax for queries and provides class libraries to take advantage of these capabilities.

http://msdn2.microsoft.com/en-us/netframework/aa904594.aspx


The LiNQ project covers several areas each naturally has a different function:

If you don’t have Orcas Beta 2 yet you can download it here : http://msdn2.microsoft.com/en-us/vstudio/aa700831.aspx. Now I realise its quite a massive download so if you want me to copy it to DVDs for you then drop me a mail here at “StevenMcd at StevenMcD.Net” and we’ll work something out to get these DVDs to you.

LiNQ to SQL

LiNQ to SQL is what I’m doing to be concentrating on first since this is basically and O/RM as previously stated. An amazing set of tutorials are available from ScottGu’s blog located here. His tutorials on LiNQ to SQL start here. His blog is wealth of information and if your aren’t subscribed to his RSS feed you are seriously missing out! Now what do I mean by saying that LiNQ is an O/RM? Imagine spending more time designing your classes to reflect your database structure? So take for an example an Employee Class. You would have an Employee Name, LastName, and probably ID Number. Imagine not having to write the general Select, Insert, Update and Delete SQL statements that makes our jobs so tedious?! Well imagine no more!

By constructing your class properly, and using a set of LiNQ attributes on your classes and properties you would not have to write these boring and tedious tasks! Obviously with more complex queries to the database you would still need to write your own Stored Procedures. In a future article I will cover this topic in more detail but for now I’ll end this off. I hope to have my next LiNQ article up by the weekend but due to other commitments it might only be early next week. For now, check out Scott’s blog and at the links listed below!

LINQ: .NET Language-Integrated Query
101 LiNQ Samples
LiNQ Wikipedia Entry

Blogged with Flock

VS2008 UserControl does not follow best Practice

Post date: September 20, 2007

Craig Nicholson found this bug while working with Visual Studio 2008 Beta 2 today. Help us get Microsoft to fix this before the Visual Studio 2008 release as this is extremely important. You vote here.

Why do I say this is extremely important? I have recently started delving into the world of Best Practice which I must has been an eye opening experience. When it comes to something like user controls, we as developers are generally lazy sods and we like using shortcuts. A company like Microsoft knows this and when it comes to built in controls they need to be leading the way in implementing Best Practice.

Best Practice is something a lot of developers know very little about and most of them aren’t too bothered by it. The general consensus is that if it works then its fine. This is a notion that we must get out of our heads! If developers at Microsoft are too lazy to follow things like this then why would the average developer out there care? So take the time and vote for this! head over to CraigN’s blog and show your support!

Blogged with Flock

"using” statement in C#

Posted in Development
Post date: September 4, 2007

I stumbled across something *VERY* interesting tonight that I never knew about.

usually when connecting to a Database, I manually open, close and dispose all the connection which is infact not necessary! Enter the “using” statement for C#.

This is usually how I would write the block of code:

   1:  SqlConnection sqlConn =  null;
   2:  SqlCommand sqlCmd = null;
   3:   
   4:  try
   5:  {
   6:      sqlConn = new SqlConnection(connectionString);
   7:      sqlCmd = new SqlCommand(“Sql command Here”, sqlConn);
   8:      sqlConn.Open();
   9:      sqlCmd.ExecuteNonQuery();
  10:   
  11:      sqlConn.Close();
  12:  }
  13:  catch(Exception ex)
  14:  {
  15:      //handle exception
  16:  }
  17:  finally
  18:  {
  19:      if (sqlCmd != null )
  20:      {
  21:          sqlCmd .Dispose();
  22:      }
  23:      if (null != sqlConn )
  24:      {
  25:          sqlConn .Dispose();
  26:      }
  27:  }

Whereas all that is really needed is:

   1:  using (SqlConnection sqlConn = new SqlConnection(connectionString))
   2:  {
   3:      using (SqlCommand sqlCmd = new SqlCommand(commandString, sqlConn))
   4:      {
   5:          sqlConn.Open();
   6:          sqlCmd.ExecuteNonQuery();
   7:      }
   8:  }

The using statement automatically disposes what is being used once the code block has run. Might be old news to some but awesome news to me. Its the small things that are so cool to discover

Blogged with Flock

Free C# Book

Posted in Development
Post date: August 22, 2007

Ok so the title is misleading but it basically is a book. It is in fact the C# Language Specification. And from the one or two sections I’ve already read its better than any other book I have read thus far!

Get it HERE

Thanks for Armand for the Link

Blogged with Flock

WCF

Posted in Development
Post date: August 12, 2007

Since my little problem with Circle I cannot make any decent posts concerning Ruby and Ruby on rails so I’m going to continue this month with random little posts about general stuff.

I was speaking to Andre a few months back when he mentioned WCF and I never really looked into it. Recently Rudi Grobler posted a few great links to getting started with WCF. Check out his post here : http://dotnet.org.za/rudi/archive/2007/08/07/using-windows-communication-foundation-wcf.aspx

Blogged with Flock

History within your applications

Posted in Development
Post date: July 25, 2007

Here’s a question to all you hardcore developer people. How important is history in your design of an application.

Lets say for instance, you have a client who has a car and a household on your system. Would it be important to you to be able to see the history of the client at any moment? For me this is a must, but due to an executive decision this will probably never get implemented. We are redesigning the system here so its the perfect time to implement something like this. The only reason I’ve received for not being allowed to implement it, is that the powers that be do not want redundant info in the database.

Its easy to implement though and I feel it is a very important part of any financial system. What are your thoughts?

Blogged with Flock

The Image of IT

Posted in Development, General
Post date: July 9, 2007

So here’s the deal. I’m a developer at an insurance company. We are two full time developers, one full time report writer and then our manager develops whenever he has the time. Now we trying to get a new policy in place whereby users are not just allowed to call us directly. They have to make use of a system called SysAid. Now for those of you that don’t what sysAid is, basically its a small app on which users can log help requests that then gets sent to us. Now that we starting to enforce the use of SysAid a lot of the users are no longer happy.

Whereas they used to phone and whatever was done over the phone, they now need to “pick a number and wait” so that we go through the requests in the order in which we get them. A lot of the users are now complaining that we aren’t working. Which naturally is a load of crap, but we have to now “improve the image of IT in the company”. How the hell do you improve the “image” of a department? out of our approx 250 users in the company, maybe 5 understand what does into effecting a change on a system. Besides maintaining various system we need to develop and maintain more systems!

Here’s typical query: We have two buttons on a form, one says Calculate A and the other says Calculate B. People call us and get all upset because they trying to calculate B and they are in fact clicking Calculate A! Any developer here would laugh at it the first time it happens. but when you deal with problems such as this all day is begins to take its toll! So not only has your train of thought been interrupted by an irate user BUT you now have to spend 5minutes helping them. The second problem we have is people randomly walking into our office for help. Again, 5 - 10 minutes helping them and your train of thought is gone. Now that we enforcing the rule of making use of SysAid, which rocks just BTW, everyone is getting really upset.

How would you improve the “image” of the IT department? Do we throw little parties after work and show them that “we are just like them”? How would you “portray” the amount of work done to different sets of users? We’ve come up blank on this!