54
Leveraging Application Leveraging Application Blocks in Your Blocks in Your Application Application Development Development Ihsan Anabtawi Ihsan Anabtawi Technology Technology Specialist Specialist Microsoft Microsoft ® Corporation Corporation

Leveraging Application Blocks in Your Application Development Ihsan Anabtawi Technology Specialist Microsoft ® Corporation

Embed Size (px)

Citation preview

Leveraging Application Leveraging Application Blocks in Your Application Blocks in Your Application Development Development

Ihsan AnabtawiIhsan AnabtawiTechnology SpecialistTechnology SpecialistMicrosoftMicrosoft®® Corporation Corporation

What We Will CoverWhat We Will Cover

Introduction to:Introduction to: Data Access Application BlockData Access Application Block Exception Management Application BlockException Management Application Block Configuration Management Configuration Management

Application BlockApplication Block Updater Application BlockUpdater Application Block

Session PrerequisitesSession Prerequisites

Level 200Level 200

Familiarity with Microsoft Visual StudioFamiliarity with Microsoft Visual Studio®® .NET .NET Understanding of Microsoft Visual C#Understanding of Microsoft Visual C#®®

Basic understanding of Microsoft SQL Server™ Basic understanding of Microsoft SQL Server™ 20002000

DemonstrationsDemonstrations

Demo 1 – Introduction to the Data Demo 1 – Introduction to the Data Access Application BlockAccess Application Block

Demo 2 – Introduction to the Exception Demo 2 – Introduction to the Exception Management Application BlockManagement Application Block

Demo 3 – Introduction to the Demo 3 – Introduction to the Configuration Management Application Configuration Management Application BlockBlock

Demo 4 – Introduction to the Updater Demo 4 – Introduction to the Updater Application BlockApplication Block

AgendaAgenda

IntroductionIntroduction Data Access Application Block Data Access Application Block Exception Management Exception Management

Application Block Application Block Configuration Management Configuration Management

Application Block Application Block Updater Application Block Updater Application Block Session Summary Session Summary

IntroductionIntroductionWhat are Application Blocks?What are Application Blocks?

Create less custom codeCreate less custom code Encapsulate best practicesEncapsulate best practices Based on real applicationsBased on real applications

IntroductionIntroductionAvailable Application BlocksAvailable Application Blocks Authorization and ProfileAuthorization and Profile AggregationAggregation Asynchronous InvocationAsynchronous Invocation CachingCaching LoggingLogging User Interface ProcessUser Interface Process Data AccessData Access Exception ManagementException Management Configuration ManagementConfiguration Management UpdaterUpdater

IntroductionIntroductionWhat Do Application Blocks Include?What Do Application Blocks Include? Visual Studio .NET ProjectsVisual Studio .NET Projects

Microsoft Visual BasicMicrosoft Visual Basic®® .NET and Visual C# .NET and Visual C# source codesource code

Quick Start SamplesQuick Start Samples DocumentationDocumentation

Developing ApplicationsDeveloping Applications Design and ImplementationDesign and Implementation Deployment and OperationsDeployment and Operations ReferenceReference

Available from: Available from: http://www.microsoft.com/downloadshttp://www.microsoft.com/downloads

AgendaAgenda

IntroductionIntroduction Data Access Data Access

Application Block Application Block Exception Management Exception Management

Application Block Application Block Configuration Management Configuration Management

Application Block Application Block Updater Application Block Updater Application Block Session Summary Session Summary

Data Access Application Block Data Access Application Block Main ElementsMain Elements

ExecuteNonQuery

ExecuteDataset

FillDataset

UpdateDataset

ExecuteReader

ExecuteScaler

ExecuteXmlReader

CacheParameterSet

GetCachedParameterSet

GetSpParameterSet

Int

DataSet

DataSet

DataSet

SqlDataReader

Object

XmlReader

SqlParameter Array

T-SQL Statement or Stored Procedure

SqlHelperParameterCache

SqlHelper

Data Access Application BlockData Access Client

Data Access Data Access Application Block Application Block Using the SqlHelperParameterCache Using the SqlHelperParameterCache ClassClass

Managing parametersManaging parameters CacheParameterSet CacheParameterSet GetCachedParameterSet GetCachedParameterSet GetSpParameterSet GetSpParameterSet

Caching and retrieving parameters Caching and retrieving parameters Retrieving stored procedure parameters Retrieving stored procedure parameters

Demo 1Demo 1

Introduction to the Introduction to the Data Access Data Access

Application BlockApplication Block

Demonstration SummaryDemonstration Summary

