New Posts New Posts RSS Feed: Application Design Question Lage Data Items
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Application Design Question Lage Data Items

 Post Reply Post Reply
Author
DavidKozikowski View Drop Down
Groupie
Groupie
Avatar

Joined: 02-Feb-2010
Location: Aurora, IN
Posts: 59
Post Options Post Options   Quote DavidKozikowski Quote  Post ReplyReply Direct Link To This Post Topic: Application Design Question Lage Data Items
    Posted: 02-Mar-2010 at 8:46am

I’m working on an application that needs to be disconnected at times.

The SaveCacheState() and RestoreCacheSate() looks like it will work well for most of the application architecture.

The question I have is centered around (for example) the use of large image files for instance.

Let’s say the application (WinForm and or Silverlight) would contain thousands of pictures. I would not want to make a wire trip to hydrate them on the client; I want to store them locally. My method prior to DevForce was to have an instance of SQLExpress on the client and store them there as blobs.  I would then use Merge Replication to keep the data in sync when connected.

So the question I have is could I and or should I store these bits in a Cache file?

Is there a limitation on the size and what would the performance penalty be for “finding” the correct picture to display? When I would want to show a picture how is it retrieved from the cache it the entire cache need to be expanded or is the BOS smart enough to just extract the one I need from the file.

In the Hello DevForce App it shows a picture for each Employee if we had a DB that had 20,000 employees in it and it needed to be disconnected what could be an approach to achieving this.

Any design pattern around the architecture would be appreciated. Preferably one that would work for both a Win Client and a OOB SilverLight App.

Back to Top
IdeaBlade View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 30-May-2007
Location: United States
Posts: 353
Post Options Post Options   Quote IdeaBlade Quote  Post ReplyReply Direct Link To This Post Posted: 04-Mar-2010 at 1:48pm
When you restore the contents of an EntityCacheState file into the cache, you have to bring the whole thing in: there's no way to go into the file and pick out a single entity or piece of data.  So I think your best bet would be simply to store the images in a folder on the local disk, and have enough information in the related entity to find the correct local file. You can of course encrypt the images if you need to.

We generally prefer a database architecture in which large images are stored in a separate table from the entity to which they apply; e.g, an EmployeeImage table separate from, and related to, the Employee table. That way you retrieve all of the lightweight Employee entities that you need, and only retrieve an Employee's image when you actually need it. That can solve a lot of performance issues right there.

Incidentally, the BOS, which is DevForce middleware, isn't involved when DevForce on the client communicates with an EntityState file on the client.
Back to Top
DavidKozikowski View Drop Down
Groupie
Groupie
Avatar

Joined: 02-Feb-2010
Location: Aurora, IN
Posts: 59
Post Options Post Options   Quote DavidKozikowski Quote  Post ReplyReply Direct Link To This Post Posted: 05-Mar-2010 at 6:54am

What I’m thinking I want to do to limit network bandwidth as well as make full disconnected application availability to “know” data is have a local instance of a database say using sqlexpress. The program logic flow I’m thinking about is this.

When the UI (end user) requests a “picture” if first looks for it in the cache if it’s not there is looks for it in the local database if it’s not there it then tries to get it for the remote database.  When it is found it will place it in the local database.  Once it’s in the Local DB there should never be wire trip to get that image. Each image by design is static, if the image changes a new one will be added (old one keep for historic reasons)

So using DevForce, the BOS, Cache, and EntityManager etc I’m trying to think of a way to implement this logic. And if this sounds like it will work ok.

In a nut shell I only want to use the SaveCacheState() and RestoreCacheState() when:

1)      Getting data to work offline

2)      Saving changes after working offline

3)      Saving changes back to the Master Remote DB after coming back online

There is a brief section in the Doc under Business Object Persistence – Advanced called “Access Both Local and Remote Data Sources in the Same N-tier Application” This is what I want to do.

If I understand it correctly I will need 2 EntityManager all sounds good. I think I get it.

Now the design question.  If I have a table called ProductImages that hold 300,000 + images on the remote server, and let’s say I have already loaded all that data to my local DB, when I’m disconnected would I use the Cache or my localDB. If I use the Local_EntityManager the stuff will be saved to LocalDB great but how would I get that data back to the remote DB when I come back online. I’m trying to avoid using Merge Replication.

So any high level design recommendations would be great. I would like to see a reference application of this design pattern.

 I would be willing to help provide one as I think this would be a common implementation and a reference app from DevForce would be cool.

Thanks
Dave
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 05-Mar-2010 at 12:23pm
Well, there are many possibilities for how you write the logic to retrieve the images from the remote DB; but you seem to be leaning toward a bulk operation where you just get them all at once, or maybe just install them with the app. You may need some facility for updating the local store when images are added, changed, or deleted on the remote db.
 
