1
Architecture design Use of some Microsoft patterns & practices for Architecture Guidance (http://www.microsoft.com/practices) 2
Page asp.net simple <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <html> <head> <title>start</title> <script language="c#" runat=" ="server"> void Page_Load(object object sender, System.EventArgs e) { String selectcmd = "select * from Recording"; SqlConnection myconnection = new SqlConnection( "server=(local); =(local);database=recordings;trusted_connection =yes"); SqlDataAdapter mycommand = new SqlDataAdapter(selectCmd selectcmd, myconnection); DataSet ds = new DataSet(); mycommand.fill(ds ds,, "Recording" Recording"); recordingselect.datasource = ds; recordingselect.datatextfield = "title" title"; recordingselect.datavaluefield = "id"; recordingselect.databind(); } void SubmitBtn_Click(Object sender, EventArgs e) { String selectcmd = String.Format( "select * from Track where recordingid = {0} order by id", (string)recordingselect.selecteditem.value recordingselect.selecteditem.value); SqlConnection myconnection = new SqlConnection( "server=(local); =(local);database=recordings;trusted_connection Trusted_Connection=yes") ; SqlDataAdapter mycommand = new SqlDataAdapter(selectCmd selectcmd, myconnection); DataSet ds = new DataSet(); mycommand.fill(ds ds,, "Track" Track"); MyDataGrid.DataSource = ds; MyDataGrid.DataBind(); } </script> </head> <body> <form id="start" method="post" runat="server"> <h3>recordings</h3> Select a Recording:<br /> <asp:dropdownlist id="recordingselect" runat="server" /> <asp:button runat="server" text="submit" OnClick="SubmitBtn_Click" /> <p/> <asp:datagrid id="mydatagrid" runat="server" width="700" backcolor="#ccccff" bordercolor="black" showfooter="false" cellpadding="3" cellspacing="0" font-name="verdana" font-size="8pt" headerstyle-backcolor="#aaaadd" enableviewstate="false" /> </form> </body> </html> 3
Model-View View-Controller (MVC) modifie Contrôleur (gère les actions de l utilisateur : inputs Modèle génère (gère les données) Vue Demande infos (affichage des informations) 4
The View (page aspx) <%@ Page language="c#" Codebehind=" ="Solution.aspx.cs" AutoEventWireup=" ="false" Inherits="Solution" %> <html> <head> <title>solution</title> </head> <body> <form id="solution" method="post" runat="server"> <h3>recordings</h3> Select a Recording:<br/> <asp:dropdownlist id="recordingselect" runat="server" /> <asp:button id="submit" runat="server" text="submit" enableviewstate="false" /> <p/> <asp:datagrid id="mydatagrid" runat="server" width="700" backcolor="#ccccff" bordercolor="black" showfooter="false" cellpadding="3" cellspacing="0" font-name="verdana" font-size="8pt" headerstyle-backcolor="#aaaadd" enableviewstate="false" /> </form> </body> </html> 5
Le modèle using System; using System.Collections; using System.Data; using System.Data.SqlClient; public class DatabaseGateway { public static DataSet GetRecordings() { String selectcmd = "select * from Recording"; public static DataSet GetTracks(string recordingid) { String selectcmd = String.Format( "select * from Track where recordingid = {0} order by id", recordingid); SqlConnection myconnection = new SqlConnection( } SqlConnection myconnection = new SqlConnection( "server=(local);database=recordings;tru sted_connection=yes"); SqlDataAdapter mycommand = new SqlDataAdapter(selectCmd, myconnection); DataSet ds = new DataSet(); mycommand.fill(ds, "Recording"); return ds; } "server=(local);database=recordings;tru sted_connection=yes"); SqlDataAdapter mycommand = new SqlDataAdapter(selectCmd, myconnection); DataSet ds = new DataSet(); mycommand.fill(ds, "Track"); return ds; 6
Le contrôle (code behind) using System; using System.Data; using System.Collections; using System.Web.UI.WebControls; public class Solution : System.Web.UI.Page { protected System.Web.UI.WebControls.Button submit; protected System.Web.UI.WebControls.DataGrid MyDataGrid; protected System.Web.UI.WebControls.DropDownList recordingselect; private void Page_Load(object sender, System.EventArgs e) { if(!ispostback) { DataSet ds = DatabaseGateway.GetRecordings(); recordingselect.datasource = ds; recordingselect.datatextfield = "title"; recordingselect.datavaluefield = "id"; recordingselect.databind(); } } void SubmitBtn_Click(Object sender, EventArgs e) { DataSet ds = DatabaseGateway.GetTracks( (string)recordingselect.selecteditem.value); #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.oninit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.submit.click += new System.EventHandler(this.SubmitBtn_Click); this.load += new System.EventHandler(this.Page_Load); } #endregion } MyDataGrid.DataSource = ds; MyDataGrid.DataBind(); } 7
Page controller pattern 8
Page controller pattern ( presentation : extension of MVC pattern ) Page controller pattern http://msdn.microsoft.com/practices/type/patterns/enterprise/imppagecontroller/ 9
Architecture design Layered Architecture Users Presentation Business Business Workflows Service Interfaces Business Components Business Entities User interfaces decoupled from business logic Ability to add new functionalities/technologies Access Data Access Logic Components Service Agents Data Sources Services 10
Du rôle des objets Stockage (arrière boutique) cuisine façade Extérieur fast food salade 0 3 carottes frigo Ouvre le frigo Va me chercher les ingrédients chef Ils veulent une salade serveur On voudrait une salade clients commis Ouvre le placard, s huile sel placard 11
Du rôle des objets Stockage (arrière boutique) cuisine façade Extérieur fast food salade 0 3 carottes frigo voilà ingrédients préparés 30 chef Voila la recette préparée serveur Je vous présente le plat clients, huile commis Je prépare les ingrédients,s plat Je prépare le plat 00 33saladier Je présente le plat 33 00 s s sel placard 12
0 3 Stockage (arrière boutique) salade carottes frigo Du rôle des objets 30 cuisine Objets métiers (traitement des données) chef façade serveur Extérieur fast food clients Données, huile stockage commis,s 00 0 plat 33saladier 33 s s sel placard Objets de données (entity objects, data object, data transfer objects ) 13
Façade ade Pattern Façade ade 14
Architecture n tiers UI/WS Biz Facade Biz Rules Data Access Data Sources Simulation pages WEB MCE PC PDA Smartphone Objets métiers WS WS (appliances) Cas d utilisations provider Boiler Thermostat Programm User connexion aux sources de données XML Conf Data RegisterAppliance Evts boiler breakdown temp changed Représentation des données communes : biz entities 15
Architecture n tiers MCE MCE PC Data Sources Data Access Biz Rules Biz Facade UI / WS PPC IIS +.netfw Simulation UI : WS WEB/Exe Biz Facade (use cases) 16
Architecture design : ed architecture W3Home application server Business Logic Presentation Biz Facade Biz Rules Data Access Data Sources/ services User Serveur Pages WEB Services Use Cases Business components Business components Data Access components Data Access components WS XML Conf Data Code to physically access Data, equipments & services 17
Architecture design : example Presentation applicative logic - specific protocols decouplement Biz Facade Biz Rules Data Access Boiler Simulation SetBoilerState.aspx SetBoilerState Boiler DaBoiler Calendar Simulation User IComeBack.aspx UserComeBack ComfortSystem Zones Thermostat Da Thermostat Standalone application WEB Interface to simulated Objects : = application component Check equipments states Raise events 18
Architecture design : example Loosely coupled component functionalities augmentation Presentation Biz Facade Biz Rules Data Access SetBoilerState.aspx SetBoilerState Boiler DaBoiler Boiler Simulation Calendar User SetBoilerState.aspx UserComeBack ComfortSystem Zones Thermostat Da Thermostat Video surveillance system WEBCam DA WEBCam = application component 19
Architecture design : example Equipments integration via standard protocols Presentation Biz Facade Biz Rules Data Access User User DA System Notification RegisterBoilerError.asmx Register Boiler Error System Notification Boiler DaBoiler Boiler Simulation Boiler Service Provider Boiler Service Provider SOAP = application component Content/services Providers Ex : customer service application 20
WEB Facade Relations entre les Couches BizFacade BizRules Interfaces WEB Point d entrée public aux : (pour le User) EntertainmentSystem ThermalComfortSystem SecuritySystem (pour les Devices) ControlPointSystem Règles métier pour gérer : Boiler thermostat camera MediaCenter NotificationSystem Devices ControlPoint ServiceProvider Zones Zone DataSources Data Access Fichiers XML Simulation Services WEB Accès bas niveau Common Types de données commun : liste programmes, messages d événements,conf etc. Services Distants Devices, Services clients 21
(long terme) exemple d alternative d possible BizFacade Point d entrée public aux : (pour le User) EntertainmentSystem ThermalComfortSystem SecuritySystem (pour les Devices) ControlPointSystem BizRules Règles métier pour gérer : Boiler thermostat camera MediaCenter NotificationSystem Devices ControlPoint ServiceProvider Zones Zone DataSources Data Access Fichiers XML Simulation Socket Serveur Accès bas niveau Common Types de données commun : liste programmes, messages d événements,conf etc. 22
MySchool S identifier User Voir la liste des étudiants <<étend>> Voir les informations d un étudiant 23
Architecture design : example Presentation Biz Facade Biz Rules Data Access Login.aspx AccountingSystem DataFees Simulé ViewStudentList.aspx StudentsSystem User DAUser Browser ViewStudent.aspx MySchoolAP.asmx app = application component 24
Les classes 25
Les classes 26
Projet serveur Projet client 27
KO CheckLogin(log,pwd) OK GetStudentList() Mise en session De la valeur Id «UserId» Session Page suivante GetStudent (int) 28
29
football247.net In the pack you receive at the end of the day Post-event CD http://www.football247.net Football247.Net Workspace on http://www.gotdotnet.com http://www.rational.com/uml/ Building Secure ASP.NET Solutions http://www.microsoft.com/downloads/release.asp?rel easeid=44047 30
Football247.net use case diagram Browse Football Data Shopping Browser Buy Authentication User Maintenace Reporter Game Reporting Import Football Data Game Maintenance Administ rator 31
Football247.net Football247.Common Application Architecture.Core.Datasets Solution Structure System Architecture Football247.Presentation Firewall User Tier.Administrator,.Reporter.WinControls.WebSite.WebControls.Facades Football247.Business Business Tier.Facades.Services.Host Firewall Data Tier Football247.Data.DataAccess SQL 32
Do you Web Forms or Windows Forms you want thin, thick,, fat, rich, dumb,, smart, Windows or Internet? User Experience Deployment Updating Security Mobile Web Forms Relatively hard to make web pages dynamic with DHTML. Easy. Only on server. Reach Shadow copying prevents restarts of the web application Authorized actions depend on zone. Microsoft Mobile Internet Toolkit Windows Forms Dynamic, responsive UI. End users love it. Can be deployed through web server..net Framework required on client. Can Rich update on web server. Authorized actions depend on zone. Code Access Security..NET Compact Framework 33
34 Presentation Presentation Data Data Football247.net Football247.net clients clients WS Façade (asmx) WS Façade (asmx) ASP.NET UI (aspx) ASP.NET UI (aspx) WIN Service WIN Service Business Business WS Façade WS Façade ES Façade ES Façade Biz Services Biz Services D A L D A L S P S P or browser admin reporter
35