This project has moved. For the latest updates, please go here.

Only updating while on WIFI

Nov 23, 2011 at 1:26 AM

I have been playing around with the idea of having some collections only update if I am on Wifi / Ethernet.  I have found the way to determine if you are connected  ( Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType ).

Now I am trying to make a custom data loader that has logic to test for the connection prior to calling the web load request. 

I can't figure out what the correct behavior is when you don't even want to try to connect, just give me back the cached item.  If I return null from the load context it seems like I get nothing back (even though there is data in the cache). 

Any ideas?


Nov 28, 2011 at 7:01 PM

Hi Jason -

Yes, returning null from GetLoadRequest short circuits the process and it won't check the cache.

So you want this flow, right?

if (IsOnWiFi) {



else {



Unfortunately, I'm struggling to think of an easy way to do this as AgFx currently lacks extensibility around deciding when to allow a live load, the data loader doesn't really give you this choice.  I think it would have to be a feature add.

But another way to do this is with the code above, but like this:

if (IsOnWiFi) {

   return DataManager.Current.Load<MyVM>("foo");


else {

   return DataManager.Current.LoadFromCache<MyVM>("foo");




Nov 29, 2011 at 5:05 AM

Yes, that is correct except that I don't have any data in the cache yet.  I need a way to prepopulate the cache for that initial call.

I tried to Save items to the cache manually, but it was not quite that straight forward.


Nov 30, 2011 at 1:39 AM

Why doesn't save work?  Because you don't have good default data or because you couldn't get Save to work?

Nov 30, 2011 at 1:42 AM

I couldn't get save to work.  :( 

I also had the same problem someone else mentioned on LoadFromCache doesn't return null when the items don't exist.  I had started debugging it and found that the low level routines do return null, but then a higher level has a .FirstOrDefault of the class so it returns it instead of null.  Haven't had time to get back to it and see what was going on for sure.

I will hopefully have a little more time soon as I have a project AGFX is perfect for and really want to use it.


Nov 30, 2011 at 5:22 AM

If you could spend a few minutes to build a simple repro of your case where save is failling, I'd like to take a look at it.  Sounds like a bug.  Did you implement IDataOptimizer on your DataLoader?

Nov 30, 2011 at 7:49 PM

Yes, I did.  But I was not getting that far.  It was crashing before it called it. 

I have a small template project I am working on that is still pretty simple.  I was planning to add AGFX for RSS Feed caching anyway, so I will see if I can get a quick repro in that small code and send it.

Thanks for the replies.