Arik Poznanski's Bloghttp://blogs.microsoft.co.il/arik
It CAN be done with .NETFri, 27 Dec 2013 21:36:59 +0000en-UShourly1https://wordpress.org/?v=5.0.2Blog Summaryhttp://blogs.microsoft.co.il/arik/2011/11/20/blog-summary/
http://blogs.microsoft.co.il/arik/2011/11/20/blog-summary/#respondSun, 20 Nov 2011 00:13:28 +0000http://blogs.microsoft.co.il/?p=935937I feel this is a good time for me to present a summary of some of the posts I wrote..

Most Interesting Posts

Following are posts that I’m personally proud of.

Shake Gestures Library – A Windows Phone RecipeIn this post I present an algorithm for detecting shake gestures on a Windows Phone system using the accelerometer sensor. This is by far my favorite post since I actually needed to use some math to solve this one.

I’d like to thank Microsoft and specifically Guy Burstein for his guidance and excellent advice on finding ways to help the developers community. Also, a special thanks is in order for my managers at Sela Group: David Bassa, Caro Segal and Ishai Ram for giving me the time to invest in the developers community.Lastly, I’d like to thank you, my blog readers.

Now that I got this out, I can continue my Thailand honeymoon trip

That’s it for now,Arik Poznanski.

]]>http://blogs.microsoft.co.il/arik/2011/10/02/im-a-microsoft-mvp/feed/7Comparing Versions of a .NET Framework DLL Using NDependhttp://blogs.microsoft.co.il/arik/2011/09/22/comparing-versions-of-a-net-framework-dll-using-ndepend/
http://blogs.microsoft.co.il/arik/2011/09/22/comparing-versions-of-a-net-framework-dll-using-ndepend/#respondThu, 22 Sep 2011 14:28:57 +0000http://blogs.microsoft.co.il/?p=904081Following Build conference, many people may ask what is new in the .NET Framework. Well, you could find out by examining the documentation, but then you are limited to what it covers. If you want to know ALL that is new / updated in the .NET Framework, read on..

You can use the following method to easily find the difference between .NET Framework 4.5 and its previous version, .NET Framework 4.0!

In this post I will show you how you can use the tool NDepend to compare two versions of a DLL which is part of the .NET Framework.

I’ve already done it major parts of the framework and found interesting results! Unfortunately, I don’t have the time to publish my results since I’m going out on vacation for a month. So I leave you with these instructions on how to dig easily in the right places.

Introduction

NDepend is a tool for static analysis of .NET code. It has many features including the ability to run both predefined and custom queries against the code base. These queries let you evaluate the quality of the code.

Another neat feature of NDepend is the ability to compare two versions of the same DLL. This lets you see progress between different builds of your project. Note that you don’t need the actual code, you compare the actual DLLs.

Using NDepend to compare DLLs that are part of the .NET Framework is not trivial, but can be done. This post will show you exactly how.

Prerequisites

The .NET Framework v4.0 version of the file resides in: C:\NET\v4.0\mscorlib.dll

The .NET Framework v4.5 version of the file resides in: C:\NET\v4.5\mscorlib.dll

Step 1: Create an NDepend project for each version of the .NET Framework

In this section we will analyze each version of the DLL in a different project, so the following steps will be done twice. On the next step we will compare the two project results.

Launch NDepend and select Create Project…

Fill the fields Project Name and Location and press OK.

Select Browse… and choose the first file: C:\Net\v4.0\mscorlib.dll

Now select View Folders that contain .NET assemblies to analyze

Select the .NET Framework folders that were automatically added and remove each one of them by right-clicking and selecting Remove

Finally, click the green Play button or simply press F5 to start analyzing the DLL

When the analyze is finished you should see some statistics about the selected DLL and you will have options to manually analyzing the file. For our purpose we can simply skip this and close the application (entirely).

Now repeat these instructions to analyze the second version of your DLL. Don’t forget to remove the .NET Framework folders!

Step 2: Compare between the NDepend projects

In this step we will compare the two project results from the previous step.

Launch NDepend and select Compare: 2 versions of a code base

Select the projects you have created in the previous step. Make sure you put the older version on the left and the newer version on the right.

That’s it! now you can easily compare the two versions. For example, you can check which types are new in the new DLL version, or which types have changed, etc..

That’s it for now, Arik Poznanski.

]]>http://blogs.microsoft.co.il/arik/2011/09/22/comparing-versions-of-a-net-framework-dll-using-ndepend/feed/0Windows 8: What’s New?http://blogs.microsoft.co.il/arik/2011/09/19/windows-8-whats-new/
http://blogs.microsoft.co.il/arik/2011/09/19/windows-8-whats-new/#respondMon, 19 Sep 2011 00:24:04 +0000http://blogs.microsoft.co.il/?p=902624Got back from Build conference. Since I expect many people will ask me "So, what’s new?" and since the answer is rather complex, I figured I should try to write a post about it, so here goes…

General Information

Windows 7 sold (i.e. legal copies) over 450,000,000 copies since it was released.

