Work with Exchange Web Services

# February 21, 2012 - 10:47 by
Last Update: 21.2.2012 - 19:18

The following code has cost me allot of time. It was very hard to find the pieces and put them together. So I hope I can help a few of you with that post ;-)

The Problem

The problem was that I need to access different Exchange accounts via Exchange Web Services (EWS) and read out the mailbox size.

First

To do this I first used a view only account in the active directory that I have activated for impersonation by typing the following code into the Exchange-Shell:

Get-ExchangeServer
| where {$_.IsClientAccessServer -eq $TRUE}
| ForEach-Object {Add-ADPermission -Identity $_.distinguishedname -User (Get-User -Identity User1 | select-object)
    .identity -extendedRight ms-Exch-EPI-Impersonation}

You can find an explanation to this code on msdn: http://msdn.microsoft.com/en-us/library/bb204095(EXCHG.80).aspx

Second

Then I set up the connection string to the EWS:

// Certification Validation always true
ServicePointManager.ServerCertificateValidationCallback =
                    delegate(
                        Object obj,
                        X509Certificate certificate,
                        X509Chain chain,
                        SslPolicyErrors errors)
                    {
                        return true;
                    };

// Setup connection string
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new NetworkCredential("viewadmin", "password", "FQDN");
service.AutodiscoverUrl("viewadmin@FQDN");

Third

Thirdly I used impersonation to connect to another mailbox account:

// Impersonate
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "user@FQDN");

Finally

And finally I requested the folder size with this nice little piece of code:

private static readonly ExtendedPropertyDefinition PidTagMessageSizeExtended = new ExtendedPropertyDefinition(0xe08, MapiPropertyType.Long);

/// <summary>
/// Gets the size of the mailbox in kilobytes.
/// </summary>
/// <param name="service">The ExchangeService object.</param>
/// <returns>Returns the used kilobytes in double.</returns>
public static double GetMailboxSize(ExchangeService service)
{
    var offset = 0;
    const int pagesize = 12;
    long size = 0;

    FindFoldersResults folders;
    do
    {
        folders = service.FindFolders(WellKnownFolderName.MsgFolderRoot,
                                      new FolderView(pagesize, offset, OffsetBasePoint.Beginning)
                                      {
                                          Traversal = FolderTraversal.Deep,
                                          PropertySet =
                                              new PropertySet(BasePropertySet.IdOnly, PidTagMessageSizeExtended,
                                                              FolderSchema.DisplayName)
                                      });

        foreach (var folder in folders)
        {
            long folderSize;
            if (folder.TryGetProperty(PidTagMessageSizeExtended, out folderSize))
                size += folderSize;
        }
        offset += pagesize;
    } while (folders.MoreAvailable);

    return size;
}

 

I hope I could help you. If you have improvements on the code don´t hazle to comment ;-)

Software-Reengineering

# February 9, 2012 - 19:00 by
Last Update: 4.2.2012 - 17:45

Einer meiner Studienkollegen hat mir eben angeboten seine Seminararbeit zum Thema Software-Reengineering zu veröffentlichen. Vielen Dank an Andre Ufer und euch viel Spaß beim lesen ;-)

Ausarbeitung

 

Download Link

Software-Reengineering
Software-Reengineering
Seminararbeit_SRE_Ufer.pdf
218.2 KiB
10 Downloads
Details...

Setting up a Mac VM inside Windows 7

# February 2, 2012 - 1:16 by
Last Update: 4.2.2012 - 17:48

1. Intro

Because of some changes in my company I now have to code for iOS. This is why I need to learn Cocoa (the programming language for developing iOS  software). So tonight I have set up a virtual machine with Mac OS X Lion 10.7.2 to play a little bit around with Xcode – the preferred IDE.

Till now I thought setting up a Mac-VM is very difficult and hard to obtain but it was very easy and I hadn´t any problems. To help all you guys out there that like to do the same, here is my how to ;-)

For this how to I assume that you have already played around with VMware and also know how to open a terminal window in Mac OS X.

2. Getting the software

  • For the virtualization I have used a VMware Workstation 7.0.0, can´t say if there are problems if you use the Fusion or the Player, if you like to test it I would appreciate a comment about your  experience ;-)
  • The next thing you need ist the “Mac OS X Lion Bootable .vmdk (For VMware)“, google it, download it – should around 4, 12GB
  • VMware unlocker: mirror1 mirror2 (contains unlocker for VMware Fusion, Player & Workstation – Linux only for Workstation)
  • VMware guest installation: mirror
  • Audio driver: mirror
  • Mac Os X update to 10.7.2 from Apple: link

