tag:blogger.com,1999:blog-21537515477880860732009-07-14T11:43:23.290ZMJJames - Web DeveloperA Web Developers View on Grasping New TechnologiesMichael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.comBlogger125125tag:blogger.com,1999:blog-2153751547788086073.post-83853665240243014782009-06-26T19:16:00.007Z2009-06-26T22:12:26.778ZFlickVimTube - An FCKEditor Plugin<p>First things first, ignore the random title for this post, it does have a meaning and it's the best I could up with ;)</p>
<br />
<p>The other evening I was hitting some downtime and rather than carry on playing FarCry 2 I decided I'd write a quick <a href="http://fckeditor.net">FCKEditor</a> plugin which I've been meaning to write for a while. By default the editor comes with functionality to insert flash files into your content which works well however I wanted to have a way to only insert online videos from Flickr, Vimeo or YouTube. To insert these I was having to manually go into source view, paste in the embed code etc. A chore and a heartache.</p>
<br />
<p>So enough was enough and I banged together a quick plugin that would take a YouTube Embed URL and then insert the appropiate embed HTML for it. This was actually quite simple. I worked out there was four main steps, 1. Extract the video ID from the URL 2. Create suitable embed markup and insert into the editor 3. Create a preview video so you can ensure it works before clicking ok. 4. Be able to view and update the video after inserting.</p>
<br />
<p>Extracting the video ID I'm sure could be done using some clever regex expression however for simplicity and speed I opted to simply slice the YouTube url at ?v= bit and then use the remainder as the ID. As the official embed url is in the format http://www.youtube.com/watch?v={id} I have decided for my first version of this plugin I can nievly split, however I should really parse it properly.</p>
<br />
<p>
To insert the embed object I made use of some build in FCKEditor methods to create the object and then assign the attributes to it. </p>
<pre><code class="javascript">
e = FCK.EditorDocument.createElement('EMBED');
SetAttribute(e, 'src', embedUrl);
SetAttribute(e, 'type', 'application/x-shockwave-flash');
SetAttribute(e, 'pluginspage', 'http://www.macromedia.com/go/getflashplayer');
SetAttribute(e, "width", GetE('txtWidth').value == '' ? 360 : GetE('txtWidth').value);
SetAttribute(e, "height", GetE('txtHeight').value == '' ? 150 : GetE('txtHeight').value);
SetAttribute(e, "allowscriptaccess", "always");
SetAttribute(e, "allowfullscreen", "true");
</code></pre>
<p>
After getting the basics working I decided to add support for Vimeo and Flickr. This was a case of just working out which service it was and then parsing out the id's and then setting the correct embed URL on the embed object.
</p>
<p>FCKEditor plugin's are dead easy to configure, in your fckeditor settings file simply register the plugin using FCKEditor.Plugins.Add and ensure your custom toolbar settings include the button, 'OnlineVideo' </p>
<pre><code class="javascript">
FCKConfig.ToolbarSets["mjjames"] = [
['Cut','Copy','PasteText','-','SpellCheck',
'-','Image','OnlineVideo','Table','Rule','Smiley','SpecialChar','-',
'Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat','-','Link','Unlink','Anchor','-','Source'],
['Style','FontFormat','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyFull',
'-','Bold','Italic','Superscript','OrderedList','UnorderedList','-','Outdent','Indent']
];
FCKConfig.Plugins.Add('OnlineVideo', 'en');
</code></pre>
<p>The plugin file includes language settings for english, however adding additional languages can be added by simply providing translations for the labels and then changing your plugin registration to include the new file name. If you want to add French for example create a file called fr.js in the plugins languages and then the plugin registration becomes:</p>
<pre><code class="javascript">
FCKConfig.Plugins.Add('OnlineVideo', 'fr');
</code></pre>
<p>The following language settings are available: <br />
OnlineVideoTip, DlgOnlineVideoTitle, DlgNoVideo, DlgInvalidVideoUrl, DlgOnlineVideoURL, DlgOnlineVideoWidth, DlgOnlineVideoHeight, DlgOnlineVideoQuality, DlgOnlineVideoLow, DlgOnlineVideoHigh. </p>
<br />
<p>The plugin can be downloaded as a <a href="http://development.mjjames.co.uk/scripts/JS/FCKEditorOnlineVideoPlugin.zip">zip file</a> and is licensed under <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0 License </a></p>
<br />
<p>In the future I intend to extend this further, maybe to allow users to find and search for videos using the various API's provided by the video sources but that will be at a later date.</p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-8385366524024301478?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com2tag:blogger.com,1999:blog-2153751547788086073.post-79849134033658945232009-05-19T19:58:00.004Z2009-05-19T20:47:03.796ZWasting Bandwidth One Image at a Time....<p>Content Management Systems are great, they allow the average Joe to have a great level of control over their website. Gone are the days of clients asking for static pages to be amended, we live in the database powered give the power of editing and updating content to the client</p>
<br />
<p>Our clients get to use Rich Text Editors like FCKEditor. They look and feel just like Microsoft Word, they can play with text, upload images, resize them simply by dragging them and are very often really happy.</p>
<br />
<p>However this often comes at a cost. Most RTE's by default simply resize images by sticking on the HTML img attributes height and width. As many people are aware this doesn't actually resize the image, it just simply tells the browser take this massive image and render it smaller. The end user still has to download the huge image, I have seen on some sites 2000px x 1200px images being downloaded and then only shown at 250px x 120px!, which can take a while to load dependant their internet connection and ultimately we the developers have to pay the bandwidth cost for those images.</p>
<br />
<p>Tonight I decided to come up with something I could put on my church websites to combat this. It's more to aid the overall user experience rather than bandwidth cost but it all helps ;)</p>
<h2>The Solution</h2>
<p>The solution is actually really simple.</p>
<ol>
<li>Take the CMS content from the database </li>
<li>Before rendering it to the page, parse it into a HTML Parser</li>
<li>Using the parser find all the image tags</li>
<li>Using the height,width and src attributes to generate a new URL to an image resizer app</li>
<li>Replace the images src attribute with the new URL </li>
<li>Render the content to the page</li>
</ol>
<p>Parsing HTML in ASP.Net really is easy nowadays. Previously it was a pain, regex would never work properly or you could risk parsing your page as XML but luckily there are now tons of 3rd party libraries. I chose <a href="http://www.codeplex.com/htmlagilitypack">HTML AGility Pack</a> as alot of people seemed to recommend it on <a href="http://stackoverflow.com">stackoverflow</a></p>
<p>For my solution I simply did the following:</p>
<pre><code class="c#">
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(page.body);
HtmlNodeCollection imgs = doc.DocumentNode.SelectNodes("//img");
if (imgs != null)
{
foreach (HtmlNode img in imgs)
{
if (img.Attributes["height"] != null && img.Attributes["width"] != null)
{
HtmlAttribute src = img.Attributes["src"];
string imgurl = src.Value;
src.Value = String.Format("/loadImage.aspx?image={0}&action={1}&width={2}&height={3}", imgurl, "resizecrop",img.Attributes["width"].Value, img.Attributes["height"].Value);
}
}
}
mainContent.Text = doc.DocumentNode.InnerHtml;
</code></pre>
<p>So what's going on here? Well first I create a new HtmlDocument, provided by the HTMLAgilityPack. I then load my html from my db model, page.body, then I use a nice simple XPATH syntax to pull out any img tags within the content and stick them into a HTMLNode collection. Next after ensuring I have some nodes, I spin through each of them and check to see if they have a height and width attribute. If they do then I use these and the original image url to write a new url, in my case I have a page that does this, ideally though this should be a httpmodule or something to be nice and tidy. Then with the img tags updated I render the HtmlDocument back out to the page.</p>
<br />
<p>That's it, a few line's of code. Now I was concerned I may have slowed down my page, as parsing and spinning through tag's could be CPU intensive however I found on my machine and quickly playing with it, I noticed no real difference. In production I'd output cache the page for a period of time anyway. I noticed 100KB difference on one of my site's home pages and they weren't massive images, so I think it's well worth it.</p>
<br />
<p>There you have it, at the end of the day CMS's provide users with alot of power / flexibility but we have to ensure as developers that we provide systems that cater for users abusing the system, be this uploading massive images or otherwise. In the case of images simply having something that resizes the images on render keeps the frontend responsive whilst allowing the client to provide high resolution images if needed, in this case it wasn't alot of effort and the improvement alone was worth it.</p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-7984913403365894523?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com2tag:blogger.com,1999:blog-2153751547788086073.post-74641826702031492712009-04-29T15:01:00.002Z2009-04-29T21:10:47.815ZContent Disposition in different browsers<p>Today I had to resolve an issue where in different browsers the filed dynamically generated download worked very differently / at all</p>
<br />
<p>The setup, we had an xml file with a custom extension, say .mj, which was being served up by ASP. The HTTP Header had a content disposition header and a response type set.</p>
<pre><code class="vbscript">
Response.AddHeader "Content-Disposition", "attachment; filename=""our file.mj"""
Response.ContentType = "text/xml"
</code></pre>
<p>This worked fine in Internet Explorer, the file was downloaded as "our file.mj". However FireFox and Chrome acted very differently, in FireFox the file was downloaded as just "our", and Chrome as "our file.xml".</p>
<p>In FireFox it appears that the issue is caused by having a space in the file name, this <a href="http://www.webmaster-talk.com/asp-forum/35962-content-disposition-does-nto-work-firefox.html">forum post by funkdaddu</a> helped me on this, so by removing the space FireFox could now download the file as "ourfile.mj".</p>
<br />
<p>Chrome however did not want to play ball. It was still insisting on changing the file extension to ".xml". I guessed it was because we were telling it we serving up text/xml mime/type under a different file extension, I decided to change the response type to "Application/Save" just to see if this would make a difference, and amazingly it did. Amazing!</p>
<br />
<p>So there we have it, changing the file name to have no spaces and ensuring that the content type is set to "Application/Save" seems to make all browsers behave at least some what consistently with the Content Disposition header. Its worth noting that Scott Hanselman has a great blog post <a href="http://www.hanselman.com/blog/TheContentDispositionSagaControllingTheSuggestedFileNameInTheBrowsersSaveAsDialog.aspx"> The Content Disposition Saga</a> which talks alot about how the different of IE handles it. Also GreenBytes has a ton <a href="http://greenbytes.de/tech/tc2231/">Test Cases for HTTP Content-Disposition header</a> which I certainly found helpful.</p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-7464182670203149271?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com0tag:blogger.com,1999:blog-2153751547788086073.post-46193972705344024432009-04-23T15:59:00.010Z2009-04-23T16:33:04.886ZLooking for a URL using Linq and SiteMaps<p>I've been off sick from work with Man Flu but this afternoon I was getting bored of staying in bed for the second day so I got out my laptop just to have a play in between blowing my nose.</p>
<br />
<p>I wanted to write a quick way of looking up the full url path for a page within a sitemap. The only bit of information I know is the key of the page. Now I knew that I could possibly make use of the IndexOf method. This expects a SiteMapNode of the value you are looking for and returns the index of the node, you then need to get the node out of your collection of nodes, example below.</p>
<pre>
<code class="c#">
SiteMapNodeCollection nodes = SiteMap.RootNode.GetAllNodes();
int nodeIndex = nodes.IndexOf(new SiteMapNode(SiteMap.Provider, pagekey));
return nodes[nodeIndex].Url ?? String.Empty;
</code>
</pre>
<p>Now that method does work, however it felt dead clunky, I was sure I could write a more .Net 3.5 shiny one line way of doing this using Linq. In fact it was dead easy. First I still needed to get all the nodes, SiteMap.RootNode.GetAllNodes(), but I then cast these to SiteMapNode, I could then use FirstOrDefault with a nice lambda expression that matches the key property. Code below. </p>
<pre>
<code class="c#">
SiteMapNode node = SiteMap.RootNode.GetAllNodes().Cast<SiteMapNode>().FirstOrDefault(n => n.Key.Equals(pagekey));
return node != null ? node.Url : String.Empty;
//note: the </sitemapnode> is not part of the code, the code highlighter JS is randomly adding it.
</code>
</pre>
<p>Simple, my only concern is that the bigger the sitemap becomes the more memory / slower this becomes, especially if called multiple times per page. It may make sense to cache the sitemapnodecollection for the duration of the page however that's beyond the scope of this brief article.</p>
<br />
<p>What hopefully you can see though is that a little bit of Linq and Lambda expressions can take chunks of code that seem long winded and turn them into nice neat one liners, which I think is usually more readable.</p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-4619397270534402443?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com1tag:blogger.com,1999:blog-2153751547788086073.post-84820391098620200402009-04-22T13:25:00.004Z2009-04-22T14:23:07.763ZBook Review: ASP.Net MVC 1.0 Quickly<p>So this month I again have the privaledge of writing another book review. This time in an area I have particular interest. ASP.Net MVC has recently been released and there are no end of books coming out of the market, one of these being <a href="http://blog.maartenballiauw.be/">Maarten Balliauw</a>'s <a href="http://www.packtpub.com/asp-net-model-view-controller-1-0-quickly/book/mid/300309msa6ak">ASP.NET MVC 1.0 Quickly.</a></p> <br />
<p>When the book arrived I first noted how it used the traditional orange Packt colour scheme with an interesting picture of a pair of glasses on the beach. This I preferred over the look of the <a href="http://urls.mjjames.co.uk/bookreview1">last book I reviewed</a>, however I am yet to work out the significance of the picture if there even is one?</p> <br />
<p>The book starts by saying that the book will take you through "the essential tasks" and "does not cover every single feature in detail". This is my opinion is not a bad thing. It is not a full reference book like ... but more of a rapid guide to get developers to start using MVC and know the basics preety much everything, you can then get the in depth knowledge as you go along.</p> <br />
<p>The book covers the following topics, not necessarily in order:
<ul>
<li>What MVC Is</li>
<li>Brief comparison between ASP.NET web forms and ASP.NET MVC</li>
<li>What a Controller, View and Model is and how you go about creating them in VS</li>
<li>What the process of a page is and how you handle interactions</li>
<li>What is routing and what you can do with it</li>
<li>Customizing the framework</li>
<li>Using Web Forms features in MVC</li>
<li>JQuery and AJAX in MVC</li>
<li>Testing and Mocking</li>
<li>Deployment</li>
</ul>
</p><br />
<p>It then has three appendices which I recommend NOT skipping, It has a full application with source code, information on the MockHandlers available and finally tons of links on where to get more information on topics. The links help to fill in the gaps that the book has left due to its "quickly" approach and for me at least have been the most thumbed pages of the book.</p>
<br />
<p>The format of the book is very clear, lots of examples in C#, screenshots where appropiate and well worded. In particular I like areas where Maarten Balliauw takes the time to explain all the options for an attribute. For example in Chapter 4 he outlines Action Method Attributes, rather than just give a brief description of what they are, Marten takes the time to outline briefly all the possible attributes with a simple piece of source code if appropiate. Again this highlights how the book is just trying to make you aware of what exists so when you come to write something you think about what you could use and then go away and find out more if needed. </p> <br />
<p>I have to admit I really like the book as an intro into MVC and to get people aware of it, it highlights alot and get's you thinking about design methodologies. It's one I recommend others to read.</p>
<h3>Scores</h3>
<p><strong>Presentation</strong> 8/10 - Overall this book feels well put together and everything is clearly laid out</p>
<p><strong>Code Examples</strong> 9/10 - Quite a high score for this, the book it littered with short code snippets and examples but what really does it for me is the example application included in the appendices. Simply working through this highlights everything you have read so far and highlights more. Well worth looking at</p>
<p><strong>Quality of Content</strong> 8/10 - Again repeating what I have said earlier but I feel the content has been well put together and arranged in a manner that is clear and conjusive to learning </p>
<p><strong>Overall</strong> 8/10 - If you are looking at just finding out about this ASP.NET MVC is all about and just want an outline to get you started this book is for you. It's not claiming to be a reference but a starting block to use to get you started, the links in the back give you some where else to go afterwards. Well worth a read.</p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-8482039109862020040?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com1tag:blogger.com,1999:blog-2153751547788086073.post-23043603715351406432009-03-28T14:41:00.005Z2009-03-28T14:58:47.189ZGoogle SiteMap Generator + Input validation failed Error<p>Since Google release their <a href="http://code.google.com/p/googlesitemapgenerator/">Google Site Map Generator</a> I have been using it on my web server for the sites that I manage. Setting it up and getting it running was fine and I haven't had a problem, that was until this week. </p>
<br />
<p>This week I noticed that as I was only letting the generator update the sitemap from actual URL hits quite often a few of my sites aren't hit for a day at a time which was resulting in empty sitemaps. This then causes Google WebMaster Tools to whinge at you which isn't a good thing. So I decided to update my settings to include parsing my IIS Log Files in the hope it would use previous days ones and not generate blank files.</p>
<br />
<p>This is where I hit a road block. When ever I changed a setting and clicked save the generator would be really useful and tell me that "Input Validation Failed" and to basically sort myself out. I was confused to say the least as everything was fine, no field was highlighted as being erroneous so I ended up giving up and leaving it.</p>
<br />
<p>Today I came back to it and tried again but the same error occurred. So I started to poke around and decided to manually update the sitesetttings xml file, usually located: C:\Program Files (x86)\Google\Google Sitemap Generator\sitesettings.xml. And this is when I noticed the issue that was affecting me.</p>
<br />
<p>Each site within your IIS setup has a node in the sitesettings xml file, here it has information about it's host name, whether it's setup for sitemaps etc. But it also contains the location of the IIS log files regardless of whether you are parsing them or not. </p>
<br />
<p>Now a few weeks ago I decided to move all my sites log files from the default location of C:\WINDOWS\system32\LogFiles\{site} to a more convenient location, for this example lets say E:\LogFiles\{site}, now this was all well and good for IIS etc but upon creation of sites the Google SiteMap Generator is logging these locations. So when I had moved the log files the generator was still looking at the old location, a bit of guessing / how I would do it lead me to believe that upon saying parse log files for sitemaps the generator checks to see if it can read the log files, but as they have moved it cant find them and errors. </p>
<br />
<p>Now all I did to fix this was manually do a find and replace on the log file locations within sitesettings.xml saved the file and restarted the generator to find it was finally happy and working OK. Hopefully Google in the next release of this generator will remove this issue / make it clearer what is wrong. Ideally upon startup or even when you choose to use log file parsing it should look at IIS to see if the path to the log files is the same as it has, if not update it before it validates. This would save heartache for a few people at least.</p>
<br />
<p>So I'm now happy again with the generator, the problem wasn't that hard to fix and upon spotting it made alot of sense, it just shows what a little bit of investigating can do.</p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-2304360371535140643?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com0tag:blogger.com,1999:blog-2153751547788086073.post-44114621655681241962009-03-20T19:55:00.008Z2009-03-20T20:20:42.651ZBook Review: C# 2008 and 2005 Threaded Programming<p>So last month <a href="http://www.PacktPub.com">Packt Publishing</a> contacted me regarding sending me a promotional copy of <a href="http://www.packtpub.com/beginners-guide-for-C-sharp-2008-and-2005-threaded-programming/book">C# 2008 and 2005 Threaded Programming</a> to review. This is the first time I have been asked to do a book review and decided to take them up on the offer.</p>
<br />
<p>
Now I have been using ASP.Net for around three years now but I've never had to or decided to look into writing multi-threaded apps so the fact that this book was aimed at beginners meant that I was an ideal target audience for this book.
<a href="http://www.PacktPub.com">Packt</a> shortly sent me the book and upon first looking at it thought it looked a bit ugly! I know you can't tell a book by its cover but this cover did put me off, the green and picture didn't do it for me but alas I carried on anyway.</p>
<br/>
<p>
The book is organised into several chapters and is example driven. What I mean by this is that it doesn't give you bags of theory and then an example, it takes the approach of you following along the code examples and then it has gaps explaining bits and pieces. More on this later. </p>
<br />
<p>
The chapters within the book are organised in a way that as you progress each chapter delves into multi threading more. First of all it explains what multi threading is, then it looks as basic thread techniques, background workers, debugging multi threaded apps, thread pools all the way up to exploring the new future of multi threaded apps and new framework extensions to help with this. On the whole the chapter organisation made a lot of sense to me and allowed you to use what you had learnt before and build upon it. The one thing that struck me was that I expected ThreadPools to be talked about way before chapter 9 but that’s a minor thing.</p>
<br/>
<p>
One of the things I especially liked about this book is that at the end of each chapter you are given a quick pop quiz on the chapters content, this for me at least provided a quick way of ensuring I had understood the chapter and if I hadn't to go back and re read it, so this was good.</p>
<br />
<p>
As I mentioned earlier the book is based on learning using examples and less about theory. Personally I'm not a huge fan of this technique; the writer Gastón C. Hillar does try to provide examples that are practical however I find that by simply following these you don't really learn what is going on; you learn how threading roughly works and that it’s there but when you need to use it in a real life application or you need to work out why something isn't working as expected you are left without the knowledge to solve these issues. </p>
<br />
<p>I do realise that this book is for beginners and is meant to get developers to look into and start writing multi-threaded apps and not be a complete resource, but personally I would prefer a touch more theory. In particular locking is over looked, what setting a WinForms app to [MTAThread] really means (you can't use dialogues for example). This was probably left out to try and keep things simple for beginners but not discussing locking or exceptions could mean bad practices are picked up and carried into production code.</p>
<br />
<p>It is worth mentioning that his book solely focuses on WinForm apps, it doesn't look into WPF or WebForms, and this is both a blessing and a curse in my eyes. With that said WinForms is simple to learn and the examples really do cover everything you need to get them working so if you have never used WinForms don't be put off reading this book, by the end of it you will not only know more about multi-threading but also how to write simple WinForm apps. <br /> Also the book says that you can use Visual Studio 2008 Standard edition to debug multi threaded apps, I found out that sadly this isn't the case. In order to have the threads debug window you need the Pro edition or above version of Visual Studio.</p>
<br />
<p>
Overall I find the book alright, personally the presentation of the book, colour schemes, internal typography could do with an improvement, the headings look like they are in Impact which is wrong on so many levels, and the examples can seem slightly farfetched but the book does cover a lot. As someone new to multi-threading by the end of it I felt confident enough in what I had learnt to write a simple multi threaded WinForm app for work to perform some tests. </p>
<br />
<h3>Scores</h3>
<p>
<span style="font-weight:bold;">Presentation</span> - 6 / 10 - Although it’s clear to read the bulk of the content, the cover and headings for me let it down. <br />
<span style="font-weight:bold;">Code Examples</span> – 7/10 – The code examples are clearly written and cover all the detail you need I feel that they aren’t as real life as they could be which hinders taking what they are meant to show you and apply it to real life scenarios. <br />
<span style="font-weight:bold;">Quality of Content</span> – 7/10 – Overall I felt the quality content was quite good, potentially a bit over the top in places about being a “multi threaded guru” but overall OK. One down fall was to say that Visual Studio Standard edition can be used to debug multi threaded apps when it can’t. <br />
<span style="font-weight:bold;">Overall</span> - 6.5 / 10
In light of everything I'm not going to suggest this is a book that everyone should read / own unlike over books like the pragmatic programmer etc. However if you are looking at learning about multi-threading and want something to ease you into it then this is for you, it will cover the basics of everything you need to know and what to expect in the future.
</p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-4411462165568124196?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com0tag:blogger.com,1999:blog-2153751547788086073.post-51034243503743492062009-03-19T23:35:00.004Z2009-03-19T23:50:12.028ZMVC Snippets: must be a reference type in order to use it as parameter 'TModel' in the generic type or method 'System.Web.Mvc.ViewUserControl'<p>Recently I have been playing with <a href="http://asp.net/mvc">ASP.NET MVC</a>, in particular I have been building myself a new website. I thought it might be good to post any peculiar things / lessons I learn during this build. Tonight I stumbled across one of these lessons. </p>
<br />
<p>
When you strongly type a view or partial view the type must be a reference type. Otherwise this means you get a HttpCompilation Error: "your data type" must be a reference type in order to use it as parameter 'TModel' in the generic type or method 'System.Web.Mvc.ViewUserControl<TModel>'. Initially I couldn't figure out what this meant as I was passing my type through, it existed etc. However it was then I realised I had declared my type as a struct not a class.
</p>
<br />
<p>
If you are unsure of the difference between a class and a struct I recommend looking it up, the gist of it is that a class is a reference type and a struct isn't. As a struct isn't a reference type you can save memory due to it not having to allocate additional memory for referencing each object, this is great for short structures, but not for models in ASP.Net MVC
</p>
<p>After changing my type to a class all was sorted and my view could compile again. A lesson learned, one of many I am sure ;) </p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-5103424350374349206?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com0tag:blogger.com,1999:blog-2153751547788086073.post-11700868492659259312009-03-18T19:38:00.003Z2009-03-18T19:48:18.596ZOpen Hack Day 2009<p>Well today registration for <a href="http://www.wait-till-i.com/2009/03/18/open-hack-day-london-9th-and-10th-of-may-signup-now-open/">Yahoo! Open Hack Day 2009</a> opened, and with much excitement I signed up hoping for a place. </p>
<br />
<p>The previous Hack Day was really great fun even though my "hack team" failed to finish our project. This year I'm hoping to do something a lot simpler but as enjoyable.</p>
<br />
<p>Here's open I get a place ;)</p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-1170086849265925931?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com0tag:blogger.com,1999:blog-2153751547788086073.post-29872632241229322362009-02-15T19:51:00.004Z2009-02-17T23:54:10.908ZParsing an XML Boolean<p>Today I came across a situation where I was taking a value from an XML file which is a boolean. Now being me I knew that someone would either use 1 or true to indicate this boolean value, I for example always use 1 and 0 but I know people that prefer the "proper" way of saying true or false, especially if you don't have an XSD handy.</p>
<br />
<p>The XML itself is fine however once I had loaded this XML file into my .Net application I needed to parse the value as a boolean. This is where I hit a roadblock. Bool.Parse will only parse "true" or "false" string values not "1" or "0". </p>
<br />
<p>A quick explore through various sources led me to find <a href="http://msdn.microsoft.com/en-us/library/system.xml.xmlconvert.aspx">XmlConvert</a>.ToBoolean(), which is part of System.XML. XmlConvert allows you to convert from XML Data Types to .Net Data Types and in the case of Boolean can convert 1 to true.</p>
<br />
<p>This saved me loads of time so I thought I'd post it up here for others to find and hopefully enjoy.</p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-2987263224122932236?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com0tag:blogger.com,1999:blog-2153751547788086073.post-8405402082378443352009-01-24T11:33:00.009Z2009-01-27T13:28:35.320ZWhere's all my battery gone? / Windows 7 Hardware Interupts<p>So I got the Windows 7 Beta as soon as it came out and installed it on my laptop to give it proper "real world" testing, not a VM or a machine I use rarely. I chose to do this as it means I can give Microsoft proper feedback and if it all goes wrong I can simply reinstall Vista clean and restore data from the previous night</p>
<br />
<p>I have to say I really like windows 7, the UI changes do work for me, I like some of the new features and on the whole I'm happy with it. But this post isn't going to be about my last two weeks of running Windows 7, I'm already writing that post and need to finish it when I'm happy I've gave a real world usage. This post is about how since I've installed Windows 7 my battery life sucks.</p>
<br />
<p>Now this isn't a rant, instead I want to highlight how I found out that something was wrong with my install.</p>
<br />
<p>So when I started using Windows 7 I noticed that my system kept slowing down, I soon fired up Task Manager and found that AVG antivirus, I use the free edition for Home Users, was eating a large chunk of my CPU, it seems it was always running around 30% if not more. I checked the Windows 7 Blog and found they had a list of compatible anti virus solutions, AVG was one however it didnt indicate if the free version was so I decided to remove AVG and try the Kapersky beta instead. </p>
<br />
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_S05-HU5Oqxw/SXr_tL5ce-I/AAAAAAAAAus/OkiwmqOzN6I/s1600-h/taskmanager-core0.png"><img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 287px; height: 320px;" src="http://1.bp.blogspot.com/_S05-HU5Oqxw/SXr_tL5ce-I/AAAAAAAAAus/OkiwmqOzN6I/s320/taskmanager-core0.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5294825463680367586" /></a>
<p>After doing this the system did feel more responsive so I was happy with this and thought this was then end of it. However this week, in particular the last 3 days I noticed that my battery was running out in 60 mins or less, normally I get at least 1.5 hours, 2 if in "power saver" mode. Initially I pondered if the power profiles were running properly, I checked these and all seemed fine, "balanced" mode whilst running on battery would set the minimum cpu usage to 5%, all seemed well.</p>
<br />
<p>This morning I decided to look into this battery issue further, I started Task Manager and nothing seemed to be using the CPU but when I looked at the performance task I saw something very peculiar, see the image to the right, Core 0 was running at all times at 90%! This must be the cause of the battery being depleted so quickly, if the core is always active the power saving features can't kick in, thus burning good old power cells.</p>
<br style="clear: both;" />
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_S05-HU5Oqxw/SXsClvU4D9I/AAAAAAAAAu0/x5sBsdc1frs/s1600-h/processMonitor.png"><img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 320px; height: 266px;" src="http://4.bp.blogspot.com/_S05-HU5Oqxw/SXsClvU4D9I/AAAAAAAAAu0/x5sBsdc1frs/s320/processMonitor.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5294828634286591954" /></a>
<p>Unfortunately task manager wasn't showing what was using the CPU, not even showing processes from all users helped. So I went and got the only application you need to investigate memory leaks or CPU usage, <a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx" rel="external">process explorer</a>. Upon firing this up I saw straight away the culprit, Interupts which is part of the System Idle Process and handles all Hardware Interupts was constantly eating ~40% CPU!</p>
<br />
<p>Now here's the problem, this is a system process, which has no threads, it's core, there's no easy way (that I'm aware of), to find what is causing the Interupts to constantly burn CPU, I looked at shutting everything down that could be causing the issue, my thoughts were the animated Synaptics TrackPad icon, as this responds to your input, the On Screen Display program that indicates when you turn Caps Lock on/off etc, but still nothing changed.</p>
<br />
<p> This sadly looks like a Windows 7 issue and one that may force me to reinstall my laptop back to Vista, has anyone else found had this issue or know what causes it? If so leave a comment, in the mean time I'm going to report the issue to the Windows 7 guys and I'll update this post if I hear anything back.</p>
<br/>
<h2>Update: </h2>
<p>Well it looks like this is now solved, Intel have released a new Chipset Driver :
Intel Corporation driver update for Mobile Intel(R) 965 Express Chipset Family (Prerelease WDDM 1.1 Driver), this is an optional update for Windows 7, hence how I managed to miss it the first time I checked, so there it is if you find Hardware Interupts are cooking your CPU check for an updated Chipset driver, helped me out anyway. </p>
<h2>Further Update - 27/01/2009</h2>
<p>Much to my dismay this issue is still present, the driver update seemed to make things better however if my laptop goes to sleep and then I resume the issue reoccurs, hopefully Intel may release an updated driver to fix this issue....</p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-840540208237844335?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com0tag:blogger.com,1999:blog-2153751547788086073.post-64614306910290116832009-01-21T13:46:00.003Z2009-01-21T13:58:34.942ZVisual Studio Welcome Screen<p>Today a colleague noticed that whilst he was debugging his web application random requests were being made to Microsoft, these requests were also returning a HTTP/1.1 301 Moved Permanently header, and apart from being annoying was causing him a few issues.</p>
<br />
<p>From experience I soon realised that these requests were being made by the Visual Studio Welcome Screen. By default even if you don't use the welcome screen, Visual Studio keeps the Start Page News Channel RSS Feed up to date, the default in every 60 minutes. If you aren't using the welcome screen then its probably worth disabling the RSS feeds auto download content functionality, not only will this stop you seeing random requests, if you even notice them, but if you are working on a mobile and pay per KB save you some bandwidth.</p>
<br />
<p>To disable the auto content update simply: goto Tools > Options, click the Show All Settings checkbox, then under the Environment leaf find Startup. Once here simply untick the "download content every" check box. You can also configure it to update less frequently, alter the news channel location, for example you may prefer to use the <a href="http://dotnetshoutout.com/" rel="external">DotNetShoutOut</a> <a href="http://feeds.feedburner.com/Dotnetshoutout-Published" rel="external" title="DotNetShoutOut RSS Feed">RSS Feed</a>.</p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-6461430691029011683?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com0tag:blogger.com,1999:blog-2153751547788086073.post-27075228799695006292009-01-19T14:07:00.004Z2009-01-19T14:20:07.966ZSyntax Highlighting and Intellisense for WSC Files in Visual Studio 2008<p>Recently I've been working on a system that makes use of custom WSC components. These components contain the usual XML Wrappings and then a large CDATA area containing the VBScript code. </p>
<br />
<p>What's really been bugging me is that Visual Studio was treating all the code within the CData XML Area as XML and I really want the VBScript to be all nice and highlighted and for VBScript intellisense to kick in, it really does save time. Now luckily making this happen was remarkably easy.</p>
<br />
<p>First within Visual Studio go to tools and options, click Show All Settings. Then open the Text Editor leaf and click on File Extension. Next add a new option for wsc files and specify that you wish it to use the Web Form Editor as it's editor. Click Add and then OK. You should now find when you next open a wsc file the XML has syntax highlighting as well as the VBScript, and intellisense works! </p>
<br />
<p>I hope this helps you, it certainly did me!</p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-2707522879969500629?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com0tag:blogger.com,1999:blog-2153751547788086073.post-86690238480914738632008-11-22T11:00:00.003Z2008-11-22T11:21:24.844ZWindows Vista + Loosing the Ability to Hibernate<p>I'm one of the few people I know that use the Hibernate feature on my laptop. I find its helpful when shutting down for the evening but want to resume exactly where I left off the next day. Sleep even S3 doesn't work for me as I often find my battery depletes as on this laptop it is shockingly poor.</p>
<br />
<p>The other day I was performing some basic maintainence and decided to run disk cleanup to see if it was any better than XP's counterpart, it ran well and asked me would I like to remove my hibernate file. This is where my troubles began, I expected the file to be recreated upon my next hibernate, however what did happen was hibernate ceased to exist on my start menu.</p>
<br />
<p>After much hunting through the Control Panel I was unable to find a definitive option to renable the hibernate file, power options was all setup to hibernate however I was still unable to hibernate. I then found a simple command line setting you need to run to renable it, or even turn it off if that is your desire.</p>
<br />
<p>First open a command prompt window in administrative mode, its annoying when you forget to do this, then simply run the following: powercfg -H ON. The -H switch indicates hibernate and then its a simple on off. And that's it Hibernate restored and my laptop is back to it's normal self, good stuff.</p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-8669023848091473863?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com0tag:blogger.com,1999:blog-2153751547788086073.post-17893966245783673602008-11-18T20:10:00.007Z2008-11-18T21:02:51.095ZSite Maintainance and IP Restriction<p>There are times during many site's life that you must perform some maintainence on the database / code, and allowing people to have access to the site whilst doing this must be restricted. Often most updates / upgrades can occur on the fly without any down time but there are occasions when you need to do this. </p>
<br />
<p>Usually I logon to my web server and IP Restrict the site to my IP Address and let IIS provide a default message to users that try to access the site during this period. Now although this works I often find it cumbersom, I have to have access to the web server, I need to find out my IP address, as I don't have a static one at home, and the entire process can be quite long. It's even worse if its for a site that I don't host and can't IP Restrict through IIS.</p>
<h2>Another Way</h2>
<p>Tonight I decided to explore a better way of doing this, and as such I've came up with a simple HTTPModule that you can stick into your ASP.Net Web Application which will handle IP Restrictions for you.</p>
<br />
<p>In order to maximise the use / potential of this module I've enabled it to do two things, first to allow conigurable IP Restrictions but secondly to specify whether the restriction is for a temporary basis, I.E the sites under maintainence, or whether this is a perminant block.</p>
<h2>The Code</h2>
<p>The code for this module is actually pretty simple. First of I created a class called IPRestrict and implemented the basic IHttpModule interface</p>
<pre><code class="c#">
namespace mjjames.HttpModules
{
public class IPRestrict : IHttpModule
{
public void Init(HttpApplication context)
{
}
public void Dispose()
{
}
}
}
</code></pre>
<p>With the basic interface I added a event handler to the init method that on BeginRequest, when a request starts to be processed, call Application_BeginRequest. Application_BeginRequest takes the user's IP Address from the Request object and passes this to ValidIP. ValidIP by default returns that the IP is valid, the site isn't using IP Restriction, however if the site's web.config has an app setting called "IPRestrict" then the provided ip address is searched for in the app setting.</p>
<pre><code class="c#">
private bool ValidIP(string ipaddress)
{
bool bValidIP = true;
if(!String.IsNullOrEmpty(ConfigurationManager.AppSettings["IPRestrict"])){
bValidIP = ConfigurationManager.AppSettings["IPRestrict"].Contains(ipaddress);
}
return bValidIP;
}
</code></pre>
<p>The reason i decided to perform a contains function on the app setting for the ip address was so that I could ignore the IP Address delimiter within the app setting. This way whether you seperate valid IPs with a comma, a space, a comma space etc it doesn't matter, as long as the IP is within the app setting it is returned as valid</p>
<br />
<p>As far as the IP Check goes that's it, however in order to make the module more usable and user friendly Application_Request can use an additional two app settings from the Web.Config. "MaintainenceMode" is boolean setting which indicates the IP Restriction is in use due to maintainence, if the setting is not provided then the module assumes this is not the case by default. Maintainence Mode changes the HTTP Response Status Code for the request, by default IP Restriction means the end user recieves a 403 status code, forbidden, however whilst in Maintainence Mode a 503 status code is delivered to indicate the service / site is temporarily unavailable.</p>
<br />
<p>The second app setting used in Application_Request is "CustomIPRestrictMessage". This setting as the name implies is used to provide a custom IP restriction message to the user instead of te default.</p>
<br />
<p>The module is really simple to use, simply add the <a href="http://development.mjjames.co.uk/scripts/aspnet/downloads/mjjames.httpmodules.zip" title="Download IPRestrict HTTP Module">mjjames.HttpModules dll</a> to your project as a reference and update your web.config to include the app settings. Along with the app setting the HttpModule needs adding to the HTTPModules section of the web.config, find an example of how to do this below</p>
<pre><code class="xml">
<add name="IPRestrict" type="mjjames.HttpModules.IPRestrict, mjjames.HttpModules"/>
</code></pre>
<p>That's it hopefully you'll find the module easy to use. Currently it doesn't do IP Ranges as I didnt require this, I may look at adding this in the future.</p>
<br />
<p>Now whilst testing this I thought about how I could provide more than a custom message upon recieving the IP Restriction response, maybe a branded page dependant on the site it's used in. This is actually very easy and all you need to do is create a custom html page branded appropiately within your site and then change the CustomErrors section of your web.config.</p>
<br />
<p>Within here simply add a new error node, give it either the 503 or 403 status code dependant on whether you are using maintainence mode or not, and provide the html file to redirect to.</p>
<pre><code class="xml">
<error statusCode="503" redirect="MaintainenceMode.htm"/>
</code></pre>
<p>This makes the module for me at least very useful. If you want to give the module a go why not <a href="http://development.mjjames.co.uk/scripts/aspnet/downloads/mjjames.httpmodules.zip" title="Download IPRestrict HTTP Module"> download the dll</a> and let me know how you get on. If there's interest I'll also look at bundling a version with the full source. </p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-1789396624578367360?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com0tag:blogger.com,1999:blog-2153751547788086073.post-26026056193719364822008-09-22T20:16:00.006Z2008-11-20T09:35:45.160ZRename a Computer Using WMI Scripting<p>This Wednesday I'm doing an MVC Hack Night at my work with <a href="http://derek-says.blogspot.com/">Derek Fowler</a>. This evening will hopefully give us a chance to show other employees what <a href="http://www.asp.net/mvc/">ASP.NET MVC</a> is and to give them some simple tutorials to work on.</p>
<br />
<p>As ASP.NET MVC is only preview 5 we didn't want to install the extensions onto the work machines, so we decided to create a time based XP Virtual Machine that everyone could copy and use for the evening. Not only did this mean we could install the extensions without fear of breaking our development machines but it also meant we could ensure that Sql Express and Visual Studio Express was setup and working with the tutorial code properly.</p>
<br />
<p>There was one giltch with the plan and that was that the Virtual Machines would all be using the same Computer Name, this would result in the computers not logging onto the network and all sort of errors could occur.</p>
<br />
<p>My solution to this was to write a dead simple WMI Script in VB that would run at logon, this script would check to see if the Computer Name was the default, in this case MVC, and if it was to rename it to MVC-{Random Number}. It would then reboot the computer and then find the name changed and hopefully find it can logon to the network fine.</p>
<br />
<p>The source code is below, I've chosen to generate a number between 1 & 1000. This should hopefully not generate any machines with the same name, as there's only 10 of us. <br /> The script really is quite simple, I first get the Computer WMI object and check it's name to see if it equals MVC, if it isn't I change it, echo out its been changed and then use the WMI Script object to run Shutdown.exe /r (reboot the computer). Now I could use the Operating System WMI Object to issue a shutdown but I didnt think of this until after I had wrote the script.</p>
<br />
<pre><code class="vb">
lowerbound = 0 ' lowest value
upperbound = 1000 ' highest value
Randomize
randomvalue = CInt(Int((upperbound - lowerbound + 1) * Rnd() + lowerbound)) 'generate random number
Name = "MVC-" & randomvalue ' our new computer name
Password = "abc123" 'my admin password
Username = "admin" 'my admin username
Set objWMIService = GetObject("Winmgmts:root\cimv2")
' Call always gets only one Win32_ComputerSystem object.
For Each objComputer in _
objWMIService.InstancesOf("Win32_ComputerSystem")
If objComputer.Name = "MVC" Then ' check to see if comp is using default name
Return = objComputer.rename(Name,Password,Username) ' rename comp
If Return <> 0 Then 'check for error
WScript.Echo "Rename failed. Error = " & Err.Number
Else
WScript.Echo "Rename succeeded." & _
" Rebooting for new name to go into effect"
set objWSHShell = WScript.CreateObject("WScript.Shell")
objWSHShell.Run "shutdown.exe /r" ' reboot comp for changes to take effect
End If
Else
WScript.Echo "Rename Not Needed"
End If
Next
</code></pre>
<p>If you want to use this script / adapt it for your needs feel free, it certainly made my life easier!</p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-2602605619371936482?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com1tag:blogger.com,1999:blog-2153751547788086073.post-19353333221145290122008-09-16T07:59:00.005Z2008-09-16T08:22:38.009ZWelcome to Google Developer Day 2008<p>OK, I'm here, I have my shiny Google pass and a coffee I'm ready ;) </p>
<br />
<p>It all looks preety good so far, we strangly have a small wrapped up box which is for a session later.. I want to open it now but much like Christmas I'm thinking it may spoil it, apart from that upon arrival we are being showered in free coffee and pastries, if only I could eat the pastries I wouldn't be hungry, very good none the least.</p>
<br />
<p>Wembley Stadium is gorgeuos, it may have been over time and budget but it is beautiful, a nice venue to hold such an event in. I'll try to put some pictures online of the stadium later. </p>
<br />
<p>I have taken a few quick shots so far and will upload them to Flickr shortly, sadly I forgot my SLR and then Chris Alcock's small camera so alas it's LG "Viewty" quality only, I'll post later with more thoughts and ramblings about the day, given last night's performance though I'm thinking I need to scout out power sources soon! </p>
<p><strong>Update</strong><br /> Google's WiFi has fallen over already and there's only 50 people here, I've switched to my 3G connection, it may be more reliable, although it will suck my battery quicker! Doh!</p>
<h3>Pictures so Far</h3>
<iframe src="http://www.flickr.com/photos/mjjames/sets/72157607317784426/show/" width="600" height="450"></iframe><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-1935333322114529012?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com2tag:blogger.com,1999:blog-2153751547788086073.post-25154924739916046532008-09-14T18:39:00.005Z2008-09-14T18:54:57.652ZGoogle Developer Day 2008 London<p>Tuesday is the <a href="http://code.google.com/intl/en_uk/events/developerday/2008/home.html">UK's Google Developer Day</a>, this year its taking place at <a href="http://www.wembleystadium.com/default.aspx">Wembley Stadium</a> and I'm lucky enough to be attending</p>
<br />
<p>I have to say I'm quite looking forward to it, a chance to get see Google Speakers and to catch up with other developers that utilise the Google API's will be awesome. </p>
<br />
<p>So far I have used the Google Calendar API and started to write a .Net wrapper for the YouTube API, so learning about others will be good. The sessions I have pencilled in to attend so far are: State of AJAX: Dion Almaer, YouTube API: Build YOUR YouTube: Jean Laurent Wotton, Mashing up Google Data APIs: Ryan Boyd and probably but not fully sure V8 - the Chrome engine Kevin Millikin. </p>
<p>As you can see it's going to be a jam packed day, but the sessions look top and I look forward to sharing and learning.</p>
<br />
<p>Due to travelling I'm heading down Monday night, and coming back on Tuesday Evening. If you are in London on Monday night, and fancy catching a pre dev day pint or even food, drop me a DM on twitter (mjjames)</p>
<br />
<p>After the day I plan on doing a summary writeup on here and hopefully sharing some cool info</p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-2515492473991604653?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com0tag:blogger.com,1999:blog-2153751547788086073.post-30267399017038103302008-09-02T21:01:00.005Z2008-09-02T22:00:50.313ZGoing Chrome<p>So today Google Launched <a href="http://google.com/chrome">Google Chrome</a>, and like any good geek I got on it straight away.</p>
<br />
<p> Installation was quick and painless, and it fired up blistering quick. It was then the magic started. Now I won't focus on how nice the interface is to use, the new home page, etc I want to concentrate on the features I have used tonight whilst using it and whilst coding.</p>
<br />
<h2>HTML & CSS Features</h2>
<p>The first thing I did whilst playing was to view some page source, this as you would expect is on the context menu, nothing overly special here, however I did like the nice syntax highlighting, +1 to Google. However it doens't do any sort of nice reformat document, this would have been a really nice feature but we can't have it all. </p>
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_S05-HU5Oqxw/SL2ry3IQyaI/AAAAAAAAAgk/zIGg4WHTDsA/s1600-h/chrome_source.jpg"><img style="cursor:pointer; cursor:hand;" src="http://3.bp.blogspot.com/_S05-HU5Oqxw/SL2ry3IQyaI/AAAAAAAAAgk/zIGg4WHTDsA/s320/chrome_source.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5241534431609538978" /></a>
<p>Whilst looking for View Source I discovered that Chrome has a DOM Inspector built in, I got to it by "inspecting an element". This is far more than the DOM Inspector that you can get for FireFox, it gives you a nice DOM view, style information (computed, inherited, etc), Metrics, which shows the Box Model being applied to the element, and finally a properties tab giving you anything being applied to an element. </p>
<br />
<p>
Next there's a funky search box, this allows you to search the DOM for anything, how many times have you needed to find the image with a class and you aren't sure where it renders? Now you could use inspect element, but if you are already in the inspector simply type "img" into the search box to find it lists all of the image tags within the document, now if it was really ace you could type image + class="photo" but this is not the case yet... </p>
<br />
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_S05-HU5Oqxw/SL21YoRDK6I/AAAAAAAAAgs/fKNjAbIvImo/s1600-h/chrome_inspector.jpg"><img style="cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_S05-HU5Oqxw/SL21YoRDK6I/AAAAAAAAAgs/fKNjAbIvImo/s320/chrome_inspector.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5241544976059542434" /></a>
<h2>Resources and Debugging</h2>
<p>
All of that was only under the Elements section, there's another section... Resources
This is similar to the net view tab in FireBug, it shows all of the "resources" requested by the page and shows them on a nice graph, showing how long they took to load and where in the process or you can compare the file sizes. <br /> By clicking on the file the graph turns into a preview of the file, be it the image, JavaScript file etc.
</p>
<br />
<p>
I was slightly disapointed when I opened a JavaScript file to preview, I was expecting to be able to set breakpoints and watch's but alas no :( However there is a JavaScript Console, this is located at the bottom of the screen, the 2nd button from the left, this pops up the console. </p>
<br />
<p>Now this is really good, it has intelisense ;) So if you start typing document.getElementByID for example all you need to do is: do [tab].get[tab] and choose by ID. If you cant remember the name, for example getElementsByName you can just keep pressing [tab] <br /><br /> Now at the moment it only seems to do DOM but I'm hoping it may eventually pick up references and then you can do funky jQuery or something within the console...
</p>
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_S05-HU5Oqxw/SL21ZBfAu3I/AAAAAAAAAg0/hGCAlD_QKSE/s1600-h/chrome_resources.jpg"><img style="cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_S05-HU5Oqxw/SL21ZBfAu3I/AAAAAAAAAg0/hGCAlD_QKSE/s320/chrome_resources.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5241544982828989298" /></a>
<br />
<p>
Now there is soo much more I could talk about, however the final feature I used tonight was the JavaScript debugger, this is under Developer > Debug Javascript or you can use the keyboard shortcut.
</p>
<p>
Now I expected more than this, but maybe It does do more than I currently know, if you type help within the console you can see what you can do. You can attach breakpoints using the console, print variables, see what scripts are loaded, etc.
</p>
<br />
<p>
When attached to a tab the debugger will catch any errors and you can print out any variables that you need to inspect before typing continue to continue.
<br /> <br />
For me I still prefer firebug for JS debugging but I'm sure this will evolve further over time.
</p>
<br />
<p>So that's it for tonight, I am loving Chrome, it's fast, it's slick but... there are still some bugs and glitches to iron out. For example I have seen quite a few pages where font-size is being inherited wrong within li's, so if I had 90% font size by the 5th li the text was unreadable :( There have been some other weird text issues but nothing that major. <br /> I'm not going to make Chrome my default browser yet... but I'm not far off ;)
</p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-3026739901703810330?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com2tag:blogger.com,1999:blog-2153751547788086073.post-87888150102416789492008-07-25T15:49:00.003Z2008-07-25T15:57:26.318ZLinqDataSource and Could not find a row that matches the given keys in the original values stored in ViewState.<p> Today I was working on something quickly where I used a LinqDataSource, to keep things simple I attached a simple list view to it and had insert, update and delete operations.</p>
<br />
<p>Insert operations seemed to work OK however when I came to do an update to an existing item it crashed out</p>
<pre>
Could not find a row that matches the given keys in the original values stored in ViewState.
</pre>
<p>Initially I thought that maybe some databinding had gone astray but this wasn't the issue. As I hadn't used design view but source view to create the ListView had missed off the DataKeyNames attribute, this meant that upon update the LinqDataSource was trying to match all my values against the database, of course it couldnt do this. By specifying the DataKeyName to match against, usually your Primary Key if using LinqtoSql, not only do you limit how much matching and work your LinqDataSource has to do, but also you'll find you can update :D</p>
<br />
<p>So quick tip, if you get "Could not find a row that matches the given keys in the original values stored in ViewState." double check your ListView, FormView, GridView etc has the DataKeyNames set. </p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-8788815010241678949?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com2tag:blogger.com,1999:blog-2153751547788086073.post-79663816685675244452008-07-21T08:52:00.003Z2008-07-21T09:10:40.050ZSystem.Web.Query.Dynamic.ParseException: Digit expected<p>Today I wrote a quick piece of code using Linq to Sql that would pull out some records from a table given a provided where clause <br /> To make my life easy, I used a LinqDataSource within a web form and then databound a form view to it, this was only a quick prototype of an idea so I felt these were appropriate.</p>
<br />
<p>The where clause for my LinqDataSource was being assigned programatically and consisted of a GUID value from a user object I had knocked together. Upon compiling and running the code though I got an odd error: System.Web.Query.Dynamic.ParseException: Digit expected</p>
<br />
<p>First thing to check was that the value I was giving the where clause was actually an GUID value, debugging showed this fine, I next looked at putting a hard coded GUID where clause in to see if it was some weirdness caused by my user object, but this wasn't the case. I finally googled the error message, and found 1 meesly result which pointed to the MSDN forums.</p>
<br />
<p> Here someone posted that you can convert to various types and to try explicitly converting to a GUID value</p>
<pre><code class="c#">
lds.Where = string.Format("user_id == Guid({0})", user_id);
</code></pre>
<br />
<p>This worked fine, and it made sense too, as when you declare where parameters on the linqdatasource control you normally define its type, as I wasn't doing this nor programtically it was type casting by itself.</p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-7966381668567524445?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com0tag:blogger.com,1999:blog-2153751547788086073.post-14752719094309777662008-07-14T09:44:00.005Z2009-06-30T22:51:23.040ZBuild failed due to validation errors in. dbml<p>OK so I got in today to find that I was unable to build my current project, I got the following </p>
<span style="font-family: courier new;">Error 1 Build failed due to validation errors in C:\xxx\DB.dbml. Open the file and resolve the issues in the Error List, then try rebuilding the project. C:\xxx\DB.dbml 2</span>
<p>I opened the projects dbml files to find that these files were fine, no errors or typos, the project was just dead. a little bit of Googling lead me to find that its a problem with Visual Studio 2008 not loading an assembly correctly, in particular the one with a GUID of 8D8529D3-625D-4496-8354-3DAD630ECC1B</p>
<p>In order to load the assembly correctly you need to get Visual Studio to reset it's packages, to do this: </p>
<ol>
<li> Open a new command prompt</li>
<li>Navigate to C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE</li>
<li> Run Visual Sudio with the /resetskippkgs argument: devenv /resetskippkgs</li>
</ol>
<p> You should now find that your project opens and builds correctly! I'm hoping that maybe <strike>SP1 of Visual Studio will correct this</strike>, if not SP2 maybe...</p>
<p>Update: SP1 Didn't fix this :( Also worth noting if you are running a 64 bit OS then the visual studio folder path is C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE </p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-1475271909430977766?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com6tag:blogger.com,1999:blog-2153751547788086073.post-3851468195651196562008-06-26T22:41:00.004Z2008-06-26T22:59:25.105ZLoosing the Address Bar<p>Microsoft Windows has had the "address bar" for a long time. Although not used by many adding it to your taskbar for some has provided an amazing way of quickly getting to files, folders and web addresses.</p>
<br />
<p>I have used it for a while and have it in the bottom row of my task bar, I have this setup at home on my machine, work and until recently Hayleys Laptop.</p>
<br />
<p>SP3 came out recently and I immediately updated Hayleys laptop to it, all seemed fine, however today I logged into as me, and noticed the address bar had "vanished". First of all I thought I has just knocked it off but no it had physically disapeared from the toolbar list.</p>
<br />
<p>A quick Google later left me speachless.... </p>
<br />
<quote>"After installing Windows XP Service Pack 3, the Address Bar feature will be removed from the Taskbar. The Address Bar feature will not be present in Windows XP Service Pack 3. This change is in response to a regulatory request and is present beginning with Windows XP Service Pack 3 Beta."</quote>
<br /><br />
<p>It has been removed! The reason behind this is that the Addres Bar is actually part of IE, and Microsoft are trying to make IE less dominant within Windows due to antitrust. I personally think this is a joke, if the address bar opens links up in your preffered browser, in my case Firefox, does it matter that it's an IE component that fires up FireFox??</p>
<br />
<p>After further browsing I have found an Addon some one has wrote <a href="http://www.muvenum.com/products/freeware/">MuvEnum Address Bar </a> to help with the issue but as of yet I havn't tried it due to now wanting to put something else on Hayleys Laptop. </p>
<br />
<p>To remove such an established feature is a real low blow, and I'm sure there must be a better solution, even if it involved more work.... So I was left without my address bar on Hayleys Laptop and hoping that work doesn't upgrade to SP3 anytime soon. Interestingly SP1 Vista still has the address bar so I wonder if SP2 will remove it.</p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-385146819565119656?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com3tag:blogger.com,1999:blog-2153751547788086073.post-6753441547305299412008-06-24T21:16:00.008Z2008-06-24T22:20:29.952ZUsing Yahoo! Media Player on a dynamic page<p>Recently I added paging to my churches podcast page, the steps on how I did this are part of another post that I aim to finish at some point, however I thought I'd quickly blog tonight some tips on using the Yahoo! Media Player on a dynamic page.</p>
<br />
<p>Originally the podcast paging was causing a full postback which reloaded everything on the page, this felt dirty so tonight I reconfigured my podcast control to make use of the ASP.Net Ajax UpdatePanel. The paging worked great however the WMP wasn't updating which left the playlist out of date and the new podcasts without play buttons.</p>
<br />
<p>The issue was that by default the YMP JS fires on load and the ajax update wouldn't trigger this. Moving the script to load as part of the ajax updated content also wouldn't help this, all I would be doing would be reloading the source, not actually solving the problem.</p>
<br />
<p>I turned to the <a href="http://yahoomediaplayer.wikia.com/">YMP wiki</a> however I didn't really turn anything up that was of great use.</p>
<br />
<p>I knew that the YMP scraped the page on load for MP3 files and then built up its playlist, so it was a case of finding this scrape function, clearing the current playlist and then triggering the scrape.</p>
<br />
<p>Firebug came to my rescue, I add a watch to the YMP object YAHOO.music.WebPlayer and found that it had quite a few functions available if you know they are there, I have listed a few useful ones below:
<ul>
<li>asyncLoadPlayer() - if the player is loaded after the window has loaded this will manually load the whole player
</li>
<li>clear() - clears the playlist
</li>
<li>pause() - pauses the item playing in the media player
</li>
<li>play() - plays the current item in the playlist
</li>
<li>scrape() - scrapes the page for mp3's and adds them to the playlist
</li>
<li>shutdown() - shutsdown the media player and releases all resources
</li>
<li>startup() - starts the player up, not sure if this is useful as asyncLoadPlayer()is probably better
</li>
<li>stop() - stops the item playing in the media player</li></ul></p>
<br />
<p>So for my case with a dynamically loading page I added some simple JavaScript to the content that is loaded in, this JavaScript first ensures YMP has already been loaded and then clears the playlist and scrapes the page for new media items for adding to the playlist.</p>
<pre><code class="javascript">
function PageLoadedEventHandler() {
if(YAHOO.music.WebPlayer.loaded){
YAHOO.music.WebPlayer.clear();
YAHOO.music.WebPlayer.scrape();
}
}
</code></pre>
<br />
<p>I did ponder about leaving out the clear, that way as you page through the podcasts the playlist simply grows so you can listen to any of them, I decided against this but I hope you can see what you can do.</p>
<br />
<p>So there wasn't much to it, I am hoping Yahoo! will properly document the functions available within the YMP as I would have saved alot of time faffing with FireBug and the watch window. I hope this helps someone, I'm now thinking on how I could use my own player interface and utilise YMP to power it... any way thats something for a rainy day</p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-675344154730529941?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com4tag:blogger.com,1999:blog-2153751547788086073.post-70901566262802707912008-05-30T10:16:00.005Z2008-06-24T22:26:33.107ZLinq + Failed to set one or more properties on type<p>So I have had quite an interesting hour or so tracking down the following Linq error:<p>
<br />
<p><span style="font-family: courier new;">Failed to set one or more properties on type [namespace].EntityContexts.project. Ensure that the input values are valid and can be converted to the corresponding property types.</span></p>
<br />
<p>This was occurring whilst performing an update in a formview. Previously the form had been behaving properly, but this morning I added a new field to the database and updated the LinqtoSQL file. I also added a new databound field to my formview, however since this every time i tried to update the form it crashed out.</p>
<br />
<p><a href="http://forums.asp.net/p/1255515/2332474.aspx">A few people have suggested</a> to delete your LinqtoSQL file and readd, this didn't work for me, I even created a new page with just the datasource and formview for testing purposes.</p>
<br />
<p>The datasource was configured to select all from a table and had auto insert, update delete set. The formview was just generated. </p>
<br />
<p>It was at this point that I noticed the foreign key relationships I had setup were child entities in my entitycontext. This meant that my formview was generating databound controls for my lookup table etc. In my original page these didn't exist as I had manually removed them in sourceview. <br />So I again removed these controls within my new page and tried again, still no joy, I then wondered if removing them in Design view instead of Source had any impact, and it did. What was happening was my designer code file was not being updated upon rebuilding from the pages source view.</p>
<br />
<p>I then thought further on how to avoid this, my initial thoughts were upon inserting a LinqDataSource only select the columns you need, thus skipping the child entities, this would work for read only select data sources however to use auto generate insert and update you can't use select. If you try to do this then you get the following error:</p>
<br />
<p><span style="font-family: courier new;">LinqDataSource 'LinqDataSource1' does not support the Select property when the Delete, Insert or Update operations are enabled</span></p>
<br />
<p>There is a way around this though, although its not pretty and i think its a massive bodge but, insert your datasource and manually select the columns you need, create your formview. Then update the datasource, you are now able to turn on auto gen insert, update and delete. However the manual select still exists on your datasource so switch to source view and remove that.</p>
<br />
<p>You should then finds it all works...... Total bodge, I'd sooner just ensure i switch to Design mode to remove my extra fields, but hey everyone has there own way...</p><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2153751547788086073-7090156626280270791?l=blog.mjjames.co.uk'/></div>Michael Jameshttp://www.blogger.com/profile/06895910562063854287noreply@blogger.com1