RedshirtMB/trakt-mb3 — pull request #21 by LukePulverenti (2013-05-18 14:57:04+00:00)
Title: Re-worked sync from trakt task

This is completely untested so i'll leave that to you. Notes:

- You need to break down methods into small units of work so that you're not writing functions with 100+ lines of code.

- Avoid SingleOrDefault unless you actually need it. FirstOrDefault stops at the first match. SingleOrDefault always loops over the entire collection.

- I improved the where clause to try and weed out movies and episodes that will not be synced, thus improving the progress reporting.

- Similarly, I removed the continue statements so that progress is always updated after each item, whether it syncs or not.

- Don't test strings for null, use string.isnullorempty

- When properties are nullable, you can't perform equality tests on them without checking for null or they'll throw an exception when they are null. I cleaned most of them up by defaulting them to -1, but I might have missed some.

- Your save user data code is inconsistent between movies and episodes. Movies set Played, PlayCount and LastPlayed, while Episodes only set Played. Please note that Played is not a very good name. It really means Completed. For example, if I watch 1/4th of a movie three times, I'm now 3/4th of the way through the movie. PlayCount = 3, Completed = false. LastPlayedDate = date of last play.

- Make sure dates saved are in utc. I will soon update the core to throw exceptions if you supply a value that is not utc.