Resources

Sterling Isolated Storage Database

Paul Ballard

12 Oct , 2013  

Sterling is a lightweight object-oriented database implementation for Silverlight 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.
Read more

,

Wintellect Blogs

Telerik, Windows Phone 7, Sterling, and Free Licenses

Jeremy Likness

9 Jun , 2011  

You’ve heard plenty about the Sterling database engine on this blog. I recently released version 1.5 which extended the reach of the database and added several feature requests. My article on Sterling for Isolated Storage on Windows Phone 7 was also recently published in MSDN Magazine. The phone has made this a very popular engine and it has been used in several production applications that you can read about in this discussion thread.

Telerik is a vendor that provides controls and tools for developers. I’ve used them in projects myself and favor them for Silverlight development because they are developer, designer, and MVVM friendly. In addition to controls, they provide an ORM, code analysis tools, unit mocking and testing aids, and even a free .NET decompiler. I’m also impressed by how involved with the development community they are, sponsoring many events including the one I recently spoke at, CodeStock.

To showcase the UI controls that Telerik has for the Windows Phone 7 and demonstrate how you can create a very high performance application, the team at Telerik produced a full how-to code example called “todolist.” You can download the source (including a trial of RadControls for Windows Phone 7) and read the details of the project here.… Read more

,

Wintellect Blogs

The Sterling NoSQL Database in a Mango World

Jeremy Likness

5 Jun , 2011  

I was at the MIX 2011 event. There was an “Open Source Fest” before the event and I came to showcase the Sterling NoSQL Database project that I run (and code most of, although there have been numerous enhancements and patches now added by a growing team of fantastic supporters). I was happy to speak to several people who hadn’t heard of the database before, not because it was unknown but because of the opportunity to introduce it to others.

There seems to be a common impression that Sterling is a database specifically designed to fill a hole on the Windows Phone 7 platform – namely, the lack of a database. That’s actually not entirely true. The database was originally created to fill that hole for Silverlight in the web browser. It happened that the platform shared so much with the phone that it was an easy port (perhaps a few dozen lines of code to tweak, mostly to close the gap between the Silverlight 4 version and the Silverlight 3-ish that the phone presented at the time).

Once on the phone, it filled another gap I hadn’t anticipated: the dreaded tombstone operation. People were struggling to find a consistent, easy way to serialize state and Sterling, able to handle nearly any type and depth of object graph and capable of serializing it without all of the ceremony of deriving from a custom class or splashing attributes through all of your code, was happy to oblige.… Read more

, , ,

Wintellect Blogs

Supporting Non-Supported Entities like IEnumerable in Sterling

Jeremy Likness

27 Apr , 2011  

While the Sterling NoSQL database supports many items out of the box, there are certain item types it just doesn’t know enough about. For example, consider a property defined as IEnumerable. Unlike a list, an enumerable is not bounded. It simply exposes an iterator, and for all we know, that iterator might be an enumerable method that produces random numbers in an infinite loop. The property doesn’t reveal what the backing store is, and while Sterling could guess that it is a list or array or other structure, guessing doesn’t cut it when faithfully persisting an object graph.

Fortunately, Sterling was designed with extensibility in mind. If it can’t infer how to handle a structure, you can train it using custom serializers. With the latest changeset (Sterling Changeset 76881 – part of the path from the 1.4 beta to 1.5 RTM) some key internals to Sterling were exposed that help this process. In the 1.0 version of Sterling, a custom serializer had to manage all serialization from that node. There was no “re-entry” into the recursive model that Sterling uses to walk object graphs, handle foreign keys and manage lists, dictionaries, and other structures. This limited the flexibility of custom serializers.… Read more

Wintellect Blogs

Performance Optimization of Silverlight Applications using Visual Studio 2010 SP1

Jeremy Likness

16 Apr , 2011  

Today I decided to work on some miscellaneous performance optimization tasks for my Sterling NoSQL Database that runs on both Silverlight and Windows Phone 7. The database will serialize any class to any level of depth without you having use to attributes or derive from other classes, and despite doing this and tracking both keys and relationships between classes, you can see it manages to serialize and deserialize almost as fast as native methods that don’t provide any of the database features:

Note: click on any smaller-sized image in this post to see a full-sized version in case the text is too small for the sample screenshots.

Obviously the query column is lightning fast because Sterling uses in-memory indexes and keys. I decided to start focusing on some areas that can really help speed up the performance of the engine. While there are a lot of fancy profiling tools on the market, there really isn’t much need to look beyond the tools built into Visual Studio 2010. To perform my analysis, I decided to run the profile against the unit tests for the in-memory version of the database. This will take isolated storage out of the picture and really help me focus on the issues that are part of the application logic itself and not artifacts of blocking file I/O.… Read more

,

Wintellect Blogs

A Numeric Input Control for Windows Phone 7

Jeremy Likness

5 Mar , 2011  

I’m exploring the phone more and more and came across the case of allowing the user to enter digits. One thing to keep in mind on the phone is that the form factor requires approaches to input that are different from the traditional desktop. A desktop application might handle numeric entry by simply filtering the text box, but that assumes a keyboard-centric model. On the phone, touch is key.

Of course, at the most basic level we could simply define an input scope on the phone and the SIP would give the user a number-friendly keyboard:

<TextBox Text="{Binding Weight,Mode=TwoWay,Converter={StaticResource DoubleConverter}}" 
    Grid.Row="1"<TextBox.InputScope<InputScope<InputScopeName NameValue="Digits"/</InputScope</TextBox.InputScope</TextBox

