Welcome to SpellCoder Sign in | Join | Help

Bashmohandes Blogs has moved!

Hey,
I have moved my blogs to MSDN blogs, so if you are interested in following up, update your address book, RSS reader or anything else with the new address
http://blogs.msdn.com/bashmohandes
Or you can use
http://www.Bashmohandes.com

Thanks for spellcoder for hosting my blogs for the last 2 years :)

My longest two weeks ever

Hey, It's been a while since my last blog post, I was somehow busy getting married, moving to another country, dealing with tons of paper work, however finally I had a weekend, and I am back to blogging, I have a lot to say, and I think it will be interesting enough for you to keep reading till the end

So basically this is what I am going to blog about today

  1. Last days in Cairo
  2. Moving to Canada & Vancouver City
  3. Microsoft Canada Development Center (MCDC)
    1. First Days
    2. MCDC Cares Day

Last days in Cairo

The past two weeks started with my wedding arrangement and God, this is very exhausting, lots of stuff to deal with, writing a guest list, however Thanks to Facebook I didn't have to call everybody, and the result I came out of the wedding experience is, my kids whatever their IQ will be, they will have one of two options in their career life, either being a wedding planner or a hair dresser and/or make up artist.

The wedding was nice, it was a very nice opportunity for me to see everybody before being relocated to Canada, I really thank everyone for showing up that night, I was really proud of my friends.

Moving to Canada & Vancouver City

Couple of days after my wedding I was in the plane with my wife heading to Vancouver, we had a 20 hours journey from Cairo, we had a connection in London, the flight went smooth and very nice, however my back hurts when I recall sitting for 10 hours from London to Vancouver.

Once we arrived to Vancouver, we took a cab to our temp house, the first thing I noticed the high-tech cabs, the cab has a GPS with maps for the city, and also a very interesting fare counter, the counter was moving like a stop watch, even when the cab wasn't moving, the counter continues to move, the ride from the Airport to the temp house, which took around 15 mins cost about 27 CAD.

The city is wonderful, the streets are clean, nice and easy to learn, people are extra friendly, both cars and people are moving according to traffic rules, this is quite interesting for anyone coming from a country like Egypt :)

The temp house is in a very nice area, Map, I am in the 29th floor, so I have an amazing view of the sea and the mountains.

My first couple of days were very hard, because of the electricity here in Vancouver, the problem that the voltage range here is 100~110, while Egypt is 200~220 so many devices I had didn't work, also I found the strange outlet in the wall, which is different from the Egyptian outlets, so all devices like Laptops, Mobiles ... etc went out of charge during the first couple of days, I had to find a store where I can buy some adapters, in these days I felt like stone age, no mobile phones, no computers, no Internet, how could we live 15 years before today, Once I got the adapters I could communicate with my friends who arrived in Vancouver city couple of days before me (Haytham, Mustafa and Abdullah)

Also a nice tip, when I was changing money from Egypt, CAD was cheaper than USD, in Vancouver, CAD is higher than USD, so I lost some money when I exchanged some USD to CAD here in Vancouver.

Live/Google maps works great in Vancouver, and all Canada area, providing great help for directions and finding addresses, Google Maps though has a nice feature to give direction in public transit, so you can see which busses you'll need to take and at what time.

Microsoft Canada Development Center


In the picture from left, Abdullah, Mostafa and Me


In the picture from left, Abdullah, Mustafa and Haytham 

Here comes the first day @ Microsoft, the first day started in a park nearby Microsoft, the day started with some introductory sessions about Microsoft Canada, and Microsoft future of Computing, and the future vision of MS.

After couple of hours we went to MCDC, we had a nice tour around the facility, the place is very amazing, simple and fun, some parts still under construction.

People there are from everywhere, it is like a small united nations, Egyptians are all over the place and we are increasing, in our batch there was 7 Egyptians out 31 new hires, this is quite nice number.

Then after the tour we had another session about the needed paperwork, lots of forms to fill, I had to write my name about 50 times later this night when filling in the forms, then we head to our offices.

My office is in Building 3, Office 1077B, I am sharing the same office room with Mostafa, every dev is using two machines, one for web surfing, email, IM, ... etc and the other for development, the machines are GREAT, I even found people working in triple machine setup according to their work needs.

 

In the first day my manager called me from Redmond, I IMed the other team mates, I found out that I am the only dev outside Redmond in my team.

During the first days, we were all busy finishing the paperwork, we didn't start working yet, however in the forth day we had a great experience.

MCDC Cares

