daniel egan msdn tech days oc day2

49
Daniel N. Egan Daniel N. Egan Microsoft – Developer Microsoft – Developer Evangelist Evangelist http://www.DotNetDoc.com http://www.DotNetDoc.com http://Twitter.com/DanielEgan http://Twitter.com/DanielEgan Building a VSTO Building a VSTO application using LINQ application using LINQ

Upload: daniel-egan

Post on 10-May-2015

1.335 views

Category:

Technology


5 download

TRANSCRIPT

Page 1: Daniel Egan Msdn Tech Days Oc Day2

Daniel N. EganDaniel N. EganMicrosoft – Developer EvangelistMicrosoft – Developer Evangelisthttp://www.DotNetDoc.comhttp://www.DotNetDoc.comhttp://Twitter.com/DanielEganhttp://Twitter.com/DanielEgan

Building a VSTO application Building a VSTO application using LINQusing LINQ

Page 2: Daniel Egan Msdn Tech Days Oc Day2

Daniel Egan –Developer Evangelist Microsoft Daniel Egan –Developer Evangelist Microsoft MCSD, MCSD,

Former Microsoft Regional DirectorFormer Microsoft Regional DirectorMicrosoft MVP – ASP.Net, MCSD, MCTMicrosoft MVP – ASP.Net, MCSD, MCT

Former INETA PresidentFormer INETA President INETA Speakers BureauINETA Speakers Bureau Author : Building Websites with VB.Net

and DotNetNuke 3.0 Packt Publishing .Net Certificate Instructor

California State University Fullerton CSUF .Net Advisory Board Member Run DotNetDoc.com Co-Founder – SoCalDotNet TwitterID : DanielEgan

Daniel Egan

Page 3: Daniel Egan Msdn Tech Days Oc Day2

• INETA – International .Net Association– www.Ineta.org

User groups in this Area. User groups in this Area. • OCDotNet – www.OCDotNet.org • SoCalDotNet –www.SoCalDotNet.org• South Bay .Net - southbaynet.org/ • LADotNet –www.LADotNet.org • LA C# - www.LACSharp.org• SGV – www.SGVDotNet.org • Inland Empire – www.IEDotNetUG.org

User Groups

Page 4: Daniel Egan Msdn Tech Days Oc Day2

m.Twitter.Com

#TechDays

http://www.Twitter.com/DanielEgan

Twitter Your questions…

Page 5: Daniel Egan Msdn Tech Days Oc Day2

Walk through of the fundamentals of VSTO development

The LINQ how and why

Demos, Demos, Demos…

Session Objectives And Agenda

Page 6: Daniel Egan Msdn Tech Days Oc Day2
Page 7: Daniel Egan Msdn Tech Days Oc Day2

Developing on Microsoft Office

Page 8: Daniel Egan Msdn Tech Days Oc Day2

A unified solutions platform for A unified solutions platform for building Office Business Applicationsbuilding Office Business Applicationsthat make line-of-business systems, enterprisethat make line-of-business systems, enterprisedata and workflows accessible and relevant to data and workflows accessible and relevant to users. users.

Premiere developer toolsPremiere developer toolsfor developing Office Business for developing Office Business

ApplicationsApplicationsand scalable enterprise grade solutionsand scalable enterprise grade solutions

utilizing Visual Studio and Microsoft utilizing Visual Studio and Microsoft Office Office

Page 9: Daniel Egan Msdn Tech Days Oc Day2

Integrated design-time experienceIntegrated design-time experience

Increased security through .NET Increased security through .NET FrameworkFramework

Document-level & application-level Document-level & application-level task pane customizationstask pane customizations

……

Support for managed controlsSupport for managed controls

Support for host controlsSupport for host controls

Ability to add controls at design-time Ability to add controls at design-time or dynamically at run-timeor dynamically at run-time

……

Quick developmentQuick development

Competitive advantageCompetitive advantage

Strength of two major productsStrength of two major products

……

