Skip to content
September 21, 2011

From Entity Model to Data on your iPhone/Windows Phone 7/Silverlight application

This post describes a utility I have written to automate the generation of sync components for remote applications. Read on…

I’ve been doing a lot of Silverlight application design and development recently. A significant number of the applications have also been design to be installed on the desktop, and to run both when online and offline. In the past when building Smart Client applications with offline capabilities, I would either ‘cache’ service calls to the server so I could ‘replay’ them when connected, or I would use a local database to cache information and synchronise information when a connection became available.

This latter technique does not work with web based applications though because the web based applications can’t access a local database. Or at least that was the story until Silverlight4 and the Microsoft Sync Framework 4.0 CTP. This has been out for a while now, and basically integrates with ‘classic’ Sync Framework 2.1 components, to provide interop between the Sync Framework running on a server and sync components running in a Silverlight application, or for applications running on Windows Phone 7 or even Apple iPhone. When building a Silverlight application for example, you can write the application so that it stores it’s data in the local store, confident in the knowledge that the Sync Framework will do all the heavy lifting when it comes to synchronising the data with your corporate SQL Server. That opens up a host of cool remote worker application possibilities.

Now when designing and building these applications, I start by using the Entity Framework designer in VS 2010 to build my application entity model. That works well, and results in an entity model, and a database project that will construct my corporate SQL Server database. To use the Microsoft Sync Framework CTP, I now run the Sync Framework Sync Service Utility, and start by constructing a Sync Configuration. This is an XML file which describes one or more Sync scopes that I wish to run.

Let’s keep things simple, and suppose that I want a simple Master/Detail table schema, and that I want to synchronise these details with my Silverlight application with a single sync scope. I model the tables in the Entity Framework design inside Visual Studio. Then I generate the database project and use this to create my SQL Server database scripts, which when run generate my SQL Server database with all tables etc created. Then, I run the Sync Service Utility, and specify the tables in the SQL Server I want to synchronise, and it generates an XML file that describes this sync scope. Lastly, I run the Sync Service Utility, or the command line version of the utility to create the server side components that can synchronise the scope I have defined, and the client side objects that will represent my Master and Detail tables, appropriately configured to synchronise with my server side service. For Silverlight, these client side objects will be represented as IEnumerable<Class> lists that are stored in Local Storage, and can be synchronised with the tables on the server.

All of that is a lot of manual steps. It’s not too bad if you do it once, but typically you will be making small changes to your entity model throughout development, and even a small change like changing the NULLABLE attribute for a field on a table means you need to go and re-create your server side service and client side components. This is a pain, especially if you have automated most of the rest of your project build and test. The problem is that the creation of the XML Sync Scope definition file is a manual process. This is where my utility comes in…

The Entity Framework model file (*.edmx) is also an XML file, which describe the data model both in terms of objects, and in terms of data tables. My utility reads in the file, and using LINC to XML converts the file into a Sync Scope configuration file. The utility does need an additional XML file which specifies which tables you want in your scope, and the filters etc on those tables (since you rarely want to synchronise every row of every table), but those details don’t tend to change much. The Sync Framework Utility can then use this generated Sync Scope configuration file to provision the SQL Server database, and generate server side and client side code.

One of my colleagues (Aggie Rossa) has now taken the code and created a GUI for the utility in case you want to run it yourself, or you can add the utility to your build commands and automate the entire process, so you can work with your Entity Model, and when you build your project it will create the database, provision it for Sync, and generate the server side and client side components. Full source is available from my web site.

Enjoy

PS. Don’t laugh at my LINC To XML code, it’s the first I’ve ever written J

February 9, 2011

Home Server – Drive Extender Options

I’ve had my week hi-jacked with the recent release of the Windows Home Server “Vail” Release Candidate.

There has been heaps of comment about the removal of the Drive Extender functionality (much of it bitter). Actually, for me Drive Extender is not such an issue, because in my opinion it was always a bit of an ad hoc solution. It worked well, but I would have liked to have seen it implemented as a lower level system driver, rather than at the file system level. I tend to use only a couple of big disks, either in a RAID array or separately. Assuming you still plan to use Vail, what are your options? I did a little research, and then tried out some of the options on my Hyper-V system. None of the options I present are a replacement for DE, but they may fit your requirements.

Option #1, Hardware RAID on the motherboard – If you have two hard drives that are the same size and preferably the same manufacturer, then you can set up a RAID 0 array. For example my Gigabyte motherboards support Hardware RAID. I’m not going to go into details here, because many of the posts indicated that RAID is too complex for the average home user, and I figure those of you who may use this approach probably already know about RAID and the various configurations.

Option #2, Hardware RAID on eSATA device – I am the proud owner of a SOHOTank ST2, which is an external enclosure which takes two hard disks (the same size), and optionally applies RAID 0 to the two drives. I’ve used this to prop up a 4 TB disk on the VAIL RC. There are other devices available that take more drives, and provide other RAID configurations. I mention this because although this is an expensive solution (at least when compared to a bunch of old disks you have lying around), it works well, and the user really does not need any technical knowledge. It also performs really well.

