+ All Categories
Home > Documents > Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other...

Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other...

Date post: 25-Sep-2020
Category:
Upload: others
View: 7 times
Download: 0 times
Share this document with a friend
67
Feature Styles FEATURE FEATURE TYPE OTHER INSTRUCTIONS PAGE NUMBER Sidebar type = ”general” Title must be provided 1017 Try it Out type = ”activity” Title must be provided 1000 Warning type = “warning” No title 1000 Note type = “note” No title 1015 Common Mistakes type = “warning2” No title 1004 CODE LENGTHS FOR WROX BEGINNING CodeSnippet (83 characters) 12345678901234567890123456789012345678901234567890123456789012345678901234567890123 Code80 (88 characters) 1234567890123456789012345678901234567890123456789012345678901234567890123456789012 345678 CodeSnippetSub (77 characters) 12345678901234567890123456789012345678901234567890123456789012345678901234567 CodeListing (83 characters) 12345678901234567890123456789012345678901234567890123456789012345678901234567890123 CodeListing80 (88 characters) 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678 Feature Code Samples FeatureCodeSnippet (84 characters) 123456789012345678901234567890123456789012345678901234567890123456789012345678901234 FeatureCodeSnippetSub {79 characters) 1234567890123456789012345678901234567890123456789012345678901234567890123456789 FeatureCode80 (90 characters) 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 FeatureCode80Sub (84 characters) 123456789012345678901234567890123456789012345678901234567890123456789012345678901234 PRODUCTION NOTE: DO NOT WRAP CODE AROUND FIGURES THE BUBBLESHEET DOES NOT SHOW CONTENT FROM AN ACTUAL CHAPTER AND SHOULD ONLY BE USED FOR FORMATTING. FOR SPECIFIC CONTENT INFORMATION PLEASE REFER TO THE SERIES GUIDELINE DOCUMENTATION. WroxBeg.030912.indd 1 3/13/12 11:29 AM
Transcript
Page 1: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

Feature Styles

Feature Feature type Other InstructIOns page number

Sidebar type = ”general” Title must be provided 1017

Try it Out type = ”activity” Title must be provided 1000

Warning type = “warning” No title 1000

Note type = “note” No title 1015

Common Mistakes type = “warning2” No title 1004

Code Lengths for Wrox Beginning

CodeSnippet (83 characters)12345678901234567890123456789012345678901234567890123456789012345678901234567890123

Code80 (88 characters)1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678

CodeSnippetSub (77 characters)12345678901234567890123456789012345678901234567890123456789012345678901234567

CodeListing (83 characters)12345678901234567890123456789012345678901234567890123456789012345678901234567890123

CodeListing80 (88 characters)1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678

Feature Code Samples

FeatureCodeSnippet (84 characters)

123456789012345678901234567890123456789012345678901234567890123456789012345678901234

FeatureCodeSnippetSub {79 characters)

1234567890123456789012345678901234567890123456789012345678901234567890123456789

FeatureCode80 (90 characters)

123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

FeatureCode80Sub (84 characters)

123456789012345678901234567890123456789012345678901234567890123456789012345678901234

PRODUCTION NOTE: DO NOT WRAP CODE AROUND FIGURES

The bubblesheeT does noT show conTenT from an acTual chapTer and should only be used for formaTTing. for specific conTenT

informaTion please refer To The series guideline documenTaTion.

WroxBeg.030912.indd 1 3/13/12 11:29 AM

Page 2: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

Feature

FeatureCodeSnippet (68 characters)

12345678901234567890123456789012345678901234567890123456789012345678

FeatureCode80 (72 characters)

123456789012345678901234567890123456789012345678901234567890123456789012

FeatureCodeSnippetSub (62 characters)

12345678901234567890123456789012345678901234567890123456789012

FeatureCode80Sub (66 characters)

123456789012345678901234567890123456789012345678901234567890123456

note/Warning/CoMMon MiStaKeS FeatureCodeSnippet (66 characters)

123456789012345678901234567890123456789012345678901234567890123456

note/Warning/CoMMon MiStaKeS FeatureCode80 (70 characters)

1234567890123456789012345678901234567890123456789012345678901234567890

note/Warning/CoMMon MiStaKeS FeatureCodeSnippetSub (60 characters)

123456789012345678901234567890123456789012345678901234567890

note/Warning/CoMMon MiStaKeS FeatureCode80Sub (64 characters)

1234567890123456789012345678901234567890123456789012345678901234

WroxBeg.030912.indd 2 3/13/12 11:29 AM

Page 3: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

begInnIng asp.net mVc test DrIVen DeVelOpment

IntrODuctIOn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix

chapter 1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

chapter 2 High-Level Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

chapter 3 Membership . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

chapter 4 Refactor: Model Binders, Mocks, and Asserts . . . . . . . . . . . . . . . . . . . . . 65

chapter 5 Client and Server Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

chapter 6 Data Layer and IRepository Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

chapter 7 Declare Your Independence with Dependency Injection

and IRepository Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103

chapter 8 Contact Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

chapter 9 Import Contacts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .147

chapter 10 Composing Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

chapter 11 HTML WYSIWYG Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187

chapter 12 Image Hosting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195

chapter 13 Message Templating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211

chapter 14 Billing and Subscriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225

chapter 15 Usage Tracking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237

chapter 16 Fill In the Blanks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249

chapter 17 Declare Your Independence with Dependency Injection

and IRepository Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103

chapter 18 Contact Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

chapter 19 Import Contacts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .147

chapter 20 Composing Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

chapter 21 HTML WYSIWYG Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187

chapter 22 Image Hosting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195

chapter 23 Message Templating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211

Continues

Contents at a Glance page without Parts

WroxBeg.030912.indd 3 3/13/12 11:29 AM

Page 4: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

chapter 24 Billing and Subscriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225

chapter 25 Usage Tracking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237

chapter 26 Fill In the Blanks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249

appenDIx a Useful Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253

appenDIx b Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257

InDex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263

WroxBeg.030912.indd 4 3/13/12 11:29 AM

Page 5: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

begInnIng asp.net mVc test DrIVen DeVelOpment

IntrODuctIOn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix

⊲ part I part Opener tItle

chapter 1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

chapter 2 High-Level Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

chapter 3 Membership . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

chapter 4 Refactor: Model Binders, Mocks, and Asserts . . . . . . . . . . . . . . . . . . . . . 65

chapter 5 Client and Server Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

⊲ part II the secOnD part Opener tItle

chapter 6 Data Layer and IRepository Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

chapter 7 Declare Your Independence with Dependency Injection . . . . . . . . . . . 103

chapter 8 Contact Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

chapter 9 Import Contacts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .147

chapter 10 Composing Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

chapter 11 HTML WYSIWYG Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187

⊲ part III anD a thIrD part Opener tItle

chapter 12 Image Hosting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195

chapter 13 Message Templating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211

chapter 14 Billing and Subscriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225

chapter 15 Usage Tracking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237

chapter 16 Fill In the Blanks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249

appenDIx a Useful Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253

appenDIx b Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257

InDex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263

Contents at a Glance page with Parts

WroxBeg.030912.indd 5 3/13/12 11:29 AM

Page 6: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

WroxBeg.030912.indd 6 3/13/12 11:29 AM

Page 7: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

praise for beginning asp.net mVc test Driven Development

“A must read for anyone wanting to learn how Excel Services revolutionizes the world of spreadsheets!”

—Richard McAniff Corporate Vice President,

Microsoft Office

“This book will guide you through everything you need to know about the great new functional-ity in Excel Services. Microsoft Office SharePoint Server 2007 is Microsoft’s platform for business applications. Excel Services provides great new business intelligence functionality and helps users control and manage their spreadsheets. We’re already seeing these tools and services unleashing tre-mendous creativity in the developer community.”

—Kurt DelBene Corporate Vice President,

Office Business Platform Group

“Microsoft Excel’s sophisticated calculation and analysis capabilities, combined with ease of use and programmability, have led to wide deployment in Capital Markets for critical applications such as pricing and risk management. To date, management and auditing, of what can be highly complex linked workbooks, have posed challenges.

“Excel Services, part of Microsoft Office SharePoint Server 2007, now provides a powerful solution for management of mission-critical spreadsheet applications by centralizing workbook con-tent and calculations and providing controlled web browser access to Excel applications and data on a client/server basis.

“We at HCL technologies see huge take-up of Excel Services in Capital Markets and are mak-ing significant investments in developing deployment capabilities. If you want to learn more about Excel Services, you must get this book.”

—Peter Bennett Principal, Capital Markets,

HCL Former CIO of London Stock Exchange

“Excel Services is a critical enhancement to the analysis tool that the world knows and loves. This is the definitive book on Excel Services, from the team that dreamed it up and built it.”

—Bill Baker Distinguished Engineer,

General Manager Business Intelligence, Microsoft Corporation

Style as H1, Comp will restyle to Praise page styles

Style as Para, Comp will restyle to Praise page styles

Style as ChapterCredit, Comp will restyle to Praise page styles

WroxBeg.030912.indd 7 3/13/12 11:29 AM

Page 8: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

WroxBeg.030912.indd 8 3/13/12 11:29 AM

Page 9: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

Beginning

asp.net mVc test Driven Development

BookHalfTitle

BookHalfTitle2

WroxBeg.030912.indd 9 3/13/12 11:29 AM

Page 10: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

WroxBeg.030912.indd 10 3/13/12 11:29 AM

Page 11: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

Beginning

asp.net mVc test Driven DevelopmentSuBtitLe goeS here

Fifth edition

Emad IbrahimBookAuthor

Style as BookTitle,

Comp will change styles as needed BookEdition

WroxBeg.030912.indd 11 3/13/12 11:29 AM

Page 12: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

Beginning ASP.net MVC test Driven Development

Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com

Copyright © 2009 by Wiley Publishing, Inc., Indianapolis, Indiana

Published simultaneously in Canada

ISBN: 978-0-470-44762-8

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.

Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or pro-motional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the pub-lisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read.

For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.

Library of Congress Control Number: 2009931752

Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. All other trademarks are the property of their respective owners. Wiley Publishing, Inc. is not associated with any product or vendor mentioned in this book.

Copyright

Character Style:InlineURL

WroxBeg.030912.indd 12 3/13/12 11:29 AM

Page 13: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

This book is dedicated to my beautiful soon-to-be-

wife, Laura, for her unconditional love and support. I

love you. Te amo mucho.

—Ana BahebykDedication

WroxBeg.030912.indd 13 3/13/12 11:29 AM

Page 14: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

WroxBeg.030912.indd 14 3/13/12 11:29 AM

Page 15: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

abOut the authOr

emaD IbrahIm is a programmer, an entrepreneur, a thinker, a dreamer, and a humanist. He is all that and none of that. He is clearly conflicted.

He graduated from Virginia Tech in 2009 without honors and since worked in small and large companies, in small and large teams. He has worked in coffee shops, libraries, skyscrapers, and basements. He has managed teams across the room, across the country, and across the world.

