Next generation's garbage RSS 2.0
# Friday, July 02, 2010
I wanted rounded corners, but with minimal fuss. I'm using border-radius and variants (-moz, -webkit, -khtml) which is great, except for on IE, but I found a DHTML behavior (http://code.google.com/p/curved-corner/) that makes it so IE will appear to have these powers. The trouble is, I'm using SiteFinity which, like any good CMS, has these virtual folders that don't exist in IIS and url references to behaviors must be in the same directory.

To fix this, I wrote a quick HttpHandler to all me to capture requests for htc files and serve them from any path.

Here's the source:
    public class HtcAnywhereHandler : IHttpHandler
    {
        public HtcAnywhereHandler() { }
        public bool IsReusable { get { return false; } }

        public void ProcessRequest(HttpContext context)
        {
            FileInfo fi = new FileInfo(context.Server.MapPath("~/htc/" + context.Request.Url.Segments[context.Request.Url.Segments.Length - 1]));

            if (fi.Exists && fi.Extension.Equals(".htc", System.StringComparison.InvariantCultureIgnoreCase))
            {
                context.Response.ContentType = "text/x-component";
                context.Response.BinaryWrite(File.ReadAllBytes(fi.FullName));
            }
            else
                context.Response.StatusCode = 404;
        }
    }
So now I have an /htc directory where I really store my behavior but a request to /skljfsfcio/border-radius.htc will serve the /htc/border-radius.htc file. Yay.

To make this work, you'll need to add an entry to the httpHandlers section in the web.config

<add verb="GET" path="*.htc" validate="false" type="HtcAnywhereHandler, HtcAnywhere" />

Then you need to tell IIS to use ASP.NET for .htc files. Go to the web site properties, Home Directory tab, [configuration...], add an application extension to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll for .htc, Limit to: "GET", and turn off verify that it exists.

The bummer for me was that in my html that border-radius.htc didn't end up working. Sigh.

Friday, July 02, 2010 12:40:58 PM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
.NET | HTML | SiteFinity
# Tuesday, May 04, 2010
It's true. I was pretty excited when I heard about a chance to ride along with Carl Franklin and Richard Campbell of DotNetRocks. It was a promotion put on by Telerik where one lucky victim from each city would get to ride in the RV with them to the next city and watch that show.

Timeline:
  • Several weeks before - heard about the RoadTrip on a DotNetRocks episode. Went to the site mentioned, but there wasn't a sign-up form yet. Set an alarm on my phone to remind me to check the site daily.
  • A couple of weeks before - The form was there. I filled it in. I then told my wife about it and said that there was a insignificant chance that I might win that. I then realized that this was going to conflict with SqlSaturday in Huntington Beach.
  • Monday 4/19 - canceled plans to go to SqlSaturday.
  • Tuesday 4/20 - Beta 2 of a certain smart phone OS broke camera support. Boo. Did take a pocket camera with, but didn't take many shots with it.
  • Friday 4/23 - went to the DotNetRocks RoadTrip event in Phoenix. Got there right at 6 PM. Chatted with Richard and mentioned how cool I thought the RoadTrip ride-along was. He said, "You should go." - They were going to pick me up on Saturday. I texted my wife. I found it rather hard to concentrate during the event.
  • Saturday 4/24 - Carl and Richard drove the RV to my house, around 11 am - crazy - got onboard and away we went. Bound for Houston, some 1100 miles away. They opted for driving straight through. Chatted their ears off probably. We jury-rigged the PA speaker to a MP3 player so we could listen to old episodes of Mondays on the drive.

  • Sunday 4/25 - Pulled in to Houston around 9 am. Around 20 hours with the time difference. Got a little sleep in the RV and a little more at the hotel after going for a walk. Later Richard, Tom (driver) and I met up with Zain Naboulsi (MS Dev Evangelist) for dinner and had some spirited discussions over a great dinner. Then just hung out with Richard for a couple of hours chatting about techie nerdy stuff.
  • Monday 4/26 - Met up with Dustin Campbell and had really great sushi with everyone. Totally geeked out with Dustin about languages and Visual Studio. Then we went to the MS office, setup and they did the show. It was kinda neat to see them do a second show. Did a video interview with Todd of Telerik about the experience and we discussed some of the cool stuff in SiteFinity 4.0 CTP. Then we went back to the hotel. Sadly, the experience was over. Got about 2 hours of sleep then took a cab to IAH airport and got on my early flight back to PHX.


