SpriteHand
Module Border
  Andy's Blog
Module Border
Author: host Created: 3/6/2006 9:55 PM
Adventures in .NET

Using RIA Services Programmatically
By Andy Beaulieu on 1/7/2010 9:56 AM


Many demos of WCF RIA Services show off using the DomainDataSource Class to in a declarative manner to quickly throw together a data-enabled application. And in VS2010, there is added support for using the Data Sources Window to Drag/Drop data entities onto the designer --- this action also adds a DomainDataSource instance into your XAML.

For many applications, using a DomainDataSource in XAML is fine and enables RAD development. But some pundits (Hi Shawn!) argue that having direct interaction with the Data Layer from the UI Layer is bad for proper Model/View separation, testability, and general karma.

Luckily, there are several ways to use WCF RIA Services programmatically - without relying on the DomainDataSource controls in XAML. Let's take a look at some of these programmatic methods:

Download the Demo Code
  * requires SL4/VS2010 Beta 2, WCF RIA Services Beta

Using the DomainContext

The DomainContext class allows the Silverlight client to access the Domain Service Class you created on the server side. A new DomainContext class is automatically generated on the client side for you when you create a new Domain Service.

In the demo, our DomainContext class is named BeerContext. We can load all of the Beer rows from the database using the Load method, passing in an entity query that exists in our Domain Service:

BeerContext _beerContext = new BeerContext();


LoadOperation<Beer> loadBeers = _beerContext.Load(_beerContext.GetBeersQuery());

grdLoadFromContext.ItemsSource = loadBeers.Entities;

We can also use a LINQ query against a DomainContext, allowing us to request more specific records:

EntityQuery<Beer> beerQuery = from b in _beerContext.GetBeersQuery()

                               where b.BrewerId == 1

                               select b;

LoadOperation<Beer> loBeers = _beerContext.Load(beerQuery);

grdLoadWithLinq.ItemsSource = loBeers.Entities;

Using DomainDataSource In Code

Normally, you will see the DomainDataSource class used declaratively in XAML. But we can also utilize a DDS through code and take advantage of its paging, filtering, sorting and grouping functions . Consider this code, which creates a DDS and executes the GetBeers query, only retreiving the Beers for BrewerId == 1. Note that only the records for BrewerId == 1 are sent from the server, because the DDS creates an appropriate query for any paging, filtering, sorting, or grouping functions.

DomainDataSource dsBeers = new DomainDataSource();

dsBeers.LoadSize = 30;

dsBeers.QueryName = "GetBeers";

dsBeers.AutoLoad = true;

dsBeers.DomainContext = _beerContext;

dsBeers.SortDescriptors.Add(new SortDescriptor("BeerName", System.ComponentModel.ListSortDirection.Ascending));

dsBeers.FilterDescriptors = new System.Windows.Data.FilterDescriptorCollection();

dsBeers.FilterDescriptors.Add(new System.Windows.Data.FilterDescriptor("BrewerId", System.Windows.Data.FilterOperator.IsEqualTo, 1));

grdLoadDomainDataSource.ItemsSource = dsBeers.Data;
dsBeers.Load();

 

Comments (9)

RIA Services Talk at CNY .NET Dev Group
By Andy Beaulieu on 1/7/2010 8:12 AM


Thanks to everyone who attended my WCF RIA Services talk at the CNY .NET Developer Group in Syracuse, NY! In this talk we used Visual Studio 2010 Beta 2 and WCF RIA Services Beta to develop a line of business application centered around (what else) Beers! If you are in the Rochester, NY area, I'll be repeating this presentation at the Visual Developers of Upstate NY group on Wednesday, January 27th.

Download the Demo 
  * requires SL4/VS2010 Beta 2, WCF RIA Services Beta

Download the Slides

I had mentioned in the talk that I ran out of time and didn't get to cover the Programmatic Use of WCF RIA Services, and so I have posted that in this separate blog entry.

 

Comments (2)

Happy New Year!
By Andy Beaulieu on 1/2/2010 9:13 AM


Here's wishing everyone a great 2010! I had a good start to the new year myself - I found out that I was again awarded a Microsoft MVP award for Silverlight!

Silverlight has been evolving at light speed, and I'm really looking forward to all the great new features coming in SL4, VS2010, and beyond.

