Monday, July 27, 2009

Foundations of C++ /CLI, Book Review

I just finished reading Foundations of C++/CLI: The Visual C++ Language for .NET 3.5 .  I read this book hoping to get a grasp of how to wrap native libraries with C++/CLI.  Unfortunately I didn't read the Amazon Editorial review and only chapter 13 covered this topic.  The book assumes the reader knows C++ and wants to learn .NET.  This made the majority of the book review for me.

This book would probably be good for someone with a C++ background wanting to learn .NET, although if one isn't going to do interop the book recommends using C# instead.

Monday, July 20, 2009

Viewing Google Login via Fiddler

I started playing around with the Google Data APIs.  I'm amazed at how easy the .NET library is to consume.  In a few minutes I had their samples connecting to Google Photo,and in about an hour I had connected to my Google Contacts and viewed all my contacts.

I wanted to know how this was working.  Firing up WireShark there was too much going on, so I tried Fiddler which worked well. It also has a cool Request Builder feature that I'm going to dive into.

Launch Fiddler and click the Request Builder tab.  From the drop down list on the left select Post.  Type in https://www.google.com/accounts/ClientLogin in the textbox, and HTTP/1.0 in the next drop down.  In the Request Headers put Content-type: application/x-www-form-urlencoded.  In the request body put accountType=GOOGLE&Email=YOUREMAIL@gmail.com&Passwd=YOURPASSWORD&service=cl

Click the Execute button.  You should get back a result 200.  Click the TextView in the Response area of Fiddler.  This lets you see the all important Auth token :)

Go here to learn about Google API authentication: http://code.google.com/apis/gdata/auth.html#ClientLogin

Monday, July 13, 2009

C# Programming Language Book Review

I just finished reading The C# Programming Language (3rd Edition).

For those interested in learning C# try Programming C# 3.0 instead.  The specification is about 650 pages and some parts describe the grammar of familiar subjects at great length without explaining how to use C#.  The best part about the book: the cool factor of having it sit on my desk.  Chicks dig nerds ;)

This was a good read now instead of earlier in my career so I could appreciate the annotations and lexicon.  The book pointed out things I didn't know C# could do, and don't see why I'd want to do, but would make good trivia (does this compile?).  Some things were interesting like the fact that the this keyword is a reference in structs.  Also I had never looked into the unsafe features of the C# language, making that chapter good reading.

Monday, July 6, 2009

Select * from table where column in %

This method allows you to filter a column based on a list supplied by the user or when the user doesn't supply anything to return all the results without using dynamic SQL.  You can use ANDs in the where clause to include additional filters.  In our application we parse a comma delimited string in SQL to get our list of user input.  SQL 2005 introduced table variables and you could probably use those instead.
--pretend this table contains all the states.
      declare @states table (identifier varchar(2))
      insert into @states
            select 'MI' UNION
            select 'CO' UNION
            select 'NY'

--this simulate states selected in the application
      declare @selectedStates table (identifier varchar(2))

--insert a state to simulate the user selecting a state.
      insert into @selectedStates --comment this line to see @allStates flip
            select 'MI'           --comment this line to see @allStates flip
declare @allStates bit

--if the user hasn't selected a state get all the results.
if ((select count(*) from @selectedStates) = 0)
      select @allStates = 1

--give back the results:
select identifier from @states
      where (identifier in (select identifier from @selectedStates) OR @allStates = 1) AND 1=1 --additional filters could go here instead of 1=1