Synchronising two folders using Microsoft Sync Framework using less than 10 lines of code

I remember that long time ago I wrote my own synchronisation class in order to sync folders for the needs of a project I was working on. I'm sure many of you have done something similar. Like me, maybe some of you even enjoyed writing that code. But now Microsoft Sync Framework is here! And the job is sooooo easy! Take a look at the code:

var provider1 = new FileSyncProvider(@"C:\Temp\FolderA"); var provider2 = new FileSyncProvider(@"C:\Temp\FolderB"); provider1.DetectChanges(); provider2.DetectChanges(); var agent = new SyncOrchestrator {     LocalProvider = provider1,     RemoteProvider = provider2,     Direction = SyncDirectionOrder.DownloadAndUpload }; agent.Synchronize();

What is Microsoft Sync Framework?

From MSDN: A comprehensive synchronization platform that enables collaboration and offline access for applications, services, and devices with support for any data type, any data store, any transfer protocol, and any network topology.

Permalink | Leave a comment  »

Windows Azure Boot Camp Webcast series - Cloud is in the air

If you are an IT guy, whether a developer or not, you must have heard something about the "Cloud". Don't you think it is about time to get into it more thorougly!? If you are indeed a developer, here is something to help you start. This is a series of web casts that started last week and will be completed until February.

11/29: MSDN Webcast: Azure Boot Camp: Introduction to Cloud Computing and Windows Azure

12/06: MSDN Webcast: Azure Boot Camp: Windows Azure and Web Roles

12/13: MSDN Webcast: Azure Boot Camp: Worker Roles
01/03: MSDN Webcast: Azure Boot Camp: Working with Messaging and Queues

01/10: MSDN Webcast: Azure Boot Camp: Using Windows Azure Table

01/17: MSDN Webcast: Azure Boot Camp: Diving into BLOB Storage

01/24: MSDN Webcast: Azure Boot Camp: Diagnostics and Service Management

01/31: MSDN Webcast: Azure Boot Camp: SQL Azure

02/07: MSDN Webcast: Azure Boot Camp: Connecting with AppFabric

02/14: MSDN Webcast: Azure Boot Camp: Cloud Computing Scenarios

And here is also the upcoming Firestarter event:

12/09: MSDN Simulcast Event: Windows Azure Firestarter

Permalink | Leave a comment  »

Super fast WCF Services Activation - The Riders of the Lost Thread

Whenever I speak or write about WCF, I never forget to say how configurable it is and how much its long exception messages help when you are doing something wrong. However if you try to really push it to get really great performance under heavy request load, you will bump to a number of issues that need special care. In this post I will try to enumerate each one of them and hopefully at the end you will know how to get really fast activation of a service when hit by hundreds of concurrent requests.

The scenario
You have 300 clients hitting the same WCF service concurrently (or just one client that hits the service using 300 separate but concurrent threads). Your service runs using net.tcp binding and is hosted either under a standard windows process or IIS. We choose to use net.tcp because it is the recommended binding for the communication of two processes running under .net and on different machines. All issues bellow apply also to net.pipes, which can be used only if the two processes, client and server, rely on the same machine.
Warning!
The goal of this article is to guide through the process of achieving super fast service activation and not necessarily make your application run faster! This is a more complicated process which requires many other issues to be considered. Also I will not talk about implications of opening and running many concurrent threads.

Step 1 - Behavior configuration and throttling (server side only)
You need to start by configuring your service behavior in order to allow the many concurrent sessions, instances and calls. Here is one such configuration:
<behavior name="MyServiceBehavior">   <serviceThrottling maxConcurrentCalls="350" maxConcurrentSessions="350" maxConcurrentInstances="350" /> </behavior> 
You can read more about service throttling here and here. In brief, if you are using single instance service (use of this attribute on your service class [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]) you do not care about maxConcurrentInstances, since you are using only one anyway. If you are using session-less service you do not care about maxConcurrentSessions, since you are not using sessions anyway. For sure you care about maxConcurrentCalls. Configure these values with numbers greater than the number of concurrent calls you are expecting.

