CLSADataProvider in Silverlight - Design Time Data

CLSADataProvider in Silverlight - Design Time Data

Old forum URL: forums.lhotka.net/forums/t/6415.aspx


Jack posted on Friday, February 13, 2009

Rocky,

I was looking at this blog and was curious if his second option would work with the CSLA DataProvider in Silverlight?  If you had a minute I would be interested in your off the top of your head thoughts before I added it to my list of things to try.

http://karlshifflett.wordpress.com/2008/10/11/viewing-design-time-data-in-visual-studio-2008-cider-designer-in-wpf-and-silverlight-projects/

Thanks

jack

RockfordLhotka replied on Friday, February 13, 2009

We enable design time data generation in both WPF and Silverlight. The model is the same either way - you implement a DesignTime_Create() method in your business class that generates this data.

The data portal detects that it is running in design time and invokes that method instead of doing normal data portal processing.

Jack replied on Friday, February 13, 2009

You guys never cease to impress me – I’ll give that a whirl today. 

 

How does it work with filtering down to child objects?

 

Do I need to call the children myself of will that happen if I just create 5 new child objects and add them to a list?

 

Or can I put the DesignTime_Create in my listBO and add them there?

 

Ie) ParentBO /w ChildListBO

 

 

 

From: RockfordLhotka [mailto:cslanet@lhotka.net]
Sent: Friday, February 13, 2009 7:57 AM
To: jaddington@alexandergracie.com
Subject: Re: [CSLA .NET] CLSADataProvider in Silverlight - Design Time Data

 

We enable design time data generation in both WPF and Silverlight. The model is the same either way - you implement a DesignTime_Create() method in your business class that generates this data.

The data portal detects that it is running in design time and invokes that method instead of doing normal data portal processing.



RockfordLhotka replied on Friday, February 13, 2009

The data portal only invokes the root object. It is your responsibility to create a mock-up of the object graph as you wish.

 

I should point out that I’m not real happy with the method signature right now, as it returns a value. I think it should be a static void method like the other data portal methods, and that’ll probably change in 3.6.2.

 

Rocky

 

 

From: Jack Addington [mailto:cslanet@lhotka.net]
Sent: Friday, February 13, 2009 9:20 AM
To: rocky@lhotka.net
Subject: RE: [CSLA .NET] CLSADataProvider in Silverlight - Design Time Data

 

You guys never cease to impress me – I’ll give that a whirl today. 

 

How does it work with filtering down to child objects?

 

Do I need to call the children myself of will that happen if I just create 5 new child objects and add them to a list?

 

Or can I put the DesignTime_Create in my listBO and add them there?

 

Ie) ParentBO /w ChildListBO

 

 

 

From: RockfordLhotka [mailto:cslanet@lhotka.net]
Sent: Friday, February 13, 2009 7:57 AM
To: jaddington@alexandergracie.com
Subject: Re: [CSLA .NET] CLSADataProvider in Silverlight - Design Time Data

 

We enable design time data generation in both WPF and Silverlight. The model is the same either way - you implement a DesignTime_Create() method in your business class that generates this data.

The data portal detects that it is running in design time and invokes that method instead of doing normal data portal processing.

 



Jack replied on Friday, February 13, 2009

If you let me know when you modify it, I’ll be happy to try the implementation.

 

From: Rockford Lhotka [mailto:cslanet@lhotka.net]
Sent: Friday, February 13, 2009 8:31 AM
To: jaddington@alexandergracie.com
Subject: RE: [CSLA .NET] CLSADataProvider in Silverlight - Design Time Data

 

The data portal only invokes the root object. It is your responsibility to create a mock-up of the object graph as you wish.

 

I should point out that I’m not real happy with the method signature right now, as it returns a value. I think it should be a static void method like the other data portal methods, and that’ll probably change in 3.6.2.

 

Rocky

 

 

From: Jack Addington [mailto:cslanet@lhotka.net]
Sent: Friday, February 13, 2009 9:20 AM
To: rocky@lhotka.net
Subject: RE: [CSLA .NET] CLSADataProvider in Silverlight - Design Time Data

 

You guys never cease to impress me – I’ll give that a whirl today. 

 

How does it work with filtering down to child objects?

 

Do I need to call the children myself of will that happen if I just create 5 new child objects and add them to a list?

 

Or can I put the DesignTime_Create in my listBO and add them there?

 

Ie) ParentBO /w ChildListBO

 

 

 

From: RockfordLhotka [mailto:cslanet@lhotka.net]
Sent: Friday, February 13, 2009 7:57 AM
To: jaddington@alexandergracie.com
Subject: Re: [CSLA .NET] CLSADataProvider in Silverlight - Design Time Data

 

We enable design time data generation in both WPF and Silverlight. The model is the same either way - you implement a DesignTime_Create() method in your business class that generates this data.

