SlideShare une entreprise Scribd logo
1  sur  30
Sterling DB for Windows Phone 7




                            Jeremy Likness
                            Project Manager, Senior Consultant         Copyright © 2011


                            jlikness@wintellect.com



consulting   training   design   debugging                       wintellect.com
what we do
    consulting     training    design     debugging

 who we are
   Founded by top experts on Microsoft – Jeffrey Richter, Jeff Prosise, and John Robbins –
   we pull out all the stops to help our customers achieve their goals through advanced
   software-based consulting and training solutions.

 how we do it                                           Training
                                                        •   On-site instructor-led training
   Consulting & Debugging                               •   Virtual instructor-led training
   •   Architecture, analysis, and design services      •   Devscovery conferences
   •   Full lifecycle custom software development
   •   Content creation                                 Design
   •   Project management                               •   User Experience Design
   •   Debugging & performance tuning                   •   Visual & Content Design
                                                        •   Video & Animation Production


consulting    training    design     debugging                                   wintellect.com
Agenda
 •   What is Sterling?
 •   Brief History
 •   Stated Goals
 •   Features
 •   Sterling vs. SQL CE
 •   Who is Using Sterling?
 •   Demo: Recipe Application
 •   Questions?


consulting   training   design   debugging   wintellect.com
What is Sterling?
  “Sterling is a lightweight NoSQL object-oriented database for .Net 4.0, Silverlight
  4 and 5, and Windows Phone 7 that works with your existing class structures.
  Sterling supports full LINQ to Object queries over keys and indexes for fast
  retrieval of information from large data sets.”

  • Sterling is not a fully relational database
  • Sterling is not a document database
  • Sterling is not a transactional, large scale database
  • Sterling focuses on specific serialization concerns
  • Sterling is suitable for local caches
  • Sterling is suitable for local lightweight data storage or a window of
    data that synchronizes with a parent server
  • Sterling is a very easy way to quickly persist existing classes, especially
    with dynamic schemas



consulting   training   design    debugging                              wintellect.com
Brief History
  • Many customers were working with Silverlight 4 because of the ability
    to have the out-of-browser (OOB) offline mode
  • Found that existing serialization strategies tended to be shallow,
    invasive, and lacked query capabilities
  • Used various techniques such as synchronizing lists as individual items
    and then providing a “keyed” index or view into the list
  • Built first version of Sterling to abstract this and introduce concept of
    both indexes and foreign keys to serialization
  • Windows Phone 7 was released and Sterling filled the need for a local
    database
  • Was able to port over to run on Windows Phone 7 within hours
    (mostly just needed to stub Silverlight 3 – Silverlight 4 differences)
  • Popularity grew and requests came in for in-memory, .NET, etc.
    versions, (1.5 release)


consulting   training   design   debugging                        wintellect.com
Stated Goals
  • Non-intrusive – don’t modify your classes or
    derive from some base class just to be able to use
    it.
  • Lightweight – current DLL is < 100 kilobytes.
  • Flexible – extensions for adding compression,
    encryption, triggers, custom serializers, etc.
  • Portable – same API in browser, on desktop/server
    and in phone (possible Mono versions in the
    pipeline)


consulting   training   design   debugging    wintellect.com
Features
  •   Recurses complex object graphs and handles cycle conditions
  •   Handles public properties and fields (including interface/abstract)
  •   Ability to suppress serialization of fields, properties, and types
  •   Flexible “is dirty” support to avoid saving full graph
  •   Driver-model allowing in-memory, isolated storage versions for phone
  •   Easy configuration – specify table type, key type, and how to resolve
      the key or index
  •   “Save as” allows saving derived types to base class
  •   Full “foreign key” allowing child objects to serialize to separate tables
  •   Binary serialization for much smaller footprint
  •   Extensions for serialization, compression, encryption, etc.
  •   Trigger support
  •   Database backup and restore
  •   LINQ to Object queries on in-memory keys, indexes, “records”


consulting   training   design   debugging                          wintellect.com
Sterling DB vs. SQL CE
             Feature                 Sterling DB   SQL CE
             Database Backup
             Database Create
             Insert Many Items
             Delete Items
             Truncate Table
             Search Substring
             Search Key
             Search Key w/ Joins
             Search Non-Idx Col
             Search Index
             Serialize Full Graph
             Dynamic Types

consulting   training   design      debugging               wintellect.com
Who is Using Sterling?
  • HealthCaddy
  • Sharp DropBox Client for .NET
    (WP7 Library)
  • Expense Report Tracker
  • Horse Vaccine Tracker
  • Stacks for Instapaper
  • SmugSeven
  • RunKeeper
  • MyReiningScores
  • Many more that you can read
    about on the Sterling site




consulting   training   design   debugging   wintellect.com
demo
   recipe application




consulting   training   design   debugging   wintellect.com
Define your Database
  public class RecipeDatabase : BaseDatabaseInstance
  {
     protected override List<ITableDefinition> _RegisterTables()
     {
        return new List<ITableDefinition>();
     }

      /// this is optional, will default to full type name
      public override string Name
      {
         get { return STERLING_RECIPES; }
      }
  }




consulting   training   design   debugging                   wintellect.com
Define a “Table” and Key

                                        This is provided in the base database class

                                                        Type of the “table”

  CreateTableDefinition<IngredientModel, int>(i => i.Id)


             Type of the key


       Expression: given the “table” how do I get the key?

  * Keys are stored in-memory for fast search & lookup
    (100,000 records w/ Int32 key = 400,000 bytes, < 400Kb memory)



