Friday, May 28, 2010

Using Silverlight Isolated Storage

To store string data in Isolated Storage:

IsolatedStorageSettings.ApplicationSettings.Add("KeyName",
    Value);

To remove:

if (IsolatedStorageSettings.ApplicationSettings.Contains("KeyName"))
    IsolatedStorageSettings.ApplicationSettings.Remove("KeyName");

Invoking a Method Call Over RIA Services

To invoke a method through RIA Services:

On the server side, declare the method, an decorate it with the [Invoke] annotation. Return types can be simple types or collections.  Not sure if complex types work or not.

[Invoke]

public string BuildAdjusterMetricBatch(string users)
{
    DoSomeWork()

    return batch;
}

On the client side, invoke the method, and pass it a function for the asynchronous Callback:

var context = new Web.Services.MSIClaimContext();
context.BuildAdjusterMetricBatch(txtFilter.Text,  
    BatchBuildCompleted, null);

then declare a method for the callback that matches the return type of the Method.

void BatchBuildCompleted(InvokeOperation<string>
    invokeOperation)
{
    string myValue = invokeOperation.Value;
    DoClientSideWork();

}

Tuesday, May 25, 2010

Column Headers in Reporting Services 2008

If the column headers in Reporting Services 2008 won't repeat on a new page, do the following.

  • Click on the triangle button at the bottom of the screen, and click on "Advanced Mode".
  • In the "Row Groups" section of the window, click on the "Static" element at the top of the list.
  • Set the following properties:
    • FixedData = True
    • KeepWithGroup=After
    • RepeatOnNewPage=True

image

Load operation failed for query ‘GetUser’

Getting this error when deploying a Silverlight RIAServices application to a new server.

Fiddler helped debug this one.   Pulling up the Response header in Fiddler gave the following additional information:

IIS specified authentication schemes 'IntegratedWindowsAuthentication, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous. Change the IIS settings so that only a single authentication scheme is used

Had to reboot the server after making the change, but this resolved the problem.

Sunday, May 23, 2010

Calling a RIAServices Query from Code

var context = Project.Web.Services.DomainContext();

context.Load(
    context.GetSomeItemQuery(parameters),
    LoadBehavior.RefreshCurrent, DataLoaded, null);

void DataLoaded(LoadOperation<Web.Models.Entity> loadOperation)
{
    loadOperation.Entities = …

DependencyProperty

Sometimes it is necessary to bind to a custom property on a Silverlight Control.  In order for that to work properly, you need to set it up as a DependencyProperty. 

public int Denominator
{
    get { return (int)this.GetValue(DenominatorProperty); }
    set { this.SetValue(DenominatorProperty, value); }
}

public static readonly DependencyProperty DenominatorProperty
    = DependencyProperty.Register(
            "Denominator", //Property Name
            typeof(int), //Property Type
            typeof(QualitativeStatusIndicator),  // type of Control
            new PropertyMetadata(
                 0, // default value
                 Denominator_PropertyChangedCallback));  // callback

private static void Denominator_PropertyChangedCallback(
    DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    QualitativeStatusIndicator myControl
       = d as QualitativeStatusIndicator;
    myControl.SetStatus();
}

Friday, May 21, 2010

Adding and Deleting from a RIAServices DomainDataSource

If you drag and drop a ‘Details’ form from the DataSources window onto a Silverlight form, by default you won’t have any add or save ability.  To fix this, you have to add buttons to the form to do the Insert and Delete.  The code behind for those buttons looks like this:

private void btnAdd_Click(object sender, RoutedEventArgs e)
{
    Web.Models.UserEdit newUser = new Web.Models.UserEdit();
    userEditDomainDataSource.DataView.Add(newUser);
}
private void btnDelete_Click(object sender, RoutedEventArgs e)
{
    userEditDomainDataSource.DataView.Remove(userEditDomainDataSource.DataView.CurrentItem);
}

Thursday, May 20, 2010

Converting One Kind of Collection to Another

Getting an ObservableCollection from an IEnumerable (this is the type of loadOperation.Entities

myCollection = new ObservableCollection<myEntityType>(loadOperation.Entities)

// DON’T do this. It returns a null value

//myCollection = (ObservableCollection<myEntityType>)
//loadOperation.Entities;

Converting an iQueryable returned by EntityFramework into a List.  Note that this is an extension method, which means you must be “Using System.Linq” in order have this function available to the iEnumerable.

var myQueryable = (from x in myContext.table select x).ToList()