Getting back into the Silverlight world as it's been too long. With the release of Silverlight 3 being the biggest instigator. Since working with Silverlight 1.0, 1.1 (2.0), and coming from a Windows/MFC/C/C++ development background, I always thought the lack of Bitmap manipulation and limited effects was s big deficiancy in Silverlight. Now that Silverlight 3 has come out, it looks like there maybe some light at the end of the tunnel.
I have just gone through a great video on Pixel Shaders :
http://silverlight.net/learn/learnvideo.aspx?video=187303
So it's now going to be time to bring back the memories of all those math classes from school, and see what kind of cool effects I can come up with.
Might start with some each ones like the flips in the video. This can be done with rotations and projections in Silverlight already, but this will give me some good ground work for moving to more complex effects. Too bad I can't think of one right now. :)
Also, I have to look into the Bitmap API that is now part of Silverlight 3. I wonder what goodies lay there.
BTW.. if you are adding a pixel shader file as a resource to your project, make sure you put a forward slash just before your project name in the new Uri you build up. I believe the video is using a slightly older release than is currently available.
so :
UriSource = new Uri("/MyVideoProject;component/Swirl.ps", UriKind.Relative)
All for now. Time to play :)
Sunday, July 12, 2009
Monday, June 1, 2009
Nintex Workflow - Execute SQL to PostgreSQL on a 64-bit server
Time to get back into the blogging, if only to keep my mind fresh and to keep track of what I find in my geeking.
After some talks with a friend of mine last night, we decided to check out PostgreSQL, seeing as for a simple application, MSSQL Express was taking up way too much diskspace and memory.
So, I thought I'd try out Nintex Workflow and specifically the Execute SQL action with ODBC checked. The bonus here, being that I wouldn't have to write code.
Installing PostgreSQL and it's ODBC driver was really quick and painless. The odd thing I found, was that on my Windows Server 2008 64-bit, when I clicked on Adminstrative Tools->Data Sources (ODBC), the PostgreSQL driver did not appear in the Drivers tab. Which also meant, that I couldn't create a DSN to my database.
Some hunting around, and I found that on Windows Server 2008, there is another ODBC Manager that is located in c:\Windows\SysWow64 and it is odbcad32.exe. This is the 32-bit version of the ODBC Manager, and the PostgreSQL driver appeared in there. I was now able to create a DSN and test the connection successfully.
I then configured the Execute SQL action in Nintex Workflow, but I still received the same error about "No data source....". So, time to get back to development and write some C# code that uses the OdbcConnection class. Funnily enough, I received the same error. When I changed my build configured to x86 it worked.
Conclusion :
PostgreSQL only has a 32-bit ODBC driver. If you have installed Nintex Workflow on a 64-bit Server, then it will not be able to access your database. I would assume that this would be the case for other databases that don't have a 64-bit version of their ODBC driver. Hopefully Oracle and MySQL do, but I don't have the time currently to investigate them.
Note :
I thought I might be able to recompile the PostgreSQL ODBC driver into 64-bit to see if that would work, but I'm having trouble find some header files. The hunt continues.
After some talks with a friend of mine last night, we decided to check out PostgreSQL, seeing as for a simple application, MSSQL Express was taking up way too much diskspace and memory.
So, I thought I'd try out Nintex Workflow and specifically the Execute SQL action with ODBC checked. The bonus here, being that I wouldn't have to write code.
Installing PostgreSQL and it's ODBC driver was really quick and painless. The odd thing I found, was that on my Windows Server 2008 64-bit, when I clicked on Adminstrative Tools->Data Sources (ODBC), the PostgreSQL driver did not appear in the Drivers tab. Which also meant, that I couldn't create a DSN to my database.
Some hunting around, and I found that on Windows Server 2008, there is another ODBC Manager that is located in c:\Windows\SysWow64 and it is odbcad32.exe. This is the 32-bit version of the ODBC Manager, and the PostgreSQL driver appeared in there. I was now able to create a DSN and test the connection successfully.
I then configured the Execute SQL action in Nintex Workflow, but I still received the same error about "No data source....". So, time to get back to development and write some C# code that uses the OdbcConnection class. Funnily enough, I received the same error. When I changed my build configured to x86 it worked.
Conclusion :
PostgreSQL only has a 32-bit ODBC driver. If you have installed Nintex Workflow on a 64-bit Server, then it will not be able to access your database. I would assume that this would be the case for other databases that don't have a 64-bit version of their ODBC driver. Hopefully Oracle and MySQL do, but I don't have the time currently to investigate them.
Note :
I thought I might be able to recompile the PostgreSQL ODBC driver into 64-bit to see if that would work, but I'm having trouble find some header files. The hunt continues.
Labels:
64-bit,
Nintex Workflow,
ODBC,
PostgreSQL
Monday, November 19, 2007
Add Reference to a non signed (strong typed) assembly
Recently, I had to work with the Visual SourceSafe api. I added a reference to the api via the Add Reference (COM), but my assembly was strongly typed and the Interop.SourceSafeTypeLib was not.
So, here's what a find while searching the best way to do this.
1. DO NOT [Add Reference (COM)].
2. Find the original assembly C:\Program Files\Microsoft Visual SourceSafe\\ssapi.dll
3. run the TLBIMP.exe application on it
C:\Program Files\Microsoft Visual SourceSafe\ssapi.dll" /keyfile:myproj.snk /out:Interop.SourceSafeTypeLib.dll4. You now have a signed/strongly typed assembly
5. Add Reference -> Browse to Interop.SourceSafeTypeLib.dll
6. Smile and admire what a great achievement that was!!!
So, here's what a find while searching the best way to do this.
1. DO NOT [Add Reference (COM)].
2. Find the original assembly C:\Program Files\Microsoft Visual SourceSafe\\ssapi.dll
3. run the TLBIMP.exe application on it
C:\Program Files\Microsoft Visual SourceSafe\ssapi.dll" /keyfile:myproj.snk /out:Interop.SourceSafeTypeLib.dll4. You now have a signed/strongly typed assembly
5. Add Reference -> Browse to Interop.SourceSafeTypeLib.dll
6. Smile and admire what a great achievement that was!!!
Wednesday, October 17, 2007
Clearing the ClickOnce Application Cache
Recently I have been looking into hosting an XBAP object inside a Vista Sidebar Gadget.
I didn’t hit any major hurdles, until I tried to change the XBAP object and realized that the gadget was still loading an old version. The same thing happens if I double click on the XBAP file (in my debug folder) and it gets loaded in IE. Once it’s loaded for the first time, it gets installed into a cache. I tried clearing the IE cache, but that didn’t help.
XBAP gets installed via the ClickOnce functionality, into the ClickOnce Application Cache.
In order to clear it, there is a useful command line app that comes with .Net Framework 2.0.
1. Open a command line (Start->cmd)
2. mage –cc
Where I found the info :
http://mattfaus.com/blog/2007/07/31/clear-clickonce-application-cache/
Writing C/C++ code to call into the windows dll that actually opens up this functionality :
http://bombayboy.wordpress.com/2006/07/03/
I didn’t hit any major hurdles, until I tried to change the XBAP object and realized that the gadget was still loading an old version. The same thing happens if I double click on the XBAP file (in my debug folder) and it gets loaded in IE. Once it’s loaded for the first time, it gets installed into a cache. I tried clearing the IE cache, but that didn’t help.
XBAP gets installed via the ClickOnce functionality, into the ClickOnce Application Cache.
In order to clear it, there is a useful command line app that comes with .Net Framework 2.0.
1. Open a command line (Start->cmd)
2. mage –cc
Where I found the info :
http://mattfaus.com/blog/2007/07/31/clear-clickonce-application-cache/
Writing C/C++ code to call into the windows dll that actually opens up this functionality :
http://bombayboy.wordpress.com/2006/07/03/
SQL Stored Procedure - statistics
If you have a stored proc that is doing a lot of work, you can put :
SET STATISTICS IO ON
before the exec call, run your stored proc and it will tell give you some statistics on the execution.
Example:
DECLARE @return_value int
SET STATISTICS IO ON
EXEC @return_value = [dbo].[MyStoredProc]
GO
It will tell you the table that a query is running against, scan count, logical reads, physical reads, read-ahead reads and more. This might point you in the right direction as to how to improve the speed of your application, that is making calls to the database.
I know there are other ways, like using Query Analyzer and a Profiler, but this is a quick and dirty way.
SET STATISTICS IO ON
before the exec call, run your stored proc and it will tell give you some statistics on the execution.
Example:
DECLARE @return_value int
SET STATISTICS IO ON
EXEC @return_value = [dbo].[MyStoredProc]
GO
It will tell you the table that a query is running against, scan count, logical reads, physical reads, read-ahead reads and more. This might point you in the right direction as to how to improve the speed of your application, that is making calls to the database.
I know there are other ways, like using Query Analyzer and a Profiler, but this is a quick and dirty way.
Sunday, August 5, 2007
ActiveX Deployment, CRT, MFC
I had the pleasure of writing an ActiveX control, and I found that those pc's that didn't have MFC, the control wouldn't work. Obviously I was linking in MFC as a shared dll. So I changed it to a static link, and although it was better, I had another error in the event long. Turns out, that I also needed the c++ runtime.
So here what I found needs to be done, in order to build your ocx (ActiveX) control into a deployable cab.
MFC80.DLL
MSVCR80.DLL
MSVCP80.DLL (optional - put in there only if you need it)
Microsoft.VC80.CRT.manifest
Microsoft.VC80.MFC.manifest
These files can be found in these folders:
\program files\microsoft Visual Studio 8\vc\redist\x86\Microsoft.VC80.MFC
and
\program files\microsoft Visual Studio 8\vc\redist\x86\Microsoft.VC80.CRT
All of the above need to be added into your INF file, prior to calling makecab.
MSDN Link
A good example of an INF file is the following :
[version]
signature="$CHICAGO$"
AdvancedINF=2.0
[Add.Code]
PsPrintReports.ocx=PsPrintReports.ocx
MSVCR80.dll=MSVCR80.dll
MFC80.dll=MFC80.dll
Microsoft.VC80.CRT.manifest=Microsoft.VC80.CRT.manifest
Microsoft.VC80.MFC.manifest=Microsoft.VC80.MFC.manifest
[Microsoft.VC80.MFC.manifest]
file-win32-x86=thiscab
[Microsoft.VC80.CRT.manifest]
file-win32-x86=thiscab
[MFC80.dll]
file-win32-x86=thiscab
[MSVCR80.dll]
file-win32-x86=thiscab
[PsPrintReports.ocx]
file-win32-x86=thiscab
clsid={13FDEB06-7AF2-44CC-AE6B-3AB8F4C3D2AE}
FileVersion=1,0,0,3
RegisterServer=yes
Cheers,
I hope this helps someone else.
So here what I found needs to be done, in order to build your ocx (ActiveX) control into a deployable cab.
MFC80.DLL
MSVCR80.DLL
MSVCP80.DLL (optional - put in there only if you need it)
Microsoft.VC80.CRT.manifest
Microsoft.VC80.MFC.manifest
These files can be found in these folders:
\program files\microsoft Visual Studio 8\vc\redist\x86\Microsoft.VC80.MFC
and
\program files\microsoft Visual Studio 8\vc\redist\x86\Microsoft.VC80.CRT
All of the above need to be added into your INF file, prior to calling makecab.
MSDN Link
A good example of an INF file is the following :
[version]
signature="$CHICAGO$"
AdvancedINF=2.0
[Add.Code]
PsPrintReports.ocx=PsPrintReports.ocx
MSVCR80.dll=MSVCR80.dll
MFC80.dll=MFC80.dll
Microsoft.VC80.CRT.manifest=Microsoft.VC80.CRT.manifest
Microsoft.VC80.MFC.manifest=Microsoft.VC80.MFC.manifest
[Microsoft.VC80.MFC.manifest]
file-win32-x86=thiscab
[Microsoft.VC80.CRT.manifest]
file-win32-x86=thiscab
[MFC80.dll]
file-win32-x86=thiscab
[MSVCR80.dll]
file-win32-x86=thiscab
[PsPrintReports.ocx]
file-win32-x86=thiscab
clsid={13FDEB06-7AF2-44CC-AE6B-3AB8F4C3D2AE}
FileVersion=1,0,0,3
RegisterServer=yes
Cheers,
I hope this helps someone else.
Thursday, July 26, 2007
Silverlight Holdem Calculator
Building on my Silverlight skills, I decided to play with creating a Silverlight Holdem Calculator. Rather than doing some sort of calculation or lookup to a database, I decided to reuse some code I've played around with before.
The code that deals with the holdem hands, is based on Wesley Varela & Jonathan Feldkamp's PokerCardLibrary. I believe they've made changes to it since I got my hands on it a few years back, but at the same time, I've made some tweaks to it myself.
The goal of this little project, was not to create the best Holdem Calculator. There are many of those out there, and they work much faster and smoother than this one. The goal was to play around with multi-threading, and synchonization of objects and lists in Silverlight.
Step 1
Create a table that seats atleast 10 players.
Basically, a Rectangle object, with Radius X and Y of 200. Give the table Fill a Radial Gradient that goes from Black to a Dark Green. This gives the appearance of a poker table top.
Generate a Canvas of each of the 10 players, and place two images in the canvas, one overlapping the other slightly. Add a TextBox underneath the two images for any messages for that player.
I could have written some code to calculate the exact position of all the players around the table, but I chose not to give myself a headache for now. Each of those canvases probably should have been their own UserControl, but that can be left for later if I decided to refactor this project.