consulting   training   design    debugging                               wintellect.com
Composite Keys
  public static string GetCompositeKey(TestCompositeClass
  testClass)
  {
      if (testClass == null) return string.Empty;
      return string.Format("{0}-{1}-{2}-{3}", testClass.Key1,
             testClass.Key2, testClass.Key3, testClass.Key4);
  }
  // method 1 uses a string
  CreateTableDefinition<TestCompositeClass,string>(GetCompositeKey)

  // method 2 uses a class to represent the key
  // requires a custom serializer
  CreateTableDefinition<TestCompositeClass,
  TestCompositeKeyClass>(k=>
  new TestCompositeKeyClass(k.Key1, k.Key2, k.Key3, k.Key4))



consulting   training   design   debugging               wintellect.com
Define an Index
  CreateTableDefinition<FoodModel, int>(f => f.Id)

                   Extension method for tables
                                   Type of the table
                                               Type of the index
  .WithIndex<FoodModel, string, int>

             Type of the key

  (IDX_FOOD_NAME, f => f.FoodName)
                                           Expression: given table, how do I get index?
                                    Name of the index

   * Indexes, like keys, are stored in memory so choose wisely!



consulting      training   design    debugging                              wintellect.com
Activating the Engine/Databases
  _engine = new SterlingEngine();

  // register custom serializers
  _engine.SterlingDatabase.RegisterSerializer<TypeSerializer>();

  // register any loggers (or use the default logger)
  _logger = new
  SterlingDefaultLogger(SterlingLogLevel.Information);

  // activate the engine – now ready for your databases
  _engine.Activate();

  // here is a database registration
  Database =
  _engine.SterlingDatabase.RegisterDatabase<RecipeDatabase>();



consulting   training   design   debugging                wintellect.com
Drivers
  Database =
  _engine.SterlingDatabase.RegisterDatabase<RecipeDatabase>();

  Database =
  _engine.SterlingDatabase.RegisterDatabase<RecipeDatabase>(
     new IsolatedStorageDriver());

  Database =
  _engine.SterlingDatabase.RegisterDatabase<RecipeDatabase>(
     new MyCustomDriver());




consulting   training   design   debugging               wintellect.com
Serializers
  // required for any keys that are not core value types
  // required for any classes that are not easily de-serialized
  // (i.e. no parameterless constructor, etc. – e.g. “Type” class)

  public class TypeSerializer : BaseSerializer
  {
     public override bool CanSerialize(Type targetType)
     {
        return typeof (Type).IsAssignableFrom(targetType);
     }

      . . .
  }




consulting    training   design   debugging              wintellect.com
Serializers (cont.)
  public class TypeSerializer : BaseSerializer
  {
     public override void Serialize(object target, BinaryWriter
  writer)
      {
          var type = target as Type;
          . . .
          writer.Write(type.AssemblyQualifiedName);
      }
      . . .
  }




consulting   training   design   debugging               wintellect.com
Serializers (cont.)
  public class TypeSerializer : BaseSerializer
  {
     public override object Deserialize(Type type, BinaryReader
  reader)
      {
          return Type.GetType(reader.ReadString());
      }
      . . .
  }




consulting   training   design   debugging               wintellect.com
Triggers
  public class IdentityTrigger<T> : BaseSterlingTrigger<T,int>
  where T: class, IBaseModel, new()
  {
      private static int _idx = 1;

       public IdentityTrigger(ISterlingDatabaseInstance database)
       {
           // if a record exists, set it to the highest value plus 1
           if (database.Query<T,int>().Any())
           {
               _idx = database.Query<T, int>().Max(key => key.Key) +
  1;
             }
       }
  }



consulting   training   design   debugging                wintellect.com
Triggers (cont.)
  public override bool BeforeSave(T instance)
  {
      if (instance.Id < 1)
      {
          instance.Id = _idx++;
      }

       return true;
  }

  public override void AfterSave(T instance)
  {
      // set dirty flag?
      return;
  }



consulting   training   design   debugging      wintellect.com
Database Setup
  // register trigger
  database.RegisterTrigger(new
  IdentityTrigger<FoodModel>(database));

  // check for existing records
  if (database.Query<CategoryModel, int>().Any()) return;

  // truncate tables
  database.Truncate(typeof (MeasureModel));
  database.Truncate(typeof (FoodModel));

  // save an entity (handles update and insert)
  database.Save(measure);

  database.Flush(); // ensure keys/indexes are persisted!



consulting   training   design   debugging                  wintellect.com
Dynamic Tombstoning Support
  var tombstone = new TombstoneModel {SyncType = typeof
  (IRecipeViewModel)};
  tombstone.State.Add(RECIPE_ID, _recipe.Id);
  Tombstone.State.Add("ComplexType", MyComplexType);
  database.Save(tombstone);

  //   handles recursion into sub-lists and dictionaries
  //   further recursion on types
  //   will not choke on cycles
  //   take a look at tests for examples
  //   TestCycle, TestEnum, TestInterfaceProperty, TestNestedInstance




consulting   training   design   debugging                 wintellect.com
Queries
  public IEnumerable<RecipeModel> Recipes
  {
      get        Dual key handled by tuple
      {
          return
              from r in
                  App.Database.Query<RecipeModel, int, string,
  int>(RecipeDatabase.IDX_RECIPE_CATEGORYID_NAME)
              where r.Index.Item1.Equals(CurrentCategory == null ?
  0 : CurrentCategory.Id)
              orderby r.Index.Item2
              select new RecipeModel {Id = r.Key, Name =
  r.Index.Item2};
      }
  }                                       “Covered query” = no deserialization



