grasping the lightswitch paradigm
DESCRIPTION
From Visual Studio Live! Redmond presentation "Grasping The LightSwitchParadigm(The Taming of the Tool)"TRANSCRIPT
Grasping The LightSwitchParadigm
(The Taming of the Tool)
Grasping The LightSwitchParadigm
(The Taming of the Tool)
Level: Intermediate
October 20, 2011
Andrew BrustAndrew BrustCEO and Founder
Blue Badge Insights
• CEO and Founder, Blue Badge Insights• Member, Microsoft BI Partner Advisory Council• Microsoft Regional Director, MVP• Co-chair VSLive! and over 16 years as a speaker• Founder, Microsoft BI User Group of NYC
– http://www.msbinyc.com
• Co-moderator, NYC .NET Developers Group• http://www.nycdotnetdev.com
• “Redmond Review” columnist for Visual Studio Magazine and Redmond Developer News
• brustblog.com, Twitter: @andrewbrust
Meet AndrewMeet Andrew
The LightSwitch White PapersThe LightSwitch White Papers
• Go to microsoft.com/lightswitch and click on white paper links
• Or use these direct, shortened URLs:• http://bit.ly/vslsoverview
• http://bit.ly/vslsfirstapp
• http://bit.ly/vslsdata
• http://bit.ly/vslsui
• http://bit.ly/vslsextensions
• Get these slides on SlideShare
AgendaAgenda
• Intro• Basic Skills• Advanced Techniques
INTROINTRO
What is LightSwitch?What is LightSwitch?
• A streamlined, optimized system for building line of business applications
• A SKU of Visual Studio – introduces new C#/VB project types
• Built on the existing MS stack• Uses Silverlight on the front-end, leverages IIS
• Uses Entity Framework, RIA Services and other core .NET components too
• Uses SQL Server if maintaining its own database•Can also connect to existing SQL Server and other databases
• Can Read/Write SharePoint 2010 Lists
Core ConceptsCore Concepts• Data Sources
• Entities/Tables and Properties/Columns
• Screens• Template-based, but full control over design• Groups and controls; lots of nesting
• Access Control• Built-in role-based security
• Code• Computed data properties• Full event model
• Extensions• Controls and more
What’s Different?What’s Different?
• Model-driven• No forms package. Instead, you design
screens schematically.• Generic structures with specific implementations
• Business Types, not just data types• Built-in export to Excel• No requirement to code…and yet plenty of
opportunity to do so
What Else is Different?What Else is Different?
• Many things are inferred:• Screen scenarios
• Screen region layout
• Control types, and read-only equivalents
• Invoking your default detail screen when Summary Property clicked
• Impact of access control on UI
• The context-sensitive role of buttons (Command Bars)
• Very cloud-capable• Works with Windows Azure and/or SQL Azure
• Might have the best deployment story in the stack
BASIC SKILLSBASIC SKILLS
The IDE: DataThe IDE: Data
Toolbar
Can have multiple data sources
Our entity, in the singular
Our entity set, pluralized
Entity type becomes field type
Propertieswindow
Business TypesBusiness Types
• Imply UI, formatting, data validation• Built-In:
• Phone
• Money
• Others can be added through extensions• Business Types can be very useful when
connecting to an existing database• Just change underlying data type to business type in
the data designer
The IDE: ScreensThe IDE: Screens Members area
Query and its properties. Can drag properties onto visual tree
Methods (editable)
Toolbar
Layout Group
Controls.Icons represent control types. Click drop-down arrow to change.
Add more elements
Screen Name (editable)
Command bars
Screen TemplatesScreen Templates
• Details• Editable Grid• List and Details• New Data• Search Data
Adding an EntityAdding an EntityAnd Building a ScreenAnd Building a Screen
What You Get For FreeWhat You Get For FreeRibbon
Menu
Tabbed layout
Toolbar
Search box
Data Navigation
Design while executing!
Data Validation UI
Design ModeDesign Mode
Commit or roll back the changes andyou’re done!
This is an actual live copy of your app.
You can even do data entry and click controls
Visual tree and Properties window for you to make live changes interactively
NavigationNavigation
• The side bar menu is generated and updated automatically, as you add screens
• You can customize it though:• Change order of items
• Add, remove or rename screens and groups
• Show/hide screens programmatically•Using the CanRun event
Pop-upsPop-ups
• Screens for creating and editing individual records are generated on-the-fly by LightSwitch
• See them by clicking the Edit or Add New buttons on the toolbar
• You can replace these generated screens with your own…
Parameterization and Loading Parameterization and Loading Screens Through CodeScreens Through Code
• You can design your own screens for creating or editing single records & use them in place of the generated pop-up screens• Use New Data and Details screen templates
• For New Data screen:• You must put code in Add button’s Execute event
handler:•this.Application.ShowScreenName();
• For Details screen:• Set the “Use as Default Details Screen” option in the
Add New Screen dialog box.
Navigation, PopupsNavigation, PopupsButtons, Loading ScreensButtons, Loading Screens
Data ValidationData Validation
• You can easily add your own Validation in code.• Click Custom Validation in the Properties window,
• Put in conditional logic and pass a string to the results.AddPropertyError method.
• Use AddEntityError method for server-side validation when saving changes
• Or AddPropertyResult and AddEntityResult for info and warning messages
• Validation goes in data model, and flows into all screens. Even generated ones.
The Event ModelThe Event Model
• Types: General, Access Control• Objects:
• Queries
• Data Sources
• Tables
• Properties (Fields), for validation
• Computed fields, for computation
• Screens
• Buttons (Execute and CanExecute)
• Menu items (CanRun event hook)
Data ValidationData Validation
Buttons and Command BarsButtons and Command Bars
• Have Execute and CanExecute events• Buttons are children of Command Bars
and Command Bars are everywhere• Ribbon, toolbar, collection controls, rows within
collection controls
• Simple controls too…just right click and then select Add Button…
• So buttons can go just about anywhere• Lots of predefined buttons:
• AddNew, AddAndEditNew, EditSelected, DeleteSelected, RemoveSelected, Refresh
Ribbon ButtonsRibbon Buttons
ADVANCED TECHNIQUESADVANCED TECHNIQUES
QueriesQueries
• All screens’ data are fetched through queries
• You can edit these and add:• Filter
• Sort
• Parameter
• Group
• Also• Support paging, sorting, search
• Set page size
LayoutLayout
• Screen layout is based on layout groups:• Rows, Columns, Table, Tabs, Modal Window
• These are nest-able• Scroll bars, splitter bars and relative sizing
of screen region controllable through:• Scroll Enabled, Alignment, Min/Max Height/Width, Is
Row/Column Resizable properties provide
Queries and LayoutQueries and Layout
SearchSearch
• Built in to List and Data Grid controls• Implemented automatically on all string
fields• Can be disabled at the property or entity
level using Is Searchable property• Support search property on screen query
• Search-ability defined in the data model; respected by all screens• Even the generated ones
• Search is rather brute force• So don’t allow too many fields to be searchable
Access ControlAccess Control
• Optional Windows- or forms-based authentication
• You define:• Groups, and their membership
• Named permissions, which you check programmatically in code
• Access control event hooks available for:• Whether visible:
•Screens in the navigation menu•Buttons
• Whether editable:•Properties/fields,
Access ControlAccess Control
ExtensionsExtensions
• Controls• Screen Templates• Custom Data Sources• Business Types• Themes• Shells
Themes and ShellsThemes and Shells
ExtensionsExtensions
DeploymentDeployment
• Client is in-browser or desktop• Middle tier on PC, server or Azure• Deploy your database, or use existing db• Work in SQL Server user instance mode +
Express during dev, but deploy to SQL Server or SQL Azure.• Or stay in Express!
Platform Shifts and Market AnalysisPlatform Shifts and Market Analysis
• Most LOB app tools give high productivity but low customization. LS is different.
• Most are either frameworks or code generators. LS is different.
• LS is model-driven. It renders Silverlight code/XAML today. What about tomorrow?
Thank youThank you
• [email protected]• @andrewbrust on twitter• Want to get the free “Redmond Roundup
Plus?”• Text “bluebadge” to 22828