The data portal detects that it is running in design time and invokes that method instead of doing normal data portal processing.

 

 



Jack replied on Wednesday, February 25, 2009

Rocky,

 

I couldn’t get this to work in Silverlight.  I had to add a public constructor because the designtime didn’t pick up anything in the #if !SILVERLIGHT … #endif directives.

 

But that didn’t seem to help.  Is there a way to deb

 

From: Jack Addington [mailto:cslanet@lhotka.net]
Sent: Friday, February 13, 2009 9:46 AM
To: jaddington@alexandergracie.com
Subject: RE: [CSLA .NET] CLSADataProvider in Silverlight - Design Time Data

 

If you let me know when you modify it, I’ll be happy to try the implementation.

 

From: Rockford Lhotka [mailto:cslanet@lhotka.net]
Sent: Friday, February 13, 2009 8:31 AM
To: jaddington@alexandergracie.com
Subject: RE: [CSLA .NET] CLSADataProvider in Silverlight - Design Time Data

 

The data portal only invokes the root object. It is your responsibility to create a mock-up of the object graph as you wish.

 

I should point out that I’m not real happy with the method signature right now, as it returns a value. I think it should be a static void method like the other data portal methods, and that’ll probably change in 3.6.2.

 

Rocky

 

 

From: Jack Addington [mailto:cslanet@lhotka.net]
Sent: Friday, February 13, 2009 9:20 AM
To: rocky@lhotka.net
Subject: RE: [CSLA .NET] CLSADataProvider in Silverlight - Design Time Data

 

You guys never cease to impress me – I’ll give that a whirl today. 

 

How does it work with filtering down to child objects?

 

Do I need to call the children myself of will that happen if I just create 5 new child objects and add them to a list?

 

Or can I put the DesignTime_Create in my listBO and add them there?

 

Ie) ParentBO /w ChildListBO

 

 

 

From: RockfordLhotka [mailto:cslanet@lhotka.net]
Sent: Friday, February 13, 2009 7:57 AM
To: jaddington@alexandergracie.com
Subject: Re: [CSLA .NET] CLSADataProvider in Silverlight - Design Time Data

 

We enable design time data generation in both WPF and Silverlight. The model is the same either way - you implement a DesignTime_Create() method in your business class that generates this data.

The data portal detects that it is running in design time and invokes that method instead of doing normal data portal processing.

 

 

 



RockfordLhotka replied on Friday, February 27, 2009

Silverlight does require a public constructor on all business objects.

 

Also, Silverlight requires that the DesignTime_Create() method be public.

 

Finally, to my knowledge, Visual Studio doesn’t invoke the data binding infrastructure when working with a Silverlight form in the designer. Blend does though. So in VS you’ll only get design time data for WPF forms, not Silverlight. But in Blend you should get design time data in both environments.

 

Rocky

Jack replied on Friday, April 24, 2009

Does anybody have a working example of DesignTimeData working in Silverlight for 3.6.2?  I'm not getting anything at all.  I have a very similar example to the WpfDesignTime example with a ROLB.

I have the runtime working but I cannot for the life of me get any data for design time.

The WPF example doesn't use a DataTemplate but I've tried also not doing that and overriding ToString() in my BO.  I tried to debug Blend DesignTime but I'm not having any success there trapping anything.

Any ideas?  Thanks

jack


My Control:
<UserControl.Resources>
        <csla:CslaDataProvider x:Key="ObjectInfoListDataProvider"
                               ManageObjectLifetime="True"
                               IsInitialLoadEnabled="False"
                               ObjectType="Epm.Library.ProgramObject.ObjectInfoList, Epm.Library"
                               FactoryMethod="GetObjectInfoList" />
    </UserControl.Resources>
    <Border BorderThickness="1,1,1,1"
            CornerRadius="10,10,10,10"
            Padding="2"
            BorderBrush="AliceBlue">
        <Grid x:Name="LayoutRoot"
             DataContext="{Binding Source={StaticResource ObjectInfoListDataProvider}, NotifyOnValidationError=true, ValidatesOnExceptions=true}"

            <ListBox x:Name="ObjectList" ItemsSource="{Binding Mode=OneWay}"     VerticalAlignment="Stretch" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Vertical" HorizontalAlignment="Stretch">
                            <TextBlock Text="{Binding Mode=OneWay, Path=CalcObjectName}" VerticalAlignment="Top" HorizontalAlignment="Stretch"  />
                            <TextBlock Text="{Binding Mode=OneWay, Path=CalcSourceName}" Foreground="#FFBF2D2D" VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="20"/>
                            <TextBlock Text="{Binding Mode=OneWay, Path=CalcObjectSortedName}" VerticalAlignment="Top" HorizontalAlignment="Stretch"  />
                            <TextBlock Text="{Binding Mode=OneWay, Path=ObjectType}" VerticalAlignment="Top" HorizontalAlignment="Stretch"  />
                            <TextBlock Text="{Binding Mode=OneWay, Path=ObjectStatus}" VerticalAlignment="Top" HorizontalAlignment="Stretch"  />
                            <TextBlock Text="{Binding Mode=OneWay, Path=LastRefreshDateString}" VerticalAlignment="Top" HorizontalAlignment="Stretch" />
                            <TextBlock Text="{Binding Mode=OneWay, Path=NextScheduledPeriodText}" VerticalAlignment="Top" HorizontalAlignment="Stretch"  />
                            <TextBlock Text="{Binding Mode=OneWay, Path=CalcObjectName}" VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
    </Border>