Windows 7 bypassed Windows XP in world usage.

Windows 8 will be used primary for tablets and other touch-based devices.

Windows 8 for Developers

There is a new way to expose Windows API named Windows Runtime or WinRT.

WinRT is completely native and is built above COM with the addition of inheritance, generics, delegates and more. Basically WinRT = Modern COM.

WinRT doesn’t cover all previous Win32 APIs.

WinRT has can be used from C++, C#, VB.NET and JavaScript using language projections which are auto-generated from the WinRT APIs and provide a natural and familiar experience for developers of the language.

WinRT API follow a guideline that says that every API which might take more than 50ms should be async. As a result a lot of WinRT APIs are async.

WinRT includes a native UI framework, XAML-based, for building Metro-style applications.

The XAML of the new WinRT UI framework resembles Silverlight XAML rather than WPF XAML.

Metro-style applications can be built in the following technologies:

C++ and XAML

C# and XAML

VB.NET and XAML

JavaScript and HTML/CSS

A Metro-style application can collaborate with another Metro-style application without knowing him at all using several contracts that Windows 8 defines, e.g. share source contract and share target contract.

Metro-style applications should define the capabilities they use, similar to Windows Phone applications. At runtime these declarations are enforced.

C++ has new extensions that allows easy integration with WinRT, these extensions follow a syntax similar to C++/CLI, only they are completely native.

The next version of .NET Framework is 4.5, nothing too exciting there.

Some General Insights:

C++ is very much alive! I’ve been to an excellent lecture on modern C++ (the portable one, not MS specific), by Herb Sutter. Wow. So many C++ developers, the room was packed!

Future of Silverlight is not clear. There will be version 5 but there’s no information about what’s next.

Since all the videos are now available on the conference site, I strongly suggest you see the ones that are interesting for you. Note that there quite a lot.

That’s it for now, Arik Poznanski.

]]>http://blogs.microsoft.co.il/arik/2011/09/19/windows-8-whats-new/feed/0WPF Tutorial Published [HEB]http://blogs.microsoft.co.il/arik/2011/09/07/wpf-tutorial-published-heb/
http://blogs.microsoft.co.il/arik/2011/09/07/wpf-tutorial-published-heb/#commentsWed, 07 Sep 2011 23:30:52 +0000http://blogs.microsoft.co.il/?p=896919After publishing a Windows Phone tutorial and a Silverlight tutorial, I now bring you the WPF tutorial, for the sake of XAML-based technology completeness.

This 37 chapters tutorial in Hebrew completely adapted to fit WPF desktop development and using relevant source code and screenshots.

The tutorial is hosted on the great Hebrew developers community site: WebMaster.org.il

The tutorial is based on WPF 4 and it teaches desktop development from the first step, using Visual C# 2010 Express, provided freely by Microsoft.

System.Windows.Forms.Application.ThreadException

This event is used for catching unhandled exceptions only on UI threads created by WinForms. Other exceptions, generated on non-UI threads won’t arrive to this event. Use AppDomain.Current.UnhandledException to catch them.

The default behavior of a WinForms application with an unhandled exception is to present the following error dialog:

If you register to this event, the application will not show the error dialog and will automatically extend the application life (i.e. the application won’t be killed).

If you do want to end your application, maybe after logging the exception or asking the user with a personalized dialog, you must do it yourself using Application.Exit().

Dispatcher.UnhandledException

This event is used for catching unhandled exceptions on the thread attached to the specific Dispatcher (WPF only). Note, that in WPF two threads can have two different Dispatcher object attached. This event is only useful if you have several UI threads in your WPF application, which is quite rare. If you’re not sure, you probably need to handle only the previous event: Application.Current.DispatcherUnhandledException.

As in the previous event, if you register, you will get the change to log the exception. To prevent the exception internal handling from being called set e.Handled = true.

AppDomain.CurrentDomain.UnhandledException

Bonus: AppDomain.CurrentDomain.FirstChanceException

This event which exists only from .NET 4, is raised on ANY exception, if the handled one. In fact, the event is raised before the search for the catch blocks. You can’t handle the exception using this event. You can use it if you need to log exceptions that are caught.

To all those nice developers who keep asking me C# related questions by mail, I strongly urge you to post your C# related questions on this forum.

NOT because I don’t enjoy it!

On contrary, I love to help you and would even more enjoy it if even more people could enjoy the answers. Plus, there’s more people on this forum that can help, so you will probably get an answer sooner

In other news..

New Windows 8 Blog

With Build conference approaching fast, Microsoft recently opened a new blog for Windows 8 behind the scenes details. Hopefully this is a sign that Microsoft is going to raise the curtain from the mysterious Windows 8. Follow the new blog here or on their Twitter @BuildWindows8.

