Tuesday, July 12, 2011

Insert many rows into MSSQL2005 using XML

This troubled me for a long time... Here's my solution in VB.net

                Dim xmlSource As New StringBuilder  
                dim recordsToCreate   
                recordsToCreate = 100000  
                for x = 1 to recordsToCreate   
                     xmlSource.Append("<row>")  
                          xmlSource.Append("<Col1>SomeData in col1 " & x & "</Col1>")  
                          xmlSource.Append("<Col2>SomeData in col2 " & x & "</Col2>")  
                     xmlSource.Append("</row>")  
                next   
                Dim startTime As Date = Now  
                ' Run the process that is to be timed.  
                Using con As New SqlConnection( connStr )  
                          con.Open()                           
                          strSQL = "DECLARE @xml XML; SET @xml=@xmlSource; "  
                          strSQL = strSQL & "INSERT INTO XDELETEME (col1, col2) Select "  
                          strSQL = strSQL & "Tbl.Col.value('Col1[1]', 'nvarchar(50)'), Tbl.Col.value('Col2[1]', 'nvarchar(50)') FROM @xml.nodes('//row') Tbl(Col) "  
                          cmd = New SqlCommand(strSQL, con)  
                          With cmd.Parameters  
                            .Add(New SqlParameter("@xmlSource", xmlSource.toString() ))  
                          End with  
          cmd.ExecuteNonQuery()  
                          con.Close()  
                End using  
                Dim runLength As Global.System.TimeSpan = Now.Subtract(startTime)  
                Dim millisecs As Integer = runLength.Milliseconds  
                response.write(recordsToCreate & " records imported in " & millisecs & " Milliseconds")  

This works really well for bulk inserts.

Sunday, May 1, 2011

Airplay through Media Center

So I felt like doing some media center programming this morning. I thought about how cool it would be to get AirPlay working with media center. Unfortunately, my solution is not native to MCE but it seems to work ok. I read this TUAW article about AirMediaPlayer, which opened to the door. AirMediaPlayer was discontinued by the author without releasing the source code, which SUCKS. So I wrote an AutoIt script to bridge the gaps between MCE and AirMediaPlayer. Here's a video of it in action:



How it works:

The first time you run the Airplay app from media center, it launches AirMediaPlayer and also launches a daemon to wait for the airplay connection, then returns you to media center. Now all you have to do is start playing a video on your iDevice, and click the airplay icon to select the computer name of your MCE machine. Once AirMediaPlayer receives the connection, MCE's "Now Playing" title is stopped, then MCE is minimized, and AirMediaPlayer is maximized to full screen mode. When you stop the video from the iDevice, AirMediaPlayer is minimized and you are returned to MCE. It's pretty seamless, although not native.

Setup: AirPlay.zip

1. So first download the zip file an extract the contents to "C:\Airplay\"

2. Run AirMediaPlayer. If you get an error, it's probably because you need to install Bonjour and Quicktime. If you can't get AirMediaPlayer to get airplay videos from your iphone, there is no point in going to Step 3 until you get that working. Once you can airplay videos, move on to step 3.

3. Run the install.cmd This will put the airplay app into media center. I only tested on windows 7 x64, so others will have to find a workaround. you can find the icon in the "Extras menu" or get Advent Media center studio to put it wherever you want it.

4. Launch the addin from media center, and you should see the screen flicker as AirMediaPlayer starts and MCE restores back.

5. Now launch a vid from your iphone, hit the airplay icon and send to MCE. MCE should notice and start the stream.

Other stuff:

There's a config.ini that you can edit that will enable logging or set the timeout of the daemon. The default timeout is 900 seconds (5 minutes). So if you dont send an airplay stream to MCE within that time period, AirMediaPlayer will close and you will have to click the MCE airplay icon again to start it.

Launcher.exe does all the real work. The source code is at launcher.au3 ( an autoit script ) feel free to recompile it if needed. If someone get this going on 32bit let me know and I'll add your changes.

So, that was my sunday... I would love to see Airplay audio, and a native Airplay video solution in the future. I just won't be the dev to do it, I dont have that kind of time anymore.

Saturday, May 1, 2010

GeoVision iphone webbrowser alternative

I got a geo vision card to replace the standalone dvr for my security cameras. GV makes a decent application, but best of all, it's easy to hack your own stuff. I was not really happy with the GV-IView iphone app. It takes like a half hour to load and view a camera feed. And it's the same situation on the firefox jpeg viewer. So here's my workaround.


Go to your gv directory and find the web temp directory, mine was C:\GV-600\WebTemp\
Then rename your ChangePwd.htm to ChangePwd.BAK (for backup) then download my version, replacing the original. Download here.

