Software Development

Building Business Applications with Silverlight 4 & .Net RIA Services

Trusted By

Welcome Back! I hope you enjoy the content on this site. If you have not done so already, you may want to subscribe to my RSS feed or become a fan of this blog on Facebook. Thanks for visiting!

This is a good series of posts from Brad Abrams on building business applications with Silverlight 4 & .Net RIA Services

  1. Starting a New Project with the Business Application Template
  2. Exposing Data from Entity Framework
  3. Consuming Data in the Client
  4. Updating Data
  5. Validating Data
  6. Authentication and Personalization
  7. Silverlight and Search Engine Optimization (SEO)
  8. Exposing OData Services
  9. Exposing WCF (WSDL) Services
  10. Exposing JSON Endpoint - In Progress
  11. Working with Reference Data - In Progress
  12. Deploying to a 3rd Party Hoster (I could not do any better than Saurabh’s post!)
  13. Workflow Integration - In Progress
  14. Management with AppFabric - In Progress
  15. Debugging Tips and Tricks - In Progress
  16. Globalized and Localized 

 

This is great for getting started! My only beef with it is that unfortunately real life scenarios are not that simple.  I would love to see some more depth in these articles. Don’t mean to knock Brad’s work. It’s still better than nothing.

Hope that helps,

Hatim

Metro Application Style coming to Silverlight

The metro application style introduced in the Zune and windows mobile 7 is coming to Silverlight along with some other themes.

image

Isn’t it just gorgeous. Large fonts, simple forms and a simple layout

image

This more conservative look isn’t bad either.

Check out Tim Heuer’s post for the full info.

Sign up for a free trial at audible and get a free audio book from more than 50,000 books. And the best thing is you can keep it even if you decide to cancel after the 14 days trial

5 Tips on using Rapid Application Development (RAD)

As consultants which I believe most of the reader of this blog are, or even if you are a developer working for a software company, time is always of the essence. We are always trying to do more in less time either because we have a tight deadline or to free time to do other things we enjoy.

A concept that is not new is RAD or (Rapid Application Development) promises to let us do just that.

In fact so many software companies have tried many approaches to tackle this problem but unfortunately as it has been said before,  there is no Silver Bullet to beat the monster. There is no one size fits all methodology that can help all ISVs.

What I have seen over the years is that software vendors come up with tools that are either too hard to learn and thus us developers have to climb a pretty steep learning curve just to try them out and see if they are viable for our work environment. I am thinking here of the (Rational Rose Suite, The DSL tools by Microsoft) and so many others. Or on the other hand, they come up with too simple and weak solutions that are OK for small scale applications but that quickly bite the dust when facing large enterprise requirements. The slap on a dataset for each query comes to mind. You can try that with a multimillion records table and see how quickly it crashes!

When we started our company our first client was a large insurance company that needed a web application used by insurance brokers to sell their  products. We had a very tight deadline, and we needed a solid and scalable application that can handle multiple  transactions per second.

Today the system is not just a web application to sell insurance  products, but a full blown insurance system that handles claims, manages billing and also integrates with the company’s accounting system.

Last year we shipped version 3.0 of the online system and haven’t had a bug report since then. So how did we do it?

1. Write a framework

Even with the tight deadline we knew we had to write a solid code base that we can reuse for other projects and also to give us the flexibility to add new modules to the application without too much fuss.

The framework includes:

  • Logging interface
  • Data access helpers to handle transactions, factory to instantiate you DAL services,
  • Exception handling and logging
  • UI base objects and custom controls.

The framework should be optimized for performance and scalability. It has to be fully unit tested. You can think of it as the heart of your application, if it stops beating ..well  your application is dead.

2. Use Code Generation Tools

Back when I was in university I had written data access code generation templates for Code Smith. That’s years before LINQ or the Entity Framework. I just couldn’t bring myself to using DataSets and DataTables when I saw the performance hit when compared to DataReaders and Custom Objects.

Without code generation every time you make a change to your database you have to rewrite the Database access code, mapped objects, services, and UI. Retest everything and hope it works.