Software options, Windows Server Disk Management – You can use the Windows Server Disk Manager in Vail to combine multiple drives together. I added 5 different disks, sized 8GB, 4GB, 8GB, 10 GB and 10 GB (the reason for the weird sizes is that I created virtual disks, because I did not want to have to set up a physical system until Vail is released).

  1. I extended the 8GB drive with the 4 GB drive (Right-click on the 8GB drive, and select Extend Volume…, and then select spanned volume). I formatted the resulting 12 GB drive, and assigned my “Pictures” share to this drive. Then I copied about 10 GB of photos onto this drive, leaving about 2 GB of free space. Then, while Home Server continued to run and serve up media, I went back into Disk Management, and extended the volume I just created again, with the other 8 GB drive. Immediately the Home Server Dashboard reported that I had about 10 GB of free space available. Now I tested this with virtual drives, but it will work perfectly with physical hard drives. This is equivalent to the “extender” functionality in Drive Extender.
  2. I did the same as above, but instead of selecting a spanned volume, I select striped volume (using only the two 8 GB drives because a striped volume will only stripe upto the size of the smallest drive. Note I don’t think this option is so useful, because of the requirement of having two identically sized drives. This option gives increased speed, but given that all access to media is typically over the network, I don’t get any benefit from having my drive work slightly faster.
  3. The last option I tried is to provide fault-tolerance using the “Add Mirror” command. This takes two drives that are the same size, and keeps a copy of your files on both. DE did this by copying all files to two separate disks, which is similar. This is a software version of RAID 1. Again this functioned perfectly

So, the software options provide at least some of the functionality of DE, but do NOT provide a means to pull a drive out of the middle of a bunch of drives (say if it is starting to fail).

PS. One last option I did not investigate. There is also the ability to create a RAID 5 array, which is a much more efficient way of getting fault tolerance than RAID 1. I might try that tomorrow.

January 27, 2011

Optionally Hiding Columns, and Showing Columns in Different Orders

Well, as they say, “the road to hell is paved with good intentions”. I started this blog in October, and only now have I gotten around to writing anything.

I had a requirement for a tabular report, in which I could for each column optionally choose of that column was displayed, and also change the ordering of the columns.

A report with columns that are optionally visible can be created using the column visibility attribute, and setting this to an expression. However, the drawback with this approach is that the visible columns in the table will not be automatically expanded to fill the space made available by the hidden columns. This can lead to an ugly look to the table.



The two clips above show the originally designed table, and the table displayed with one column optionally missing.

I found an alternate approach, in a post by Jon at the following URL

http://stackoverflow.com/questions/1440381/ssrs-keep-a-table-the-same-width-when-hiding-columns-dynamically. (Complete with code in VB.NET). This answered my first issue, and provided a clue for my second issue, namely that I needed to dynamically change the RDL code.

The approach I took was as follows:

  1. Design my reports so that they include all columns required, in some default column order.
  2. Develop a function which loads the RDLC file into an XmlDocument, and dynamically modifies it.

    The Tablix XML element contains firstly a list of TablixColumn definitions.


<Tablix Name=”table1″>

<TablixBody>

<TablixColumns>

<TablixColumn>

<Width>1in</Width>

</TablixColumn>…

This is followed by the TablixRow definition, which contains the TablixCells.

<TablixRow>

<Height>0.22in</Height>

<TablixCells>

<TablixCell>

<CellContents>

<Textbox Name=”textbox2″>

<CanGrow>true</CanGrow>

<KeepTogether>true</KeepTogether>

<Paragraphs>

<Paragraph>

<TextRuns>

<TextRun>

<Value>Date</Value>

<Style>

<FontFamily>Tahoma</FontFamily>

<FontSize>11pt</FontSize>

<FontWeight>Bold</FontWeight>

<Color>White</Color>

</Style>

</TextRun>

</TextRuns>

<Style />

</Paragraph>

</Paragraphs>

<rd:DefaultName>textbox2</rd:DefaultName>

<Style>

<Border>

<Color>LightGrey</Color>

<Style>Solid</Style>

</Border>

<BackgroundColor>SteelBlue</BackgroundColor>

<PaddingLeft>2pt</PaddingLeft>

<PaddingRight>2pt</PaddingRight>

<PaddingTop>2pt</PaddingTop>

<PaddingBottom>2pt</PaddingBottom>

</Style>

</Textbox>

</CellContents>

</TablixCell>

The function finds these nodes in the RDLC XML Document using Xpath, and builds up a list of XmlNodes which represent each of the columns. It then replaces both the TablixColumn and TablixRow nodes in the TablixBody node, only writing the columns that are to be displayed, in the order that they need to be displayed. This function will work for any simple tabular report, and means the report authors do not need to put any special coding in the report, or add specific parameters to the report.

The function also uses a second function which determines the new column sizes that should be used, and overwrites these values in the TablixColumn nodes. In my case this function simply calculates the sum of the original columns, and then equally splits the space made available across all columns that will be visible, but a more sophisticated algorithm can be easily substituted.

Note: I will be posting the function to this blog in a week or so, after it has gone through testing

Follow

Get every new post delivered to your Inbox.