Using the SqlHelper classUsing the SqlHelper class SqlHelper::ExecuteNonQuery()SqlHelper::ExecuteNonQuery() SqlHelper::ExecuteDataSet()SqlHelper::ExecuteDataSet() SqlHelper::ExecuteReader()SqlHelper::ExecuteReader()

Supporting transactionsSupporting transactions

Data Access App. Block Data Access App. Block SqlHelper Class Public FunctionsSqlHelper Class Public Functions

ExecuteNonQueryExecuteNonQuery This method is used to execute commands that do not return This method is used to execute commands that do not return any rows or values. any rows or values.

ExecuteReaderExecuteReader This method is used to return a SqlDataReader object that This method is used to return a SqlDataReader object that contains the resultset returned by a command.contains the resultset returned by a command.

ExecuteDatasetExecuteDataset This method returns a DataSet object that contains the This method returns a DataSet object that contains the resultset returned by a command.resultset returned by a command.

ExecuteXmlReaderExecuteXmlReader This method returns an XML fragment from a FOR XML query.This method returns an XML fragment from a FOR XML query.

FillDatasetFillDataset This method is similar to ExecuteDataset, except that a pre-This method is similar to ExecuteDataset, except that a pre-existing DataSet can be passed in, allowing additional tables existing DataSet can be passed in, allowing additional tables to be added.to be added.

UpdateDatasetUpdateDataset This method updates a DataSet using an existing connection This method updates a DataSet using an existing connection and user-specified update commands. It is typically used with and user-specified update commands. It is typically used with CreateCommand.CreateCommand.

CreateCommandCreateCommand This method simplifies the creation of a SQL command object This method simplifies the creation of a SQL command object by allowing a stored procedure and optional parameters to be by allowing a stored procedure and optional parameters to be provided. This method is typically used with UpdateDatasetprovided. This method is typically used with UpdateDataset

Data Access App. Block Data Access App. Block SqlHelper Class Private FunctionsSqlHelper Class Private Functions

AttachParameterAttachParameter A function used to attach any necessary SqlParameter objects A function used to attach any necessary SqlParameter objects to the SqlCommand being executed.to the SqlCommand being executed.

AttachParametersAttachParameters A function used to attach any necessary SqlParameter objects A function used to attach any necessary SqlParameter objects to the SqlCommand being executed.to the SqlCommand being executed.

PrepareCommandPrepareCommand A function used to initialize the properties of the command, A function used to initialize the properties of the command, such as its connection, transaction context, and so on.such as its connection, transaction context, and so on.

ExecuteReaderExecuteReader This private implementation of ExecuteReader is used to open This private implementation of ExecuteReader is used to open a SqlDataReader object with the appropriate a SqlDataReader object with the appropriate CommandBehavior to manage the lifetime of the connection CommandBehavior to manage the lifetime of the connection associated with the reader most efficiently.associated with the reader most efficiently.

Provide a consistent way to execute Provide a consistent way to execute commandscommands

AgendaAgenda

IntroductionIntroduction Data Access Application Block Data Access Application Block Exception Management Exception Management

Application Block Application Block Configuration Management Configuration Management

Application Block Application Block Updater Application Block Updater Application Block Session Summary Session Summary

Exception Management Exception Management Application BlockApplication BlockPublishing ExceptionsPublishing Exceptions

ExceptionManagement Assembly

Interfaces Assembly

IExceptionPublisherIExceptionXmlPublisher

BaseApplicationException

ExceptionManagementSectionHandler

ExceptionManager

CustomPublisherException

DefaultPublisher

Application

Exception

ConfigFile

WMIEvent

Custom Publisher

Custom Publisher

Custom Publisher

E-mailNotification

EventLog

1

2

34

5

6

5

Exception Management Exception Management Application BlockApplication BlockInternal DesignInternal Design

ExceptionManagement Assembly

EventLog

LogFile

Interfaces Assembly

IExceptionPublisherIExceptionXmlPublisher

ExceptionManagementInstaller

BaseApplicationException

ExceptionManagementSectionHandler

DefaultPublisher

ConfigFile

WMIEvent

Custom Publisher

Custom Publisher

Custom Publisher

E-mailNotification

Database

ExceptionManager

Exception Management Exception Management Application BlockApplication BlockDesign ElementsDesign Elements BaseApplicationException ClassBaseApplicationException Class

Computer name where the exception was created Computer name where the exception was created Date and time when the exception occurred Date and time when the exception occurred Name of the application domain hosting your Name of the application domain hosting your

