Adventures in dlna with Blu-Ray players

So the wife and I decided that we would get on NetFlix and be able to stream movies versus going out to BlockBuster. We thought we would go ahead and pick up a new Blu-Ray player that has the streaming built in, and hey while we are at it get one that will also be dlna compliant and connect to my Arch linux powered minidlna media server.

Well getting minidlna setup on Arch via Yaourt is super simple, just a “yauurt -S minidlna” and boom installed. Yay for just works! yay!

So onto getting the Blu-Ray player hooked up to stream pictures, music and video from the dlna server, should be easy enough to get a dlna certified player and, ah, it just happen, right? Pffft.

Off to NFM to pick up a Sony BDP-S470 seems they have it on sale for around $125 and from the manufacturer site it has evertyhing and then some.

I set it up and sure it sees the dlna server, plays the pictures and the music but does not see any movies – no avi, mkv, wmv – nothing. Grrrr. I Make sure the dlna server is working by playing movies via the Xbox 360; works fine indeed.

So return that player and then pick up the Panasonic DMP-BD65, heck its on sale for around $90 and from my cursory search on the net it is dlna certified.

Get it home, hook it up. Humm. Where is the dlna part? Look around the web and find out that the dlna part is only for the European market; not available in the US models. Good grief.

Then off to pick up the LG BD-570 its the most expensive one in my adventure, around $165, but it seems to have Wifi built in and it does have the dlna sticker on the box.

Get it home, hook it up. Endure looks from the wife that I am losing my mind and working on becoming some sort of Blu-Ray exporter. Aha! Eureka right off the bat it sees my dlna server and, wait for it …. Yes! it plays the movies, pictures and music just fine.

Sure the WiFi part stutters a bit playing back some 1080p video (Big Buck Bunny ftw!) but connected on the wired it seems to be excellent in both video and audio.

After some more checking the NetFlix and Vudu works as well. Woot!

Enjoy!

Redirect old aspx to new MVC

I upgraded Dvdcrate.com to be ASP.NET MVC and one of the problem is the old pages are indexed by search engines and being served on search results. So I have the old *.aspx page that I need to fix up and send along to the MVC page.

An example of the page in the search database;
www.dvdcrate.com/viewdvd.aspx?upc=5027035006161

And I need it to go to the new MVC controller and action like this;
www.dvdcrate.com/Media/Detail/5027035006161

So I did it this way, I put this in the Global.aspx.cs file;

        protected void Application_BeginRequest (object sender, EventArgs e)
        {
            var requestUrl = Request.Url.ToString().ToLower();
            if (requestUrl.Contains("/viewdvd.aspx"))
            {
                var equalPos = requestUrl.LastIndexOf("=") + 1;
                var upc= requestUrl.Substring(equalPos, requestUrl.Length - equalPos);
                Context.Response.StatusCode = 301;
                Context.Response.Redirect("/Media/Detail/" + upc);
            }
       }

Probably not the most elegant, but it does work.

Enjoy!

jQuery UI Themeswitcher Cookie Expires

So I disagree with the current setup that is the default configuration with jQuery UI Themeswitcher, it expires the cookie at the end of the session. I mean really if the user is going to change the cookie to some color scheme they like chances are its going to be for longer than the current session and for crying out loud the user is going to expect your site to load the theme they selected last – else it looks broken. Just a poor decision in my opinion – so here is how I fixed it to last 1 year.

Download the themeswitcher.js and save it locally wherever you like.

Now add the “cookieName” below this to the options defition in the file;

    var options = jQuery.extend({
        loadTheme: null,
        initialText: 'Switch Theme',
        width: 150,
        height: 200,
        buttonPreText: 'Theme: ',
        closeOnSelect: true,
        buttonHeight: 14,
        cookieName: 'jquery-ui-theme',
        cookieExpires: 365,
        onOpen: function () { },
        onClose: function () { },
        onSelect: function () { }
    }, settings);

Now modify where the cookie gets made to use this new “cookieExpires” option (line 49);

        $.cookie(options.cookieName, themeName, { expires: options.cookieExpires });

Know you can either use the default set here (365) or set your own in the initializer in your calling script;

    $('#switcher').themeswitcher({ cookieExpires: 365, path: '/', loadTheme: "Sunny"});

Enjoy!

Securing ELMAH with ASP.NET MVC

So I like Elmah and its logging of my unhandled exceptions suer, but I don’t need every yahoo with visibility to that. This is the steps I took to only allow Elmah access to users in the “Admin” role and have it still work with ASP.NET MVC.

Put this into the web.config;

  
    
      
        
      
      
        
        
      
    
  

Now put this into your global.asax, up top (before all the other routing) is best;

            routes.IgnoreRoute("admin/elmah.axd");
            routes.IgnoreRoute("admin/{resource}.axd/{*pathInfo}");

You don’t have have any controller action setup, the handler builds this on the fly to handle the incomding axd request. Nice and simple.

Enjoy!

Simple merging object to object

I use View Models to hand to my MVC views, nice and slim with little if any methods on them and I use a think ORM model that has all my business logic and is generated by my ORM (BLToolkit).

