Tag Cloud

All tags on blog, arranged by weight

EF4 T4 Templates

I just started my first open-source project. EF4 Templates. Yeahhh!

EF4 Templates uses T4toolbox to generate POCO self-tracking entities that can be unit tested, along with validation for WPF, Silverlight RIA services and ASP.NET/ASP.NET MVC. They also generate an ODATA service with authentication for usage with WPF.

Some of the features already implemented:

Self-tracking entities that use IContext and IObjectSet so they can be seperated from EF, and unit tested.

Fake object context for testing purposes.

OData service endpoint for use with WPF or windows forms, including forms authentication.

Validation using sidecar classes like RIA services and DataAnnotiations. A special class is generated for WPF to use DataAnnotations too.

Some of the new features I wish to implement are:

Web crud page generation

WPF crud page generation

Silverlight domain service with OData endpoint

The templates generate VB.NET and C# code. Wanna help?

http://ef4templates.codeplex.com/

Xaml color scheme generator

I've made a xaml color scheme generator that works with http://colorschemedesigner.com/

It generates a resource dictionary and xaml demo source. In the color scheme generator site, just export to xaml, and save to a file. In the generator, browse for that file, and click convert.

Download it here

Requires .NET 4.0 Client Profile.

Windows 7 Multi-touch Panning with ScrollViewer in WPF 3.5 Part Duex

In my last post I described a class that wraps the ScrollViewer control to enable multi-touch panning in it.

Well, it's not exactly the right way to do it. You should be receiving the pan messages in the Window, then finding the scroll viewer where the window was touched using a Hit Test, and scroll that ScrollViewer.

 

Code Snippet
  1.         private void Page2_Loaded(object sender, RoutedEventArgs e)
  2.         {
  3.              // Get our items for the itemscontrols
  4.              this.GetItems();
  5.  
  6.              // Check for multi-touch capabilities
  7.              if (Windows7.Multitouch.Handler.DigitizerCapabilities.IsMultiTouchReady)
  8.             {
  9.                  // Enable stylus events
  10.                 Windows7.Multitouch.WPF. Factory.EnableStylusEvents(this);
  11.                  // Add the gesture handler
  12.                  this.GestureHandler = Windows7.Multitouch.WPF.Factory.CreateGestureHandler( Window.GetWindow(this));
  13.                  // Attach the handler to the method
  14.                  this.GestureHandler.Pan += new EventHandler<Windows7.Multitouch.GestureEventArgs>( this.GestureHandler_Pan);
  15.             }
  16.         }
  17.  
  18.  
  19.         private void GestureHandler_Pan(object sender, Windows7.Multitouch.GestureEventArgs e)
  20.         {
  21.              this.panTranslation = e.PanTranslation;
  22.  
  23.              PointHitTestParameters hitTestParameters = new PointHitTestParameters(Windows7.Multitouch.WPF.PointUtil.ToDrawingPointF(e.Center));
  24.              VisualTreeHelper.HitTest(this, null, new HitTestResultCallback(this.HitTestResult), hitTestParameters);
  25.         }
  26.  
  27.         public HitTestResultBehavior HitTestResult(HitTestResult rawresult)
  28.         {
  29.              ScrollViewer sv = null;
  30.              try
  31.             {
  32.                 sv = (ScrollViewer)rawresult.VisualHit;
  33.             }
  34.              catch
  35.             {
  36.             }
  37.  
  38.              // If we have a reference to the scrollviewer, then we scroll
  39.              if (sv != null)
  40.             {
  41.                  // Make the Scroller scroll
  42.                 sv.ScrollToVerticalOffset(sv.VerticalOffset - this.panTranslation.Height);
  43.  
  44.                  // Stop trying to find more controls in the visual tree
  45.                  return HitTestResultBehavior.Stop;
  46.  
  47.             }
  48.              else
  49.             {
  50.                  // Continue trying to find more controls in the visual tree
  51.                  return HitTestResultBehavior.Continue;
  52.             }
  53.  
  54.         }