applicationapplication Thread identity where the exception occurredThread identity where the exception occurred Windows identity of the thread Windows identity of the thread Additional custom information Additional custom information

ExceptionManagerSectionHandler ClassExceptionManagerSectionHandler Class ExceptionManager ClassExceptionManager Class

Exception Management Exception Management Application BlockApplication BlockDesign ElementsDesign Elements

ExceptionManagerInstaller classExceptionManagerInstaller class Automatic instantiationAutomatic instantiation Manual instantiationManual instantiation

DefaultPublisher classDefaultPublisher class IExceptionPublisher and IExceptionPublisher and

IExceptionXmlPublisher interfacesIExceptionXmlPublisher interfaces

Exception Management Exception Management Application BlockApplication BlockConfiguration formatConfiguration format<configuration><configuration> <configSections><configSections> <section name="exceptionManagement"<section name="exceptionManagement" type=" Microsoft.ApplicationBlocks.ExceptionManagementtype=" Microsoft.ApplicationBlocks.ExceptionManagement ExceptionManagerSectionHandler,ExceptionManagerSectionHandler, Microsoft.ApplicationBlocks.ExceptionManagement" />Microsoft.ApplicationBlocks.ExceptionManagement" /> </configSections></configSections>

<exceptionManagement mode="on/off"><exceptionManagement mode="on/off"> <publisher mode="on/off" assembly="AssemblyName"<publisher mode="on/off" assembly="AssemblyName" type="TypeName" exclude="(+)Type,(+)Type"type="TypeName" exclude="(+)Type,(+)Type" include="(+)Type,(+)Type"exceptionFormat="xml" include="(+)Type,(+)Type"exceptionFormat="xml" customattr = "value" /> customattr = "value" /> </exceptionManagement></exceptionManagement></configuration></configuration>

Brad Matter
Should that be </ConfigSections>?

Exception Management Exception Management Application BlockApplication BlockConfiguration SummaryConfiguration Summary

Enable or disable publishersEnable or disable publishers Include or exclude exception typesInclude or exclude exception types Exception detail formatException detail format Custom attributesCustom attributes

Demo 2Demo 2

Introduction to the Introduction to the Exception Management Exception Management

Application BlockApplication Block

Demonstration SummaryDemonstration Summary

Creating custom exceptionsCreating custom exceptions Publishing custom exceptionsPublishing custom exceptions Using Exception Block configuration Using Exception Block configuration

filesfiles Creating custom publishersCreating custom publishers

Exception Management Exception Management Application BlockApplication BlockExtending the Exception Management Extending the Exception Management Application BlockApplication Block Why extend?Why extend? Creating a custom publisherCreating a custom publisher

Custom publisherCustom publisher Receive detailsReceive details

Configure the custom publisherConfigure the custom publisher

AgendaAgenda

IntroductionIntroduction Data Access Application Block Data Access Application Block Exception Management Exception Management

Application Block Application Block Configuration Management Configuration Management

Application BlockApplication Block Updater Application Block Updater Application Block Session Summary Session Summary

Configuration Management Configuration Management Application BlockApplication Block Using the Configuration Management Using the Configuration Management Application BlockApplication Block SimplicitySimplicity Flexible data modelFlexible data model Storage location independenceStorage location independence Data security and integrityData security and integrity PerformancePerformance ExtensibilityExtensibility

Configuration Management Configuration Management Application BlockApplication Block Internal DesignInternal Design

Caching Service

ConfigurationSection

Handlers

Data ProtectionProviders:

DPAPIBCL

Custom

Application

KeyStores

ConfigurationManager

Configuration StorageProvider

DataProtectionProvider

CryptoLibraries

Application XMLConfiguration File

ConfigurationStorage

Providers:XML File

SQL ServerRegistryCustom

Configuration Management Configuration Management Application BlockApplication Block Reading a Named Configuration Reading a Named Configuration SectionSection

Hashtable configData;Hashtable configData;

// Read the configuration section named AppConfig// Read the configuration section named AppConfigconfigData = configData = (Hashtable)ConfigurationManager.Read("AppConfig");(Hashtable)ConfigurationManager.Read("AppConfig");

Configuration Management Configuration Management Application BlockApplication Block Writing a Named Configuration Writing a Named Configuration SectionSection

Hashtable configData;Hashtable configData;

// Write the configuration section named AppConfig// Write the configuration section named AppConfigConfigurationManager.Write("AppConfig",configData);ConfigurationManager.Write("AppConfig",configData);