With those hints in place, you will get a keyboard like this:

Numeric SIP on Windows Phone 7

It still isn’t easy to hit the numbers and you will still have to validate the field. You could also use a slider like the infamous date control (I’ll let you explore that one for yourself) but it’s not the ideal experience. In fact, I thought about my favorite experience entering numbers on the phone and it had to be this:

Windows Phone 7 Calculator

Yes, it’s the calculator. It’s clean, easy, and famliar. So, I decided to build a control to allow a calculator-like experience for entering numbers.… Read more

,

Wintellect Blogs

Codestock and Knoxville, Tennessee: Are You Coming in 2011?

Jeremy Likness

20 Feb , 2011  

Codestock is an amazing event that I first attended last year in Knoxville, Tennessee. It’s hosted at a great venue in a wonderful city and loaded with exciting sessions. I had just as much fun speaking at my session as I did attending the other sessions and learning about new technologies.

I’ve submitted two talks this year and if you are planning on coming and are interested in these topics, please cast your vote. Codestock, unlike other venues, gives priority voting to those who have registered. If you do register, you can vote for my sessions here:

The Sterling Database for Silverlight and Windows Phone 7: The release of Silverlight 4 and Windows Phone 7 have created an explosion of line of business applications written in Silverlight. The framework provides a powerful advantage with its ability to run offline and disconnected from the network. For browser applications this provides a unique data storage challenge. Windows Phone 7 applications must also cater to the “tombstoning” scenario and efficiently serialize and rehydrate data when the program is swapped to the background and back. Sterling is an open source object-oriented database that addresses these needs by storing data in isolated storage. Sterling works with existing classes/types and is extremely lightweight.… Read more

,

Wintellect Blogs

Windows Phone 7 Tombstoning with MVVM and Sterling

Jeremy Likness

14 Feb , 2011  

Yesterday I wrote about an ultra light Windows Phone 7 MVVM Framework and mentioned that I would deal with tombstoning in a later post. This is the post.

Sterling makes tombstoning very easy because it handles serialization of just about any type of object. To show an example, we’ll start with the concept of a view model that holds a set of categories (that a pivot is bound to) and a set of items that are filtered by category. When tombstoned, the application must remember the category as well as any item that is selected.

Build the Tombstone

First thing to do is create the generic tombstone model to hold values. This is the model:

public class TombstoneModel
{
    public TombstoneModel()
    {
        State = new Dictionary<string, object();
    }

    public Dictionary<string, objectState { get; set; }

    public T TryGet<T(string key, T defaultValue)
    {
        if (State.ContainsKey(key))
        {
            return (T)State[key];
        }
        return defaultValue;
    }
}

But wait … what’s the point? Isn’t that just like the application settings object? Sure … sort of. There are a few problems with application settings. First, they don’t handle complex object graphs and the objects must be serializable. They don’t recognize things like “foreign keys” or sub lists.… Read more

,

Wintellect Blogs

Sterling Object-Oriented Database 1.0 RTM

Jeremy Likness

11 Feb , 2011  

In early 2010 I was working on several Silverlight projects that were driven by the need to provide a working offline solution. Isolated storage was the obvious answer. Unfortunately, serializing 10,000 contacts came with some overhead and I realized quickly that I was following some similar patterns when it came to handling large sets of data: I would serialize the key fields (for example, names for contacts) in order to manage lists that I could filter in-memory, while saving the bulk of data for separate serialization events.

This inspired me to create Sterling as a way to ease the burden of persisting data. I looked at other options and didn’t like having to change my classes just to save data (for example, make them derive from a database base class when I already was deriving them from my own helper classes). I also didn’t like the inflexibility of options available. So, I set out to build something lightweight and non-intrusive that would give the user full control over serialization. The key would be to provide keys and indexes through lambda expressions to make it easy to access common data using LINQ to Object queries in memory while saving the “slow” part (loading from disk) for when it was needed.… Read more

,

Wintellect Blogs

Sterling Silverlight and Windows Phone 7 Database Triggers and Auto-Identity

Jeremy Likness

15 Jan , 2011  

Sterling changeset 72063 [browse the source code here] introduces triggers. The trigger is a powerful feature that allows you to universally intercept database operations. Their application in Sterling resolves several concerns, including:

  • Validation — prevent a save operation from succeeding if data integrity is compromised, or prevent a delete operation when prerequisites are not met
  • Data-specific concerns — should the business layer be concerned with a “last modified date” that relates to the database? Use a trigger to set the date consistently without involving other pieces of your application
  • Post-save processing (for example, clear a “dirty flag” once the item is persisted)

Declaring the Trigger

Declaring the trigger in Sterling is straightforward. Every entity that is persisted by sterling is defined by a combination of the type and the key type. The trigger is no different. Internal to Sterling, a basic interface allows the database engine to manage triggers without having to close the generic type:

internal interface ISterlingTrigger
{
    bool BeforeSave(Type type, object instance);
    void AfterSave(Type type, object instance);
    bool BeforeDelete(Type type, object key);
}

Next, we want a more strongly typed version for definitions and for external sources that are aware of the type. This allows those interfaces to close the generic and work with a strongly typed interface:

internal interface ISterlingTrigger<T, TKey: ISterlingTrigger where T: class, new() 
{
    bool BeforeSave(T instance);
    void AfterSave(T instance);
    bool BeforeDelete(TKey key);
}

Side Note: Covariance and Contravariance

Wikipedia has a good article explaining covariance and contravariance.… Read more

, ,