SpriteHand
Module Border
  Most recent blog entries
Module Border
Codeplex Adventures
Andy's Blog By Andy Beaulieu on 12/28/2006 3:43 PM

I published the Ajax Sprite Toolkit as a Codeplex project today, which was my first experience using Microsoft's open source hosting.

It wasn't a hideous experience, but it wasn't perfect either.

After requesting a new project, I only had to wait a few days for an approval email which included login and some other basic information. Not bad considering they are limiting the number of new projects and I submitted the request right around the holidays!

I was surprised to find out that Codeplex uses VS Team Foundation Server as a Source Control Provider. So what does an open source developer do if he doesn't own VS Team System? Well, Microsoft provides a free Team Explorer Client which can be used for developers wanting to contribute to a Codeplex project. But the download is an immense 246 MB .img file. ugh.

On a positive note, I have so far found the Codeplex project management functionality to be pretty good. They provide basic Forums, Issue Tracker, License, and Wiki pages which (aside from some less than intuitive interface design) all worked as advertised.

 

Comments (0)

Ajax Sprite Toolkit
Andy's Blog By Andy Beaulieu on 12/22/2006 8:23 AM

When I first learned of the cool Animations in ASP.NET AJAX, I was thinking, maybe it would be easier to make simple javascript games - you know, like DHTML Lemmings or Bunny Hunt or these other games.

But, I was frustrated over the lack of collision detection and frame-based image support... So I thought, why not try and create a few behaviors to make simple javascript games easier to develop using ASP.NET AJAX?

So here is what I came up with: The Ajax Sprite Toolkit. It contains a couple of behaviors and extender controls for Sprite support as well as a behavior for Scott Schiller's Javascript to Flash Sound API. Scott's API uses a Flash object to provide mixed sound to Javascript.

There are a couple of tutorials as well as this Fish Game to get an idea of what its all about.

This is an initial beta that I've tested under XP and Vista using IE6, IE7, and Firefox. If anyone has other flavors, especially Mac browsers, please let me know how it does.

[Ajax Sprite Toolkit Project Page]

Comments (1)

WPF/E CTP Released
Andy's Blog By Andy Beaulieu on 12/5/2006 7:51 AM

WPF/E allows you to use a subset of XAML on multiple platforms (Windows and Macintosh so far but there are rumors of "possibly" even Linux and Solaris). Microsoft has released the first public CTP which you can download here.

Once you install, there is a collection of WPF/E Samples on Channel9 including this Sprawl Game which (what can I say) feels a lot like a Flash game!

Comments (0)

By Your Command
Andy's Blog By Andy Beaulieu on 12/1/2006 9:15 AM

Controlling stuff from a web page is really cool. By stuff, I mean stuff in the real world, like lights, household appliances, or perhaps... killer robots.

While it's still tough to find an affordable automaton in the "killer robot" category, there are some fairly inexpensive alternatives like the version 1.0 Robosapien. This model is a bit less expensive because the Robosapien Version 2.0 is now the hot item for Christmas.

These robots are controlled via an Infrared remote, much like your TV or cable box. So how do we go about controlling Infrared devices from our PC using .NET?

STEP 1: Get an IR Blaster
First your PC needs a device to transmit IR signals. You can certainly build your own IR transmitter, but I found that for just $12, you can get a very good quality device from
www.irblaster.info.

Here is what the $12 device looks like. It has a basic DB9 Connector to fit into an available COM port:

STEP 2: Setup WinLIRC
WinLIRC is an open source program that allows you to transmit and receive infrared remote signals. When you run WinLIRC, you get a config dialog where you select the COM port that your IR transmitter sits on.

Notice the "Config" textbox at the bottom. WinLIRC works off config files which store remote code information for different devices. There is an extensive database of remote codes already available for a whole bunch of IR devices.

For the Robosapien, Eric Buehl created a compatible config file as part of a project. You can download his config file here

Once you download your config file and enter it into the WinLIRC configuration screen, you can select OK.