So now when you browse to your GV web version http://:/ChangePwd.htm you get a nice iphone and firefox compatible version. The only downside is that you can't change your password from the web anymore, you would have to be at the DVR to change password. I had to do it this way, because GV would not let me serve a new html file, so I had to edit an existing webpage.

Once you log in, all of your settings are saved in a cookie, so that means a quick auto login. I'm not going to get into all the details of this mod, but it does lot's of stuff, and looks great on an iPad / iPhone too because you can pinch and spread to zoom in on your feeds. Also, if you add the webpage to the iphone homescreen, it makes a nice icon.

IPhone Screenshots:






IPad Screenshots:



Saturday, February 13, 2010

Upgrading MCE2005 to Windows 7

So I made the plunge on all my boxes to Win7 from MCE2005. A lot of things have improved in Win7 but it took me forever to get everything setup right. Especially since I was attempting to upgrade old MCE2005 hardware to Win7. My box was a 2005 HP Pavilion Slimline, 1 gb ram (max), on board video card, no more expansion slots. So hardware upgrading wasn't possible. After reinstalling Win7 four times and trying specialized codec packs, which all sucked, my biggest problem was my networked xvid videos were choppy. I tried hundreds of fixes, from codecs to drivers.

The codecs that worked best for me, was CoreAVC and the XviD codec. This got the choppyness to a minimal amount, and enabled mkv formats but it still wasn't perfect. It turns out I was sharing content via an administrative share //server/d$/content for example. This was the source of my problem all along so I am documenting it for any other losers out there. Windows 7 does not stream video smoothly via an admin share! Just share the folder normally and it's all gravy FFS.

Here's some other tweaks I made. First off install mediabrowser http://www.mediabrowser.tv/ because it's awesome, a bit slow but worth it. Also you want to modify the home strip to say something more blatent than mediabrowser, so tweak it via the registry like so:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Media Center\Start Menu\Applications\{ce32c570-4bec-4aeb-ad1d-cf47b91de0b2}]
"OnStartMenu"="True"
"Title"="Movies or whatever"

And you can remove the other items from the Start menu like Extra's by running this app: http://mikinho.com/wmc/start-menu-plus/

Also, I tweaked Win7 for HTPC use only by right click, my computer, properties, Performance Information and tools (lower left) Adjust visual effects (best performance), indexing options (modify then remove all).

Lastly since my MCE is an old piece of shit box, I stuck in an old 2gb flash drive then set it up for ready boost, which is kinda like a ghetto ram expansion. But believe it or not, it did run faster with it.

After all that was done, I transformed an old POS MCE 2005 box to a usable Win7 MCE box.

Here's some other shit I changed but I don't know if it helped or not... Only try if you're desperate:
I installed the Preferred Filter Tweaker http://www.codecguide.com/windows7_preferred_filter_tweaker.htm
which basically lets you tell windows 7 mce which codec to decode with. And totally unrelated I upgraded DirectX. Both things probably weren't neccessary but I'm throwing it out there anyway.

Saturday, January 23, 2010

Grip Growl Notifications in Media Center

There was no Growl display addon for media center. So I decided to get my hands a lil dirty and create one. I found some a source code from MCE 2005 that seemed to do exactly what I wanted. The only problem is that the source code didn't work for MCE 2005 rollup 2, and the link to the fix was long gone. So after some scouring, I found/posted the fix, recompiled the application DLL's, and began testing. It works great on my MCE 2005 boxes, and I even got it working in Windows 7 MCE, didn't test in Vista because vista sucks.

Why did I write this? Because I am an idiot who has a million other paid projects I should be writing but MCE keeps pulling me back in. And also, Notify Pro was released in Cydia which allows your iPhone to push growl notifications from your phone to a growl client, this works with that so new SMS/Incoming Calls alerts etc, work with media center. The alerts vanish after 7 seconds, no remote control needed.



Download the installation files with source code here *fixed carriage return bug

To install the media center addon, exit media center, then copy all files from the MCE-Install directory into C:\Windows\ehome\ then double click the install.bat file. To uninstall run, uninstall.bat file. After this is done, MCE is ready to receive notifications. To send Growl notifications to the media center install growl http://www.growlforwindows.com and then install the scripty display: http://www.growlforwindows.com/displays/scripty

Now you need to configure scripty to launch our custom executable, so go to displays, set scripty as default, then hit browse and navigate to the MessageSender folder, and select the MessageSender.exe If scripty doesn't let you select the MessageSender.exe file then type *.* in the file name box and it should then allow it.

Now start a non maximized media center, and click preview and you should see this:














Now I guess you can install all kinds of growl apps and get your notifications in MCE.