Comments (4)

Using Fiddler to Capture RIA Services
By Andy Beaulieu on 12/13/2009 8:50 AM

If you're a fan of Fiddler, you may have used it with prior versions of RIA Services to capture the traffic between your Silverlight client and your server side. This worked great in the past because RIA Services used a (somewhat bastardized) JSON encoding format.

But in the latest release of WCF RIA Services, the default encoding format is binary - which is not supported by Fiddler out of the box. Luckily, Samuel Jack has created a WCF Binary Inspector plug-in for Fiddler, which allows for examination of the new default encoding.

Here is how to setup Fiddler to capture traffic with WCF RIA Services:

Download and Install Fiddler

Download the Fiddler WCF Binary Inspector plugin

Extract BinaryMessageFiddlerExtension.dll and copy to the Fiddler Inspectors Directory, by default C:\Program Files\Fiddler2\Inspectors

Now, start up Fiddler – and then start up your RIA Services application. You’ll quickly notice that you’re not capturing any traffic L This is because Fiddler doesn’t capture from localhost by default. There are a variety of solutions to this, some of which may or may not work for your configuration.

The easiest solution that works for me is to append a period (“.”) just after localhost in your application's URL.

After that, you should see captured sessions as you make requests, and you can visit the "WCF Binary" tabs to see the request and response values, decoded.

Comments (8)

Creating a Pinball Game in Silverlight
By Andy Beaulieu on 11/30/2009 8:57 PM


My Coding4Fun tutorial on "Creating a Pinball Game in Silverlight" is now available!

Some time ago, Brian Peek and the Coding4Fun team asked if I could create a tutorial on game programming, and we settled on a pinball game using the Physics Helper Behaviors and Farseer Physics Engine. A few months delay later :) and the video and walkthrough text are now up! Given the visual nature of using Behaviors in Blend, a video tutorial makes a lot of sense.

You can view the tutorial here... but the video walkthrough is quite cramped on the Coding4Fun site. So instead you may want to get a full screen view here.

For more info on the Physics Helper Library, check out:

Physics Helper on Codeplex

Physics Helper Demos

Comments (3)

There's an App for THAT?!
By Andy Beaulieu on 11/30/2009 6:34 PM


Let it be known that the game previously known as "Froggy Math" is now known as "Wormy Math"

"Why" you ask?

It only figures that with all of the Flash, Silverlight, and Mobile games being created every day that there would be some overlap in ideas and titles. But this one is just bizarre:

Yesterday, I uploaded a little Silverlight educational game which I had called "Froggy Math." When I came up with the title just a few weeks ago, I had searched fairly extensively to make sure the name wasn't taken.

Today, I was searching around again for Froggy Math, and hit on this iPhone app released just a couple of weeks ago:

Not only are the names the same, but the ideas are similar (at least, as far as I can tell - I don't have an iPhone so I haven't actually played this game).

I have to say though, I think my game looks a little cooler :) and I'm guessing has better physics!

 

Comments (1)

Silverlight Game: Froggy Math
By Andy Beaulieu on 11/29/2009 9:46 PM


"Froggy Math" is a little educational Silverlight game that I've been picking at when I had a free hour here and there for the past several weeks. The goal was to create something for my kids to practice their math facts (which I learned are now called "combinations"), and at the same time pique their interest in programming. I think the result was pretty good --- at least the kids seem interested in playing for awhile!

In Froggy Math, the player feeds worms to a hungry frog - but the correct worm must be picked out of the pack. The player can choose to practice Multiplication, Division, Addition or Subtraction and a "Report Card" keeps track of their grade in each subject.

The game was pretty quick to knock off and here are some notes on the development:

  • Uses the Physics Helper Library (Behaviors) for Physics.
  • The Worms are manipulated using a "pick spring"
  • There is a lot of use of Perspective 3D transforms - see if you can find them all :)
  • Uses the Fluid Container Behavior for the water effect
  • Uses GPU Acceleration, which greatly reduced CPU usage with all of the physics and fluid container action.
  • Isolated Storage is used to store the player's "report card" statistics.

I would consider this a "beta" release so if anyone has any suggestions or bugs, please let me know!

 

Comments (6)