Really a great time.
Thanks Carl and Richard and Thanks Telerik!

Tuesday, May 04, 2010 11:04:02 AM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
.NET
# Thursday, March 25, 2010

Wanted a generic way to pass a DataTable as a parameter to SqlCommand as a TVP (Table Value Parameter). It automatically creates the, IMHO, superfluous User-Defined Table Types. Here's what I have so far:

<Runtime.CompilerServices.Extension()> _
    Sub AddTableParameter(ByVal cmd As SqlCommand, ByVal n As String, ByVal dt As DataTable)
        Static typeXlat As Dictionary(Of System.Type, SqlDbType)
        If typeXlat Is Nothing Then
            typeXlat = New Dictionary(Of System.Type, SqlDbType)
            typeXlat.Add(GetType(Int64), SqlDbType.BigInt)
            typeXlat.Add(GetType(Int32), SqlDbType.Int)
            typeXlat.Add(GetType(Int16), SqlDbType.SmallInt)
            typeXlat.Add(GetType(Byte), SqlDbType.TinyInt)
            typeXlat.Add(GetType(SByte), SqlDbType.TinyInt)
            typeXlat.Add(GetType(Boolean), SqlDbType.Bit)
            typeXlat.Add(GetType(String), SqlDbType.VarChar)
            typeXlat.Add(GetType(Byte()), SqlDbType.VarBinary)
            typeXlat.Add(GetType(DateTime), SqlDbType.DateTime)
            typeXlat.Add(GetType(DateTimeOffset), SqlDbType.DateTimeOffset)
            typeXlat.Add(GetType(Char), SqlDbType.Char)
            typeXlat.Add(GetType(Single), SqlDbType.Real)
            typeXlat.Add(GetType(Double), SqlDbType.Float)
            typeXlat.Add(GetType(Decimal), SqlDbType.Decimal)
            typeXlat.Add(GetType(Guid), SqlDbType.UniqueIdentifier)
            typeXlat.Add(GetType(Xml.XmlDocument), SqlDbType.Xml)
        End If

        'assembly the typename and spec
        Dim tabletypedef As New List(Of String)
        Dim parm As New SqlParameter(n, SqlDbType.Structured)
        parm.Value = dt

        For Each c As DataColumn In dt.Columns
            Dim s As SqlDbType = SqlDbType.Variant
            If typeXlat.ContainsKey(c.DataType) Then s = typeXlat(c.DataType)
            tabletypedef.Add(c.ColumnName + " " + s.ToString)
        Next
        Dim tabledef = String.Join(",", tabletypedef.ToArray)
        Dim typename = "autotype_" + tabledef
        parm.TypeName = "[" + typename + "]"

        'create the type if needed
        Using cmd2 = New SqlCommand("select count(*) from sys.types where is_table_type=1 and name='" + typename + "'", cmd.Connection)
            If cmd2.ExecuteScalar() = 0 Then
                cmd2.CommandText = "create type [" + typename + "] as table(" + tabledef + ")"
                cmd2.ExecuteNonQuery()
            End If
        End Using

        'add the parm referencing the typename
        cmd.Parameters.Add(parm)
    End Sub

Thursday, March 25, 2010 7:54:18 PM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
.NET | SQL
Archive
<September 2010>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789
All Content © 2010, Hafthor Stefansson - Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way. - Sign In