consulting   training   design   debugging                          wintellect.com
Queries (cont.)
  get
  {
      if (string.IsNullOrEmpty(_foodText))
      {
          return Enumerable.Empty<FoodModel>();
      }
      var foodTextLower = _foodText.ToLower();
      return from f in App.Database.Query<FoodModel, string,
  int>(RecipeDatabase.IDX_FOOD_NAME)
              where f.Index.ToLower().Contains(foodTextLower)
              orderby f.Index
              select new FoodModel {Id = f.Key, FoodName =
  f.Index};
  }
                                     “Covered query” = no deserialization



consulting   training   design   debugging                      wintellect.com
Queries (cont.)
  get
  {
        return from m in App.Database.Query<MeasureModel, int>()

                  orderby m.LazyValue.Value.FullMeasure

      Lazy value access will de-serialize
                   select m.LazyValue.Value;
  }



                                              Second access will retrieve cached value




consulting    training   design   debugging                             wintellect.com
Compression/Encryption
  public class ByteInterceptor : BaseSterlingByteInterceptor
  {
      override public byte[] Save(byte[] sourceStream)
      {
          var retVal = new byte[sourceStream.Length];
          for (var x = 0; x < sourceStream.Length; x++)
          {
              retVal[x] = (byte)(sourceStream[x] ^ 0x80); // xor
          }
          return retVal;
      }

      override public byte[] Load(byte[] sourceStream)
      {
          var retVal = new byte[sourceStream.Length];
          for (var x = 0; x < sourceStream.Length; x++)
          {
              retVal[x] = (byte)(sourceStream[x] ^ 0x80); // xor
          }
          return retVal;
      }
  }




consulting     training    design      debugging                   wintellect.com
Compression/Encryption (cont.)
  databaseInstance.RegisterInterceptor<ByteInterceptor>();
  databaseInstance.RegisterInterceptor<ByteInterceptor2>();

  // called in order of registration on save
  // called in reverse order on load

  // i.e. compression -> encrypt, then decrypt -> decompress




consulting   training   design   debugging               wintellect.com
Sterling Resources
  • Full source, documentation, discussions, support:
    http://sterling.codeplex.com/
  • User’s Guide (your BEST guide is the unit tests):
    http://www.sterlingdatabase.com/
  • Telerik todolist “How-to” Application:
    http://www.telerik.com/products/windows-
    phone/getting-started/todolists.aspx
  • My Blog:
    http://csharperimage.jeremylikness.com/
    (@JeremyLikness on Twitter)

consulting   training   design   debugging    wintellect.com
Questions?




                            Jeremy Likness
                            Project Manager, Senior Consultant
                            jlikness@wintellect.com



consulting   training   design   debugging                       wintellect.com

Contenu connexe

Tendances

Hibernate Developer Reference
Hibernate Developer ReferenceHibernate Developer Reference
Hibernate Developer ReferenceMuthuselvam RS
 
HTML5 and CSS3 refresher
HTML5 and CSS3 refresherHTML5 and CSS3 refresher
HTML5 and CSS3 refresherIvano Malavolta
 
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your ApplicationsThe Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your Applicationsbalassaitis
 
Dojo - from web page to web apps
Dojo - from web page to web appsDojo - from web page to web apps
Dojo - from web page to web appsyoavrubin
 
Understanding
Understanding Understanding
Understanding Arun Gupta
 
Rich internet application development using the dojo toolkit
Rich internet application development using the dojo toolkitRich internet application development using the dojo toolkit
Rich internet application development using the dojo toolkitalexklaeser
 
Hibernate ORM: Tips, Tricks, and Performance Techniques
Hibernate ORM: Tips, Tricks, and Performance TechniquesHibernate ORM: Tips, Tricks, and Performance Techniques
Hibernate ORM: Tips, Tricks, and Performance TechniquesBrett Meyer
 
CORE JAVA & ADVANCE JAVA
CORE JAVA & ADVANCE JAVACORE JAVA & ADVANCE JAVA
CORE JAVA & ADVANCE JAVABALUJAINSTITUTE
 
Hibernate tutorial for beginners
Hibernate tutorial for beginnersHibernate tutorial for beginners
Hibernate tutorial for beginnersRahul Jain
 
All about GWT
All about GWTAll about GWT
All about GWTEd Bras
 
2010 05-21, object-relational mapping using hibernate v2
2010 05-21, object-relational mapping using hibernate v22010 05-21, object-relational mapping using hibernate v2
2010 05-21, object-relational mapping using hibernate v2alvaro alcocer sotil
 
Connect 2014 JMP101: Java for XPages Development
Connect 2014 JMP101: Java for XPages DevelopmentConnect 2014 JMP101: Java for XPages Development
Connect 2014 JMP101: Java for XPages Developmentpanagenda
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architectureAnurag
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 

Tendances (20)

Hibernate
HibernateHibernate
Hibernate
 
Hibernate Developer Reference
Hibernate Developer ReferenceHibernate Developer Reference
Hibernate Developer Reference
 
Advance java1.1
Advance java1.1Advance java1.1
Advance java1.1
 
Hibernate tutorial
Hibernate tutorialHibernate tutorial
Hibernate tutorial
 