Page 10: Daniel Egan Msdn Tech Days Oc Day2
Page 11: Daniel Egan Msdn Tech Days Oc Day2

What About VBA?

Page 12: Daniel Egan Msdn Tech Days Oc Day2

Tools Post 2003Tools Post 2003

Scenarios

N-tier Distributed AppsN-tier Distributed Apps

Complex document add-ins Complex document add-ins (high reuse)(high reuse)

Simple document add-ins Simple document add-ins (high reuse)(high reuse)

Simple document add-ins Simple document add-ins (low reuse)(low reuse)

Macro modifyMacro modify

Macro record/replayMacro record/replay

Advanced app-level add-insAdvanced app-level add-ins

Simple app-level add-insSimple app-level add-ins

Application repurposingApplication repurposing

VBAVBA(as intended)(as intended)

VBAVBA(as applied)(as applied)

MarketMarketGapGap

Tools Pre 2003Tools Pre 2003 ScenarioScenarioss

Com

ple

xit

y

Com

ple

xit

y

Page 13: Daniel Egan Msdn Tech Days Oc Day2

Reasons for Using VSTO vs. VBA

* There are no pending plans to retire VBA at this time

VBA IS A 1990’S TECHNOLOGYLimited functionality and flexibilityLimited functionality and flexibility

Code in document = no source code/version controlCode in document = no source code/version control

VISUAL STUDIO TOOLS FOR OFFICE IS 100% .NETChoice of Visual Basic .NET or C#Choice of Visual Basic .NET or C#

Pro dev environment & tools; access to .NET FrameworkPro dev environment & tools; access to .NET Framework

VSTO SOLUTIONS ARE SECUREVBA has a casual security model = high potential security riskVBA has a casual security model = high potential security risk

VSTO solutions employ the .NET Security modelVSTO solutions employ the .NET Security model

VSTO SUPPORTS BUILDING SCALABLE OFFICE BUSINESS SOLUTIONS

Take advantage of the 2007 Office system development platformTake advantage of the 2007 Office system development platform

Utilize the full benefits of the Visual Studio development Utilize the full benefits of the Visual Studio development environmentenvironment

Page 14: Daniel Egan Msdn Tech Days Oc Day2

Ask These Questions

What business problem does this

VBA solution address?

What parts of this solution, if any, can

I leave in VBA?

Does it make sense tomove this VBA solution

to VSTO?

Page 15: Daniel Egan Msdn Tech Days Oc Day2

Call VSTO from VBA

Developers enable VBA via COM Interop

Interop implemented at design time

Developers can then call VSTO from VBA with IntelliSense after building the project

Page 16: Daniel Egan Msdn Tech Days Oc Day2

VSTO and 2007 Office System

Page 17: Daniel Egan Msdn Tech Days Oc Day2

Custom Task Panes

• VSTO 2005 SE provides app-level custom VSTO 2005 SE provides app-level custom task panes task panes

• Create custom task panes with an add-inCreate custom task panes with an add-in• Add-in support & task pane support forAdd-in support & task pane support for

• Project, Excel, InfoPath, Outlook, Project, Excel, InfoPath, Outlook, PowerPoint, WordPowerPoint, Word

• Custom task panes appear in the main Custom task panes appear in the main application window or (Outlook) inspectorsapplication window or (Outlook) inspectors

• Populate custom task pane with Populate custom task pane with UserControlsUserControls• Populate user controls with Winform controlsPopulate user controls with Winform controls

Page 18: Daniel Egan Msdn Tech Days Oc Day2

Outlook Form Regions

• Implement a custom form region with an add-in

• Runtime and design-time support

Page 19: Daniel Egan Msdn Tech Days Oc Day2

VSTO simplifies and speeds up Outlook form region design and VSTO simplifies and speeds up Outlook form region design and configuration process with a visual designerconfiguration process with a visual designer

Achieve maximum form region designAchieve maximum form region designflexibility with VS visual designerflexibility with VS visual designer

