Saturday, October 22, 2011

Meeting: Magic Bag of Tricks

I intend to add to this post over time with those tricks I want to remind myself before walking into a meeting.

Pearl Metaphor: Iterative development is like a pearl starting with sand and adding Calcium Carbonate. Instead we add functionality and usability over time.

Construction Metaphor: Moving a wall 3 inches to the left doesn’t cost a lot in terms of materials – sure you need a few more nails and maybe a few more 2x4s but it is going to cost a lot in man hours. Same is true for many late changes to a program.

Source: Code Complete

Monday, December 13, 2010

MVC View Not Found Misdirection

I recently came across the following error:

image

I was deploying to a discountasp.net and could think of an infinite causes of the problem. I decided to write a simple little code block to verify the view was there and accessible:

image

This confirmed that the file was in fact there. Sure that the problem had to be with discountasp.net, I sent them an email and slept on it. Their response was that it was my fault:

image

I tried searching their forum and found it lacking so did some google searching when I found this:

http://forums.asp.net/p/1592374/4038196.aspx

Which basically states the obvious – what about your master page? Yeah – what about my master page? Wait – why didn’t my master page publish…?

image

Well that would do it… no idea how that happened – I wouldn’t have changed it on purpose.

image

Problem resolved – hopefully this saves someone else some time.

Sunday, November 21, 2010

PDC Downloader

Below is a super simple (hardly resilient) PDC downloader. Feel free to compile and tweak it to your hearts content.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace ConsoleApplication1
{
     public class Video
    {
        public string title;
        public string description;
        public string url;
    }
    class Program
    {
        static void Main(string[] args)
        {

          

            var doc = XDocument.Load("http://videoak.microsoftpdc.com/pdc_schedule/Schedule.xml");
            var sessions = doc.Descendants("Sessions").Descendants("Session").Where(session => session.Descendants("DownloadableContent").Descendants("Content").Where(content=> content.Attribute("Title").Value.ToLower().Contains("mp4 high")).Count() > 0);
            var videos = sessions.Select(s =>
                                         new Video()
                                             {
                                                 title = s.Descendants("ShortTitle").Single().Value,
                                                 description = s.Descendants("ShortDescription").Single().Value,
                                                 url =
                                                     s.Descendants("DownloadableContent").Descendants("Content").Where(
                                                         content =>
                                                         content.Attribute("Title").Value.ToLower().Contains("mp4 high"))
                                                     .First().Attribute("Url").Value
                                             });
            var downloadableVideos = videos.ToList<Video>();

            var failedLog = new List<Video>();
            for (var count = 0; count < downloadableVideos.Count; count++)
            {
                var video = downloadableVideos[count];
                try
                {
                    DownloadFile(video);
                }
                catch
                {
                    Log("Failed to download " + video.title);
                    try
                    {
                        var path = video.title + ".mp4";
                        if (File.Exists(path))
                        {
                            File.Delete(path);
                        }
                    }
                    catch
                    {
                        Log("Failed to delete " + video.title+ ".mp4");
                    }
                }
            }
            var x = failedLog.Count;
        }

        private static void Log(string msg)
        {
            Console.WriteLine(msg);
        }


        private static void DownloadFile(Video video)
        {
            if (!System.IO.File.Exists(video.title + ".mp4"))
            {
                var webClient = new System.Net.WebClient();
                Log("Downloading " + video.title);
                webClient.DownloadFile(video.url, video.title + ".mp4");
            }
            else
            {
                Log("Skipping " + video.title + " - it has already been downloaded");
            }
        }
    }
}

XNA Conference–Lack of VB

I recently attended a user group meeting with http://augustadevelopers.org/ by Chris Williams http://geekswithblogs.net/cwilliams/Default.aspx covering XNA Games for Windows 7.

The new Windows 7 phone is living up to its hype. The little the I played with it  - it proved to be just as snappy as an iPhone. You won’t see me trading in my Droid just yet but credit is due!

I was surprised at the XNA conference to find that XNA currently doesn’t support VB. It is important to point out that the XNA team is small, and support for VB is on their (someday) feature list. The fact that it was even optional by MS came to me as a surprise.

I recently landed a new job where they prefer VB. This has forced me to take a step back and analyze the difference between C# and VB. I started out with VBA and VB.NET but in my last job I fell in love with C#. I now find myself wondering if I have a good reason to like C# over VB or if it is just a comfort bubble. I am finding that there are far more reasons to go with C# than VB.

