The Silverlight side of life

by ManniAT 5. April 2010 23:33
Technorati-Tags: ,

This series is about a promotion game we built to support our iPhone apps.
You can play the game here – it is “early stage” but you can really win!

Before I wrote about WCF Services – here is the client part of this.
For the newcomers – here is the start of this series.

When we create a reference to a WCF service we get everything we need generated.
So we have the classes we use with the service, methods to invoke the service and so on.

I decided to keep these generated class as they are. The question was WHERE do I call the methods.
Since the service is “not perfectly designed” some calls contain things that are needed in multiple “forms”.

So my decision was to do the things in the application class. And I use simple .NET events and properties to handle WCF calls and their results.
The idea is simple and easy. App has some static properties (and methods) which interact with the WCF service.

A sample:

Snippet created with CBEnhancer
private static PromoInfo m_piThePromoInfo;
public static PromoInfo ThePromoInfo {
    get { return m_piThePromoInfo; }
    private set {
        if(m_piThePromoInfo != value) {
            m_piThePromoInfo = value;
            if(PromoInfoChanged != null) {
                PromoInfoChanged();
            }
        }
    }
}

And the “form” (user control) subscribes to this event (PromoInfoChanged) like this:

Snippet created with CBEnhancer
    App.PromoInfoChanged += new App.EntryChangedDG(App_PromoInfoChanged);
}

#region Promoinfo handling
void App_PromoInfoChanged() {
    SetPromoInfo(App.ThePromoInfo);
}
private void SetPromoInfo(PromoInfo pI) {
    if(pI == m_piLastSet) {    //we got this - nothing new to set
        return;
    }
    m_piLastSet = pI;    //remember it
    string strUriExtend = pI.PromoTweetStartText + App.CallKey + " " + string.Format(pI.SpreadTextAddition, pI.TwitterName);
    //btnFollowMe.NavigateUri = null;

    btnSpread.NavigateUri = new Uri("http://twitter.com/?status=" + HttpUtility.UrlEncode(strUriExtend));
    txtFollowMe.Text = pI.FollowMeText;
    App.SimpleFormatToHTML(pI.FollowMeTextInfo, tbFollowMeInfo);
    txtSpread.Text = pI.SpreadText;

And if the “form” wants to call a WCF method it looks like this:

Snippet created with CBEnhancer
if(!App.IsSearching) {
    if(App.SearchResult()) {
        rtcSearchResults.StartTransition();
    }
}

I know I could do some of these things using binding and dependency properties or “more Silverlight like” methods. But it fulfills my needs in this case and (as you see in the above method) one part of this project is the extended use of the new telerik RadTransistionControl.

The next post will handle this topic – and it will address readers which may not be so familiar with Silverlight as you might be. Since the RadTransitionControl is really new I feel (in my role as telerik MVP) a need to write something about this control which also helps newcomers.
So please excuse my “primitive” handling here.

To finalize the above shown things here the completed handler for the PromoInfo call:

Snippet created with CBEnhancer
void m_tsClient_GetPromoInfoCompleted(object sender, GetPromoInfoCompletedEventArgs e) {
        if(e.Error == null && e.Cancelled == false) {
            ThePromoInfo = e.Result;
        }
    }

That’s it about the WCF Silverlight client. In the next part I’ll show you how simple you can achieve stunning results, cool animations and other things like this – even if you are a “got to be used to designer” like me Happy

Stay tuned
Manfred

Tags: ,

Silverlight | twitter

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading


Powered by BlogEngine.NET 2.0.0.0