HTML5 and CSS3 refresher
HTML5 and CSS3 refresherHTML5 and CSS3 refresher
HTML5 and CSS3 refresher
 
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your ApplicationsThe Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
 
Dojo - from web page to web apps
Dojo - from web page to web appsDojo - from web page to web apps
Dojo - from web page to web apps
 
Jpa
JpaJpa
Jpa
 
Understanding
Understanding Understanding
Understanding
 
Hybernat and structs, spring classes in mumbai
Hybernat and structs, spring classes in mumbaiHybernat and structs, spring classes in mumbai
Hybernat and structs, spring classes in mumbai
 
Rich internet application development using the dojo toolkit
Rich internet application development using the dojo toolkitRich internet application development using the dojo toolkit
Rich internet application development using the dojo toolkit
 
Hibernate ORM: Tips, Tricks, and Performance Techniques
Hibernate ORM: Tips, Tricks, and Performance TechniquesHibernate ORM: Tips, Tricks, and Performance Techniques
Hibernate ORM: Tips, Tricks, and Performance Techniques
 
CORE JAVA & ADVANCE JAVA
CORE JAVA & ADVANCE JAVACORE JAVA & ADVANCE JAVA
CORE JAVA & ADVANCE JAVA
 
Hibernate tutorial for beginners
Hibernate tutorial for beginnersHibernate tutorial for beginners
Hibernate tutorial for beginners
 
All about GWT
All about GWTAll about GWT
All about GWT
 
2010 05-21, object-relational mapping using hibernate v2
2010 05-21, object-relational mapping using hibernate v22010 05-21, object-relational mapping using hibernate v2
2010 05-21, object-relational mapping using hibernate v2
 
Connect 2014 JMP101: Java for XPages Development
Connect 2014 JMP101: Java for XPages DevelopmentConnect 2014 JMP101: Java for XPages Development
Connect 2014 JMP101: Java for XPages Development
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architecture
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
FREE Sql Server syllabus
FREE Sql Server syllabusFREE Sql Server syllabus
FREE Sql Server syllabus
 

En vedette

Allegheny Conference - Apresentação sobre Pittsburgh e o xisto
Allegheny Conference - Apresentação sobre Pittsburgh e o xistoAllegheny Conference - Apresentação sobre Pittsburgh e o xisto
Allegheny Conference - Apresentação sobre Pittsburgh e o xistoGiovanni Sandes
 
Union Budget 2015 16 through Gender Lens by Prof. Vibuti Patel 8-3-2015 esoci...
Union Budget 2015 16 through Gender Lens by Prof. Vibuti Patel 8-3-2015 esoci...Union Budget 2015 16 through Gender Lens by Prof. Vibuti Patel 8-3-2015 esoci...
Union Budget 2015 16 through Gender Lens by Prof. Vibuti Patel 8-3-2015 esoci...VIBHUTI PATEL
 
Home heating Energy Saving Ideas
Home heating Energy Saving IdeasHome heating Energy Saving Ideas
Home heating Energy Saving IdeasPurchase.ie
 
Vibhuti Patel Gender Budgeting, Journal of Asian Business Management, Vol. 7,...
Vibhuti Patel Gender Budgeting, Journal of Asian Business Management, Vol. 7,...Vibhuti Patel Gender Budgeting, Journal of Asian Business Management, Vol. 7,...
Vibhuti Patel Gender Budgeting, Journal of Asian Business Management, Vol. 7,...VIBHUTI PATEL
 
Pricing and Marketing for Freelancers - How to?
Pricing and Marketing for Freelancers - How to?Pricing and Marketing for Freelancers - How to?
Pricing and Marketing for Freelancers - How to?Brian Hogg
 
sentenza cassazione giovanni arcangioli - 17 febbraio 2009
 sentenza cassazione   giovanni arcangioli - 17 febbraio 2009 sentenza cassazione   giovanni arcangioli - 17 febbraio 2009
sentenza cassazione giovanni arcangioli - 17 febbraio 2009Voglioscendere
 
Gender budgetting w.r. to health 12 1-07
Gender budgetting w.r. to health 12 1-07Gender budgetting w.r. to health 12 1-07
Gender budgetting w.r. to health 12 1-07VIBHUTI PATEL
 
Allenjcochran 3rd qtr_docs
Allenjcochran 3rd qtr_docsAllenjcochran 3rd qtr_docs
Allenjcochran 3rd qtr_docsAllen Cochran
 
Vibhuti patel Book Review Anirban Das Social Change vol. 45, no. 1
Vibhuti patel Book Review Anirban Das Social Change vol. 45, no. 1Vibhuti patel Book Review Anirban Das Social Change vol. 45, no. 1
Vibhuti patel Book Review Anirban Das Social Change vol. 45, no. 1VIBHUTI PATEL
 
Success with informational texts.pptx
Success with informational texts.pptxSuccess with informational texts.pptx
Success with informational texts.pptxjsmalcolm
 
I server design and implementation
 I server design and implementation I server design and implementation
I server design and implementationQBsoft Solutions
 
MVVM for Modern Applications
MVVM for Modern ApplicationsMVVM for Modern Applications
MVVM for Modern ApplicationsJeremy Likness
 
Harmony at the workplace
Harmony at the  workplaceHarmony at the  workplace
Harmony at the workplaceVIBHUTI PATEL
 
Google+ Puts Facebook in Check and Facebook Moves its King
Google+ Puts Facebook in Check and Facebook Moves its KingGoogle+ Puts Facebook in Check and Facebook Moves its King
Google+ Puts Facebook in Check and Facebook Moves its KingJamie Nafziger
 