So the problem is I wanted to take the View Model and update the ORM model with the modified values from the post, kind of a reverse AutoMapper (or BLToolkit.Mapper).

So a ORM class like this;

    public class Contact
    { 
         public int Id { get; set; }
         public string Firstname { get; set; }
         public string Lastname { get; set; } 
         // Loads of other properties
    }

And a View Model like this (note the type and name should be “EXACTLY” the same;

    public class ContactModel
    { 
         public int Id { get; set; }
         public string Firstname { get; set; }
         public string Lastname { get; set; } 
    }

Then with this generic Extension method;

        public static void MergeWith(this T1 primary, T2 secondary)
        {
            foreach (var pi in typeof(T2).GetProperties())
            {
                var tpi = typeof(T1).GetProperties().Where(x => x.Name == pi.Name).FirstOrDefault();
                if (tpi == null)
                {
                    continue;
                }
                var priValue = tpi.GetGetMethod().Invoke(primary, null);
                var secValue = pi.GetGetMethod().Invoke(secondary, null);
                if (priValue == null || !priValue.Equals(secValue))
                {
                    tpi.GetSetMethod().Invoke(primary, new object[] { secValue });
                }
            }
        }

So you make the magic in the Controller (for example) like this;

[Authorize]
[HttpPost]
[ValidateAntiForgeryToken]
[ValidateInput(false)]
public ActionResult EditContact(ContactModel model)
    Contact c = Repo.Get<Contact,long>(model.Id);
    c.MergeWith<Contact,ContactModel>(model);
    Repo.Update<Contact>(c);
}

Yea its cheesy, but it works for me 😉

Enjoy!

Microsoft Live Writer + WordPress

Wanting to use Microsoft Live Writer to be able to make blog entries I thought I would see what sort of super magic it would take.

To my surprise once you setup your user account to have at least the “Editor” role in WordPress  and then you enable the “XML-RPC” Remote Publishing option – your done. 😉

Super nice. Got to say that so far WordPress is an extremely polished project, there aren’t many open source projects on the same finish. The plug-in architecture and operation is something other projects should envy.

Enjoy!

Moved to WordPress

So I just could not take the spam from friggin’ BlogEngine.net and the fact that project doesn’t have a decent CAPTCHA to help block some of the SPAM is just mindboggling.

I personally don’t like getting 80-100 emails a day from those damn Payday Loan losers, I guess the BlogEngine.NET folks like that sort of stuff.

At any rate I figured WordPress should have lots of plugins for me to mess with and getting Live Writer integrated should be rather simple.

If your looking for some old posts, the search engine on WordPress is pretty good; most likely the page your looking for got moved around. I need to clean up the tags and slugs and all that bloggy stuff; perhaps tomorrow – perhaps.

Enjoy!

DotNetOpenAuth MVC Template + VS2010 + Win7 64 == crap;

Well I was playing around with trying to setup a new MVC 2.0 site to use DotNetOpenAuth and I was thrilled to see that the site has a template you can download to make an example site. Excellent I thought!

But of course then I tried it; Using VS210 (10.0.30319.1 RTMRel) and ASP.NET MVC 2 I get this lovely error once I get past the setup.aspx page;

The view at '~/Views/Home/Index.aspx' must derive from ViewPage, ViewPage, ViewUserControl, or ViewUserControl.

Humm I figure its something I am doing so I go out and get my Google fu on, I find its a common problem with VS2010 + ASP.NET MVC + Win7 64 Bit. Ah Joy.

So download the VS2008 template, using VS2008, run through the setup.aspx and viola it works like a charm. No funky errors with the template and the redirect they are doing.

Thought I would share as I was kinda sad to see that a VS2010 bug with ASP.NET MVC persisted past QA. So sad.

Enjoy!

Nice javascript to set window size for popups

This is some spiffy javascript to get the proper sizes of the window for say a nifty colorbox popup;

    var myWidth = 0, myHeight = 0;
    function setWindowSize() {
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
};

An example of using it is like this;

$.fn.colorbox({
    iframe: true,
    open: true,
    href: '/Controller/Action',
    width: myWidth - 40, // just a bit smaller than the window
    height: myHeight - 40 // just a bit smaller than the window
});

Dont forget to bind the window resize to reset your size variables;

$(window).resize(function(e){
    setWindowSize();
});

Enjoy!

Two forms same page?

I have a page that has two forms in the same page, the catch is the second form is nested inside the first form. Well this violates W3C, and it seems that IE8 doesn’t work with it. Color me surprised that IE8 actually is doing what it suppose to do according to the HTML specs.

Anyhow I needed this to work for my form to function and I was limited on time. So here is what I did to make the submit work with IE8.

1. Remove the “Submit” on the Button and just make it plain button;

2. Add some jQuery magic to submit the first (the outer) form;

$("#Save").click(function() {
    var form = $("form:first").serialize();
        $.ajax({
	    type: "POST",
	    url: "/Tickets/Edit/",
	    data: form,
	    success: function(msg) {
	    window.location = '/Tickets/Details/';
	    }
	});
});

Enjoy!

Ramblings of an often confused opinionated yak shaver.