Configure your form region Configure your form region with a simple, intuitive wizardwith a simple, intuitive wizard

Run and debug your form region Run and debug your form region right from Visual Studio [F5]right from Visual Studio [F5]

No need to handle manifest XML, No need to handle manifest XML, OFS files, registry entries, etc. manuallyOFS files, registry entries, etc. manually

Option to import Outlook-created OFS fileOption to import Outlook-created OFS file

Outlook Form Region Wizard

Page 20: Daniel Egan Msdn Tech Days Oc Day2

Visual Ribbon DesignerProperty GridRibbon Control Toolbox Design Surface

Page 21: Daniel Egan Msdn Tech Days Oc Day2

Building a VSTO ProjectBuilding a VSTO Project

Page 22: Daniel Egan Msdn Tech Days Oc Day2

Linq

“It is a mistake to try to look too far ahead. The chain of destiny can only be grasped one LINQ at a time.”~Sir Winston Churchill (1874 - 1965) – modified slightly ;)

Page 23: Daniel Egan Msdn Tech Days Oc Day2

• Linq has been over 7 years in the making• ObjectSpaces

– PDC 2001– Supposed to be part of .Net 2.0– Linked to WinFS

• C – Omega – Researched by Erik Meijer and Worlfram Schulte– Released as a preview in 2004– Language Extensions– Worked a lot with XML, Streams, Anonymous Structs

• Linq– Backed by Anders Hejlsberg - Distinguished Engineer (Only 16

ever) – Chief Designer of C#• Matt Warren – Chief Engineer• Luca Bolognese– Lead Developer

Very Brief Linq History

Page 24: Daniel Egan Msdn Tech Days Oc Day2

• Integrate Objects, Relational Data & XML• SQL and Xquery-like power in C# and VB• Extensible Model for languages• Type Safety• Extensive IntelliSense support• Debugger Support• Run on the .Net 2.0 CLR• 100% backwards compatible

Linq Goals

Page 25: Daniel Egan Msdn Tech Days Oc Day2

Language INtegrated Query (LINQ)

LINQ enabled data sourcesLINQ enabled data sources

LINQTo Objects

ObjectsObjects

LINQTo XML

<book> <title/> <author/> <price/></book>

<book> <title/> <author/> <price/></book>

XMXMLL

LINQ enabled ADO.NET

LINQTo DataSets

LINQTo SQL

LINQTo Entities

RelationRelationalal

Others…VB C#

.NET Language-Integrated Query

Page 26: Daniel Egan Msdn Tech Days Oc Day2

Channel 9 Videos

Future of Languages : Anders Hejlsberg, Herb Sutter, Erik

Meijer, Brian Beckman

http://tinyurl.com/513778

Page 27: Daniel Egan Msdn Tech Days Oc Day2

Linq Query Syntax

“Syntax, my lad. It has been restored to the highest place in the republic.”

~John Steinbeck

Page 28: Daniel Egan Msdn Tech Days Oc Day2

Linq Syntax – Why we started where we did

var query = dc.Recipes .Where(r => r.Title.Contains(“Chocolate”)) .Select(r => new{new{rr.Title, .Title, r.NumberOfServings})r.NumberOfServings});

Extension Extension methodsmethods

Lambda Lambda expressionsexpressions

Object Object initializersinitializersAnonymous Anonymous

typestypes

Implicitly Implicitly Declared Declared

Local Local VariablesVariables

Extension Extension methodsmethods

Page 29: Daniel Egan Msdn Tech Days Oc Day2

Standard Query Operators

• These work similarly to their SQL counterparts– Select– Where– OrderBy/ThenBy– OrderByDescending/ThenByDescending– GroupBy– Count– Sum/Min/Max/Average

Page 30: Daniel Egan Msdn Tech Days Oc Day2

Set Based Query Operators

• Combine two sets of elements– Union

• Returns all distinct elements in both sets

– Intersection• Returns only elements belonging to both sets

– Except• Returns elements in Set A but not in Set B

