<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Mr Pfisters Random Waffle</title>
	
	<link>http://mrpfister.com</link>
	<description>Notes from the underground</description>
	<lastBuildDate>Thu, 13 Jun 2013 10:17:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/MrPfistersRandomWaffle" /><feedburner:info uri="mrpfistersrandomwaffle" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Apple shows the world its hippy inspired view of the future with Mavericks and iOS7</title>
		<link>http://feedproxy.google.com/~r/MrPfistersRandomWaffle/~3/x_rqvRglS8g/</link>
		<comments>http://mrpfister.com/programming/apple-ios/apple-ios7-mavericks-all-ne/#comments</comments>
		<pubDate>Thu, 13 Jun 2013 10:17:47 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Hippy]]></category>
		<category><![CDATA[iOS7]]></category>
		<category><![CDATA[Johnny Ives]]></category>
		<category><![CDATA[Mavericks]]></category>
		<category><![CDATA[Windows Phone]]></category>

		<guid isPermaLink="false">http://mrpfister.com/?p=1486</guid>
		<description><![CDATA[Its one of the worlds worst kept secrets. Every year at the WWDC; Apples World Wide Developer Conference, they will show off the latest and greatest. Most years they have showed off software releases &#8211; usually updates to iOS and OSX as well as bumps to their notebook range and accessories, so it came as [...]]]></description>
				<content:encoded><![CDATA[<p>Its one of the worlds worst kept secrets. Every year at the WWDC; Apples World Wide Developer Conference, they will show off the latest and greatest. Most years they have showed off software releases &#8211; usually updates to iOS and OSX as well as bumps to their notebook range and accessories, so it came as little surprise for developers turning up for this years keynote.</p>
<p>Before the event, there was hints and leaks about what was too come &#8211; software tags popping up in visitor logs for websites, inform leaks about the look and feel, as well as guesses based on Jonny Ive&#8217;s take over of the &#8216;direction&#8217; of the software visual cues.</p>
<p>A clear challenge that Apple faced was one faced by Microsoft; and mocked by Apple. Put simply, as software matures and more things become dependent on the specific layout, design and expected behaviour of the API set, it becomes harder and harder to move away and design something fresh. Microsoft showed this off badly with Windows 8; merging new components with the tried and tested desktop mentality. The other challenge is on the flip side, in that as software becomes more complex, it takes longer to make new features, thus to meet the expected yearly release target, Apple has to either push out a few small changes or increase the team size &#8211; which can only go so far. Microsoft was known for this in their Office suite of products, where people would complain that there was very little innovation between versions.</p>
<h1>iOS7 &#8211; Designed by hippies</h1>
<p>The older versions of iOS had become increasing bloated and frankly odd by use of pseudomorphism, which is the use of realistic patterns, textures or features in an artificial product. Take the calendar for example; this had a leather binder effect to simulate a desk calendar, or the Podcast app had a virtual record real. These became increasingly exotic and strange, and to some people not intuitive; I doubt many teenagers have actually seen a leather bound desk calender.</p>
<p>iOS7 under Johnny Ives direction has pushed away from this route to go down a more simplistic, flat route.</p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/06/index_hero_keyframe.jpg"><img class="aligncenter size-large wp-image-1487" alt="iOS7_hippy_lockscreen" src="http://mrpfister.com/wp-content/uploads/2013/06/index_hero_keyframe-1024x666.jpg" width="600" height="390" /></a></p>
<p>I&#8217;m all for this, but it was disconcerting hearing the Apple engineers on stage partly mock their own older design patterns.</p>
<p>This look now starts incroaching on Microsofts idealogy with Windows Phone &#8211; simplistic minimalism.</p>
<p><iframe src="http://www.youtube.com/embed/DM8NSSzxNGM" height="360" width="640" allowfullscreen="" frameborder="0"></iframe></p>
<p>Microsoft had always gone down the route of flat design and removing unrequired animations and effects that detract from the user experience. The user should not be slowed down by pseudomorphism of the design. Apple has heeded this, but I do possibly here a lawsuit on the horizon.</p>
<p>The colour scheme of iOS7 seems pretty radical, or the use of transparencies over the top of the colour scheme. This creates a somewhat LSD trip for the end user.</p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/06/index.png"><img class="aligncenter size-full wp-image-1489" alt="index" src="http://mrpfister.com/wp-content/uploads/2013/06/index.png" width="240" height="424" /></a></p>
<p>When Microsoft Vista came out and touted its Aero &#8216;Glass&#8217; interface, with the extensive use of transparencies to see whats underneath a window, people complained about the unneccessary use of resource and lack of design clarity &#8211; much heralded by Apple. A few years down the line and Apple is doing almost exactly the same.</p>
<p>In terms of features, there actually wasn&#8217;t that many, this release was mainly a reskin, but for developers there is hope:<br />
<strong>Apple Maps</strong> &#8211; iOS 7 will let developers include additional mapping features in apps, including 3D viewing experiences, direction related route information and map-based images.</p>
<p><strong>iBeacons</strong> &#8211; Designed to use the Bluetooth Low Energy profile for microlocation, allowing iOS devices to use Bluetooth 4.0 devices to access location data.</p>
<p><strong>AirDrop from Activity Sheet</strong> &#8211; Apps will be able to incorporate AirDrop support, giving users the ability to share photos, documents and more with friends from within an app.</p>
<p><strong>MFi Game Controllers</strong> &#8211; iOS 7 includes support for MFi &#8220;Made for iPhone&#8221; Apple Certified hardware game controllers, which will allow manufacturers to create dedicated iOS gaming controllers, turning the iPhone and the iPad into gaming machines on par with handheld gaming systems. Apps will be able to be designed around the Game Controller framework, allowing for seamless connectivity. Apple&#8217;s <a href="https://developer.apple.com/library/prerelease/ios/documentation/ServicesDiscovery/Conceptual/GameControllerPG/Introduction/Introduction.html">developer library</a> detailing a reference design of both a standalone controller and an iPhone enclosure.</p>
<p><img alt="mifcontrollers" src="http://cdn.macrumors.com/article-new/2013/06/mifcontrollers.jpg" width="800" height="412" data-lazy-loaded="true" /><br />
<strong>Sprite Kit</strong> &#8211; The Sprite Kit framework is designed to allow developers to create high-performing 2D games, controlling sprite attributes like position, size, rotation, gravity, and mass. It includes built-in support for physics to make animations look realistic and it also includes particle systems for additional game effects.</p>
<p><strong>Game Center</strong> &#8211; iOS 7 adds new turn-based gaming modes (including simultaneous turns, chats, and trades) along with new methods for player authentication and secure game score transmission. This feature is likely designed to cut down on hacked Game Center scores from jailbroken devices.</p>
<p><strong>Multitasking and Background Downloads</strong> &#8211; Apple&#8217;s new multitasking APIs are designed to allow apps to update and download content in the background at intelligently scheduled times. For example, a Twitter app might incorporate this functionality, downloading new content in the background while the phone is not otherwise in use, staying up to date without unnecessarily draining battery. Push notifications can also initiate content downloads.</p>
<p><strong>Inter-App Audio</strong> &#8211; With Inter-App Audio, apps are able to share audio streams with other apps, an API that will make it even easier to use Apple&#8217;s iDevices to create music.</p>
<p><strong>60-fps Video Capture</strong> &#8211; iOS 7 will allow apps to capture video at up to 60 frames per second.</p>
<p><strong>Peer-to-Peer Connectivity</strong> &#8211; This data transmission API is designed to allow users to discover nearby devices and initiate direct communication without Internet connectivity.</p>
<h1>Mavericks</h1>
<p>When Microsoft Vista launched, everyone complained saying it felt half complete, which was partly true due to the restart in 2003-2004 after the failings of Longhorn. Vista had a lot of new features, some were really great; Shadow Copy, Display Window Manager, WDDM, but most seemed half implemented, or just there without real reason or just forgotten about e.g. Cardspace, Windows Extras.</p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/06/Osx-mavericks-screenshot.jpg"><img class="aligncenter size-full wp-image-1488" alt="Osx-mavericks-screenshot" src="http://mrpfister.com/wp-content/uploads/2013/06/Osx-mavericks-screenshot.jpg" width="602" height="377" /></a></p>
<p>OSX Mountain Lion although meant to be an entirely new OS, felt little more than a paid for service pack to OSX Lion. It had some new iOS inspired features but seemed rushed out the door and not thouroughly tested. OSX Mavericks seems to be the Windows 7 to Windows Vista, it appears Apple has heard the complaints, and made relevant adjustments.</p>
<p>For example:</p>
<p>Full screen apps under Mountain Lion would take up one full screen (all well so far) but then all other screens would be unusable &#8211; who the hell thought this would be a good idea??</p>
<p>Safari has been based on Webkit, however Google for many years has been the primarily contributer to the source tree. Google has now forked Webkit to Blink due to the architectural flaws of Webkit. Apple is now left to pick up the pieces and attempt to maintain track with the other browsers without Googles extensive input.</p>
<h1>Apple is finally maturing</h1>
<p>I have mentioned before that Apple seems to be entering its mid-life crisis point. Almost all of its products are mature, and people no longer want the unexpected. Apple is therefore being pushed down the route of doing minor incremental updates to its products.</p>
<p>Security was one of the terms that wasn&#8217;t really mentioned much this year, this is where again I see Apple being hurt in a big way. Microsoft has had years of &#8216;training by fire&#8217; with its OS to keep it secure for enterprises. Apple is only now having to do the same with OSX. Gone are the days when they could simply say &#8216;OSX doesnt get viruses&#8217;</p>
<p>So what can Apple do? Make new products &#8211; if you can&#8217;t alter your existing cash cows (iPhone, OSX), enter new markets (TV, Watches, In-Car systems etc.)</p>
<!-- Start Shareaholic Recommendations Automatic --><!-- End Shareaholic Recommendations Automatic --><img src="http://feeds.feedburner.com/~r/MrPfistersRandomWaffle/~4/x_rqvRglS8g" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://mrpfister.com/programming/apple-ios/apple-ios7-mavericks-all-ne/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mrpfister.com/programming/apple-ios/apple-ios7-mavericks-all-ne/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=apple-ios7-mavericks-all-ne</feedburner:origLink></item>
		<item>
		<title>Subclassing .Net Compact Framework Controls</title>
		<link>http://feedproxy.google.com/~r/MrPfistersRandomWaffle/~3/ZbxRmpMK5sE/</link>
		<comments>http://mrpfister.com/programming/subclassing-net-compact-framework-controls/#comments</comments>
		<pubDate>Wed, 15 May 2013 12:51:30 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[.Net Compact Framework]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NetCF]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Compact Framework]]></category>
		<category><![CDATA[DoEvents]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Handle]]></category>
		<category><![CDATA[Subclassing]]></category>
		<category><![CDATA[WM_PAINT]]></category>
		<category><![CDATA[WndProc]]></category>

		<guid isPermaLink="false">http://mrpfister.com/?p=1463</guid>
		<description><![CDATA[To aid development of rich interactive applications, and reduce the amount of time spent on handling OS specific interactions. .Net applications hide a lot of the underlying message passing that occurs between an application and the OS. This obfuscation is done either at a control or CLR level and usually is perfectly reasonable. However when [...]]]></description>
				<content:encoded><![CDATA[<p>To aid development of rich interactive applications, and reduce the amount of time spent on handling OS specific interactions. .Net applications hide a lot of the underlying message passing that occurs between an application and the OS. This obfuscation is done either at a control or CLR level and usually is perfectly reasonable.</p>
<p>However when implementing custom controls, interacting with Native COM objects (IE Tiling Engine, Webkit), or requiring fine grain control you will most likely need to start tinkering&#8230;</p>
<p>By default all applications start off as Single Threaded. Computation is performed on this thread, hopefully using the event methodology. What .Net developers may not realise that on that thread also sits the WndProc (Message Queue).</p>
<p><strong>MSDN Extract: </strong></p>
<p style="padding-left: 30px;">&#8220;The system can display any number of windows at a time. To route mouse and keyboard input to the appropriate window, the system uses message queues.</p>
<p style="padding-left: 30px;">The system maintains a single system message queue and one thread-specific message queue for each GUI thread. To avoid the overhead of creating a message queue for non–GUI threads, all threads are created initially without a message queue. The system creates a thread-specific message queue only when the thread makes its first call to one of the specific user functions; no GUI function calls result in the creation of a message queue.&#8221;</p>
<p style="padding-left: 30px;"><strong>In English:</strong> The OS sends messages to GUI threads, some have to be immediately processed, others can be stored till the GUI thread becomes available.</p>
<h2><strong>WndProc</strong></h2>
<p>GUI developers in C / C++ are usually more familar with the <a href="http://msdn.microsoft.com/en-us/library/ms633573.aspx">WindowProc</a>. It is a method that intercepts messages being sent from the OS, it handles functionality such as paint requests, mouse movement, requests to exit etc. and it becomes the applications responsibly to implement these. This gave rise to wrappers in C / C++ to abstract these into events to reduce the boiler-plate code needed to be written for every application.</p>
<p>C# went even further and fully hid the WndProc method from the developer by default. All system messages are internally intercepted, some require immediate processing or are disgarded, othersare added to the &#8216;Message Queue&#8217;, when the program is idle, the Message Queue is &#8216;pumped&#8217; and all outstanding actions are processed. This gives rise to developers from the VB days as well noticing during long running processes the UI would not update or would become unresponsive. This is down to the Message Queue not been given time to pump its outstanding messages (usually paint events). Windows can use the outstanding messages on the Message Queue, and the response time to a request as an indicator as to whether an application has stopped responding.</p>
<p>When in a long running procedure, developers usually go down two routes:</p>
<ul>
<li>Split off the long running task into a new thread, thus leaving the GUI (Message Queue) thread idle to perform required actions.</li>
<li>Insert <strong>Application.DoEvents()</strong> into the task where appropriate. This halts the current process and pumps all actions in the message queue. This is a cheap hack but most still use it.</li>
</ul>
<p style="padding-left: 30px;"><strong>Do:</strong> Split long running tasks into a seperate thread. Use the ThreadPool for small repeatitive tasks.</p>
<p style="padding-left: 30px;"><strong>Don&#8217;t:</strong> Keep the main GUI thread busy. If using the MVC methodology you should only be using the GUI thread to update controls, not perform processing.</p>
<h2><strong>Full .Net WndProc support</strong></h2>
<p>In what has become the norm, support in the full .Net framework is far beyond that in the Compact Framework and is ever increasing.</p>
<p>The full .Net environment allows direct access to WndProc by overriding the internal functionality (<a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.wndproc(v=vs.90).aspx">Control.WndProc</a>)<br />
Below is an example of how to override the internal WndProc method and perform intermediate actions before falling through to the base implementation. The WM_ACTIVATEAPP operating system message is handled in this example to know when another application is becoming active</p>
<pre class="brush: csharp; title: ; notranslate">
using System;
using System.Drawing;
using System.Windows.Forms;

namespace csTempWindowsApplication1
{
    public class Form1 : System.Windows.Forms.Form
    {
        // Constant value was found in the &quot;windows.h&quot; header file.
        private const int WM_ACTIVATEAPP = 0x001C;
        private bool appActive = true;

        [STAThread]
        static void Main()
        {
            Application.Run(new Form1());
        }

        public Form1()
        {
            this.Size = new System.Drawing.Size(300,300);
            this.Text = &quot;Form1&quot;;
            this.Font = new System.Drawing.Font(&quot;Microsoft Sans Serif&quot;, 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            // Paint a string in different styles depending on whether the
            // application is active.
            if (appActive)
            {
                e.Graphics.FillRectangle(SystemBrushes.ActiveCaption,20,20,260,50);
                e.Graphics.DrawString(&quot;Application is active&quot;, this.Font, SystemBrushes.ActiveCaptionText, 20,20);
            }
            else
            {
                e.Graphics.FillRectangle(SystemBrushes.InactiveCaption,20,20,260,50);
                e.Graphics.DrawString(&quot;Application is Inactive&quot;, this.Font, SystemBrushes.ActiveCaptionText, 20,20);
            }
        }

	[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name=&quot;FullTrust&quot;)]
        protected override void WndProc(ref Message m)
        {
            // Listen for operating system messages.
            switch (m.Msg)
            {
                // The WM_ACTIVATEAPP message occurs when the application
                // becomes the active application or becomes inactive.
                case WM_ACTIVATEAPP:

                    // The WParam value identifies what is occurring.
                    appActive = (((int)m.WParam != 0));

                    // Invalidate to get new text painted.
                    this.Invalidate();

                    break;
            }
            base.WndProc(ref m);
        }
    }
}
</pre>
<p style="padding-left: 30px;"><strong>Note:</strong> You still need to call base.WndProc(&#8230;) otherwise all the messages you do not process will not be processed, thus your application may become unresponsive.</p>
<p>The values for m.Msg as used in the example can be found online in the Windows.h header file. An outline can be found <a href="http://msdn.microsoft.com/en-us/library/ms644927.aspx#system_defined">here</a> &#8211; though WndProc only intercepts the messages pre-fixed with WM_.</p>
<p>The one that is usually important is the <a href="http://msdn.microsoft.com/en-us/library/dd145213.aspx">WM_PAINT</a> event, which occurs when the control is invalidated by the system and windows requests a repaint. This is somewhat different to internal invalidation where the user triggers it. In older (XP and earlier) painting was done in a one phase approach rather than having backing buffers for each windows via the Desktop Windowing Manager, thus if a control moved, all affected windows would have WM_PAINT called.</p>
<h2><strong>Accessing WndProc in the Compact Framework</strong></h2>
<p>The Compact Framework does not provide easy access to &#8216;protected override void WndProc(ref Message m)&#8217; like the full .Net and so from the offset we have a problem, how do we access it?</p>
<p>Like most good things in the Compact Framework, they aren&#8217;t actually in there, but have to be accessed via P-Invoking into the Native system DLLs. Accessing WndProc is no exception. Newer versions of the .Net Compact Framework have improved matters, but still are annoying.</p>
<p><a href="http://blogs.msdn.com/b/priozersk/">Alex Yakhnin</a> who worked at Microsoft and on the Open Source (at the time) OpenNetCF project gives helpful insights.</p>
<p>On a side note, interoping between Managed and unmanaged code in the Compact Framework has always been a nightmare, especially version 1 where:</p>
<ul>
<li>It didn&#8217;t expose the native handle of a window, so Subclassing was never going to be possible. Nor was it easy (possible but extremely difficult) to perform direct native operations on managed controls.</li>
<li>There was no way of native methods to call back to the managed world via delegates. Most calls were effectively &#8216;fire-and-forget&#8217; from the managed side.</li>
</ul>
<p>This was mainly in part because the COM Callable Wrapper (CCW) part of the CLR in the Compact Framework is tiny in comparison to the full .Net version. The CCW handles the &#8216;glue&#8217; between managed and native functions, and performs marshalling and refactoring of data structures between the two.</p>
<p style="padding-left: 30px;"><strong>Interesting Sidenote:</strong> Due to the limitations of the Compact Framework CCW, Marshalling complex data structures is not possible without major re-working. This is because the CCW will only marshall blittable types (1 to 1 byte mappings). Managed types like strings are not blittable when in a structure. This means there may be native functions you can not P-Invoke to from managed code, and may require an intermediate native function.</p>
<p>The .Net V2 approach was to create a static WindowProc for all registered controls in an application. This has the advantage of not requiring additional code reuse, and also would be the global approach if the application is single threaded &#8211; the singular GUI thread would have a singular shared WindowProc for all subcontrols. Subcontrols can then individually register new message sinks for particular events. I&#8217;ve extended Alex&#8217;s implementation, and corrected formatting so its consistent with C# (you could tell he was a C/C++ dev originally).</p>
<p>A summary of how it works:</p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/05/WndProc.png"><img class="aligncenter size-full wp-image-1470" alt="WndProc" src="http://mrpfister.com/wp-content/uploads/2013/05/WndProc.png" width="505" height="303" /></a></p>
<p>Firstly you will need a class to house all the P-Invoke methods down to <strong>coredll.dll</strong> on the desktop you would be interacting with <strong>user32.dll</strong> instead.</p>
<pre class="brush: csharp; title: ; notranslate">
using System;
using System.Drawing;
using System.Runtime.InteropServices;

///
/// Contains managed wrappers or implementations of Win32 structs, delegates,
/// constants and PInvokes that are useful for this sample.
///
/// See the documentation on MSDN for more information on the elements provided
/// in this file.
///
public sealed class Win32
{
    public const int GWL_WNDPROC = -4;

    ///
/// A callback to a Win32 window procedure (wndproc)
    ///
    ///The handle of the window receiving a message
    ///The message
    ///The message's parameters (part 1)
    ///The message's parameters (part 2)
    /// A integer as described for the given message in MSDN
    public delegate int WndProc(IntPtr hwnd, uint msg, uint wParam, int lParam);

    [DllImport(&quot;coredll.dll&quot;)]
    public extern static int DefWindowProc(
        IntPtr hwnd, uint msg, uint wParam, int lParam);

    [DllImport(&quot;coredll.dll&quot;)]
    public extern static IntPtr SetWindowLong(
        IntPtr hwnd, int nIndex, IntPtr dwNewLong);

    [DllImport(&quot;coredll.dll&quot;)]
    public extern static int CallWindowProc(
        IntPtr lpPrevWndFunc, IntPtr hwnd, uint msg, uint wParam, int lParam);
}
</pre>
<p>Notice the exposed <strong>WndProc</strong> delegate. This is called from the native methods when a message is triggered.</p>
<pre class="brush: csharp; title: ; notranslate">
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace SubclassSample
{
    class WndProcHooker
    {
        ///
/// The callback used when a hooked window's message map contains the
        /// hooked message
        ///
        ///The handle to the window for which the message
        /// was received
        ///The message's parameters (part 1)
        ///The message's parameters (part 2)
        ///The invoked function sets this to true if it
        /// handled the message. If the value is false when the callback
        /// returns, the next window procedure in the wndproc chain is
        /// called
        /// A value specified for the given message in the MSDN
        /// documentation
        public delegate int WndProcCallback(
            IntPtr hwnd, uint msg, uint wParam, int lParam, ref bool handled);

        ///
/// This is the global list of all the window procedures we have
        /// hooked. The key is an hwnd. The value is a HookedProcInformation
        /// object which contains a pointer to the old wndproc and a map of
        /// messages/callbacks for the window specified. Controls whose handles
        /// have been created go into this dictionary.
        ///
        private static Dictionary&lt;IntPtr, HookedProcInformation&gt; hwndDict =
            new Dictionary&lt;IntPtr, HookedProcInformation&gt;();

        ///
/// See hwndDict. The key is a control and the value is a
        /// HookedProcInformation. Controls whose handles have not been created
        /// go into this dictionary. When the HandleCreated event for the
        /// control is fired the control is moved into hwndDict.
        ///
        private static Dictionary&lt;Control, HookedProcInformation&gt; ctlDict =
            new Dictionary&lt;Control, HookedProcInformation&gt;();

        ///
/// Makes a connection between a message on a specified window handle
        /// and the callback to be called when that message is received. If the
        /// window was not previously hooked it is added to the global list of
        /// all the window procedures hooked.
        ///
        ///The control whose wndproc we are hooking
        ///The method to call when the specified
        /// message is received for the specified window
        ///The message we are hooking.
        public static void HookWndProc(
            Control ctl, WndProcCallback callback, uint msg)
        {
            HookedProcInformation hpi = null;
            if (ctlDict.ContainsKey(ctl))
            {
                hpi = ctlDict[ctl];
            }
            else if (hwndDict.ContainsKey(ctl.Handle))
            {
                hpi = hwndDict[ctl.Handle];
            }

            if (hpi == null)
            {
                // We havne't seen this control before. Create a new
                // HookedProcInformation for it
                hpi = new HookedProcInformation(ctl,
                    new Win32.WndProc(WndProcHooker.WindowProc));
                ctl.HandleCreated += new EventHandler(ctl_HandleCreated);
                ctl.HandleDestroyed += new EventHandler(ctl_HandleDestroyed);
                ctl.Disposed += new EventHandler(ctl_Disposed);

                // If the handle has already been created set the hook. If it
                // hasn't been created yet, the hook will get set in the
                // ctl_HandleCreated event handler
                if (ctl.Handle != IntPtr.Zero)
                {
                    hpi.SetHook();
                }
            }

            // stick hpi into the correct dictionary
            if (ctl.Handle == IntPtr.Zero)
            {
                ctlDict[ctl] = hpi;
            }
            else
            {
                hwndDict[ctl.Handle] = hpi;
            }

            // add the message/callback into the message map
            hpi.messageMap[msg] = callback;
        }

        ///
/// The event handler called when a control is disposed.
        ///
        ///The object that raised this event
        ///The arguments for this event
        static void ctl_Disposed(object sender, EventArgs e)
        {
            Control ctl = sender as Control;
            if (ctlDict.ContainsKey(ctl))
            {
                ctlDict.Remove(ctl);
            }
            else
            {
                System.Diagnostics.Debug.Assert(false);
            }
        }

        ///
/// The event handler called when a control's handle is destroyed.
        /// We remove the HookedProcInformation from hwndDict and
        /// put it back into ctlDict in case the control get re-
        /// created and we still want to hook its messages.
        ///
        ///The object that raised this event
        ///The arguments for this event
        static void ctl_HandleDestroyed(object sender, EventArgs e)
        {
            // When the handle for a control is destroyed, we want to
            // unhook its wndproc and update our lists
            Control ctl = sender as Control;
            if (hwndDict.ContainsKey(ctl.Handle))
            {
                HookedProcInformation hpi = hwndDict[ctl.Handle];
                UnhookWndProc(ctl, false);
            }
            else
            {
                System.Diagnostics.Debug.Assert(false);
            }
        }

        ///
/// The event handler called when a control's handle is created. We
        /// call SetHook() on the associated HookedProcInformation object and
        /// move it from ctlDict to hwndDict.
        ///
        ///
        ///
        static void ctl_HandleCreated(object sender, EventArgs e)
        {
            Control ctl = sender as Control;
            if (ctlDict.ContainsKey(ctl))
            {
                HookedProcInformation hpi = ctlDict[ctl];
                hwndDict[ctl.Handle] = hpi;
                ctlDict.Remove(ctl);
                hpi.SetHook();
            }
            else
            {
                System.Diagnostics.Debug.Assert(false);
            }
        }

        ///
/// This is a generic wndproc. It is the callback for all hooked
        /// windows. If we get into this function, we look up the hwnd in the
        /// global list of all hooked windows to get its message map. If the
        /// message received is present in the message map, its callback is
        /// invoked with the parameters listed here.
        ///
        ///The handle to the window that received the
        /// message
        ///The message
        ///The message's parameters (part 1)
        ///The messages's parameters (part 2)
        /// If the callback handled the message, the callback's return
        /// value is returned form this function. If the callback didn't handle
        /// the message, the message is forwarded on to the previous wndproc.
        ///
        private static int WindowProc(
            IntPtr hwnd, uint msg, uint wParam, int lParam)
        {
            if (hwndDict.ContainsKey(hwnd))
            {
                HookedProcInformation hpi = hwndDict[hwnd];
                if (hpi.messageMap.ContainsKey(msg))
                {
                    WndProcCallback callback = hpi.messageMap[msg];
                    bool handled = false;
                    int retval = callback(hwnd, msg, wParam, lParam, ref handled);
                    if (handled)
                        return retval;
                }

                // if we didn't hook the message passed or we did, but the
                // callback didn't set the handled property to true, call
                // the original window procedure
                return hpi.CallOldWindowProc(hwnd, msg, wParam, lParam);
            }

            System.Diagnostics.Debug.Assert(
                false, &quot;WindowProc called for hwnd we don't know about&quot;);
            return Win32.DefWindowProc(hwnd, msg, wParam, lParam);
        }

        ///
/// This method removes the specified message from the message map for
        /// the specified hwnd.
        ///
        ///The control whose message we are unhooking
        ///
        ///The message no longer want to hook
        public static void UnhookWndProc(Control ctl, uint msg)
        {
            // look for the HookedProcInformation in the control and hwnd
            // dictionaries
            HookedProcInformation hpi = null;
            if (ctlDict.ContainsKey(ctl))
            {
                hpi = ctlDict[ctl];
            }
            else if (hwndDict.ContainsKey(ctl.Handle))
            {
                hpi = hwndDict[ctl.Handle];
            }

            // if we couldn't find a HookedProcInformation, throw
            if (hpi == null)
            {
                throw new ArgumentException(&quot;No hook exists for this control&quot;);
            }

            // look for the message we are removing in the messageMap
            if (hpi.messageMap.ContainsKey(msg))
            {
                hpi.messageMap.Remove(msg);
            }
            else
            {
                // if we couldn't find the message, throw
                throw new ArgumentException(
                    string.Format(
                        &quot;No hook exists for message ({0}) on this control&quot;,
                         msg));
            }
        }

        ///
/// Restores the previous wndproc for the specified window.
        ///
        ///The control whose wndproc we no longer want to
        /// hook
        ///if true we remove don't readd the
        /// HookedProcInformation
        /// back into ctlDict
        public static void UnhookWndProc(Control ctl, bool disposing)
        {
            HookedProcInformation hpi = null;
            if (ctlDict.ContainsKey(ctl))
            {
                hpi = ctlDict[ctl];
            }
            else if (hwndDict.ContainsKey(ctl.Handle))
            {
                hpi = hwndDict[ctl.Handle];
            }

            if (hpi == null)
            {
                throw new ArgumentException(&quot;No hook exists for this control&quot;);
            }

            // If we found our HookedProcInformation in ctlDict and we are
            // disposing remove it from ctlDict
            if (ctlDict.ContainsKey(ctl) &amp;&amp; disposing)
            {
                ctlDict.Remove(ctl);
            }

            // If we found our HookedProcInformation in hwndDict, remove it
            // and if we are not disposing stick it in ctlDict
            if (hwndDict.ContainsKey(ctl.Handle))
            {
                hpi.Unhook();
                hwndDict.Remove(ctl.Handle);
                if (!disposing)
                {
                    ctlDict[ctl] = hpi;
                }
            }
        }

        ///
/// This class remembers the old window procedure for the specified
        /// window handle and also provides the message map for the messages
        /// hooked on that window.
        ///
        class HookedProcInformation
        {
            ///
/// The message map for the window
            ///
            public Dictionary&lt;uint, WndProcCallback&gt; messageMap;

            ///
/// The old window procedure for the window
            ///
            private IntPtr oldWndProc;

            ///
/// The delegate that gets called in place of this window's
            /// wndproc.
            ///
            private Win32.WndProc newWndProc;

            ///
/// Control whose wndproc we are hooking
            ///
            private Control control;

            ///
/// Constructs a new HookedProcInformation object
            ///
            ///The handle to the window being hooked
            ///The window procedure to replace the
            /// original one for the control
            public HookedProcInformation(Control ctl, Win32.WndProc wndproc)
            {
                control = ctl;
                newWndProc = wndproc;
                messageMap = new Dictionary&lt;uint, WndProcCallback&gt;();
            }

            ///
/// Replaces the windows procedure for control with the
            /// one specified in the constructor.
            ///
            public void SetHook()
            {
                IntPtr hwnd = control.Handle;
                if (hwnd == IntPtr.Zero)
                {
                    throw new InvalidOperationException(
                        &quot;Handle for control has not been created&quot;);
                }

                oldWndProc = Win32.SetWindowLong(hwnd, Win32.GWL_WNDPROC,
                    Marshal.GetFunctionPointerForDelegate(newWndProc));
            }

            ///
/// Restores the original window procedure for the control.
            ///
            public void Unhook()
            {
                IntPtr hwnd = control.Handle;
                if (hwnd == IntPtr.Zero)
                {
                    throw new InvalidOperationException(
                        &quot;Handle for control has not been created&quot;);
                }

                Win32.SetWindowLong(hwnd, Win32.GWL_WNDPROC, oldWndProc);
            }

            ///
/// Calls the original window procedure of the control with the
            /// arguments provided.
            ///
            ///The handle of the window that received the
            /// message
            ///The message
            ///The message's arguments (part 1)
            ///The message's arguments (part 2)
            /// The value returned by the control's original wndproc
            ///
            public int CallOldWindowProc(
                    IntPtr hwnd, uint msg, uint wParam, int lParam)
            {
                return Win32.CallWindowProc(
                    oldWndProc, hwnd, msg, wParam, lParam);
            }
        }
    }
}
</pre>
<p>There are two classes, a static Window Procedure handler, which contains the exposed message loop and methods to hook up new controls, as well as another class to store intermediate information.</p>
<p>HookedProcInformation is then created per Control, passed into the constructor is the controls native handle and a WindowProc callback. Exposed via a public property is a mapping for hooked messages to be processed, those that aren&#8217;t are passed back to the default message handler.</p>
<p>Now you just need to wire up your control, if you are writing your own control from scratch then thats great, but if you are wanting to hook up an existing control, then all you need to do is extend the existing control class by using it as a base. This should work with most build in controls as they do not implement the &#8216;sealed&#8217; attribute.</p>
<p>For example extending a TreeView would be done via:</p>
<pre class="brush: csharp; title: ; notranslate">
public partial class SubClassedTreeView : TreeView
</pre>
<p>Now you need to wire everything up, this all occurs in the Overridden OnParentChanged Event which informs a control when its parent has been instantiated or changed.</p>
<pre class="brush: csharp; title: ; notranslate">
///
/// The original parent of this control.
///
private Control prevParent = null;

protected override void OnParentChanged(EventArgs e)
{
    // unhook the old parent
    if (this.prevParent != null)
    {
        WndProcHooker.UnhookWndProc(prevParent, Win32.WM_NOTIFY);
    }
    // update the previous parent
    prevParent = this.Parent;

    // hook up the new parent
    if (this.Parent != null)
    {
        WndProcHooker.HookWndProc(this.Parent,
            new WndProcHooker.WndProcCallback(this.WM_Notify_Handler),
            Win32.WM_NOTIFY);
    }

    base.OnParentChanged(e);
}
</pre>
<p>The above code sample hooks onto the WM_NOTIFY event but you could easily change it to hook onto the WM_PAINT event by adjusting the HookWndProc and UnHookWndProc events:</p>
<pre class="brush: csharp; title: ; notranslate">
WndProcHooker.HookWndProc(this.Parent,
            new WndProcHooker.WndProcCallback(this.WM_Paint_Handler),
            Win32.WM_PAINT);
</pre>
<p style="padding-left: 30px;"><strong>Do:</strong> Make sure you have correct references to the Native WM_&#8230; Event Uint value.<br />
<strong>Do:</strong> Make sure you unhook all your hooked events and vice versa, otherwise you may raise COM exceptions.</p>
<p>The example callback handler methods look like the following, and can be extended to do whatever you require.</p>
<pre class="brush: csharp; title: ; notranslate">
private int WM_Notify_Handler(
            IntPtr hwnd, uint msg, uint wParam, int lParam,
            ref bool handled)
{
    return 0;
}
</pre>
<p>The Marshaller can perform a conversion of wParam and lParam values where some inbound messages hold additional structure information.</p>
<p>There are limitations with the above approach, mainly if there are more than one control on a parent window. This can sometimes cause the WindowProc controller to constantly shift between instances.</p>
<p>Eventually .Net 3.5 Compact Framework came and offered a little bit more support. Mainly in the form of additional extension to controls via factory objects. Instead of calling the WndProc hooking functions manually this can be done for us in a control extension. Alex goes on to suggest an implementation in one of his newer <a href="http://blogs.msdn.com/b/priozersk/archive/2008/11/30/message-control-implementation.aspx">blog posts</a>.</p>
<p style="padding-left: 30px;"><strong>Summary:</strong> Subclassing controls to access the WndProc in .Net Compact Framework is diffuclt, but isn&#8217;t impossible. The primary rule of P-Invoking is not to use it, minimise it where possible. If you can shift as much across to either side of the P-Invoke divide then thats great. Think about even re-writing your control to not need the WndProc, or push more code onto the native side as that can much easier interact with WndProc.</p>
<!-- Start Shareaholic Recommendations Automatic --><!-- End Shareaholic Recommendations Automatic --><img src="http://feeds.feedburner.com/~r/MrPfistersRandomWaffle/~4/ZbxRmpMK5sE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://mrpfister.com/programming/subclassing-net-compact-framework-controls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mrpfister.com/programming/subclassing-net-compact-framework-controls/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=subclassing-net-compact-framework-controls</feedburner:origLink></item>
		<item>
		<title>Improving WPF Rendering Performance</title>
		<link>http://feedproxy.google.com/~r/MrPfistersRandomWaffle/~3/G5YoaNQfv3A/</link>
		<comments>http://mrpfister.com/journal/improving-wpf-rendering-performance/#comments</comments>
		<pubDate>Fri, 03 May 2013 16:17:44 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Journal]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[BCL]]></category>
		<category><![CDATA[BitmapCache]]></category>
		<category><![CDATA[DesiredFrameRateProperty]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Threads]]></category>
		<category><![CDATA[Visual Tree]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://mrpfister.com/?p=1435</guid>
		<description><![CDATA[I have posted quite a few times previously covering WPF, its quirks and workarounds as well as ways to improve its overall perceived performance to end users. In this article I will summarise them all, add in lots more tips and tricks and tell you some big gotchas. Versioning WPF and Windows have come a [...]]]></description>
				<content:encoded><![CDATA[<p>I have posted quite a few times previously covering WPF, its quirks and workarounds as well as ways to improve its overall perceived performance to end users. In this article I will summarise them all, add in lots more tips and tricks and tell you some big gotchas.</p>
<p><strong>Versioning</strong></p>
<p>WPF and Windows have come a long way since the initial &#8216;Avalon&#8217; concept was internally thrown around at Microsoft. Making sure you are targeting the latest .Net version can help a great deal, not just in terms of optimising the WPF components, but being able to more efficiently code your app.</p>
<p>The rendering pipeline under the hood of WPF is all DirectX where possible, with fewer and fewer things falling back to a software rendering layer. Because of this the performance of WPF is tied to the rendering pipeline of the installed version of Windows.</p>
<p>If you run a WPF application in XP, Vista and then Windows 7 you will notice a steady performance boost through each version. Vista started the concept of a unified Desktop Windowing Manager (DWM) however it was only finalised in Windows 7. Vista still had some of the rendering pipeline being done via the system and not GPU memory and stored redundant graphical surfaces slowing down overall performance. XP was just composited using an older version of DirectX.</p>
<p style="padding-left: 30px;"><strong>Do:</strong> Make sure you are writing your application against the current .Net and WPF version.</p>
<p style="padding-left: 30px;"><strong>Do:</strong> Test your app across different versions of Windows to judge performance</p>
<p><strong>.Net Source Code</strong></p>
<p>This is one of the unsung amazing Microsoft actions that not many people know about which I give them credit for.</p>
<p>Microsoft releases the vast majority of the source code to the C# Base Class Library (BCL) and some of the components of .Net sitting on top. If you have a bug that just points of mscorlib, you can download the source and debug symbols and step inside the .Net source.</p>
<p>You can pick up the latest source from here:</p>
<p style="padding-left: 30px;"><a title="Source Code for .Net" href="http://referencesource.microsoft.com/netframework.aspx" target="_blank">.Net Source Code</a></p>
<p>You will want the NET source code for the current version of installed .Net (4.5) near the bottom of the download list.</p>
<p>Why is this important for WPF, well Microsoft kindly includes the source code for a vast majority of the WPF components, controls and namespaces. So recently when I had a problem with MediaPlayer I just looked at the source code:</p>
<p style="padding-left: 30px;">\RefSrc\Source\.NET 4.5\4.5.50709.0\net\wpf\src\Core\CSharp\System\Windows\Media\MediaPlayer.cs\550320</p>
<p style="padding-left: 30px;"><strong>Do:</strong> Just browsing through the code is a great way to learn how to layout source, build controls and to understand how they work.</p>
<p><strong>Understand the WPF thread model</strong></p>
<p>When you build most WinForms applications, everything is run in a single thread. Which becomes apparent if you perform a blocking operation; the UI becomes frozen.</p>
<p>WPF split the threading model in two, where there is an animation clocking thread and the UI thread.</p>
<p>The animation thread is clocked to poll at around 60FPS where possible, and triggers animation clock events at these intervals which call into the UI rendering thread, where the majority of user code lives.</p>
<p>Doing it this way means the clocks and animations can live in a separate low priority thread and not block where possible.</p>
<p>The downside to this is there is still the problem where user code in the UI thread can delay render calls by the animation thread; thus leading to the common performance symptom of stuttering or slow animations.</p>
<p style="padding-left: 30px;"><strong>Don&#8217;t:</strong> Put long running code in UI thread.</p>
<p style="padding-left: 30px;"><strong>Do:</strong> Any CPU bound operation should be pushed out to a BackgroundWorker, ThreadPool operation or a separate application thread.</p>
<p><strong>WPF Animation Framerate</strong></p>
<p>The WPF animation thread clock has been designed by default to run at 60FPS, this means that the render loop can run hot while nothing much is on screen by calls to invalidate if your components aren&#8217;t designed correctly. If you are porting from Flash especially (where framerates are usually set at 30 anyway) it may be a good idea to adjust this value. The improvement is best seen during heavy animation sequences where the animation thread only has to invoke onto the UI thread half as much.</p>
<pre class="brush: csharp; title: ; notranslate">
Timeline.DesiredFrameRateProperty.OverrideMetadata(
    typeof(Timeline),
    new FrameworkPropertyMetadata { DefaultValue = 30 }
);
</pre>
<p>This can in extreme cases nearly half the CPU usage. Try adjusting the DefaultValue to even lower values for idle screens or when no animations are occurring.</p>
<p style="padding-left: 30px;"><strong>Do:</strong> Lower the default animation frame rate if possible.</p>
<p>Changes to the animation framerate do not even have to be a global operation, as DesiredFrameRateProperty is a dependency property, they can be applied to animation in XAML and in the codebehind directly.</p>
<p>Changing the animation framerate on a signal animation will still mean the global animation thread clocks faster, but reduces the number of invalidate calls to the render target; thus the control needs to be rendered and composited fewer times.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;DoubleAnimation Storyboard.TargetProperty=&quot;Opacity&quot; Duration=&quot;0:0:0.5&quot; 
                 From=&quot;1.0&quot; To=&quot;0.5&quot; Timeline.DesiredFrameRate=&quot;30&quot; /&gt;
</pre>
<p style="padding-left: 30px;"><strong>Do:</strong> Check all animations to see if they can have their frame rate individually reduced.</p>
<p><strong>Render Options</strong></p>
<p>WPF has codec support for a large array of image formats. When loading in images into an ImageBrush and creating temporary surfaces during animations WPF can scale and cache resources, when this happens you will be able to make trade-offs on how this occurs and the quality of the scaling mode.</p>
<p style="padding-left: 30px;"><strong>Do:</strong> Make sure you only use images of the final size and DPI of your application. Loading in larger sizes means a higher memory footprint and additional calls to scaling operations.</p>
<p>The default scaling mode is Linear, which is faster than HighQuality mode, but produces lower quality output. The full list of render modes can be found on <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.bitmapscalingmode.aspx">MSDN</a>.</p>
<p style="padding-left: 30px;"><strong>Do:</strong> If the animation sequence on an Imagebrush occurs fast, it may be advisable to lower the scaling image quality to increase performance.</p>
<p>Below is a sample of code that alters the RenderOptions of the brush _PictureBrush.</p>
<pre class="brush: csharp; title: ; notranslate">
RenderOptions.SetCachingHint(_PictureBrush, CachingHint.Cache);
RenderOptions.SetBitmapScalingMode(_PictureBrush, BitmapScalingMode.LowQuality);
</pre>
<p>SetCachingHint is another way of telling WPF to cache the output of the visual. By default, WPF does not cache the rendered contents of <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.drawingbrush.aspx">DrawingBrush</a> and <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.visualbrush.aspx">VisualBrush</a> objects because they may change. If the final state of these brushes is a static image, or the composition phase is CPU bound, make sure you enable this.</p>
<p style="padding-left: 30px;"><strong>Do:</strong> Apply the SetCachingHint property for Brushes that have static content when produced in the code behind to reduce invalidation calls.</p>
<p><strong>Bitmap Caching</strong></p>
<p>An instant hot path is where complex objects have to be rendered repeatedly to the screen, what makes it worse from a design perspective is if these never change and are static. The CLR and compiler can notice this to varying degrees and can perform optimisations, but if you know when something won&#8217;t change for a long time; a button, or control, it might be best to give the CLR the heads up.</p>
<p>Bitmap caching works by rendering the control once, and then storing the finalised bitmap version. Future renders will use this cached version rather than needing to redraw the entire control again, this can lead to substantial improvements.</p>
<p>Caching has problems with the following:</p>
<ul>
<li>Animations are happening within the control</li>
<li>Video</li>
<li>Interaction with native controls</li>
<li>Transformations (can cause image corrupts / degradation)</li>
</ul>
<p>Caching options of a control can be accessed via the CacheMode dependency property of a UIElement, for example the following is how to set the CacheMode of a Canvas.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;Canvas.CacheMode&gt;
    &lt;BitmapCache EnableClearType=&quot;True&quot; RenderAtScale=&quot;1.0&quot; /&gt;
&lt;/Canvas.CacheMode&gt;
</pre>
<p>The EnableClearType attribute specifies whether text in the cached object should still have ClearType font smoothing applied. If you are using ClearType on your app as a whole, have small text in the control and expect to be scaling then I would suggest you enable it.</p>
<p>RenderAtScale is important if you are scaling the end control. As the BitmapCache creates a pixel based representation of the control &#8211; no longer vector based, the attribute specifies how big the generated source bitmap should be. The default is 1.0, making it smaller means a smaller footprint, faster animations but blurring may become noticeable. Having the value higher than one means less detail will be lost during scaling transforms however the memory footprint will be larger and there will be a small (but growing as the attribute value rises) performance impact &#8211; although most likely lower than re-rendering the control from scratch.</p>
<p style="padding-left: 30px;"><strong>Do:</strong> If using the RenderAtScale attribute, try different values to see the best trade off of quality vs speed.</p>
<p><strong>Hide what you don&#8217;t need to render</strong><br />
When the render passes through the Visual Tree, it will update and render what it needs too, sometimes it will render controls regardless of if it is visible or not. To stop this from happening and thus reduce the path through the render phase you should hide or collapse the visibility of UIElements you do not require.<br />
You may sometimes fade out UIElements using an Opacity brush to 0, effectively hiding it by making it transparent, however it is still part of the render tree.<br />
Set the Visibility property to Hidden. Setting it to Collapse will do the same, but removes it completely from the visual tree rather than just not calling the render phase. Setting it to Collapse causes a small performance hit when re-showing it.</p>
<p>As Visibility is a Dependency Property, you can include this into your animations so their visibility is hidden when the animation finishes. You may even want to stop them being hit testable at the same time.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;Storyboard x:Key=&quot;Exit&quot;&gt;
    &lt;DoubleAnimation 
	Storyboard.TargetName=&quot;ControlToFadeOut&quot;
	Storyboard.TargetProperty=&quot;Opacity&quot;
	Duration=&quot;0:0:0.25&quot;
	From=&quot;1&quot; To=&quot;0&quot; /&gt;
    &lt;ObjectAnimationUsingKeyFrames Storyboard.TargetName=&quot;ControlToFadeOut&quot; Storyboard.TargetProperty=&quot;Visibility&quot; Duration=&quot;0:0:0.25&quot;&gt;
        &lt;DiscreteObjectKeyFrame KeyTime=&quot;0:0:0.25&quot;&gt;
            &lt;DiscreteObjectKeyFrame.Value&gt;
                &lt;Visibility&gt;Hidden&lt;/Visibility&gt;
            &lt;/DiscreteObjectKeyFrame.Value&gt;
        &lt;/DiscreteObjectKeyFrame&gt;
    &lt;/ObjectAnimationUsingKeyFrames&gt;
    &lt;BooleanAnimationUsingKeyFrames Storyboard.TargetName=&quot;ControlToFadeOut&quot; Storyboard.TargetProperty=&quot;IsHitTestVisible&quot; Duration=&quot;0:0:0.25&quot;&gt;
        &lt;DiscreteBooleanKeyFrame KeyTime=&quot;0:0:0.25&quot; Value=&quot;False&quot; /&gt;
    &lt;/BooleanAnimationUsingKeyFrames&gt;
&lt;/Storyboard&gt;
</pre>
<p style="padding-left: 30px;"><strong>Don&#8217;t:</strong> Hooking to the event if you need to in C# means additional overheads and some untidy code. Overall it may be actually less code, but by doing it in XAML means the majority is performed in the animation and not UI thread.</p>
<p><strong>Reducing Image Footprint</strong><br />
If you are loading in large images, but do not need to view or process them at their original size. You should try and create a &#8216;thumbnail&#8217; version, however don&#8217;t been fooled, you can create a thumbnail up to any reasonable size. Once done, the output can be saved and used just like the original. You can also set the CacheOption to cache the bitmap on load rather than on demand.</p>
<pre class="brush: csharp; title: ; notranslate">
public BitmapImage CreateThumbnail(Uri Source, int PreferredWidth)
{
    BitmapImage bi = new BitmapImage();
    bi.BeginInit();
    bi.DecodePixelWidth = PreferredWidth;
    bi.CacheOption = BitmapCacheOption.OnLoad;
    bi.UriSource = Source;
    bi.EndInit();
    return bi;
}
</pre>
<p>This code takes a Uri Source and creates a thumbnail of the PeferredWidth, thus if you use this method you can drastically reduce the memory requirements of handling images as Brushes.</p>
<p style="padding-left: 30px;"><strong>Do:</strong> Set the thumbnail size to your target on screen visual size, thus reducing memory utilisation and lowering graphics bandwidth utilisation.</p>
<p><strong>Reducing Visual Tree Footprint</strong><br />
The Visual Tree contains all items that are to be rendered. There is a common illusion that built in controls only have one visual subelement, however things like TextBox have nearly 30! If you are never using an element again it may even be good to remove it completely from the parent control rather than just settings its Visibility to Hidden or Collapsed. If you ever do use it again then you may get a performance hit of re-adding it to the visual tree.</p>
<p>One way round may be to store the UIElement outside the Visual Tree so it won&#8217;t be touched during the Render Pass.</p>
<p>Below is a snippet you can use to work out how many subvisuals there are from a specific Visual in the Visual Tree. Note this does not take into account the Visibility dependency property, so even if it is not visible, the element will still be counted.</p>
<pre class="brush: csharp; title: ; notranslate">
/// &lt;summary&gt;
/// Calculates the number of visual surfaces that are inherited from 
/// the visual specified
/// &lt;/summary&gt;
/// &lt;param name=&quot;v&quot;&gt;&lt;/param&gt;
/// &lt;returns&gt;Number of visual children.&lt;/returns&gt;
public static int GetVisualTreeComplexity(Visual v)
{
    return GetVisualTreeComplexity(v, 0);
}

/// &lt;summary&gt;
/// Internal recursive Visual Tree helper to calculate visual complexity
/// &lt;/summary&gt;
/// &lt;param name=&quot;visual&quot;&gt;The child visual to process&lt;/param&gt;
/// &lt;param name=&quot;complexity&quot;&gt;The current complexity&lt;/param&gt;
/// &lt;returns&gt;&lt;/returns&gt;
private static int GetVisualTreeComplexity(Visual visual, int complexity)
{
    int curComplexity = complexity;

    for (int i = 0; i &lt; VisualTreeHelper.GetChildrenCount(visual); i++)
    {
        Visual childVisual = (Visual)VisualTreeHelper.GetChild(visual, i);
        curComplexity = GetVisualTreeComplexity(childVisual, ++curComplexity);
    }

    return curComplexity;
}
</pre>
<p style="padding-left: 30px;"><strong>Do:</strong> The lower the number generated is usually better, but sometimes unavoidable.</p>
<p>In Visual Studio 2010 and 2012 you can use the built in Tree Visualiser tool to analyse the Visual Tree and inspect dependency properties of child UIElements.<br />
To open the Tree Visualiser, in a DataTip, Watch window, Autos window, or Locals window, next to a WPF object name, click the arrow adjacent to the magnifying glass icon. A list of visualizers is displayed. Click WPF Tree Visualizer.</p>
<p><strong>Verify Data Bindings</strong><br />
Data binding in WPF and and also Silverlight is done vary lazy instantiated late bound resolution for bindings in XAML files. This feature allows a DataContext to be set at run-time via the code behind and the objects within that DataContext to correctly resolve their property bindings then.<br />
This mechanism of using late binding (rather than compile time binding) allows for really useful features such as run-time loading of loose XAML, DataTemplates and composable applications.<br />
Internally a lot of reflection occurs to attempt to wire up the data binding contexts. These are done in several orders of precedent to minimise the reflection hit. Therefore if an application has an incorrectly wired databinding or a missing data context, the applications performance can suffer while the control is initialised.<br />
By default the output log will only show critical binding errors that can be detected during compile time. Internally additional checks can be performed and binding information can be shown to the output window.</p>
<p style="padding-left: 30px;"><strong>Do:</strong> Fix incorrect bindings to speed up data context wiring and reduce reflection calls during UIElement construction.</p>
<p>To enable or customize WPF trace information for Data Binding</p>
<ol>
<li>On the Tools menu, select Options.</li>
<li>In the Options dialog box, in the box on the left, open the Debugging node.</li>
<li>Under Debugging, click Output Window.</li>
<li>Under General Output Settings, select All debug output.</li>
<li>In the box on the right, look for WPF Trace Settings.</li>
<li>Open the WPF Trace Settings node.</li>
<li>Under WPF Trace Settings, click the category of settings that you want to enable (Pick Data Binding).A drop-down list control appears in the Settings column next to Data Binding or whatever category you clicked.</li>
<li>Click the drop-down list and select the type of trace information that you want to see: All, Critical, Error, Warning, Information,Verbose, or ActivityTracing.Critical enables tracing of Critical events only.Error enables tracing of Critical and Error events.
<p>Warning enables tracing of Critical, Error, and Warning events.</p>
<p>Information enables tracing of Critical, Error, Warning, and Information events.</p>
<p>Verbose enables tracing of Critical, Error, Warning, Information, and Verbose events.</p>
<p>ActivityTracing enables tracing of Stop, Start, Suspend, Transfer, and Resume events.</li>
<li>Click OK.</li>
</ol>
<p>You can use this menu to set trace options for other properties.</p>
<!-- Start Shareaholic Recommendations Automatic --><!-- End Shareaholic Recommendations Automatic --><img src="http://feeds.feedburner.com/~r/MrPfistersRandomWaffle/~4/G5YoaNQfv3A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://mrpfister.com/journal/improving-wpf-rendering-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mrpfister.com/journal/improving-wpf-rendering-performance/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=improving-wpf-rendering-performance</feedburner:origLink></item>
		<item>
		<title>Plugin Architecture in Azure</title>
		<link>http://feedproxy.google.com/~r/MrPfistersRandomWaffle/~3/iQJdInwKks4/</link>
		<comments>http://mrpfister.com/journal/plugin-architecture-in-azure/#comments</comments>
		<pubDate>Thu, 02 May 2013 09:34:50 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Journal]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[AssemblyResolve]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[Blob]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MAF]]></category>
		<category><![CDATA[MEF]]></category>
		<category><![CDATA[Plugin]]></category>

		<guid isPermaLink="false">http://mrpfister.com/?p=1421</guid>
		<description><![CDATA[Trade-offs have to be made when moving to Cloud platforms, that&#8217;s a fact, the question is how much of a comprise do you have to make. Performance and flexibility are two such entities that are intertwined. In this article I want to talk about how you can build a plugin based architecture in Azure so [...]]]></description>
				<content:encoded><![CDATA[<p>Trade-offs have to be made when moving to Cloud platforms, that&#8217;s a fact, the question is how much of a comprise do you have to make. Performance and flexibility are two such entities that are intertwined. In this article I want to talk about how you can build a plugin based architecture in Azure so you can easily and flexibly alter your service to cope with new situations.</p>
<p><strong>How does C# on the Desktop do plugins?</strong></p>
<p>In C# there are known frameworks or coding paradigm when it comes to plugins, <a href="http://mrpfister.com/journal/mef-maf-and-all-c-plugins-in-between/">MAF and MEF</a> which are the common ways; you create an interface and then create plugins which implement that interface. You then point to where the assemblies housing those implementations are and bosh, you have a plugin architecture.</p>
<p>In Azure things happen a little differently, where do you host assemblies, how do you load dependencies?</p>
<p style="padding-left: 30px;"><strong>Note:</strong> If you are after performance, you should always load plugins during the initialisation phase of your service, if you have to do it during runtime make sure its in a separate thread to stop or minimise blocking to the plugin manager.</p>
<p><strong>Think Blobs and Containers, not Files and Folders</strong></p>
<p>Azure and other PaaS providers move away from the concept of Files and Folders and instead have the concept of high availability replicated binary blobs. Plugins are great for blobs as they are effectively static content; they may get a minor version bump but are not dynamically changing. Blobs are stored in virtual containers whose name can be configured to represent virtual paths.</p>
<p style="padding-left: 30px;"><strong>Do:</strong> Store your plugin libraries in a separate container so that they do not interfere with your working file set, or vice versa.</p>
<p>The first step is to create a plugin library, this step is exactly the same as regular desktop C#.</p>
<p>Example Plugin Interface (stored in main service library)</p>
<pre class="brush: csharp; title: ; notranslate">
namespace CloudExample.Plugins
{
    public interface IWorkerOutlet
    {
        string ModuleName { get; }
    }
}
</pre>
<p>Example Plugin Class (stored in an external library)</p>
<pre class="brush: csharp; title: ; notranslate">
namespace CloudExample
{
    public class ExamplePlugin : IWorkerOutlet
    {
        #region Public Properties
        public string ModuleName
        {
            get { return &quot;ExamplePlugin&quot;; }
        }
        #endregion
    }
}
</pre>
<p>You can create a new container via code or in the Azure management console, the same thing goes with uploading the Plugin library to the folder. I won&#8217;t explain that here as if you are thinking about plugins, I think you should be able to push files to containers.</p>
<p><strong>Loading Plugin Assemblies</strong></p>
<p>There are two parts to using plugins successfully, firstly loading the initial plugin assembly, and secondly determining and validating any required dependency assemblies.</p>
<p>Loading plugins is as simple as scanning the container for *.dll files (blobs) and downloading them into memory. Once this is done they can be handled much the same way as on the desktop but you are loading an assembly from a binary array instead of a direct file path.</p>
<p style="padding-left: 30px;"><strong>Do:</strong> Make sure you perform the usual checks for versioning and scanning for the correct interface implementation otherwise your host service may get unhandled exceptions.</p>
<p style="padding-left: 30px;"><strong>Do:</strong> If you only care about loading plugins at initialisation, cache the query from the container search for use when checking dependencies to reduce IO traffic.</p>
<pre class="brush: csharp; title: ; notranslate">
private static CloudBlobContainer assemblyContainer;

private static Dictionary&lt;string, IWorkerOutlet&gt; availablePlugins = new Dictionary&lt;string, IWorkerOutlet&gt;();

public static void InitialisePlugins()
{
    string connectionString = CloudConfigurationManager.GetSetting(&quot;Example.Storage.ConnectionString&quot;);
    CloudStorageAccount blobStorageAccount = CloudStorageAccount.Parse(connectionString);

    CloudBlobClient blobClient = blobStorageAccount.CreateCloudBlobClient();

    assemblyContainer = blobClient.GetContainerReference(PluginContainer);
            
    assemblyContainer.CreateIfNotExists();

    // Set the permissions of the container so that other instances and the website can access it and the blogs within.
    assemblyContainer.SetPermissions(new BlobContainerPermissions() { PublicAccess = BlobContainerPublicAccessType.Container });

    AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

    LoadPlugins();
}

/// &lt;summary&gt;
/// Iterate through the list of available plugins, download and attempt
/// to initialise them.
/// &lt;/summary&gt;
private static void LoadPlugins()
{
    if (!assemblyContainer.Exists())
    {
        // There is no assembly container, thus no plugins can be available
        return;
    }

    foreach (IListBlobItem blobItem in assemblyContainer.ListBlobs())
    {
        // Download the plugin
        using (MemoryStream blobStream = new MemoryStream())
        {
            try
            {
                var blob = new CloudBlockBlob(blobItem.Uri);
                if (blob.Exists())
                {
                    blob.DownloadToStream(blobStream);

                    byte[] assemblyBytes = blobStream.ToArray();
                    Assembly asm = Assembly.Load(assemblyBytes);

                    AddPluginAssembly(asm);
                }
            }
            catch (StorageException)
            {
                // Unable to download the file
            }
        }
    }
}

/// &lt;summary&gt;
/// Validates and if successful loads the corresponding assembly into the plugin architecture
/// &lt;/summary&gt;
/// &lt;param name=&quot;asm&quot;&gt;&lt;/param&gt;
private static void AddPluginAssembly(Assembly caller)
{
    // Iterate through the types available in the Assembly to see if any inherit 
    // from the IWorkerOutlet interface but not equals to. These can be instantiated as plugins
    foreach (Type t in caller.GetTypes())
    {
        // Checking non-equality allows the project assembly to be scanned as well as a caller.
        if (typeof(IWorkerOutlet).IsAssignableFrom(t) &amp;&amp; !t.Equals(typeof(IWorkerOutlet)))
        {
            try
            {
                IWorkerOutlet plugin = (IWorkerOutlet)caller.CreateInstance(t.ToString());

                // Note: Additional logic can be done here rather than just storing the plugin
                availablePlugins.Add(plugin.ModuleName, plugin);
            }
            catch
            {
                // Invocation failure on the Plugin, this is to be expected.
            }
        }
    }
}
</pre>
<p>This is great, you can load assemblies but some may fail, or cause exceptions, why? -because they are missing dependencies that are not part of your host service.</p>
<p style="padding-left: 30px;"><strong>Do:</strong> Make sure you note which references you use in your plugin library, and compare them to your host service, deltas between the two may cause issues.</p>
<p>An example would be where your plugin library interfaces with a 3rd party library, but your main service doesn&#8217;t. Even if you as part of the first phase uploaded both libraries, only the first would be stored as its implementing the required interface, the second would be ignored.</p>
<p><strong>Resolving Dependencies</strong></p>
<p>When an application fails to resolve a dependency the <strong>AppDomain.CurrentDomain.AssemblyResolve</strong> event is fired but is unhandled by default. You can hook up to this event to see when internally the CLR requires referencing to a new library.</p>
<p>By not returning null, the CLR will attempt to resolve the specified assembly rather than performing internal checks. This can be useful in general for swapping out real libraries for test versions or in this case, helping point the way to where libraries are stored. MSDN contains information about the ordering sequence of how <a href="http://msdn.microsoft.com/en-us/library/ff527268.aspx">internal resolving occurs</a>, but this doesn&#8217;t work in the Cloud due to the differences in file structure.</p>
<p>By hooking into this event, we can check the assemblies container to determine if the required assembly is present, if so this file can be downloaded and used. Sometimes we don&#8217;t need to host all assemblies &#8211; as I&#8217;ve mentioned the host service may already have them as references which can be internally resolved.</p>
<p style="padding-left: 30px;"><strong>Do not</strong>: There is no need to upload all assemblies thrown in the AssemblyResolve event, most of these will be triggered by the host service internally and thus will internally resolve.</p>
<p style="padding-left: 30px;"><strong>Do:</strong> Keep a flag of when you are loading plugins, AssemblyResolve will fire in two phases, first during the initial startup of your host service when it is loading its own dependencies, then while it is loading plugin dependencies. By seperating the two phases you can reduce the requests to Blob Storage.</p>
<pre class="brush: csharp; title: ; notranslate">
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    string assemblyPath = GetAssemblyName(args) + &quot;.dll&quot;;

    // Download the missing assembly if available
    using (MemoryStream blobStream = new MemoryStream())
    {
        try
        {
            // Note: Use precache of where the assembly container is
            CloudBlockBlob blob = assemblyContainer.GetBlockBlobReference(assemblyPath);
            if (blob.Exists())
            {
                blob.DownloadToStream(blobStream);

                byte[] assemblyBytes = blobStream.ToArray();
                Assembly asm = Assembly.Load(assemblyBytes);

                // Check to see if this assembly actually matches the fully
                // qualified name.
                if (asm.FullName == args.Name)
                {
                    return asm;
                }
            }
        }
        catch (StorageException)
        {
        }
    }

    // Failed to resolve the plugin DLL.
    return null;
}

/// &lt;summary&gt;
/// Determines the assembly name of a fully qualified assembly name
/// &lt;/summary&gt;
/// &lt;param name=&quot;args&quot;&gt;Assembly Arguments to resolve&lt;/param&gt;
/// &lt;returns&gt;Returns a value indicating the assembly name&lt;/returns&gt;
private static string GetAssemblyName(ResolveEventArgs args)
{
    string name = string.Empty;
    if (args.Name.IndexOf(&quot;,&quot;) &gt; -1)
    {
        name = args.Name.Substring(0, args.Name.IndexOf(&quot;,&quot;));
    }
    else
    {
        name = args.Name;
    }

    return name;
}
</pre>
<p>What I usually do is store dependencies that I could not resolve to a serialised XML file in blob storage, to a debug log, or to a dependency table in a DB so I can check them at a later date.</p>
<p><strong>Why use plugins?</strong></p>
<p>Its pretty easy to implement plugins in C#, even if in Azure by utilising Blob storage. You should always be careful using this technique though due to the costs of reflection.</p>
<p style="padding-left: 30px;"><strong>Do Not:</strong> Use this code in production, there&#8217;s very little validation, error checking or concurrency checks!</p>
<!-- Start Shareaholic Recommendations Automatic --><!-- End Shareaholic Recommendations Automatic --><img src="http://feeds.feedburner.com/~r/MrPfistersRandomWaffle/~4/iQJdInwKks4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://mrpfister.com/journal/plugin-architecture-in-azure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mrpfister.com/journal/plugin-architecture-in-azure/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=plugin-architecture-in-azure</feedburner:origLink></item>
		<item>
		<title>Quis custodiet ipsos custodes</title>
		<link>http://feedproxy.google.com/~r/MrPfistersRandomWaffle/~3/fSiS4ByK5Bs/</link>
		<comments>http://mrpfister.com/journal/quis-custodiet-ipsoscustodes/#comments</comments>
		<pubDate>Thu, 18 Apr 2013 19:36:30 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Journal]]></category>
		<category><![CDATA[Photography]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[3d model]]></category>
		<category><![CDATA[Boston]]></category>
		<category><![CDATA[Forensic]]></category>
		<category><![CDATA[investigation]]></category>
		<category><![CDATA[photo synth]]></category>
		<category><![CDATA[Pictures]]></category>

		<guid isPermaLink="false">http://mrpfister.com/?p=1411</guid>
		<description><![CDATA[Quis custodiet ipsos custodes? is a Latin phrase literally translated as &#8220;Who will guard the guards themselves?&#8221; but commonly rendered as &#8220;Who watches the watchmen?&#8221; made famous paraphased from its original latin in Orwell&#8217;s 1984. With the recent events such as the London Riots and the bombing in Boston, its slowly becoming clear that the technology [...]]]></description>
				<content:encoded><![CDATA[<p><em><strong>Quis custodiet ipsos custodes?</strong></em> is a Latin phrase literally translated as &#8220;<em>Who will guard the guards themselves?&#8221;</em> but commonly rendered as <em>&#8220;Who watches the watchmen?&#8221; </em>made famous paraphased from its original latin in Orwell&#8217;s 1984.</p>
<p>With the recent events such as the London Riots and the bombing in Boston, its slowly becoming clear that the technology exists which supplants CCTV as the all seeing benefactor, but the public themselves act as the <em>Eye of Providence</em>. It falls upon the Computer Scientist to provide the technological missing link.</p>
<p>During these events, there are an ever increasing amount of people with cameras or regular camera-phones who take pictures, sometimes of friends, family or surroundings. Each in turn may shed light on the surroundings; effectively a piece in a puzzle.</p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/photosynth.jpg"><img class="aligncenter size-full wp-image-1412" alt="photosynth_concept" src="http://mrpfister.com/wp-content/uploads/2013/04/photosynth.jpg" width="400" height="305" /></a></p>
<p>Virtually all cameras now imprint Exif metadata into the picture, usually the camera model, focal length, aperture but sometimes also the date and time of the shot, and an ever increasing number of smartphones include geo data from the GPS unit.</p>
<p>Piecing this together you can work out when and where pictures were taken. Sites like Flickr already allow uses to search for pictures based on time of shot and / or geographic region.</p>
<p>Technology therefore allows for the first piece of the puzzle, getting all the pictures from a location spanning a certain time period.</p>
<p>Remember watching <em>Enemy of the State? -</em>where they use video footage to construct a 3d model of a bag to see if a drop had been made , and everyone thought that was silly and wouldn&#8217;t work in real life.</p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/EnemyOfTheState3dModel.png"><img class="aligncenter size-full wp-image-1416" alt="EnemyOfTheState_3dModel" src="http://mrpfister.com/wp-content/uploads/2013/04/EnemyOfTheState3dModel.png" width="1024" height="576" /></a></p>
<p>Well the University of Washington and Microsoft Live labs provided the reel technology behind this next piece of the puzzle.</p>
<p>They developed the ability to analyse a group of pictures and their corresponding metadata to place them within a 3d space to construct a 3d model representation.</p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/2086.jpg"><img class="aligncenter size-full wp-image-1413" alt="photosynth_3d_model" src="http://mrpfister.com/wp-content/uploads/2013/04/2086.jpg" width="612" height="450" /></a></p>
<p>The processing power and need now exists to take this concept one stage further. As events such as those in Boston have 1000s of onlookers who have taken 10,000s of pictures over several hours, the sheer amount of source images exists to create these 3d models based on pictures from time slices not just the entire data set. Video footage could also be interweaved and used as effectively it is just a series of images. Variations and inaccuracies of cameras can be either determined via <em>mechanical turk</em> or via analysing the white balance &amp; colour range of the corresponding camera data to determine lighting conditions of the scene and thus interpolated time of day.</p>
<p>What does this all mean? well the technology exists to create a 3d animation of an event based on real images, thus if something is spotted, it can be tracked in temporal and 3d space back to a point where an image was taken that accurately portrays the individual.</p>
<p>&#8230;But thats just my 2 cents.</p>
<!-- Start Shareaholic Recommendations Automatic --><!-- End Shareaholic Recommendations Automatic --><img src="http://feeds.feedburner.com/~r/MrPfistersRandomWaffle/~4/fSiS4ByK5Bs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://mrpfister.com/journal/quis-custodiet-ipsoscustodes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mrpfister.com/journal/quis-custodiet-ipsoscustodes/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=quis-custodiet-ipsoscustodes</feedburner:origLink></item>
		<item>
		<title>Oblivion, a mind bogglingly awesome film</title>
		<link>http://feedproxy.google.com/~r/MrPfistersRandomWaffle/~3/s7s9KuQDoHM/</link>
		<comments>http://mrpfister.com/journal/oblivion-a-mind-bogglingly-awesome-film/#comments</comments>
		<pubDate>Thu, 18 Apr 2013 18:05:39 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Journal]]></category>
		<category><![CDATA[Film Review]]></category>
		<category><![CDATA[HAL]]></category>
		<category><![CDATA[Joseph Kosinski]]></category>
		<category><![CDATA[Oblivion]]></category>
		<category><![CDATA[SciFi]]></category>
		<category><![CDATA[Space Odyssey]]></category>
		<category><![CDATA[Stanley Kubrick]]></category>
		<category><![CDATA[Tom Cruise]]></category>

		<guid isPermaLink="false">http://mrpfister.com/?p=1399</guid>
		<description><![CDATA[Knowing that Joseph Kosinski, the man behind TRON Legacy was directing this film, I knew from the get go that this was going to be a visually stunning multi layered films, and I was stunned when I watched it, and by stunned I mean holding onto my set going &#8216;the awesomeness &#8230;its everywhere!!&#8217; The visual [...]]]></description>
				<content:encoded><![CDATA[<p>Knowing that Joseph Kosinski, the man behind TRON Legacy was directing this film, I knew from the get go that this was going to be a visually stunning multi layered films, and I was stunned when I watched it, and by stunned I mean holding onto my set going &#8216;the awesomeness &#8230;its everywhere!!&#8217;</p>
<p>The visual styling was very much the same Bauhaus inspired design, very Dieter Rams, full of clean lines and structural minimalism that I would love my house to be like.</p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/oblivion_bauhaus.jpg"><img class="aligncenter size-large wp-image-1401" alt="oblivion_bauhaus" src="http://mrpfister.com/wp-content/uploads/2013/04/oblivion_bauhaus-1024x540.jpg" width="600" height="316" /></a></p>
<p>The non spoiler version of the plot is that the year is 2077 and it has been 60 years since Earth was invaded by an alien race, known as Scavengers, the moon was destroyed during the first wave of attack. Humanity prevailed but Earth was left ruined. A space station was constructed to transport the survivors to Titan. Jack Harper (Tom Cruise) and Victoria (Andrea Riseborough), the main protagonists are the mop up crew; repairman for mechanical drones which protect hydro-rigs &#8211; sucking Earths remaining water and convert it to fusion power for the new colony.</p>
<p><iframe src="http://www.youtube.com/embed/HQ0iiqyJ7BU" height="360" width="640" allowfullscreen="" frameborder="0"></iframe></p>
<p>Joseph direction of the film is very much a scattergun of visual stylings from previous scifi outings, which in the hope that if there is enough to choice from, there should be something for everyone.</p>
<p>One of the things I always loved about his work is that he creates stunning visual set pieces, much from his time of directing commercials, everything had to be there for a reason and show it off clearly. An obvious example being the clean stark lines of the tower; the home for Jack and Victoria compared to the crumbling wasteland underneath.</p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/Oblivion_03.jpg"><img class="aligncenter size-large wp-image-1407" alt="Oblivion_Repairman" src="http://mrpfister.com/wp-content/uploads/2013/04/Oblivion_03-1024x591.jpg" width="600" height="346" /></a></p>
<p><strong>*SPOILERS*</strong></p>
<p>Summed up: You could nearly be mistaken that the last 5 minutes was actually filmed by Stanley Kubrick and is in fact a modern interpretation of 2001: A Space Odyssey.</p>
<p>In the end you find out that Jack is one of thousands of clones of the original; an astronaut assigned to investigate an alien object headed towards earth. He joins the surviving human rebels and builds a bomb to blow the alien spaceship up.</p>
<p>When he ventures into space towards the object to deliver the bomb everything gets surreal; the incredible music and synth by M83 shifts to a lower key, the visuals become stark and the voice of Sally &#8211; the alien lifeform who for the majority of the film were led to believe was just mission control sounds all very much like HAL.</p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/Oblivion_preview2_SD.jpg"><img class="aligncenter size-large wp-image-1406" alt="Oblivion_Sally" src="http://mrpfister.com/wp-content/uploads/2013/04/Oblivion_preview2_SD-1024x554.jpg" width="600" height="324" /></a></p>
<p>Even the Red glowing ring of the drones and Sally were eerily like HAL. Now I am not complaining about this, I understand the instant associations people have with machines and red glowing eyes (think terminator as well) makes it an easier vessel for people to believe she is actually evil, and not just a living being trying to survive.</p>
<p>It was a really nice twist that not only is he a clone, but actually he is working for the &#8216;baddy&#8217; all along without actually knowing about it. Watching the film for a second time really proved interesting as you get to pick up on the subtleties that had to be placed</p>
<p>Overall, I really liked the film, at over 2 hours it may seem long to some but I liked the pacing. Mixed with a homage to the classic sci-fi films I would give it a <strong>8 out of 10</strong></p>
<!-- Start Shareaholic Recommendations Automatic --><!-- End Shareaholic Recommendations Automatic --><img src="http://feeds.feedburner.com/~r/MrPfistersRandomWaffle/~4/s7s9KuQDoHM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://mrpfister.com/journal/oblivion-a-mind-bogglingly-awesome-film/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mrpfister.com/journal/oblivion-a-mind-bogglingly-awesome-film/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=oblivion-a-mind-bogglingly-awesome-film</feedburner:origLink></item>
		<item>
		<title>Currying Function C#</title>
		<link>http://feedproxy.google.com/~r/MrPfistersRandomWaffle/~3/UNG_z_3JLZI/</link>
		<comments>http://mrpfister.com/journal/currying-function-c/#comments</comments>
		<pubDate>Sun, 07 Apr 2013 07:42:14 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Journal]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Currying]]></category>
		<category><![CDATA[Lambda Calculus]]></category>

		<guid isPermaLink="false">http://mrpfister.com/?p=1391</guid>
		<description><![CDATA[A while ago I did a post about Lambda calculus in C#, mainly focusing on how you can implement the concept of Y combinators. Y combinators are one of the simplest fixed point combinators in Lambda calculus, and was discovered by a Mr Curry. One of the other interesting concepts of Lambda calculus is the [...]]]></description>
				<content:encoded><![CDATA[<p>A while ago I did a post about Lambda calculus in C#, mainly focusing on how you can implement the concept of Y combinators. Y combinators are one of the simplest fixed point combinators in Lambda calculus, and was discovered by a Mr Curry. One of the other interesting concepts of Lambda calculus is the concept of &#8216;Currying&#8217;.</p>
<p>Heres a quick foray back at Y Combinator:</p>
<pre class="brush: csharp; title: ; notranslate">
///
/// One-argument Y-Combinator.
///
public static Func&lt;T, TResult&gt; Y&lt;T, TResult&gt;(Func&lt;Func&lt;T, TResult&gt;, Func&lt;T, TResult&gt;&gt; F)
{
	return t =&gt; F(Y(F))(t);
}

///
/// Two-argument Y-Combinator.
///
public static Func&lt;T1, T2, TResult&gt; Y&lt;T1, T2, TResult&gt;(Func&lt;Func&lt;T1, T2, TResult&gt;, Func&lt;T1, T2, TResult&gt;&gt; F)
{
	return (t1, t2) =&gt; F(Y(F))(t1, t2);
}

///
/// Three-arugument Y-Combinator.
///
public static Func&lt;T1, T2, T3, TResult&gt; Y&lt;T1, T2, T3, TResult&gt;(Func&lt;Func&lt;T1, T2, T3, TResult&gt;, Func&lt;T1, T2, T3, TResult&gt;&gt; F)
{
	return (t1, t2, t3) =&gt; F(Y(F))(t1, t2, t3);
}

///
/// Four-arugument Y-Combinator.
///
public static Func&lt;T1, T2, T3, T4, TResult&gt; Y&lt;T1, T2, T3, T4, TResult&gt;(Func&lt;Func&lt;T1, T2, T3, T4, TResult&gt;, Func&lt;T1, T2, T3, T4, TResult&gt;&gt; F)
{
	return (t1, t2, t3, t4) =&gt; F(Y(F))(t1, t2, t3, t4);
}
</pre>
<p>Currying is the concept of integrating an argument of a function into a new function with the argument built in.</p>
<p>Take the following maths equation:</p>
<p style="padding-left: 30px;"><strong>f(a, b, c) where f = a + b + c</strong></p>
<p>so</p>
<p style="padding-left: 30px;"><strong>f(1, 2, 3) would mean f = 6</strong></p>
<p>The concept of currying takes the argument and effectively hardcoding it, so take a look again at the previous function.</p>
<p style="padding-left: 30px;"><strong>Currying f(1, b, c) would produce a new function f1(b, c) where f1 = 1 + b + c</strong></p>
<p>This idea is important of things like constructors or overloading functions, where some arguments may be fixed.</p>
<p>Currying in C# lambda calculus looks like the following:</p>
<pre class="brush: csharp; title: ; notranslate">
// Curry first argument
public static Func&lt;T1, Func&lt;T2, TResult&gt;&gt; Curry&lt;T1, T2, TResult&gt;(Func&lt;T1, T2, TResult&gt; F)
{
	return t1 =&gt; t2 =&gt; F(t1, t2);
}

// Curry second argument.
public static Func&lt;T2, Func&lt;T1, TResult&gt;&gt; Curry2nd&lt;T1, T2, TResult&gt;(Func&lt;T1, T2, TResult&gt; F)
{
	return t2 =&gt; t1 =&gt; F(t1, t2);
}

// Uncurry first argument.
public static Func&lt;T1, T2, TResult&gt; Uncurry&lt;T1, T2, TResult&gt;(Func&lt;T1, Func&lt;T2, TResult&gt;&gt; F)
{
	return (t1, t2) =&gt; F(t1)(t2);
}

// Uncurry second argument.
public static Func&lt;T1, T2, TResult&gt; Uncurry2nd&lt;T1, T2, TResult&gt;(Func&lt;T2, Func&lt;T1, TResult&gt;&gt; F)
{
	return (t1, t2) =&gt; F(t2)(t1);
}
</pre>
<!-- Start Shareaholic Recommendations Automatic --><!-- End Shareaholic Recommendations Automatic --><img src="http://feeds.feedburner.com/~r/MrPfistersRandomWaffle/~4/UNG_z_3JLZI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://mrpfister.com/journal/currying-function-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mrpfister.com/journal/currying-function-c/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=currying-function-c</feedburner:origLink></item>
		<item>
		<title>New York, Cake, Getting old and everything else!</title>
		<link>http://feedproxy.google.com/~r/MrPfistersRandomWaffle/~3/ynJAgSRRyPk/</link>
		<comments>http://mrpfister.com/journal/new-york-cake-getting-old-and-everything-else/#comments</comments>
		<pubDate>Fri, 05 Apr 2013 22:56:02 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Cake]]></category>
		<category><![CDATA[Journal]]></category>
		<category><![CDATA[New York]]></category>
		<category><![CDATA[NYC]]></category>

		<guid isPermaLink="false">http://mrpfister.com/?p=1368</guid>
		<description><![CDATA[It has been a busy few months with very few blog posts to show for it, I believe it is time to change that! In January I went to New York to attend the National Retail Federation (NRF) conference but took nearly a week off to wander around and explore, try out the local food [...]]]></description>
				<content:encoded><![CDATA[<p>It has been a busy few months with very few blog posts to show for it, I believe it is time to change that!</p>
<p>In January I went to New York to attend the National Retail Federation (NRF) conference but took nearly a week off to wander around and explore, try out the local food and get lost trying to find the fire station from Ghost Busters.</p>
<p>There was a big downside and that was I visited mid january and so temperatures wern&#8217;t particularly warm! Between -5 and -10 average during the day, a far cry from my trip 2 years earlier with 30+ temperatures constantly.</p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/DSC00345.jpg"><img class="aligncenter size-full wp-image-1370" alt="EmpireStatesBuilding" src="http://mrpfister.com/wp-content/uploads/2013/04/DSC00345.jpg" width="683" height="1024" /></a>My first hotel was located on Times Square but my main hotel where I sent my &#8216;mini hotel&#8217; was just around the corner on 5th Avenue. Once unpacked I headed out, not wanting to be frozen trying to visit the Shake Shack I headed around the corner to GoodBurger for my first true American burger.</p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/DSC00283.jpg"><img class="aligncenter size-full wp-image-1371" alt="GoodBurger" src="http://mrpfister.com/wp-content/uploads/2013/04/DSC00283.jpg" width="1024" height="683" /></a></p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/DSC00284.jpg"><img class="aligncenter size-full wp-image-1372" alt="HoldingGoodBurger" src="http://mrpfister.com/wp-content/uploads/2013/04/DSC00284.jpg" width="1024" height="683" /></a>That to this day was one of the best burgers I have ever had.</p>
<p>During my visit I went to lots of iconic places, such as going up to the Top of the Rock, visiting the USS Intrepid, going to Grand Central Station, sitting in the public library&#8230;</p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/DSC00296.jpg"><img class="aligncenter size-full wp-image-1373" alt="DSC00296" src="http://mrpfister.com/wp-content/uploads/2013/04/DSC00296.jpg" width="1024" height="683" /></a></p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/DSC00334.jpg"><img class="aligncenter size-full wp-image-1374" alt="DSC00334" src="http://mrpfister.com/wp-content/uploads/2013/04/DSC00334.jpg" width="1024" height="683" /></a></p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/DSC00360.jpg"><img class="aligncenter size-full wp-image-1375" alt="DSC00360" src="http://mrpfister.com/wp-content/uploads/2013/04/DSC00360.jpg" width="1024" height="683" /></a>Breakfasts consisted of mainly egg and waffles, portions to American standards but the evening meals &#8230;well that is a different story all together&#8230;</p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/DSC00349.jpg"><img class="aligncenter size-full wp-image-1376" alt="DSC00349" src="http://mrpfister.com/wp-content/uploads/2013/04/DSC00349.jpg" width="1024" height="683" /></a></p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/IMG_0914.jpg"><img class="aligncenter size-full wp-image-1377" alt="IMG_0914" src="http://mrpfister.com/wp-content/uploads/2013/04/IMG_0914.jpg" width="1024" height="768" /></a></p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/IMG_0919.jpg"><img class="aligncenter size-full wp-image-1378" alt="IMG_0919" src="http://mrpfister.com/wp-content/uploads/2013/04/IMG_0919.jpg" width="1024" height="768" /></a></p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/IMG_0920.jpg"><img class="aligncenter size-full wp-image-1379" alt="IMG_0920" src="http://mrpfister.com/wp-content/uploads/2013/04/IMG_0920.jpg" width="1024" height="768" /></a></p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/IMG_0928.jpg"><img class="aligncenter size-full wp-image-1380" alt="IMG_0928" src="http://mrpfister.com/wp-content/uploads/2013/04/IMG_0928.jpg" width="1024" height="768" /></a></p>
<p>Moving on from New York, I have been able to try out a lot more cake. As most people know I have a soft spot for cake, as I believe everyone should have it as part of their lives&#8230;</p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/Bar_Refaeli_Cake.jpg"><img class="aligncenter size-large wp-image-1382" alt="Bar_Refaeli_Cake" src="http://mrpfister.com/wp-content/uploads/2013/04/Bar_Refaeli_Cake-767x1024.jpg" width="600" height="801" /></a>As Bar Refaeli kindly demonstrates, cake should be part of everyones lives.</p>
<p>So since then there has been birthdays, and many other reasons for cake! Horray for cake.</p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/IMG_0242.jpg"><img class="aligncenter size-large wp-image-1383" alt="IMG_0242" src="http://mrpfister.com/wp-content/uploads/2013/04/IMG_0242-1024x1024.jpg" width="600" height="600" /></a></p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/IMG_0484.jpg"><img class="aligncenter size-large wp-image-1384" alt="IMG_0484" src="http://mrpfister.com/wp-content/uploads/2013/04/IMG_0484-1024x1024.jpg" width="600" height="600" /></a></p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/IMG_0571.jpg"><img class="aligncenter size-large wp-image-1385" alt="IMG_0571" src="http://mrpfister.com/wp-content/uploads/2013/04/IMG_0571-1024x768.jpg" width="600" height="450" /></a></p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/IMG_0610.jpg"><img class="aligncenter size-large wp-image-1386" alt="IMG_0610" src="http://mrpfister.com/wp-content/uploads/2013/04/IMG_0610-768x1024.jpg" width="600" height="800" /></a></p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/04/IMG_0922.jpg"><img class="aligncenter size-large wp-image-1387" alt="IMG_0922" src="http://mrpfister.com/wp-content/uploads/2013/04/IMG_0922-1024x768.jpg" width="600" height="450" /></a>Luckily it shall soon be cycling season, so plenty of calories that I&#8217;ll need to eat to be burnt off ;-)</p>
<!-- Start Shareaholic Recommendations Automatic --><!-- End Shareaholic Recommendations Automatic --><img src="http://feeds.feedburner.com/~r/MrPfistersRandomWaffle/~4/ynJAgSRRyPk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://mrpfister.com/journal/new-york-cake-getting-old-and-everything-else/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mrpfister.com/journal/new-york-cake-getting-old-and-everything-else/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=new-york-cake-getting-old-and-everything-else</feedburner:origLink></item>
		<item>
		<title>Build your own cheap NAS box</title>
		<link>http://feedproxy.google.com/~r/MrPfistersRandomWaffle/~3/C3z30LITxTY/</link>
		<comments>http://mrpfister.com/journal/build-your-own-cheap-nas-box/#comments</comments>
		<pubDate>Sun, 17 Feb 2013 22:08:13 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Journal]]></category>
		<category><![CDATA[DPC Watchdog Violation]]></category>
		<category><![CDATA[HP]]></category>
		<category><![CDATA[N40L]]></category>
		<category><![CDATA[Proliant]]></category>

		<guid isPermaLink="false">http://mrpfister.com/?p=1356</guid>
		<description><![CDATA[Till now I had been using a combination of an Apple Time Capsule and a collection of attached USB external harddiscs as my NAS and backup solution. This isn&#8217;t really that good and also I am starting to approach the Time Capsules known lifespan of around 20 months. The Time Capsule Memorial Register has a [...]]]></description>
				<content:encoded><![CDATA[<p>Till now I had been using a combination of an Apple Time Capsule and a collection of attached USB external harddiscs as my NAS and backup solution. This isn&#8217;t really that good and also I am starting to approach the Time Capsules known lifespan of around 20 months. The Time Capsule Memorial Register has a great graph showing the bell curve of the failure rates; the average being <a href="http://timecapsuledead.org/stats.html">19 months and 20 days</a></p>
<p>Due to this I decided to go out and buy a NAS, but looking at the price of a 4 bay QNAP or Synology unpopulated drives which started around £250-300, I though there had to be a better/cheaper way as this is nearly the price of a small desktop PC.</p>
<p>Some of my work colleagues had used a HP Microserver, and after reading up on it, and using a £100 cashback offer I managed to get my very own HP N40L Microserver for only £97 &#8211; already far cheaper than the main rivals.</p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/02/HP-ProLiant-N40L-Microserver-alt-580-90.jpg"><img class="aligncenter size-full wp-image-1357" alt="HP ProLiant N40L Microserver alt -580-90" src="http://mrpfister.com/wp-content/uploads/2013/02/HP-ProLiant-N40L-Microserver-alt-580-90.jpg" width="580" height="345" /></a></p>
<p>Specs wise, it won&#8217;t be beating your average PC anytime soon but its not meant to, this is a low power small business server. As standard it comes with a dual core AMD Turion 1.5GHz processor, a 250GB harddisc and 2GB of RAM. What makes it cheaper is that it doesn&#8217;t come with an OS pre-installed, thats up to the end user.</p>
<p>It should be noted a few niggles that don&#8217;t make this perfect from the get-go.</p>
<ul>
<li>There is only VGA out, perfectly fine as the default function of a server but HDMI would be perfect for turning this into a media centre.</li>
<li>There is no audio-out.</li>
<li>The 5th SATA is not full speed (designed for an ODD) &#8211; can be fixed with a BIOS mod.</li>
</ul>
<p>While buying the server I also bought a selection of components to upgrade the rig and make my choice of OS more usable:</p>
<ul>
<li>Crucial 8GB (2x4GB) DDR3 1333Mhz Ballistix Sport Memory Kit CL9 1.5V</li>
<li>Asus GT 610 1GB DDR3 VGA DVI HDMI PCI-E Low Profile Graphics Card</li>
<li>8GB Sandisk Cruzer USB drive</li>
</ul>
<p>This combine caused me a few hiccups when installing OS&#8217;s (Windows fault not the hardware) which I&#8217;ll explain later but overall it cost me (including the N40L itself) around £170</p>
<p>One of the nice things about this server is that it has an internal USB port, some people use this for hosting a USB based OS such as FreeNAS or even Ubuntu however I originally choose Windows Server 2012 as my OS of choice but I ran into a problem.</p>
<p>After installing, while setting up devices I encountered a BSOD; the dreading &#8216;DPC Watchdog Violation&#8217; error. After reading up on the matter it seems there are a variety of reasons for this on the N40L but mainly revolves around the use of NVidia graphics cards when your installed RAM is over 2GB. I checked out my RAM and it was error free, and the OS worked fine when I had the external graphics card disabled or removed, but as soon as I installed it I got BSODs.</p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/02/Capture.png"><img class="aligncenter size-full wp-image-1359" alt="DPC Watchdog Violation" src="http://mrpfister.com/wp-content/uploads/2013/02/Capture.png" width="627" height="428" /></a></p>
<p>This was really annoying, the same BSOD occured with Windows 8, and there is no known install time fix apart from removing the graphics card.</p>
<p>I settled on Windows 7 as my OS of choice &#8211; with the graphics card and lots of RAM I could also use the machine as a basic gaming rig, or run XBMC or MMC so I ruled out Windows Home Server as an option.</p>
<p>Everything installed fine and I used the 8GB USB drive as a supplemental readyboost drive to improve idle spin up performance.</p>
<!-- Start Shareaholic Recommendations Automatic --><!-- End Shareaholic Recommendations Automatic --><img src="http://feeds.feedburner.com/~r/MrPfistersRandomWaffle/~4/C3z30LITxTY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://mrpfister.com/journal/build-your-own-cheap-nas-box/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mrpfister.com/journal/build-your-own-cheap-nas-box/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=build-your-own-cheap-nas-box</feedburner:origLink></item>
		<item>
		<title>Up in the air with Cloud Development</title>
		<link>http://feedproxy.google.com/~r/MrPfistersRandomWaffle/~3/WuXWLkM_EgE/</link>
		<comments>http://mrpfister.com/programming/up-in-the-air-with-cloud-development/#comments</comments>
		<pubDate>Sun, 10 Feb 2013 08:29:39 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[IaaS]]></category>
		<category><![CDATA[PaaS]]></category>
		<category><![CDATA[saas]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://mrpfister.com/?p=1348</guid>
		<description><![CDATA[The Cloud seems to be the buzz word of the modern generation, such as HTML5, Ruby on Rails and AJAX were before it. Everyone is scrambling to use it, some bash out an idea or two after a few days tinkering but its only a few that actually understand the technologies. So what does it [...]]]></description>
				<content:encoded><![CDATA[<p>The Cloud seems to be the buzz word of the modern generation, such as HTML5, Ruby on Rails and AJAX were before it. Everyone is scrambling to use it, some bash out an idea or two after a few days tinkering but its only a few that actually understand the technologies.</p>
<p>So what does it take to develop a cloud solution? &#8211; The best analogy I would use is that of building a house on sand; whether you are setting down one brick or a thousand, without proper foundations you are doomed to failure. The cloud is good if it is designed correctly but can go horribly wrong horribly quick otherwise.</p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/02/1481410_300.jpg"><img class="aligncenter size-full wp-image-1353" alt="1481410_300" src="http://mrpfister.com/wp-content/uploads/2013/02/1481410_300.jpg" width="300" height="300" /></a></p>
<p>So what are the areas that could go wrong, where do people run into difficulty?</p>
<ul>
<li>Reliability</li>
<li>Scalability</li>
<li>Efficiency</li>
<li>Security</li>
<li>Redundancy &amp; Failover</li>
</ul>
<p>Most of the Cloud providers such as <a href="http://www.windowsazure.com/en-us/">Microsoft Azure</a>, <a href="https://cloud.google.com">Google AppEngine </a>and <a href="http://aws.amazon.com">Amazon AWS</a> provide a Platform as a Service (PaaS) which provide an API set and sometimes an SDK to develop against. There are also Infrasture as a Service (IaaS) which could be classed as the &#8216;Cloud OS&#8217; such as <a href="http://www.openstack.org">OpenStack</a> which provide underlying load balancing, networking and file access which PaaS and eventually Software (SaaS) sits on.</p>
<p><a href="http://mrpfister.com/wp-content/uploads/2013/02/SaaS_PaaS_IaaS.png"><img class="aligncenter size-full wp-image-1350" alt="SaaS_PaaS_IaaS" src="http://mrpfister.com/wp-content/uploads/2013/02/SaaS_PaaS_IaaS.png" width="656" height="327" /></a></p>
<p>Each are slightly different but most provide extensive documentation and examples (hopefully), the problem of which is that they are keen to show how easy it is to connect to the cloud. It can take less than a day to sign up, and fling a file or data record to the cloud. This is where developers show a demo and managers call it done.</p>
<p>Ramping up from this 1 demo to 10,000+ machines is a nightmare.</p>
<p><strong>Security</strong></p>
<p>Depending on what the cloud service is being designed for, whether it is serving or processing data security is still a concern but in different ways. The areas where security should be considered are:</p>
<ul>
<li>Connection Security (Injecting data)</li>
<li>Direct Data Injection &amp; Corruption</li>
<li>DDoS</li>
</ul>
<p>Even if you have a reliable connection, if someone can insert &#8216;Drop Table&#8217; or corrupt inbound data your service may fail. Moving to larger services, sometimes people or companies may target you for DDoS and thus you may need back off strategies.</p>
<p><strong>Scalability</strong></p>
<p>This is the much toted idea of cloud computing, but it requires work. You might have a powerful server but if it doesn&#8217;t load balance incoming requests then its just as useful as a small PC. The idea put fourth is that of Starbucks where data comes in and placed on a queue, lots of workers come along and then fulfil the requests.</p>
<p>On a larger scale the concept of load balancing between multiple servers, and task managers to cull spun off processes become important. &#8211; Again something that isn&#8217;t required with just one connection. Eventually it may just get to a point where you can&#8217;t just get a bigger server, and you will have to refactor your design to either fix it or make it more efficient.</p>
<p><strong>Redundancy &amp; Failover</strong></p>
<p>Your cloud solution may need to connect with other cloud services or external APIs (think Facebook, Twitter, authentication servers etc.) The first rule of this situation is never to believe they will be available 100% of the time, even your own database may sometimes not be available. Designing a solution with possible redundancy or routes of action when these external services fail is a must.</p>
<!-- Start Shareaholic Recommendations Automatic --><!-- End Shareaholic Recommendations Automatic --><img src="http://feeds.feedburner.com/~r/MrPfistersRandomWaffle/~4/WuXWLkM_EgE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://mrpfister.com/programming/up-in-the-air-with-cloud-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mrpfister.com/programming/up-in-the-air-with-cloud-development/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=up-in-the-air-with-cloud-development</feedburner:origLink></item>
	</channel>
</rss>