Step 2
Create the Card Selector.
This is a UserControl that has 52 other UserControls inside it. Why 52? One for each card in a deck, not including jokers ofcourse. I considered handle events for left mouse down on every one of the cards, but decided it'd be much easier to handle one left mouse down event (for the main card selector canvas), and then calculate which card was clicked on based on the mouse point.
The last thing I added to the single card canvas, was the ability to set the back of a card, as the image, when a card is already in use. That way, when a user is selecting a card, they can't give (deal) the same card to two players. (This is a single deck game :P)

Step 3
Warning messages.
I realised that if a user clicks on the "Calculate" button, and the cards haven't been selected properly, then there was no notification to the user. So I whipped up the canvas you see below. This fades is, and lets the player know what they need to do. Simple canvas with title TextBox, body TextBox, and a GlassButton based on a few messages on the Silverlight.net forums.

Step 4
Creating the Holdem Calculator Thread.
I didn't know what the threading was like in Silverlight, so I finally am at a stage where I can try it out. I'm still learning to see what it's like, and one of the things I still haven't looked into, is whether Events can be set by other threads (thread safe?). One of these days, I'll have the time.
Basically, I start up a thread like this :
The calculating thread works on the Monte Carlo algorithm. Basically, it runs through a set number of scenarios, and gives you the results back. In my example app, I run through 3,000 hands. It may not sound like a lot, but that's what I found was a reasonable sample size, that didn't take a huge amount of time to calculate while running in IE.
I'll be looking at converting this to Keith Rule's Fast, Texas Holdem Hand Evaluation and Analysis code in the future, so I can increase my sample size, and therefore get more accurate results.
With each calculation, the thread adds a message to a static object MessageQueue. This class has all static member variables and methods, and wraps all calls to the Queue object with a Mutex, so that it is thread-safe. The MessageQueue is based on the Observer Pattern. I've made one of my controls/pages inherit from a IObserver class that I have created, and added to the list of observers that want to monitor the MessageQueue.
The notifications will set an event in the observer class, and a timer that is running on that class will notice the event (WaitHandle.WaitOne() call), and then pop the message off the queue and do what is required. In this instance, it is display the state of the calculation. The reason for the event, is that a call from calculating thread, can not make a call in your UI thread, and make changes to UI (IVisual) objects. So this is the reason for the event Timer work-around.

