Tuesday, March 27, 2007

SmartCards & .NET

This is insane.

My project at work has the requirement of talking to a SmartCard reader, and our hardware partner on this project had developed libraries to do just that - one for Linux and one for Windows. Good deal, huh?

Well, after learning enough C++.Net to get these C Libraries to actually talk to .Net in an efficient fashion, I went to use the first function and managed to get a NULL Reference Exception. Yippie.

And of course the libraries weren't compiled in DEBUG mode, so all I know is that there's this exception coming out of the library. Fast Forward two days and we're attempting to recompile the libraries in DEBUG mode in the vain hope that we can pinpoint where this error is coming from.

And while one of our programmers more familiar with C and MAKEFILES has been working on that, I've been looking at other options for getting information to and from the SmartCards.

Why, oh why, did Microsoft leave the ability to interact with PC/SC compliant devices out of the .NET Framework? It was a seriously gross oversight on their part, and one that I sincerely hope they correct in the near future.

Oh well, back to trying to get the SmartCards read.

Monday, March 26, 2007

HIJAX

Jeremy Keith presented something regarding AJAX at XTECH 2006 entitled HIJAX: Progressive Enhancement with AJAX.

I've just recently found the slides to the presentation and must say that I like the concept a lot.

A whole lot.

In a nutshell, what Mr. Keith advocates is that we develop webapplications with AJAX in mind, but in a traditional postback form. Minus any form of JavaScripting (such as .NET's Link buttons with are traditional A tags but with a JavaScript function as the HREF).

Then once the application is built, go back and build JavaScript which hijacks the application's links and button submissions and passing the data through the XMLHttpRequest object.

The whole purpose of the thing is to ensure that the application degrades well in downlevel browsers and/or those browsers with JavaScript turned off.

I suggest you go look at them slideshow, it's a great working platform for rolling out AJAX applications.

Wednesday, March 21, 2007

Nifty!

My freelance project has shifted from being a windows rich-client application to a web-based application. There are various reasons for this shift, among them the desire to have the ability to secure the application against misuse, ease of pushing out updates to the application and then centralizing the system in general.

While the rich-client world offers a lot of fun things, the application itself can be built utilizing the .NET Framework and AJAX to deliver a nearly seamless user experience that almost rivals a traditional rich-client application.

Of course, because it's a shift in paradigms, things have to be built differently, we need a different style of UI, we need user management, and a few other odds and ends which aren't necessary on a rich-client application.

Understandable, and I estimated between two to three weeks to get the application back to the point it was at in the rich-client environment.

Of course, none of that is the point of this article.

What I'm here to talk about is the UI itself. The design I went with is something very similar to the UI elements of GMail or Google Reader (and thousands of other websites out there as well). There's a left hand navigation which provides menu options for the game itself. There's a nav bar at the top of the screen for options relevant to the users - and less relevant as far as the prime functionality of the application. And then there's a content area.

The left nav and content areas I wanted to use boxes with rounded corners.

But I didn't want to spend time building those boxes in GIMP.

So, I did what any sensible person would do and turned to Google hunting for a CSS/JavaScript based solution to give me my rounded corners.

And that's where Nifty comes in.

Three files (a screen CSS, a print CSS and a JavaScript file), a few modifications to my main style sheet and then a couple lines of JavaScript in the body of the .Master page and I have my rounded corners.

Nifty.

Tuesday, March 20, 2007

Using unmanaged C in a managed world

I'm having a problem.

And it's a dozy.

My company is working with some Norwegians to produce a product - and we're making a software bit of it, utilizing libraries that they created.

Sounds reasonable so far.

Well, we're a .NET shop - and more specifically a VB.Net shop. While I was big on C++ in college, those days are long past. Nearly everything I need to do, can be done in VB. And for those odd bits that are left over, I usually employ C#.

Well, this library which we're having to use is built in C.

Without classes. Without structures. Without the STD.

For example, there's a function with this declaration in the header file:

short SW_getVersion(char* version);

As you might have guessed - the short that the function returns just tells us if the function was successful or not. The actual data we care about is being passed through that char pointer.

Beautiful huh?

Actually, it's not that bad. Or at least it wasn't until I started trying to use it in the managed world of .NET.

My first attempts in C#/C++ .NET 2.0 met with the unreasonable compiler error that libcd.lib was no longer supported. Since that was compiled directly into the library's I could do nothing.

So I went down to .NET 1.1.

It compiled, and i tried to link the DLL into my VB.Net front end - and quickly discovered that none of the functions which used c-style strings were accessible.

So, I went and started writing wrapper functions for the library functions which returned managed classes filled with relevant data. Which is when I discovered that managed code does not like talking to unmanaged code.

First C#, despite having the "UNSAFE" flag really doesn't do it. It's only, truly, possible to work in managed/unmanaged code side-by-side in C++.

No Big deal, I thought. After all, C++ was the language we used in college.

Famous last words. I'm now on day three of this fiasco, and am just beginning to get to a point where I can use the function listed above. Yet, I'm still not certain if I'm building these things correctly. Which means that I'm spending a whole bunch of time doing research on MarshalAs, IntPtr and P/Invoke.

And trying my best to figure out where the CString class is stored, so I can use the proper library to try playing with that.

Good times. :|

Monday, March 19, 2007

Apollo

And no, not the Greek god.

Apollo is Adobe's entry into the system markup field - it's not a web-based programming language so much as a framework for Windows/Macs to use HTML/Javascript/Flash/Flex in the production of rich-client applications.

Basically it's a better form of the Executable HTML files which Microsoft created a few years ago (and those things were terrors).

Frankly, this has potential, and I would love to see its functionality included in the next version of the .NET Framework. Likewise, having something similar built into FireFox for all those web-based applications I tend to use would be quite helpful (which is something FireFox plans for their version 3.0).

Friday, March 16, 2007

I'm amused.

This little story about a new certification program for applications came across my RSS reader. And while my initial thought was to flag it for SHARED in my little side bar there, I felt it was good enough to share through an actual post.

With that out of the way, I'm afraid that I must admit to having told our testing staff that in the past.

Monday, March 12, 2007

Nested Stored Procedures & Data results

For my project at work, I went about building the search capabilities today. The system has two main data types that can be searched for mutually exclusive of one another, and later iterations of the software may have other data types which can be searched for then. My solution was a Windows.Form which would display the search results and allow the user to enter a search term list (separated by a comma) and research. The search itself would be powered by a stored procedure hiding in SQL Server.

No big deal right?

Well it worked until I tried to parse the search terms list out. I knew I would have multiple stored procedures doing the heavy work of searching, so I only wanted to keep maintain the functionality to split the search term out into an array in a single place. So I stuck it into a stored procedure.

Smart huh?

One would think so. Unfortunately, SQL Server does not allow for the manipulation of data sets returned from Stored Procedures - and this includes that they do not allow me to stick that returned data set into a temporary table so I can walk it with a cursor to perform my searches.

Annoying to say the least.

So I turned to Google for a bit, and then realized that some of my co-workers had a similar problem in their project. So I came out of my den... err, my office and wandered across the hall to talk to the guy over there.

He showed me the solution they're using, and I felt like smacking myself on the forehead.

It was that little used option for manipulating data in SQL Server in composite chunks. You know, FUNCTIONS.

Apparently, the table dataset that a SQL Server function which returns can be manipulated by a calling Stored Procedure or function.

Since, I got the base Stored Procedure for splitting a search string into tabular format from the web, I figured I would post how I changed that to a function on the web.

/********************************************************************************
* Procedure Name: ParseArray *
* Author: graz@sqlteam.com *
* Purpose: Takes two inputs, a csv style string *
* AND the seperator. Returns a table of all the values *
* in the CSV style string *
* *
* History: *
* 03/07/2007 Modified to be a Function
* *
********************************************************************************/

CREATE FUNCTION dbo.ParseArray
(
@Array VARCHAR(1000),
@Separator CHAR(1)
)
RETURNS @Return TABLE (Word VARCHAR(1000) )
AS
BEGIN -- FUNCTION

-- @Array is the array we wish to parse
-- @Separator is the separator character such as a comma
DECLARE @Separator_Position INT; -- This is used to locate each separator character
DECLARE @Array_Value VARCHAR(1000); -- this holds each array value as it is returned
DECLARE @Temp INT;

-- For my loop to work I need an extra separator at the end. I always look to the
-- left of the separator character for each array value
SET @Array = @Array + @Separator

-- Loop through the string searching for separtor characters
WHILE PATINDEX('%' + @Separator + '%' , @Array) <> 0
BEGIN -- While PATINEDEX('%' + @Separator + '%' , @Array) <> 0

-- patindex matches the a pattern against a string
SELECT @Separator_Position = PATINDEX('%' + @Separator + '%' , @Array)
SELECT @Array_Value = LEFT(@Array, @Separator_Position - 1)

-- This is where you process the values passed.
-- Replace this select statement with your processing
-- @array_value holds the value of this element of the array

-- insert @array_value into the temp. table
IF LTRIM(RTRIM(@Array_Value)) = '' OR @Array_Value = NULL
BEGIN -- LTRIM(RTRIM(@Array_Value)) = '' OR @Array_Value = NULL
SET @Temp = 1;
END -- LTRIM(RTRIM(@Array_Value)) = '' OR @Array_Value = NULL
ELSE -- LTRIM(RTRIM(@Array_Value)) = '' OR @Array_Value = NULL
BEGIN -- ELSE: LTRIM(RTRIM(@Array_Value)) = '' OR @Array_Value = NULL
INSERT INTO @Return (Word) VALUES (LTRIM(RTRIM(@Array_Value)));
END -- ELSE: LTRIM(RTRIM(@Array_Value)) = '' OR @Array_Value = NULL

-- This replaces what we just processed with and empty string
SELECT @Array = STUFF(@Array, 1, @Separator_Position, '');
END -- While PATINEDEX('%' + @Separator + '%' , @Array) <> 0

-- return all rows from temp table
RETURN;

END -- FUNCTION

Thursday, March 8, 2007

Parsing Enumerations

In my project at work, I deal with a large number of enumerations. Things such as the type of a key or the status of various objects. Now, I could have maintained a table in the database which corresponds to those enumerations, but that seems like double work to me, so when designing the database, I made the decision to just use VARCHAR fields where I would normally have the lookup identifier for the database table.

That means, I can just save my enum straight into the table rather than having to deal with looking up its corresponding value.

I also chose VARCHAR for a string representation in the database over an INT for just the numeric value behind the enum so that when looking at the actual data in the various tables, I could easily discern what those enums actually are.

Getting the string representation of an enum is something I've known how to do for quite a while, and do do it whenever I'm working with them and I need to see the chosen enum in the debug output. It's just a simple matter of using the ToString method of the enumeration.

Yet, I've never gone the other way, of taking a string back to the enum value. It's not a simple matter of using CType as enumerations are in actuality numbers and not the strings that I'm saving.

So, I went to my good friend Google.

And discovered this glob entry: Miscellaneous Debris: VB.Net and Enums

His issue was using the enumerations that are inherent parts of the VB.Net language, but the concept he described works regardless.

The solution is to basically, force the compiler to read the string, and compare the possible enum values to see which is the correct one using the parse command like thus:

[Enum].Parse(System.Type, Value)

So, for my purposes what I would use is:
[Enum].Parse(GetType(Status), dataReader("Status"))
And it works beautifully!

Wednesday, March 7, 2007

Finally, a Requirements Dev course

I've finally found a Requirements Development training course that sounds like it is what I need to flesh out my truly lacking skills in this regard. Only downside is that it is around $2400 for a four day course. Not that $600 a day is that obscene of an amount to charge for a training course.

Tuesday, March 6, 2007

Color coding

Part of my freelance project is derived from the statistical representation of large data sets. And one of the statistical representations is a color coding based on frequency. Well I had originally set it up as basically a tri-state frequency to reflect cold/warm/hot status, yet this did not meet the customer's needs.

He wanted a range of colors based on that frequency, so now I've got to find out a way to graduate from red to blue (through yellow) based on a frequency. It shouldn't be that hard, as it's just a matter of converting the color from an RGB code.

Of course I'm saying that from a point of ignorance. Alas, Google here I come.

Thursday, March 1, 2007

Sorry, sorry.

I've been busy with RealLife and making some "necessary" changes to my project's SDD.

Unfortunately, that means that I don't really have a lot to blog on, as I'm not developing any new features and mainly slamming my head against the desk at routine intervals. It also means that I'm more focused on getting that document written than reading articles and whitepapers and other blogs to garner odds an ends about Software Engineering.

Like it says in the title, sorry.


As a side note, I'll be offline Friday and Monday, so don't expect new posts on those days either.

Blog Widget by LinkWithin