Prof. vibhuti patel's tribute to dr. vina mazumdar 31 5-2013
Prof. vibhuti patel's tribute to dr. vina mazumdar 31 5-2013Prof. vibhuti patel's tribute to dr. vina mazumdar 31 5-2013
Prof. vibhuti patel's tribute to dr. vina mazumdar 31 5-2013VIBHUTI PATEL
 
WinRT and the Web: Keeping Windows Store Apps Alive and Connected
WinRT and the Web: Keeping Windows Store Apps Alive and ConnectedWinRT and the Web: Keeping Windows Store Apps Alive and Connected
WinRT and the Web: Keeping Windows Store Apps Alive and ConnectedJeremy Likness
 

En vedette (16)

Allegheny Conference - Apresentação sobre Pittsburgh e o xisto
Allegheny Conference - Apresentação sobre Pittsburgh e o xistoAllegheny Conference - Apresentação sobre Pittsburgh e o xisto
Allegheny Conference - Apresentação sobre Pittsburgh e o xisto
 
Union Budget 2015 16 through Gender Lens by Prof. Vibuti Patel 8-3-2015 esoci...
Union Budget 2015 16 through Gender Lens by Prof. Vibuti Patel 8-3-2015 esoci...Union Budget 2015 16 through Gender Lens by Prof. Vibuti Patel 8-3-2015 esoci...
Union Budget 2015 16 through Gender Lens by Prof. Vibuti Patel 8-3-2015 esoci...
 
Home heating Energy Saving Ideas
Home heating Energy Saving IdeasHome heating Energy Saving Ideas
Home heating Energy Saving Ideas
 
Vibhuti Patel Gender Budgeting, Journal of Asian Business Management, Vol. 7,...
Vibhuti Patel Gender Budgeting, Journal of Asian Business Management, Vol. 7,...Vibhuti Patel Gender Budgeting, Journal of Asian Business Management, Vol. 7,...
Vibhuti Patel Gender Budgeting, Journal of Asian Business Management, Vol. 7,...
 
Pricing and Marketing for Freelancers - How to?
Pricing and Marketing for Freelancers - How to?Pricing and Marketing for Freelancers - How to?
Pricing and Marketing for Freelancers - How to?
 
sentenza cassazione giovanni arcangioli - 17 febbraio 2009
 sentenza cassazione   giovanni arcangioli - 17 febbraio 2009 sentenza cassazione   giovanni arcangioli - 17 febbraio 2009
sentenza cassazione giovanni arcangioli - 17 febbraio 2009
 
Gender budgetting w.r. to health 12 1-07
Gender budgetting w.r. to health 12 1-07Gender budgetting w.r. to health 12 1-07
Gender budgetting w.r. to health 12 1-07
 
Allenjcochran 3rd qtr_docs
Allenjcochran 3rd qtr_docsAllenjcochran 3rd qtr_docs
Allenjcochran 3rd qtr_docs
 
Vibhuti patel Book Review Anirban Das Social Change vol. 45, no. 1
Vibhuti patel Book Review Anirban Das Social Change vol. 45, no. 1Vibhuti patel Book Review Anirban Das Social Change vol. 45, no. 1
Vibhuti patel Book Review Anirban Das Social Change vol. 45, no. 1
 
Success with informational texts.pptx
Success with informational texts.pptxSuccess with informational texts.pptx
Success with informational texts.pptx
 
I server design and implementation
 I server design and implementation I server design and implementation
I server design and implementation
 
MVVM for Modern Applications
MVVM for Modern ApplicationsMVVM for Modern Applications
MVVM for Modern Applications
 
Harmony at the workplace
Harmony at the  workplaceHarmony at the  workplace
Harmony at the workplace
 
Google+ Puts Facebook in Check and Facebook Moves its King
Google+ Puts Facebook in Check and Facebook Moves its KingGoogle+ Puts Facebook in Check and Facebook Moves its King
Google+ Puts Facebook in Check and Facebook Moves its King
 
Prof. vibhuti patel's tribute to dr. vina mazumdar 31 5-2013
Prof. vibhuti patel's tribute to dr. vina mazumdar 31 5-2013Prof. vibhuti patel's tribute to dr. vina mazumdar 31 5-2013
Prof. vibhuti patel's tribute to dr. vina mazumdar 31 5-2013
 
WinRT and the Web: Keeping Windows Store Apps Alive and Connected
WinRT and the Web: Keeping Windows Store Apps Alive and ConnectedWinRT and the Web: Keeping Windows Store Apps Alive and Connected
WinRT and the Web: Keeping Windows Store Apps Alive and Connected
 

Similaire à Sterling DB for Windows Phone 7

Add-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his DutyAdd-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his Dutyreedmaniac
 
Add-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his DutyAdd-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his DutyLeslie Doherty
 
Entity framework core v3 from sql to no sql
Entity framework core v3 from sql to no sqlEntity framework core v3 from sql to no sql
Entity framework core v3 from sql to no sqlAndrea Tosato
 
U-SQL - Azure Data Lake Analytics for Developers
U-SQL - Azure Data Lake Analytics for DevelopersU-SQL - Azure Data Lake Analytics for Developers
U-SQL - Azure Data Lake Analytics for DevelopersMichael Rys
 
Strudel: Framework for Transaction Performance Analyses on SQL/NoSQL Systems
Strudel: Framework for Transaction Performance Analyses on SQL/NoSQL SystemsStrudel: Framework for Transaction Performance Analyses on SQL/NoSQL Systems
Strudel: Framework for Transaction Performance Analyses on SQL/NoSQL Systemstatemura
 