</UserControl>

My BOL:

 public static ObjectInfoList GetObjectInfoList()
        {
            return new ObjectInfoList();
        }

public void DesignTime_Create()

        {

            IsReadOnly = false;
           
            var r1 = ObjectInfo.GetDesignTimeObjectInfo(100);
            var r2 = ObjectInfo.GetDesignTimeObjectInfo(101);
            var r3 = ObjectInfo.GetDesignTimeObjectInfo(142);
            this.Add(r1);
            this.Add(r2);
            this.Add(r3);
            IsReadOnly = true;
        }

My BO:

   public static ObjectInfo GetDesignTimeObjectInfo(int objectId)
        {

            ObjectInfo objectInfo = new ObjectInfo();

            objectInfo.LoadProperty<int>(ObjectIdProperty, objectId);
            objectInfo.LoadProperty<int>(ObjectSiteIdProperty, 47);
            objectInfo.LoadProperty<int>(ProgramIdProperty, 400);
            objectInfo.LoadProperty<int>(ObjectSourceIdProperty, objectId);
            objectInfo.LoadProperty<int>(ObjectNumberProperty, objectId*103);
           
            objectInfo.LoadProperty<string>(ObjectStatusCodeProperty, "ACTIVE");
            objectInfo.LoadProperty<string>(ObjectTypeCodeProperty, "PARTICIPANT");
            objectInfo.LoadProperty<string>(ObjectStatusProperty, "Active");
            objectInfo.LoadProperty<string>(ObjectTypeProperty, "Participant");

            objectInfo.LoadProperty<string>(CalcObjectNameProperty, "NAPLS-07-00" + objectId.ToString());
            objectInfo.LoadProperty<string>(CalcObjectSortedNameProperty, objectId.ToString());

            objectInfo.LoadProperty<string>(CalcSourceNameProperty, "Jack Addington" + objectId.ToString());
            objectInfo.LoadProperty<string>(CalcSourceSortedNameProperty, "Addington, Jack" + objectId.ToString());
           
            objectInfo.LoadProperty<SmartDate>(LastRefreshDateProperty, DateTime.Now);
           
            objectInfo.LoadProperty<string>(ResourcingIssueIndProperty, "1");
            objectInfo.LoadProperty<string>(SchedulingConflictIndProperty, "1");
            objectInfo.LoadProperty<decimal>(NextScheduleIdProperty, 324332);
            objectInfo.LoadProperty<SmartDate>(NextScheduledPeriodDateProperty, DateTime.Today.AddMonths(6));
            objectInfo.LoadProperty<string>(NextScheduledPeriodTextProperty, "Visit #3: Six Month Followup");
            objectInfo.LoadProperty<string>(HasOverdueTaskIndProperty, "1");
            objectInfo.LoadProperty<string>(ReadyForDataEntryIndProperty, "1");
            objectInfo.LoadProperty<string>(ReadyForDoubleEntryIndProperty, objectId.ToString().Substring(objectId.ToString().Length -1,1));
            objectInfo.LoadProperty<string>(HasMissingDataIndProperty, "1");
            objectInfo.LoadProperty<string>(HasDataIssueIndProperty, "1");
            objectInfo.LoadProperty<string>(HasDoubleEntryIssueIndProperty, "1");

            return objectInfo;
        }




RockfordLhotka replied on Friday, April 24, 2009

Silverlight design time data only works in Blend from what I can tell. It doesn’t appear that the VS designer creates instances of Silverlight resources, and so there’s nothing to trigger the creation of any design time data.

 

Not that I’m ruling out there being a bug in how CslaDataProvider does this – the whole thing is largely guesswork on our part, because there is no formal concept of design time data for XAML at all – we’re literally making this stuff up as we go until Microsoft formalizes the concept (hopefully in VS 2010 and Blend 3).

 

In other words, we noticed that the Blend designer actually creates instances of types defined as resources. We used this knowledge to trigger creation of design time data.

 

And the WPF designer in VS does the same thing.

 