With the generated code we only need to change the services and the UI so that’s your work cut in half already.

3. Don’t reinvent the wheel for each project

Yeah I know that new tool or framework is so cool that you have to use it in  your next project. But your customer only sees 3 things in your software:

  • Does it work?
  • Does it address the business requirements?
  • Did you ship on time?

Which framework, or technology you used is the last thing he/she will care about. So stick to what you know. I am not saying you can’t learn new techniques or explore new frameworks, but do that on side projects and don’t use it in your projects until you can answer this questions with confidence: What are the chances I blow this project if I use (insert your new framework here). And your answer is none because I used it on X, Y and Z projects and I master it.

You should also have a viable business argument why you would want to switch to this new framework. Either because it’s going to cut our development time in half, or it offers a better user experience for the client etc…

4. Simple is Always Better

Remember your main goal is to ship a working version of your software while including the most feature you can on time. This doesn’t go along so well with trying to come up with the most clever solution. For example If your application needs to get a CSV file from a webservice and parse it to include those records in the database. You can write that in a few hours. You don’t have to put a BizTalk server to orchestrate all that for you.  you get my drift? Most of the time the simplest solution is the most elegant one and the safest.

5. Modularity

I try to always  break our applications in small modules. Why?

  • We can reuse those components in different project
  • As customer requirements change we have very loosely coupled modules that we can just replace without having to refactor all the code.
  • Give ownership of each module to a team member and thus speed development time.
  • It’s easier to unit test each module.

I am sure I left a few things out so do share your ideas in the comments please.

Looking for a great book on .Net? Pro C# 2010 and the .NET 4.0 Platform, Fifth Edition

Hope this helps,

Hatim

ASP.Net MVC 2 Released

ASP.NET MVC 2 is now available for Visual Studio 2008 and Visual Web Developer 2008 Express with ASP.NET 3.5. You can download and install it from the following locations:

The final release of Visual Studio 2010 and Visual Web Developer 2010 will have ASP.NET MVC 2 built-in – so you won’t need an additional install in order to use ASP.NET MVC 2 with them.

Some of the new features and capabilities include:

  • New Strongly Typed HTML Helpers
  • Enhanced Model Validation support across both server and client
  • Auto-Scaffold UI Helpers with Template Customization
  • Support for splitting up large applications into “Areas”
  • Asynchronous Controllers support that enables long running tasks in parallel
  • Support for rendering sub-sections of a page/site using Html.RenderAction
  • Lots of new helper functions, utilities, and API enhancements
  • Improved Visual Studio tooling support

For more information, see ASP.NET MVC 2 Released.

5 Tips to get the most out of your coding time

I remember seeing an add from Microsoft I believe for hiring programmers and the jist of it was “We give you an office with a door”.

image

Why you might wonder?

Well, it might take up to 20 minutes to refocus on the task at hand after you get distracted either by a phone call, by a coworker barging in or by a video someone posted on Facebook.

I will give you an example of a spiral I used to find myself in. I will be happily hacking at this new feature that we need to ship soon and an email notification shows up for an email that I was cc’ed in so I open the email read it and can’t remember what it  was about so I end up reading the whole thread just to remember. Then I switch to my browser to see if there is anything new in my RSS reader, oh wonder if someone sent me something on Facebook. Off to Facebook I go.

An hour later I am back to visual studio and completely lost the thread to what I was doing. And that’s when bad stuff happens, bugs introduced and things get forgotten.

These are a few tips I use now to keep me focused and get the most out of my work hours.

1. Close your internet browser

As hard as it might seem, learn to open your browser only if you need it to research something related to the task you are doing.

What I like to do is to dedicate a couple hours before I start  coding to research the references I need. So that when I get started it’s only coding and nothing else.

Try it for a week and see how much stuff you get done.

2. Close your mail client / instant messenger

Don’t worry, if something really urgent happens you would know about it. You don’t need to keep your mail client open at all times, and read each email as it arrives.