– Repeat• Returns multiple copies of a set of elements

– Distinct• Removes duplicate elements

Page 31: Daniel Egan Msdn Tech Days Oc Day2

Projection That Creates a Nested 1-Many Collection

• A query can be nested inside another query to produce a 1-Many Collection

var q = from c in db.Customerswhere c.City == "London"select new {

c.CompanyName,c.Phone,OrderDates = (

from o in c.Ordersselect o.OrderDate).Take(5) };

foreach( var c in q ) {Console.WriteLine( c.CompanyName );foreach( od in c.OrderDates )

Console.WriteLine( od )}

Page 32: Daniel Egan Msdn Tech Days Oc Day2

LINQ Queries Are Lazy

• Assigning a query to an IEnumerable<T> variable doesn’t execute the query

• When user iterates over members of the collection, each query operator executes as many times as needed to retrieve the next element– Hence the data can change while elements are still being

retrieved

• Use .ToList<T> or .ToArray<T> to force iteration over the entire query in one statement– Creates a snapshot copy of the original data

Page 33: Daniel Egan Msdn Tech Days Oc Day2

• Every syntactic query expression in C# begins with a "fromfrom" clause and ends with either a "selectselect" or "group" clause. 

– The "from" clause indicates what data you want to query.  – The "select" clause indicates what data you want returned, and what shape it should be in.

• For example, let's look again at the query against the List<Person> collection:

Syntax – From a list (Linq to Objects)

Page 34: Daniel Egan Msdn Tech Days Oc Day2

• If we query from a Database we use the same syntax.• We will cover the DataContext soon

Syntax – From a DB

Page 35: Daniel Egan Msdn Tech Days Oc Day2

• What goes on under the covers?

• You write this :

• Linq sends this to the database

Syntax – Under the hood

Page 36: Daniel Egan Msdn Tech Days Oc Day2

• What about complex queries?• You write this :

• Linq sends this to the database

Syntax – Under the hoodExtension Extension methodsmethods

Page 37: Daniel Egan Msdn Tech Days Oc Day2

Why are SELECT and FROM Reversed

• In C# 3.0, the IDE still doesn’t do background compilation, so it has to parse code line-by-line– Putting SELECT before FROM would prevent IntelliSense from

knowing what can be SELECTed

Page 38: Daniel Egan Msdn Tech Days Oc Day2

Defining the Data Model Classes

Page 39: Daniel Egan Msdn Tech Days Oc Day2

• The DataContext Object is what links the class entities to the database entities.

• This can be done by hand OR by using the Linq to SQL Class Model

The DataContext Object

Page 40: Daniel Egan Msdn Tech Days Oc Day2