Step 2 - Binding configuration and max connections (server and client side)
When you use net.tcp binding you need to configure the maximum connections as follows:
<netTcpBinding>   <binding name="Default" maxConnections="300" listenBacklog="300"> </netTcpBinding>
What do these settings mean? (pasted from MSDN documentation) maxConnections setting controls the maximum number of connections to be pooled for subsequent reuse on the client and the maximum number of connections allowed to be pending dispatch on the server. listenBacklog setting controls the maximum number of queued connection requests that can be pending.

Step 3 - Max connections, port sharing and IIS (server side only - Warning!!! Read even if you think that you are not using port sharing)
Although you will find dozens of articles, blog posts and samples regarding previous steps, you will not find easily information on how port sharing can affect your service. What is port sharing? .NET has a windows service called 'Net.Tcp Port Sharing Service' which allows sharing a single port among many processes. This way you can have two processes running and listening to the same port. Port sharing service will filter incoming requests and forward them to the correct service instance depending on the full url each one listens to. If you need this feature, you can enable it using the portSharingEnabled setting on your binding configuration.
However, even if you don't need it, you have to bear in mind that if you are hosting net.tcp services under IIS you are using port sharing even if you do not configure it! This is the only way IIS can host all your net.tcp services under the same port (by default this is 808).
So how does port sharing affects the performance of our service? Port sharing service has it's own configuration file which overrides some of the settings we mentioned above. To find this file go to your Local Services snap-in from your control panel and look for the "Net.Tcp Port Sharing Service". Right click on it, click Properties and look at the "Path to executable". Open that path using Windows Explorer and look for the SMSvcHost.exe.config. This is the file we are looking for. Don't mind if you find that this path of the file does not match the .NET Framework version you are using. This service is common for all framework versions since you may want to share one port in processes using different versions. Open this file and edit it. Here is one recommended configuration:
<net.tcp listenBacklog="300" maxPendingConnections="300" maxPendingAccepts="300"/>
Do not forget to restart the service.

Step 4 - Thread pool configuration
WCF utilizes thread pool in order to create and use threads for handling each incoming request. If you expect to receive 300 concurrent requests then the server will have to create 300 concurrent threads to handle them. Without proper configuration of the thread pool you will not get the responsiveness you expect. This is because thread pool creates only two threads per second. If you need 300 threads, this will take 150 seconds! This is not what we would call high performance! Right? You need to use ThreadPool.SetMinThreads and ThreadPool.SetMaxThreads to configure the thread pool. You can imagine what these methods are for and you can read more here and here. Both methods accept two parameters. First one is about worker threads and second one is about completion port threads. We care about the latter. Here is how you can set the completion port threads (second parameter) without affecting the worker threads (first parameter):
// get current values int maxWorker, minWorker, maxCompletion, minCompletion; ThreadPool.GetMaxThreads(out maxWorker, out maxCompletion); ThreadPool.GetMinThreads(out minWorker, out minCompletion); // set new values bool resultMax = ThreadPool.SetMaxThreads(maxWorker, 500); bool resultMin = ThreadPool.SetMinThreads(minWorker, 400);
In this code I set minimum threads to 400, although I expect 300 connections since thread pool may be used by other parts of my server and only by WCF.

Step 5 - ThreadPool bug
You think you are done? Think again! If you are using .NET 3.5 (with or without service pack 1) then you will notice that setting minimum number of threads simply does not work! This is because of a known bug of the thread pool described here. In order to get around this you need to contact Microsoft Support and get this fix. Unfortunately it is not available for direct download but most probably you will get this free of charge. After you install this fix you will notice that immediately after your client(s) create the 300 concurrent requests your server process will allocate 300 threads (w3wc.exe if you are hosting under IIS). Excellent! But bear with me for just one more second. We are almost but not exactly there yet!

