Wednesday, September 14, 2011

Windows 8 Platform and Tools - C#

Heard some people mentioning the .NET/C# won't be part of Windows 8. Seems like it would have been a crazy move by Microsoft. Good to see it up there in the Windows 8 Platform and Tools diagram during the build conference (@1:43:52).

Or maybe its just .NET that is getting replaced by WinRT - WinRT: An Object Orientated Replacement for Win32

Update: Replaced isn't right. Seems like WinRT is more like a sand-boxed alternative to using the full .NET stack. This will allow Microsoft to make assurances about applications that are downloaded from the application store. See WinRT demystified.

Tuesday, September 13, 2011

Gettings started with WP7 development

Thought I'd jot down some things I found useful getting started with Windows Phone 7 development

Tips

  • Using a physical keyboard with the WP7 emulator
  • You can't at present update the application tile frequently enough to make something like a clock.
  • Ensure you test your application with both the light and the dark background themes to ensure the buttons etc... are visible.
    I've been caught out by using images for buttons than only worked on the dark background. By using a canvas to draw the images instead I was able to handle the background change based on a phone brush.
  • A Custom Font can be used to create monochrome icons that can easily scale. E.g. http://fontstruct.com/
  • Beware when you are submitting the app that you will be using Silverlight forms, so your web browsers built in spell checker probably won't pick up your mistakes.
  • Take screenshots of the running app after detaching the debugger. Then the performance counters won't appear.
  • Remember to increment at least the Minor Version number in the AssemblyInfo.cs before resubmitting the xap.
  • Save space by compressing Content and then extracting it with something like REALLY small unzip utility for Silverlight

See Also:

Sunday, September 11, 2011

Using a physical keyboard with the WP7 emulator

The Windows Phone 7 on screen keyboard is nice, but when I'm running the emulator I often wish I could use my physical keyboard to speed things up.

Apologies if this is old news, but I'm new to this.
Turns out it is really easy. Just press Pause Break on the physical keyboard to toggle between using your actual keyboard and the phones touch screen in the emulator. Page Up and Page Down can also be used.

Your physical keyboard will be used to simulate a hardware keyboard on the phone so there can be some odd mappings. See Keyboard Mapping for Windows Phone Emulator.

Friday, September 9, 2011

Automated downloading of an entire Salesforce Data Export

UPDATE: This is now available for free as part of the Fuse IT SFDC Explorer.


I recently needed to download an entire Salesforce Weekly Data Export where there were 62 zip files at 130 megabytes each to individually select and save locally.

Rather than manually working through all the downloads I extended S4S/G4S to download and save all the files.

You pass it:

  • A SalesforceSession, which can be established a number of ways. Typically with a Salesforce user name, password, and security token.
  • an export id. E.g. (092xxxxxxxxxxxx). This can be seen in the download Urls
  • The base name of each export file - E.g. WE_00D9xxxxxxxxxxxAAA_{0}.ZIP
  • the number of files in the export - e.g. 62
  • where to save the files to locally

S4S/G4S will then work through all the zip files and save them to the specified directory.
In the future I could probably automate getting the export id and base file name. But for now I can churn through all the weekly data exports with no user interaction.

Tuesday, August 30, 2011

TechEd 2011 Round Up / Summary

I've summarised some of the most interesting/important parts of my TechEd 2011 NZ notes here.

WUX206 - Pimp My App - 3 screens and a challenge

DEV302 Lesser Known Design Patterns

  • Null object pattern - Avoid the ceremony of checking if something is null before using it.
  • Command pattern - Alternative to adding additional methods to interface by instead creating new objects.
  • Object Emancipation - Objects are more than just buckets of information. Give your objects responsibility for managing their own State.
  • State Pattern - Partially change the type of the object by swapping out behaviour based on state.

DEV301 Going Mobile: Any System to any Mobile Device

  • With REST. No URI construction on the client; follow the hyperlinks instead. Dependency on the namespace.
  • With REST. DO NOT define new verbs; use GET, PUT, POST, DELETE

WUX101 HTML 5 Hands On

  • Polyfill - A way to support HTML 5 features in older browsers using JavaScript shims.
    What is a Polyfill?
    A polyfill, or polyfiller, is a piece of code (or plugin) that provides the technology that you, the developer, expect the browser to provide natively. Flattening the API landscape if you will.
  • Rather than UserAgent sniffing using feature detection with something like Modernizer

SIM201 Hack-Ed - The Attackers are coming!

  • SQL Injection is still the number one threat to most websites.
    • SQLMAP - a python script fpr automatic SQL injection and database takeover
  • Cross Site Scripting (XSS) variations are still a serious issue. They can be weaponized with a server for the hacker to send instructions to the users browser.
  • Unescaped twitter feeds can be used for XSS attacks.
  • Local proxies for security testing Paros - "Through Paros's proxy nature, all HTTP and HTTPS data between server and client, including cookies and form fields, can be intercepted and modified." Burp proxy - "an intercepting proxy server for security testing of web applications. It operates as a man-in-the-middle between your browser and the target application"
  • It's important to check that the credit card authorized amount was the amount expected amount.