He was born in Egypt, graduated kindergarten and met Santa Claus for the first time in Jordan, graduated high school in Zambia, and graduated college in the Virginia, USA. He has lived in Virginia for more than 14 years and now claims it as his home and final destination.

Emad programs in VB, C#, Objective-C, and Ruby. He programs for Windows, the Web, mobile, and iPhone. Legend has it that after a few beers he once said, “I wish I had my computer. I feel like coding.”

About the Author single author

MatterTitle

If there are no blanks and both pages are side-by-side, then Credits should be on left and About the Authors on right

Para

WroxBeg.030912.indd 15 3/13/12 11:29 AM

Page 16: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

WroxBeg.030912.indd 16 3/13/12 11:29 AM

Page 17: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

abOut the authOrs

emaD IbrahIm is a programmer, an entrepreneur, a thinker, a dreamer, and a humanist. He is all that and none of that. He is clearly conflicted.He graduated from Virginia Tech in 2009 without honors and since worked in small and large companies, in small and large teams. He has worked in coffee shops, libraries, skyscrapers, and basements. He has managed teams across the room, across the country, and across the world.

emaD IbrahIm is a programmer, an entrepreneur, a thinker, a dreamer, and a human-ist. He is all that and none of that. He is clearly conflicted.He graduated from Virginia Tech in 2009 without honors and since worked in small and large companies, in small and large teams. He has worked in coffee shops, libraries, skyscrapers, and basements. He has managed teams across the room, across the country, and across the world. He

has managed teams across the room, across the country, destination and across the world.

He was born in Egypt, graduated kindergarten and met Santa Claus for the first time in Jordan, grad-uated high school in Zambia, and graduated college in the Virginia, USA. He has lived in Virginia for more than 14 years and now claims it as his home and final destination.

emaD IbrahIm is a programmer, an entrepreneur, a thinker, a dreamer, and a human-ist. He is all that and none of that. He is clearly conflicted. He graduated from Virginia Tech in 2009 without honors and since worked in small and large companies, in small and large teams. He has worked in coffee shops, libraries, skyscrapers, and basements. He has managed teams across the room, across the country, and across the world. He

was born in Egypt, graduated kindergarten and met Santa Claus for the first time in Jordan, gradu-ated high school in Zambia, and graduated college in the Virginia, USA. He has lived in Virginia for more than 14 years and now claims it as his home and final destination.

emaD IbrahIm is a programmer, an entrepreneur, a thinker, a dreamer, and a humanist. He is all that and none of that. He is clearly conflicted.

He graduated from Virginia Tech in 2009 without honors and since worked in small and large companies, in small and large teams. He has worked in coffee shops, librar-

ies, skyscrapers, and basements. He has managed teams across the room, across the country, and across the world. He was born in Egypt, graduated kindergarten and met Santa Claus for the first time in Jordan, graduated high school in Zambia, and graduated college in the Virginia, USA.

About the Author multiple authors

Para

MatterTitle

WroxBeg.030912.indd 17 3/13/12 11:29 AM

Page 18: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

WroxBeg.030912.indd 18 3/13/12 11:29 AM

Page 19: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

acquisitions editor Paul Reese

project editor Adaobi Obi Tulton

technical editor Cody Reichenau

production editor Debra Banninger

copy editor Catherine Caffrey

editorial Director Robyn B . Siesky

editorial manager Mary Beth Wakefield

production manager Tim Tate

Vice president and executive group publisher Richard Swadley

Vice president and executive publisher Barry Pruett

associate publisher Jim Minatel

project coordinator, cover Lynsey Stanford

compositor Jeff Lytle, Happenstance Type-O-Rama

proofreader Jen Larson, Word One

Indexer J & J Indexing

creDIts MatterTitle

Style as Credits, Comp will apply additional styles

WroxBeg.030912.indd 19 3/13/12 11:29 AM

Page 20: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

WroxBeg.030912.indd 20 3/13/12 11:29 AM

Page 21: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

acknOwleDgments

many peOple cOntrIbuteD DIrectly and indirectly to this effort. I am grateful for their thoughtful insights. I thank Adaobi Obi Tulton and Jim Minatel for their incredible patience, understanding, and support throughout the writing process. They have made the writing process so much easier.

By the time this book is published, I will be married to Lauramy fiancée of two years and the love of my life. I am looking forward to spending the rest of my life with you. Thank you for your love, sup-port, encouragement, and your belief in me.

I want to acknowledge my dad for teaching me to dream big, encouraging and supporting me in every-thing I do. When I was a kid, I used to tell people I wanted to win the Nobel Peace Prize when I grew up. Needless to say, everyone thought it was funny except my parents, and specifically except for my dad. No dream was ever too big for him. Of course, I have not won the Nobel Peace Prize, but the fact that I am writing this acknowledgement means that one of my dreams did come true to write a book.

Last but not least, I want to acknowledge my “little” sister, Caroline. Thank you for being there when I need you. You are a great sister and friend. I can’t believe you will be a doctor in a few months. Don’t expect me to address you as “Doctor,” though.

—Ana Bahebyk

I want tO acknOwleDge the best mom in the world. She is the best listener, the most compassionate and loving mother. Thanks for unconditionally listening to all that I have to say even when none of it made sense. She is also a fantastic cook. One day we will create a cookbook together. I also want to acknowledge the best mom in the world. She is the best listener, the most compassionate and lov-ing mother. Thanks for unconditionally listening to all that I have to say even when none of it made sense. She is also a fantastic cook. One day we will create a cookbook together.

—John Smith

MatterTitle

Para

ChapterCredit

WroxBeg.030912.indd 21 3/13/12 11:29 AM

Page 22: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

WroxBeg.030912.indd 22 3/13/12 11:29 AM

Page 23: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

cOntents

IntroductIon xix

part I: part Opener tItle

chapter 1: requIrements 1

Problem 1Design 1

Message Management 2

Contact Management 3

Reports and Stats 5

Miscellaneous Requirements 5

Solution 6Model-View-Controller 6

ASP .NET MVC 6

Methodology, Concepts, and Approach 10

Tools and Frameworks 18

Why evenContact? 22Summary 23

chapter 2: hIgh-leVel DesIgn 25

Problem 25Design 25

Membership 25

Account Management 29

Message Management 31

Contact Management 32

Solution 34Summary 34

part II: part Opener tItle twO

chapter 3: membershIp 35

Problem 35Design 35Solution 36

Minor Interruption 46

ContentsPartTitle

TOCTitle

ContentsChapterTitle

ContentsH1

ContentsH2

ContentsH3

WroxBeg.030912.indd 23 3/13/12 11:29 AM

Page 24: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

xxiv

ContentS

Problem 206Back on Track 207

Message Templating 209

Design 209Solution 211

My Templates 217

Summary 222

chapter 4: bIllIng anD subscrIptIOns 223

Problem 223Design 223Solution 224

PayPal Implementation 226

Summary 234

part III: part Opener tItle three

chapter 5: usage trackIng 235

Problem 235Design 235Solution 236Summary 246

appenDIx a: FIll In the blanks 247

Problem 247Design 247

User Interface 247

Refactor and Optimize 248

Scaling 248

Solution 248User Interface 248

Refactor and Optimize 254

Scaling 257

Summary 259

appenDIx b: an OVerVIew OF xml 267

glossary 281

Index 289

WroxBeg.030912.indd 24 3/13/12 11:29 AM

Page 25: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

FOrewOrD

After three years, the time is here. Microsoft Office SharePoint Server 2007 has shipped with great fanfare and lots of accolades from customers, partners, and the press.

It’s humbling to be part of the team that helped bring this monstrous release to market. When I worked on SharePoint Portal Server 2001 (codenamed Tahoe back then), Microsoft was making its first offi-cial foray into the portal market with document management added in for good measure. For those of you who worked with SharePoint in those days, the 2001 version was a good first attempt to enter into a new market for Microsoft even with some of the limitations we knew the product had. With the 2007 release, I can definitely say that we have worked hard to make sure SharePoint meets the needs of diverse sets of customers from the smallest business to the largest enterprise.

So, why should you care about SharePoint and this book?

Well, if you look at the 2007 release, we’ve extended the surface area of SharePoint twofold. The previous version of SharePoint was a great collaboration, portal, and enterprise search tool. We’ve enhanced each of those capabilities, while at the same time adding enterprise content management, business process management and e-forms, and finally business intelligence capabilities to the prod-uct. That’s a lot of new technology, information, APIs, and best practices that you need to learn. You’ll need a great teacher and this book is that teacher.

The authors cover the breadth of SharePoint without sacrificing the depth you need to understand how to build complete and robust SharePoint solutions. In fact, you will find yourself consistently reaching for this book on your bookshelf, earmarking pages that have the tips and tricks you need to get your job done, and this book will quickly become an indispensable part of your SharePoint reference set.

After reading this book, you will become a sought-after SharePoint expert ready to tackle the prob-lems that your users throw at you. I know I learned a number of new things about SharePoint after reading this book. I think you will, too.

—Tom Rizzo Redmond, WA

March 2007

MatterTitle

Para

ChapterCredit

WroxBeg.030912.indd 25 3/13/12 11:29 AM

Page 26: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

WroxBeg.030912.indd 26 3/13/12 11:29 AM

Page 27: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

IntrODuctIOn

Dear reaDer, thank yOu FOr pIckIng up thIs bOOk, and welcome to the exciting world of Test Driven Development (TDD) and ASP.NET MVC. Sometime in 2008, I quit my job and decided to start my own company. Naturally, my startup was web-based. At the time, I was already very famil-iar with the Microsoft web development platform, a natural choice for my website. I hesitated to use it because I wanted to learn something new and I wanted to use TDD. Several of the web startups at the time were written in Ruby on Rails (RoR), and I seriously considered going that route. I played around with RoR and became familiar with it. I liked its approach to development, the ease of test-ing, and the control I had over HTML and JavaScript. There are several things that I didn’t like, however, especially the Integrated Development Environment (IDE). Nothing came close to Visual Studio. Luckily, around that time Microsoft introduced ASP.NET MVC, which made the decision very easy for me.

Even though ASP.NET MVC was still in early alpha, I went ahead and built my startup on top of it (talk about taking risks). It was a great experience for me and turned out to be a good decision. I instantly fell in love with the MVC way of doing things. I enjoyed the control I had over the gener-ated HTML and scripts. I loved the clean and friendly URLs. I can’t imagine living without the unit tests that I could easily run when I make a change to verify that I haven’t broken anything. I can go on and on about why I love ASP.NET MVC and TDD and how much more enjoyable they make programming.

Don’t get me wrong, though; it’s not all sunshine. There is a learning curve. You can’t just drag-and-drop a control and instantly have a grid. You can’t drag-and-drop a few controls, set a couple proper-ties, and instantly have form validation. ASP.NET MVC requires some manual work. The upside is that there is no more magic, so you will actually know what is happening on your page, what gets rendered, and how it gets there. Best of all, you will not see anything that you didn’t put on the page. No more hidden fields, strange scripts, or magical eventsjust straight up HTTP requests.