But let's say that's all outboard of the normal operation of your app, so that you're only job is to get a particular image when needed for display. Given your relatively complex algorithm for retrieval of a particular image for immediate use (first look in cache; then in the local db; then in the remote), it will probably be better if your Employee and EmployeeImage tables aren't joined in a relationship, so that the Employee entity has no EmployeeImage property on it. That's because DevForce's normal behavior is to look for a navigation property entity (EmployeeImage) first in the cache, and then in the remote Db if its best information says it isn't already in the cache.  There's no easy way of fudging this to insert a look at a local db into the middle.
 
But let's say you wire some logic to a button, or to the event of navigating to a new Employee on a form. The handler for that event can do a cache-only search for the image of Employee 123456; if that returns the null entity it can attempt to retrieve it from the local db; if that produces nothing then it can do a datasource-only retrieval.  And of course, if the latter is required, you could put some logic right there to save it to the local db at the same time.
 
Once you've viewed a given image during a given application session, it will, of course, always be found in the cache. If there's a ever problem with so many images getting loaded that the cache gets too large, you can always remove images from the cache.
 
I suppose another way to go might be to go ahead and relate the Employee and EmployeeImage tables, then introduce a DataConverter into any databindings that kicks into action if the EmployeeImage property returns the null entity. You'd want to prototype that, of course, to see if any issues arise.
 
>>
 If I use the Local_EntityManager the stuff will be saved to LocalDB great but how would I get that data back to the remote DB when I come back online. I’m trying to avoid using Merge Replication
<<
 
Is the user changing the images locally, or adding new ones? If so, and assuming the image is a property of an Entity, then they'll be persisted according to the same rules that other modified properties are. If offline you simply save them to your EntityStateFile; when back online you read them from the EntityStateFile into the cache (unless you happen to know that they're already there) and then do a normal save.
 
 
 
 
Back to Top
DavidKozikowski View Drop Down
Groupie
Groupie
Avatar

Joined: 02-Feb-2010
Location: Aurora, IN
Posts: 59
Post Options Post Options   Quote DavidKozikowski Quote  Post ReplyReply Direct Link To This Post Posted: 08-Mar-2010 at 5:22am

Greg,

                Thanks for taking the time to answer.

>> 

Given your relatively complex algorithm for retrieval of a particular image for immediate use (first look in cache; then in the local db; then in the remote…

>> 

Well this is what I thought I would want to do, maybe not. What if while connected I look for the image from the remote DB, as a matter of fact while connected I will use the Framework EntityManger “normally”

So now disconnected, I have a field rep that will be going to a customer site, the site may not grant / have internet access (to the remote DB) so before he leaves he will perform an operation that will hydrate all the related “customer” specific information related to the project. No big deal I can use the cache file for this perfect. The only caveat is if the tek needs to lookup a part from a catalog, this catalog is huge both general data as well as pictures, and the kicker is that the tek needs the ability to add a new entry including a picture as well, this new entry will need to be pushed back to the remote DB and all the other tech need to syc up when it is available.

So maybe the catalog DB piece is different DB than the main app. That way I can use a separate EntityCache and EntityStateFile for the piece. The workflow for this piece would be: when connected use the remote DB, when disconnected using a separate EntityManager look in the local DB and use the EntityManager as designed and save the CacheFile on exit. Then when connected I could restore the cache file then save data to the remote DB.

Will this work?

 I think I will.

 

Is this the same solution that is in the doc? Maybe so. Just took me awhile to get there.

 

Thanks

Dave

Back to Top
DavidKozikowski View Drop Down
Groupie
Groupie
Avatar

Joined: 02-Feb-2010
Location: Aurora, IN
Posts: 59
Post Options Post Options   Quote DavidKozikowski Quote  Post ReplyReply Direct Link To This Post Posted: 08-Mar-2010 at 8:17am

I have an idea. I will use Microsoft Sync Framework 2.0 to keep the DB in sync I will then use DevForce Locally.

So the workflow will be on application start and sync up the Local DB from the Remote DB.

Then the application will use the local DB while in use. On Exit I’ll syn up the Data to the remote DB.

I could then have an application option that would enable local DB or not, for the users that will not need disconnected access.

Should work yes?

Back to Top
IdeaBlade View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 30-May-2007
Location: United States
Posts: 353
Post Options Post Options   Quote IdeaBlade Quote  Post ReplyReply Direct Link To This Post Posted: 08-Mar-2010 at 3:27pm
I'm not familiar with the Sync Framework, but assuming it does what it sounds like it does, that seems like it would work, yes. Naturally your methods that try to sync should first make sure the remote DB can be reached.

You might want to have a look at some of the materials on the DataSourceKeyResolver in the Learning Resources (see screen shot below of search results). The resolver gives you a convenient way to switch instances of a database at runtime



Back to Top
DavidKozikowski View Drop Down
Groupie
Groupie
Avatar

Joined: 02-Feb-2010
Location: Aurora, IN
Posts: 59
Post Options Post Options   Quote DavidKozikowski Quote  Post ReplyReply Direct Link To This Post Posted: 09-Mar-2010 at 4:03am
Great Thanks I'll have a look at it.
 
Dave
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down