Configuration Management Configuration Management Application BlockApplication Block Reading the Default Configuration Reading the Default Configuration SectionSection

Hashtable configData;Hashtable configData;

// Read the default configuration section // Read the default configuration section // (must be Hashtable-based)// (must be Hashtable-based)configData = (Hashtable)ConfigurationManager.Read();configData = (Hashtable)ConfigurationManager.Read();

Configuration Management Configuration Management Application BlockApplication Block Writing the Default Configuration Writing the Default Configuration SectionSection

Hashtable configData;Hashtable configData;

// Write the default configuration section // Write the default configuration section // (must be Hashtable-based)// (must be Hashtable-based)ConfigurationManager.Write(configData);ConfigurationManager.Write(configData);

Configuration Block Configuration Block Documentation Documentation

Demo 3Demo 3

Introduction to the Introduction to the Configuration Configuration Management Management

Application Block-Application Block-

Demonstration SummaryDemonstration Summary

The ConfigurationManager classThe ConfigurationManager class ReadRead WriteWrite

Encrypting configuration settingsEncrypting configuration settings Providing alternate storage locationsProviding alternate storage locations

AgendaAgenda

IntroductionIntroduction Data Access Application Block Data Access Application Block Exception Management Exception Management

Application Block Application Block Configuration Management Configuration Management

Application Block Application Block Updater Application BlockUpdater Application Block Session Summary Session Summary

Updater Application Block Updater Application Block When to Use the Updater When to Use the Updater Application BlockApplication Block

Update applicationsUpdate applications vs. Windows Forms downloadsvs. Windows Forms downloads vs. Centralized management systemsvs. Centralized management systems vs. IntelliMirrorvs. IntelliMirror

Updater Application Block Updater Application Block Using the Updater Application BlockUsing the Updater Application Block

Client Server

Manifest Utility

Downloader

Validator

Post Processor(optional)

UpdaterUpdate Controller(Application or separate EXE)

Controller XML Configuration File

Application Application

Application Update

Administrator

Manifest

1

2

3

4

5

Demo 4Demo 4

Introduction to the Introduction to the Updater Application Updater Application

BlockBlock

Demonstration SummaryDemonstration Summary

Configuring, writing and running a self-Configuring, writing and running a self-updating applicationupdating application

Using AppStart.exeUsing AppStart.exe Using ManifestUtility.exeUsing ManifestUtility.exe

Updater Application Block Updater Application Block Developing ControllersDeveloping Controllers Application to control the updaterApplication to control the updater ApplicationUpdateManager classApplicationUpdateManager class

StartUpdater methodStartUpdater method StopUpdate methodStopUpdate method

Updater Application Block Updater Application Block Developing DownloadersDeveloping Downloaders

Moving filesMoving files IDownloader interfaceIDownloader interface BITSBITS

Transfers are restartableTransfers are restartable ManageabilityManageability SecuritySecurity Prioritized transfersPrioritized transfers

Custom downloader classCustom downloader class

Updater Application Block Updater Application Block Developing ValidatorsDeveloping Validators Manage cryptographic signaturesManage cryptographic signatures IValidator interfaceIValidator interface Included validatorsIncluded validators Custom validatorsCustom validators

Updater Application Block Updater Application Block Developing Post-ValidatorsDeveloping Post-Validators

Post-deployment configurationPost-deployment configuration IPostProcessor interfaceIPostProcessor interface Implementing IPostProcessorImplementing IPostProcessor

AgendaAgenda

IntroductionIntroduction Data Access Application Block Data Access Application Block Exception Management Exception Management

Application Block Application Block Configuration Management Configuration Management

Application Block Application Block Updater Application Block Updater Application Block Session Summary Session Summary

Session SummarySession Summary

Reusable codeReusable code Best practices applied to common Best practices applied to common

programming tasksprogramming tasks

For More Information…For More Information…

MSDN Web site at MSDN Web site at msdn.microsoft.commsdn.microsoft.com

Microsoft Patterns and Practices on Microsoft Patterns and Practices on MSDNMSDN

Training and Training and EventsEvents

MSDN Webcasts, MSDN Online MSDN Webcasts, MSDN Online Seminars, Tech·Ed, PDC, Developer DaysSeminars, Tech·Ed, PDC, Developer Days

MSDNMSDNEssential Resources for DevelopersEssential Resources for Developers

Subscription Subscription ServicesServices

OnlineOnlineInformationInformation

MembershipMembershipProgramsPrograms

Print Print PublicationsPublications

