1 / 71

Datengetriebene Anwendungen mit REST, WPF und Silverlight

Datengetriebene Anwendungen mit REST, WPF und Silverlight. Workshop Spring BASTA 2009. Umgebung. SQL Server 2008 Visual Studio 2008 SP 1 SQL Server Compact Edition 3.5 SP 1. Unsere Ziele…. Motivation für neue Datenzugriffstechniken klären

keelty
Télécharger la présentation

Datengetriebene Anwendungen mit REST, WPF und Silverlight

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Rainer Stropekcubido business solutions gmbh Datengetriebene Anwendungen mit REST, WPF und Silverlight Workshop Spring BASTA 2009

  2. Rainer Stropek, cubido business solutions gmbh Umgebung • SQL Server 2008 • Visual Studio 2008 SP 1 • SQL Server Compact Edition 3.5 SP 1

  3. Rainer Stropek, cubido business solutions gmbh Unsere Ziele… • Motivation für neue Datenzugriffstechniken klären • Überblick über Entity Framework, ADO.NET Data Services und Sync Services for ADO.NET • Welchen Vorteil bringt ihr Einsatz? • Wie hängen sie zusammen? • Szenarien für Datenzugriff in Web- und Full-Client besprechen • Entscheidungsgrundlage für ihr nächstes Projekt erarbeiten • Qual der Wahl zwischen den BASTA Sessions erleichtern

  4. Rainer Stropek, cubido business solutions gmbh Session-Hinweise • Das Entity Framework in mehrschichtigen Webanwendungen (Mathias Raacke) • Dienstag, 11:45 – 13:00 • ADO.NET Entity Framework, Anfänger und Fortgeschrittene(Holger Schwichtenberg) • Mittwoch, 10:15 – 13:00 • ADO.NET DataServices(Thorsten Kansy) • Dienstag, 16:15 – 17:30 • Datensynchronisierung mit den Sync Services for ADO.NET 2.0(Mathias Raacke) • Donnerstag, 15:15 – 16:30 • AdvancedData Access Patterns (Jörg Neumann) – Level 400! • Mittwoch, 8:30 – 9:45 • Fesselspiele – Data Binding in WPF und Silverlight (Rainer Stropek) • Donnerstag, 10:15 – 11:30

  5. Rainer Stropek, cubido business solutions gmbh Unsere NICHT-Ziele… • Detaillierte Besprechung aller Funktionen der gezeigten Technologien • Konzentration auf Abfrage, nicht auf Manipulation • Bewertung der gezeigten Technologien im Vergleich zu Konkurrenzprodukten • Verkündung der „einzig wahren Wahrheit“

  6. Rainer Stropek, cubido business solutions gmbh Beispiel 1 Was ist schlecht an klassischem ADO.NET?

  7. Rainer Stropek, cubido business solutions gmbh Klassisches ADO.NET Bruch im Programmiermodell Fehlende Kapselung des Geschäftslogik using (varcmd = new SqlCommand(@" selectAnimal.AnimalName, Species.SpeciesName, case when Bird.BirdId is not null then cast( Bird.AvgNumberOfEggsPerWeek as varchar ) + ' eggs per week.‘ else cast( Mammal.AvgNumberOfChildrenPerYear as varchar ) + ' children per year.‘ end asAnimalInfo fromAnimal inner join Farm on Farm.FarmId = Animal.FarmId inner join Species on Animal.SpeciesId = Species.SpeciesId left join Bird on Species.SpeciesId = Bird.BirdId left join Mammal on Species.SpeciesId = Mammal.MammalId whereFarm.FarmId = @FarmId;", conn)) DB-Design im Programm verstreut

  8. Rainer Stropek, cubido business solutions gmbh Klassisches ADO.NET Keine Prüfung zur Kompilierzeit Kein Type Checking intnumberOfCats = 0; foreach(DataRow row in this.AnimalInfoTable.Rows) { if (row["SpeciesName"].ToString() == "Cat") { numberOfCats++; } } MessageBox.Show(numberOfCats.ToString()); und viele, viele weitere Nachteile…

  9. Rainer Stropek, cubido business solutions gmbh ABER!!! • Kapselung kann durch Views, Procedures und Functions verbessert werden • Wiederverwendbarkeit von Code kann über SQLCLR erreicht werden • Sehr effizientes Programmiermodell für kleine und mittelgroße Projekte • Individuelle Anpassungen einfach und schnell • Datenbank erspart viele Kopfschmerzen • Parallelisierung, Locking, Security, etc.

  10. Rainer Stropek, cubido business solutions gmbh Beispiel 2 Linq2SQLDer erste Schritt zur Besserung

  11. Rainer Stropek, cubido business solutions gmbh Datenbankdesign wird in einem Modell gekapselt

  12. Rainer Stropek, cubido business solutions gmbh Datenbankdesign wird in einem Modell gekapselt

  13. Rainer Stropek, cubido business solutions gmbh Linq2Sql Einheitliches Programmiermodell Immer noch fehlende Kapselung des Geschäftslogik var result = from a in context.Animals where a.Farm.FarmId == 1 select new { AnimalName = a.AnimalName, SpeciesName = a.Species.SpeciesName, AnimalInfo = (a.Species.Birds.Count != 0) ?(a.Species.Birds.First().AvgNumberOfEggsPerWeek + " eggs per week.") :(a.Species.Mammals.First().AvgNumberOfChildrenPerYear + " children per year.") }; AnimalInfoTable = result DB-Design im Linq2Sql Modell gekapselt

  14. Rainer Stropek, cubido business solutions gmbh Linq2Sql Prüfung zur Kompilierzeit Type Checking var result = (from a in this.AnimalInfoTable where a.SpeciesName == "Cat“ select a).Count(); MessageBox.Show(result.ToString()); und viele, viele weitere Vorteile…

  15. Rainer Stropek, cubido business solutions gmbh Linq2Sql Kapselung von Geschäftslogik möglich public partial class Animal { public string AnimalInfo { get { return (this.Species.Birds.Count != 0) ? (this.Species.Birds.First().AvgNumberOfEggsPerWeek + " eggs per week.") : (this.Species.Mammals.First().AvgNumberOfChildrenPerYear + " children per year."); } } } Achtung! Auswirkung auf den Aufbau der SQL Queries!

  16. Rainer Stropek, cubido business solutions gmbh ABER!!! • Weniger Kontrolle über erstellten SQL-Code • Teilweise weniger effizienter SQL-Code • Linq2Sql ist auf SQL Server eingeschränkt und ist für mittlere oder größere Projekte nicht zu empfehlen • Kein „Sorglos-Paket“ • Wissen über die Arbeitsweise von Linq und DB ist notwendig!

  17. Rainer Stropek, cubido business solutions gmbh Beispiel 3 Entity FrameworkLinq2Sql wird erwachsen

  18. Rainer Stropek, cubido business solutions gmbh Modell ähnlich Linq2Sql Bessere Möglichkeiten zur Abbildung von Vererbung

  19. Rainer Stropek, cubido business solutions gmbh Entity Framework Model Mapping CSDLConceptual Schema SSDLStore Schema Abstrakte Spezifikation für Entities, Typen, Assoziationen, etc.

  20. Rainer Stropek, cubido business solutions gmbh Modell ähnlich Linq2Sql Flexibles Mapping auf die DB

  21. Rainer Stropek, cubido business solutions gmbh Abbildung der Vererbungs-beziehung im Modell

  22. Rainer Stropek, cubido business solutions gmbh Abbildung der Vererbungs-beziehung im Modell public partial class Species { public virtual string AnimalInfo { get { throw new NotImplementedException(); } } } public partial class Bird { public override string AnimalInfo { get { return this.AvgNumberOfEggsPerWeek + " eggs per week."; } } } public partial class Mammal { public override string AnimalInfo { get { return this.AvgNumberOfChildrenPerYear + " children per year."; } } }

  23. Rainer Stropek, cubido business solutions gmbh Entity Framework var result = from a in context.Animal where a.Farm.FarmId == 1 select new { AnimalName = a.AnimalName, Species = a.Species }; AnimalInfoTable = from x in result.ToList() select new TempResult { AnimalName = x.AnimalName, SpeciesName = x.Species.SpeciesName, AnimalInfo = x.Species.AnimalInfo }; Wissen über Möglichkeiten von Entity Framework Arbeitsweise notwendig

  24. Rainer Stropek, cubido business solutions gmbh ABER!!! • Noch weniger Kontrolle über erstellten SQL-Code als bei Linq2Sql • Teilweise weniger effizienter SQL-Code • Gibt Vererbungshierarchie für Business-Objekte teilweise vor • Kein „Sorglos-Paket“ • Wissen über die Arbeitsweise von Linq und DB ist notwendig!

  25. Rainer Stropek, cubido business solutions gmbh Beispiel 4 Entity Frameworkin theCloud - REST

  26. Rainer Stropek, cubido business solutions gmbh Clients (Tools, Libraries, etc) HTTP (AtomPub) ADO.NET Data Services Framework SQL Data Services SQL Server (Cloud data service) (On premises data service)

  27. Rainer Stropek, cubido business solutions gmbh Basistechnologien von REST(RepresentationalState Transfer) • Entity Data Model • Modellierung des zugrunde liegenden Datenmodells • URIs • URI-Schema wird zur Datenabfrage verwendet • HTTP • HTTP Verbs steuern Aktion • Daten werden als Ressourcen transportiert • Nutzung von Proxies, caching, etc. • Formate • AtomPub (XML) • Json

  28. Rainer Stropek, cubido business solutions gmbh Anwendungsbereiche • Datenzugriff aus RIAs • Spezielle Unterstützung für Silverlight • Plattformunabhängiger Datenzugriff • Zugriff auf Datendienste im Web • Azure Data Services • Zukunft: Astoria Offline

  29. Rainer Stropek, cubido business solutions gmbh Verbindung REST und Entity Framework Verbindung zum Entity Framework namespace FarmSample.Web { public class FarmSampleDataService : DataService<FarmSampleContainer> { public static void InitializeService( IDataServiceConfigurationconfig) { config.SetEntitySetAccessRule("*", EntitySetRights.AllRead); } } }

  30. Rainer Stropek, cubido business solutions gmbh Debugging REST Traffic mit Fiddler http://ipv4.fiddler:55478/FarmSampleDataService.svc/Animal

  31. Rainer Stropek, cubido business solutions gmbh Debugging REST Traffic mit Fiddler

  32. Rainer Stropek, cubido business solutions gmbh Kapselung von Geschäftslogik public class FarmSampleDataService : DataService<FarmSampleContainer> { public static void InitializeService(IDataServiceConfigurationconfig) { config.SetEntitySetAccessRule("*", EntitySetRights.AllRead); config.SetServiceOperationAccessRule("GetAnimals",ServiceOperationRights.All); } [WebGet] public IQueryable<Animal> GetAnimals(intfarmId) { return from a in this.CurrentDataSource.Animal where a.Farm.FarmId == farmId select a; } } Kapselung von Geschäftslogik in „Service Operations“

  33. Rainer Stropek, cubido business solutions gmbh Beispiel 5 Entity Framework und Silverlight

  34. Rainer Stropek, cubido business solutions gmbh Service Reference

  35. Rainer Stropek, cubido business solutions gmbh Gemeinsamer Code für SL + WPF im Bereich Geschäftslogik Link Gegebenenfalls C# Preprozessor nutzen Add as Link #if WPF namespace FarmSample.SmartClient.EntitiyFramework #else namespace FarmSilver.FarmSampleDataService #endif

  36. Rainer Stropek, cubido business solutions gmbh Aufruf des Data Service(Asynchron) var context = new DataServiceContext( new Uri("FarmSampleDataService.svc", UriKind.Relative)); context.BeginExecute<Animal>( new Uri( "Animal?$filter=Farm/FarmIdeq 1&$expand=Species", UriKind.Relative), QueryFinished, context); Asyncexecutionpattern, Query String Parameter

  37. Rainer Stropek, cubido business solutions gmbh Abfragen der Ergebnisse private void QueryFinished(IAsyncResult result) { var context = result.AsyncState as DataServiceContext; var source = context.EndExecute<Animal>(result).ToList(); Animals.ItemsSource = from a in source select a.AnimalName + " is a " + a.Species.SpeciesName + " and produces " + a.Species.AnimalInfo; }

  38. Rainer Stropek, cubido business solutions gmbh Beispiel 6 Offlinefähige Anwendungen auf Basis Entity Framework

  39. Make applications available without network connection Utilize local resources Reduce necessary server power Enable peer-to-peer collaboration without available server Rainer Stropek, cubido business solutions gmbh Das Problem

  40. Rainer Stropek, cubido business solutions gmbh Warum Microsoft Sync Framework? • TechnischeProblemederSynchronisationwerdennureinmalgelöst • Microsoft soll die Schwierigkeitendabeilösen • VerschiedeneTypen von Datenspeichern • Konflikterkennung und –Behandlung • UnverlässlicheNetzwerke, … • MS Sync Framework isteinePlattform, keinfertigesProdukt • Entwicklerkonzentrierensich auf ihrkonkretes Problem, nicht auf die Implementierung von Sync • Erweiterbar und Anpassbar auf verschiedenenEbenen – je nachindividuellemBedarf

  41. Rainer Stropek, cubido business solutions gmbh MS Sync Framework Architecture

  42. Rainer Stropek, cubido business solutions gmbh MS Sync Framework Architecture OfflinefähigkeitfürAnwendungen auf Basis ADO.NET Data Services Framework („Astoria“) Synchronisierenverschiedner DB-Typen ins Web (SQL Services)

  43. Rainer Stropek, cubido business solutions gmbh Was ist die richtige Sync-Technologie? Sync Framework Sync Services for ADO.NET Code required Merge Replication Flexibility

  44. Rainer Stropek, cubido business solutions gmbh Ressourcen • Azure SQL Services • http://www.microsoft.com/azure/sql.mspx • Project „Astoria Offline“ • Astoria Team Blog:http://blogs.msdn.com/astoriateam • „Astoria Offline“ on SQLServices Lab:http://sqlserviceslabs.net/AstoriaOffline.html • Project „Huron“ • „Huron“ on SQLServices Lab:http://sqlserviceslabs.net/huron.html • Guidelines for choosing the right sync technology • http://msdn.microsoft.com/en-us/sync/cc470041.aspx

  45. Startenmiteinerzweischichtigen DB-Anwendung Anwendungofflinefähigmachen Change Tracking erklären Sync over any network Rainer Stropek, cubido business solutions gmbh Agenda Tipp: Demo-DatenbankmitSourcecodeistverfügbar; die versteckten Slides enthalteneineSchritt-für-SchrittAnleitungfür dieses Sample

  46. Rainer Stropek, cubido business solutions gmbh Beispiel 6 – Teil 1 Einfachezweischichtige DB Anwendung

  47. Rainer Stropek, cubido business solutions gmbh Datenbankstruktur

  48. Zweischichtige DB-Anwendung Entity Framework alsDatenzugriffsschicht Rainer Stropek, cubido business solutions gmbh ArchitekturnachSchritt 1

  49. Rainer Stropek, cubido business solutions gmbh Beispiel 6 – Teil 2 Anwendungofflinefähigmachen

  50. Rainer Stropek, cubido business solutions gmbh Datenbankcaching aktivieren

More Related