Think of how many emails you are CC’ed in just for the sake of it and to which you have no say in. And think of how  many hours you waste opening those emails and getting distracted by them and having to refocus on what you were doing before.

Set specific times at which you read your emails. I find just before my lunch break and at the end of the day the best time. I find emails a good way to unwind :). I also end up writing better quality emails instead of the quickly I have to get back to what I was doing mess I used to send to clients.

If you don’t want to close just turn off the notification sounds and status bar alerts.

3. Unhook your phone  (or put it in silent mode)

This follows on the no email theory. I ask all our clients that if something is really urgent to send me an SMS. They almost never do so I let the calls go to voice mail  and I can check it later.

This tip is also good for keeping your clients  happy and show your professionalism,  you wonder how? Well when they leave a voice mail your already know what they want to talk about when you call them back. Say the leave the following message:

Hey Hatim, I wanted to know what’s the status of feature N° 156 and if we are still on for the system update schedule by the end of the week.

What you can do is go find out what the status of that feature, check with your team that everything is good and ready to go for the system update.

The phone conversation will take less time as you won’t have to stall them and scramble while you open your tracking application or IM the person responsible for the feature or your team to see what’s going on.

4. Buy good noise canceling headphones

image

I have a pair of Bose® QuietComfort® 3 Acoustic Noise Cancelling® Headphones. These are great for listening to music and also shields you from all the distractions. Coworkers talking in the hallway, the guy talking loud on his phone, … . They also work I just put them on without anything playing.

A nice plus is that they have great sound quality!

Of course you don’t have to use noise canceling heaphones they are just nice to have, regular headphones will do too, specially with some loud music!! :D

5. Make small and regular breaks

When I am coding I like to have a 5 to 10 minutes break each hour and a half to 2 hours. I either go get a coffee,  talk to a coworker, check voice mail, walk in the hallway. The idea is when I get away from my  screen I can have a better spatial thinking and find new ideas or solutions more easily.

It’s also revigorating and gives you a mental boost when you are working.

Oh I can finish this new screen and have my break.

A great book on how to manage time is Tim Ferris’s “The 4 Hour Work Week” you can get it for free as an audio book if you sign up for a free audible trial or if you prefer you can get the dead tree version.

I hope this was helpful and would to would love to hear if you have any tricks and stratagems to keep your self focused.

Hatim

How to Drop All Relations in A Database

this is related to my earlier post on dropping all indexes from an sql database but this one is to delete all foreign key relations from a database.

set nocount on
 declare @statements cursor
 set @statements = cursor static for
 select  'alter table ' + quotename(ctu.table_schema) + '.' + quotename(ctu.table_name) +
         ' drop constraint ' + quotename(cc.constraint_name)
 from  INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS as cc
          join INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE as ctu
           on cc.constraint_catalog = ctu.constraint_catalog
              and cc.constraint_schema = ctu.constraint_schema
              and cc.constraint_name = ctu.constraint_name

 open @statements
 declare @statement nvarchar(1000)
 While  (1=1)
  begin
         fetch from @statements into @statement
                if @@fetch_status <> 0
                 break
                exec (@statement)
         end

 

Hope this was Helpful!

Hatim

How To Drop All Indexes From A Database

I was doing some performance tweaking of a batch job that was hanging and i was suspecting the indexes in the database to have something to do with it shocking up so I used this script to clear all indexes.

Ironically it was a missing index that caused the bottleneck. But here it is for anyone that might need it.

DECLARE @indexName VARCHAR(128)
DECLARE @tableName VARCHAR(128)

DECLARE [indexes] CURSOR FOR

    SELECT        [sysindexes].[name] AS [Index],
            [sysobjects].[name] AS [Table]

    FROM        [sysindexes]

    INNER JOIN    [sysobjects]
    ON        [sysindexes].[id] = [sysobjects].[id]

    WHERE        [sysindexes].[name] IS NOT NULL
    AND        [sysobjects].[type] = 'U'

OPEN [indexes]

FETCH NEXT FROM [indexes] INTO @indexName, @tableName