Library, OS, Professional, Enterprise, Library, OS, Professional, Enterprise, Universal Delivered via CD-ROM, DVD, WebUniversal Delivered via CD-ROM, DVD, Web

MSDN Online, MSDN Flash, How-To MSDN Online, MSDN Flash, How-To Resources, Download CenterResources, Download Center

MSDN User GroupsMSDN User Groups

MSDN MagazineMSDN MagazineMSDN NewsMSDN News

MSDN WebcastsMSDN WebcastsInteractive, Live Online EventsInteractive, Live Online Events

Interactive, synchronous, live online Interactive, synchronous, live online eventsevents

Discuss the hottest topics from MicrosoftDiscuss the hottest topics from Microsoft Open and free for the general publicOpen and free for the general public Take place every TuesdayTake place every Tuesday

http://www.microsoft.com/usa/webcastshttp://www.microsoft.com/usa/webcasts

MSDN Subscriptions MSDN Subscriptions THE way to get Visual Studio .NETTHE way to get Visual Studio .NETVisual Studio .NETVisual Studio .NET MSDN SubscriptionsMSDN Subscriptions

NE

W

ProfessionalProfessional• Tools to build applications Tools to build applications

and XML Web services for and XML Web services for Windows and the WebWindows and the Web

MSDN ProfessionalMSDN Professional$1199 new$1199 new

$899 renewal/upgrade$899 renewal/upgrade

MSDN EnterpriseMSDN Enterprise$2199 new$2199 new

$1599 renewal/upgrade$1599 renewal/upgrade

MSDN UniversalMSDN Universal$2799 new$2799 new

$2299 renewal/upgrade$2299 renewal/upgrade

Enterprise DeveloperEnterprise Developer• Enterprise lifecycle toolsEnterprise lifecycle tools• Team development supportTeam development support• Core .NET Enterprise Core .NET Enterprise

ServersServers

Enterprise ArchitectEnterprise Architect• Software and data modelingSoftware and data modeling• Enterprise templatesEnterprise templates• Architectural guidanceArchitectural guidance

Where Can I Get MSDN?Where Can I Get MSDN?

Visit MSDN Online atVisit MSDN Online atmsdn.microsoft.commsdn.microsoft.com

Register for the MSDN Flash e-mail Register for the MSDN Flash e-mail newsletter at newsletter at

msdn.microsoft.com/flashmsdn.microsoft.com/flash Become an MSDN CD subscriber at Become an MSDN CD subscriber at

msdn.microsoft.com/subscriptionsmsdn.microsoft.com/subscriptions MSDN online seminarsMSDN online seminars

msdn.microsoft.com/training/seminarsmsdn.microsoft.com/training/seminars Attend more MSDN eventsAttend more MSDN events

Microsoft PressMicrosoft Press®®

Essential Resources for DevelopersEssential Resources for Developers

Microsoft Visual StudioMicrosoft Visual Studio®® .NET is here! .NET is here!This is your chance to start building the next big This is your chance to start building the next big

thing. Develop your .NET skills, increase your thing. Develop your .NET skills, increase your productivity with .NET books from Microsoft Pressproductivity with .NET books from Microsoft Press

www.microsoft.com/mspresswww.microsoft.com/mspress

Become a Microsoft Certified Become a Microsoft Certified Solution DeveloperSolution Developer

What is MCSD?What is MCSD? Premium certification for professionals who design Premium certification for professionals who design

and develop custom business solutionsand develop custom business solutions How do I attain MCSD certification?How do I attain MCSD certification?

Pass four exams to prove competency with Pass four exams to prove competency with Microsoft solution architecture, desktop Microsoft solution architecture, desktop applications, distributed application development, applications, distributed application development, and development toolsand development tools

Where do I get more information?Where do I get more information? For more information about certification For more information about certification

requirements, exams, and training options, requirements, exams, and training options, visit visit www.microsoft.com/mcpwww.microsoft.com/mcp

© 2004 Microsoft Corporation. All rights reserved. Microsoft, the .NET logo, Visual Basic, Visual C#, Visual J#, Visual Studio, the Visual Studio logo, Windows, the © 2004 Microsoft Corporation. All rights reserved. Microsoft, the .NET logo, Visual Basic, Visual C#, Visual J#, Visual Studio, the Visual Studio logo, Windows, the Windows logo, Active Directory, MSDN, and Microsoft Press are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or Windows logo, Active Directory, MSDN, and Microsoft Press are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or

other countries. The names of actual companies and products mentioned herein may be the trademarks of their respective owners. other countries. The names of actual companies and products mentioned herein may be the trademarks of their respective owners.