Now you will be at the WinLIRC test screen. Here you can select a remote (defined in your config file) and send a code to the IR device. I call this a "test screen" because that's all its really good for - making sure that your IR Blaster and config file are all working happily.

Is it working? Is your PC making the device do stuff? Cool, then you can click the "Hide Window" button which will make WinLIRC disappear into your system tray and appear like a little virtual LED light:

 

STEP 3: Using WinLIRC as a Server
Using the WinLIRC test screen is fun and all, but we want to control our IR device from some .NET code! To do this, WinLIRC provides a telnet server which we can communicate with on TCP port 8765.

To test the telnet server you can open a command prompt and type:

telnet 127.0.0.1 8765

...after which you will be logged into the WinLIRC telnet service. There are a few basic commands you can type here, such as:

LIST                             
(gives a list of available remotes from your config)

LIST [REMOTE name]  
(gives a list of remote codes available on a remote)

Now, to send an actual IR command, there is some security in place here. After all, this is a telnet server and if you are not behind a firewall, any lame hacker could come in and start using your killer robot against you!! 

So to send IR codes through the telnet server, we need to add a password to our registry. Run Regedit and go to the HKEY_LOCAL_MACHINE\SOFTWARE\LIRC node. Add a new String value named password with the value of a password:

Now, in a telnet session, you can use a command to send IR signals in this format:

[PASSWORD] [REMOTE] [CODE] [# repeats]

For example, to have my SONY-TV change to channel 4, I would use the command:

password SONY-TV 4 1

STEP 4: Using the WinLIRC Telnet Service from .NET
.NET makes a lot of things easy, including Telnet! To perform a telnet session to the WinLIRC server and send a command, the code is short and sweet:

TcpClient client = new TcpClient("127.0.0.1", 8765);

Stream s = client.GetStream();

StreamWriter sw = new StreamWriter(s);

sw.AutoFlush = true;

sw.WriteLine("password SONY-TV 4 1");

sw.Close();

s.Close();

client.Close();

NEXT STEPS
Oh, so much to do! We could create an ASP.NET page to send whatever IR codes we want to our household appliances! We could create a queuing mechanism so that multiple users could submit commands to the devices simultaneously! We could create an army of Robosapiens equipped with Lasers and control them all from the comfort of our keyboard.

Comments (0)

Book Review: Foundations of WF
Andy's Blog By Andy Beaulieu on 11/8/2006 7:56 AM

Looking for a good intro to Windows Workflow Foundation?

For most people, the best way to learn is by example. And that seems to be the creed behind "Foundations of WF" by Brian Myers. This book is short on theory and long on example as it takes the reader through scads of Windows Workflow Foundation activities.

It's a skinny book at just 224 pages plus index but no paper is wasted as the author fires up his first solution walk-thru on page 4. From there on, it's all code as the author builds on previous chapters to show how to use many WF activities.

Chapter 10 pulls together the previous sections with a final real world example: an Employee Performance Review application implemented in ASP.NET and SQL Server.

If you're looking for lots of WF theory and concepts, look elsewhere. But "Foundations of WF" by Brian Myers has much to offer to the kinesthetic learner.

Comments (0)

Submit using Enter on multiple controls
Andy's Blog By Andy Beaulieu on 10/9/2006 6:48 PM

ASP.NET 2.0 adds the DefaultButton property, which allows you to specify which button causes a postback when the Enter key is pressed.

But what if you have multiple controls on the page that could potentially cause a postback? For example, maybe you have multiple search textboxes on your page - any of which the user should be able to press Enter on and cause a postback?

In the example below we will assume there is a textbox named "txtFind" and when the user hits <enter> on txtFind, we want to execute a Postback on btnFind.

First we add a client-side handler to the control that should cause the postback when enter is hit. You also pass in the ClientId of the element you want to cause the postback:

txtFind.Attributes.Add("onkeydown", "return OnKeyDown(event, '" + btnFind.ClientID + "');");

Then we need to add some script to handle that event in both IE and Mozilla -

    function OnKeyDown(e, submitButton)

    {

        var nKey = -1;

        var sourceElement;

 

        if (e && e.which)

            nKey = e.which;    // NS

        else

            if (window.event && window.event.keyCode)

                nKey = window.event.keyCode;  // IE

       

        if (nKey == 13)

        {

             document.getElementById(submitButton).click();

             return false;

        }

 

        return true;

    }

 

Comments (0)

Notes for ASP.NET Class
Andy's Blog By Andy Beaulieu on 9/13/2006 1:25 AM

Here are some various notes for the ASP.NET class that I am teaching this week (more to come):

A Visual Studio Add-In That Converts C# Code To Visual Basic
VB.NET Naming Conventions
CSS Friendly ASP.NET 2.0 Control Adapters (Beta 2.0)

Enterprise Library
(for .NET 2.0)
Exception Handling Block
Logging Application Block
(for .NET 1.1)

Upcoming Local Events
Next Code Camp in Waltham
Next MSDN Event in Syracuse

ASP.NET Performance Tips
Keep Sites Running Smoothly By Avoiding These 10 Common ASP.NET Pitfalls
10 Tips for Writing High-Performance Web Applications

A "Complete" Data Grid Example for ASP.NET 1.1
       
Zip Download

AJAX/Atlas
     
Scriptaculous
      Fiddler Tool

Data Access Layer
     
ActionPack
      ActionPack Video Intro

Simple Printing from the browser
(Method 1) Add some Javascript to an HTML button

(Method 2) Add some Javascript to a Button from the server side:
Button2.Attributes.Add("onclick", "window.print(); return false;")

Note that Method 2 can also be used for other things like a Confirm dialog for a postback

Button1.Attributes.Add("onclick", "return confirm('Are you sure?')")

Dynamically Enabling Page Caching, Based on DEBUG Mode
Because of the headaches that page caching can cause when you are in development mode, you may want to dynamically enable or disable page caching based on something like a compiler constant:

#If DEBUG Then
   
lblStatus.Text = "*NOT* using output caching (debug mode)"
#Else
   
Response.Cache.SetExpires(Date.Now.AddMinutes(20))
   
lblStatus.Text = "using output caching (Production mode)"
#End If


 

Comments (0)

"Atlas" gets a Name
Andy's Blog By Andy Beaulieu on 9/12/2006 6:49 AM

... from a post by Scott Guthrie where he also estimates the v1.0 release "around the end of this year."

1) The client-side “Atlas” javascript library is going to be called the Microsoft AJAX Library. This will work with any browser, and also support any backend web server (read these blog posts to see how to run it on PHP and ColdFusion).

2) The server-side “Atlas” functionality that nicely integrates with ASP.NET will be called the ASP.NET 2.0 AJAX Extensions. As part of this change the tag prefix for the “Atlas” controls will change from <atlas:>to <asp:>. These controls will also be built-in to ASP.NET vNext.

3) The “Atlas” Control Toolkit today is a set of free, shared source controls and components that help you get the most value from the ASP.NET AJAX Extensions. Going forward, the name of the project will change to be the ASP.NET AJAX Control Toolkit.

Comments (0)

ReportViewer Control - Customization at Runtime
Andy's Blog By Andy Beaulieu on 8/30/2006 7:14 AM

Let's say you just created a really cool Report for the .NET 2.0 ReportViewer Control (well, as cool as a report can be anyway).

But wait... At runtime, you want to examine and maybe even change attributes of the report. Like column names, labels, etc.

How do we get at Report properties at runtime?

One way is to tweak the RDLC (Client Report Definition) file before it is fed to the ReportViewer Control. RDLC is based on XML, so we can use XPath queries to find and tweak RDLC properties.

There is a post here that describes this method, and another example below.

First we create a utility function to load in the RDLC and tweak or examine it as necessary...