WHILE @@FETCH_STATUS = 0
BEGIN
    PRINT 'DROP INDEX [' + @indexName + '] ON [' + @tableName + ']'

    FETCH NEXT FROM [indexes] INTO @indexName, @tableName
END

CLOSE        [indexes]
DEALLOCATE    [indexes]
 
 

Hope this was helpful!

Hatim

6 Of My Favorite Visual Studio Shortcuts

These are some of my favorite and most used shortcuts in visual studio:

  1. Ctrl + - and the opposite Ctrl + Shift + -  To move the cursor back or forward to the last position without having to scroll or switch  files.
  2. Shift+Alt+Enter Switches to Full Screen Mode
  3. Ctrl+K, Ctrl+C Comment a block,   Ctrl+K, Ctrl+U Uncomment the block
  4. Shift + Alt + F10 then Enter expands the smart tag to insert a using statement or implement an Interface
  5. Ctrl+K, Ctrl+D Auto format the file (Source, xml or  html)
  6. Ctrl+M, Ctrl+ O Collapses all outlining to  definition and then Ctrl+M, Ctrl+M to toggle the current block to expanded or collapsed.

What about you what are your favorites. I would like this post to become a repository for the most used Visual Studio Shortcuts. So do share

Hope This Helps!

Hatim

Building Amazing Business Applications with Silverlight 4, RIA Services and Visual Studio 2010

A great tutorial by Brad Abrams about building business applications using Silverlight, RIA Services and Visual Studio 2010

10 Not So Well Known Keywords in C#

Ok before the flaming start let me state this. These are known to most hardcore programmers and not knowing them doesn’t make you less of a programmer either.

That said these keywords can come in handy and allow for better code quality and readability. Enjoy!

yield

The yield keyword signals to the compiler that the method in which it appears is an iterator block. The compiler generates a class to implement the behavior that is expressed in the iterator block. In the iterator block, the yield keyword is used together with the return keyword to provide a value to the enumerator object. This is the value that is returned, for example, in each loop of a foreach statement. The yield keyword is also used with break to signal the end of iteration.

example:

  public classList
 
{
       //using System.Collections;
     
public static IEnumerable Power(int number, int exponent)
       {
           int counter = 0;
           int result = 1;
           while(counter++ < exponent)
           {
               result = result * number;
               yield returnresult;
           }
       }

       static void Main()
       {
           // Display powers of 2 up to the exponent 8:
         
foreach (int i inPower(2, 8))
           {
               Console.Write("{0} ", i);
           }
       }
   }
   /*
   Output:
   2 4 8 16 32 64 128 256
   */

msdn reference: http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx

var

Beginning in Visual C# 3.0, variables that are declared at method scope can have an implicit type var. An implicitly typed local variable is strongly typed just as if you had declared the type yourself, but the compiler determines the type.

An application running on version 2.0 can also use the var keyword in their code as long as it’s compiled with 3.0 or up and set to output to 2.0.

example:

var i = 10; // implicitly typed

int i = 10; //explicitly typed

msdn reference: http://msdn.microsoft.com/en-us/library/bb383973.aspx

using()

Defines a scope, outside of which an object or objects will be disposed.

example:

using (C c = new C())

{

    c.UseLimitedResource();

}

msdn reference: http://msdn.microsoft.com/en-us/library/yh598w02%28VS.80%29.aspx

readonly

The readonly keyword is a modifier that you can use on fields. When a field declaration includes a readonly modifier, assignments to the fields introduced by the declaration can only occur as part of the declaration or in a constructor in the same class.

msdn reference: http://msdn.microsoft.com/en-us/library/acdd6hb7%28VS.80%29.aspx

as

The as operator is like a cast operation. However, if the conversion is not possible, as returns null instead of raising an exception. 

example:

class Base

   
{ public override string ToString()

        {

            return "Base";

        }

    }

    class Derived : Base

   
{ }

    class Program

   
{

        static void Main()