whO thIs bOOk Is FOr

Do you love programming? I don’t mean “like” or “enjoy,” I mean love. If you are like me, then you probably do, and if you do, then you owe it to yourself to learn ASP.NET MVC and to get into Test Driven Development. They will make something that you already love so much more enjoyable.

With that said, let me state up front that this isn’t a book for completely novice programmers, or for experienced developers who have never touched ASP.NET and the .NET Framework in general. This book teaches how to write a real-world website from scratch to deployment, and as such, it can’t explain every single detail of the technology, but must concentrate on designing and writing actual solutions. To read this book comfortably, you should already have had some experience with ASP.NET 2.0, even if not advanced solutions. You’re not required to know ASP.NET MVC, as each chapter will introduce the new concepts and features that you’ll use in that chapter, providing enough background information to

IntroductionTitle

Para

H1

WroxBeg.030912.indd 27 3/13/12 11:29 AM

Page 28: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

xxviii

introDuCtion

implement the solution. If you then want to go deeper and learn everything you can about a feature, you can refer to the MSDN official documentation or to another reference book such as Professional ASP.NET MVC 1.0 by Rob Conery, Scott Hanselman, Phil Haack, and Scott Guthrie (Wrox, 2009).

This book is not a crash course in ASP.NET MVC, and it’s also not an advanced ASP.NET MVC or TDD book. I don’t do a lot of handholding, and I don’t delve into all the intricacies of the frame-work or theories of TDD. I wanted this book to be practical and as close to real-world development as possible. I wanted to create an application, show and explain my decisions, make mistakes, and fix them.

Think of this book as a documentary. I try to develop a web application from scratch and document the process. I make mistakes. I correct them. I (and hopefully you) learn from them. I intentionally kept the mistakes I made in earlier chapters and addressed them in later chapters because I wanted to show the flexibility, power, and usefulness of Test Driven Development. Do you know the feeling when you make a change to the code and cross your fingers hoping that you didn’t break something somewhere else in the application? This problem, and the risks associated with it, is greatly dimin-ished when you use TDD. Imagine making a change, running your tests, and instantly finding out that you just broke six different tests. This immediate knowledge is very comforting. It also allows you to make changes more frequently, fix bugs easily, and feel confident that your changes didn’t break anything.

what thIs bOOk cOVers

This book is basically a documentary of creating a web application using Test Driven Development. This book leads the reader through the development of an ASP.NET MVC 1.0 website that has most of the features users expect to find in a modern site.

The one thing that sets this book apart is its practicality. You will not find many (if any) theoretical explanations that span multiple pages. This book covers practical decisions and concepts, such as:

➤➤ Unit testing frameworks and tools

➤➤ Inversion of Control and Dependency Injection

➤➤ Code coverage

➤➤ Mocking

➤➤ JavaScript libraries and AJAX

I will also use the following .NET 3.5 features that were added in C# 3.0:

➤➤ LINQ

➤➤ LINQ-to-SQL

➤➤ Extension methods

➤➤ Anonymous methods

WroxBeg.030912.indd 28 3/13/12 11:29 AM

Page 29: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

xxix

introDuCtion

In addition, you will learn how these new features and concepts integrate standard ASP.NET 2.0 features, such as:

➤➤ Master pages

➤➤ Membership and profile modules

Not only does this book cover the new features of ASP.NET MVC 1.0; it also demonstrates how to integrate all of them together in order to develop a single full-featured site. After reading this book, you will know many of the best practices for web development using TDD.

hOw thIs bOOk Is structureD

This books starts at the beginning of building a web application using TDD. It starts with a high-level description of the project I am building and then goes into the initial setup and tool selection. Then I start working my way through the actual development of the application.

There are many steps that are common to each chapter. These steps are explained in detail the first time, and from then on they are briefly mentioned.

If you want to build the application and follow along, then it will be more useful to read the book in order. Otherwise, you should be able to open any chapter and learn something new.

Each chapter has three major sections:

➤➤ Problem —This defines the problem or problems to be addressed in the chapter: What do you want to do in this chapter? What features do you want to add to the site and why are they important? What restrictions or other factors need to be taken into account?

➤➤ Design—After the problem is defined adequately, this section describes what features are needed to solve the problem. This will give you a broad idea of how the solution will work.

➤➤ Solution—After establishing what I am going to accomplish and why (and how that solves the problem defined earlier), I will produce and discuss the code and any other material that will realize the design and solve the problem laid out at the beginning of the chapter. Just as the book as a whole focuses primarily on the solution, so does each chapter. This is where you will get hands-on practice and create the code.

what yOu neeD tO use thIs bOOk

All you need to follow along in this book is Visual Studio 2008 and ASP.NET MVC 1.0, as well as the tools, frameworks, and libraries mentioned in the first two chapters. Other than Visual Studio, all the tools used in the book are free and/or Open Source. There are one or two commercial tools, but they are only suggested, not required.

WroxBeg.030912.indd 29 3/13/12 11:29 AM

Page 30: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

xxx

introDuCtion

cOnVentIOns

To help you get the most from the text and keep track of what’s happening, we’ve used several con-ventions throughout the book.

Warning Boxes like this one hold important, not-to-be forgotten information that is directly relevant to the surrounding text.

note Notes, tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.

As for styles in the text:

➤➤ We show filenames, URLs, and code within the text like so: persistence.properties.

➤➤ We present code in two different ways:

We use a monofont type with no highlighting for most code examples.

We use bolding to emphasize code that’s particularly important in the present context.

sOurce cODe

As you work through the examples in this book, you may choose either to type in all the code manu-ally or to use the source code files that accompany the book. All of the source code used in this book is available for download at www.wrox.com. Once at the site, simply locate the book’s title (either by using the Search box or by using one of the title lists) and click on the “Download Code” link on the book’s detail page to obtain all the source code for the book.

note Because many books have similar titles, you may find it easiest to search by ISBN; this book’s ISBN is 978-0-470-44762-8.

Once you download the code, just decompress it with your favorite compression tool. Alternatively, you can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books.

ListBulleted

FeatureType = “warning”

FeatureType = “note”

FeatureType = “note”

CodeSnippetCodeHighlight

InlineURL

FeaturePara

FeaturePara

WroxBeg.030912.indd 30 3/13/12 11:29 AM

Page 31: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

xxxi

introDuCtion

errata

We make every effort to ensure that there are no errors in the text or in the code. However, no one is perfect, and mistakes do occur. If you find an error in one of our books, like a spelling mistake or faulty piece of code, we would be very grateful for your feedback. By sending in errata you may save another reader hours of frustration, and at the same time you will be helping us provide even higher quality information.

To find the errata page for this book, go to www.wrox.com and locate the title using the Search box or one of the title lists. Then, on the Book Search Results page, click on the Errata link. On this page, you can view all errata that has been submitted for this book and posted by Wrox editors.

note A complete book list including links to errata is also available at www.wrox.com/misc-pages/booklist.shtml.

Notes, tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.

If you don’t spot “your” error on the Errata page, click on the Errata Form link and complete the form to send us the error you have found. We’ll check the information and, if appropriate, post a message to the book’s errata page and fix the problem in subsequent editions of the book.

p2p.wrOx.cOm

For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a web-based system for you to post messages relating to Wrox books and related technologies and interact with other readers and technology users. The forums offer a subscription feature to email you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other indus-try experts, and your fellow readers are present on these forums.

At http://p2p.wrox.com you will find a number of different forums that will help you not only as you read this book, but also as you develop your own applications. To join the forums, just follow these steps:

1. Go to p2p.wrox.com and click on the Register link.

2. Read the terms of use and click Agree.

3. Complete the required information to join as well as any optional information you wish to provide and click Submit.

4. You will receive an email with information describing how to verify your account and com-plete the joining process.

ListNumbered

InlineURL

FeatureParaFeatureType = “note”

FeaturePara

H1Para

Para

WroxBeg.030912.indd 31 3/13/12 11:29 AM

Page 32: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

xxxii

introDuCtion

note You can read messages in the forums without joining P2P, but in order to post your own messages, you must join.

Once you join, you can post new messages and respond to messages other users post. You can read messages at any time on the Web. If you would like to have new messages from a particular forum emailed to you, click on the “Subscribe to this Forum” icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works as well as many common questions specific to P2P and Wrox books. To read the FAQs, click on the FAQ link on any P2P page.

WroxBeg.030912.indd 32 3/13/12 11:29 AM

Page 33: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

Part Ian Overview of excel services

⊲ chapter 1: Introduction to Excel Services

⊲ chapter 2: Getting Started with Excel Services

⊲ chapter 3: Architecture

⊲ chapter 4: XML

PartTitle

PartFeaturingList

Style as PartTitle, Part number and Part title should be on one line in manuscript

WroxBeg.030912.indd 997 3/13/12 11:29 AM

Page 34: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

WroxBeg.030912.indd 998 3/13/12 11:29 AM

Page 35: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

nhibernate with ASP.net

what yOu wIll learn In thIs chapter:

➤➤ How to build a very simple web application that will immediately

introduce you to NHibernate .

➤➤ Understanding the concepts behind NHibernate in detail .

➤➤ Showing you how to leverage the power of NHibernate as an Object

Relational Mapper to help remove the monotony of setting up and

creating your data layer .

wrOx.cOm cODe DOwnlOaDs FOr thIs chapter

The wrox.com code downloads for this chapter are found at www.wrox.com/remtitle.cgi?isbn=0123456789 on the Download Code tab. The code for this chapter is divided into the following major examples:

➤➤ MyBasePageCS.zip

➤➤ MyBasePageVB.zip

wrOx.cOm cODe DOwnlOaDs FOr thIs chapter

The wrox.com code downloads for this chapter are found at www.wrox.com/remtitle.cgi?isbn=0123456789 on the Download Code tab. The code is in the chapter xx download and individually named according to the names throughout the chapter.

what Is an Object relatIOnal mapper?

The role of an Object Relational Mapper (ORM) is to bridge the gap between the relational model (the database) and the object-oriented model. This problem is often referred to as “the imped-ance mismatch.” Using mapping fi les or attributes on a business object.

1 ChapterTitle

Chapter number and Chapter title should be on one line in manuscript

ChapterObjective

ChapterObjectiveTitle

NOTE: There is NO monofont in heads and fi gure and table captions

H1

ChapterIntroductionHead

ChapterIntroductionHead

Para

The bubblesheeT does noT show conTenT from an acTual chapTer and should only be used for formaTTing. for specific conTenT

informaTion please refer To The series guideline documenTaTion.

Wrox.com downloads

Option 1

Wrox.com downloads

Option 2

maximum 5 ListBulleted items

WroxBeg.030912.indd 999 3/13/12 11:29 AM

Page 36: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

1000 ❘ chapter 1 NHiberNate witH aSP.Net