Step 6 - Yet another bug?
Let your server at rest for 15 seconds. You will notice that the 300 threads are released and if you client(s) creates another 300 concurrent requests you are back to where you started from! One thread will be created every half second and the performance will drop! Now I'm not sure if this is a bug of the thread pool or WCF. Not sure exactly why or what, since I haven't found this one to be officially recorded in Microsoft Connect. And this one affects .NET 4.0 also! So what now? I tried to apply the solution mentioned in this blog post and it worked for me. Briefly the solution proposed is to use the ThreadPool.RegisterWaitForSingleObject method to queue some dummy job there in intervals and keep the threads alive. Yes it's ugly, I know. But this is the only one I got so far!

We are done! Hopefully now you should have achieved to have really fast activation of your services on server side. Don't forget that it is your responsibility to harness this power after your services are activated.

Permalink | Leave a comment  »

The Workflow Way (e-book)

Workflow Foundation brings a new programming model to the developer's arsenal. Like any new programming model, starting from the good old procedural programming that provided as with methods and function, to the modish parallel and functional programming, the Workflow programming model requires some shifting in the way the developers thinks and designs solutions. In addition to that, WF of .NET 4 is completely redesigned and one of Microsoft's main concerns is to make it a standard part of every developer's toolkit.

To help in this endeavour, Microsoft published a free e-book called 'The Workflow Way'. In the 25 pages of this book you can read how you can employ the Workflow Foundation and get the best things out of it.
Click here to download the e-book.

Permalink | Leave a comment  »

.NET 4 Resources for my today's VS2010 Launch presentation

How to enable SSL for testing and development purposes on Windows 7

I created a small screen cast that shows how to enable SSL on IIS for testing or development purposes. Procedure involves creating a self-signed SSL certificate and then enabling SSL (https binding) on IIS using that certificate.

Permalink | Leave a comment  »

Creating a Skype add-on using .NET - Part 1

Skype provides pretty rich API for us developers to create add-ons that can customize it's behaviour. There are a number of ways to use this API and access Skype functionality programmatically. Skype4COM is one of these ways and is the recommended one if you want to create your add-on using .NET. Skype4COM is a wrapper dll that provides Skype functionality into the COM world, therefore also to the .NET world, since .NET can use COM dll libraries.

Skype4COM.dll is located into the Program Files\Common\Skype folder (or Program Files (x86)\Common\Skype in case of x64 version of Windows). It is installed (and registered) there if you install Skype with Extras enabled (this is an option of one of the steps of Skype installation). Once done, you can add a reference to it from your .NET project. Simply right click on your project in the Visual Studio solution explorer, select Add Reference and then click on the COM tab. Skype4COM should be in the list populated there.

Example
Here is a simple (self descriptive) example of accessing Skype functionality from your C# code:

SkypeClass skype = new SkypeClass();
Debug.WriteLine(skype.Friends.Count);

Note that once new SkypeClass() is executed, Skype will warn the end-user that some process is trying to access it. End-user must allow your process to access Skype, else you will get an exception.

x64 operating systems!
Here is something you should take care of! I missed this step and in the beginning and spend quite some time figuring out why SkypeClass fails to be initialized! Since Skype4COM is a x86 (a.k.a. 32 bit) library, your add-in should also be x86 in order to be able to use it. In order to configure your project to produce a x86 executable you need to use the configuration manager of Visual Studio. Click on Build menu and then Configuration Manager. In Active solution platform drop down list, select <New>... and on the dialog that opens select x86 as platform. If you miss performing this steps you will notice the problem only on machines with x64 operating system. If operating system is x86, your .NET executable will run as x86 process anyway so it will succeed in instantiating Skype4COM dll.

Resources
Skype4COM Reference (all things you can do with Skype4COM)
Examples (a number of useful examples in many languages)
Forums (unfortunately you will not find prompt help there. most of the threads remain unanswered for days)

