Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403
REDUCE # LINES OF CODE
Actually, it's about reducing Cyclomatic Complexity But Why?
REDUCE POINTS OF POSSIBLE FAILURE (More robust code)
Session Objectives and Takeaways Session Objective(s): Benefits of “Pure FP” 3 Approaches: LINQ / Open XML Tools and Resources
It's All About Transformations Projection Composability Purity Tuples Aggregation
More FP Extension Methods Lazy Evaluation Closures Method Syntax
Open XML Zip Files (called Packages) Packages contain Parts (files in the Zip file) Package has relationship to Parts Parts have relationship to other Parts Content Type tells what the XML is PowerTools for Visual Studio Rock! Open XML Diff is your friend
Open XML SDK V1 Strongly Typed access to Parts No help with the XML V2 Strongly Typed access to Xml Validation Helper Functions
LtxOpenXml Class XDocument Annotations on Parts Extension methods on MainDocumentPart Lazy Projects collections of Named Tuple Types
LINQ to XML Tips Pre-atomize XName and XNamespace Use Extension methods to find optional Elements/Attributes
LINQ to Excel Tables Use friendly names of Tables and Columns Based on LtxOpenXml Class Lazy
Modifying XML Trees “Halloween Problem” Accept Revisions Remove Personal Information Remove Comments See OpenXmlInfo class on my blog
Annotations / Events Use Annotations and Events to determine if tree changed Can implement “Flush” – get list of all parts
In-Memory Open XML Documents Web application servers SharePoint SharePoint Web Services
Transforming in XSLT Style Annotate the tree with new nodes Query to find nodes == XPath pattern Replacement node == Sequence Constructor ApplyTransforms node == xsd:apply-templates Example uses extension methods to reduce syntactic noise Supports Mode
Recap: Three Approaches 1)Pure Functional Transforms 2)“Imperative” Document Modification 3)XSLT Style
DocProc An “imperative” approach to document assembly Part of PowerTools for Open XML Project Alternative to altChunk
Document Reflector “Build a document assembly solution in 5 minutes” Functional Construction in “Expression Context”
Open XML Code Tester Content Controls are Key Uses Title of Content Control Puts XML in Content Controls
Next Steps Go through the Functional Programming Tutorial Download, run the samples Modify them for your scenario Get involved in the community
Key Resources Open XML SDK V1 Open XML SDK V2 MSDN Contains how-to articles and documentation Forums related to SDK
Key Resources Connect Access to more articles and forums Ability to log bugs and vote for features
Key Resources Blogs blogs.msdn.com/ericwhite blogs.msdn.com/brian_jones blogs.msdn.com/dmahugh PowerTools for Visual Studio ?FamilyId=46B6BF86-E35D-4870-B214- 4D7B72B02BF9&displaylang=en PowerTools for Open XML
Sessions On-Demand & Community Resources for IT Professionals Resources for Developers Microsoft Certification and Training Resources Microsoft Certification & Training Resources Resources
Complete an evaluation on CommNet and enter to win! Required Slide
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Required Slide