Introducing U-SQL (SQLPASS 2016)
Introducing U-SQL (SQLPASS 2016)Introducing U-SQL (SQLPASS 2016)
Introducing U-SQL (SQLPASS 2016)Michael Rys
 
Rajnish singh(presentation on oracle )
Rajnish singh(presentation on  oracle )Rajnish singh(presentation on  oracle )
Rajnish singh(presentation on oracle )Rajput Rajnish
 
iOS Beginners Lesson 1
iOS Beginners Lesson 1iOS Beginners Lesson 1
iOS Beginners Lesson 1Calvin Cheng
 
SharePoint 2014: Where to save my data, for devs!
SharePoint 2014: Where to save my data, for devs!SharePoint 2014: Where to save my data, for devs!
SharePoint 2014: Where to save my data, for devs!Ben Steinhauser
 
Rapid SQL Datasheet - The Intelligent IDE for SQL Development
Rapid SQL Datasheet - The Intelligent IDE for SQL DevelopmentRapid SQL Datasheet - The Intelligent IDE for SQL Development
Rapid SQL Datasheet - The Intelligent IDE for SQL DevelopmentEmbarcadero Technologies
 
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...dotNet Miami
 

Similaire à Sterling DB for Windows Phone 7 (20)

Add-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his DutyAdd-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his Duty
 
presentation
presentationpresentation
presentation
 
Add-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his DutyAdd-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his Duty
 
presentation
presentationpresentation
presentation
 
Entity framework core v3 from sql to no sql
Entity framework core v3 from sql to no sqlEntity framework core v3 from sql to no sql
Entity framework core v3 from sql to no sql
 
U-SQL - Azure Data Lake Analytics for Developers
U-SQL - Azure Data Lake Analytics for DevelopersU-SQL - Azure Data Lake Analytics for Developers
U-SQL - Azure Data Lake Analytics for Developers
 
Strudel: Framework for Transaction Performance Analyses on SQL/NoSQL Systems
Strudel: Framework for Transaction Performance Analyses on SQL/NoSQL SystemsStrudel: Framework for Transaction Performance Analyses on SQL/NoSQL Systems
Strudel: Framework for Transaction Performance Analyses on SQL/NoSQL Systems
 
Taming the shrew Power BI
Taming the shrew Power BITaming the shrew Power BI
Taming the shrew Power BI
 
ow.ppt
ow.pptow.ppt
ow.ppt
 
ow.ppt
ow.pptow.ppt
ow.ppt
 
Ow
OwOw
Ow
 
Introducing U-SQL (SQLPASS 2016)
Introducing U-SQL (SQLPASS 2016)Introducing U-SQL (SQLPASS 2016)
Introducing U-SQL (SQLPASS 2016)
 
Plantilla oracle
Plantilla oraclePlantilla oracle
Plantilla oracle
 
Rajnish singh(presentation on oracle )
Rajnish singh(presentation on  oracle )Rajnish singh(presentation on  oracle )
Rajnish singh(presentation on oracle )
 
iOS Beginners Lesson 1
iOS Beginners Lesson 1iOS Beginners Lesson 1
iOS Beginners Lesson 1
 
SharePoint 2014: Where to save my data, for devs!
SharePoint 2014: Where to save my data, for devs!SharePoint 2014: Where to save my data, for devs!
SharePoint 2014: Where to save my data, for devs!
 
Rapid SQL Datasheet - The Intelligent IDE for SQL Development
Rapid SQL Datasheet - The Intelligent IDE for SQL DevelopmentRapid SQL Datasheet - The Intelligent IDE for SQL Development
Rapid SQL Datasheet - The Intelligent IDE for SQL Development
 
Day2
Day2Day2
Day2
 
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
 
Where to save my data, for devs!
Where to save my data, for devs!Where to save my data, for devs!
Where to save my data, for devs!
 

Dernier

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 

Dernier (20)

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 