When you are tracking multi-touch in a specific control, the touchs register at the window level, so even if you are not touching in the ScrollViewer, it still will pan it.

So the code was moved to the window , and uses the standard <ScrollViewer>.

Download the example project in C# and VB.NET

Windows 7 Multi-touch Panning with ScrollViewer in WPF 3.5

UPDATE: You should be using the Window to receive events. See my updated post for details.

Yes, it can be done easily, including inertia. It does require the Windows 7 Multitouch .NET Interop Sample Library

First, create a class that inherits from scrollviewer.

Code Snippet
  1. Public Class MultiTouchScollViewer
  2.     Inherits ScrollViewer
  3.  
  4. End Class

Then you add references to Windows7.Multitouch.dll and Windows7.Multitouch.Wpf.dll.

Then modify the MultiTouchScrollViewer like so:

Code Snippet
  1. Imports System.Windows
  2. Imports System.Windows.Controls
  3.  
  4. Public Class MultiTouchScrollViewer
  5.     Inherits ScrollViewer
  6.  
  7.     Private GestureHandler As Windows7.Multitouch.GestureHandler
  8.  
  9.     Public Sub New()
  10.         AddHandler MyBase.Loaded, New RoutedEventHandler(AddressOf Me.MultiTouchScollViewer_Loaded)
  11.         Me.GestureHandler = Nothing
  12.     End Sub
  13.  
  14.     Private Sub MultiTouchScollViewer_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
  15.         If Windows7.Multitouch.TouchHandler.DigitizerCapabilities.IsMultiTouchReady Then
  16.             GestureHandler = Windows7.Multitouch.WPF.Factory.CreateGestureHandler(System.Windows.Window.GetWindow( Me))
  17.              AddHandler GestureHandler.Pan, AddressOf Me.GestureHandler_Pan
  18.         End If
  19.     End Sub
  20.  
  21.     Private Sub GestureHandler_Pan(ByVal sender As Object, ByVal e As Windows7.Multitouch.GestureEventArgs)
  22.         Dim s As System.Drawing.Size = e.PanTranslation
  23.  
  24.         Me.ScrollToVerticalOffset( Me.VerticalOffset - s.Height)
  25.     End Sub
  26.  
  27. End Class

Download the VB.NET code here

Download the C# code here

 

NOTE: It does require hit testing if using multiple scrollviewers in the same window.

Binary hacking an executable part duex

A couple of the tools I use for binary hacking:

One of the problems with binary hacking a .net executable is references. Say you have an executable and a .dll file that is referenced by the executable. If you modify the .dll and resign it with a new public key token, the executable's reference will be broken.

You are welcome to download the following code and binaries to "crack" along with me.

Crack Me Test files

In the zip file above, I have the following files:

crack01

In the Common Library class library code, is the following:

Code Snippet
  1.     Public Shared Function IsLicensed() As Boolean
  2.         Dim retval As Boolean = False
  3.         retval = False
  4.         Return retval
  5.     End Function

<rant>This is BAD for you to protect your executables this way. There are even professional .NET component designers who use methods like this. All you have to do is change the false to a true and it is cracked. Please, you are selling these components to developers, some who know how to crack, and most know how to use reflector at least. Duh!</rant>

Open up ILDASM by typing ILDASM at the visual studio command prompt. Once you open the CommonLibrary.dll Go to the view menu, and choose "show bytes". Navigate to the method you wish to crack, in this case the CommonLibrary.LicenseProtector.IsLicensed() function and double-click on it. crack02 This brings up the IL code for it, but more importantly, by turning on the "show bytes" it allows you to find this method in the binary file.

Now go ahead and open the CommonLibrary.dll in UltraEdit or any other binary editor. We are going to change the false to a true.

According to the picture above on the right, we are looking for the following hex code 16 0B 16 0B 07 2A. Your code may vary. Once we find it, and are sure we are in the right place by searching again for it, we can now edit it. Change the 16s to 17s. This makes the false to a true. crack03

This is how it looks after. 17 0B 17 0B 07 2A.

Now that we've cracked it, we have to re-sign it with a public key. Run the following, which creates a crack.snk key file.