Enabling a class

 [Table(Name = "Customer")]    public class Customer    {        private int _Id;        private string _Name;        private string _Phone;         [Column(Id = true, Name = "Id”)]        public int Id { get { return _Id; } set { _Id = value; } }         [Column(Name = "Name")]        public string Name { get { return _Name; } set { _Name = value; }

}         [Column(Name = "PhoneNumber")]        public string Phone { get { return _Phone; } set { _Phone =

value; } }    }

But doing this manually is not required.!

Page 41: Daniel Egan Msdn Tech Days Oc Day2

Adding LINQ to our VSTO AppAdding LINQ to our VSTO App

Page 42: Daniel Egan Msdn Tech Days Oc Day2

Summary

• Microsoft Office is a unified solutions platform for building Office Business Applications that make line-of-business systems, enterprise data and workflows accessible and relevant to users

• VSTO is the premiere developer tool for developing Office Business Applications and scalable enterprise grade solutions utilizing Visual Studio and Microsoft Office

• VSTA is the key developer tool technology that enables ISVs to provide rich customization capabilities within their products and solutions

Page 43: Daniel Egan Msdn Tech Days Oc Day2

Resources

• Newsgroups and web forum– microsoft.public.vsnet.vstools.office– microsoft.public.officedev– microsoft.public.office.developer– http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16

• VSTO-related blogs– VSTO Team Blog – http://blogs.msdn.com/vsto2 – Eric Carter (VSTO Team Member) - http://blogs.msdn.com/eric_carter/ – Andrew Whitechapel (VSTO Team Member) -

http://blogs.msdn.com/andreww/default.aspx – John Durant (VSTO Team Member) -

https://blogs.msdn.com/johnrdurant/default.aspx – Paul Stubbs (VSTO Team Member) – http://blogs.msdn.com/pstubbs/ – Mike Hernandez (VSTO Product Manager) –

http://blogs.msdn.com/mikeh/default.aspx – Kathleen McGrath (UE Team Writer) - http://blogs.msdn.com/kathleen – Office Zealot Site (Tim Huckaby) -

http://www.officezealot.com/VSTO/bloghome.aspx

Page 44: Daniel Egan Msdn Tech Days Oc Day2

For More Information

• Visit the VSTO Developer Center– http://msdn.microsoft.com/office/tool/vsto/default.aspx

• Visit the VSTO 2005 SE web page– http://www.microsoft.com/downloads/details.aspx?

FamilyId=5E86CAB3-6FD6-4955-B979-E1676DB6B3CB

• VSTO Help documentation on MSDN– http://msdn2.microsoft.com/library/d2tx7z6d(en-

us,vs.80).aspx

Page 45: Daniel Egan Msdn Tech Days Oc Day2

TechDays Technology Pilots

• TechDays survey – informing business and technology reporters

Bluetooth opt in Text “survey” to 95495 Privacy policy

• TechDays “Resources on Demand”

Text TuesATwo to 95495 Respond with preferred email

address Resources/links from this session

will be pushed to you via email

• Wireless internet available in the lobby area

• SSID: “TechDays”, no passcode

• Provided by iBahn, hospitality broadband leader

• Internet kiosks also available in the registration area after check-in

Text Messaging Wireless Internet

Page 46: Daniel Egan Msdn Tech Days Oc Day2

Event IDs for TemplateSession Title Text Message Keyword (send to

95495)

SQL Roadshow TuesAOne

MSDN: What’s New for Developers: Highlights from PDC TuesATwo

Partner: Microsoft Licensing and Solution Update TuesBOne

TechNet: Windows Vista, Powershell and Group Policy WedsAOne

MSDN: SQL 2008, VSTO, Silverlight 2.0 WedsATwo

SB2 at TS2: Solution Building for System BuildersTS2 Partner Event: SBS/EBS, Response Point VoIP, and S+S!

WedsBOneWedsBtwo

TechNet: Virtualization and Enterprise Search ThursAOne

MSDN: The Role of the Architect: Today and in the Future ThursATwo

Momentum: Solution Briefing for IT and Business Executives ThursBOne

Momentum Supersize Event ThursBTwo

Dynamics ERP Briefing ThursCOne

Partner: BPOS Deep Dive ThursCTwo

Page 47: Daniel Egan Msdn Tech Days Oc Day2

Your Feedback is Important

• 1. Which technology has your organization purchased, but not yet deployed, that would have the greatest ability to create cost savings?

• 2. What technology has your organization not purchased that would have the greatest impact on cost savings?

• 3. On a scale of 1-5 rate your company’s current level of interest for using IT to make the organization more environmentally friendly.

• 4. On a scale of 1-5 how would you rate your organization’s interest in cloud-based solutions?

• 1. On a scale of 1-5 (5=High, 1=Low), how would you rate your organization’s interest in investing in IT staff or resources within the next 12 months?

• 2. What do you think is the biggest factor influencing your organization’s interest in investing in IT staff or resources within the next 12 months?

Microsoft Technology IT Staffing and Resources

Page 48: Daniel Egan Msdn Tech Days Oc Day2

Slides and Demos

Slides can be

found at:

Demo code can be found at:

www.DotNetDoc.com

Page 49: Daniel Egan Msdn Tech Days Oc Day2