Since our first day, we were asked to join this event, the event called MCDC Cares, is a community work program that Microsoft will help the Richmond city in building a 700ft long boardwalk in Richmond Park, the idea is that this part of the park is very muddy that no visitors can get inside, so Microsoft decided to help in building this boardwalk by providing manpower (150 computer geeks) for a whole day.

So early on May 15th, all Microsoft Canada Development Center gathered in the cafeteria where Parminder (Par) Singh, the Managing Director of MCDC gave a short speech to everybody


In the picture Parminder Singh

After this we all moved to the park, the park is quite big, it was my first time to actually feel being in the woods, were the trees are very high and land is either very green or very muddy.

In this picture the completed part of the boardwalk we were about to complete, the  boardwalk goes very deep into the woods.

So first things first, we had to move 1500 pieces of wood from the parking area outside the park to the working place deep into the woods, about 800m distance, this part of the job took around 4~5 hours.

After this phase we had a lunch break and during this break

Then phase 2 started, the phase 2 was to nail the 1500 pieces of wood we moved in phase 1 with 6 nails per piece, so in a period of 3 hours we had to hummer about 9000 nails manually.

Then we head back to MCDC, very exhausted but very happy with the work we've done, this boardwalk will be there for ages, and this was a very nice opportunity to do something useful.

In MCDC we had a BBQ party for everyone so the day ended pretty much after the BBQ, then I believe that everybody slept like a baby for more than 9 hours :)

Here you can find the TV coverage of MCDC Cares day

If you read this line so you survived the whole blog post, thank you for reading this, I will be blogging again & again, so keep in touch :)

posted by Mohammed Hossam | 13 Comments
Filed Under:

Windows Live Mesh

Microsoft has just launched a new Windows Live service called Live Mesh, the service is still in Tech Preview, which means a limited number of users (10,000) and a waiting list for the extra users, the whole concept of this service is synchronizing all devices (PC's, Laptop, Mobiles, ... etc) as long as all of them are running any version of Windows.

If you watched Ray Ozzie keynote in Mix last March, he pointed to the Live experience, and I think this product is one a new series of products in this direction.

This strategy shift was also mentioned on TechCrunch from Ray Ozzie memo to employees

Central to this strategy is our embrace of both a world of the web and a world of devices. Over the past ten years, the PC era has given way to an era in which the web is at the center of our experiences – experiences delivered not just through the browser but also through many different devices including PCs, phones, media players, game consoles, set-top boxes and televisions, cars, and more.

Read the whole memo here

SOA via WCF in CuttingEdgeClub (ITWorx)

Hey, I will be giving a presentation in ITWorx CuttingEdgeClub, the presentation is similar to the one I did in SKDD II (SOA via WCF), however I will add to it more slides about REST, ROA and WCF Restful services, I wish it becomes more exciting and interesting.

Here is the poster Thanks to Mostafa Mourad :)

Technorati Tags: ,,,

A good DotNetWork gathering

Hey,

Yesterday (Saturday, March 22nd) DotNetWork user group had its 3rd gathering, Meligy & I had the opportunity to present in this day, Meligy did a "Scrum for Developers" and I did "Windows Workflow Foundation", the day was nice, I enjoyed being with geeks as usual, I met some of my friends, and that's the most important thing.

My WF session wasn't very primitive as I hate these hello world sessions, but it wasn't an advanced one as well,

you can find the slides and samples here

If you attended the session and have any feedbacks please comment here, I need your feedbacks, it is important to me.

Internet Explorer 8 Beta 1

IE8 Beta has just been released few hours ago, click here to download

Have fun

posted by Mohammed Hossam | 1 Comments
Filed Under: ,

SilverLight on Nokia Mobiles

I found this interesting article that says Nokia has announced that SilverLight will be available for Nokia S40 & S60 phones, also this will be one of the topic in which MIX keynote is going to discuss.

This opens a new play ground of competitiveness between Flash & SilverLight, also it shows that SilverLight is going down the road to the offline applications competing with Adobe Air.

Technorati Tags: ,

Parallel Extensions

Last Thursday, we had an internal Demo Day in SilverKey, I had the opportunity to introduce the new Parallel Extensions, it was a nice topic and I enjoyed presenting it, I hope the audience enjoyed listening to it :)

I was just about to blog the whole presentation, till I noticed this GREAT article about Parallel Extensions, it covers almost the whole set of API's, so I will recommend it for reading instead of rewriting the same info.

Parallel Extensions to .Net Framework

Enjoy

Technorati Tags: ,,
posted by Mohammed Hossam | 0 Comments
Filed Under: ,

Add-In Libraries in .net 3.5

Tamer has just told me this news.