sn.exe -k crack.snk

Then we can run the SNReplace. The code for that is at the top of the article, create a console app and paste that code there.

snreplace.exe commonlibrary.dll crack.snk

Now, open the CrackMeTest.exe in reflector and the commonlibrary.dll in reflector. When you click on the CrackMeTest.exe in reflector, you will see the public key token, which is 82db601ed5cd3521 (On my machine). Since you re-signed the commonlibrary.dll you will see a different public key token. If you navigate in Reflector to the method CommonLibrary.LicenseProtector.IsLicensed() you will see it returns true.

crack06

Great, but now we have to fix the reference between the exe and dll. Write down the public key tokens for both. Now we run the resigner on the executable.

snreplace.exe CrackMeTest.exe crack.snk

This will change the public key of the executable to the same as the dll file. Plus it will help us, since we won't have duplicates for the public key since we re-signed our exe.

Open the exe in UltraEdit. We are looking for the old key, which in this case is 82 DB 60 1E D5 CD 35 21 (May be different on your machine). When we find it, we just swap that out with the new key, and then we re-sign the executable again. Voila, the reference to the .dll has changed to the new key.

kick it on DotNetKicks.com

Multitouch table – Step 4 – Fitting the wood and LCD in the hole

I started with a table that was perfect for this, as it almost fit the LCD perfectly. They sold it to me cheap too because the hole in the table did not have glass (they apparently broke or lost it).

So I took the side rails off the hole, and replaced them lower in the hole to support the LCD monitor.

After dry fitting the monitor, I drilled the two holes at a 45 degree angle so I could place the lasers. One I drilled perfect, the other had to be adjusted.

 

Going forward, I need to find a permanent solution for mounting the camera above the monitor, and some type of lip for the rim. I used black

duct tape for the rim currently, but it's not the perfect solution.

 
 
 
Photo gallery

Changing the URL for TFS 2008

I've seen many sites for changing the URL in TFS, but they usually refer to TFS 2005. Here's my way of changing it on TFS 2008.

Step 1. Run the command TFSAdminUtil ActivateAT tfs.mycompany.com

Step 2. Start RegEdit and Navigate to the following key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\TeamFoundation\ReportServer\80\Sites

and change the two string values BaseReportsUrl and ReportsService.

Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\TeamFoundation\Servers and edit the server string value.

Step 3. Go to C:\Program Files\Microsoft Visual Studio 2008 Team System Web Access\Web and edit the web.config under <tfServers>

Step 4. Go to C:\Program Files\Microsoft Visual Studio 2008 Team Foundation Server\TFSServerScheduler and edit the TFSServerScheduler.exe.config, and edit the key TFSNameUrl

Step 5. Go to Start > All Programs > Administrative Tools > SharePoint 3.0 Central Administration. Navigate to Operations > Alternate Access Mappings (under Global Configuration). Add two mappings for Internal URLs

http://tfs.mycompany.com Zone: Intranet

http://tfs.mycompany.com:17012 Zone: Intranet

You need to do this so the document node in Team Explorer will map to the proper URL, and for the portal and project creation to work properly.

You should do a IISRESET or reboot.

Multitouch table – Step 3 - Testing

Well, I got the laser goggles yesterday, so I am testing the lasers now. I mounted my lasers

The lasers are "near infrared" meaning they have a faint glow, but you can't really see the beam. You should not only wear safety laser goggles, but don't look directly into the beam. I've got 90 degree line generators on the front of the lasers. This shoots a 90 degree sheet of laser light, and when your finger touches the laser, your fingers "glow" so the camera can pick them up.

So I tested with the Multitouch Vista WPF app, and it works great. See the video below.

Watch in HD here.

Multitouch table – Step 2 – Getting lasers and stuff

Well, I found out that the back of the LCD glass reflects IR back at the camera, so the blobs don't work very well.

So, the solution is to get lasers. I got two 780nm 25mw near-infrared lasers, with a 90 degree line generators. I got the power supply for it too, but now I am waiting for the laser goggles to wear, so I don't burn my eyes out.