Tuesday, February 22, 2011

Code to capture the Message arrived event in Outlook

There may be times when we want to do some operation upon arrival of the message in the Outlook Inbox. Here is the simple piece of code which will help to capture the message arrived event in Outlook.

//Initialization code
protected override bool DoInitialise()
{
outlook = new ApplicationClass();
outlook.Session.Logon(null, null, false, false);
inbox = outlook.Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox).Items;
inbox.ItemAdd += new ItemsEvents_ItemAddEventHandler(inbox_ItemAdd);
outlook.NewMailEx += new ApplicationEvents_11_NewMailExEventHandler(outlook_NewMailEx);
return true;
}


void outlook_NewMailEx(string EntryIDCollection)
{
//This event will be fired whenever a mail arrives in Inbox
}

Passing Default Credentials from Silverlight to WCF

While developing Silverlight and WCF apps you will have to share the default credentials from Silverlight to WCF service sometime.



This is how you can do;


1) Create the <basicHttpBinding> with the following information under the <bindings> section;

<basicHttpBinding>
<binding name="BasicBinding0">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows"/>
</security>
</binding>
</basicHttpBinding>

2) Add the below piece of section under the <System.ServiceModel> section
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
</serviceHostingEnvironment>

3) Add the below piece of code above the OperationContract behavior;
[System.ServiceModel.Activation.AspNetCompatibilityRequirements(RequirementsMode=System.ServiceModel.Activation.AspNetCompatibilityRequirementsMode.Allowed)]
public class StaticDataProcessing : ProcessTaskWCFBase

Please note that steps 2 and 3 are needed to avoid the HttpContext.Current coming as NULL issue.

This way you can pass the default credentials from Silverlight to WCF.

ProjectLinker extension for Visual Studio

Recently we were developing an application in silverlight which will consume WCF for doing some business operations and data access. WCF was designed using MessageContracts and DataContracts concept. Each operation will translate to input and output DataContracts. This WCF is not an tranditional one in which when you add reference you will get all the data contracts. So we will have to share all these DataContracts to Silverlight app. There arised the problem, since the Desktop/Web class library project cannot shared in silverlight app. So we thought of creating a separate silverlight class library replicating all the classes. This will be a serious maintenance nightmare!!!!
That time, I came across the concept of ProjectLinker synchronization tool. This is specially designed to address such scenarios. Basically Multi-targeting framework.
Bingo!!! Problem solved. Using this we can share the same class files between different platforms nothing but between the Desktop/Web class library and Silverlight class library.

You can find more about how to use this tool in the below link;
http://msdn.microsoft.com/en-us/library/ff921108(v=pandp.20).aspx

Download Project Linker for VS2008 here;
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=387c7a59-b217-4318-ad1b-cbc2ea453f40&displaylang=en

Download Project Linker for VS2010 here;
http://visualstudiogallery.msdn.microsoft.com/5e730577-d11c-4f2e-8e2b-cbb87f76c044/