        {

            Derived d = new Derived();

            Base b = d as Base;

            if (b != null)

            {

                Console.WriteLine(b.ToString());

            }

        }

    }

msdn reference: http://msdn.microsoft.com/en-us/library/cscsdfbt.aspx

is

Checks if an object is compatible with a given type.

An is expression evaluates to true if the provided expression is non-null, and the provided object can be cast to the provided type without causing an exception to be thrown.

The is keyword causes a compile-time warning if the expression is known to always be true or to always be false, but typically evaluates type compatibility at run time.

The is operator cannot be overloaded.

example:

class Class1{ }

classClass2{ }

classClass3: Class2{ }

classIsTest

  
{

        static voidTest(objecto)

        {

            Class1a;

            Class2b;

            if(o isClass1)

            {

                Console.WriteLine("o is Class1");

                a = (Class1)o;

                // Do something with "a."

           
}

            else if (o is Class2)

            {

                Console.WriteLine("o is Class2");

                b = (Class2)o;

                // Do something with "b."

           
}

            else

           
{

                Console.WriteLine("o is neither Class1 nor Class2.");

            }

        }

        static void Main()

        {

            Class1 c1 = new Class1();

            Class2 c2 = new Class2();

            Class3 c3 = new Class3();

            Test(c1);

            Test(c2);

            Test(c3);

            Test("a string");

        }

    }

    /*

    Output:

    o is Class1

    o is Class2

    o is Class2

    o is neither Class1 nor Class2.

    */

msdn reference: http://msdn.microsoft.com/en-us/library/scekt9xw.aspx

default

    n generic classes and methods, one issue that arises is how to assign a default value to a parameterized type T when you do not know the following in advance:

    • Whether T will be a reference type or a value type.

    • If T is a value type, whether it will be a numeric value or a struct.

    Given a variable t of a parameterized type T, the statement t = null is only valid if T is a reference type and t = 0 will only work for numeric value types but not for structs. The solution is to use the default keyword, which will return null for reference types and zero for numeric value types. For structs, it will return each member of the struct initialized to zero or null depending on whether they are value or reference types. For nullable value types, default returns a System.Nullabe<T>, which is initialized like any struct.

    example:

    T temp = default(T);

    msdn reference: http://msdn.microsoft.com/en-us/library/xwth0h0d.aspx

    global

    The global contextual keyword, when it comes before the :: operator, refers to the global namespace, which is the default namespace for any C# program and is otherwise unnamed.

    example:

    class TestClass : global::TestApp { }

    msdn reference: http://msdn.microsoft.com/en-us/library/cc713620.aspx

    volatile

    The volatile keyword indicates that a field might be modified by multiple concurrently executing threads. Fields that are declared volatile are not subject to compiler optimizations that assume access by a single thread. This ensures that the most up-to-date value is present in the field at all times.

    msdn reference: http://msdn.microsoft.com/en-us/library/x13ttww7%28VS.80%29.aspx

    extern alias

    It can sometimes be necessary to reference two versions of assemblies that have the same fully-qualified type names, for example when you need to use two or more versions of an assembly in the same application. By using an external assembly alias, the namespaces from each assembly can be wrapped inside root-level namespaces named by the alias, allowing them to be used in the same file.

    To reference two assemblies with the same fully-qualified type names, an alias must be specified on the command line, as follows:

    /r:GridV1=grid.dll

    /r:GridV2=grid20.dll

    This creates the external aliases GridV1 and GridV2. To use these aliases from within a program, reference them using the extern keyword. For example:

    extern alias GridV1;

    extern alias GridV2;

    Each extern alias declaration introduces an additional root-level namespace that parallels (but does not lie within) the global namespace. Thus types from each assembly can be referred to without ambiguity using their fully qualified name, rooted in the appropriate namespace-alias

    In the above example, GridV1::Grid would be the grid control from grid.dll, and GridV2::Grid would be the grid control from grid20.dll.

    msdn reference: http://msdn.microsoft.com/en-us/library/ms173212%28VS.80%29.aspx

     

    Hope this helps!

    Hatim