But it doesn’t appear (from my testing) that the Silverlight designer in VS creates instances of the objects. And if VS doesn’t create an instance, then there’s really nothing CSLA can do – because I’m surely not going to write my own designer :)

 

Rocky

 

Jack replied on Friday, April 24, 2009

It is in blend that I am *trying* to get some data to see.  I have noticed with playing with the WPF example that I have to open/close Blend to pick up changes to the underlying BO.  If I make certain changes then the DesignTime data just disappears until I reload Blend.


RockfordLhotka replied on Friday, April 24, 2009

.NET can only load an assembly into an appdomain once – and there’s no way to unload an assembly. It may be that Blend is loading the DLL and then it is stuck in memory even if a newer version comes along.

 

Microsoft really needs to get a more comprehensive story in place around this. But then the whole designer issue needs major improvement – I’m hoping for VS 10 and B3 to address a lot of these things.

 

Rocky

 

 

From: Jack [mailto:cslanet@lhotka.net]
Sent: Friday, April 24, 2009 4:46 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: RE: CLSADataProvider in Silverlight - Design Time Data

 

It is in blend that I am *trying* to get some data to see.  I have noticed with playing with the WPF example that I have to open/close Blend to pick up changes to the underlying BO.  If I make certain changes then the DesignTime data just disappears until I reload Blend.




Jack replied on Friday, April 24, 2009

Thanks - I'll guess I'll try another approach that doesn't use the CSLADataProvider or something.  I've seen a few examples online.

Jack replied on Friday, April 24, 2009

Rocky,

 

I'm trying to emulate this example:  http://www.silverlightshow.net/items/First-Look-at-Using-Expression-Blend-with-Silverlight-2.aspx

 

I can get to the part where I create a object (ROLB) in the Data tray but if I try to then drag it over to create/bind to a list then I get an exception.  If I create/bind to a grid then I get no error (you binding as dataContext) but if I choose list and bind to ItemsSource I get an exception.  It tells me that it "Cannot find type Csla.Wpf.PropertyStatus ... The assembly used when compiling might be different than that used when loading and the type is missing..."

 

Any thoughts?

 

Thanks

 

jack

 

 

 

 

 

From: Rockford Lhotka [mailto:cslanet@lhotka.net]
Sent: April-24-09 4:09 PM
To: jaddington@alexandergracie.com
Subject: RE: [CSLA .NET] RE: RE: CLSADataProvider in Silverlight - Design Time Data

 

.NET can only load an assembly into an appdomain once – and there’s no way to unload an assembly. It may be that Blend is loading the DLL and then it is stuck in memory even if a newer version comes along.

 

Microsoft really needs to get a more comprehensive story in place around this. But then the whole designer issue needs major improvement – I’m hoping for VS 10 and B3 to address a lot of these things.

 

Rocky

 

 

From: Jack [mailto:cslanet@lhotka.net]
Sent: Friday, April 24, 2009 4:46 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: RE: CLSADataProvider in Silverlight - Design Time Data

 

It is in blend that I am *trying* to get some data to see.  I have noticed with playing with the WPF example that I have to open/close Blend to pick up changes to the underlying BO.  If I make certain changes then the DesignTime data just disappears until I reload Blend.





RockfordLhotka replied on Friday, April 24, 2009

To get full designer support in Blend it is my understanding that you must put Csla.dll into the GAC. This is because, as I mentioned in a previous post, a DLL can be loaded into an appdomain only once – but it actually goes beyond that. If a DLL is loaded into two appdomains, it is treated as a different DLL in each appdomain, with the exception of the DLL being loaded from the GAC.

 

This is a limitation of .NET, and the way Blend uses different appdomains to load/unload assemblies in the designer.

 

So in short, install Csla.dll into the GAC and that should help.

 

Rocky

davido_xml replied on Friday, February 13, 2009

I don't have expression blend nor am I working with a designer so this reply may not be helpful to you....

I have been working with CSLALight for about a month and the productivity tip below outweighs any benefit of design time data (at the moment).

http://weblogs.asp.net/fmarguerie/archive/2009/01/29/life-changer-xaml-tip-for-visual-studio.aspx

RockfordLhotka replied on Friday, February 13, 2009

Yeah, that is really amazing – I echo-blogged it when the post came out – totally revolutionizes my view on working with XAML in VS.

 

Rocky

 

 

From: davido_xml [mailto:cslanet@lhotka.net]
Sent: Friday, February 13, 2009 10:34 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] CLSADataProvider in Silverlight - Design Time Data

 

I don't have expression blend nor am I working with a designer so this reply may not be helpful to you....

I have been working with CSLALight for about a month and the productivity tip below outweighs any benefit of design time data (at the moment).

http://weblogs.asp.net/fmarguerie/archive/2009/01/29/life-changer-xaml-tip-for-visual-studio.aspx



Copyright (c) Marimer LLC