Sharing Blend Workspace Settings
By Andy Beaulieu on 11/19/2009 8:49 PM


Expression Blend 3 has two pre-defined Workspaces, available under the Window/Workspaces menu.

  1. the Design Workspace is tuned for layout and UI creation, and is the default view you see in Blend.
  2. the Animation Workspace is tuned for creating Storyboard Animations and gives you a larger view of the StoryBoard timeline.

We can also create and save our own custom Workspaces using the Window/Save as New Worspace menu option. And we can Rename and Delete Workspaces using the Window/Manage Workspaces menu option.

Workspaces save the following information:

  • visibility of panels
  • the size and orientation of panels
  • the panels that are within panel groups
  • whether a panel is floating or docked

Sharing Blend Workspace Settings

I was recently asked, how can we share Workspace settings across multiple users? For example, you may have set up the perfect Workspace for completing a task, and want to share this with other users in your team.

While Blend does not support this natively, we can hack around a bit to get a Workspace copied to another machine.

  1. Copy the Workspace settings files stored in this folder:

    %APPDATA%\Microsoft\Expression\Blend3\Workspaces

    Each Workspace has a "default" version (containing the original settings from the "Save" operation), and a "modified" version (containing any changes made after the Save).
  2. We also need to add settings to the user.config file located in this folder:

    %APPDATA%\Microsoft\Expression\Blend3\

    Open the user.config file in your favorite XML editor (well, notepad works). Look for the node containing UserWorkspaces, and add the name of the Workspace to this value. Note that we can add multiple Workspace names, with a pipe delimiter. 

    <ConfigurationObject Name="WorkspaceService">
        <PrimitiveObject Name="ActiveWorkspace">WorkspaceX</PrimitiveObject>
        <PrimitiveObject Name="UserWorkspaces">WorkspaceX|WorkspaceY</PrimitiveObject>
      </ConfigurationObject>

Comments (2)

Silverlight 4 Beta Summary
By Andy Beaulieu on 11/18/2009 5:29 PM

At the PDC Conference today, The Gu unveiled the first public release of Silverlight 4 (Beta). This release has some really great additions, but I am most excited about the advances in Business Application Development for Silverlight.

Why will Silverlight 4 be better for Business App Development?

  1. RIA Services
    WCF RIA Services (formerly .NET RIA Services) makes it quick and easy to create a Service layer that wraps your Data Access Layer - whether your DAL uses the Entity Framework, LINQ to SQL, or another technology. Note the name change from ".NET RIA Services" to "WCF RIA Services." As confusing as another name change is, this helps clarify that this new release is built on top of WCF - The communications channel from the Silverlight client to the RIA Domain Service is now a *.svc file - which means we can Add a Service reference to the service side, get WSDL, and customize WCF service settings.

  2. Cider Support
    VS2010 includes a XAML editor (Cider), supporting drag/drop forms design and data binding. In the past, developers needed to learn Blend to do basic GUI form design. Don't get me wrong, I love Blend : and we will still need to switch over to Blend to take advantage of Behaviors, States, Templating, animation, drawing, and other tasks. But many developers were turned off by the fact that Visual Studio had no WYSIWYG designer for XAML.

  3. Data Sources Window
    WCF RIA Services and VS2010 now support a rapid Drag/Drop design experience which allows you to quickly put together data-enabled Silverlight applications.

Getting Started with Silverlight 4 Beta

Here are some links to get you past the burn and into the groove...

Silverlight 4 Beta, RIA Services... and Beer!
I've updated my Beer database demo with a walkthrough for Silverlight 4, VS2010, and the latest RIA Services.

Silverlight 4 Beta: Implicit Styles
We've been waiting for this little feature for awhile! Finally we can set a global style for a control.

Silverlight 4 Beta - A Guide
This is a great overview of new stuff from Tim Heuer.

Silverlight 4 Tech Whitepaper
John Papa walks through lots of the new goodies in SL4.

Video Resources *UPDATED*

Silverlight 4 Beta Videos on silverlight.net
Tim H. has been busy indeed, and has published a slew of videos for Silverlight 4 including most of the new toys!

PDC09 Videos
At this point, they're just starting to trickle in, but keep checking here for drops of the session recordings from PDC09! Day 2 has all of the Silverlight goodies.

 

