Beginner BXF / CSLA question DoRefresh / BeginRefresh

Beginner BXF / CSLA question DoRefresh / BeginRefresh

Old forum URL:

nhwilly posted on Sunday, November 07, 2010

Hey, guys.  I know I am still writing in VB and that's probably a problem, but I'm trying to build a test app using my own data to match the BXF example SLDemo.  I am using WPF instead of SL, and I am using some Codesmith templates to make this happen.

What I can't seem to do is get the BeginRefresh to work.  DoRefresh is fine.  I know, there's supposed to be a handler on the end, but for the life of me i can't seem to build it.  Usually I can work through stuff like this, but this one is driving me nuts. 

It looks like BeginRefresh needs a handler, but the C# sample code does a BeginRefresh with just a factory method string.  How is it working for C# and not VB?

Here's the Business method:

        Public Shared Sub NewNHApplicationAsync(ByVal handler As EventHandler(Of DataPortalResult(Of NHApplication)))
            Dim dp As New DataPortal(Of NHApplication)()
            AddHandler dp.CreateCompleted, handler
        End Sub

And here's the code in the viewmodel:

        Public Sub New()
            Shell.Instance.ShowStatus(New Status() With { _
                                      .Text = "Creating new application", _
                                      .IsBusy = True _


        End Sub

Naturally, since the signature is different I get the No Such Factory Method error.

I guess I just don't  know the syntax to make this work.

The lack of parity between VB and C# events and other stuff is hard to work through, so I guess I''m going to have to man up and learn C#, but VB is simply easier for me to read, so I've tried to stick with it.

Anybody have any example code for VB?

Pretty please?


p.s. Yes, I have the SL video series and the MVVM series, too.  But it's all in C#.

RockfordLhotka replied on Sunday, November 07, 2010

I don't see the problem to be honest - your method signature looks correct. I tried the same basic thing and it works.

Here's my business class

Imports Csla
Imports Csla.Serialization

Public Class Class1
  Inherits BusinessBase(Of Class1)

  Public Shared Sub NewClass1(ByVal callback As EventHandler(Of DataPortalResult(Of Class1)))
    DataPortal.BeginCreate(Of Class1)(callback)
  End Sub
End Class

 Here's my viewmodel:

Imports Csla.Xaml
Imports SilverlightClassLibrary1

Public Class Class1Vm
  Inherits ViewModel(Of Class1)

  Public Sub New()
    BeginRefresh(AddressOf Class1.NewClass1)
  End Sub
End Class

For a simple test I set the ProxyTypeName to "Local" so creation occured on the client - but the viewmodel invoked the factory, which ran the data portal and gave me back a model.

I think this is the same as you code?

nhwilly replied on Monday, November 08, 2010

Rocky, thanks for the quick reply.

I believe I got stuck and then was trying too many different approaches at once and overlapping the attempts - classic deer in the headlights.

Your code worked perfectly and when I went back and tried a fetch in my code, which required parameters to be passed, I got stumped again, although I know this is my own lack of knowledge. 

I then attempted both new and fetch operations with strings instead of the delegate and it works fine.

I'll find some sample delegate code that handles parameter passing and hopefully that will do it.

Would it be of any help if I translated the SLDemo code into VB?


RockfordLhotka replied on Monday, November 08, 2010

Just remember that the callback parameter is always last, and that the root data portal only allows one paramter:

DataPortal.BeginFetch(Of Customer)(id, callback)

goes to a server-side method like this:

Public Sub DataPortal_Fetch(ByVal id As Whatever)

as long as "Whatever" is a serializable type (in Silverlight this means IMobileObject).

I am always happy to accept contributions like a VB version of the C# samples, absolutely! Send me email directly (rocky at lhotka dot net) and I'll get you a contributor agreement if you are interested in doing that.

Copyright (c) Marimer LLC