That’s it for now, Arik Poznanski.

]]>http://blogs.microsoft.co.il/arik/2011/08/17/new-c-forum-for-the-israeli-developers-community/feed/0Using Windows Phone As Windows 7 Accelerometer Sensorhttp://blogs.microsoft.co.il/arik/2011/08/13/using-windows-phone-as-windows-7-accelerometer-sensor/
http://blogs.microsoft.co.il/arik/2011/08/13/using-windows-phone-as-windows-7-accelerometer-sensor/#commentsSat, 13 Aug 2011 11:54:20 +0000http://blogs.microsoft.co.il/?p=883702I just had a cool idea! (actually I had it like 6 month ago, but bear with me).

My idea involves mixing some of the features in Windows 7 with some of the features in Windows Phone 7, to create a glorious mix!

Windows 7

One of the new features in Windows 7 is the Sensor API which provides a standard interface for accessing sensors of various types, like accelerometer, etc..

Windows Phone 7

Windows Phone 7 comes with a few sensors out of the box, among them: accelerometer!

Idea

What if we use Windows Phone 7 accelerometer sensor as a standard device on Windows 7?

Roadmap

So how can we accomplish that? let’s break the idea to steps:

Step 1: Create a software driver

I’ll start with creating a dummy software driver. This driver will implement what’s necessary to be a standard Windows 7 Accelerometer sensor, but at this stage will simply return constant data.

In order to write a sensor driver for Windows 7 I’ll need to use User Mode Driver Framework (UMDF), a COM-like, C++ framework for writing user-mode drivers in Windows 7.

Step 2: Transfer Windows Phone 7 sensor data into the PC

The next step is to find a way to transfer the accelerometer data from a Windows Phone device into the PC. One possible way of doing this implementing a local WCF service on the desktop that the Phone will keep calling with accelerometer data. This will require an application to run on the phone to keep the data flowing.

Step 3: Consume the WCF service from the phone

Using the service from the previous step we can now consume it in a simple Windows Phone application that all it does is getting the accelerometer sensor data using the phone API and call the WCF service with the latest data.

Step 4: Make the software driver consume the Windows Phone 7 data

Now that I have a software driver that returns dummy accelerometer data and a way to get real accelerometer data from the Windows Phone, all I need to do is connecting the dots and make my accelerometer driver return the real data. To do this I’ll need some kind of inter process communication to transfer the data from the WCF service to the driver.

Long Story Short…

I present to you the Windows Phone Accelerometer Driver for Windows 7!

As mentioned earlier I’ve implemented a simple local WCF service for transferring the accelerometer data from the phone to the driver. You can find the service source code in the project named WP7AccelerometerService. The service uses named pipes to communicate with the driver.

The phone application is a very simple one that consumes the WCF service and call it whenever a new accelerometer value is available. You can find its source code in the project named WP7AccelerometerClient.

Finally, if you want to check the functionality of the accelerometer driver you can use either the SensorDiagnostics project or the more fun PlaneDemo project, which I borrowed for Sergey Zwezdin blog.

How to Install?

4. According to the bitness of your OS Run install_wp7_driver_32bit.bat or install_wp7_driver_64bit.bat to install the driver.

5. When the following notification appears, select "Install this driver software anyway":

This should take around 1-2 minutes to complete.

6. Enable installed Sensor in the Control Panel

7. Run the WCF service from as administrator. If you run it from Visual Studio, make sure you ran Visual Studio as administrator.

8. Run the Windows Phone client on a real device while connected to the PC and enter your PC (LAN) IP

9. That’s it! you can now sit back and enjoy the ride using the PlaneDemo application or SensorDiagnostics, or any other software that uses the accelerometer sensor.

How to Uninstall?

If you want to uninstall the driver simply go to the Device Manager, select the "WP7 Accelerometer Sensor" device from the Sensors category, select uninstall from the context menu and make sure you mark the checkbox to delete the driver.

Final Note

I’ve seen the project works both on a real device and using the phone emulator, however it’s not a one-click install. I expect users to have problems with the installation. If you encounter some problems, please post on the CodePlex project site forum page and I’ll do my best to help.

Also, if you want to improve the source code (maybe adding GPS support?) or the installation procedure, I’ll be happy to include your improvements and even include you as one of the project members on CodePlex.

This project was pure fun since it combines many useful technologies to create real value. Among the technologies you can find: C++, COM, UMDF, C#, WCF, WP7, etc..

That’s easy, here’s a solution

Usually you would simply create a new value converter which has some custom code (e.g. a switch –case statement) to convert from the enum value to the relevant image.

Is there a better solution?

How many times have you written this kind of converter, the kind that takes a value and maps it to another value?

Well, no more!

I present to you: DictionaryValueConverter. A Converter that lets you define a collection of key-value pairs and do the mapping for you.

So, how can I use this converter?

The following code provides a common usage of this converter. Here I map three enum values to three different bitmap images. Each value in the Values property is another image which is mapped by its x:Key.

publicobject Convert(object value, Type targetType, object parameter, CultureInfo culture) {// if key type is not set, get it from the first dictionary value, usually it's the same for all the keysif (KeyType == null) { KeyType = Values.Keys.First().GetType(); }