Comments (1)

Silverlight 4 Beta: Implicit Styles
By Andy Beaulieu on 11/18/2009 5:24 PM

The ability to create Implicit Styles has been a sorely missed feature in Silverlight… until Silverlight 4! The concept of an implicit style is very simple – you define how you want ALL instances of a control to look in one place (you can then override those styles if you need to).

Setting an implicit style in XAML

Let’s say we want all of our TextBox controls in our application to have White text on a Red background. We can step into our App.xaml and add the following XAML:

    <Application.Resources>
              <Style TargetType="TextBox">
                     <Setter Property="Background" Value="#FFFF0000"/>
                     <Setter Property="Foreground" Value="#FFFFFFFF"/>
              </Style>
    </Application.Resources>

The key here is that we did NOT specify an x:Key value on the TextBox – only a TargetType. After this change, if we add a couple of TextBox controls to a UserControl, we’ll see the style take effect:

<StackPanel Width="100">
       <TextBox Text="TextBox 1" />
       <TextBox Text="TextBox 2" />
</StackPanel>


Of course, we can override a property that is styled if we wish – for example maybe we want to change the foreground colors of the TextBoxes to a color other than White:

<StackPanel Width="100">
       <TextBox Text="TextBox 1" Foreground="Blue" />
       <TextBox Text="TextBox 2" Foreground="Green" />
</StackPanel>

Creating Implicit Styles in Blend

To create an Implicit Style in Blend, right-click an element and select Edit Template/Edit a Copy or Edit Template/Create Empty.

… then select the “Apply to all” radio button option in the Create Style Resource dialog:

Some Limitations

Currently, Silverlight 4 does not support BasedOn styling for Implicit Styles. This is possible in WPF and allows for the “tweaking” of a style at a local scope. For example, you may define an Implicit style for a TextBox at the application level, but then want to tweak just a couple of properties of the style in a local scope (maybe a UserControl or Container).

Comments (0)

Module Border Module Border
Module Border
  Subscribe
Module Border
RSS   Twitter
Module Border Module Border
Module Border
  Diversions
Module Border


PHYSAMAJIG
This Windows app was created using Physics Helper XAML, and the Farseer Physics Engine.
DOWNLOAD

MORE INFO



TALKING RAGDOLL
This Windows Phone app was created using Silverlight, the  Physics Helper Library,  and the Farseer Physics Engine. It gets interesting when you import your friends photos and have your way with them!

MORE INFO



BOSS LAUNCH
This physics game won first place in the Server Quest Contest. Created using Silverlight , the Physics Helper Library,  and the Farseer Physics Engine.
PLAY IT

MORE INFO



DESTROY ALL INVADERS
A scrolling shooter game where the objective is to destroy the invading UFO's flying over a neighborhood of your choosing. Imagery provided by Microsoft Virtual Earth. Created using Silverlight.
PLAY IT

INFO AND CODE



PHYSICS HELPER DEMOS
These demos were created for the Physics Helper Library, which makes it easy to create physics games and simulations using Expression Blend, Silverlight, and the Farseer Physics Engine.
PLAY IT

INFO AND CODE



HOOK SHOT
This little basketball game took first place in the TeamZoneSports Silverlight Contest. Created using Silverlight and the Farseer Physics engine.
PLAY IT

MORE INFO



SORT THE FOOBARS
A game where you need to sort the good foobars from the bad ones. Created using Silverlight and the Farseer Physics engine.
PLAY IT

MORE INFO



POLYGON PHYSICS DEMO
A demo showing polygon physics where the user draws physics objects with the mouse. Created using Silverlight and the Farseer Physics engine.
PLAY IT

MORE INFO



SILVERLIGHT ROCKS!
Destroy the asteroids before they destroy your ship! Created using Silverlight.
PLAY IT

INFO AND CODE



FISH GAME
A simple game of harpoon-the-fish. Written using the AJAX Sprite Toolkit.
PLAY IT

INFO AND CODE

Module Border Module Border
Module Border
  Search_Blog
Module Border
Module Border Module Border
Module Border
  Blog_Archive
Module Border
Module Border Module Border
Copyright (c) 2014 andy.beaulieu.com - Login