This is quite good news for people and bad news for me, the good news that in .net 3.5 there is a built-in support in the Base Class Libraries for Add-In or (Plugins or Extensions) framework, so in other words whenever you feel the need to provide an extension support you can just use the bunch of classes under System.AddIn.

You can find more information about it in the CLR Add-In team blogs

So Why it is a bad news for me?!

I have invested so much time in building one, I had the first version of it in .net 2.0 (so no problem), but I've rewritten it for version 2.0 which happen to be after the .net 3.5.

I blogged about that before check

How to Increase Application Scalability Using Plugins

I will invistigate these new bits, and I will blog about them for sure.

Technorati Tags: ,,,
posted by Mohammed Hossam | 0 Comments
Filed Under: ,

Bashmohandes @ Microsoft

Hey, great news, I will join Microsoft Windows Live Team soon, as Software Development Engineer SDE in Microsoft Canada Development Center, I will be relocating to Vancouver within the next months, I am still in the legal papers preparation period, wish me luck with governmental issues

I am very very excited to join, I had a great experience during interview process, I will be blogging about this for sure, but for now just wish me luck

I will be missing the folks in SilverKey, I will miss the chats in the kitchen, the Wii boxing tournaments, it was such a great experience to work with SK from day 1 till now...

Pray for me, I will need your prayers :)

Awesome Egypt Software Industry Statistics

I participated a month ago in a survery for Egyptian Software Industry made by Mohammed Nour, the survery was an independent attempt towards getting accurate information about Software Indusrty market in Egypt, as this industry is the fastest growing in Egypt.

Mohammed Nour has just published the detailed statistics result document on his blogs, Check Here. The document is amazingly simple to understand, and organized and provide very accurate information that might surprise you.

I think he is planning for another attempt to collect information about some other areas he didn't cover in this survery (as he mentioned in the end of the document).

C#.Next, What do you expect?

I have been searching for any clue about the next version of C# and what the features to be included, and I finally found something on Charlie Calvert's blog.

The Dynamic Lookup, a.k.a Late Binding, this feature will be great in the interoperability between DLR languages and C#, COM interoperability, and also in the Reflection Scenarios.

This is how it suggested to look like, this syntax is not yet finalized.

static void Main(string[] args)
{
    dynamic
    {
        object myDynamicObject = GetDynamicObject();
        myDynamicObject.SomeMethod();         // call a method   
        myDynamicObject.someString = "value"; // Set a field
        myDynamicObject[0] = 25;              // Access an indexer
    }
}


So this adds a new keyword to the language (dynamic) which is another scope where the compiler is not looking up for methods & properties in compile time, and the runtime will do this job.

This code can already be written today using reflection and searching for the right method and invoke it, this is much cleaner and the dynamic scope idea is nice as it fits well with the C# syntax scheme.

So by the time next version of C# ships, the C# language will have a very wide spectrum of programming models, starting from unsafe direct memory pointers to dynamic late binding.

kick it on DotNetKicks.com
posted by Mohammed Hossam | 0 Comments
Filed Under: ,

C# 3.0 Properties Acessor Tips

If you are familiar with C# 3.0, you would already noticed the new shortcut for defining a property without the need to declare the variable behind the property, so for creating a property called Length, all what you have to do is write it like this.

public int Length { get; set; }

 

This is cool as most of our classes contains bunch of properties and this saves sometimes and also it makes the intellisence list of members much shorter, but this is not the whole thing, what if you want to declare a property with a private setter and public getter?

Here comes a cool part :)

public int Length { get; private set; }

 

Now the Set operation is only accessible inside the class, you can also do stuff like protected, internal for either the set and get, or even remove one of them.

I know that this post sounds a bit old, but I felt it funny when I read the private keyword at the middle of the line :)

Using WebHttpBinding & JSON Support in WCF

I had some cool time working with WCF new features shipped with .net 3.5, one of the most ineteresting and useful features is the JSON support and how easy you can enable the JSON support for your current WCF services by changing the configurations.

Why do we need JSON support?

Well, JSON (JavaScript Object Notation) is very suitable for building ajax based applications for some reasons.

  1. The other popular alternative (XML) requires parsing code in the client side to extract the data from the document, which is not the best thing to do using Javascript.
  2. XML documents size are relatively bigger than JSON documents containing the same data

To get more info about JSON check here and here

What WCF offers to support JSON

All what you need is doing two things

  1. Create an end point that uses the new binding (WebHttpBinding)
  2. Configure the end point behavior and enabling the WebScript (which will generate a javascript proxy for your service contract and data contracts)

This is a sample configuration