Permalink | Leave a comment  »

Comparison of issue tracking systems

Couple of years ago Sotiris Fillippidis - friend of mine and author of famous Zaharias Dentoftiahno tales - initiated a table of existing issue tracking systems to compare their features. Here is his blog post.

Today I came accross something similar in Wikipedia. It's a list of about 40 or more issue tracking systems. Take a look...

Permalink | Leave a comment  »

Overriding a small problem with Net.Tcp Port Sharing service and Visual Studio 2010 RC

I installed Visual Studio 2010 RC a couple of days after it became available, after uninstalling the previous installed beta 2. Today I discovered a small problem with Net.Tcp Port Sharing service. The status of the Windows Services console was the one show in the attached screen shot. It appears that the installation didn't update the service and it was still registered with executable that was in the previous version of .NET 4 (beta 2). So when trying to start the service I was getting a File not found error in Windows Event log.

I'm not sure if this was a problem of installation of RC or uninstallation of beta 2. Anyway, fixing the problem was easy. I downloaded .NET Framework 4 RC and executed it with the Repair option selected.

Permalink | Leave a comment  »

Windows Authentication in WCF Services

Click here to download:
WindowsAuthenticationTest.zip (17 KB)

There aren't may things one has to do to enable windows authentication in a WCF service. Actually Windows Authentication is by default enabled when using most of the standard bindings of WCF.

Configuration
The following configuration ensures this anyway (use this configuration both on server and on client side):

  <system.serviceModel>
      <bindings>
          <wsHttpBinding>
              <binding name="test">
                  <security mode="Message">
                      <message clientCredentialType="Windows"/>
                  </security>
              </binding>
          </wsHttpBinding>
      </bindings>
      ...

Server
To get the credentials of the user on server side using the following (password in never included):
var identity = OperationContext.Current.ServiceSecurityContext.PrimaryIdentity;

Client
On client you have two options:
a) Do not ask credentials from the user (Integrated Authentication): The credentials of the current logged on user will be used. This requires that the user is logged on to a Windows Domain that is trusted or is the same with the Domain of the server. There is no special code to write here. Simple instantiate the client proxy and use it.
b) Ask for Windows Credentials from the user: This is useful when you expect that your application will be used by users using machines not registered to known Windows Domains. In this case you have to create a typical log in dialog and ask for user name and password. Username must contain the domain name (Eg. MYDOMAIN\myUserName). Also this requires that the username and password the user will use belong to a domain that is trusted or is the same with the Domain of the server. In this case you also need to write the following line after instantiating your client proxy, and use the credentials you collected from the log in dialog:
clientProxy.ClientCredentials.Windows.ClientCredential = new NetworkCredential("MYDOMAIN\\myUsername", "myPassword");

Important
Patterns and Practices team created an excellent pdf document called 'WCF Security Guidance'. This is a quite big document that describes perhaps all the security scenarios that you might consider. It is organized in such a way that you can find what you are looking for quickly. Check it out!

Permalink | Leave a comment  »

5 simple (non state of the art) features that make Skype so easy to use

