tag:blogger.com,1999:blog-300314122024-02-19T09:24:04.177+00:00Confessions of a Professional DeveloperUseful info on: .NET, C#, jQuery, AJAX, MVC 3, RAZOR, SQL Server, Microsoft, Linux, Mono, Classic ASP, XSLT
Also some bits on good software, bad software, PC Maintenance and all that jazz!bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.comBlogger56125tag:blogger.com,1999:blog-30031412.post-58046600236031884432014-12-16T01:36:00.000+00:002014-12-16T01:36:30.566+00:00oEmbed CodePen or How to embed CodePen without oEmbed plugins using serverside calls...Recently I've been working on my new project <a href="http://get-json.azurewebsites.net/" target="_blank">Get JSON</a> - I've had some brilliant responses from users on both Twitter and CodePen alike. One of my <a href="http://codepen.io/bUKaneer/pen/yyOoXG" target="_blank">pens</a> even got picked for the front page - something which I did not expect but am indeed truly grateful for.<br />
<br />
Get JSON allows you to create ad-hoc data structures in JSON format and then pull them into either client or server side code for use within your application. It's great for semi-static lists, configuration info or indeed any data that can be modelled hierarchically.<br />
<br />
I thought it might be a good idea to include the Pen whilst viewing the data so that other users have a "serving suggestion" showing how the data could be accessed and modelled. In order for this function to work it required making a call using oEmbed in order to retrieve the iframe info needed to get the Pen onto the page.<br />
<br />
Upon investigation however I had significant difficulty getting this to work. Having tried several plugins to no avail I decided to simply write my own script to make the call to get the JSON containing the iframe code myself. Below is the code currently used in order to make the call to get the JSON containing the iframe code. Underneath the C# server side code is the JavaScript I used in order to get the Pen displayed on the page.<br />
<br />
<u>C# MVC 5 Controller</u><br />
<br />
<pre><code>var request =
WebRequest.CreateHttp(string.Format("http://codepen.io/api/oembed?&url={0}",
codePenUrl));
request.Accept = "application/json";
request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate,sdch");
request.Headers.Add(HttpRequestHeader.AcceptLanguage,
"en-GB,en;q=0.8,en-US;q=0.6,cy;q=0.4,ceb;q=0.2");
var json = string.Empty;
using (var response = await request.GetResponseAsync())
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
json = reader.ReadToEnd();
}
}
ViewBag.CodePenDemoFrame = json;
return View();
</code></pre>
<br />
<u>JavaScript </u>
<br />
<pre><code>
var codePenJson = @Html.Raw(ViewBag.CodePenDemoFrame);
$('#codePenDemo').append(codePenJson.html);
</code></pre>
bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com0tag:blogger.com,1999:blog-30031412.post-87687449461533176902014-09-22T15:25:00.000+00:002014-09-22T15:33:26.650+00:00How do I share files on Twitter?<h3>
Upload and Share ANY File!</h3>
On the odd occasion I need to share something with the world and it doesn't fit into the predefined file types of the major sharing sites. In order to overcome this problem I created <a href="http://tweet-file.com/">http://tweet-file.com</a> .<br />
Tweet File lets you log in with your twitter account and upload a set of files (any type of files you like as long as they meet the fairly obvious terms and conditions). Then you can share the link with your followers.<br />
<br />
All it takes is a few clicks and you're done!<br />
<br />
<h3>
Host external files for use with GitHub and CodePen</h3>
Tweet File is also particularly useful for sites like <a href="http://codepen.io/">http://codepen.io</a> and <a href="http://github.com/">http://github.com</a> that do not let you directly link to files without a paid account.<br />
<br />
Simply upload your files to Tweet File and link to them as you would normally (All files on Tweet File are publicly accessible and indexed by Google) to host pictures for your GitHub readme.md files or pull them into your CodePen pens!bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com0tag:blogger.com,1999:blog-30031412.post-67578702605049511572014-05-13T15:59:00.000+00:002014-05-13T15:59:36.709+00:00AngularJS on Google CDNTo save me looking this up again the modules for Angular JS are on google cdn and the full list can be found <a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/MANIFEST" target="_blank">here</a><br />
<br />
For general purposes though, the main ones to use are as follows (update version number where necessary):<br />
<br />
<pre><script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-animate.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-cookies.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-resource.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-route.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-sanitize.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-touch.min.js"></script>
</pre>
bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com2tag:blogger.com,1999:blog-30031412.post-49997546721233025152013-08-19T10:35:00.000+00:002013-08-19T10:37:50.679+00:00Twitter Tactics: Don't thank your new follower - share and publicise them!This is just a quick tip, some may do this already but its something I've only just started doing recently and whilst I couldn't say for sure whether it's a GREAT tactic or not it's nevertheless better than a simple "Thank you" tweet.<br />
<br />
When you get a new follower - especially if they're in Digital Marketing (Be it a freelancer, an agency, developer or designer) if they're on twitter they're probably engaged in other Social Media areas. What I like to do, instead of a thank you, is find their Blog, Website, About.me, Xee.me or something they've created on-line and Tweet about that with a "via @xxx" suffix and some nice useful Hash-tags.<br />
<br />
Personally I can see this being positive on several fronts, firstly it shows you're engaged - they followed you and you helped to promote them - everyone likes to be promoted. It also shows some courtesy, after all they've been good enough to follow you so after following them back spread the love!<br />
<br />
Secondly if you share something of theirs with a via tag they will see it and hopefully remember you - you've backed up their decision to follow you by doing something nice for them in return - this will hopefully stick in their mind and hopefully when they need help with something they might just remember you over and above those which didn't do anything or someone who just said "Thanks".<br />
<br />
If everyone of your followers tweeted about something you'd done and you tweeted about each of your followers it will eventually create a positive feedback loop for those engaging and may even drive up your followers and theirs - its an all round win win and only takes a few seconds!bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com2tag:blogger.com,1999:blog-30031412.post-60986594035916625152013-01-29T14:04:00.001+00:002013-07-11T09:34:54.880+00:00What are Single Page Applications (SPAs) Part 1: Explanation, Resource Round-up & Javascript Libraries<h3>
Introduction and Breakdown</h3>
Firstly let me start by saying that Single Page Applications are in their infancy. The technologies used to create then have been around for a while but with the advent of HTML and the coming of age of some core libraries they now seems to be going mainstream. By this I mean that your average developer should now have enough of the heavy lifting done that they can concentrate on business logic and plug-in syntax rather than build everything from the ground up!<br />
<br />
Secondly a Single Page Application in this context can be thought of as:<br />
<br />
"A website that relies almost exclusively on Client Side technology to display and update user interface (UI) elements to provide a more fluid and context based User Experience (UX). Server side technologies tend to be used to query data (or create/update it) and returns data (usually JSON) NOT a rendered page."<br />
<h3>
Common Features of a SPA</h3>
With that sorted lets dig a bit deeper - the following list are common features used within SPAs:<br />
<br />
<ul>
<li>Client based routing engine</li>
<li>Client based data-binding</li>
<li>HTML Templates </li>
<li>Asynchronous Client-Server communication</li>
</ul>
<br />
<h3>
Visual Studio & SPA</h3>
If you're lucky enough to be using Visual Studio 2012 you will be getting a starter template in a coming update details of this can be found on <a href="http://www.johnpapa.net/insidespatemplate/" target="_blank">John Papa's blog here</a> - I'm not going to even try and expand on this as it covers things from a Visual Studio stand point extremely well but rather I'd like to talk about SPA's and related technologies to fill in some background information which I've been scratching together over the past week or so. Incidentally John Papa's post will show you how to implement some of the technologies listed below using the SPA template - well worth a read to see how the technologies hang together even if you do not have or intend to use Visual Studio.<br />
<br />
<h3>
Technology & Frameworks</h3>
<b>Javascript & AJAX Framework</b><br />
We're going to need a good JavaScript framework for working with DOM elements & getting and receiving data. My preference (and the rest of the world it seems) is jQuery. if you've not used jQuery I strongly recommend learning it RIGHT NOW it will be your JavaScript crutch throughout this type of development.<br />
<br />
<a href="http://jquery.com/" target="_blank">jQuery Project Home</a><br />
<a href="http://nuget.org/packages/jquery" target="_blank">jQuery on NuGet</a><br />
<a href="http://api.jquery.com/jQuery.ajax/" target="_blank">jQuery AJAX Documentation</a><br />
<br />
<b>Data Binding & Templating</b><br />
When we make an AJAX request we're probably expecting our server to return data in JSON format. Once we have the data we need to BIND that data to some elements or a REUSABLE TEMPLATE. Microsoft package KnockoutJS for this purpose. In essence it allows you to declare (mark-up) your HTML using data- attributes on the HTML nodes. Knockout does this by implementing an MVVM pattern using observable objects.<br />
<br />
What this means is that you have a JavaScript ViewModel that can be populated with JSON data returned from the server and bound to HTML to update the interface. Because knockout is bi-directional this whole process can also work in reverse and server updates can be issued from observed client-side events. This all sounds remarkably time consuming and complicated - the key thing to remember is that WHAT it is doing IS complicated but that complication is abstracted by using the library so that HOW you get it to do it is NOT complicated.<br />
<br />
<a href="http://knockoutjs.com/" target="_blank">KnockoutJS Project Home</a><br />
<a href="http://nuget.org/packages/knockoutjs/" target="_blank">Knockout on NuGet</a><br />
<a href="http://learn.knockoutjs.com/" target="_blank">Learn KnockoutJS</a> (Excellent interactive resource well worth using)<br />
<a href="http://knockoutjs.com/documentation/template-binding.html" target="_blank">Knockout templates documentation</a><br />
<br />
<b>Client-side Request Routing</b><br />
Whether you're from a Windows background or not the concept Server-side Routing has been around for a while (Common implementations include apache's mod_rewrite and the ASP.NET Routing engine).<br />
<br />
Routing allows you to de-couple URL's from files on the webserver. In essence that means that you can navigate from a request to a resource on the server that is not necessarily located at that exact location BUT the server knows where it should go and ROUTEs it to the appropriate request handler.<br />
<br />
So the request http://somedomain.com/page/1/really-interesting-resource could end up being routed by the server to a webpage or other resource that actually exists here http://somedomain.com/getPageData.aspx?id=1.<br />
<br />
This helps us to make URL's human (and search engine) readable and can help with SEO rankings and making links more memorable.<br />
<br />
Client-side routing takes this a stage further and uses the anchor mark # in the URL to "overload" the server-side route with client-side requests and navigation. Essentially this means you can make a request like http://somedomain.com/#/page/1 and have the client handle the request and make a server-side call for data and refresh the UI accordingly without a page refresh.<br />
<br />
This creates create a better UI/UX in the long run as the web site appears to react very similarly to desktop applications and can update only the areas of the page that concern the request rather than redrawing the whole page.<br />
<br />
<a href="http://sammyjs.org/" target="_blank">SammyJS Project Home</a><br />
<a href="http://nuget.org/packages/Sammy.js/" target="_blank">Sammy on NuGet</a><br />
<a href="http://sammyjs.org/docs" target="_blank">Sammy documentation</a><br />
<br />
<h3>
Summary</h3>
I didn't intend this post to be quite as long as it has turned out to be, in short we've looked at the concept of Single Page Applications and the technologies that may be used to create one. In Part 2 I will be walking through some technologies and techniques that can be used to keep all these libraries under control, manage dependancies and helpers that make it easier to bring them all together. Some of these technologies include <a href="http://nuget.org/packages/RequireJS/" target="_blank">RequireJS</a>, <a href="http://typescript.codeplex.com/" target="_blank">Microsoft TypeScript</a>, the Durandal project (<a href="http://nuget.org/packages/Durandal/" target="_blank">Nuget</a> & <a href="https://github.com/BlueSpire/Durandal" target="_blank">GitHub</a>) and the <a href="http://visualstudiogallery.msdn.microsoft.com/07d54d12-7133-4e15-becb-6f451ea3bea6" target="_blank">Visual Studio Web Essentials</a> plugin.<br />
<br />
<br />bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com1tag:blogger.com,1999:blog-30031412.post-75322896650510497302013-01-28T16:32:00.000+00:002013-01-29T21:00:16.597+00:00Easy PHP Development on WindowsFor the majority of my career I've been involved with the Windows stack of development products Visual Studio, SQL Server and so on. However From time to time I've had cause to get my hands dirty with some PHP coding both commercially and in a freelance basis.<br />
<br />
Its been quite some time since I've used PHP but the other day a private client requested that I use it to deliver a website and I had to set about building a development environment for this on my PC. As it happened pretty much all the work could be done client side (jQuery, Google Maps API etc) so all I really needed was an IDE and the PHP interpreter.<br />
<br />
There are really only 4 steps to getting a basic PHP environment setup which I've tried to detail below as succinctly as possible!<br />
<br />
<b>1. Download the software</b><br />
<br />
PHP Binary Interpreter:<br />
<a href="http://windows.php.net/downloads/releases/php-5.4.8-Win32-VC9-x86.zip">http://windows.php.net/downloads/releases/php-5.4.8-Win32-VC9-x86.zip</a><br />
<br />
NetBeans 7.2.1 IDE:<br />
<a href="http://netbeans.org/downloads/">http://netbeans.org/downloads/</a><br />
<br />
<b>2. Extract & add PHP location to PATH Environment variable</b><br />
Create a directory for the PHP files something like:<br />
<br />
C:\Program Files (x86)\php-5.4.8\<br />
<br />
Extract the php zip file to the above directory.<br />
<br />
If you're using Windows 7 hit "Start" and type "Environment" then click "Edit the system environment variables" when the search comes back - for me this is the second option appearing on the start menu.<br />
<br />
In the "System Properties" window on the "Advanced" tab click the "Environment variables" button which is on the bottom right just above the "OK", "Cancel", "Apply" buttons.<br />
<br />
In the "System variables" list (second one near the bottom of the window) scroll down until you see "path", left click this item and then click the "Edit" button. Scroll to the end of the text box (End key will work best here). Then type/paste the following:<br />
<br />
;C:\Program Files (x86)\php-5.4.8<br />
<br />
Modify the above accordingly if you've chosen to install to a different location. Ensure it starts with a semi-colon to "close" the previous variable.<br />
<br />
<b>3. Install & configure NetBeans</b><br />
Run the NetBeans installer accepting all the defaults (or changing them where necessary). Open the IDE and then click "Tools" from the menu then Options then PHP. Click the "Browse" button next to the "PHP Interpreter" label and text box and navigate to the PHP directory you created earlier then click on the php.exe file and click "OK".<br />
<br />
<b>4. Reboot & Create New Project</b><br />
<b><br /></b>
Because we added an environment variable we should now close everything down and do a reboot. Once you're back into Windows start NetBeans and create a new project - choose the "Built in Webserver" option when prompted and you're good to go; write some PHP and then click the little green arrow to start!<br />
<br />
<br />
<br />
<br />bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com4tag:blogger.com,1999:blog-30031412.post-15134888730159727802013-01-09T13:49:00.001+00:002013-01-15T16:33:10.663+00:00Empire Avenue - Generating Portfolio Wealth & Eaves<br />
After the initial flush of investments when signing up to Empire Avenue you may find it difficult to get as much interest in your shares as during the first few weeks. This can be frustrating but it is possible to generate continued interest with some savvy investing.<br />
<br />
If you've not blown all your eaves on missions or upgrades consider investing in some of the Leader Board users. In effect these are "Top 100" lists for various social networks including those on Empire Avenue.<br />
<br />
If you're looking for reciprocal investments I would suggest hitting the Portfolio Wealth section. This section is for those people/companies who are heavy investors (and therefore heavy users of EA). The interesting thing about these users is that they also tend to have high share prices and potentially a lot of Eaves to invest.<br />
<br />
Follow this link and you should see the list:<br />
<a href="http://www.empireavenue.com/leaders/wealth/portfolio">http://www.empireavenue.com/leaders/wealth/portfolio</a><br />
<br />
Once you're there go down the list clicking on names and hit the invest button and buy as many shares as you are able! Leave them a shout out or share the buy on a network to alert them to the fact you're buying and with any luck you'll get some investment back (This is more likely with these types of users as previously stated) - the earnings from your share sales can then be funnelled into buying even more shares from the same or other users on the board and hopefully create a positive feedback loop to keep your portfolio & wealth growing!<br />
<br />
If you enjoyed this post please also consider buying a share or two of mine here:<br />
<a href="http://www.empireavenue.com/bukaneer">http://www.empireavenue.com/bukaneer</a><br />
<br />
A few days after writing this post I thought i would update it with a small graph of what this approach has done for my share price - please see the graph below, the red box shows what happened once I started investing a small amount of Eaves in each member of the Top 100 Portfolio Wealth users. I think it speaks for itself!<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBXE_B8bjcjRZ8VIu7qufm1gRRjeQLxlrBZK3pHMlTTlpCc0-Sh-DYpOgxtIAtkSvOX0jRNeEuQrdaWwAeJBchBnEy4hSz4fLYKpmbjzQGBus_jYmrXASviZqbz2Fxuo5o-4AAyg/s1600/Top100PortfolioWealth-InvestmentEffectOnSharePrice.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="172" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBXE_B8bjcjRZ8VIu7qufm1gRRjeQLxlrBZK3pHMlTTlpCc0-Sh-DYpOgxtIAtkSvOX0jRNeEuQrdaWwAeJBchBnEy4hSz4fLYKpmbjzQGBus_jYmrXASviZqbz2Fxuo5o-4AAyg/s320/Top100PortfolioWealth-InvestmentEffectOnSharePrice.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<script type="text/javascript" src="http://embed-script.branch.com/assets/embed/embed.m.js?body=0" data-branch-embedid="xr10Wqc5ORM" ></script>
<noscript><a href="http://branch.com/b/empire-avenue">Empire Avenue</a></noscript>
bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com0tag:blogger.com,1999:blog-30031412.post-33241502732207969232012-11-30T09:19:00.001+00:002012-11-30T09:38:04.075+00:00MVC 3 to MVC 4 Project Upgrade Configuration Error __WebPagesVersion__.0.0<span style="font-family: Arial, Helvetica, sans-serif;">I've seen a few posts on forums like Stack Overflow recently regarding issues when upgrading from an MVC3 to an MVC4 site regarding Web Pages version configuration. Whilst I haven't experienced the problem myself it revolves around web.configs </span><br />
<section a="a" attribute.="attribute." entry="entry" font="font" have="have" in="in" name="host" nbsp="nbsp" placeholder="placeholder" seems="seems" the="the" to="to" version="version" which="which"></section><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">Presumably this is meant to be replaced by a version number but in some cases isn't and so the whole entry looks like so:</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<br />
<div class="post-text" itemprop="description" style="background-color: white; border: 0px; margin: 0px 5px 5px 0px; padding: 0px; vertical-align: baseline; ">
<pre class="lang-cs prettyprint prettyprinted" style="background-color: #eeeeee; border: 0px; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto;"><code style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span style="font-family: Courier New, Courier, monospace;"><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">section name</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="str" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">"host"</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> type</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="str" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">"System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=</span><span class="str" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><b>__WebPagesVersion__.0.0</b></span><span class="str" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">, Culture=neutral, PublicKeyToken=31BF3856AD364E35"</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> requirePermission</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="str" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">"false"</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">/></span></span></code></pre>
<div style="font-size: 14px; line-height: 18px;">
<code style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span></code></div>
<div style="font-size: 14px; line-height: 18px;">
<code style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span style="font-family: Arial, Helvetica, sans-serif;">To fix the error simple replace the __WebPagesVersion__ with 2.0 so it looks like the following</span></span></code></div>
<div style="font-size: 14px; line-height: 18px;">
<code style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span></code></div>
<div>
<code style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span style="font-family: Arial, Helvetica, sans-serif;"></span></span></code><br />
<pre class="lang-cs prettyprint prettyprinted" style="background-color: #eeeeee; border: 0px; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto;"><code style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span style="font-family: Arial, Helvetica, sans-serif;"><code style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">section name</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="str" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">"host"</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> type</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="str" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">"System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=</span><span class="str" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><b>2.0.0.0</b></span><span class="str" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">, Culture=neutral, PublicKeyToken=31BF3856AD364E35"</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> requirePermission</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="str" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">"false"</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">/></span></code></span></span></code></pre>
<code style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span style="font-family: Arial, Helvetica, sans-serif;">
<div style="font-size: 14px; line-height: 18px;">
<code style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><br /></span></code></div>
<div style="font-size: 14px; line-height: 18px;">
<code style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span style="font-family: Arial, Helvetica, sans-serif;">It's also worth running Find in files for this errant string and/or checking any other web.configs in your solution and ensuring that the Version reference is 2.0.0.0 and not 1.0.0.0 or ___WebPagesVersion___.</span></span></code></div>
<div style="font-size: 14px; line-height: 18px;">
<code style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><br /></span></code></div>
<div style="font-size: 14px; line-height: 18px;">
<code style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><br /></span></code></div>
<div style="font-size: 14px; line-height: 18px;">
<code style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span style="font-family: Arial, Helvetica, sans-serif;">References:</span></span></code></div>
<div style="font-size: 14px; line-height: 18px;">
<code style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></span></code></div>
<div>
<code style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="pun" style="background-color: transparent; border: 0px; font-size: 14px; line-height: 18px; margin: 0px; padding: 0px; vertical-align: baseline;"><span style="font-family: Arial, Helvetica, sans-serif;">http://stackoverflow.com/questions/13443152/configuration-error-while-using-areas-in-asp-net-mvc-4/13585812#13585812 </span></span></code></div>
<div>
<code style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="pun" style="background-color: transparent; border: 0px; font-size: 14px; line-height: 18px; margin: 0px; padding: 0px; vertical-align: baseline;"><br /></span></code></div>
</span></span></code></div>
</div>
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">http://www.asp.net/whitepapers/mvc4-release-notes</span>bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com0tag:blogger.com,1999:blog-30031412.post-15291284325795993802012-10-18T19:25:00.000+00:002012-10-18T19:29:46.140+00:00Empire Avenue: Week 1 - It Really is Social Media Rocket Fuel!In my previous few blog posts I've been talking about my experience with www.EmpireAvenue.com . In effort to record and indeed share the experience I've created this post!<br />
<br />
<b>EAv (Empire Avenue) </b>is part game, part social media, part marketing tool, bear with me and Ill try to explain as much as I know as simply as possible.<br />
<b><br /></b>
<b>The Game</b><br />
<b><br /></b>
The game is based around a stock market idea but the stock is you - or in fact all the users signed up. Using a digital currency (Eaves) you get to buy or sell shares in whomever you choose. Each user gets "paid" in eaves each day depending on your social media interaction that day. The more social you are the more you earn. As shares are bought and sold and users' activity gets logged their share price moves up or down depending on how well they've done. When you own stock in someone else you'll also receive a dividend dependant upon their performance. Your stocks are held in a portfolio where you can track, watch and filter searching for sliders or gainers to buy and sell more shares in.<br />
<b><br /></b>
<b>The Social Media</b><br />
<b><br /></b>
For the game to work like a real stock market you need a very large very active user base to keep things interesting. Fortunately EAv is bursting to the seams with all manner of social media fanatics - I was astounded at how active the user base was! For such a new system (only two years old) it seems to contain a huge number of heavy hitting social media, marketing, digital, entrepreneurial users who've all mastered klout and kredz and have clearly moved on. I've seen an extra 100 followers on Twitter and double the number of blog visits I get in just this one week. If you want the pulse of social media and marketing look here first and follow these people heavily.<br />
<br />
<b>The Marketing</b><br />
<b><br /></b>
OK so once you get to grips with the game, have a portfolio, followed/linked/friended/subscribed your shareholders and the people in whom you've bought shares its time to sit back, take a breather and look at missions. Once your share price hits 30 (day 2 or 3 if you're social) the ability to create Missions is unlocked. Missions allow you to "pay" users to undertake certain actions. Generally this centres around some form of social media action such as liking a page, retweeting a tweet or something of that nature. This is genius, for one thing, its easy and free (although you can pay real money for virtual eaves should you wish).<br />
<br />
Getting social media interaction going on this basis with this user base creates a very positive feedback loop, it generates social media actions from the EAv community which in turn creates more eaves which helps share prices rise which increases dividend and portfolio value. Because this is social media Klout and Kredz will take notice and the halo effect will raise you scores there too - you become more influential. All of this makes you more visible, followable and likeable. And so this awesome whirlwind of interaction and payback unfold beautifully before you in real time.<br />
<br />
<b>Summary</b><br />
<b><br /></b>
I've thoroughly enjoyed my first week on EAv; I've learned a lot and got some awesome followers and followees on Twitter and seen my Klout score rise 3 points. Don't be shy have a go, get to grips with it and enjoy the ride!<br />
<br />
If you enjoyed this blog post please use the side menu to share it, subscribe, like it and follow me on Twitter, buy some shares in me - and leave a comment! I'd be very much obliged! ;o)bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com1tag:blogger.com,1999:blog-30031412.post-51963973285512437422012-10-16T11:52:00.000+00:002012-10-16T13:37:21.716+00:00ADO.NET + DataTables vs Dapper.NET BenchmarksIn my <a href="http://ilovedevelopment.blogspot.co.uk/2012/10/adonet-dappernet-using-c-aspnet.html">previous blog post</a> I was looking at Dapper - basic insert and select operations versus an raw ADO.NET. In order to perform some basic speed tests (and compare lines of code written) I added a new page to my project called Benchmark.aspx with a single PlaceHolder control (called Container) to hold the results.<br />
<br />
The code and results below demonstrate that for large queries using Dapper can cut execution time by about four fifths (in my not very scientific tests). If you're thinking of using Dapper you can use/modify the code below to prove to yourself that it will be faster. This is basic boiler plate code that you can modify to perform your own analysis. Please excuse the inline SQL!<br />
<br />
As a small aside Marc (the creator) says that in later builds of Dapper.NET you don't even have to open the connection - it will do it for you!<br />
<br />
For more comprehensive and detailed benchmarks please see <a href="http://www.mattjcowan.com/funcoding/2012/02/24/adding-llblgen-to-the-dapper-benchmark-test-project/">this post here</a><br />
<br />
<br />
<b>Results</b><br />
Dapper inserts: 100, time taken: 00:00:00.4724731<br />
Dapper inserts: 1000, time taken: 00:00:05.3936728<br />
Dapper inserts: 10000, time taken: 00:00:15.3227475<br />
<br />
ADO.NET inserts: 100, time taken: 00:00:00.0400515<br />
ADO.NET inserts: 1000, time taken: 00:00:03.8124865<br />
ADO.NET inserts: 10000, time taken: 00:00:18.4029055<br />
<br />
Dapper Select: 10, time taken: 00:00:00.0164510<br />
Dapper Select: 100, time taken: 00:00:00.0017245<br />
Dapper Select: 1000, time taken: 00:00:00.0033249<br />
Dapper Select: 10000, time taken: 00:00:00.0296995<br />
<br />
DataTable Select: 10, time taken: 00:00:00.0008202<br />
DataTable Select: 100, time taken: 00:00:00.0014142<br />
DataTable Select: 1000, time taken: 00:00:00.0097499<br />
DataTable Select: 10000, time taken: 00:00:00.1048403<br />
<br />
<b>Code:</b><br />
<br />
<pre class="brush: csharp">
using Dapper;<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Configuration;<br />
using System.Data;<br />
using System.Data.SqlClient;<br />
using System.Diagnostics;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
<br />
namespace DapperSandbox<br />
{<br />
public partial class BenchMark : System.Web.UI.Page<br />
{<br />
public class DapperUser<br />
{<br />
public Guid Id { get; set; }<br />
public string Firstname { get; set; }<br />
public string Surname { get; set; }<br />
public string Email { get; set; }<br />
}<br />
<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
RunDapperInsertBenchMark(100);<br />
RunDapperInsertBenchMark(1000);<br />
RunDapperInsertBenchMark(10000);<br />
<br />
RunAdoInsertBenchMark(100);<br />
RunAdoInsertBenchMark(1000);<br />
RunAdoInsertBenchMark(10000);<br />
<br />
RunDapperSelectBenchmark(100);<br />
RunDapperSelectBenchmark(1000);<br />
RunDapperSelectBenchmark(10000);<br />
<br />
RunDataTableSelectBenchmark(100);<br />
RunDataTableSelectBenchmark(1000);<br />
RunDataTableSelectBenchmark(10000);<br />
}<br />
<br />
private void RunDapperInsertBenchMark(int iterations)<br />
{<br />
Stopwatch stopwatch = new Stopwatch();<br />
stopwatch.Start();<br />
for (int i = 0; i < iterations; i++)<br />
{<br />
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["default"].ToString()))<br />
{<br />
connection.Open();<br />
connection.Execute("UserInsert", new { Id = Guid.NewGuid(), Firstname = "First", Surname = "Second", Email = "Email" },<br />
commandType: CommandType.StoredProcedure);<br />
}<br />
}<br />
stopwatch.Stop();<br />
Container.Controls.Add(new LiteralControl(string.Format("Dapper inserts: {0}, time taken: {1}<br />
", iterations.ToString(), stopwatch.Elapsed)));<br />
}<br />
<br />
private void RunAdoInsertBenchMark(int iterations)<br />
{<br />
Stopwatch stopwatch = new Stopwatch();<br />
stopwatch.Start();<br />
for (int i = 0; i < iterations; i++)<br />
{<br />
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["default"].ToString()))<br />
{<br />
connection.Open();<br />
using (SqlCommand command = new SqlCommand("UserInsert", connection))<br />
{<br />
command.CommandType = CommandType.StoredProcedure;<br />
command.Parameters.AddWithValue("@Id", Guid.NewGuid());<br />
command.Parameters.AddWithValue("@Firstname", "First");<br />
command.Parameters.AddWithValue("@Surname", "Second");<br />
command.Parameters.AddWithValue("@Email", "Email");<br />
command.ExecuteNonQuery();<br />
}<br />
}<br />
}<br />
stopwatch.Stop();<br />
Container.Controls.Add(new LiteralControl(string.Format("ADO.NET inserts: {0}, time taken: {1}<br />
", iterations.ToString(), stopwatch.Elapsed)));<br />
}<br />
<br />
private void RunDapperSelectBenchmark(int numberOfResults)<br />
{<br />
Stopwatch stopwatch = new Stopwatch();<br />
stopwatch.Start();<br />
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["default"].ToString()))<br />
{<br />
connection.Open();<br />
var rows = connection.Query<dapperuser>("SELECT TOP " + numberOfResults.ToString() + " * FROM dbo.[User]", commandType: CommandType.Text).ToList();</dapperuser><br />
}<br />
stopwatch.Stop();<br />
Container.Controls.Add(new LiteralControl(string.Format("Dapper Select: {0}, time taken: {1}<br />
", numberOfResults.ToString(), stopwatch.Elapsed)));<br />
}<br />
<br />
private void RunDataTableSelectBenchmark(int numberOfResults)<br />
{<br />
Stopwatch stopwatch = new Stopwatch();<br />
stopwatch.Start();<br />
DataTable results = new DataTable();<br />
List<dapperuser> user = new List<dapperuser>();</dapperuser></dapperuser><br />
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["default"].ToString()))<br />
{<br />
connection.Open();<br />
using (SqlCommand command = new SqlCommand("SELECT TOP " + numberOfResults.ToString() + " * FROM dbo.[User]",connection))<br />
{<br />
command.CommandType = CommandType.Text;<br />
results.Load(command.ExecuteReader());<br />
foreach (DataRow row in results.Rows)<br />
{<br />
user.Add(new DapperUser() { Id = Guid.Parse(row["id"].ToString()), Firstname = row["Firstname"].ToString(), Surname = row["Surname"].ToString(), Email = row["Email"].ToString() });<br />
}<br />
}<br />
}<br />
stopwatch.Stop();<br />
Container.Controls.Add(new LiteralControl(string.Format("DataTable Select: {0}, time taken: {1}<br />
", numberOfResults.ToString(), stopwatch.Elapsed)));<br />
}<br />
}<br />
}</pre>bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com2tag:blogger.com,1999:blog-30031412.post-70597387806485382772012-10-16T10:18:00.001+00:002012-10-16T10:18:44.043+00:00ADO.NET & Dapper.NET using C# & ASP.NETI posted my <a href="http://stackoverflow.com/questions/12839635/is-there-a-better-faster-way-to-access-raw-data" target="_blank">first question on StackOverflow</a> the othe dayr. A question regarding best practise for high speed raw data access (Follow the link for the full blown version). In short however it centred around whether there was a faster way to access the data than executing a stored procedure and loading a DataTable with the ExecuteReader results.<br />
<br />
At first most respondents (some with >5k scores) said that this was generally the fastest way and that everything I was doing was correct. However <a href="http://stackoverflow.com/users/23354/marc-gravell" target="_blank">Marc Gravell</a> (A Microsoft MVP and Moderator of StackOverflow) kindly posted an awesome response! In order to increase the performance of StackOverflow he and Sam Saffron had developed a very small .NET ORM called <a href="http://nuget.org/packages/Dapper">Dapper.NET</a> .<br />
<br />
Essentially what this allows you to do is fire inline SQL or stored procedures from a IDBConnection type and return statically typed results! This is awesome if you just want to get data really fast and don't require the overhead of a DataTable that has functionality to manage relationships and track changes and such forth.<br />
<br />
In the jQuery AJAX, Web 2+, ASP.NET MVC world this is more often than not what you're trying to acheive, very fast smallish selects/inserts and updates and whilst Entity Framework, LLBLGEN, NHibernate etc have their advantages sometimes they are waaaaaaay more than you need and can add unecessary complexity. <br />
<br />
Because Dapper.NET removes all this complex relationship management overhead it can outperform most data related operations compared to its heavier siblings. In short, its about as fast as you can get within the framework! Heres a small sample of code I wrote to add and return users from a database - this is ALL the code I had to write and notice the statically typed objects Im using - no nasty DataTable["SomeColumnName"] references - just POCO ;o)<br />
<br />
Steps for setup:<br />
Create a Blank Web Application (I chose WebForms for ease but MVC is equally applicable)<br />
Create a Db<br />
Add Db Connection String to Web.Config<br />
Create UserInsert Stored Procedure<br />
Create UserSelectAll Stored Procedure<br />
<br />
Default.aspx.cs code:<br />
<br />
using Dapper;<br />
using System;<br />
<br />
using System.Collections.Generic;<br />
using System.Configuration;<br />
using System.Data;<br />
using System.Data.SqlClient;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
<br />
namespace DapperSandbox<br />
{<br />
public partial class Default : System.Web.UI.Page<br />
{<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
if (IsPostBack) return;<br />
BindUserResults();<br />
}<br />
<br />
public class DapperUser<br />
{<br />
public Guid Id { get; set; }<br />
public string Firstname { get; set; }<br />
public string Surname { get; set; }<br />
public string Email { get; set; }<br />
}<br />
<br />
private void BindUserResults()<br />
{<br />
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["default"].ToString()))<br />
{<br />
connection.Open();<br />
var rows = connection.Query<dapperuser>("UserSelectAll", commandType: CommandType.StoredProcedure).ToList(); </dapperuser><br />
ResultsView.DataSource = rows;<br />
ResultsView.DataBind();<br />
}<br />
}<br />
<br />
public void Add_Click(object sender, EventArgs e)<br />
{<br />
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["default"].ToString()))<br />
{<br />
connection.Open();<br />
connection.Execute("UserInsert", new { Id = Guid.NewGuid(), Firstname = Firstname.Text, Surname = Surname.Text, Email = Email.Text },<br />
commandType: CommandType.StoredProcedure);<br />
}<br />
BindUserResults();<br />
}<br />
}<br />
}<br />
bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com0tag:blogger.com,1999:blog-30031412.post-58511189612000607042012-10-12T10:10:00.001+00:002012-10-12T10:10:13.636+00:00Empire Avenue - Social Media Stock Market GameSo I happened across <a href="http://www.empireavenue.com/eahome" target="_blank">Empire Avenue</a> yesterday - some two years after it went live (where have I been)?! After getting slight addicted to it yesterday and scratching the surface of some of its features I thought I'd write up some findings!<br />
<br />
The purpose is evidently to "have fun" after all its a game. People "buy" stocks in your and you in others - depending on your Social Network reach and influence your stock goes up and down and you earn or lose Eaves (the virtual currency). So far so good fairly straight forward, but its not just a game is it?!<br />
<br />
No its not JUST a game, the most intriguing feature for me, certainly for a Social Media Impact point of view is the Missions tab. This is where users (or businesses) can set up a reward scheme (payment in Eaves generally) for you taking some action. The actions are generally quite straight forward such as "Like my page" on Facebook or "Follow me on Twitter" or retweet such and such. Now whilst this isn't necessarily going to create long standing stalwart followers or indeed a sustained growth - it lends itself nicely to Brand/Product promotion endeavours.<br />
<br />
If you need to "get the word out" setting up a mission and getting people to post and/or tweet about whatever it is will certainly have a halo effect and get your product/service in front of peoples eyes - and hopefully the more eyes see it the better the chance that they will convert to sales.<br />
<br />
In summary Empire Avenue is Fun but it definitely has potential as a bona-fide marketing tool/technique in the right circumstances.<br />
<br />
In a completely un scientific test I noted that on the day I joined EA my blog got twice the hits it does on any other normal day - whether this is sustained or not is unknown - its only been 24 hours after all!<br />
<br />
Further info can be found here:<br />
http://en.wikipedia.org/wiki/Empire_AvenuebUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com1tag:blogger.com,1999:blog-30031412.post-87681981474027337742012-10-11T19:19:00.001+00:002012-10-11T19:19:32.423+00:00Empire Avenue {EAV:d546ce401f8dfec8}{EAV:d546ce401f8dfec8}<br />
<br />
This is a verification blog post for Empire Avenue - an exciting and interesting new take on Social Networking; I only joined today and Im quite smitten - Ill write a proper post all about it when I've got to grips with it a bit more!bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com2tag:blogger.com,1999:blog-30031412.post-47388273844053665822012-10-10T08:47:00.000+00:002012-10-10T08:47:16.901+00:00ASP.NET MVC 4 & jQuery Mobile<br />
Whilst doing my usual round of research I have discovered that within the Developer Preview release of ASP.NET MVC 4 they have included two interesting features. Firstly Adaptive Rendering by Browser and the Mobile Application project type.<br />
<br />
The first of these allows the developer to provide different Views depending on the relevant (mobile) browser. The Mobile project type is specifically geared toward creating mobile web apps. Further to this the mobile functionality is provided out-of-the-box by inclusion of the jQuery Mobile 1.0.1 framework.<br />
<br />
<b><u>What does this mean?:</u></b><br />
<br />
As Microsoft are backing both jQuery and jQuery mobile by including them in its development platform by default and indeed contributing significant enhancements to the jQuery project (See Data Validators and jQuery Validation plugin). I believe that we should follow suit and any efforts toward learning/providing mobile web app functionality should be focused primarily on the jQuery Mobile framework. A list of graded browser support for the platform can be found at the following location:<br />
<br />
http://jquerymobile.com/gbs/<br />
<br />
<b><u>What does this mean for Native iOS and Andriod Apps?</u></b><br />
<br />
Actually not a lot, native apps will still need to be created in either XCode 4 (iOS) or eclipse (Andriod) or indeed using PhoneGap on a mac – there may be other options going forward – VSNomad or indeed the C# compiler for Mac (Which made such an impression Ive forgotten its name) but PhoneGap seems to be the most mature environment for Cross-Platform native apps for the time being.<br />
<br />
Interestingly if the “App” doesn’t require any native functionality (Turning on the camera flash for instance) then it would be feasible to create a “shell” native app n phone gap that simply includes the browser control as a full screen view and points at the URI for the Web App. This essentially would create a “hard coded” browser pointing to the URI of choice. In turn this means that the Web App part could be build within visual studio (or any other IDE for that matter) and a native app could be created very quickly to point at the online resource.<br />
<div>
<br /></div>
bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com0tag:blogger.com,1999:blog-30031412.post-45904375728335475842012-10-10T08:17:00.003+00:002012-10-10T08:52:22.427+00:00MVC 4, Signal R & Web API Dual Start Up Projects!For a while now I've been using Visual Studio 2012 and investigating it's new features (which are many) as well as looking at the new project types and other offerings such as the new project templates and new technologies like Signal R. I decided that the best way to get a handle on all of this was to create a sample solution using as much of it all together as possible. My idea was to have a solution with a couple of projects, I'd use MVC 4 with Signal R for the Web UI and a Web API project as my Service/Data layer. To that end I set about creating the solution with two projects. At this point I was a stuck - how do I run both the Web UI front end and the Web API service layer at the same time - traditionally you only have 1 start up project!<br />
<br />
This is where Visual Studio 2012 with IIS Express comes in handy - you can set Multiple Start up projects really simply. In essence all you have to do is right click on each project in turn - go to the web tab of the properties page and ensure both projects are using IIS Express and using different ports. Then right click on the solution node then click Properties. Select the Common Properties node then Start up Project. Click the radio button that says Multiple Start up projects and use the Grid to select the start up action of each project within the solution. With that done all you need do is hit F5 and both projects will start-up (and debug if desired) and you're ready to go!<br />
<br />
<iframe bordercolor="#000000" frameborder="0" height="250" hspace="0" marginheight="0" marginwidth="0" scrolling="no" src="http://ad.doubleclick.net/adi/N7433.148119.BLOGGEREN/B6975434.1786;sz=300x250;ord=[timestamp]?;lid=41000613802273275;pid=5792;usg=AFHzDLui8zG4fZKFiEPNvvZ-IFxWJQTThA;adurl=http%253A%252F%252Fwww.perfume-click.co.uk%252FAzzaro-Azzaro-Chrome-Sport-Gift-Set-50ml-EDT-Computer-Mouse-s5792%252F;pubid=584830;price=%C2%A322.29;title=Azzaro+Azzaro+Chrome+Sport+Gift+Set+50ml+EDT+%2B+Computer+Mouse;merc=Perfume+Click;imgsrc=http%3A%2F%2Fwww.perfume-click.co.uk%2Fpictures%2F13373_originalZXQ.jpg;width=199;height=135" vspace="0" width="300"></iframe><br />bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com0tag:blogger.com,1999:blog-30031412.post-81642342379066113322012-06-20T11:43:00.000+00:002012-06-20T11:43:02.023+00:00Visual Studio & IIS Express : Add static content mime types like ".WebM"I took over a project the other day which had cause to use video in WebM format. Cassini (bless it) flatly refused to do anything at all with the file and one of the requirements was to take some action after the video finished playing. Not wanting to code this "blind" I decided it was about time to upgrade to IIS Express (I already had Visual Studio sp1 installed but not from the Web Platform Installer). I went off and downloaded the executable and followed the following instructions to set it up.<br />
<br />
IIS Express Download:<br />
<a href="http://www.microsoft.com/en-us/download/details.aspx?id=1038">http://www.microsoft.com/en-us/download/details.aspx?id=1038</a>
<br />
<br />
Installation and Setup Instructions:<br />
<a href="http://blogs.msdn.com/b/webdevtools/archive/2011/03/14/enabling-iis-express-support-in-vs-2010-sp1.aspx">http://blogs.msdn.com/b/webdevtools/archive/2011/03/14/enabling-iis-express-support-in-vs-2010-sp1.aspx</a>
<br />
<br />
WebM File Format Details (See naming section):<br />
<a href="http://www.webmproject.org/code/specs/container/">http://www.webmproject.org/code/specs/container/</a>
<br />
<br />
Once this was completed I simply had to navigate to the installation directory and run the following command and presto everything worked! My advice, drop Cassini and use IIS Express immediately!<br />
<br />
Installation directory:<br />
<br />
C:\Program Files (x86)\IIS Express<br />
<br />
Command to enabled WebM:<br />
appcmd set config /section:staticContent /+[fileExtension='.webm',mimeType='video/webm']<br />bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com0tag:blogger.com,1999:blog-30031412.post-62499572816167933962012-05-16T15:41:00.000+00:002012-10-10T08:58:04.043+00:00Which property caused "System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details." exception?<br />
<br />
Sometimes when using ASP.NET MVC 3 / 4 with Entity Framework it can be difficult to see exactly which property is causing issues when db.SaveChanges() is called.<br />
<br />
If you wrap the db.SaveChanges() in an appropriate try {} catch {} block whilst debugging (see below) each property in conflict will be written to your debug console which is much more helpful in finding and resolving the problem!<br />
<br />
Don't forget to remove the try catch block after your debugging session though otherwise exceptions will be swallowed and disappear in a live environment which will then hinder further debugging efforts!<br />
<br />
<code>
[Authorize(Roles = "SomeRole")]<br />
[HttpPost]<br />
[ValidateAntiForgeryToken]<br />
public ActionResult Create(string SomethingsName)<br />
if (ModelState.IsValid)<br />
{<br />
db.Something.Add(new Something()<br />
{<br />
Id = Guid.NewGuid()<br />
,<br />
Name = SomethingsName<br />
});<br />
try<br />
{<br />
db.SaveChanges();<br />
}<br />
catch (DbEntityValidationException dbEx)<br />
{<br />
foreach (var validationErrors in dbEx.EntityValidationErrors)<br />
{<br />
foreach (var validationError in validationErrors.ValidationErrors)<br />
{<br />
Debug.WriteLine("Property: {0} Error: {1}",<br />
validationError.PropertyName,validationError.ErrorMessage);
}<br />
}<br />
}<br />
}<br />
return RedirectToAction("Index");<br />
} </code><br />
<code><br /></code>
<code><iframe bordercolor="#000000" frameborder="0" height="250" hspace="0" marginheight="0" marginwidth="0" scrolling="no" src="http://ad.doubleclick.net/adi/N7433.148119.BLOGGEREN/B6534697.139;sz=300x250;ord=[timestamp]?;lid=41000000000102709;pid=25512UK;usg=AFHzDLtY99QBJfF-636z6TD_DnOzY_M4kg;adurl=http%253A%252F%252Fwww.chefscatalog.com%252Fproduct%252F25512-Family-Recipe-Book-and-Organizer.aspx%253Futm_source%253Dgoogle_uk%2526utm_medium%253Dshopping%2526utm_content%253D25512%2526utm_campaign%253DTalus%252520Corporation%2526gdftrk%253DgdfV23800_a_7c2214_a_7c9506_a_7c29274;pubid=584830;price=%C2%A323.19;title=Family+Recipe+Book+and+Organizer;merc=chefscatalog.com;imgsrc=http%3A%2F%2Fwww.chefscatalog.com%2Fimg%2Fproducts%2F500x500%2F25512_500.jpg;width=135;height=135" vspace="0" width="300"></iframe><br />
<br />
</code>bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com0tag:blogger.com,1999:blog-30031412.post-38980935073535673262012-04-23T09:30:00.000+00:002012-04-23T09:30:13.004+00:00ASP.NET MVC 3 Generating an ActionLink in the controller - Html.ActionLink EquivalentGenerating routing links is extremely easy in MVC 3 using @Html.ActionLink(linkText,action,controller) when you're using Razor views this is great. However sometimes you need to generate the link within the controller - at which point you do not have direct access to the Html helper.<br />
<br />
In these instances such as creating links for a wysiwyg editor or adding a link into an email it is preferable to have the system generate it with the appropriate protocol http/https and/or a port number if you're running locally. To this end I did some digging and put together the following little code snippet which does eactly that!<br />
<br />
I thought I'd share it here to save me having to look it up again in the future!<br />
<br />
<br />
string absoluteAction = string.Format("{0}://{1}{2}",<br />
Url.RequestContext.HttpContext.Request.Url.Scheme,<br />
Url.RequestContext.HttpContext.Request.Url.Authority,<br />
Url.Action("ActionName", "ControllerName", new {Id = "Data"}));<br />bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com0tag:blogger.com,1999:blog-30031412.post-678161042430548842012-04-18T16:06:00.001+00:002012-04-18T16:06:53.500+00:00MVC 3 ModelState Validation after Postback - Page.Validate() equivalentI've been tinkering with MVC 3 for a while now and I have to say I'm extremely impressed - it is a joy to work with as are its supporting technologies Entity Framework, ASP.NET Routing and Razor view engines to name a few.<br />
<br />
However I've been working on WebForms for so long that I'm finding more than a few stumbling blocks as I grapple my way up the learning curve. One such hurdle was "How do I re-validate a model after its been posted back to the server". The scenario being I want a user to type a plain text password into a form which is required but not persisted - I used [NotMapped] DataAnnotation attribute in the model definition to get this bit done.<br />
<br />
Following that on postback I need to create a Salt (required and persisted) and a PasswordHash (required and persisted). Trouble was, I originally had the Salt and Hash properties within my if (ModelState.IsValid) statement.<br />
<br />
The Model was at this point invalid because no password hash or salt had been created yet. "Easy" I thought simply elevate the property assignments above the if condition. No luck (but along the right lines) as the properties were now filled but I needed to Re-Validate the model, no Page.Validate() to rely upon at this point so I did some digging. As it turns out you simply need to call two methods (below) and they are roughly equivalent to what a WebForms guy would consider to be Page.Validate().<br />
<br />
<br />
<pre class="lang-cs prettyprint" style="background-attachment: initial; background-clip: initial; background-color: #eeeeee; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; text-align: left; vertical-align: baseline; width: auto;"><pre class="lang-cs prettyprint" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin-bottom: 10px; max-height: 600px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; vertical-align: baseline; width: auto;"><span class="pun" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">p.Salt = CreateSalt(36);
p.PasswordHash = GenerateSaltedHash(UTF8.GetBytes(p.Password), p.Salt);
<pre class="lang-cs prettyprint" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin-bottom: 10px; max-height: 600px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; vertical-align: baseline; width: auto;"><code style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"><span class="typ" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #2b91af; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">ModelState</span><span class="pun" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">.</span><span class="typ" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #2b91af; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">Clear</span><span class="pun" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">();
</span></code><span class="typ" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #2b91af; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">TryValidateModel</span><span class="pun" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">(</span><span class="pln" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">model</span><span class="pun" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;">);
</span><span style="background-color: transparent;">if (ModelState.IsValid)
</span><span style="background-color: transparent;">{
</span><span style="background-color: transparent;">p.Id = Guid.NewGuid();
</span><span style="background-color: transparent;">db.People.Add(p);
</span><span style="background-color: transparent;">db.SaveChanges();
</span><span style="background-color: transparent;">return RedirectToAction("Index");
</span><span style="background-color: transparent;">}
</span><span style="background-color: transparent;">return View(person);</span></pre>
</span></pre>
</pre>
<br />
<pre class="lang-cs prettyprint" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; text-align: left; vertical-align: baseline; width: auto;">
</pre>bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com0tag:blogger.com,1999:blog-30031412.post-59791328489247644082012-03-03T17:43:00.000+00:002012-03-03T17:43:05.897+00:00Grow your sector knowledge using Twitter and ConferencesHello again!<br />
<br />
I've been following Microsoft development for years now and the advent of twitter gave me a brilliant insight into Microsoft developers thoughts and keeps me abreast of current feeling about technology by those developing it. For years i used Google Reader and added blogs and such forth to achieve the same result but it was must less immediate and much more in-depth.<br />
<br />
This week has been a great week on twitter for me keeping up with what's going on at the MVP Conference (still not quite made it to MVP myself but that's all part of my life time goals plan ... ). OK so here a really obvious tip that only just occurred to m,e (stupid) if I hit the #mvp12 link in twitter and then hit the people link - presto a complete list of everyone who was at MVP and who is also on twitter - amazing - all the people i need to follow in one place:<br />
<br />
<a href="https://twitter.com/#!/search/users/%23mvp12">https://twitter.com/#!/search/users/%23mvp12</a>
<br />
<br />
I went through and more than quadrupled the amount of people I followed BUT hopefully this will give me an excellent view into what's happening going forward!<br />
<br />
The same technique should work for any industry and any conference so if you're not sure who to follow and who's making noise in your industry target a conference and away you go!bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com0tag:blogger.com,1999:blog-30031412.post-65997661124517454382012-02-29T08:52:00.002+00:002012-02-29T09:58:48.303+00:00ASP.NET Location Node in web.configJust a quick one today! This has probably been around for a while now but yesterday I had good cause to use this handy piece of functionality!<br />
<br />
The location tag within the web config file of your asp.net 4 website allows you to specify a location tag with a path attribute and set "web.config" style setting for just that single location! This is particularly handy if you need to set request upload limits or request validation settings for a particular page that handles file uploads or downloads.<br />
<br />
Here is an example which allows for the upload of very large files and allows a URL Encoded filename (with some very odd characters) to be downloaded<br />
<br />
<br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
</div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 12pt;"> </span><b><span style="font-family: Consolas; font-size: 12pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 12pt;"> <</span><span style="color: #a31515; font-family: Consolas; font-size: 12pt;">location</span><span style="color: blue; font-family: Consolas; font-size: 12pt;"> </span><span style="color: red; font-family: Consolas; font-size: 12pt;">path</span><span style="color: blue; font-family: Consolas; font-size: 12pt;">=</span><span style="font-family: Consolas; font-size: 12pt;">"<span style="color: blue;">somefolder/download-resource-page.aspx</span>"<span style="color: blue;"> </span><span style="color: red;">allowOverride</span><span style="color: blue;">=</span>"<span style="color: blue;">false</span>"<span style="color: blue;">></span><b><o:p></o:p></b></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 12pt;"> <</span><span style="color: #a31515; font-family: Consolas; font-size: 12pt;">system.web</span><span style="color: blue; font-family: Consolas; font-size: 12pt;">></span><b><span style="font-family: Consolas; font-size: 12pt;"><o:p></o:p></span></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 12pt;"> <</span><span style="color: #a31515; font-family: Consolas; font-size: 12pt;">httpRuntime</span><span style="color: blue; font-family: Consolas; font-size: 12pt;"> </span><span style="color: red; font-family: Consolas; font-size: 12pt;">requestValidationMode</span><span style="color: blue; font-family: Consolas; font-size: 12pt;">=</span><span style="font-family: Consolas; font-size: 12pt;">"<span style="color: blue;">2.0</span>"<span style="color: blue;"> </span><span style="color: red;">executionTimeout</span><span style="color: blue;">=</span>"<span style="color: blue;">3600</span>"<span style="color: blue;"> </span><span style="color: red;">maxRequestLength</span><span style="color: blue;">=</span>"<span style="color: blue;">1048576</span>"<span style="color: blue;"> </span><span style="color: red;">requestPathInvalidCharacters</span><span style="color: blue;">=</span>""<span style="color: blue;"> /></span><b><o:p></o:p></b></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 12pt;"> <</span><span style="color: #a31515; font-family: Consolas; font-size: 12pt;">pages</span><span style="color: blue; font-family: Consolas; font-size: 12pt;"> </span><span style="color: red; font-family: Consolas; font-size: 12pt;">validateRequest</span><span style="color: blue; font-family: Consolas; font-size: 12pt;">=</span><span style="font-family: Consolas; font-size: 12pt;">"<span style="color: blue;">false</span>"<span style="color: blue;"> /></span><b><o:p></o:p></b></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 12pt;"> </<span style="color: #a31515; font-family: Consolas; font-size: 12pt;">system.web</span><span style="color: blue; font-family: Consolas; font-size: 12pt;">></span><b><span style="font-family: Consolas; font-size: 12pt;"><o:p></o:p></span></b></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 12pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 16px;"></</span><span style="color: #a31515; font-family: Consolas; font-size: 12pt;">location</span><span style="color: blue; font-family: Consolas; font-size: 12pt;">></span></div>
<br />
<br />
<br />
This location section should be placed within the <configuration> <configuration></configuration>tags!bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com0tag:blogger.com,1999:blog-30031412.post-28118826874753264692012-02-16T20:33:00.002+00:002012-02-16T20:33:53.101+00:00ASP.NET Entity Framework 4.3 - What's my Id???Whilst working on a simple data access layer using Sql Ce 4, POCO C# and using the Repository Pattern it occurred to me that when implementing a SaveChanges method that there was no real effective way to prevent a subsequent developer coming along and instantiating a new instasnce of some entity, directly setting the Id property and calling SaveChanges! I thought about nesting the entity within the repository and changing access levels on classes and properties but nothing really worked.<br />
<br />
At this point I figured that there are much smarter people out there that have already solved this problem - I'll just have a look and see how they did it (A good view when standing on the shoulders of giants!).<br />
<br />
I fired up visual studio, hit nuget for EF 4.3 updated everything, wrote a very contrived example waited for an exception at which point I'd delve into the code and possibly with a little reflection work out what was going on.<br />
<br />
Sadly that's not what happened. I discovered that if you instantiate an instance of an entity manually populate its Id and call save changes it simply quietly adds it to the db with the next available identity and carries on!<br />
<br />
Although this may well never actually happen in the real world I thought it was interesting none the less.<br />
<br />
If I'm being a complete idiot here please do let me know!<br />
<br />
- Class1.cs<br />
<br />
<pre style="font-family: consolas;"><pre style="font-family: consolas;"><span style="color: blue;">namespace</span> FactoryPatternSandbox.Core
{
<span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">TestContext</span> : <span style="color: #2b91af;">DbContext</span>
{
<span style="color: blue;">public</span> TestContext()
: <span style="color: blue;">base</span>(<span style="color: #a31515;">"name=conn"</span>)
{
}
<span style="color: blue;">public</span> <span style="color: #2b91af;">DbSet</span><<span style="color: #2b91af;">ExampleItem</span>> ExampleItemSet {<span style="color: blue;">get</span>; <span style="color: blue;">set</span>;}
}
<span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">ExampleItem</span>
{
<span style="color: blue;">public</span> <span style="color: blue;">int</span> Id { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }
<span style="color: blue;">public</span> <span style="color: blue;">string</span> Text { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }
}
}</pre>
<pre style="font-family: consolas;">
</pre>
<pre style="font-family: consolas;">Default.aspx</pre>
<pre style="font-family: consolas;"><pre style="font-family: consolas;"> <span style="color: blue;">public</span> <span style="color: blue;">partial</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Default</span> : System.Web.UI.<span style="color: #2b91af;">Page</span>
{
<span style="color: blue;">protected</span> <span style="color: blue;">void</span> Page_Load(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)
{
<span style="color: blue;">using</span> (Core.<span style="color: #2b91af;">TestContext</span> context = <span style="color: blue;">new</span> Core.<span style="color: #2b91af;">TestContext</span>())
{
Core.<span style="color: #2b91af;">ExampleItem</span> example = <span style="color: blue;">new</span> Core.<span style="color: #2b91af;">ExampleItem</span>();
<span style="color: green;">// Set Id to a random hard coded int</span>
example.Id = 1234;
<span style="color: green;">// Set arbitrary text value</span>
example.Text = <span style="color: #2b91af;">DateTime</span>.Now.ToString();
<span style="color: green;">// Add to context with Id 1234</span>
context.ExampleItemSet.Add(example);
<span style="color: green;">// output Id to Literal (Output = 1234)</span>
something.Text = example.Id.ToString();
context.SaveChanges();
<span style="color: green;">// At this point the Id *should* have been added to the DB as 1234</span>
<span style="color: green;">// or thrown an exception e.g. CannotAssignIdToNewEntityException()</span>
<span style="color: green;">// However checking the DB the item has been added with the next</span>
<span style="color: green;">// available Id as per a normal INSERT INTO with an IDENTITY column specification</span>
<span style="color: green;">// But its not actually told us (via an exception) that the Id value</span>
<span style="color: green;">// has indeed changed so when we call for our random hard coded int</span>
<span style="color: green;">// it throws an exception saying there are no items in the collection.</span>
Core.<span style="color: #2b91af;">ExampleItem</span> exampleFromDb = context.ExampleItemSet.Where(l => l.Id == 1234).Single();
}
}
}</pre>
</pre>
</pre>bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com0tag:blogger.com,1999:blog-30031412.post-32281186878714933352012-01-09T11:25:00.002+00:002012-01-09T11:28:37.443+00:00Manage multiple updates to Data using C#, TSQL and OPENXML in SQL ServerI'd like to share this little technique I've been using for quite a while, especially to receive feedback and validation on whether or not this is a good idea!<br />
<br />
I've used this technique with great success in the past in production systems which require a a "grid" of check-boxes and a single "update" button. This kind of thing usually occurs when you have any X can be related to any Y in a many to many kind of relationship. It comes in especially handy when mapping Users to Roles or that kind of thing. Though it can easily be adapted to manage multiple updates of anything in ONE database hit.<br />
<br />
Traditionally this kind of code ends up hitting the database either once per cell in the grid or once per row in the grid because SQL Server doesn't allow arrays of things to be sent to a stored procedure. Database hits are expensive and generally less is better.<br />
<br />
My technique leverage's SQL Servers ability to access XML data using the OPENXML keyword. When the grid of check-boxes is submitted we gather together the form collection elements (those check-boxes that have been ticked) and create an XML snippet of the results. This is then passed to SQL Server as a single input representing a set of information. OPENXML is then used inside the stored procedure to convert the XML into a temporary table which is then interrogated and used to update the relationship information that the check box represents.<br />
<br />
Below is a link to a visual studio 2010 project that you can download , it contains all the source code for the project please feel free to download and try it for yourself - if you find it useful or have an idea of how it could be improved please leave a comment at the bottom of this page.<br />
<br />
I have used MVC 3 and SQL Server as a simple container for the project but the technique is equally valid for any type of project Classic ASP, ASP.NET Web-forms included, so long as the RDBMS supports XML the technique will be valid.<br />
<br />
I will refrain from a long explanation here as the code is simply one model, controller and view and the database contains just three tables and two stored procedures. If you'd like some more detail please leave a comment at the bottom of the page and Ill update as soon as possible. If I get a lot of feedback then I will flesh out the method some more in a series of posts.<br />
<br />
I do hope you find this useful and would love to hear from you!<br />
<br />
Project files can be downloaded <a href="https://docs.google.com/open?id=0B4vV9n5dFl5dOGZiZDUzZWUtMmQ5Yy00MjNmLTgzZDMtZmU3N2IxNTgyNTg3" target="_blank">here </a> and unpacked using <a href="http://www.7zip.org/" target="_blank">7zip</a> <br />
<br />bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com4tag:blogger.com,1999:blog-30031412.post-41987870546727784792012-01-05T14:00:00.002+00:002012-01-05T14:00:44.413+00:00disqus.com for @blogger @blogspot comments - really rather good!Having not made a new years resolution at the time I have decided that it should be "use my blog more often". I'm doing quite well this year so far but to be honest its quite tricky fitting it in "out of hours" what with the twins, learning guitar and Skyrim being released but we can but try!<br />
<br />
This post centres around the ease with which I managed to sign up for and integrate Disqus comments into this very blog. It turns out that to replace the (fairly basic) standard Blogger comments with Disqus is REALLY straightforward. Simply a case of signing up to Disqus pointing it at your blog and clicking the appropriate options.<br />
<br />
Disqus accounts are free (though there are paid for versions) and it adds a social edge and more integrated experience if you're a Blogger or a commenter. I original was looking to integrate LiveFyre but it didn't seem to offer the kind of seamless integration and ease for which I was looking (I may be wrong but Disqus just made it so easy!).<br />
<br />
Anyway if you're looking for "comments on social steroids) I would definitely recommend it if you're serious about building communities around your content!<br />
<br />
<a href="http://disqus.com/">http://disqus.com</a>
<br />
<br />
<a href="http://www.livefyre.com/">http://www.livefyre.com/</a>
<br />
One last word on LiveFyre if you're looking for something a bit different it works just like other comments managers however it also include live chat as a first-class feature which, when you see it, really is quite impressive!bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com0tag:blogger.com,1999:blog-30031412.post-20491828301434495872012-01-04T09:37:00.000+00:002012-01-04T09:37:30.493+00:00Kodak ESP 5250 All-in-One Colour Ink-jet - Printer / copier / scanner<div>Having bought Kodak Camera's for both myself and my mother in law I decided to give the following printer a try when it came time to replace an older Epson model that got damaged in a house move a while ago. I have to say it is astounding for the price. B&W printing is both fast and sharp whilst the colour prints are beautiful even on normal paper! Let alone its excellent Wi-Fi facilities, combine that with its excellent cloud printing software (sadly this model does not support it natively but the software works very well indeed) its an all round winner!</div><div><br /></div><div>Kodak also do iPhone, iPad and Andriod apps for printing directly from your smart devices for free which also "just work" - usually printers (at least for me) are a nightmare but setting all this up was a breeze!</div><div><br /></div><a href="http://www.google.co.uk/products/catalog?hl=en&rlz=&q=KODAK+ESP+5250&gs_upl=1594080l1596799l0l1597026l14l13l0l3l3l0l214l1408l1.8.1l10l0&um=1&ie=UTF-8&tbm=shop&cid=10465158521842322214&sa=X&ei=bhwET5qTFsezhAeTpZH2CQ&ved=0CHcQ8wIwAQ">Kodak ESP 5250 All-in-One Colour Ink-jet - Printer / copier / scanner</a>:<br /><br /><a style="font-size:13px" href="https://chrome.google.com/webstore/detail/pengoopmcjnbflcjbmoeodbmoflcgjlk">'via Blog this'</a>bUKaneerhttp://www.blogger.com/profile/06072329739628545853noreply@blogger.com0