November 2008 I had the opportunity to spend a full week at the TechEd EMEA in Barcelona. Here are my notes:
Monday
OFC65-HOL silverlight Web Parts
- Render XAML file in web part in CreateChildcontrols
- Create custom signature field with xaml rendering
- Reference Silverlight v 2.0
- Place XAML files in 80/ClientBin folder
Keynote
- New features in VS 2010, available 09/2009
- Sequence diagrams
- Objectgraph for complete solution or assembly
- Debug symbols/MVI recording while testing
- Test-case integration, confirmed while testing, create bug in TFS functions that commits test history
- Editor rewritten in WPF
- Plenty of new hover functions
- Lab management: Provision test environment in TFS, also recorded in bug history
- CTRL-’.’ feature to create class and method stubs (incl. placemnet option)
- JQuery integration with intellisense
- Snippet support via text in editor
- Config transformations that go with build configs such as web.Debug.config
- Web deploy via zip files
- New web deploy tab in properties
- SharePoint tools: Server exploer (SPM), templates, WYSISWYG for SP pages, Packaging explorer
- ThreadBlocking view and performance analyzer
- Multicore syntax (C# 4.0?): parallel_for
- Windows 7 has touch screen support
- Windows Azure – cloud services (hosted)
- Geneva for security (SafeWhere?)
- Lifecycle tools can be downloaded from MSDN
DVP03-IS Agile development with VS
- Stephanie Saad
- Agile task distribution: Pick a task of the pile
- Annotation shows WIs besides the code
- Policy at check-in: Testing (run before check-in), Code analysis (configuration can be copied locally via context menu)
- Continiuos integration build: Build definition, trigger on check-in, build explorer to check result
- Database unit testing and refactoring: database in TFS, refactor (eg. rename a table), unittest for stored procedures (TSQL)
- Code metrics: complexity, lines of code
- Dataplan genration: generate testdata automatically, CSV import, cannot handle data migration
- Schema comparasion tool
- DB features are part of the database VS version (now part of dev version also!)
- MSDN process templates (about 25 templates, mostly free)
- Check the process guidance on SP site
- Planning tools with TFS integration
- VS 2010 features:
- WI hirarchy: User story, tasks, sub tasks, drag and drop, Excel roundtripping (publish, refresh)
- Excel spreadsheets for: Capacity planning, burndown chart, velocity
- RS reports: burndown, velocity, story drill-down with unit test results
- Excel reports: click Create Report in Excel, 45 s per report for generation, WI count by security/priority
- SP quality dashboard, test dashboard
- Gated check-in: Extends CI, shelves changes, runs ci and can reject on fail, is a new trigger in policies
OFC301 SharePoint Features
- Ted Pattison
- Webdav protocol to interface with content database, used for SharePoint configuration
- 12-hive: WSS system directory (12-hive is a WSS 2.0 term)
- Only site columns require the curly braces in GUID, optional in all other cases
- Feature.xml must reference all files in feature folder as those are not referenced else where
- Feature install: adds entry to configuration database
- Feature install scope is always farm wide
- STSDEV can create WSP package, uses target files for deployment (instead of batch files)
- Uses DDF files to avoid low-level interaction with cab API
- Download demos from http://tedpattison.net
- Best practice for layouts sub folders: Use CompanyName.SolutionName
- Custom site pages: page templates, page instances are created based on template, change in template is reflected on all instances, can be ghostable or not
- To avoid SharePoint Designer modifications the SPFile event handlers can be used in eg. default.master
- Use module to provision custom site pages, web parts pages, web part pages with web parts included
- Declaritive statements are always executed before code: <declarative> -> FeatureActivated, FeatureDeactivating -> <declarative>
OFC79-HOL Open XML
- Linq to XML: XElement, XDocument, XAttribute
- Add custom xml to word documents
- Modify databindings of word controls
Tuesday
OFC75-HOL Variations for multi-language
- Create variation
- Ordering in browser
- Add variation labels
- Use publishing workflow to distribute changes
OFC07-IS STSDEV
- Project on codeplex
- Two modes: create VS solution, create from 12-hive folder
- No VS integration
- Custom MS build tasks (target files)
- Compatible with MS-Build
- Solution.config: holds STSDEV configuration, eg. solution id, SafeControls
- Buildinfo.txt is build log
- Template places code-behind of application pages in root folder of project
- Can only handle one DLL (the auto created VS project), does not handle any references
DVP303 Bringing the best out of multicore systems
- Motivation: Because of multi-cores you do not get much performance gain with sequential programming in future
- Supports native and managed code
- VS/.NET support: .NET thread pool, PLINQ, task parallel libarary (TPL), debugging and profiler tools
- Steps: define goals, measure existing performance, tune, identify parallelism oppurtunities
- Use parallellism only when necessary as bugs are not easy to reproduce (different execution path)
- But take adavantage of new possibilities from beginning with parallelism
- Profiling options in VS 2010: CPU sampling, instrumentation, thread contention, concurrency analysis
- Tracing tools: TimingBlock, MeassurementBlock, Tracing
- Amdahls law: Natural limit to how much of a program can be executed in parallel
- VS 2010 concurrency analysis (vista and higher): CPU utilization, thread blocking, core execution
- TIP: Use buffered IO to reduce blocking issues
- TIP: Use thread pool for parallelism (will make best choice based on current hardware)
- TPL elements: Parallel.For, Parallel.ForEach, Parallel.Invoke
- Coordination Data Structure (light locks), MPI.net
ARC307 Design for testability
- Book: The art of unittesting
- Web: http://artofunittesting.com
- Challenge: Isolation from dependencies, control all inputs and outputs
- Dependency injection via: Interface and constructor, properties, factory, virtual methods
- Global cutting concerns: Common dependencies for most of the code -> use inversion of control (IoC) with eg. Unity Applicaiton Block or Castle.Windsor or smart object factory
- Wrapping DateTime.Now: Interface and IoC, static class with get and set or function
- No configuration: Virtual method to encapsulate call to configuration manager
- Database: Use transactions to roll-back
- Singletons: Use containers or put singleton logic in separate class
- Use unittest in architecture requirements to forace testable implementation
- Guidelines: no singletons, IoC, virtual by default, use factory for object creation, follow S.O.L.I.D design principles (http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod)
- See Typemock Isolator for testing of statics
WIN302 Composite WPF and Silverlight (PRISM)
- Motiviation: make application customizable, testable, dynamic and extensible
- PRISM 2.0 release beginnig of 2009, seven core concepts, codeplex project
- Modules: loaded with ModuleLoader, support background loading
- UI composition: regions as UI containers, view is pushed into region (bottom-up) or top-down
- MVP or MVC: central is the separation of concerns – UI and applicaiton logic
- Multitargeting: Silverlight and WPF are not binary compatible, most code can be reused, required to use file links (see ProjectLinker VS add-in)
- Silverlight and WPF toolkit make both more alike, this will be improved (but not perfect) in .NET 4.0
OFC02-IS WPF and WCF VSTO
- Office business applicaitons (OBA) programmed with VSTO
- Two approaches: document centric (document refers assembly), application centric (add-in)
- WinForms control can bind directly to ActionPane
- WPF controls can be hosted with an ElementHost
- VSTO programming is dependent on .NET and Office version used, you need to create different code for the various constellations
- Office Globals object provides access to office object modell
- Excel: ThisWorkbook.cs, startup event, register control with action pane
- XAML describes .NET objects
- UserControls can be integrated in Outlook in form region, different places and positions
- Microsoft Blend tool to create XAML (designer tool)
- Outlook deployment: Remove add-ins does not always work fully, need to remove registry entries manually
- Excel code does not require cast, is perfect at formatting strings correctly
- Use VPC for Outlook development
- Office object modell is now published, varies depending on application (origin)
- Send mail to Tim for demo code: timhuck@interknowlogy.com
Wednesday
ARC308 Future of unittesting
- Microsoft comes with test frameworks for threading applications in VS 2010: Chess, Racer. These build on top of MS Test
- UI testing does not really work, check project white for win forms and WPF
DAT41-HOL Microsoft SQL Server Analysis Services with Microsoft Office Excel and Excel Services
- Create Excel workbook
- Connect to data source
- Use CUBExxxx commands to generate sets, columns and calculations
- Publish spreadsheet to MOSS 2007
OFC309 Lauching an Internet facing MOSS 2007
- Performance testing, packaging should be integrated in project
- Name ActiveX control: MSKB 931509 or Andrews Javascript
- Minimize page payload
- Page payload: SharePoint has table based design, which is a bit slower than CSS based (here only first hit is expensive than the CSS is cached), lazy load of core.js (50 to 70 kB) can speed up load (is used mainly for Site Actions menu), via custom control that renders an iframe to async load the script file, see Andrews pointers
- Two empty JS functions to supress ActiveX control, there also other methods, check pointers
- CAS policies: use them especially on foreign code
- Application page lock down feature: hidden feature that is automatically activated, check that this is done, normally users with limited access can see pages such as AllForms.aspx, the feature disables ViewApplicationpages right for this group
- Page output cache: set at site level or site collection level, custom profiles, separate for registered and anonymous users, deactivated per default
- Object cache: default 100 MB, used with eg. CQWP, check CacheHitRatio performance counter for amount, should be > 90 %
- Disk-based cache: web.config BlobCache element, caches files from content db on frontend, use max-age setting to keep files longer on client, use max-age="86400" for 24 h
- Two environments: one for production, one for authoring – set different cache policies for each of them to optimize for read-only and read/write
- IIS compression: static for HTML and dynamic for ASPX, …, configurable in IIS (dynamic is per default off)
- Check-out Safari WebInspector, has payload visualization
- IIS 7 can automatically activate/deactivate dynamic caching depending on CPU load thresholds
- Disable manually following SharePoint functions for anonymous users: user presence information, Blog API, incoming email
- Check-out Andrews resources
- SharePoint variations: use for identical copy of one site/structure in multiple languages, can be customized via custom workflow eg. using multi-language file format
Parallel Programing for managed developers
- http://www.danielmoth.com/blog
- VS 2010 and .NET 4.0 talk
- Released already as CTP
- Current servers have up to 64 cores, 256 cores are supported in Windows 7
- Use threads to use multiple cores
- Thread.SpinWait?
- Old way: start to Threads with new Thread(delegate…) and Thread.Join(), no scheduler being used, will run on one core only
- New way: Task and Task.Wait(), here the scheduler is used
- Thread pool enhancements in 4.0:
– local LIFO queue per task
– all local queues are checked when global or current local queye is empty
– rich API of Task class
– implements parent/child relationships
– Self replication (used with Parallel.For)
– Return value of an executed delegate is in Task.Value
– Good exception handling: will return one exception with all occured exceptions in the inner exception
- Terms: fine grained parallelism (task), structured parallelism (TPL), PLINQ
- Parallel.ForEach(IEnumerable, delegate…)
- Parallel.For
- Parallel.Invoke – takes an array of delegates as parameter
- LINQ two flavours: IEnumerable (delegates), IQueryable (Expression trees)
- PLINQ: AsParallel() extension method, works on LINQ to objects, casts internally to IParallelEnumerable that spins off tasks
- Coordination data structures: thread-safe collections, work exchange, …
- Check-out: http://msdn.com/concurrency
SQL Index tuning
- Find a balance: manually index foreign key constraint and use database tuning advisor
- Clustered index performs usually better, depends on the number of returned items, if greater than about 1 % a non-clustered is faster
- Query optimizer determines whether to use a scan or bookmark lookup (see query execution plan)
- Index covering: index that has all the data to satisfy all requests
- Non-clustered index contains all columns and rows
- Clustered index contains one column and all rows
- Covered index has selected columns and all rows, sequence of columns matters
- SQL 2008 server introduces filtered index: selected columns and selected rows
- Use sp_helpindex to show indexes and DBCC SHOWSTATISTICS
- AND Tuning: For equality find the most common combination, for ranges find the most selective
- OR Tuning: Include clustered key columns in select list
- JOINS tuning: Use covered indexes or indexed views
MOSS 2007 publishing guidance
- Updating content types: Check Patterns and Practice Guidance
- Use Web Parts only for functionallity as these do not have history
- Development stategy: Use UI and than featurize with Andrews tools afterwards (does not work for workflows)
- Check SharePoint Project Utility templates for VS
- Remote Shell in Windows 2008 server will be used instead of PSEXEC
SharePoint custom fields
- Motivation: extend OOTB behaviour, validation, data source, properties
- Cons: Does not inherit everything, does not integrate with office (except for base type rendering), read-only in datasheet view, not included in Excel when exporting a list, can require custom code to integrate in search (if field does not contain exactly what user sees)
- XML definition, class library with field class
- SDK says not to inherit from SPField
- Optional items: ascx, field rendering control, validation, field editor control
- Common overrides: Default value, GetValidatedString, FieldRenderingControl
- FieldControl inherits from BaseFieldControl, Value returns what will be stored in DB
- GetValidatedString: Only strings are stored in content DB, throw SPFieldValidationException on validation error
- Custom field types definition starts with fldtypes
- Use SPContext to get access to current list or list item, make that approach works for site columns and in a list
- Rendering pattern: CAML to define rendering in view, edit form, new form…
- Check-out www.sharepoint-tips.com
Debugging managed code
- COM objects: DebugDiag, free tool, good for hangs, crashes, only native debugging
- MEM overflows: windbg.exe, native debugger, free, creates process dump or live debugging
– Check performance counters: bytes heap vs private/ virtual bytes, tells you whether leak is in managed (heap) or unmanaged code
– Check blog.msdn.com/tess for detailed debugging instructions
– Open dump in windbg
– Load SOS for .NET support
– Look at stacks or memory
– GCROOT to find objects not released
– VS 2010 will contain dump debugging tool
– Example of dropdown list saved in session state creates memomry leak as whole page is stored on each request
- GC happens when need for Gen 0, Gen 1 and Gen 2 memory, not by timing, when a generation is full, GC removed data with handle, compacts memory and moves to lower Gen
- Close objects with finalizer as soon as possible
- Compiler optimizes string concatenations when no logic is involved
- DLK command in SOSEX to detect a deadlock
- CLRSTACK to show managed stack
- SYNCBLK shows current locks, MonitorHeld: 2 per thread waiting and 1 per thread that has lock
- Logging with performance counters, data collection sets (vista), .NET CLR xxxx, % GC time, GEN 0, 1, 2, can create alert, make sure that trigger alert action is only invoked once
- Performance impact: counters have small impacts, creating dumps has big impact
- ADSPLUS in crash mode to generate auto dumps or setup debugdiag (requires install) or windbg (does not require install), windbg auto attaches after crash others do not
- Use performance counters to verify your code: eg. count exceptions when running unittest or check mem usage and cpu resources
MOSS search customizing
- Search server 2008: extends MOSS 2007 search, is part of infrastructure update
- Better administration (dashboard), federation support, performance and stability
- Customizing search center UI:
– Add tab, create new pages, set scope and result page
– XSL editing in SharePoint Designer, get source XML with simple XSLT, manage data sources, add XML file
– Tabs work only with publishing site
– Federation web parts are not sealed
- Query object model: SQL or keyword syntax
– Create query object
– Execute
– Engine returns ResultTable
- Search query web service: for remote access to query engine, has Query and QueryEx web method, located at /_vti_bin/search.asmx
- Federation: Queryies multiple search engines, results cannot be merged, requires engines to be open search 1.0 or 1.1 compatible and return XML, eg. yahoo or live search
- Federation connectors:
– if search engine does not support open search or does not return XML
– can be ASPX page or ASHX handler
– eg. search in database, google, virtual earth
– work-around: use live search with site setting
- NetworkCredential class for running in users context
- Check-out codeplex examples and ASP.NET search controls
MOSS ajax
- Only one script manager per page
- Master page or dynamically added
- Update panel post-back causes full render on server and filter everything except update panel content before returning to client
- MOSS: Register fixup script if not running WSS SP1
- Ajax Smart part: Ensure ScriptManager (custom code), add update panel, dynamically load ASCX in update panel
- Update panel has trigger property to set trigger event for a refresh, update mode setting
- Real ajax asp.net client side library:
– ScriptService attibute in asmx (12\isapi)
– enableWebScript with WCF
– javascript function to call
– add WS reference to script manager
– use html button for client side and execute WS call in onclick event
– create result event handler
– in web part scenario use control prefix (INamingContainer!) to find correct web part/control that has send the request to WS
– you can use JS from embedded resource and register with script manager
- Codeplex has control toolkit with cool ajax features
HOL Ajax .NET 3.5 SP 1
- Control browser history
- Script performance
Enterprise library
- When extending yourself hard to integrate future Ent Lib releases
- Block can be used independently, a few dll dependencies only, Logging -> DataAccess
- Application block on codeplex
- What’s new: WMI support for EntLib config (push changes), partial trust correctly, VS 2008 support
- Unity advantages: testablility, uniformity, extensibility, flexibility, does not support config file
- Exception handling: Define policy (which exceptions should be logged where), choose handler (logging, wrapper, …)
- Blocks can be configured via code or config file
- Policy injection block: for AOP style programming (aspect oriented), every method call (in/out) can be intercepted, eg. for validation, authentication, collecting performance data, make cleaner logic
- PolicyInjection.Wrap or .Create, matching rule (what to intercept), handlers – actions, set category name, order of handlers in config is order of execution and order property (!)
- Validation application block: pre-defined validation blocks
- Depency injection with Unity Application Block: container creates instances of dependent objects, resolves recursivly (all child dependencies also resolved), set dependcy attribute on property, define extensions in config, type mappting with constructor and lifetime setting, global.asax: init unity block, page_load: Container.BuildUp() – wires up dependencies, can also use resolve
- WMI support: EntLib objects are exposed as set of classes
- EntLib 5.0: Media release – Silverlight, debugging visualizer, feature review (remove unneeded stuff), velocity caching, integration packs for specific technologies (SharePoint, ASP.NET, …)
Databinding Win Forms and WPF
- Author of CSLA.NET framework
- Win Forms behaves different from WPF
- INotifyPropertyChange is required for databinding, has PropertyChanged event, the ProperyChanging event is not used by databinding, only by LINQ
- Win Forms: A single changed event raises all changed events on form
- WPF: Changed event is only raised for current control
- Raising PropertyChanged in setter does not cause a refresh
– Use value converter in WPF with eg. an IdentityConverter
– Handle BindingComplete event and re-read value in Win Forms
- Serializeable data class with PropertyChanged event creates run-time exception on serialization with BinaryFormatter or NetDataContractSerializer, because they try to serialize the form also, mark event as NonSerialized and manually add/remove the event handlers in event declaration or use [target: NonSerialized]
- IBindingList and IBindingList<T> for in place editing, objects must implement IEditableObject to revert changes on cancel
– does not work with entity framework
– WPF has no Microsoft Grid and therefore all thrid party grids are not compatible, note WPF grid on codeplex
– in place editing without IBindingList works fine via user interface but when a new item is added via code
– use BindingList<T> for Win Forms and Observable<T> for WPF
– BindingList<T> has Allow properties, requires to override xxxxCore method and controls grid behaviour
- Validation support
– Can be placed in object
– IDataErrorInfo, indexer and error property, called on each databinding refresh, so keep it fast: run validation only in setter and store result
– Use ErrorProvider control in Win Forms
– Use ValidatesOnDataErrors property in databinding expression in WPF
– Remember to refresh dependant properties in WPF to remove validation errors because only the changed control is refreshed
- Top-level cancel button: Implement IEditableObject in all data objects, does not work LINQ lists, works fine for DataSets
Intentions and Interfaces
- Intentional Interfaces: DataAccess, ServiceLayer and Validation
- Do no design everything up front
- Bolt on flexibility when you need it
- Make roles explicit – interface is the representation of a role
- Create IEntity, IValidator<T> that calls validation logic of entity object
- DataAccess: ICustomerPreferred, IAddOrders and IFetchingStrategy<T> to specify load options
- Service layer: IMessage, IMessageHandler<T>
TDD
- Idea for naming convention: MethodUnderTest_Scenario_Behaviour, eg. Sum_Overflow_SumsThemUp()
- Project name: ProjectName.Test
- Write short, confined tests, refactor tests, eg. use factory method for instantiation, avoid code redundancy
- Use ReSharper snippets for test method
- Use MS Test when working with TFS
- Use simple test data so that people do not wonder why you used 42
- TDD is difficult because i requires testing, refactoring and design for testability knowledge
- TDD compared to non-TDD implementation of similiar feature: 19 d (non-TDD) vs. 22 d (TDD) and after integration phase 26 d v 24 d, TDD team produced 90 % more stable production code