The funniest adverts ever

I came across these adverts on the apple website today – they are just so FUNNY! Now I’m not saying they are all completely factually correct, but the acting is so good, they play up to the sterotypes of macs and pcs something rotten – they are just pitched so perfectly at the viral market!

http://www.apple.com/getamac/ads/?better_medium

[tags]windows, apple, mac, advert, ad[/tags]

Robert Burke – Flickr Assistance

Just a quick post to introduce another application which is using the Flickr.Net API Library.

Rob Burke has been helping me for a while with various problems we where having with the code, most specifically the Medium Trust stuff, so a big thanks to him. He’s also developed what could be a very useful little tool for helping to sync a local copy of images against Flickr. I’ve yet to give it a try, but there is certainly a need for this kind of tool.

Robert Burke’s Weblog : Introducing Little Syncr

Coding Horrors

I found me a new blog to read (like I need more, I have 179 feeds in Bloglines currently).

Coding Horror

Its similar in essence to what I kinda aim to do with my blog, although he’s being a bit more successful (i.e. A coding blog with a bit of other stuff, whereas mine is more a other stuff blog with a bit of coding, and not updated as often!)

Anyway, I thought I’d quickly mention two of his recent posts that caught my eye.

Coding Horror: C# Snippet Parity

Microsoft have apparently released a new set of code snippets for C#. Now I’ve never been a big user of code snippets in general, although I have started to use the property ones in Visual Studio 2005 quite a lot. But having installed these code snippets I have even learnt a thing or two. Examples include capturing the output from a console app, pinging a web site. There are many other useful code snippets that could save so much time and effort, and also result in better code (such as some of the database snippets that wrap execute statements in a try finally block to make sure connections are always closed).

Coding Horror: Darwinia

I looked at this entry and thought – looks interesting, wonder if there is a demo. Quick jump to the web site and minutes larger I’m blasting little red pixels to protect my little green pixels (it really is that basic on some levels). After completing the demo level I almost immediately paid for the full game (only $20 if downloaded via Steam), minutes later I’m playing the game and many hours later (late into the night) I emerge bleary eyed, it has proved an absolute winner. I may have to check out their previous game Uplink which is also meant to be very good. I also think the future of games is the download distribution model. (They have a new game due soon as well, Defcon).

Darwinia

Flickr.Net API and Medium Trust

I’ve had a few requests to get the FlickrNet API Library working in Medium Trust mode under ASP.Net, so I thought I’d look at it. Here lies the tales and tribulations that such a journey took.

What is ‘Medium Trust’?

Good darn question. I wasn’t actually sure until I looked it up. Basically its a more secure environment for ASP.Net, often in which you might find yourself if using ASP.Net hosting on a shared server. It means you can’t iterate through all the directories on the server and read a load of files, and it also has other restrictions, which I’ll get to in a bit. (Read this for more details on the permission levels for each type of built in trust level.)

Where To Start

First thing is first, put a test web site into ‘Medium Trust’ mode.

Add the line to your system.web of either your applications web.config (for testing) or your machine.config.

<trust level=”Medium” />

Easy so far.

The only thing is this just gave me a generic “SystemException: Security error” which was no help whatsoever.

What Next?

Turns out that if I took OUT the [assembly:AssemblyKeyFile()] attribute from the AssemblyInfo.cs file it got rid of the above error, and gave me another one. But at least this new one has a line number associated with it! I still haven’t managed to find a reason for this, but for now the FlickrNet assembly isn’t signed. I shall probably have to start distributing a signed and a none signed version if I can’t find an answer to this one.

(Update: Found out what the problem was here. When in Medium Trust mode the web application is considered a ‘partial trust’ application and by default code libraries do not allow partial trust applications to call them. I’ve added the AllowPartialTrustCallersAttribute() to the assembly and this is now working correctly. Hurray. See here for blog post)

File IO Errors

The main effect that Medium Trust has is on file access. You are not allowed to browse directory or create files outside of your own virtual web directory. Therefore I was obviously going to have to look in further detail at the caching infrastructure, specifically where it created these files.

I made all these changes (eventually), as well as adding the ability to specify the cache location from within the configuration file (and then added the ability to specify it at runtime as well, which took a bit more work).

Unmanaged Code