I have been using Skype intensively for some months now, to make both personal and professional voice and video calls. Put aside the superb quality of voice and video (which I've seen also in other solutions like Live Messenger), I noticed some very simple, yet extremely useful features that differentiate it from the competition:
  1. Incoming call notification on all speakers: This means that you can have your headphones pluged in so that you can use them to communicate, but still hear the incoming call notifications when you are not wearing them! (see 1st picture)
  2. Order of preference for sound devices: This is very useful if you are using a laptop and your sound equipement changes frequently. You can specify which device (speakers/microphone) will be used for communication. If not found the next available will be used etc. So if you want to use the microphone of your external camera at work but the integrated microphone of your laptop when you are on the move, you don't have to get into the options page every time. You specify this once and you are done (see 2nd picture).
  3. Mute is canceled when you answer or start a call: Often when you are about to make or answer a call you may forget that you muted your speakers just a while ago. This can also happen to the other participant, especially if he/she is not very comfortable with this way of communication. Skype takes initiative and enables your speakers when a call is started. It's obvious that since you started or answered a call you want to use them! When call is completed speakers are muted again.
  4. Auto answer call: Enable this feature and Skype can be used as a remote surveilance system (see 3rd picture).
  5. Echo / Sound Test Service: A very simple idea that helps you identify microphone, speakers and bandwidth problems. Echo user is a virtual user always present in your contact list. Call this user and see if and how other users hear you.
It seems that web conferencing and remote collaboration will become daily activity of mine in the near future. So stay tuned for more details about this experience.

See and download the full gallery on posterous

Permalink | Leave a comment  »

Resharper and RIA Services

(The following are applicable to current Resharper and RIA Services releases (see post date). I'm sure it will be fixed in the future)

Watch it RIA Service users that use Resharper!
RIA Services has a strange way (personal opinion) of doing code generation for references services, instead of using the traditional Service Reference approach. Actually, regardless of Resharper and the problem I'm describing underneath, when I first saw a RIA Services application I was really wondering how this works.
And it seems that Resharper is "wondering" also! That's why if you are using Resharper code inspection and/or intellisense you will notice that the classes that are supposed to be generated by RIA Services are not "visible" in your project. Actually if you do nothing, but just create a new 'Silverlight Business Application' using the Visual Studio template and open then App.xaml.cs you will see the picture bellow.
To fix this you have two options:
  • Disable Resharper completely (Tools>Add-in Manager in Visual Studio)
  • Disable Code Inspection and Intellisense of Resharper and let the Visual Studio do it:
    1. Resharper>Options in Visual Studio...
    2. Environment>Intellisense>General
    3. and Code Inspection>Settings

Permalink | Leave a comment  »

Finally! Create Project, Add New Item and Add Reference dialogs are fast!

I just installed Visual Studio 2010 Beta 2 on my machine. I only had little time to play with it so far but I'm so excited! Finally dialog boxes are fast! I never understood so far why 'Create New Project' and 'Add New Item' were so slow in previous versions! Any why 'Add Reference' was opening .NET Assembly tab by default and not Project tab.
Guess what! Huge improvement in VS 2010! Dialogs open extremely fast and Add Reference shows Project tab by default now. And even if you press COM or .NET tabs they are rendered in a few milliseconds!
Startup time of Visual Studio itself seems also improved!

Permalink | Leave a comment  »

CNET TechTracker - Scan your computers for new software versions

CNET TechTracker (www.download.com) can help you get notifications when a new version of software installed on your machine is released! It really works! You can configure to automatically run on windows tray and check for new software daily, weekly, monthly or manually. I suppose that this is possible only for software being distributed over download.com, but this is fairly big software database!
The results are reported to you with a tray notification or on the web. I've seen other applications like this one in the past, but none from such an important vendor like CNET. I suggest you try it out! See part of the results for my PC...

See and download the full gallery on posterous

Permalink | Leave a comment  »

E-commerce modules for DotNetNuke

Some time ago I was involved in a project of creating an online store for a Greek firm. The store was to be implemented using dotnetnuke. I made a research back then to find what was the most appropriate dotnetnuke module for that particular case. I run into a blog post which was presenting some, but the most interesting part was the comments under it. If you search you will find a couple of mine also there.
Its been several months now that I keep getting notifications about new comments on that post. The discussion goes on and on... Its quite interesting, have a look...

Permalink | Leave a comment  »

Use REST and let others do the caching for you

I run into an (one year) old article of Udi Dahan today. He explains how REST can be used to scale up an application, of course without the need to add additional hardware. The idea is simple. If you have a SOAP web service that thousants of clients call, then a common practice would be to add caching behind it, in order to avoid hitting your database (or other resources) for each request. Common and cheap practice that works up to some extend. However, If you use REST instead of SOAP for your service, then

Διαβάστε περισσότερα »

Model - View - ViewModel in Silverlight

I'm trying to find my way into the Silverlight world lately. And one of the most predominant phrases in this world is Model-View-ViewModel pattern or else MVVM. This good old pattern suggests the separation of concerns in the UI tier into the three distinctive layers it's name indicates. I've never dealt with MVVM before and as I said Silverlight is also new to me. Therefore I'm trying to read as much as I can before digging into the code. The most enlightening article I've read so far is Kathleen Dollard's

Διαβάστε περισσότερα »

Google uses ClickOnce to download Google Chrome!

I had a little problem today accessing a web resource and I decided to download Google Chrome "to get a second opinion". The last time I did the same thing was quite some time ago and since I got a new laptop recently I hadn't installed it yet. And guess what I found out? Ok, you don't have to guess... you read the title... Yes, Google uses Microsoft .NET's ClickOnce technology to download and automatically upgrade Google Chrome in Windows Environment! If this is not a surprise what is!? Check it out... ! However...

Διαβάστε περισσότερα »

Donating your software

I've blogged about Balsamiq Mockups in the past . Excellent tool that was really missing from my toolbox for a long time! I fully recommend it. I give Five Stars! But the reason I'm writing this post is not about how useful and engenious it is but its about the latest blog post Peldi Guilizzoni (creator of the software) wrote. The title is " Donating Your Software: A Whole Lot of WIN! ". Interesting way to look at software. Sure, being a member of WWF or Greenpeace or sending some money to Médecins Sans Frontières

Διαβάστε περισσότερα »

Interlude... my Athens Theme Pack for Windows 7

I installed Windows 7 RTM a few days ago and I decided to create my own theme pack using Athens as theme! The theme contains a number of photos from the city... The Parthenon Temple of Poseidon (Cape Sounio) The Athens Academy Panathinaikon Stadium (Kallimarmaro) Stoa of Attalus Herrodion Theatre The Acropolis Museum

Διαβάστε περισσότερα »

WCF FAQ

Fellow MVP Shivprasad Koirala put together an excellent series of three articles with Frequently Asked Questions regarding the Windows Communication Foundation. Take a look... WCF FAQ Part 1 : This is a 20 question FAQ for beginners which explains basic concepts of WCF like End points, contracts and bindings. It also discusses about various hosting methodologies of WCF service. The article finally ends talking about bindings and one ways operations in WCF. WCF FAQ Part 2 : This FAQ covers 10 questions which

Διαβάστε περισσότερα »

Low bandwidth view in MSDN! Cool!

I just noticed a new (?) cool feature in MSDN library today! There is a link on top of each page to switch in low bandwidth view. The result is a more simple, lighter page. This lighter page seems more clear also! Check it out. High Bandwidth Low Bandwidth

Διαβάστε περισσότερα »

Finally! Edit and Continue in x64!

To x64 or not to x64? One thing that was troubling me answering this question was the lack of 'Edit and Continue' feature when Visual Studio works under x64 (64 bit) operating system. Yes, yes. Some people will argue that this is not a big deal, since 'Edit and Continue' is just a nice to have feature and not that usefull. I will tell you something. Most of the times these people are web developers that never had the chance to use it, since it was never available when developing on ASP.NET. Good news! Edit and

Διαβάστε περισσότερα »

For Silverlight starters...

For Silverlight 2 starters I recommend this free tutorial from silverlight.net: http://silverlight.net/learn/tutorials.aspx There is code available both in C# and VB.

Διαβάστε περισσότερα »

Times Square billboard crash!!!

Have you ever wondered whats behind the Times Square billboards? I was in New York City for a couple of days this week and while I was wondering around the Times Square look what I captured with my camera on the intersection of Broadway and 47th street ! An application crash!

Διαβάστε περισσότερα »

Περισσότερες Δημοσιεύσεις Επόμενη »