Sunday, May 17, 2009
Auto Complete Example Project
Saturday, May 16, 2009
More AutoComplete
- You have to write a web service to handle the back in call to the data source. So if all of your data is in an MS SQL database, or Access, or XML, you have to write the query for that and put it in a web service and tag it with a WebMethod attribute. Read more about web services here.
- The webservice that the Auto Complete calls can have any name but it must have the following paramter signature: Public Function GetItemName(ByVal prefixText As String, ByVal count As Integer) As String(). The first variable must be a string and it has to be called prefixText. The second one must be called count and it has to be an Integer. Read more about the Auto Complete extender here.
- One final thing you need to know about the Auto Complete extender is that most of the examples you'll find online show how to get back the text that the user selected, but they don't show you how to get back the ID. Let's say you have a dropdown list of car parts. There could be thousands of them. The user types in a few letters, sees the part, arrows down to it and hits enter. What you need now in order to do look ups in your related tables is the ID of that item, not the text itself. How do you get that? Inside my webMethod function I do something like this: tempResult.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(itemname), itemID))
In this example tempResult is List( Of String). By using this CreateAutoCompleteItem function I can create an item that the Auto Complete Extender knows should be split into a text value to display and an ID value that will actually be used. Now, the return type has to be a string array, so the last line of my function is "Return tempResult.toArray()". I like working with generic lists but you could just as easliy dimension a string array with the size based on the count paramter. - Now, how do I get the value back from the ajax call? In the markup for the AutoComplete Extender, you need to specify a javascript function to be called after the user selects an item. Something like this: OnClientItemSelected="showItem". The showItem function will look something like this:
function ShowItem( source, eventArgs ) {
alert( " Key : "+ eventArgs.get_text() +" Value : "+eventArgs.get_value());
}
- What's that? You don't want the value in a javascript alert, you want to assign it to an ASP.net control, like an asp:HiddenField or something like that? Then do a getElementById('hiddencontrolID').value = eventArgs.get_value(); somewhere in your javascript function.
- Now you are probably going to ask...what if it's in a User Control and there are lots of them on the page and I don't know what the ID is going to be for each asp:Hidden control? That's an answer for another blog post. If this one generates lots of hits I'll write it up.
Thursday, February 12, 2009
Auto Complete on the Google Search Appliance
First off, the Ajax toolkit from Microsoft has an auto complete extender. It's great for running against SQL tables, or XML files or just about any data source. You can get back the ID of the record that the user selected and really make things snazzy. The question is, how do I use a GSA as a data source?
The GSA does return results in XML, but it doesn't do wild card queries. You can't do a search for "hea*" and get back head, hearing, heart and things like that. You get Dr.Hea and some mis-spellings and that's it. I did some looking on the Google Code site and found a "Search as you Type" project that seemed to do just what I wanted. It said in the documentation that you could turn any text box into a Google suggest box. It was written in PHP but I figured I could download it and convert the page to .Net. Most of it was in javascript files anyway so no biggie. Except that the page doesn't connect to a GSA. It has a pipe delimited text file that it uses as the demo source for the drop down. I looked through the readme.txt looking for some way to magically refernce the GSA. Nothing. What I had found was a Google Base code project that did the same thing as the ajax toolkit from Microsoft. I was right back where I started.
I fumed for a little bit. I drummed my fingers on my desk. I went back to Google's site and looked over their page source and javascript files. Then, as I was taking a swig of Red Bull, I realized what Google was doing. They weren't running against their index either.
Google is fast but not so fast that they can ajax call from your browser back to their index and back to your browser with search results each time you press a key (Update 7/12/2011: Actually, they are that fast now. Most of my speculations about Google in this post are obsolete). They have been in the search business for quite a while so there is no doubt that they know the top 1,000 search terms for words that start with each letter of the alphabet. The top 1000 As, the top 1000 Bs and so forth. Google had compiled a list of the Top 26,000 key words (something like that, I'm gusessing) and that's what they are running against when they do the Google suggest ajax call.. That's why when you do an obscure search it doesn't show anything but when you hit "search" you get results.
Now, back to my problem. It's not a problem anymore. I can run a report against our GSA, get back the top 10,000 or so search results, filter out the trash, and have everything I need in a nice and tidy XML document. I can put it in a SQL table or leave it in XML. I'll b able to sort it either way. Now I can use the ajax toolkit Auto Compete extender and in a short amount of time I have the same functionality as Google Suggest for our GSA. Only I'll be using .Net.
I'll post the code and link to the search page when I'm done. Shouldn't be long (will I ever learn to stop saying that).
Wednesday, February 11, 2009
Debugging and Windows Service in VB.Net
'****Modified by JWear on 4/12/2006****
Private Sub New()
If Debugger.IsAttached = True Then
' debug code: allows the process to run as a non-service
' will kick off the service start point, but never kill it.
' shut down the debugger to exit
'Open this page for help ' 'http://www.codeproject.com/dotnet/DebugWinServices.asp
Dim service As New YourService
Dim tempargs() As String
service.OnStart(tempargs)
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite)
Else
'Original Code Below
ServicesToRun = New System.ServiceProcess.ServiceBase() {New YourService}
System.ServiceProcess.ServiceBase.Run(ServicesToRun)
'Original Code Above
End If
'**************
End Sub
Friday, May 20, 2005
DOOMed
So I work at a software company. There are many topics that come up in conversation over and over again. The Star Wars Prequels, the Simpsons, South Park, what's really wrong/right with the government, comic books, obscure movie references and...video games(many of these stories are told in some kind of "accent"). Many of the guys at the company either have had or are currently in the throws of a deep video game addiction. I was an id Software junkie back in the day. Back in 2000, work would end and the office would play Quake III for at least two hours after work. Every day. Sometimes we came in on Saturdays to play. Civ3 was the worst. On three separate occasions I have thrown that game away because it took up so much of my time.
Those of you who are still reading this are doing one of two things. You are either shaking your head and saying, "what a doorknob" or you are nodding your head, raising your hand in the air and saying "Preach on!" I'll take the good with the bad. At least you are still reading.
Okay, where am I going with this? Well here's the thing. I do not have a college degree. I made several attempts but never walked across the stage. My mom has her degree but my father never got his. I have two great parents but the combined salaries of a police officer and a public school teacher didn't exactly put us in the country club...er...club. I'm not saying I had it bad. I had it good. But with no degree, no marketable trade and no trust fund, how was I going to make a living?
So there I am back in 1994. I knew that it was just a matter of time until I dropped out of college. I went from being an out of state full time student to an in state part time student to a flunky who got up and walked out of his astronomy final exam because I did not have a clue what I was looking at on the planetarium dome. I failed astronomy. Astronomy for crying out loud.
One day while I was at work (I was a radio dispatcher for a wrecker service) a co-worker handed me a floppy disk. It was your typical 3.5" disk that some people mistakenly called a "hard disk" at the time.
"Here," he said, "Play this game." It had one word written on it, DOOM.
It sat in a stack on my desk for several weeks. I was busy with my real full time job, which was keeping up appearances. It's hard work keeping up the illusion that you are a serious college student when in actuality you're just reading Dragonlance novels and screwing around with whatever pirated games you can get your hands on. Anyway, I popped in DOOM and I saw that opening screen. Then the first person POV comes up. I'm in that hallway. I walk through that first door and that first monster jumps right in front of me. Pure 2D Pixelated Horror! I hit the Enter key to fire my pistol. The monster screams. I hit the key two more times and he falls. My pulse is racing. I'm sitting up in my chair (There is that great shot out the window to your right as you your character down the hallway). It looks like the level just goes on forever.
I played until 10 am the next morning.
That is what did it for me. It started with Doom. My Packard Bell 486sx 25 Mhz with 4MB of DIMM memory, 110 MB HDD, a 2x CD-ROM and a 16 bit sound card barely played it. And of course, the 2400 Baud modem. So I learned how to upgrade. First the RAM went from 4 megs to 8 megs. Then I got a clock trippler to take my chip to a 486 75mhz with the DX math co-processor. Then I figured out how switch out that 100MB drive for a 1.0GB Western Digital (set me back over $300). Then I disabled the on board modem and installed a screaming 14.4k modem so I could play doom head to head against other people (I played John "You're No" Romero once on DWANGO). Now this is back in the day where no one really knew what the heck they were doing when it came to upgrading computers. This was the day of comm port conflicts, IRQ conflicts and jumpered motherboards/hard drives. Don't even get me started on deciphering modem initialization strings. You couldn't look it up on the web because the web didn't exist yet. There were no books because no one had done this before. You just figured it out for yourself and pieced together the rest from FAQs and ReadMe.Docs that came with the downloaded addons.
Then there was Doom II and it all got kicked up to another level. Full blown editing tools were floating around. I would play DOOM II all night with my friends and then we would start making our own levels (WAD file maniacs) when we woke up the next day. Then there was Quake I and OpenGL hit big. Everyone had to learn how to get their PCs to run the 3dFX video card so that all those crazy colors and the crisp resolution would come through.
If you are still reading then I thank you. I got a little carried away there. Why did I go into all that? That is where I learned how to be a programmer. I learned how to trouble shoot, how to research, how to think about abstract things in my head and hold it there long enough to type some commands that would make it show up as a level in the Doom II engine. If I could not figure something out then I would pour over books, download files and talk to other like minded junkies until we did figure it out. Programming in QBASIC as a kid was interesting but DOOM made it fun.
So in closing, if it had not been for id Software and their groundbreaking games Castle Wolfenstein and Doom, I'm not sure where I would be. I'd be like that guy in the Sting song, "I got no prospects, no education, I was lucky to get a job at this gas station." In my case it was working for AAA. But now? I started working in the Best Buy PC upgrade/repair shop in 1995. In 1996 I went to technical support for a software company and ended up writing software for them until I left in 1998. After that I went to development full time, building experience and a skill set a little at a time until I got to where I am now. Am I on top of the world? Heck no. But I can write half decent code and solve the tech problems that come my way due to the time I put in figuring out how to make hardware run a game and then how to make that game do more. Without id Software, I don't know if that would have happened.
So now, as far as economics go, life is good. Debt is going down, savings are going up and as long as I stay current I take care of my fiscal responsibilities and finance my writing endeavors. Speaking of which, I need to get on that. Remember to keep moving. You don't wanna get telefragged.
Wikipiedia: Doom