I didn’t have any unmanaged code in the API, or so I thought. Then I came across a bit of code which called the Marshal.GetHRForException method. This converts a .Net Exception into a HRESULT integer, i.e. an old school Win32 error code. The code in question was used to distinguish a file locked error from other types of IOExceptions. And hopefully unsuprisingly (from the description I’ve just given you) you should be able to tell that this method is effectively a call out to unmanaged code. I’ve yet to work out a replacement for this code so at the moment its commented out.

Miscellaneous others

Other various things I had to work around was access to System.Net.WebProxy.GetDefaultProxy() static method, which throws an exception if called in Medium Trust. So I wrapped a try catch around this to catch that error. Then it turned out you cannot assign “null” to a HttpWebRequest.Proxy property if you are running in Medium Trust as well. Strange I though, but thats fine too (who wants to assign null to it anytime!)

The Final Stumbling Block – Shot in the Head?

Finally, everything compiled and I could create an actual Flickr class instance successfully. Then came the time to perform a quick test to Flickr.

Bam – turns out that any WebRequest to any web site (apart from the local web server) is blocked under Medium Trust. What? How is anyone ever going to use the FlickrNet API library under these scenarioes.

There is a Code Access Security document that is included with DotnetNuke that says the following code in your web.config will fix this particular problems:

<trust level=” ” originUrl=”http://www.flickr.com/*” />

The document also details ways to create a custom medium trust level. So if you are working in a modified medium trust envorinment you probably wont have this problem. You’ll either have to ask your hosting provider or just play around to see what works.

As an aside, if working in the above Medium environment then picture downloading will not work, as pictures are hosted at http://static.flickr.com and not http://www.flickr.com. But then it you’re working on a web app you probably just want to output the URL to the web page for the user’s browser to download anyway.

Conclusion

It has been a fun run around the .Net Framework for this one little feature, so I hope you all appreciate the work :)

[tags]microsoft, security, asp.net, .net, web, flickrapi[/tags]

Performancing Plugin – Blogging tool for firefox

Well, I’ve just installed the Performancing Plugin for firefox. And I have to say, so far it kicks ass! Having a split screen interface from within firefox in which I can type my blog posts, make notes, post to any blog I want to (wordpress, blogger, movabletype etc), all the time being able to search the interenet and browse is great. Its even WYSIWYG! This could actually be a stand alone blogging tool without too much trouble.

The only thing left I can see is for my notes and settings to be stored centrally so I can blog from any browser with the plugin installed!

Strange ASP.Net 2.0 Error

While developing a new web site using ASP.Net 2.0 recently I came across this strange error on compilation.

Cannot implicitly convert type ‘string’ to ‘System.Web.UI.WebControls.TextBox’

It took my ages to work out what the hell was the problem, which string was it trying to convert?

The problem occurred because of the new Page.Title property. I had a TextBox whose ID was also set to Title. It was therefore trying to convert the string in the Page declaration into a textbox – not gonna work! This Title property is new for ASP.Net 2.0 so you might want to watch that one in your apps.

FlickrNation Podcast

I’d just like to thank [Thomas Hawk](http://www.thomashawk.com/) who has recently started a new podcast called [FlickrNation](http://www.flickrnation.com). Its up to its 3rd episode so far and I just got some serious pimpage. I must say I really get a huge ego boost out of this kinda thing (I must be slightly shallow I guess :) ).

He mentions my new [Delete Me Resurrection](http://undeleteme.blogspot.com) blog, plus the wonderful (but sometimes hard going) [Entrance To Hell](http://www.flickr.com/groups/entrancetohell/) group.

He’s also got other stuff about things that are happening in the Flickr community, such as the debate that seems to be going on about none photos uploaded to Flickr and their place in the community. Personally I think the lines drawn between ‘art’ and ‘photography’ can be so grey an area I don’t see how you can enforce the distinction.

I also spotted a great Wikipedia article that was article of the day yesterday, about the [Canon T90](http://en.wikipedia.org/wiki/Canon_T90), the last manual focus that Canon produced before they moved on to the EOS range (disclaimer: I have 3 Canon cameras, an Powershot A70 P&S, the EOS 350D digital SLR, and my newest toy, a EOS 300V film camera for messing about old stylee with).