DEV311 A Practical Developer's Introduction to F#

  • A functional language that is native to .NET. It can call and be called by other .NET code.
  • Is well suited for Scientific and numerical computing, Finance, Insurance, Parsers, and Domain Specific Languages
  • Pipeline operator |> makes chaining operators easier to read. Kind of similar to extension methods in C#

DEV309 - Visual Studio vNext Directions

SIM305 - The Attackers are Coming!

  • SQL Injection - As a start, look for calls in SQL to sp_executesql, exec that aren't using parameters correctly
  • Cross Site Scripting (XSS) - With ASP.NET use HttpUtility or AntiXSS Html and Attribute Encode. Consider the Security Runtime Engine - Safety Net
  • Enforce Session logout server-side rather than just removing the cookie client side
  • Set 'httponly' and 'secure' flags on cookies.
  • Cross Site Request Forgery - ASP.NET - Set the ViewStateUserKey in the OnInit of a base page. Used in addition to the MAC Key to hash the ViewState.
  • Send the following HTTP headers when server content uploaded by users:
    • Content-Disposition: Attachment
    • X-Download-Options: noopen
    • X-Content-Type-Options: nosniff
    • Content-Type: [mime-type]

DEV401 Advanced .NET Debugging

  • WinDBG with the SOS Extension from the .NET framework team can make debugging specific classes of bugs much easier.
  • Memory Leaks
  • Deadlocks
  • Race conditions
  • Dumps form production applications (where it isn't otherwise possible to attach a debugger)

DEV204 Tools I use to improve my development

  • Mindscape Web Workbench - Add Sass, Less & CoffeeScript support to VS2010
  • Web Standards Update for VS2010 - Adds support for HTML5 & CSS 3 to VS 2010 SP1
  • Nuget - Manage common packages and dependencies for your projects
  • Chrome Developer Tools - "Pretty Print" to reformat compressed Javascript.

DEV306 The WCF Web Community - REST, jQuery and WebSocket

  • fiddler - a Web Debugging Proxy which logs all HTTP(S) traffic between your computer and the Internet. Fiddler allows you to inspect traffic, set breakpoints, and "fiddle" with incoming or outgoing data.
  • OData is useful in .NET to .NET scenarios
  • RIA Services - OData endpoint that can be queried over LINQ.

DEV312 Getting the most from Visual Studio using Managed Extensibility Framework (MEF)

  • MEF is a framework for creating extensible applications and consuming plug-in parts.
  • Visual Studio 2010 editor extensibility is built through MEF.
  • The VS2010 Find Box is also a command box when prefixed with >
    • > File.CloseAllButThis
    • > File.CopyFullPaths
    • > Tools.GoToCommandLine

DEV308 Visual Studio LightSwitch - Beyond the Basics

  • Submit pipeline
    1. Pre-processing
    2. Process modified entities
    3. Execution – LightSwitch passes all of the changes to the underlying data provider for processing
    4. Post-process modified entities
    5. Post-processing

WUX205 Kick starting your web development with ASP.NET 4.0

DEV303 Making Asynchronous Programming Easy

DEV403 Dynamic and Meta-programming in .NET 4

Online sessions

Breakout Sessions Other Videos
COS302 | Line of Business in the Cloud 2011 Tech·Ed New Zealand Keynote
COS305 | Guidelines and Best Practices for Migrating .NET Web Services to the Azure Platform Welcome to NZ’s Premier IT Conference – Tech·Ed 2011
DBI207 | Trade Me: 0-70 million pages in 0.34 Gigaseconds What is happening in the Hub?
DBI208 | Project "Crescent" the next level of SQL Server BI Data Visualisation: Demos Galore End Of Day 1 - 2011 Tech·Ed NZ
DBI304 | Building a Mission-Critical High Availability Solution Using AlwaysOn HP - Principal Sponsor of 2011 Tech·Ed New Zealand
DEV311 | A Practical Developer's Introduction to F# TechFest MC- Dai Henwood
DEV403 | Dynamic and meta-programming in .NET 4 Interview with Main Act - Fat Freddy's Drop
DPR202 | Good architect vs. Bad architect (coming soon) Highlights from TechFest 2011
DPR209 | Hitchhiker’s Guide To Technical Leadership 2011 TechEd New Zealand - Wrap Up
DYN301 | A Developer's Guide to Integrating Microsoft Dynamics CRM 2011 & SharePoint 2010 Tech Talk Interview with Andrew Ehrensing
DYN304 | When CRM 2011 Goes Viral Tech Talk Interview with Rob Reinauer
EXL302 | Exchange 2010 High Availability Concepts Tech Talk Interview with Scott Schnoll
INO204 | Microsoft Research - Technologies from MSR that YOU can use Tech Talk Interview with the UPT Digital Kids
INO301 | Transforming Our Future Today Tech Talk Interview with Steve Smith
OSP304 | The SharePoint 2010 Search Service Decoupled Tech Talk Interview with Debbie Ireland
SIM201 | 2011 Hack-Ed - The Attackers are coming! Tech Talk Interview with Carolyn Chau
SIM302 | Creating a Federated Extranet with ADFSv2 and SharePoint2010 – Notes from the field Tech Talk Interview with Brendon Ford
SIM305 | Hack-Ed - Boost your defences! Tech Talk Interview with Team Unite
WCL303 | How to develop a successful Desktop Strategy (Thin, Thick, VDI... ) Tech Talk Interview with Eric Chang
WCL304 | How to secure and manage Consumerisation of IT Tech Talk Interview with Team OneBuzz
WPH204 | Windows Phone First Up / All Up Tech Talk Interview with Michael Niehaus
WPH305 | Peeking at the Source of a Successful Windows Phone App Tech Talk Interview with Regan Murphy
WSV302 | Get Out of Dodge: Migrating to Windows Server 2008 R2 x64 Tech Talk Interview with Dr Nitin Paranjape
WSV402 | Network Access Protection (NAP) in the Real World Tech Talk Interview with Miha Kraljis
WUX207 | Releasing Trade Me's Latest Project Tech Talk Interview with Thomas Lewis
WUX208 | Responsive Design - The View of the World Depends on the Glasses I Wear

Sunday, August 28, 2011

DEV403 Dynamic and Metaprogramming in .NET 4

Presenter: Ivan Towlson
Apologies that this post is fairly nonsensical. I've put my raw NZ TechEd 2011 notes up here for my reference. I'd like to think that I'll refine them over time, but that probably won't be the case.
TechEd Online

What C# dynamic keyword does

dynamic keyword - "I know better than the compiler" - deferred look up until run time.

Old COM libraries - like Microsoft Office 2010.

No intellisense.

MVC ViewBag is of type dynamic. DynamicViewDataDictionary

Inherit from dynamic object. 

DynamicObject.TryInvokeMember

DynamicProgramming - "It's all just string diddling. Diddling is a technical term." 
"Really is is a fancy way of passing strings into a method."

named arguments

Runtime Code Generation

Activator.CreateInstance(type); // Very slow as it uses reflection

Expression.Compile() turns an abstract tree into executable code.

Turn reflection based code into compiled expression trees to improve performance.

Create a class that implements an interface at runtime. Interact with it at runtime.
DynamicAssembly

AssemblyBuilder

"I'm not encouraging you to write code you don't understand. That's what the Entity Framework Generator is for"

DynamicMetaObject


C# Expression Trees

Dynamic operator using Dynamic Language Runtime

DEV303 Making Asynchronous Programming Easy

Jeremy Boyd
Apologies that this post is fairly nonsensical. I've put my raw NZ TechEd 2011 notes up here for my reference. I'd like to think that I'll refine them over time, but that probably won't be the case.
Synchronous -> Wait for result before returning

Asynchronous ->Return now, but call back with result

Async benefits

 UI responsive: Frees UI thread for interaction
 Server scalability: Thread can be reused for other requests

Connected Systems - Increasing latency due to service calls
Use Async only frameworks -JavaScript and Silverlight

Rise of Async only environments
 Node.js - Promotes a totally async environment
 What is Node.js?

Next version of C# will have features specifically for asynchronous coding.
IAsyncResult Pattern (APM)

.NET 2
Event Based Async Pattern (EAP)
 Method name ends in Async

New Extensions
 Task based Async Pattern (TAP)
 New keywords async and await
 Already available in .NET 4. - Task Parallel Library

Goals:
 Compile time code generation into async patterns
 Supports cancellations
 Easy concurrency management

await keyword
 - used in front of an async call.

async keyword
 - indicates to the compiler that this body of code will run async.

Task - represents the body of work being done.
 Task
 CancellationToken
 taskMethodNameAsync

Compiler is transforming code into the Task Asynchronous Pattern
Task performs initial setup and then installs a callback at await.

.MoveNext()

So its like an async within an async...

Handling Progress

Progress

Handling Cancellation

CancellationTokenSource

Support will go through the framework and to WPF, Silverlight, etc...

Only available in full .NET framework at this time.
 Planned to be supplied in `asynchronous work.

Parallel LINQ (PLINQ)

.AsParallel() extension
Utilizes parallel hardware for LINQ queries
 Partitions and merges data intelligently
 Supports all .NET Standard Query Operators
 Works for any IEnumerable
 
 Built on top of the Task Parallel Library.

.AsOrdered()

Try using .AsParallel() when working with LINQ over in memory objects.

TIP: Async CTP requires a clean install of VS2010 SP1 to install into.