<system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="ChatAspNetAjaxBehavior">
          <enableWebScript/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <services>
      <service name="ChatService">
        <endpoint address="" behaviorConfiguration="ChatAspNetAjaxBehavior" 
                binding="webHttpBinding" name="ajaxEndpoint" contract="IChat"/>
      </service>
    </services>
  </system.serviceModel>

As you can see the endpiont configuration is using the Binding "webHttpBinding" and it is also configured in the behavior tag to enable web script.

Now the WCF runtime will generate a javascript proxy containing all services and data contracts as javascript classes, we will see an example shortly.

Example: Building a Chat Application using WCF & JSON support

It is time for more detailed example, in this example we will develop a small web based chat application using javascript as a client language and WCF as a server side.

The chat application will be able to do these functionalities

  1. Register users
  2. User logins
  3. Retrieve users list
  4. Check new messages
  5. Send message
  6. Log out

So let's write down the contract for this service (we will ignore good design practices for the sake of simplicity and will make one service that does both the user management and chatting)

[ServiceContract(Namespace = "")]
public interface IChat
{
    [OperationContract]
    User Register(string username, string password);
 
    [OperationContract]
    User Login(string username, string password);
 
    [OperationContract]
    bool Call(Guid fromUserId, string toUsername, string message);
 
    [OperationContract]
    Message[] GetMyMessages(Guid userId);
 
    [OperationContract]
    bool SignOut(Guid userId);
 
    [OperationContract]
    User[] GetUsers();
}

 

This is basically how the service contract looks like, we are still missing two data contracts User & Message and here they are.

[DataContract]
public class Message
{
    [DataMember]
    public Guid ID { get; set; }
    [DataMember]
    public string Body { get; set; }
    [DataMember]
    public DateTimeOffset Date { get; set; }
    [DataMember]
    public string FromUsername { get; set; }
 
    public Message()
    {
        ID = Guid.NewGuid();
        Date = DateTimeOffset.Now;
    }
}
 
[DataContract]
public class User
{
    [DataMember]
    public Guid ID { get; set; }
 
    [DataMember]
    public string Username { get; set; }
 
    public string Password { get; set; }
 
    public User()
    {
        ID = Guid.NewGuid();
    }
}

The implementation of the service is not very important and the code is attached with the blog entry, basically it saves all the messages and users in static collections, in real life cases the implementation will be different most probably a database is going to be used.

Now let's start building the client side of the chat application.

We will be hosting the chat service on IIS so we will create a .svc file chat.svc which will contain one line

<%@ ServiceHost Language="C#" Debug="true" Service="ChatService" CodeBehind="~/App_Code/Chat.cs" %>

And this will be the address of our service.

and then we will place the configuration of the service in web.config

1: <system.serviceModel>
2:   <behaviors>
3:     <endpointBehaviors>
4:       <behavior name="ChatAspNetAjaxBehavior">
5:         <enableWebScript/>
6:       </behavior>
7:     </endpointBehaviors>
8:   </behaviors>
9:   <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
10:   <services>
11:     <service name="ChatService">
12:       <endpoint address="" behaviorConfiguration="ChatAspNetAjaxBehavior" 
13:         binding="webHttpBinding" name="ajaxEndpoint" contract="IChat"/>
14:     </service>
15:   </services>
16: </system.serviceModel>

The configuration is similar to the above one, except for the line #9 which is the serviceHostEnvironment, all what you need to know about this attribute that enabling it will make asp.net treats the WCF service as regular asmx service, for more details about different modes of running WCF services with ASP.net check this article

We will now create two views

  1. Login View
  2. Chat View

The login view is basically like this

Two text boxes (txtUsername, txtPassword) and two input type buttons for register and login actions

The Chat View will look like this

Which contains two more textboxes (txtToUsername, txtMessage) and a select control containing the current users (slGuests) and a panel that will show the message history (pnlMessageHistory)

May be it is not the best user interface but it will do the basic things.

now we will need to add the ScriptManager to the page and add a reference to the wcf service

1: <asp:scriptmanager id="scrptMgr" runat="server">
2:     <services>
3:         <asp:servicereference path="~/Chat.svc" />
4:     </services>
5: </asp:scriptmanager>

This will add a script element with a source pointing to this url http://[domain]/Chat.svc/js which will download the javascript proxy code.

We will now do some initialization codes let's see how it looks like...

1: var user;
2: var chatService = new IChat();
3: var guests = new Array();
4: window.onload = function(){
5:     var btnRegister = $get("btnRegister");
6:     $addHandler(btnRegister, "click", doRegister);
7: }

 

Let's check line #2, this is the neat part of using WebScript, the IChat class is the generated proxy object for the IChat service contract, and for this application we need only one object so the object is created and initialized globaly.

