/* BeejBlog */

Windows 8 – my initial perspectives

Decent developer oriented introduction to the new Win8 app dev paradigm called “Metro”: “Metro style apps using XAML: what you need to know” (by Joe Stegman, Group Program Manager for the Windows XAML team at the Microsoft //BUILD/ Conference, Sep.2011, Anaheim CA)

  • "Metro" is the name they're putting on building applications that embrace the touch/gesture/handheld era we're in now.
  • MS marketing is drawing a clear distinction between this and the "old school" "productivity" oriented desktop apps... one key pattern they're throwing around to distinguish the two is that these kinds of apps are highly CONTENT focused … raw content consumes the screen real-estate, traditional buttons (aka “chrome”) are hidden... gestures rule... the ubiquitous demo is the gesture-nav photo album... thumbnails are all you see to start... you flip around in the gallery with touch gestures... drill into images with another gesture, yada yada
  • XAML still seems to be an active technology (which is a relief since i spent the last two years self educating there... I must say that if nothing else, databinding in XAML is definitely a strong evolution... i've already seen evidence of frameworks coming up after taking XAML as the current pinnacle from which to consider improvement)
  • HTML5 + JavaScript looks to be the new UI go-to - which is interesting and wasn't discussed so i still have a mental gap about what that really means.
  • significant: the .Net framework is now "native" and it's morphed into "WinRT" (Windows Runtime)... i.e. these APIs are now bundled directly within the OS just like we've been familiar with Win32 all these years... this was a very logical step and i'm glad they made it... but this leads to the next point...
  • Metro/WinRT is Win8 only
    http://social.msdn.microsoft.com/Forums/en-US/windowsdeveloperpreviewgeneral/thread/d4850eb7-5fb2-45b6-9e89-cd13056c4797
    this will create some inevitable app fragmentation in the medium term... yet another choice for the harried mobile developer... such is progress... on a personal level i'm not really worried about it... i like seeing the upgrades... pretty much at all costs.
  • the demo showed that basic Silverlight/WPF XAML syntax is mostly cut/paste compatible in "Metro" XAML app.
    The basic development approach of Metro is the same as SL/WPF.
    • But you can tell from the tone, that there have been some breaking tweaks...
  • and of course there's outright new controls to get cozy in this new content/gesture focused paradigm.
    • i liked the part of the demo where he showed how trivial it was to slap on some new "flipview" type controls that handle all the momentum style scrolling where the scroll naturally speeds up, slows down and jiggles when it stops... we don't have to code that... we just drop the equivalent of a fancy listbox on the UI, bind it to a list of data and it does all that fancy footwork... that's pretty cool.
  • One biggish thing they mention is that *everything* is now async... i know SL was already pretty much that way anyway... in WPF you had a choice... the basic motivation is that it leaves the UI responsive... i.e. no longer possible to create an app where the Window locks up and greys out with "(Not Responding)"... i agree that this is a good thing overall... i've been coding this way and there's some nice language facilities in C# that make it not that much different from sync programming from a code readability and maintenance standpoint (e.g. inline anonymous functions passed to an async context).
  • of course, all this goes back to whether you think you need to tie yourself to a Windows platform in the first place... there's still pure web driven apps via HTML5, etc representing a strong viable option.

  • from a consumer standpoint, it'll be cool to have a solid tablet oriented flavor of Windows knocking heads with the Androids and iPhones out there.
    • Windows 8 of course fires up with the Windows 7 Phone style "tile" based "home page".
    • And the familiar old Windows desktop/Start Bar is just a flip away if you need that.
    • they're saying Win8 will run on both ARM and Intel so the whole mobile hardware spectrum is fair game.
      • after a quick scan, I'm not the only one thinking about Win8 on a contemporary Samsung Galaxy tab.

Wading into MVVM

  1. Commands rather than Events
    • instead of event handlers, think in terms of firing commands that will find their way to the corresponding command properties declared on ViewModels
    • i.e. use Command attribute of XAML widgets rather than Click event handler
    • MVVM popularized class RelayCommand works well as a lightweight ICommand implementation to use on ViewModels
    • or barring that, use the Expression Blend Interactivity DLL to map click events to Model object methods via "CallMethodAction" behavior

SQL Server Table-Valued Stored Procedure Parameters <=> ADO.Net

Nutshell:
  1. Declare a User Defined Type (UDT)
  2. Declare a stored proc parm of that UDT
  3. Fill an ADO.Net DataTable with the same columns as the UDT
  4. Assign the DataTable to a Parameter of an ADO.Net SqlCommand corresponding to the sproc
Notes:

Code Examples:
  1. File_UDT.sql
    CREATE TYPE File_UDT AS TABLE
    (
      FullPath varchar(900) PRIMARY KEY, 
      ModifiedDate datetime, 
      [Size] bigint
    )
    GO
    
    GRANT EXECUTE ON TYPE::dbo.File_UDT TO PUBLIC
    GO
  2. Files_UploadCompare.sql
    CREATE PROCEDURE [dbo].[Files_UploadCompare]
    @BackupProfileID INT,
    @NextDiscNumber INT = NULL OUT,
    @AllFiles File_UDT READONLY -- <= *****
    AS BEGIN
            
    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
    
    -- new approach, simply return all files which don't match something already in the database 
    -- then we don't have to worry about partial results left in the tables ... 
    -- we just upload the current batch of files when we're with each burn and then start fresh with the next batch selection from there
    -- there will be no records in FileArchive unless they've been put there specifically as marking a "finalized" MediaSubset
    
    SELECT *,
      CONVERT(BIT, 0) AS Selected,
      CONVERT(BIT, 0) AS SkipError
    FROM @AllFiles a
    WHERE NOT EXISTS(
      SELECT 1
      FROM FileArchive fa
      JOIN [File] f ON fa.FileID = f.FileID
      WHERE f.FullPath = a.FullPath AND fa.ModifiedDate = a.ModifiedDate AND fa.Size = a.Size
    )
    
    DECLARE @IncrementalID int
    SELECT @IncrementalID = MAX(IncrementalID) FROM [Incremental] WHERE BackupProfileID = BackupProfileID
    
    SELECT @NextDiscNumber = isnull(COUNT(1),0)+1 FROM MediaSubset WHERE IncrementalID = @IncrementalID
    
    END
    
  3. FileSystemNode.cs
    static private void ScanFolder(FolderNode folder, DataTable IncludedFiles)
    {
      DirectoryInfo dir = new DirectoryInfo(folder.FullPath);
      FileInfo[] files = dir.GetFiles("*.*", folder.IsSubSelected ? SearchOption.TopDirectoryOnly : SearchOption.AllDirectories);
      foreach (FileInfo file in files)
      {
        DataRow r = IncludedFiles.NewRow();
        r["FullPath"] = file.FullName;
        r["ModifiedDate"] = file.LastWriteTimeUtc;
        r["Size"] = file.Length; //megabytes
        IncludedFiles.Rows.Add(r);
      }
    }  
    
  4. MainWindow.xaml.cs
    using (Proc Files_UploadCompare = new Proc("Files_UploadCompare"))
    {
      Files_UploadCompare["@BackupProfileID"] = (int)cbxBackupProfiles.SelectedValue;
      Files_UploadCompare["@AllFiles"] = IncludedFilesTable; // <= ******
      WorkingFilesTable = Files_UploadCompare.ExecuteDataTable();
      lblCurrentDisc.Content = Files_UploadCompare["@NextDiscNumber"].ToString();
    }
Tips:
  • (from here): If the login that SqlCommandBuilder.DeriveParameters is run under does not have permission to access the UDT, no error will be thrown - the method will return successfully, but the SqlCommand.Parameters collection will not contain the UDT parameter.!!!
  • Granting permissions on a type (from here): GRANT EXECUTE ON TYPE::dbo.MyType TO public;
Links:

CAC (SmartCard) Enabling ASP.Net on IIS

  • The only configuration settings required are (IIS7 screenshots below):
    • Require SSL (this represents server side)
    • and either Accept or Require Client Certificates … “Accept” will populate the SmartCard’s cert info to your ASP.Net Request object (if it’s provided) but won’t deny access if one hasn’t been provided, “Require” will deny access unless a valid SmartCard Cert has been provided.

Tips:

  • One key thing to be aware of how this works is that the server will send a list of Trusted Root Certificates down to the client/browser and then the browser will compare that list to the Trusted Roots represented by the CAC present and only if there’s a match will it prompt for the Certificate and PIN input.  Therefore, both the Server and the client must have the same Trusted Root Certs installed for this to work, the easiest way to do this for the DoD CAC’s is to grab the latest install_root.exe and fire that up.
  • Another key thing I discovered was that after you get the certs installed, go ahead and do a reboot, I was still getting 403 access denied errors that simply disappeared after I rebooted.
  • Throw these lines in a ASP.Net wizard generated project’s Default.aspx to see the basic Cert info… the .Subject property is the juiciest looking info, there may be other properties of value.
    • <%=Page.Request.ClientCertificate.IsPresent%>
    • <%=Page.Request.ClientCertificate.Subject%>
  • It’s probably also helpful to go ahead and make sure your server side SSL cert is properly named & not expired, such that you don’t get any warnings when you browse to the page… I was getting some errors related to that when I was working with the Client Cert’s required.
    • this reference was helpful, see the section titled “Generate a Self Signed Certificate with the Correct Common Name”
    • this is the basic command you need to generate your own SSL cert for testing: SelfSSL /N:CN=www.whatever.com /V:9999
    • find SelfSSL in the IIS6 Reskit

image image

Self Refresher

  • .Net Framework v4 New Features
    • Parallel Linq Extensions
  • C# 4.0 New Features (all good stuff IMPO, variance being the hardest to grok)
    • Named and Optional Parameters – already use this quite a bit
    • Dynamic Support – handy way to ignore the complexity of ‘dynamically’ generated type declarations (e.g. linq results & COM Interop)
    • Co/Contra-Variance – primarily intended to make .Net Framework methods with Generic type parameters like IEnumerable<T> “work like we’d expect” as is often quoted in explanatory texts (look for Jon Skeet and Eric Lippert).  It removes a couple rather unexpected annoyances that C# 3 would’ve snagged on.
      • Covariance represents “upcastable”.  Concerns types coming out of an API.  Represented by “out” keyword, e.g. public interface IEnumerable<out T>
      • Contravariance is “downcastable”. Typically concerns types passed into an API.  e.g. public interface IComparer<in T>
      • Invariance is when something must go both in and out of a method and it can’t be declared differently on either side of the interface, it must be the same coming and going.
    • COM Interop
      • Dynamic Vars
      • Optional Parms
      • Optimized interop assembly file size
  • WPF4 New Features
    • New Controls – *DataGrid*, Calendar/DatePicker
    • Touch
    • Fancy Win7 Taskbar support
    • Easements
  • Silverlight 4 New Features
    • New Controls – ViewBox (auto resize), RichTextBox
    • Out-Of-Browser Support
    • Printing support
    • Drag and drop, clipboard access
    • More WPF compatible XAML parser
    • DataBinding improvements – StringFormat, collection grouping, INotifyDataErrorInfo or IDataErrorInfo support,
    • WCF Data Services enhancements – Direct POCO mapping via Linq queries on Open Data Protocol feeds.
    • Dynamic Support