private TextReader GetCustomRDLC(string rdlcSource)

{

    TextReader readerReport;

    XmlDocument xmlReport = new XmlDocument();

    Stream streamReport;

 

    streamReport = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(rdlcSource);

 

    xmlReport.Load(streamReport);

 

    XmlNamespaceManager nsManager = new XmlNamespaceManager(xmlReport.NameTable);

    nsManager.AddNamespace("dns", "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");

 

    XmlNodeList nodes = xmlReport.SelectNodes("//dns:Table[@Name='table1']//dns:Details//dns:Textbox", nsManager);

 

    foreach (XmlNode node in nodes)

    {

        System.Diagnostics.Debug.WriteLine(node.Attributes["Name"].Value);

    }

 

    return new StringReader(xmlReport.OuterXml);

 

}

... then we can use this function to feed the ReportViewer Control...

 

 

// create a datasource for the report and set to the datatable dt1

ReportDataSource rds = new ReportDataSource();

rds.Name = "DataSet2_Employees";

dt1.DefaultView.Sort = "FirstName";

rds.Value = dt1.DefaultView;

 

 

 

reportViewer1.LocalReport.DataSources.Clear();

reportViewer1.LocalReport.DataSources.Add(rds);

 

reportViewer1.LocalReport.LoadReportDefinition(GetCustomRDLC("ReportViewerTest.Report2.rdlc"));

 

reportViewer1.RefreshReport();

Comments (0)

Marshaling a Byte Array to COM object
Andy's Blog By Andy Beaulieu on 8/25/2006 7:05 AM

I have been helping someone port a Delphi app to WindowsForms and we ran into something interesting. The Delphi app uses a 3rd-party ActiveX control to display spreadsheets. Unforunately, the ActiveX control has not been ported to .NET, and the Delphi app stores the spreadsheet control data as a proprietary format BLOB in the database.

The ActiveX control had documentation for the method we needed to call:

Syntax
ReadFromBlob hBlob, nReservedBytes

Part           Type       Description
hBlob          OLE_HANDLE Reference to a BLOB variable in memory.
nReservedBytes Integer    Size of the BLOB variable. Not implemented in this version and must be 0.

So, after adding the ActiveX control to WindowsForms, how to feed it these bytes? We need to create an unmanaged buffer to hold the data and get that to the method. We can use AllocCoTaskMem of the Marshal class to allocate the unmanaged buffer and then marshal it to the ActiveX control...

// assume we have a byte array inside byteData read from DB.
int
size = byteData.Length;
IntPtr buffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(size) * size);
Marshal.Copy(byteData, 0, buffer, size);
int ptr = buffer.ToInt32();

// now we can feed the control 
myControl.ReadFromBlob(ptr, 0);

Marshal.FreeCoTaskMem(buffer);

Comments (2)

Module Border Module Border
Module Border
  Blog_List
Module Border
Module Border Module Border
Module Border
  Subscribe
Module Border

RSS

Module Border Module Border
Module Border
  Diversions
Module Border

DESTROY ALL INVADERS
A scrolling shooter game where the objective is to destroy the invading UFO's flying over a neighborhood of your choosing. Imagery provided by Microsoft Virtual Earth. Created using Silverlight 2.
PLAY IT

INFO AND CODE



SORT THE FOOBARS
A game where you need to sort the good foobars from the bad ones. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



POLYGON PHYSICS DEMO
A demo showing polygon physics where the user draws physics objects with the mouse. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



SILVERLIGHT ROCKS!
Destroy the asteroids before they destroy your ship! Created using Silverlight 2.
PLAY IT

INFO AND CODE



FISH GAME
A simple game of harpoon-the-fish. Written using the AJAX Sprite Toolkit.
PLAY IT

INFO AND CODE

Module Border Module Border
Module Border
  Search_Blog
Module Border
Module Border Module Border
Module Border
  Blog_Archive
Module Border
Module Border Module Border
Copyright (c) 2008 andy.beaulieu.com - Login