eric white technical evangelist microsoft corporation session code: ofc403

29

Upload: april-merritt

Post on 04-Jan-2016

220 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403
Page 2: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

Developing Office Client Solutions Using LINQ and Open XML Eric White

Technical EvangelistMicrosoft CorporationSession Code: OFC403

Page 3: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

REDUCE# LINES

OF CODE

Page 4: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

Actually, it's about reducing Cyclomatic Complexity

But Why?

Page 5: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

REDUCEPOINTS OF POSSIBLE

FAILURE(More robust code)

Page 6: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

Session Objectives and Takeaways

Session Objective(s): Benefits of “Pure FP”3 Approaches: LINQ / Open XMLTools and Resources

Page 7: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

It's All About Transformations

ProjectionComposabilityPurityTuplesAggregation

Page 8: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

More FP

Extension MethodsLazy EvaluationClosuresMethod Syntax

Page 9: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

Open XML

Zip Files (called Packages)Packages contain Parts (files in the Zip file)Package has relationship to PartsParts have relationship to other PartsContent Type tells what the XML is

PowerTools for Visual Studio Rock!Open XML Diff is your friend

Page 10: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

Open XML SDK

V1Strongly Typed access to PartsNo help with the XML

V2Strongly Typed access to XmlValidationHelper Functions

Page 11: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

LtxOpenXml Class

XDocument Annotations on PartsExtension methods on MainDocumentPartLazyProjects collections of Named Tuple Types

Page 12: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

LINQ to XML Tips

Pre-atomize XName and XNamespaceUse Extension methods to find optional Elements/Attributes

Page 13: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

LINQ to Excel Tables

Use friendly names of Tables and ColumnsBased on LtxOpenXml ClassLazy

Page 14: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

Modifying XML Trees

“Halloween Problem”Accept RevisionsRemove Personal InformationRemove CommentsSee OpenXmlInfo class on my blog

Page 15: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

Annotations / Events

Use Annotations and Events to determine if tree changedCan implement “Flush” – get list of all parts

Page 16: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

In-Memory Open XML Documents

Web application serversSharePointSharePoint Web Services

Page 17: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

Transforming in XSLT Style

Annotate the tree with new nodesQuery to find nodes == XPath patternReplacement node == Sequence ConstructorApplyTransforms node == xsd:apply-templates

Example uses extension methods to reduce syntactic noiseSupports Mode

Page 18: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

Recap: Three Approaches

1) Pure Functional Transforms2) “Imperative” Document Modification3) XSLT Style

Page 19: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

DocProc

An “imperative” approach to document assemblyPart of PowerTools for Open XML ProjectAlternative to altChunk

Page 20: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

Document Reflector

“Build a document assembly solution in 5 minutes”Functional Construction in“Expression Context”

Page 21: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

Open XML Code Tester

Content Controls are KeyUses Title of Content ControlPuts XML in Content Controls

Page 22: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

Next Steps

Go through the Functional Programming TutorialDownload, run the samples

Modify them for your scenarioGet involved in the community

Page 23: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

question & answer

Page 24: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

Key Resources

Open XML SDK V1http://go.microsoft.com/fwlink/?LinkId=120908

Open XML SDK V2http://go.microsoft.com/fwlink/?LinkId=127912

MSDNContains how-to articles and documentationForums related to SDKhttp://msdn.microsoft.com/office/xml

Page 25: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

Key Resources

ConnectAccess to more articles and forumsAbility to log bugs and vote for featureshttp://connect.microsoft.com

Page 26: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

Key Resources

Blogsblogs.msdn.com/ericwhiteblogs.msdn.com/brian_jonesblogs.msdn.com/dmahugh

PowerTools for Visual Studiohttp://www.microsoft.com/downloads/details.aspx?FamilyId=46B6BF86-E35D-4870-B214-4D7B72B02BF9&displaylang=en

PowerTools for Open XMLwww.codeplex.com/powertools

Page 27: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

www.microsoft.com/teched

Sessions On-Demand & Community

http://microsoft.com/technet

Resources for IT Professionals

http://microsoft.com/msdn

Resources for Developers

www.microsoft.com/learningMicrosoft Certification and Training Resources

www.microsoft.com/learning

Microsoft Certification & Training Resources

Resources

Page 28: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

Complete an evaluation on CommNet and enter to win!

Page 29: Eric White Technical Evangelist Microsoft Corporation Session Code: OFC403

© 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.