Step 5
Calculation Complete.
Now that the calculation thread has finished, a message is posted to the MessageQueue, and when the Page realises it's the "completed" message, it displays the win percentage for each of the players.

TO DO:
1. community cards (up to the 4th [turn] card)
2. try a different calculating algorithm (Keith Rule's)
3. add a "cancel" or "stop" button
4. omaha calculator??? maybe not. I'm pretty busy with work at the moment to take this on
5. think of other things to do I guess.
Link to try the Holdem Calculator out
I'll be releasing the source code to this, but it's kind of a mess at the moment. Watch this space.........
The code that deals with the holdem hands, is based on Wesley Varela & Jonathan Feldkamp's PokerCardLibrary. I believe they've made changes to it since I got my hands on it a few years back, but at the same time, I've made some tweaks to it myself.
The goal of this little project, was not to create the best Holdem Calculator. There are many of those out there, and they work much faster and smoother than this one. The goal was to play around with multi-threading, and synchonization of objects and lists in Silverlight.
Step 1
Create a table that seats atleast 10 players.
Basically, a Rectangle object, with Radius X and Y of 200. Give the table Fill a Radial Gradient that goes from Black to a Dark Green. This gives the appearance of a poker table top.
Generate a Canvas of each of the 10 players, and place two images in the canvas, one overlapping the other slightly. Add a TextBox underneath the two images for any messages for that player.
I could have written some code to calculate the exact position of all the players around the table, but I chose not to give myself a headache for now. Each of those canvases probably should have been their own UserControl, but that can be left for later if I decided to refactor this project.

Step 2
Create the Card Selector.
This is a UserControl that has 52 other UserControls inside it. Why 52? One for each card in a deck, not including jokers ofcourse. I considered handle events for left mouse down on every one of the cards, but decided it'd be much easier to handle one left mouse down event (for the main card selector canvas), and then calculate which card was clicked on based on the mouse point.
The last thing I added to the single card canvas, was the ability to set the back of a card, as the image, when a card is already in use. That way, when a user is selecting a card, they can't give (deal) the same card to two players. (This is a single deck game :P)

Step 3
Warning messages.
I realised that if a user clicks on the "Calculate" button, and the cards haven't been selected properly, then there was no notification to the user. So I whipped up the canvas you see below. This fades is, and lets the player know what they need to do. Simple canvas with title TextBox, body TextBox, and a GlassButton based on a few messages on the Silverlight.net forums.

Step 4
Creating the Holdem Calculator Thread.
I didn't know what the threading was like in Silverlight, so I finally am at a stage where I can try it out. I'm still learning to see what it's like, and one of the things I still haven't looked into, is whether Events can be set by other threads (thread safe?). One of these days, I'll have the time.
Basically, I start up a thread like this :
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadCalculator), holdemGame);
The calculating thread works on the Monte Carlo algorithm. Basically, it runs through a set number of scenarios, and gives you the results back. In my example app, I run through 3,000 hands. It may not sound like a lot, but that's what I found was a reasonable sample size, that didn't take a huge amount of time to calculate while running in IE.
I'll be looking at converting this to Keith Rule's Fast, Texas Holdem Hand Evaluation and Analysis code in the future, so I can increase my sample size, and therefore get more accurate results.
With each calculation, the thread adds a message to a static object MessageQueue. This class has all static member variables and methods, and wraps all calls to the Queue
The notifications will set an event in the observer class, and a timer that is running on that class will notice the event (WaitHandle.WaitOne() call), and then pop the message off the queue and do what is required. In this instance, it is display the state of the calculation. The reason for the event, is that a call from calculating thread, can not make a call in your UI thread, and make changes to UI (IVisual) objects. So this is the reason for the event Timer work-around.

Step 5
Calculation Complete.
Now that the calculation thread has finished, a message is posted to the MessageQueue, and when the Page realises it's the "completed" message, it displays the win percentage for each of the players.

TO DO:
1. community cards (up to the 4th [turn] card)
2. try a different calculating algorithm (Keith Rule's)
3. add a "cancel" or "stop" button
4. omaha calculator??? maybe not. I'm pretty busy with work at the moment to take this on
5. think of other things to do I guess.
Link to try the Holdem Calculator out
I'll be releasing the source code to this, but it's kind of a mess at the moment. Watch this space.........
Subscribe to:
Posts (Atom)
