Me Love You Runtime Code Monkey!

Sitecore media and an mp3 player

Recently, I had a bit of a pain with adding an mp3 player to pages for playing files held in Sitecore. Here’s a bit of background to the issue: the client wanted an mp3 player like a sister site of theirs has on their site. The sister site does have a player, but the mp3s are served by their Wordpress blog. In our client’s case, they will be uploading mp3s to the Sitecore Media Library.

The task was simple. Search for any link with a class of “audio” or where the extension is .mp3. Whack in the player over that. All done in 30 minutes. Testing in Firefox, it worked fine. In IE, Chrome, Opera and Safari it would play the mp3, but the display would say “Connecting…” and stick with this while playing. I used the standalone version of WP Audio Player

I ended up comparing all the headers with a working version and noticed that requesting from Sitecore gave no content-length. Apparently Sitecore (up to 6.4.1 update 1) does not include this essential header.

I wrote to Sitecore who replied with: To add the “Content-Length” header to the “Response” headers, please perform the following steps:

  1. Compile the “CustomMediaRequestHandler.cs” file (the file is attached) and copy DLL to the “bin” folder.
  2. Change the old handlers in the “configurationsystem.webhandlers” and “configurationsystem.webhttpHandlers” with the new ones:

For example:

<handlers><add verb="*" path="sitecore_media.ashx" type="Sitecore.Customization.CustomMediaRequestHandler, Sitecore.Customization" name="CustomMediaRequestHandler" /></handlers>
<httpHandlers><add verb="*" path="sitecore_media.ashx" type="Sitecore.Customization.CustomMediaRequestHandler, Sitecore.Customization " /></httpHandlers>

I have attached the Sitecore.Customization.dll I created for this which is the compiled CustomMediaMediaRequestHandler.cs (Download Sitecore.Customization.dll here or the zip here). Clear cache and BINGO! All good.

One other thing to this little tale. Make sure, if you are searching through Mime types in Sitecore (in web.config and MimeTypes.config), that mp3 is set to audio/mpeg, not audio/mp3 which they seem to have done.

I hope this helps someone.

Mercurial: Adding a remote repository

For home projects I have started using Mercurial. I have a fairly good grasp of Git and DVCS. I have been using Bitbucket for this and it’s pretty damn slick. But one thing they don’t say is how to add a remote repository to your existing code. It just shows how to clone. With Git the way to add a remote repo is: remote add origin [remote repo url here]

But in Mercurial, there doesn’t seem to be such a thing. I’m sure there is, and please, if you have found one, just leave a comment. In the meantime, the best I have is to add an hgrc file in your .hg folder (created when hg init is run). This should contain the following:

[paths]
default = https://[your repo url here]

I hope this helps someone.

ORA-28001: the password has expired

Recently, I have been working with a client who uses Oracle as their database. We have been running Sitecore from this and it works ok, bar a few bugs.

However, one day, without warning, we started getting the following error:

ORA-28001: the password has expired

Great. After some searching, we realised it is easily fixable. You need to get into the server and open SQLPlus, Oracle’s command line tool.

Type in the user and password. You will then get an error that your password has expired. It should then start the process to change it. You can use the old password (depending on settings) or type a new one.

Micro ORMs

I’ve always been a little wary of ORMs. Linq to SQL, Entity Framework, NHibernate. They’re all powerful, great to use and ease up development time quite a bit. The reason I’m not sure about them is the Select n+1 issue, general performance, tweakability and, well, DBAs don’t particularly like them, and if they don’t like them, I wonder how that can be good for the database they control.

Enter the micro ORM. Yes, we are going back to writing SQL, they are just small libraries that take your SQL, and convert them to objects. It makes for much better performance and DBAs should be much happier to write their stored procedures for you to consume with fewer issues.

The current micro ORMs are: PetaPoco: http://www.toptensoftware.com/petapoco/ Dapper: http://code.google.com/p/dapper-dot-net/ Massive: https://github.com/robconery/massiveMr. Scott Hanselmann also covers this.

What are your thoughts on this? Is it a bit too light? I can see both the benefits and downsides, but it is an interesting way of working.

CruiseControl.net Log Cleanup

I’ve recently got well into CruiseControl.net. Having a server building, testing and even packaging for you is, well, brilliant for so may reasons which I will not get into here.

However, at my current work, we constantly use up space with log files, every build builds a log file, and as we have a huge amount of code to compile, it gets messy quickly. Gigs of files which we will only use the last 10 of at the most.

One dev wrote a Powershell script which just scans the logs folders and deletes any logs older than a certain date. Pretty good, but I realised there is a cleaner built in to Cruisecontrol.net already called Artifact Cleanup Publisher (added in version 1.6).

You just add the following in your publishers area for projects in your Cruisecontrol config file:

<artifactcleanup cleanUpMethod="KeepLastXBuilds" cleanUpValue="50" />

Let’s put that in the context of a project:

<publishers>
   <xmllogger/>
   <artifactcleanup cleanUpMethod="KeepLastXBuilds" cleanUpValue="10" />
</publishers>

This will then only keep the last 10 logs, you can also cleanup by file age. You can read more here: http://build.nauck-it.de/doc/CCNET/Artifact%20Cleanup%20Publisher.html