Sterling DB for Windows Phone 7

  • 1. Sterling DB for Windows Phone 7 Jeremy Likness Project Manager, Senior Consultant Copyright © 2011 jlikness@wintellect.com consulting training design debugging wintellect.com
  • 2. what we do consulting training design debugging who we are Founded by top experts on Microsoft – Jeffrey Richter, Jeff Prosise, and John Robbins – we pull out all the stops to help our customers achieve their goals through advanced software-based consulting and training solutions. how we do it Training • On-site instructor-led training Consulting & Debugging • Virtual instructor-led training • Architecture, analysis, and design services • Devscovery conferences • Full lifecycle custom software development • Content creation Design • Project management • User Experience Design • Debugging & performance tuning • Visual & Content Design • Video & Animation Production consulting training design debugging wintellect.com
  • 3. Agenda • What is Sterling? • Brief History • Stated Goals • Features • Sterling vs. SQL CE • Who is Using Sterling? • Demo: Recipe Application • Questions? consulting training design debugging wintellect.com
  • 4. What is Sterling? “Sterling is a lightweight NoSQL object-oriented database for .Net 4.0, Silverlight 4 and 5, and Windows Phone 7 that works with your existing class structures. Sterling supports full LINQ to Object queries over keys and indexes for fast retrieval of information from large data sets.” • Sterling is not a fully relational database • Sterling is not a document database • Sterling is not a transactional, large scale database • Sterling focuses on specific serialization concerns • Sterling is suitable for local caches • Sterling is suitable for local lightweight data storage or a window of data that synchronizes with a parent server • Sterling is a very easy way to quickly persist existing classes, especially with dynamic schemas consulting training design debugging wintellect.com
  • 5. Brief History • Many customers were working with Silverlight 4 because of the ability to have the out-of-browser (OOB) offline mode • Found that existing serialization strategies tended to be shallow, invasive, and lacked query capabilities • Used various techniques such as synchronizing lists as individual items and then providing a “keyed” index or view into the list • Built first version of Sterling to abstract this and introduce concept of both indexes and foreign keys to serialization • Windows Phone 7 was released and Sterling filled the need for a local database • Was able to port over to run on Windows Phone 7 within hours (mostly just needed to stub Silverlight 3 – Silverlight 4 differences) • Popularity grew and requests came in for in-memory, .NET, etc. versions, (1.5 release) consulting training design debugging wintellect.com
  • 6. Stated Goals • Non-intrusive – don’t modify your classes or derive from some base class just to be able to use it. • Lightweight – current DLL is < 100 kilobytes. • Flexible – extensions for adding compression, encryption, triggers, custom serializers, etc. • Portable – same API in browser, on desktop/server and in phone (possible Mono versions in the pipeline) consulting training design debugging wintellect.com
  • 7. Features • Recurses complex object graphs and handles cycle conditions • Handles public properties and fields (including interface/abstract) • Ability to suppress serialization of fields, properties, and types • Flexible “is dirty” support to avoid saving full graph • Driver-model allowing in-memory, isolated storage versions for phone • Easy configuration – specify table type, key type, and how to resolve the key or index • “Save as” allows saving derived types to base class • Full “foreign key” allowing child objects to serialize to separate tables • Binary serialization for much smaller footprint • Extensions for serialization, compression, encryption, etc. • Trigger support • Database backup and restore • LINQ to Object queries on in-memory keys, indexes, “records” consulting training design debugging wintellect.com
  • 8. Sterling DB vs. SQL CE Feature Sterling DB SQL CE Database Backup Database Create Insert Many Items Delete Items Truncate Table Search Substring Search Key Search Key w/ Joins Search Non-Idx Col Search Index Serialize Full Graph Dynamic Types consulting training design debugging wintellect.com
  • 9. Who is Using Sterling? • HealthCaddy • Sharp DropBox Client for .NET (WP7 Library) • Expense Report Tracker • Horse Vaccine Tracker • Stacks for Instapaper • SmugSeven • RunKeeper • MyReiningScores • Many more that you can read about on the Sterling site consulting training design debugging wintellect.com
  • 10. demo recipe application consulting training design debugging wintellect.com
  • 11. Define your Database public class RecipeDatabase : BaseDatabaseInstance { protected override List<ITableDefinition> _RegisterTables() { return new List<ITableDefinition>(); } /// this is optional, will default to full type name public override string Name { get { return STERLING_RECIPES; } } } consulting training design debugging wintellect.com
  • 12. Define a “Table” and Key This is provided in the base database class Type of the “table” CreateTableDefinition<IngredientModel, int>(i => i.Id) Type of the key Expression: given the “table” how do I get the key? * Keys are stored in-memory for fast search & lookup (100,000 records w/ Int32 key = 400,000 bytes, < 400Kb memory) consulting training design debugging wintellect.com
  • 13. Composite Keys public static string GetCompositeKey(TestCompositeClass testClass) { if (testClass == null) return string.Empty; return string.Format("{0}-{1}-{2}-{3}", testClass.Key1, testClass.Key2, testClass.Key3, testClass.Key4); } // method 1 uses a string CreateTableDefinition<TestCompositeClass,string>(GetCompositeKey) // method 2 uses a class to represent the key // requires a custom serializer CreateTableDefinition<TestCompositeClass, TestCompositeKeyClass>(k=> new TestCompositeKeyClass(k.Key1, k.Key2, k.Key3, k.Key4)) consulting training design debugging wintellect.com
  • 14. Define an Index CreateTableDefinition<FoodModel, int>(f => f.Id) Extension method for tables Type of the table Type of the index .WithIndex<FoodModel, string, int> Type of the key (IDX_FOOD_NAME, f => f.FoodName) Expression: given table, how do I get index? Name of the index * Indexes, like keys, are stored in memory so choose wisely! consulting training design debugging wintellect.com
  • 15. Activating the Engine/Databases _engine = new SterlingEngine(); // register custom serializers _engine.SterlingDatabase.RegisterSerializer<TypeSerializer>(); // register any loggers (or use the default logger) _logger = new SterlingDefaultLogger(SterlingLogLevel.Information); // activate the engine – now ready for your databases _engine.Activate(); // here is a database registration Database = _engine.SterlingDatabase.RegisterDatabase<RecipeDatabase>(); consulting training design debugging wintellect.com
  • 16. Drivers Database = _engine.SterlingDatabase.RegisterDatabase<RecipeDatabase>(); Database = _engine.SterlingDatabase.RegisterDatabase<RecipeDatabase>( new IsolatedStorageDriver()); Database = _engine.SterlingDatabase.RegisterDatabase<RecipeDatabase>( new MyCustomDriver()); consulting training design debugging wintellect.com
  • 17. Serializers // required for any keys that are not core value types // required for any classes that are not easily de-serialized // (i.e. no parameterless constructor, etc. – e.g. “Type” class) public class TypeSerializer : BaseSerializer { public override bool CanSerialize(Type targetType) { return typeof (Type).IsAssignableFrom(targetType); } . . . } consulting training design debugging wintellect.com
  • 18. Serializers (cont.) public class TypeSerializer : BaseSerializer { public override void Serialize(object target, BinaryWriter writer) { var type = target as Type; . . . writer.Write(type.AssemblyQualifiedName); } . . . } consulting training design debugging wintellect.com
  • 19. Serializers (cont.) public class TypeSerializer : BaseSerializer { public override object Deserialize(Type type, BinaryReader reader) { return Type.GetType(reader.ReadString()); } . . . } consulting training design debugging wintellect.com
  • 20. Triggers public class IdentityTrigger<T> : BaseSterlingTrigger<T,int> where T: class, IBaseModel, new() { private static int _idx = 1; public IdentityTrigger(ISterlingDatabaseInstance database) { // if a record exists, set it to the highest value plus 1 if (database.Query<T,int>().Any()) { _idx = database.Query<T, int>().Max(key => key.Key) + 1; } } } consulting training design debugging wintellect.com
  • 21. Triggers (cont.) public override bool BeforeSave(T instance) { if (instance.Id < 1) { instance.Id = _idx++; } return true; } public override void AfterSave(T instance) { // set dirty flag? return; } consulting training design debugging wintellect.com
  • 22. Database Setup // register trigger database.RegisterTrigger(new IdentityTrigger<FoodModel>(database)); // check for existing records if (database.Query<CategoryModel, int>().Any()) return; // truncate tables database.Truncate(typeof (MeasureModel)); database.Truncate(typeof (FoodModel)); // save an entity (handles update and insert) database.Save(measure); database.Flush(); // ensure keys/indexes are persisted! consulting training design debugging wintellect.com
  • 23. Dynamic Tombstoning Support var tombstone = new TombstoneModel {SyncType = typeof (IRecipeViewModel)}; tombstone.State.Add(RECIPE_ID, _recipe.Id); Tombstone.State.Add("ComplexType", MyComplexType); database.Save(tombstone); // handles recursion into sub-lists and dictionaries // further recursion on types // will not choke on cycles // take a look at tests for examples // TestCycle, TestEnum, TestInterfaceProperty, TestNestedInstance consulting training design debugging wintellect.com
  • 24. Queries public IEnumerable<RecipeModel> Recipes { get Dual key handled by tuple { return from r in App.Database.Query<RecipeModel, int, string, int>(RecipeDatabase.IDX_RECIPE_CATEGORYID_NAME) where r.Index.Item1.Equals(CurrentCategory == null ? 0 : CurrentCategory.Id) orderby r.Index.Item2 select new RecipeModel {Id = r.Key, Name = r.Index.Item2}; } } “Covered query” = no deserialization consulting training design debugging wintellect.com
  • 25. Queries (cont.) get { if (string.IsNullOrEmpty(_foodText)) { return Enumerable.Empty<FoodModel>(); } var foodTextLower = _foodText.ToLower(); return from f in App.Database.Query<FoodModel, string, int>(RecipeDatabase.IDX_FOOD_NAME) where f.Index.ToLower().Contains(foodTextLower) orderby f.Index select new FoodModel {Id = f.Key, FoodName = f.Index}; } “Covered query” = no deserialization consulting training design debugging wintellect.com
  • 26. Queries (cont.) get { return from m in App.Database.Query<MeasureModel, int>() orderby m.LazyValue.Value.FullMeasure Lazy value access will de-serialize select m.LazyValue.Value; } Second access will retrieve cached value consulting training design debugging wintellect.com
  • 27. Compression/Encryption public class ByteInterceptor : BaseSterlingByteInterceptor { override public byte[] Save(byte[] sourceStream) { var retVal = new byte[sourceStream.Length]; for (var x = 0; x < sourceStream.Length; x++) { retVal[x] = (byte)(sourceStream[x] ^ 0x80); // xor } return retVal; } override public byte[] Load(byte[] sourceStream) { var retVal = new byte[sourceStream.Length]; for (var x = 0; x < sourceStream.Length; x++) { retVal[x] = (byte)(sourceStream[x] ^ 0x80); // xor } return retVal; } } consulting training design debugging wintellect.com
  • 28. Compression/Encryption (cont.) databaseInstance.RegisterInterceptor<ByteInterceptor>(); databaseInstance.RegisterInterceptor<ByteInterceptor2>(); // called in order of registration on save // called in reverse order on load // i.e. compression -> encrypt, then decrypt -> decompress consulting training design debugging wintellect.com
  • 29. Sterling Resources • Full source, documentation, discussions, support: http://sterling.codeplex.com/ • User’s Guide (your BEST guide is the unit tests): http://www.sterlingdatabase.com/ • Telerik todolist “How-to” Application: http://www.telerik.com/products/windows- phone/getting-started/todolists.aspx • My Blog: http://csharperimage.jeremylikness.com/ (@JeremyLikness on Twitter) consulting training design debugging wintellect.com
  • 30. Questions? Jeremy Likness Project Manager, Senior Consultant jlikness@wintellect.com consulting training design debugging wintellect.com

Notes de l'éditeur

  1. So where is Silverlight today?
  2. So where is Silverlight today?
  3. So where is Silverlight today?
  4. So where is Silverlight today?
  5. So where is Silverlight today?
  6. So where is Silverlight today?
  7. DEMO: Show the TextOverflowDemo project.
  8. So where is Silverlight today?