why nhibernate?NHibernate is a port of the popular Open Source Hibernate Framework for Java. Hibernate has been around for years, and it’s a proven and robust piece of software. ORM has had a slow take-up in the .NET world, but with the release of LINQToSQL and the beta of the Entity Framework, many devel-opers are starting to see the benefit of automating their Data Access Layer.

One of the best features of NHibernate, in my opinion, is the support for transparent persistence — this means that your business objects don’t have to inherit from any base classes or implement any framework interfaces. This enables you as a developer to build a rich model of a problem domain and put off worrying about persistence requirements to the end. This is why I have chosen to use NHibernate as my ORM of choice, and after you read this article, I hope you start to use it as well.

Warning You will often see the terms exception and error used interchange-ably, although technically they are not the same thing. An error is simply any situation in which unwanted or unexpected results occur, while an exception is a specific object instantiated in response to a runtime error. However, as long as it’s understood that you’re talking about runtime errors, swapping these terms is usu-ally not a problem. For more information, go to www.wrox.com.

gettIng starteD wIth nhIbernate

Before we get into the details of NHibernate, I think it’s important to show you how powerful it is with a quick demo project. By the end of this small project, you will have a real taste for what NHibernate can offer you and just how much time it’s going to save you.

try It Out using the Selectors APi

For a hands-on demonstration of jQuery’s Selectors API, follow these steps:

1. Create the following markup document in your text editor, and save the document as Example 1-1.html:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”><html xmlns=’http://www.w3.org/1999/xhtml’ xml:lang=’en’> <head> <meta http-equiv=’content-type’ content=’text/html; charset=utf-8’ /> <meta http-equiv=’content-language’ content=’en-us’ /> <title>Link</title> <script type=’text/javascript’ src=’../../../Source Code/jQuery/jQuery.js’> </script> <script type=’text/javascript’ src=’Example 2-1.js’></script>

<link type=’text/css’ href=’Example 2-1.css’ rel=’stylesheet’ /> </head>

H2

FeatureTitle, type in “Try It Out,” hit tab, then type in the title of the Try It Out section

FeaturePara

FeatureListNumbered

FeatureCodeSnippet

FeatureType = “activity”

Character Style: InlineURL

WroxBeg.030912.indd 1000 3/13/12 11:29 AM

Page 37: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

getting Started with nhibernate ❘ 1001

<body id=’tmpDialogueExample’> <form action=’javascript:void(0);’ method=’post’> <p> In jQuery, the selector API allows you to select elements from the DOM, just like you do in CSS stylesheets. This simple dialogue contains a few selector API examples. </p> <p> <input type=’submit’ name=’tmpDialogueOpen’ id=’tmpDialogueOpen’ value=’Open Dialogue’ /> </p> <div id=’tmpDialogue’> <input type=’submit’ name=’tmpDialogueClose’ id=’tmpDialogueClose’ value=’Close Dialogue’ /> </div> </form> </body></html>

2. Create the following CSS document in your text editor, and save the CSS document in the same folder where you saved the previous HTML document, as Example 1-1.css:

body { font: 16px sans-serif;}div#tmpDialogue { display: none; position: absolute; top: 50%; left: 50%; width: 500px; height: 500px; margin: -251px 0 0 -251px; border: 1px solid blue; background: lightblue;}body#tmpDialogueExample div.tmpDialogueOn { display: block; }input#tmpDialogueClose { position: absolute; bottom: 5px; right: 5px; width: 100px;}

3. Enter the following JavaScript, and save this as yet another document in the same folder as your HTML and CSS as Example 12-1.js:

var tmpExample = { ready : function() { $(‘input#tmpDialogueOpen’).click( function($e) { $e.preventDefault();

NOTE: Runing heads are set in Dictionary style

WroxBeg.030912.indd 1001 3/13/12 11:29 AM

Page 38: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

1002 ❘ chapter 1 NHiberNate witH aSP.Net

$(‘div#tmpDialogue’).addClass(‘tmpDialogueOn’); } );

$(‘input#tmpDialogueClose’).click( function($e) { $e.preventDefault(); $(‘div#tmpDialogue’).removeClass(‘tmpDialogueOn’); } ); }};

$(document).ready(tmpExample.ready);

using std::cin;

Now that you have NHibernate, it’s time to start writing the Quick Demo project. Open Visual Studio and create a new blank solution called NHibernate.QuickDemo, as shown in Figure 1-1.

Add a Class Library project to the solution by following these steps:

1. From the File menu, select Add➤➪➤New Project.

2. Select a Visual Basic Class Library.

3. Name the Class Library NHibernate.QuickDemo.NHibernateDAL.

Add a web site to the solution by following these steps:

12. From the File menu, select Add➤➪➤New Website.

13. Select an ASP.NET web site with the language set as Visual Basic.

14. Name the web site NHibernate.QuickDemo.Web.

Your solution should resemble the solution posted earlier.

How It Works

Add a new SQL Express 2005 database to the web project, and name it QuickDemo.mdf. Visual Studio will prompt you to ask if you want to place it in the App_Data folder. Do so and add a new table to the database called People with the column definitions shown in Table 1-1.

FeatureH2 Sample

Now add a reference to the NHibernate.dll from the location where you extracted the NHibernate files and folders. If you were following along, the NHibernate.dll will be found in the folder C:\NHibernate\ bin\net-2.0.

FIgure 1-1: The solution

structure of a newly created

Silverlight Application proj-

ect for type .

FeatureListNumbered

MenuArrow

FeatureH1

FeatureH2

Slug

WroxBeg.030912.indd 1002 3/13/12 11:29 AM

Page 39: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

getting Started with nhibernate ❘ 1003

expressIOn DescrIptIOn

Node Name Retrieves the node

/ Selects nodes from the root, for example, /menu/section retrieves

the section nodes that are children of the menu node

// Selects all children nodes regardless of where they are; for example,

we could use //link to retrieve every link element without having to

navigate down through the section

@ Selects an attribute, so in the example, this is how we retrieve the

section title, and the link’s url and name

Add a class file to the Class Library project called person as defined in Listing 1-1. This will be the plain old business object that you will map to the database table.

Mark the web site as the start-up project and run the application site by pressing [F5] or starting the debugger. The web site project will run, and the web page will load up to display a web.

Fill in the textboxes with a first and last name, select a date, and then click on the “Add Person” but-ton. Do this a couple of times with different data, and you will see your people appear on the grid. If you take a look in the People database table, you will see your newly added Person definitions.

lIstIng 1-1: Selectors example — SelectorsAPiexample01.htm

protected void LogEntry(object sender, EventArgs e){ string path = GetPathToLog(); try { StreamWriter writer = File.AppendText(path);

writer.WriteLine(DateTime.Now.ToString(CultureInfo.InstalledUICulture)); writer.WriteLine(“Entry: {0}”, txtLogEntry.Text); writer.WriteLine(“-------------------”); writer.Dispose(); } catch (PathTooLongException) { Response.Write( “The path contains too many characters.”); catch (DirectoryNotFoundException) { Response.Write(“The specified path is invalid.”); }

continues

TabularHead

TabularEntry

CodeTitle

CodeListing

Listing title or TIO title should match the name of

the download file.

WroxBeg.030912.indd 1003 3/13/12 11:29 AM

Page 40: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

1004 ❘ chapter 1 NHiberNate witH aSP.Net

catch (IOException) { Response.Write(“There was a problem accessing the file.”); }}

CoMMon MiStaKeS You will often see the terms exception and error used interchangeably, although technically they are not the same thing. An error is simply any situation in which unwanted or unexpected results occur, while an exception is a specific object instantiated in response to a runtime error. However, as long as it’s understood that you’re talking about runtime errors, swapping these terms is usually not a problem.

Do this a couple of times with different data, and you will see your people appear on the grid. If you take a look in the People database table, you will see your newly added Person.

(x+1)2 = 2x2 + x + 1

(x+1)2 = 2x2 + x + 1 (1)

When you have learned all about the concepts and features of NHibernate, you will build a real-world ASP.NET application with more of an enterprise feel so you can see how to use NHibernate in your line-of-business applications.

architecture and core conceptsBefore we start going into the details of the NHibernate Framework API, it’s important to under-stand some concepts that you used in the Quick Demo project in Part 1.

Configuration, iSession, and iSessionFactoryListing 8 walks you through the steps you took in the demo project and the different parts of NHibernate’s framework that you met. You created an instance of NHibernate’s configuration class, called the configure method, which set up NHibernate based on the application configura-tion file, which in this case was the web.config file. You then added the assembly that contained the embedded mapping metadata, and lastly, you asked the configuration to build an instance of the ISessionFactory.

ISessionFactory

The ISession is the main interface used to persist and retrieve business entities. In the demo proj-ect, you used it to retrieve all the people from the database, as can be seen in Listing 9, and persist new people. Think of ISession as your gateway to the database or, as the NHibernate site defines it, as the “persistence manager,” and then send email to [email protected].

lIstIng 1-1 (continued)

FeaturePara

FeatureType = “warning2”

InlineEmail

Equation

EquationNumbered

WroxBeg.030912.indd 1004 3/13/12 11:29 AM

Page 41: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

getting Started with nhibernate ❘ 1005

ISession

All of the code in this section uses SelectorsAPIExample01.htm code file. An ISession instance will enable you to retrieve and persist your business objects. There are a variety of ways to do this with NHibernate, and I will go into them in more detail later in this article. The ISession interface implements the Unit of Work pattern — a number of actions can be performed on business entities, and the session will keep track of the updates, additions, and deletions; then, using a transaction, all changes can be committed as part of one atomic action. You will see this later when you look at the ITransaction interface.

<TextBlock TextWrapping=”Wrap” > <TextBlock.Foreground> <LinearGradientBrush EndPoint=”0,0” StartPoint=”1,1”> <GradientStop Color=”#FFFF2300”/> <GradientStop Color=”#FFFB00FF” Offset=”1”/> <GradientStop Color=”#FFF0FF00” Offset=”0.25900000333786011”/> <GradientStop Color=”#FF1CFF00” Offset=”0.51800000667572021”/> <GradientStop Color=”#FF0B07FF” Offset=”0.75900000333786011”/> </LinearGradientBrush> </TextBlock.Foreground>

try It Out Selectors example — SelectorsAPiexample01.htm

To recap selection filtering, follow these steps:

1. Create the following markup document as Example 1-2.html:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” <head> <meta http-equiv=’content-type’ content=’text/html; charset=utf-8’ /> <title>Link</title> <script type=’text/javascript’ src=’../../../Source Code/jQuery/jQuery.js’>

table 1-2: A Table in the Try It Out Section

expressIOn DescrIptIOn

Node Name Retrieves the node

/ Selects nodes from the root, for example, /menu/section retrieves the

section nodes that are children of the menu node

// Selects all children nodes regardless of where they are; for example, we

could use //link to retrieve every link element without having to navi-

gate down through the section

SETS WIDTH AND HEIGHT

ADDS MORE TEXT

ADDS PADDING

TableCaption

TableHead

TableEntry

CodeLabel, position above line it defines in Word doc

Option A for code snippets where an entire section used the same code (no need to repeat the code name with every snippet):

WroxBeg.030912.indd 1005 3/13/12 11:29 AM

Page 42: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

1006 ❘ chapter 1 NHiberNate witH aSP.Net

</script> <script type=’text/javascript’ src=’Example 2-2.js’></script> <link type=’text/css’ href=’Example 2-2.css’ rel=’stylesheet’ /> </head> <body id=’tmpDialogueExample’> <div id=’tmpSelection’> <div class=’tmpList’> <h4>Edible Plants</h4> <ul id=’tmpPlants’> <li class=’tmpVegetables’ id=’tmpOnion’>Onion</li> <li class=’tmpVegetables’ id=’tmpBroccoli’>Broccoli</li> <li class=’tmpVegetables’ id=’tmpPepper’>Pepper</li> <li class=’tmpVegetables’ id=’tmpCarrot’>Carrot</li> <li class=’tmpFruits’>Apple</li> <li class=’tmpFruits’>Cherry</li> <li class=’tmpFruits’ id=’tmpOrange’>Orange</li> <li class=’tmpFruits’>Lemon</li> </ul> </div>

2. Create the following CSS document as Example 1-2.css:

body { font: 16px sans-serif;}ul { list-style: none; padding: 0; margin: 0; width: 200px;}li { padding: 3px; margin: 3px;}div.tmpList { float: left; margin: 0 20px;}div#tmpRecap { clear: left; padding: 10px;}.tmpExample { border: 1px solid rgb(200, 200, 200); background: #cbe5f8;}div#tmpSelection { overflow: hidden;}

3. Create the following JavaScript document as Example 1-2.js:

var tmpExample = { ready : function() {

WroxBeg.030912.indd 1006 3/13/12 11:29 AM

Page 43: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

getting Started with nhibernate ❘ 1007

// Find all <input> elements and add a click // event. $(‘a’).click(tmpExample.findElements); },

findElements : function($e) { // Prevent the default action, navigating to the link. $e.preventDefault(); // Reset the example before applying the next. $(‘*’).removeClass(‘tmpExample’);

switch (this.id)

}

How It Works

Clicking on each link in the example results in a different section of the top portion of the document being highlighted, depending on the description provided for each <a> element.

itransactionNHibernate supports its own Transaction API via the ITransaction interface. Now you may be asking, why is another Transaction API needed when we have ADO.NET transactions as well as many others? The advantage is that by using NHibernate’s implementation, we can abstract away the concrete underlying Transaction API, which enables you to code against a consistent Transaction API no matter what your underlying database or environment is.

If you want the short and sweet version of Microsoft’s history, there’s no need to look further than Chairman Bill Gates. More than almost any tech company, Microsoft has been identified with its founder and leader since the get-go. As Gates went, so, too, did Microsoft.

Bill Gates earns $250 every SECOND; that’s about $20 million a DAY and $7.8 billion a YEAR!

If he drops a thousand-dollar bill, he needn’t even bother to pick it up because in the four seconds it would take him to pick it up, he would’ve already earned it back.

—Joe Everyman’s Blog

As Microsoft has morphed and spread into new markets over the years, Gates has remained the con-stant star by which everything and everyone connected with the company has navigated. In short, up until this point, Microsoft has been all about Bill.

QuotePara

QuoteSource

WroxBeg.030912.indd 1007 3/13/12 11:29 AM

Page 44: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

1008 ❘ chapter 1 NHiberNate witH aSP.Net

itransactionNHibernate supports its own Transaction API via the ITransaction interface. Now you may be ask-ing, why is another Transaction API needed when we have ADO.NET transactions as well as many others? The advantage is that by using NHibernate’s implementation, we can abstract away the con-crete underlying Transaction API, which enables you to code against a consistent Transaction API no matter what your underlying database or environment is.

iQuery and iCriteriaNHibernate has two interfaces for querying — the IQuery and the ICriteria interfaces. IQuery sup-ports NHibernate’s own brand of SQL — HQL — that queries using object syntax: that is, classes and properties versus SQL syntax tables and columns. The ICriteria interface enables the querying of entities in an object-oriented manner as well as querying by example. NHibernate also sup-ports native SQL for retrieving entities; you look at all of these different methods in more detail later in this article (see Figure 1-2).

To retrieve all the people in the database, I have used the Criteria API. The Criteria API is one of the two main APIs for querying the database. If you take a look at the GetAllPeople method, you can see that we are asking the cur-rent session to create an instance of a criterion that will be used to query against the Person entity. I then just call a list to return all of the people. If I wanted to add a clause — such as people whose name began with a “P” — I would need to add a criterion to the criteria, but more on this later in the article (see Listing 1-2).

lIstIng 1-2: exception handling in a CreateuserWizard control

protected void CreateUserWizard1_CreateUserError(object sender, CreateUserErrorEventArgs e){ switch (e.CreateUserError) { case MembershipCreateStatus.DuplicateUserName: litResult.Text = “That user name is taken. “ + “Please enter a different user name.”; break;

CodeHeAd

case MembershipCreateStatus.InvalidUserName: litResult.Text = “The user name provided is invalid. “ + “Please check the value and try again.”;

FIgure 1-2: IntelliSense displays all of the objects in

that namespace .

CodeHead

CodeTitle

CodeListing

WroxBeg.030912.indd 1008 3/13/12 11:29 AM

Page 45: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

getting Started with nhibernate ❘ 1009

break;

break; case MembershipCreateStatus.InvalidPassword: litResult.Text = “The password provided is invalid. “ + “Please enter a valid password.”; break;

case MembershipCreateStatus.InvalidEmail: litResult.Text = “The e-mail address is invalid. “ + “Please check the e-mail address and try again.”; break;

case MembershipCreateStatus.InvalidAnswer: litResult.Text = “The password retrieval answer provided is invalid. “ + “Please check the answer and try again.”; break;

case MembershipCreateStatus.InvalidQuestion: litResult.Text = “The password retrieval question provided is invalid. “ + “Please check the question and try again.”; break;

case MembershipCreateStatus.ProviderError: case MembershipCreateStatus.UserRejected: litResult.Text = “An error occurred. The user was not created. “ + “Please verify your input and try again.”; break;

default: litResult.Text = “An unknown error occurred. “ + “Please verify your input and try again.”; break; }}

The CreateUserError event handler in Listing 15 uses the CreateUserError property of the passed-in CreateUserErrorEventArgs object to determine what error has occurred and notifies the user accordingly. The CreateUserError property is an enumeration of type MembershipCreateStatus, which contains all the possible outcomes from an attempt to create a user.

Hopefully, now you are beginning to understand how we got our simple demo application to work and are getting to grips with the main concepts of the NHibernate Framework. In the next part of this article, you start to build a larger application that uses the full spectrum of features that NHibernate provides, and I will be discussing my choices and giving alternatives for different approaches.

InlineCode CodeHighlight

InlineCodeUserInput

InlineCodeUserInputVariable InlineCodeVariable

WroxBeg.030912.indd 1009 3/13/12 11:29 AM

Page 46: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

1010 ❘ chapter 1 NHiberNate witH aSP.Net

try It Out Writing a jQuery Plugin

To write your first jQuery plugin, follow these steps.

1. Key in the following HTML document:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”><html xmlns=’http://www.w3.org/1999/xhtml’ xml:lang=’en’> <head> <meta http-equiv=’content-type’ content=’text/html; charset=utf-8’ /> <meta http-equiv=’content-language’ content=’en-us’ /> <title></title> <script type=’text/javascript’ src=’../../../Source Code/jQuery/jQuery.js’></script> <script type=’text/javascript’ src=’../../../Source Code/jQuery/jQueryUI.js’></script> <script type=’text/javascript’ src=’Example 9-1.js’></script> <link type=’text/css’ href=’Example 9-1.css’ rel=’stylesheet’ /> </head> <body> <div> <p> jQuery plugins give you the ability to extend jQuery’s functionality, quickly and seamlessly. In this example you see how to make a context menu plugin, that handles everything you need to make a context menu <ul> <li>This is a context menu item.</li> </ul> </div> </body></html>

2. Save the preceding HTML document as Example 1-3.html.

3. Enter the following CSS document:

body { font: 12px “Lucida Grande”, Arial, sans-serif; background: #fff; color: rgb(50, 50, 50);}body, html { width: 100%; height: 100%; margin: 0; padding: 0;}div { position: absolute; width: 100%; height: 100%;}p {

WroxBeg.030912.indd 1010 3/13/12 11:29 AM

Page 47: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

getting Started with nhibernate ❘ 1011

padding: 5px; }ul.tmpContextMenu { list-style: none; margin: 0; padding: 5px; border: 1px solid rgb(200, 200, 200); position: absolute; top: 0; left: 0; background: lightblue; width: 200px; min-height: 200px; display: none;}li { padding: 3px;}

14. Save the preceding style sheet as Example 1-3.css.

25. Enter the following JavaScript document:

$.fn.extend({ ContextMenu: function() { this.each( function() { $(this).addClass(‘tmpContextMenu’);

$(this).hover( function() { $.data(this, ‘ContextMenu’, true); }, function() { $.data(this, ‘ContextMenu’, false); } );

// Only attach the following event once. if (!$.data(document, ‘MouseDown’)) { $.data(document, ‘MouseDown’, true);

How It Works

Add a new SQL Express 2005 database to the web project, and name it QuickDemo.mdf. Visual Studio will prompt you to ask if you want to place it in the App_Data folder. Do so and add a new table to the database called People with the column definitions shown in Table 1-1.

Now add a reference to the NHibernate.dll from the location where you extracted the NHibernate files and folders. If you were following along, the NHibernate.dll will be found in the folder C:\NHibernate\bin\net-2.0.

WroxBeg.030912.indd 1011 3/13/12 11:29 AM

Page 48: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

1012 ❘ chapter 1 NHiberNate witH aSP.Net

usIng nhIbernate

Now that you have a good grounding in the main components of NHibernate, it’s time to find out how you can leverage it into your line-of-end-business applications. I find the best way to learn is by example, so I am going to follow the Wrox Problem–Design–Solution approach to a small applica-tion. Let’s begin by looking at the requirements (see Figure 1-3).

Activities

Documents

Logs

Senddocuments

to therepository

Assignpermissions

Monitoraccess to

patientrecords

Performconsistency

checkson records

Gatherand monitor

systemmetrics

Responsibilities

Ensure the validityof document

metadata

Ensureconfidentiality ofpatient records

Ensureaccuracy of

financial records

Optimize storagebandwidth andperformance

Roles

RMS

End User HIPAACompliance

O�cer

SOXCompliance

O�cer

Administrator

Procedures MetricsPolicies

Validation RulesRequestsLogs

287620 Ch01 figure 05 f0105.eps 9/03/09 rsFIgure 1-3: This is just a regular full-size figure .

Before we can start to build an application, we need a set of requirements. This section will intro-duce a sample set of requirements for a fictitious mail order company. Once we have these require-ments, we can define an architecture that will best suit the solution and one that will shape the rest of our project.

The company has these requirements for the software:

➤➤ The ability to add, remove, and update customers. However, no customer should be able to be deleted if they have placed an order with us.

The ability to add, remove, and update products; again, we do not want products that have been ordered to be deleted.

➤➤ The ability to create an order

Slug

ListPara

ListBulleted

WroxBeg.030912.indd 1012 3/13/12 11:29 AM

Page 49: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

using nhibernate ❘ 1013

the DesignBased on the requirements, the system will have a small amount of business logic to start with but will increase as the software evolves over time. You need to ensure that you can isolate the business logic and process from the code that is used to present it. To keep focused on the business problem, you will be following a domain-driven approach and using a Domain Model pattern to model the business problem. The Domain Model will implement all of the business rules, processes, and logic and will represent the problem domain in code.

The architecture will consist of the following layers:

listhead

User Interface (UI) — This layer is responsible for displaying the data and handling user com-mands. In this application, you are using ASP.NET pages, but you could easily add a Win Forms or WPF front-end with only a few minor changes to the applications’ configuration.

Presentation Layer — This layer is the interface between the UI (in this case, the ASP.NET pages) and the rest of the application. This layer will contain some validation logic and can be easily unit tested and used with a variety of different UIs.

Service Layer — The Service Layer acts as the entry point into the application and coordinates all activity between the presentation layer and the repositories. The ser-vices will expose business use cases and will be autonomous.

Domain Model — The Domain Model contains all of the business objects, business rules.

Repository (Data Access Layer) — The Repository acts like an in-memory domain collec-tion. It is used to persist and retrieve our domain business objects. The Repository Layer needs to support Lazy Loading, concurrency checks, querying of business entities, and a transaction interface that can be controlled via the service layer.

the Solution The solution will be written in Visual Studio 2008 with a SQL Express 2005 database.

Figure 19 shows how you would map a simple one-to-many relationship — an Order and its OrderItems.

The object-oriented model of the relationship (shown in Listing 54) uses an IList(Of OrderItem) to store the Items collection. I could have also used an ISet(Of OrderItem) as well, as the order should not contain any duplicate OrderItems.

table 1-5: The Mapping Relationships that NHibernate Supports

relatIOnshIp example

One-to-one One customer has one payment card .

One-to-many One customer has many orders .

continues

ListUnmarked

ListUnmarkedSub

ListHead

ListUnmarkedSub2

set narrow tables to 23p0 wide

WroxBeg.030912.indd 1013 3/13/12 11:29 AM

Page 50: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

1014 ❘ chapter 1 NHiberNate witH aSP.Net

relatIOnshIp example

Many-to-many Customers can rent many DVDs, and a

DVD can be rented by many customers* .

Many-to-one Many orders are placed by one customer .

* table footnote

mappIng cOllectIOn type when tO use anD .net type

Bags Collection of objects each element can repeat . Implemented as

IList, or IList(Of T) .

Sets Collection of objects; each element must be unique . Implemented

as ISet or ISet(Of T) using the Iesi.Collections.dll

namespace .

List Collection of object with integer indices . Each element can repeat .

Implemented as IList or ArrayList .

Map Collection of Key/Value pairs . Implemented as Hashtable or

IDictionary .

Listing 1-1 has a call to File.AppendText (which takes as an argument a string indicating the phys-ical path to the file you want to append to), as well as several calls to the StreamWriter.WriteLine method. Now, stop for a moment and think about all the things that could go wrong here.

➤➤ path could be an empty string.

➤➤ path could be null.

It would be great if there was a way to defer the loading of the full list of orders until you really needed it.

➤➤ path could be too long.

➤➤ path could contain invalid characters.

➤➤ path could be in an invalid format.

➤➤ path could point to a valid directory, but not a specific file.

➤➤ The directory specified in path may not exist.

➤➤ The directory specified in path may not exist.

➤➤ The ASP.NET account may not have sufficient permissions on the directory.1

Note that the foreign key in the object is a full order, not just an order ID property.

1 Footnote on a page. The directory specified in path may not exist.

table 1-5 (continued)

Footnote

TableFootnote

TabularHead

TabularEntry

ListBulleted

ListBulletedSub

ListBulletedSub2

ListParaSub

WroxBeg.030912.indd 1014 3/13/12 11:29 AM

Page 51: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

using nhibernate ❘ 1015

note When handling an exception, avoid throwing a new exception that fails to include the original exception in its InnerException property, as all the informa-tion about the original exception is then lost.

CallbackShouldReturnNull or callback_should_return_nullpublic void Register_Can_Successfully_Register_New_User(){

The new exception starts a new stack trace starting from the exact spot where you threw it, making it appear as though this is where the error actually originated.

There was a requirement to ensure that customers with orders were not deleted. Now you can easily check if a customer has an order by inspecting his or her orders collection — if the count is 0, then you can safely remove them; and if it is 1 or greater, then you cannot.

relatIOnshIp example

One-to-one One customer has one payment card .

One-to-many One customer has many orders .

It would be great if there was a way to defer the loading of the full list of orders until you really needed it. Well, wouldn’t you know — NHibernate has just that very feature!

6 Terabytes of Usable Capacity Looks Like:

RAID 5 Configuration Means 7 1TB Drives:

RAID 10 Configuration Means 12 Drives:

+ Mirrored Copy:

1TBdata

1TBdata

1TBdata

1TBdata

1TBdata

+ 1TBdata

1TBdata

1TBdata

1TBdata

1TBdata

1TBdata

1TBdata

+ 1TBdata

1TBdata

1TBdata

1TBdata

1TBdata

1TBdata

1TBdata

1TBdata

1TBdata

1TBdata

1TBdata

1TBdata

1TBdata

1TBdata

RAID 5 Configuration Means 4TB of Usable Capacity:

Copyright ©2001, Library of Congress.

FIgure 1-4: This is just a regular full-size figure .

FeaturePara

FeatureType = “note”

FeatureCodeSnippet

FigureSourceSabon LT Std 7/11, run under figure, right align with edge, apply cell style FigureSource

WroxBeg.030912.indd 1015 3/13/12 11:29 AM

Page 52: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

1016 ❘ chapter 1 NHiberNate witH aSP.Net

Following Along?If you are following along and building the projects as I progress through the application, simply follow the steps below; or alternatively, you can download the entire application from the Wrox site:

1. Add a reference to the System.Web.dll from the ACompany.OrderProcessing.NHibernate Repository project by right-clicking on the project and selecting “Add Reference,” then finding the System.Web component from the list and clicking “OK.” You need to add this reference because you need to implement the IHttpModule and obtain a reference to the application’s HttpContext.

2. Add a new class to the ACompany.OrderProcessing.NHibernateRepository project, and name it NHibernateHttpModule. The code definition can be found in Listing 1-65.

3. Add the NHibernate configuration section as defined in Listing 1-66 to the web.config file located in the web site project. Don’t worry that Visual Studio will complain about the namespace — this will be fixed later when you add the reference to the Presentation project.

4. Add the context property definition as described in Listing 1-64 to the web.config file within the web site project. This will let NHibernate know that you want to store the current session in a Web context.

i. Add the GetCurrentSession() method to the SessionFactory class within the ACompany.OrderProcessing.NHibernateRepository project, as defined in code Listing 1-67.

ii. Refactor the NHibernateRepository class from the ACompany.OrderProcessing NHibernate Repository project by adding support for the current session, as defined in Listing 1-68.

Your solution should now resemble the solution in Figure 1-23.

Overriding the equals and getHashCode Methods in the Business Base

One thing I haven’t talked about is ensuring that we always identify an entity by its ID. It’s important to override the equals and getHashCode methods of each of the entities because NHibernate will use proxy classes for the Lazy Load features, and comparing objects may bring undesired results. Also if you are using more than one NHibernate session, overriding the equality methods will ensure that NHibernate will identify an entity in the correct way. You can add a new method definition to the IEntity interface to support equality checking as seen in Listing 1-87. The updated BusinessBase class with equality overrides is displayed in Listing 1-88. (code file: SelectorsAPIExample01.htm).

Imports ACompany.OrderProcessing.PresentationImports ACompany.OrderProcessing.InfrastructureImports ACompany.OrderProcessing.ModelPartial Class CustomerList Inherits System.Web.UI.UserControl Implements ICustomerListView Private _Presenter As CustomerListPresenter Protected Sub Page_Init(ByVal sender As Object, _ ByVal e As System.EventArgs) _ Handles Me.Init End Sub

CodeSnippet

ListNumbered

ListNumberedSub

ListNumberedSub2

Option B for code snippets if there are multiple individual downloads add the following sentence to the end of the preceding paragraph. The wording can be different but the meaning should be the same

WroxBeg.030912.indd 1016 3/13/12 11:29 AM

Page 53: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

using nhibernate ❘ 1017

Public WriteOnly Property Customers() As List(Of Customer) _ Implements ICustomerListView.Customers Set(ByVal value As List(Of Customer)) Me.grdCustomers.DataSource = value Me.grdCustomers.DataBind() End Set End Property Protected Sub btnNewCustomer_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) _ Handles btnNewCustomer.Click Response.Redirect(“CustomerDetail.aspx”) End Sub Protected Sub grdCustomers_RowCommand(ByVal sender As Object, _ ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) _ Handles grdCustomers.RowCommand Select Case e.CommandName.ToLower() Case “deletecustomer” _Presenter.RemoveCustomerBy( _ New Guid(e.CommandArgument.ToString)) End Select End Sub

The remainder of the pages in the web site project follow the same logic using user controls to imple-ment the views from the presentation project and creating a presenter in the code-behind to interact with the model.

cOnVentIOn

Test classes will be named as follows [class name]Tests, for example if we are testing the PayController class then the test fi xture will be named PayControllerTests.

Test methods will be named using clear and descriptive names that clearly identify the test and its outcome. You can either separate the name using capitals or using underscores. For example:

CallbackShouldReturnNull or callback_should_return_nullpublic void Register_Can_Successfully_Register_New_User(){ var ac = new AccountController(); var results = ac.Register(username, email, question, answer, password); Assert.IsNotNull(results); Assert.IsInstanceOfType(typeof(RedirectToRouteResult), results); var typedResults = results as RedirectToRouteResult; Assert.AreEqual(“Index”,

I personally prefer the underscore method but there will be a mix of both in the code. I settle on using lower cases and underscores towards the end of the book.

continues

FeatureTitle

FeatureCodeSnippet

FeatureType = “general”FeaturePara

FeatureCodeSnippet + CodeHighlight

WroxBeg.030912.indd 1017 3/13/12 11:29 AM

Page 54: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

1018 ❘ chapter 1 NHiberNate witH aSP.Net

Not surprisingly, I am going to be using NHibernate as my Data Access Layer because it has built-in support for concurrency, transactions, and Lazy Loading. NHibernate also gives you transparent persistence, which will allow me to build my Domain Model without hindrance, and if you want to change my Data Access Strategy at a later date, you will be able to with no change to your Domain Model as in Tables 1-2 and 1-3.

I personally prefer the underscore method but there will be a mix of both in the code. I settle on using lower cases and underscores towards the end of the book.

Again, I will only be showing you the code required to satisfy the customer management require-ments. You will be able to inspect all of the other classes involved in the ASP.NET layer from the complete application download from the Wrox web site. Let’s ensure that the user can actually view the Register page. We start by creating a simple test that would simply need to show whether a user can navigate to the Register view i.e. http://evencontact.com/account/register.

Run the test. The test passes (green light). Woohoo!!! Our fi rst test works.

note This is a very simple action and test, so there isn’t really much to refactor. At least, for now.

Moving on. We need to write tests for the second Register Action, the one that actually registers the user. We want to:

➤➤ Ensure that a Register action exists with the correct signature

➤➤ Ensure that the user is registered

➤➤ Ensure that we are redirected to the homepage after registration

Here is our fi rst test

public void Register_Can_Successfully_Register_New_User(){ var ac = new AccountController(); var results = ac.Register(username, email, question, answer, password); Assert.IsInstanceOfType(typeof(RedirectToRouteResult), results); var typedResults = results as RedirectToRouteResult; Assert.AreEqual(“Index”, typedResults.Values[“action”], “Wrong action”); Assert.AreEqual(“Home”, typedResults.Values[“controller”], “Wrong controller”);}

continued

CodeSnippet + CodeHighlight

WroxBeg.030912.indd 1018 3/13/12 11:29 AM

Page 55: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

using nhibernate ❘ 1019

In this test, we check that the returned value is not null and that it is of type RedirectToRoute Result. Then we make sure that it is redirecting to the correct destination i.e. /home/index. Then we check that page title is correct. There are two Register actions that we need to accommodate. One action just displays the view that would happen with a GET request and the other will submit the form to the server to perform the registration that would happen with a POST request.

Let’s ensure that the user can actually view the Register page. We start by creating a simple test that would simply need to show whether a user can navigate to the Register view i.e. http://evencontact .com/account/register.

exercIses

1. What other client-side technology does jQuery have a lot in common with in terms of its fine-grained

control over selection of elements from markup source?

2. If you wanted to select an element from the DOM using jQuery based on an ancestral relationship,

which method would you use?

3. Let’s say you wanted to swap an element’s position in the DOM with its preceding sibling, what

jQuery method would help with that application?

4. If you have selected an element, and want to select one of that element’s descendants from the

DOM, what methods does jQuery expose that would give you the results you seek?

5. If you made a selection, but later wanted to remove one or more elements from that selection, what

jQuery method would you use?

6. If you only wanted to select a single element from a broader selection, what jQuery method would

you use?

20. List all of the methods that jQuery provides for working with sibling elements .

ExercisesHead

ListNumbered

Production note: Exercises can flow in with the text.

WroxBeg.030912.indd 1019 3/13/12 11:29 AM

Page 56: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

1020 ❘ chapter 1 NHiberNate witH aSP.Net

⊲ what yOu learneD In thIs chapter

all all eVent types anD actIOns are mOnItOreD

checkIn an entry is created when the object is checked in

checkOut an entry is created when the object is checked out

childDelete an entry is created when one of the object’s child objects is deleted (such as

when deleting a file from a folder or a site from a site collection)

copy an entry is created when the object is copied

Delete an entry is created when the object is deleted

move an entry is created when the object is moved

none no event types or actions are monitored

profilechange an entry is created when a profile associated with an object is changed

schemachange an entry is created when the object’s schema is modified

search an entry is created when the object is searched

securitychange an entry is created when a change is made to the object’s configuration

undelete an entry is created when the object is restored from the recycle bin

update an entry is created when the object’s properties are updated

View an entry is created whenever the object is viewed by a user

SummaryHead

TabularHead

TabularEntry

WhAT YOU LEARNED IN ThIS ChAPTER section starts on new page

WroxBeg.030912.indd 1020 3/13/12 11:29 AM

Page 57: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

recommended reading ❘ 1021

recOmmenDeD reaDIng

Wardriving & Wireless Penetration Testing by Chris Hurley, Russ Rogers, Frank Thornton, and Daniel Connelly (Syngress Publishing. ISBN: 159749111X)

Infosec Career Hacking: Sell Your Skillz, Not Your Soul by Aaron W. Bayles, Chris Hurley, Johnny Long, and Ed Brindley (Syngress Publishing. ISBN: 1597490113)

CONFER PROGRAMMER TO PROGRAMMER ABOUT THIS TOPIC.

Visit p2p.wrox.com

YOU CAN DOWNLOAD THE CODE FOUND IN THIS BOOK. VISIT WROX.COMAND SEARCH FOR ISBN 9780470123456

Reference

OnlineReference Option A

Insert Graphic [blurb1.ai] space above varies, generally placed at the bottom of a page. If wording doesn’t match, graphic will need to be updated.

Apply para style _AnchoredGraphic and object style Reference.

OnlineReference Option B

Insert Graphic [blurb2.ai] space above varies, generally placed at the bottom of a page. If wording doesn’t match,

graphic will need to be updated. Apply para style _AnchoredGraphic and object style Reference.

Neither should be used in the middle of a chapter. End of chapter only and not on every chapter. Very occasionally.

WroxBeg.030912.indd 1021 3/13/12 11:29 AM

Page 58: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

WroxBeg.030912.indd 1022 3/13/12 11:29 AM

Page 59: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

regular expressionsThomas Hardy

This appendix examines some basic aspects of constructing regular expressions. One reason for working through the simple regular expressions presented in this chapter is to illuminate the regular expressions used in Chapter 3 and further extend your knowledge of regular expressions.

The following exercises use OpenOffi ce.org Writer — a free document editor that makes it easy to apply regular expressions to text, and verify that they do what you expected. You can download this tool from http://www.openoffice.org.

Warning This appendix has been “borrowed” from beginning regular expressions (Wiley Publishing, Inc., 2005) by Andrew Watt. We recommend this book for further (and more comprehensive) reference into the world of regular expressions.

One of the issues this chapter explores in some detail is the situation where you want to match occurrences of characters other than those characters simply occurring once.

This Appendix looks at the following:

➤➤ How to match single characters

➤➤ How to match optional characters

➤➤ How to match characters that can occur a specifi ed number of times Matching Single Characters

A AppendixTitle

ChapterAuthor

NOTE: For multiple appendixes, use a letter

AppendixLetter and AppendixTitle should be on one line in the manuscript

WroxBeg.030912.indd 1023 3/13/12 11:29 AM

Page 60: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

1024 ❘ appenDIx a regular exPreSSioNS

matchIng sIngle characters

The simplest regular expression involves matching a single character. If you want to match a single, specified alphabetic character or numeric digit, you simply use a pattern that consists of that charac-ter or digit. So, for example, to match the uppercase letter L, you would use the following pattern:

runInpara Any occurrence of the uppercase L. You have not qualified the pattern in any way to limit matching, so expect it to match any occurrence of uppercase L. Of course, if matching is being carried out in a case-insensitive manner (which is discussed in Chapter 4), both uppercase L and lowercase l will be matched.

runInparasub The matching of the pattern L in OpenOffice.org Writer against the sample document UpperL.txt. Notice that there are five matches contained in the sequences of charac-ters XLM, CMLIII, Leoni, Legal, and Lewinski.

The default behavior of OpenOffice.org Writer is to carry out a case-insensitive match. As you can see in Figure A-1, I have checked the Match Case check box so that only the same case as specified in the regular expression is matched.

namespacesA namespace groups elements together by partitioning elements and their attributes into logical areas and providing a way to identify the elements and attributes uniquely. Namespaces are also used to reference a particular DTD or XML Schema. Namespaces were defined after XML 1.0 was formally presented to the public. After the release of XML 1.0, the W3C set out to resolve a few problems, one of which is related to naming conflicts. To understand the significance of this problem, the future of the Web.

http://evencontact.com/account/register

InterVIew q&a

q: If my wireless network doesn’t have a lot of traffic, is it okay to use WEP because the IVs required to crack the WEP key won’t be generated?

a: No. Automated tools are available that allow attackers to capture an ARP packet and rein-ject it to the access point very rapidly. This generates a significant amount of traffic and allows the attacker to capture enough unique initialization vectors to quickly crack the key.

q: What is the difference between active and passive WLAN detection?

a: Active WLAN detection requires that the SSID be broadcast in the beacon frame. Passive WLAN detection listens to all traffic in range of the device and determines what WLANs are in range.

RunInPara, style RunInHead and RunInPara as two separate lines in manuscript

RunInParaSub

Question

Answer

RunInHead

RunInHead

URLPara

WroxBeg.030912.indd 1024 3/13/12 11:29 AM

Page 61: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

regular expressionsMail your packages early so the post offi ce can

lose them in time for Christmas.

— Johnny Carson

This appendix examines some basic aspects of constructing regular expressions. One reason for working through the simple regular expressions presented in this chapter is to illuminate the regular expressions used in Chapter 3 and further extend your knowledge of regular expressions.

The following exercises use OpenOffi ce.org Writer — a free document editor that makes it easy to apply regular expressions to text, and verify that they do what you expected. You can download this tool from http://www.openoffice.org.

Warning This appendix has been “borrowed” from beginning regular expressions (Wiley Publishing, Inc., 2005) by Andrew Watt. We recommend this book for further (and more comprehensive) reference into the world of regular expressions.

One of the issues this chapter explores in some detail is the situation where you want to match occurrences of characters other than those characters simply occurring once.

This Appendix looks at the following:

➤➤ How to match single characters

➤➤ How to match optional characters

appenDIx style as MatterTitle, Comp will apply correct style

EpigraphwithSource

EpigraphSource

WroxBeg.030912.indd 1025 3/13/12 11:29 AM

Page 62: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

1026 ❘ appenDIx regular exPreSSioNS

matchIng sIngle characters

The simplest regular expression involves matching a single character. If you want to match a single, specifi ed alphabetic character or numeric digit, you simply use a pattern that consists of that charac-ter or digit. So, for example, to match the uppercase letter L, you would use the following pattern:

runInpara Any occurrence of the uppercase L. You have not qualifi ed the pattern in any way to limit matching, so expect it to match any occurrence of uppercase L. Of course, if matching is being carried out in a case-insensitive manner (which is discussed in Chapter 4), both uppercase L and lowercase l will be matched.

runInparasub The matching of the pattern L in OpenOffi ce.org Writer against the sample document UpperL.txt. Notice that there are fi ve matches contained in the sequences of charac-ters XLM, CMLIII, Leoni, Legal, and Lewinski.

The default behavior of OpenOffi ce.org Writer is to carry out a case-insensitive match. As you can see in Figure A-1, I have checked the Match Case check box so that only the same case as specifi ed in the regular expression is matched.

cOnVentIOn

Test classes will be named as follows [class name]Tests, for example if we are testing the PayController class then the test fi xture will be named PayControllerTests.

1. Test methods will be named using clear and descriptive names that clearly iden-tify the test and its outcome. You can either separate the name using capitals or using underscores. For example:

CallbackShouldReturnNull or callback_should_return_nullpublic void Register_Can_Successfully_Register_New_User(){ var ac = new AccountController(); var results = ac.Register(username, email, question, answer, password); Assert.AreEqual(“Index”,

I personally prefer the underscore method but there will be a mix of both in the code. I settle on using lower cases and underscores towards the end of the book.

➤➤ I personally prefer the underscore method but there will be a mix of both in the code. I settle on using lower cases and underscores towards the end of the book.

➤➤ Widespread industry support exists for XML. There are also some subtle differences in the way Apache handles rules for mod_rewrite in .htac vs. httpd.conf.Numerous tools and utilities are being with Web browsers, databases, and operating systems.

FeatureListNumbered

FeatureListBulleted

InlineCode

InlineCodeUserInput InlineCodeUserInputVariable

InlineCodeVariable

WroxBeg.030912.indd 1026 3/13/12 11:29 AM

Page 63: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

glOssary

apache cocoon An open source XML publishing system developed under the banner of the Apache Software Foundation.

attribute Metadata on an XML tag that provides additional information.

biztalk An XML-based framework from the Microsoft Corporation that enables communications and integration of business applications.

bpmn Business Process Modeling Notation.

bpms Business process management systems.

bpr Business process reengineering.

cData Character DATA, which is not interpreted or parsed.

cms Content management system.

cOm Component Object Model.

comment Characters included between the comment delimiters <!-- and --> that are not considered part of the document’s character content.

cOrba Common Object Request Broker Architecture.

DcOm Distributed Component Object Model.

Declaration If present, this is the first line within an XML file, which essentially lets parsers, tools, and readers know that the file contains XML.

DOm Document Object Model.

DtD Document type definition; a file that contains element and attribute definitions.

ebxml Electronic Business using Extensible Markup Language.

elements The structural units represented by the starting and ending tags that make up XML files.

encoding The manner in which the abstract characters of a coded character set, such as Unicode, are converted into an integer code representation suitable for storage, transmission, and manipulation.

entity An item that can be included in an XML metadata document by referring to it by a represen-tative name.

GlossaryTitle

GlossaryDefinitionGlossaryTerm

GlossaryTerm and GlossaryDefinition should be typed as two separate lines in manuscript

WroxBeg.030912.indd 1027 3/13/12 11:29 AM

Page 64: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

1028 ❘ gLoSSArY

FO Formating Objects.

DOm Document Object Model.

DtD Document type definition; a file that contains element and attribute definitions.

ebxml Electronic Business using Extensible Markup Language.

elements The structural units represented by the starting and ending tags that make up XML files.

encoding The manner in which the abstract characters of a coded character set, such as Unicode, are converted into an integer code representation suitable for storage, transmission, and manipulation.

entity An item that can be included in an XML representation document by referring to it by a rep-resentative name.

etl Extract, Transform, and Load.

FO Formating Objects.

markup Logical delimiters of a document, consisting of start tags, end tags, empty element tags, entity references, character references, comments, CDATA section delimiters, document type declara-tions, processing instructions, XML declarations, text declarations, and white space outside of the document.

parameter entity A distinct type of entity that is used to modify the structures of a DTD.

pcData Parsed Character Data, which is parsed and uses XML syntax.

pipeline A chain of application components that allows processing data in stages.

processing Instruction Markup used to convey information directly to an application, without being part of the document’s character data.

prologue The optional XML declaration, document type declaration, and any comments, process-ing instructions, or spaces that occur at the very beginning of an XML document.

rmI Remote Method Invocation.

rosettanet An organization that defines standards for business processes such as supply chain and distribution management.

sax Simple API for XML.

sgml Standard Generalized Markup Language, somewhat related to XML and HTML.

sOa Service-Oriented Architecture.

sOap Simple Object Access Protocol.

tag The markup delimiters, element name, and (for a start tag) the attributes, demarcating the start and end of an element instance within a document. In XML an element is expressed either as a paired start tag and end tag, or as a single empty element tag. Contrast with “element,” which encompasses the entire logical structure.

WroxBeg.030912.indd 1028 3/13/12 11:29 AM

Page 65: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

1029

InDex

symbols

& (ampersand) symbol, 8‘ (apostrophe) symbol, 8@ (at) expression, 160// (backslash, double) expression, 160/ (backslash) expression, 160[ ] (brackets) expression, 160> (greater than) symbol, 8< (less than) symbol, 8.. (period, double) expression, 160. (period) expression, 160| (pipe) expression, 160“ (quotation) symbol, 8

a

Actor property, 427, 431Add method, 108AddExtensionObject method, 190AddParam method, 190administration and management, 35–37ADO.NET

DataColumn objects, controlling the rendering behavior of, 225

DataSet schemas, 218–222DataTable, 243–245DiffGram, 223–225

executing FOR XML queries from, 290loading XML into a DataSet, 214–218modifying table and column names,

225–227Multiple Active Result Sets (MARS) in,

323–326

nesting XML output from a DataSet, 228–230

.NET Framework, 42, 56overview, 214ReadXml method, 214

string from a DataSet, getting XML as, 227–228

transforming DataSet to XML, 222–230XML data type columns and, 303–316XmlDataDocument class, 235–241XmlReadMode enumeration, 215XmlWriteMode enumeration, 222XPathNavigator class and XmlData Document relationship between, 242–243

advanced operations, 207–209advanced serialization

collections, serializing, 392–394namespaces used to generate qualified

names, 389–392overview, 384–385XmlAttributeOverrides object, 387–

389XmlAttributes class, 385–387XmlSerializerNamespaces object,

389–392xsd namespace declaration, removing,

391–392xsi namespace declaration, removing,

391–392advanced operations, 207–209airline reservation system

architecture of system, 336ASP.NET 2.0 script callback, 367–369business processes, 336–337

IndexTitle

IndexLetter

Index1

Index2

Index3

WroxBeg.030912.indd 1029 3/13/12 11:29 AM

Page 66: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

1030

airline reservation system (continued) – building XML Web service

confirmation page implementation, 374Access layer methods, implementation of,

343–349database design, 337–342HTML, transforming XML to, 371–373limitations, 337login process, 352–355logout process, 360–362new user registration process, 356–360overview, 335–337search flight process, 362–367

ambiguity and namespaces, 11ampersand (&) symbol, 8annotations used with typed DataSets, 234–235<anonymousIdentification> configuration

section, 468AnonymousIdentificationSection class, 469App_Code subdirectory, 25AppendChild method, 137, 164AppendChildElement method, 164application settings, 473–474applying a style sheet to an XML document,

179–186apostrophe (‘) symbol, 8/appsettingbaseurl: [url] command line

switch, 418AppSettings property, 472/appsettingurlkey: [key] command line

switch, 418architecture

of airline reservation system (case study), 336of Atlas, 280–281for configuration, 57of ShoppingAssistant (case study), 498–

499ASP.NET MMC snapin, 492ASP.NET page, implementation of, 204–207ASP.NET 1.x way of accessing configuration

sections, 467<asp:XmlDataSource>, 26async pages, 446–447asynchronous invocation of Web service

async pages, 446–447

from a browser using IE Web service behavior, 448–453

callService method, 448from a client application, 443–447createUseOptions method, 448how it works, 448–450, 455–457methods, 454–457.NET client application, asynchronous

programming in, 444–446overview, 443–444, 448, 454ShoppingAssistant (case study), 530useService method, 448

asynchronous invocation of Windows service, 526–531

at (@) expression, 160Atlas

architecture of, 280–281features of, 281overview, 280retrieving data from a Web service using,

281–284AttributeCount property, 64attributes

appending, 151elements compared, 6overview, 6–7reading, 69, 73–76writing, 86

Attributes property, 136AuthenticationSection class, 469AuthorizationSection class, 469AUTO mode, 289

b

// (backslash, double) expression, 160/ (backslash) expression, 160benefits of configuration system used by

ASP.NET, 58binary serialization, 51brackets ([ ]) expression, 160binary serialization, 51BufferResponse property, 416building XML Web service, 412–416

WroxBeg.030912.indd 1030 3/13/12 11:29 AM

Page 67: Feature Feature type Other InstructIOns page number · Feature Styles Feature Feature type Other InstructIOns page number Sidebar type = ”general” Title must be provided 1017

1031

built-in configuration management tools – diffusion networks

built-in configuration management toolsASP.NET MMC snapin, 492ASPNET_REGSQL tool, 495command line tools, 495

Budzinski, 133Burch, David, 268Burt, Ronald S., 416Bush, George W., 15“Business Models for Realities: The Newspapers

Industry’s Video SEO Opportunity” (Crowell), 364–365

BuzzLogic, 366

c

“Call for Help” program, 279“Call Me” ad, 143calls to action, 319, 321camcorders

defined, 449guidelines, 281–283, 282reviews, 277–278, 278

camera techniques, 262–263, 263campaign comparisons in Google Analytics, 371Cansei De Ser Sexy band, 100captdeaf channel, 272

captions, 272–273, 272, 449CaptionTube, 281Caraeff, Rio, 291, 407

Carl Zeiss optics, 283Carlson, Nicholas, 152Carnegie Mellon University, 80Carousel application, 299Carr, Nicholas, 119–120,

119–120, 239Carroll, Jill, 113–114, 114, 431Carrozza, J. L., 132categories

Channels tab, 56defined, 449Live Search Video, 110in titles, 98videos, 417–421, 418–421Videos tab, 52viewer statistics, 33–34, 34

“Caucus Night: Barack in Ankeny” video, 385CBS channel, 192, 193Colbert, Stephen, 15, 22college partners, 417color

brand channels, 185–187, 186channel background, 175

“Com.puter.TV” video, 278, 278Comedian accounts, 174, 449comedy and humorous videos, 33–34Comicless, 281comments

brand channels, 197–198defined, 450memes in, 368on videos, 214–215, 215

comments box, 197–198communication channels, 77Community Auditions, 69community engagement, 78–79, 209

Akon, 231–232Boyle, Susan, 244–246, 244–24D

D

Dailymotion, 5, 70–71, 70Dancing 2006 video, 154Darling, Jennifer, 60

Insight, 346–347, 347demonstrations, 135Denters, Esmee, 140–142, 141,

224, 423depth of field, 450descriptions

defined, 450optimizing, 97–98

Dickson, Tom, 398, 402“Did You Know; Shift Happens - Globalization;

Information Age” (Fisch), 447–448, 447“Diet Coke + Mentos” video,

12, 158diffusion networks, 8

brand channels, 197–198defined, 450memes in, 368

WroxBeg.030912.indd 1031 3/13/12 11:29 AM


Recommended