One of the most convincing arguments has been the close relationship C# has with other languages. I have found very few developers embrace JavaScript and far fewer (none that I know personally) have been VB purists. JavaScript might as well be chinese to a VB purist, while a C# developer can stumble through it with little or no knowledge of the language rules.

Less important (for me) is the transition to other platforms like C++ and Java. VB has the advantage of VBA and VisualFoxPro but VisualFoxPro is already in end of life and I believe VBA is (or already has) gone to .NET which will mean that you can use either language.

Another point worth mentioning is that a majority of the documentation on the internet, in books, at conferences is all C#. Check out PDC – how many videos are in VB?

At the end of the day – I believe that each language has its strengths – and being flexible to the language is a must. But those that say you should be completely language agnostic ignore the fact that by focusing and embracing on a language – you become a master with the language. The language becomes a tool and as such – an extension of your creative ability. Being (too) language agnostic will create an implementation barrier as you are unable to gain momentum. Your intelligence is shifted from business logic problems and onto syntactic problems.

Sunday, October 31, 2010

Cool videos on WCF

http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2006/09/13/8875.aspx

Saturday, September 18, 2010

MCITP SQL Server 2008 Cram

Data Types:
  • Filestream - data is actually stored in NTFS NOT in SQL. SQL provides the filestream to access the data. For those that don't have experience programming or with file streams: a when not using file stream, the file must be loaded from the database into SQL memory, then served to the client. If the file is large, this consumes a great deal of memory. With filestreams we essentially stream the file to the client as we can - minimizing the strain on memory. Research shows that > 1 MB is more efficient in NTFS. Also NTFS doesn't share the SQL 2 GB Blob limit. Source
Performance / Monitoring
  • Data Collectors can be used to collect data from several sources, for example if you want to correlate performance issues it would be helpful to see what TSQL statements are running (otherwise you would use SQL Profiler), blocking and deadlock (otherwise you would use SQL Profiler or Dynamic Management Views), and system counters like cpu, memory, disk (System Monitor). Using Data Collectors you can capture all of these and correlate the data to determine when the server is slow, what query is running, and why.
  • Affinity - is the coupling of a thread to a processor. From an OS perspective - it is ideal to be able to move threads from one processor to another as the OS sees fit. So from an OS perspective affinity is a bad thing. So why would we have affinity - the SQL server can recognize that the data required by the thread is also going to be needed by other threads. So it can queue them together using affinity. When affinity is not set - the OS - not knowing better - will move the thread - then the required data (which is already in the preferred processor cache) will have to also be loaded into that processor's cache. Source 1, 2
  • Extended Events - ...
  • Partitioning - Vertical partitioning - think one-to-one relationship - which allows us to move a group of columns to another table. This can be very beneficial if we have a group of columns that are often needed together but not very often. Now the queries that happen more often will not have to include these columns (by not joining to this table). Horizontal partitioning - think union - move certain rows to another table (or filegroup). This is often done by moving records(rows) older than X (3 months) to a History/Archive table. This can greatly improve performance as indexes and the like don't have to reconstruct for every record but only those in the current (within 3 months) data. What is even cooler, is that this can be done at a lower layer by using file groups - so that to the client (user / application) it is just one table, but under the covers, using a partition function, old data goes to one file group while new data goes to another file group. Source

High Availability / Disaster Recovery
  • Log shipping - allows you to transmit your log (record of every transaction) to another instance - likely far away over serial link - if the primary server goes down - the data is not lost and clients can be pointed to this backup and resume operations
Security
  • Trustworthy - Database option - while a database is offline - someone could tamper with the database (ie, execute as SA, etc.). This trustworthy flag allows you to limit what the database can do. By default it is off and the database should not need trust beyond its scope. Source
  • EXTERNAL_ACCESS vs SAFE - SAFE is more restrictive as it doesn't allow you to be able to access external like files, networks, environment variables, registry. Source

Saturday, August 28, 2010

FREENAS and iSCSI for Server 2008 Clustering

Great walk through http://www.trainsignaltraining.com/how-to-setup-iscsi-drive-using-freenas/2009-01-19/

PS. Once the drive shows up in computer management on Server 2008 - it may be offline (with some bogus error about security policy). Right click offline and click online. You will likely also need to right click again and initialize. Then you should be able to right click the drive and partition.

Great video on Server 2008 Quorum http://www.youtube.com/watch?v=j9E1LgLwG88