Posts

Showing posts from 2012

Windows 7: One Network Adapter, Two Connections; No Internet Connection

Image
For the past week, my main PC has been occasionally booting with a lovely little yellow exclamation mark over the network icon in the system tray. The only way to rectify it was to reboot once or twice, which confused me a little bit. Anyway, to cut a long story short, it's the Bonjour network service that was recently installed with Skype (I'm currently working at home and we're using Skype to communicate). It seems that the best way to solve this (without affecting Skype) is to "Delay Start" the service. The service (and it doesn't sound like this happens on everyone's machine) is pretty easy to find, only because it's got a GUID for a name in the Services snap-in (Start Menu -> Administrative Tools -> Services): GUIDs: scaring the shit out of advanced computer users since 1998. Suffice to say, it looks dodgy, so it was investigated. Luckily, there's plenty of info on Google about it. Just change the startup type to "Automati...

AutoMapper: UseValue vs ResolveUsing vs MapFrom

I just hit a confusing mapping bug whilst using AutoMapper  to map DateTime.Now to a field in my database. Every item that was being added to the database had the same value in the "DateAdded" - to the millisecond. This was because I was using the following mapping expression: Mapper.CreateMap<SourceObject, DestObject>() .ForMember(m => m.DateAdded, o => o.UseValue(DateTime.Now)); UseValue() retrieves a value on first-run and stores it in the mapping (hence the static DateTime value that's being stored in the database), whereas ResolveUsing() resolves at run-time - which is obviously why it's called Resolve Using(). A minor oversight, but confusing nonetheless. Use ResolveUsing(s => {}) when you want to resolve a destination field from a derived value. This should be used for any DateTime mappings, and any more complicated mapping functions. Use MapFrom(s => s.MemberName) when you return an actual source object member. Use UseValue() if you...

IMDB API Lookup JQuery Plugin

I spent a few hours last night writing my first ever JQuery plugin, only to realise today that it's completely useless to me! I wanted an easy way to populate the "Add medium" form on RustyShark , as it tends to take me a few hours every time I add a new review (and therefore medium) to the website (y'know, looking up information, finding images, finding box art, editing the review etc), and I wanted to increase my production rate :) IMDB offers its data for free, for non commercial use, but only in text files. I found an API at http://www.imdbapi.com/ , which has gone a long way to simplifying and serializing the information in to something useful, so I decided to use this opportunity to teach myself how to write JQuery plugins. Below is my resulting plugin, queryable by Title + Year, or IMDB ID: ; (function ($) { $.fn.imdbLookup = function (options) { // Default options var defaults = { complete: function (imdbData) { ...

RustyShark.com is finally online!

Regular readers will know that I've been working on my new game and film review site for a good while now. I've been spending my spare time in the past few weeks editing the reviews I've written and gathered from friends, which has been a task in itself. Unfortunately, because the site is a bit of a movie and game database as well as a review site, it takes me a while to gather all of the information for each one, so I've not been able to launch with too many published! Suffice to say, I've got a lot more to get through, but when I've caught up I should be able to edit and publish reviews as they come in. All of the reviews I've received will be dealt with ASAP! I've still got a long way to go until version 1 of the site is completely finished. I still have to write the news editing tools and there are lots of additional features I want to implement, like a Facebook login, more products from different sites and RSS feeds. Of course, I've still got ...

AutoMapper 2.1 AfterMap() Fires Multiple Times

I've been writing some complex mapping for the hierarchical data on my RustyShark site (the Media entities on the site consist of a lot of dynamic meta data, which can be added and removed when edited). I'm using Entity Framework and AutoMapper, and I've ran in to an issue where AfterMap() executes multiple times, when it should only really execute once. I just thought I'd post my workaround, which also helps to demonstrate how C# interfaces can be handy. Here's what my source entity looks like: public class Medium : IAutoMapperAfterMapUsage { public int ? MediumID { get ; set ; } public string Title { get ; set ; } public DateTime ReleaseDate { get ; set ; } public User CreatedBy { get ; set ; } public DateTime CreatedDate { get ; set ; } public List<Genre> Genres { get ; set ; } public List<MediaFormat> Formats { get ; set ; } public List<MetaData> MetaData { get ; set ; } #region IAutoMapperAft...

Long running processes: C# 5, Visual Studio 11, async and await; updating a Winforms UI asynchronously

Image
I recently downloaded Visual Studio 11 Beta  in order to take a look at the new 4.5 .Net Framework and play around with its new features. I decided to take the opportunity to build a "quick" app that I've been meaning to build for a few years; a single form Windows Client that allows me to send out an email merge to the 1,400 agents I have in my outlook contacts list, to let them know I'm available for work. Before now, every time I've needed to send an "I'm available!" email, I've copied + pasted the same email a number of times, attached my CV and BCC'd 100 or so agents at a time (too many and Outlook just falls over). Not only is it a massive waste of my time, but it's very error prone and not a very friendly way of doing things. Unfortunately, the mail merge feature of Word has its limitations, so I've had to look in to my own solution. Anyone who's worked with bulk email systems before knows fine well that any kind of mas...

A learned journey

As a mercenary developer, I come across programmers from many different walks of life; of all skill levels and abilities with varying levels of enthusiasm. Whilst I'm certainly not perfect (and am always learning), I encounter some who are yet to grasp some of the more basic programming concepts. It's very easy to take a blinkered view of the technologies you're familiar with and to become complacent in your current role or too comfortable with your existing skills. On the other hand, some developers I encounter are far keener than I, and therefore usually far exceed my skill; two things which are directly related. I speak from first hand experience when I say that by taking a step outside of your comfort zone and making even one or two small changes to your daily routine as a developer could seriously improve your general programming knowledge and overall productivity. Although not quite ad-verbatim, I think it was Scott Hanselmann who recently blogged that simply stat...

MVC3: Redirect Action to HTML Bookmark

I'm currently in the process of writing my next personal project,  RustyShark  in .Net MVC3. It's a game and films review site, and will hopefully generate a bit of a community. Each review on the website has a comments form at the bottom that readers can use to post their own mini review, or just a simple comment. I'm using unobtrusive client side validation, but (as it should) the validation also occurs on the server side. This means that the user could potentially receive an error message on the comments form after a post-back but not notice it, as they will be redirected to the top of the page, rather than the comments form. The "read review" page is accessed via the fairly standard route /Reviews/Read/{titleURL}, which means the reviews controller exposes the Read action method. The Read method has a single override which is tagged with the [HttpPost] attribute as follows: public class ReviewsController : Controller { public ActionResult R...