3. Prepare

  • Execute the VMware unlocker (Mac OS X Lion VMware Files.exe), it extracts the unlocker and a predefined VM.
  • Your directory should now look like this (Mac Os X update to 10.7.2 isn´t listed  - sorry!):
  • Now, if you have installed the Workstation run the windows.bat in the directory: VMware Workstation Unlocker – Windows. If you use Fusion, Player or Linux take the appropriate folder ;-)
  • A little bit intel, what are you installing?
    This is in the windows.bat

    net stop vmauthdservice
    
    "%~dpn0_32.exe" %*
    
    net start vmauthdservice

    The windows.bat stops the VMware service, installs a patch and then starts the service again. At this point you have to trust the patch that he does what you’re expecting and isn´t a virus..

  • Now go to the Mac OS X Lion folder and double-click the Mac OS X Lion.vmx that should start the VMware – likewise you can start the VMware first and browse for the file.
  • Now you see the VM in VMware:
  • Edit the VM settings and add another (existing) hard drive, the Mac OS X Lion Installer.vmdk that you have downloaded earlier – around 4,12GB, you remember?
  • Also edit the CD device and add the darwin_snow.iso
  • Now it should look like this:

4. Installation

  • Start the VM!
  • Select “I moved it
  • If VMware asks you to repair the hard drive, let VMware do it.
  • Now follow the Mac OS X instructions for installing the OS.
  • When you´r done and reached the Mac desktop open the CD drive of your VM and install the VMware Tools. After that you have to reboot. From now on the resolution will automatic fitt to the screen size and a share drive shows up on your Mac desktop. If you now setting up a share in your VMware Workstation you can reach it from within the VM via that share drive – cool, isn´t it :-)
  • Now shutdown the VM, make a snapshot, add a soundcard (in the settings) and power it on again, we will now update the VM to 10.7.2!

5. Update to Mac OS X Lion 10.7.2

  • After booting you have to open a terminal window in the Mac VM.
  • We now backup a file - the dot at the end isn´t accidentally!
    cp -r /System/Library/Extensions/AppleLSIFusionMPT.kext .
  • Copy the Mac Os X update to 10.7.2 to your share drive and install it within the VM. Don´t reboot!
  • Now we remove the AppleLSIFusionMPT.kext that was created by the installation and replace it with our backup file:
    sudo rm -rf /System/Library/Extensions/AppleLSIFusionMPT.kext
    
    sudo cp -r AppleLSIFusionMPT.kext /System/Library/Extensions
  • Now reboot the VM, copy the EnsoniqAudioPCI_v1.0.3_Lion.pkg to the share and install it within the VM. After a reboot you should have working sound :-)
  • If your screen resolution won´t change dynamically any more it´s because of the system update, you can fix it by installing the VMware tools again ;-)

6. Clean up

  • Shutdown your VM. Remove the second hard drive and the mounted CD-iso, you do not need them any more.
  • Take a final snapshot!
  • Now you hopefully have a working Mac OS X Lion 10.7.2 VM in the Mac OS X Lion directory, feel free to move your VM to another location of your hard drive and remove/backup the installation files.

7. Enjoy

Now I´m All In

# January 11, 2012 - 1:51 by
Last Update: 21.2.2012 - 10:49

Two hours ago I viewed a clip from Hanselminutes on 9, called Social Networking for Developers and now I have decided to create an account for twitter.

At the moment I don´t know if I will use it both ways (read tweets), till now I setup a plugin that posts my blog posts as updates to my twitter account and twitter posts it to Facebook. I thought: “Why don´t use all the social media to make public blog posts even more popular”.

Because Google+ is in my opinion more like a massive blog I won´t publish twitter messages on this platform, I think I will promote my posts manually on Google+.

Maybe you think two hours for this is a little bit long, well, damn right! I have also moved my blog to a new directory on my web space, have created a .htaccess-file that redirects the old urls, that are out there, to the new direction and I have the plan to shut down the url blog.jwillmer.de. I believe it is better to use one domain without subdomains, the future will tell me if I´m right :-)

Also I have edited my theme and added tags for Rich Snippets but this story have to wait – for now I´m excited if this post will show up on twitter/fb and how it looks like and because I have to work tomorrow and it´s very late I´m closing for now ;-)

Zitate aus dem Adventskalender

# January 8, 2012 - 15:54 by
Last Update: 21.2.2012 - 10:49

In meinem Adventskalender waren, auf der Rückseite der Türchen, immer Zitate abgebildet, von denen ich einige so gut fand das ich sie bis jetzt auf dem Tisch liegen aufgehoben habe. Nun bin ich aber gerade am aufräumen und die Zitate werden dem zum Opfer fallen. Bevor sie also weg sind, dachte ich mir, ich poste sie hier ;-)

Die Liebe besteht zu drei Viertel aus Neugier. – Giacomo Casanova
 
Liebe ist: Freundschaft, die Feuer gefangen hat. – unknown
 
Liebe ist kein Solo. Liebe ist ein Duett. Schwindet sie bei einem, verstummt das Lied. – Adelbert von Chamisso
 
Ein Kuss ist eine Sache, für die man beide Hände braucht. – Mark Twain
 
Vergangen sei vergangen und Zukunft ewig fern: gefangen verweilt die Liebe gern. – Clemens Brentano