Now let's write the register function

1: function doRegister()
2: {
3:     var username = $get("<%=txtUsername.ClientID %>").value;
4:     var password = $get("<%=txtPassword.ClientID %>").value;
5:     chatService.Register(username, password, onRegisterSuccess);
6: }
7:  
8: function onRegisterSuccess(result)
9: {
10:     if(result != null)
11:     {
12:         user = result;
13:         var btnRegister = $get("btnRegister");
14:         btnRegister.value = "Sign Out";
15:         $clearHandlers(btnRegister);
16:         $addHandler(btnRegister, "click", doSignOut);
17:         var btnLogin = $get("btnLogin");
18:         btnLogin.style.display = "none";
19:         $get("<%=txtUsername.ClientID
            %>").disabled = true;
20:         $get("<%=txtPassword.ClientID
            %>").disabled = true;
21:         $get("divChat").style.display = "inline";
22:         setTimeout(doCheckMessages, 1500);
23:     }
24:     else{
25:         alert('Error!');
26:     }
27: }

 

the doRegister function is calling the Register method defined in the IChat service contract, you will notice a nice feature that VS intellisence is working nice in this part

All the proxy function will have the same parameters defined in the contract, but because of the nature of the asynchronous call, all the functions will add three extra parameters (onSuccessCallback, onFailureCallback, userContext)

The onSuccess callback is very important, as this where you will get to know the return value (if any), and also where you can say that the server finished working on the request, so in the Register example, in the onRegisterSuccess if the user is created, the Login view is disabled and the Chat view is displayed, also an important part is a timer configured for polling the server for new messages, and the timer is called once every 1.5 seconds, and the result parameter to the onRegisterSuccess function is the return value of the Register method on the IChat service, which in our case it is either a User object or null, if the user object is returned it is saved to the global variable user.

Now let's see when we send a new message to a certain user

1: function doSend()
2: {
3:     var pnlHistory = $get("<%=pnlMessageHistory.ClientID %>");
4:     var txtMessage = $get("<%=txtMessage.ClientID %>");
5:     var txtTo = $get("<%=txtToUsername.ClientID %>");
6:     pnlHistory.innerHTML += "<b>" + user.Username + " says:</b><br>" + txtMessage.value + "<br>";
7:     chatService.Call(user.ID, txtTo.value, txtMessage.value, onSendSuccess);
8: }
9:  
10: function onSendSuccess(result)
11: {
12:     var txtMessage = $get("<%=txtMessage.ClientID %>");
13:     txtMessage.value = "";
14: }

The send message function will call the Call function on the service, and also writes down the message details on the message history panel.

The callback of this function is simply clears the message textbox.

Now when you send a message to someone else, the message is temporarily saved on server till the recipient user queries the server for his messages, this logic is done through a client side timer.

1: function doCheckMessages()
2: {
3:     chatService.GetMyMessages(user.ID, onCheckMessagesSuccess, onCheckMessagesFail);
4:     chatService.GetUsers(onGetUsersSuccess);
5: }
6:  
7: function onCheckMessagesSuccess(result)
8: {
9:     if(result == null)
10:         return;
11:     var pnlHistory = $get("<%=pnlMessageHistory.ClientID %>");
12:     for(var i=0; i<result.length; i++)
13:     {
14:        pnlHistory.innerHTML += "<b>" + result[ i].FromUsername + " says:</b><br>" + result[ i].Body + "<br>"; 
15:     }
16:     setTimeout(doCheckMessages, 1500);
17: }
18:  
19: function onCheckMessagesFail(err)
20: {
21:     alert(err.message);
22:     setTimeout(doCheckMessages, 1500);
23: }

 

The doCheckMessages function does two things, first it checks for the new messages from server, and the other thing is checking for new users in the chat.

the onCheckMessagesSuccess is reading all the messages in the result array of messages, and print them out on the message history with proper format, and then it initialzes the timer again.

This is typically how the chat will look like

Summary

In today's entry I was giving a small overview of one of the new features introduced in WCF 2.0 (.net 3.5) which is WebScript and JSON support, this feature allowed us to create a rich web based application using only Javascript as a client code, we also developed a simple Chatting application to prove the concept and the code is attached with this post for further information and details.

Have a nice day.

Technorati Tags: ,,,,
posted by Mohammed Hossam | 7 Comments
Attachment(s): Chat.zip

A nice quote from Code Complete

This was written as a side note in Code Complete Chapter Three
"Requirements are like water, it is easier to build on them when they are frozen"

posted by Mohammed Hossam | 4 Comments
Filed Under:
More Posts Next page »