Multiple calls to data service from SL3? - silverlight

I have an SL3 that makes asynchronous calls to a data service. Basically, there is a treeview that is bound to a collection of objects. The idea is that as a user selects a specific treeviewitem, a call is made to the data service, with a parameter specific to the selected treeviewitem being passed to the corresponding web method in the data service. The data service returns data back to the SL3 client, and the client presents the data to the user.
This works well. The problem is that when users start to navigate through the treeview using the arrow keys on their keyboard, they could press the down arrow key, for example, 10 times, and 10 calls will be made to the data service, and then each of the 10 items will be displayed to the user momentarily, until finishing with the data for the most recently selected treeview item.
So - onto the question. How can I put in some form of delay, to allow someone to navigate quickly through a treeview, then, once then stop at a certain treeviewitem, a call is made to the data service?
Thanks for any suggestions.
Chris

use Rx for silverlight

As suggested by funwithcoding, you could try using the Reactive Extensions for .Net (Rx), I've not used it myself but from what I hear it would do what you're after.
However if you don't feel like you want to / have time to learn Rx etc. maybe look at using a DispatcherTimer to create a slight delay in you Treeview selected event, before you call the service to retrieve the data.

Related

How to bind data from service in Kendo Scheduler from local server

I'm using kendo UI scheduler in my application to make various reservation for different rooms. I'm able to bind the data to the scheduler on the init function.
The next requirement is when I click a skip button it skips a particular number of days and the same API is called retrieving different set of data for that date range.
I'm getting this data in my 'vm' object but the data is not showing up in the scheduler. When I asked the Telerik support the asked me to implement setDataSource() but it shows error in my application
Example for binding data
Example shown from telerik

Geoloqi Geofencing Logic Flow

All,
I have been looking high and low for a solution and at this point I am baffled. I am not looking for code here. I am just looking for the proper logic flow to alert users of my app that an event is taking place nearby using Geoloqi.
My platforms:
Geoloqi: Geofencing
Appcelerator Cloud Services: User, Event and Message Management
Language: javascript
Mobile: iPhone and Android
What I am trying to do:
1) I want users of my app to be able to create an event, then create a trigger based on that event.
2) I want users of my app who are near the event to be automatically alerted that the event is happening.
What I have so far:
1) Create an Appcelerator Event - Works fine
2) Create a Geoloqi Layer including the Appcelerator EventID - Works fine
3) Create a Geoloqi Trigger for the above layer - Works fine
I can see everything getting to the Geoloqi debugger. I just don't see the alert going out. I saw a post that the anonymous user needs to subscribe to the layer in order for the trigger to send to my users inside the trigger geofence. I just don't understand how to do that. I have tried several code permutations around the user/create_anon method with a key using either the anonymous username or the user access token to subscribe to the layer with no luck. I have tried using the access token returned on init as the parameter to subscribe with no luck.
I am wondering, however, if I can get the same effect by using a place instead of the layer, and avoiding the subscription issue. I somehow doubt this as the place has to reside in a default layer.
Color me confused. I already went through hell and back just getting the push certs set up for Apple, so any and all help is greatly appreciated.
Thanks,
Bruce
Bruce,
I'd recommend hitting the geoloqi developer IRC channel. You can get to it from one of the developer pages on their website. The geoloqi guys are usually online and they've been very helpful to me in the past.
If you do get it working, I'd love to hear the solution/flow for it! Hope that helps!
Tyler
OK, so here is what I am doing. Not sure yet if it is the answer, but I think it will work.
Create a default layer with no boundaries and a key that is the same each time the app runs. This will ensure the same layer is used based on Geoloqi's anti-dupe logic.
Create an anon user using the logged in user's email address since I am using Appcelerator to handle the user management. If I understand this correctly, this will also ensure the same anon-user is used if the user logs in again later. The anon user is automatically subscribed to the default layer.
When the user wants to create an event, the app creates an event on Appcelerator, creates a layer with a radius of x, a trigger on that layer, and sends a broadcast message to all users in the default layer using the trigger centerpoint and radius to limit the message to the immediate area.
If the user wants to cancel the event, the app sends a broadcast message to the default
layer in the same way the layer was created, then deletes the Appcelerator event and the layer.
I have all the code hooked in except the anonymous user. I can see the triggers being set and the messages being created on the Geoloqi Debugger, but I don't always get them. I'll be hooking in the anonymous user next week, so we shall see.

Silverlight Refresh data

I don't know what is the best way to force a browser refresh when using silverlight.
The scenario is like this:
We have a silverlight application hosted on IIS
Two users opens the same page and that page contains a grid with some records.
Only one of the users modify one record and save the data in the database
How can the other user see that the data has been modified unless he refreshes the page manually?
Should I implement some automatic refresh?
Thanks in advance
I would think long and hard about the requirements here before you open up a can of worms. Is the grid editable? With the automatic refresh idea what happens to the user who is in the middle of an edit? Think about alternatives. Could you possilbly check whether the data has changed at the point of saving data and then provide an appropriate message to the user? If you want the data to automatically refresh you are going to get into looking at server to client notifications e.g WCF duplex calls or constant polling and refreshing of the underlying bound observablecollection

Silverlight authentication during startup - how to mimic syncronous behavior?

I have a Silverlight app that is using the MVVM pattern. I have a WCF service which will allow me to authenticate users (I don't have direct control over that service - assume it is a black box that just returns me the user info and a list of privileges the user has). So, when the app starts up, I want to pull security data from that service.
Right now, when I do this, my views and view models can end up getting initialized before the service returns with the security data. This causes problems because the view models need to disable buttons and make things visible/invisible based on the user having certain privileges.
Is there a pattern that allows me to prevent the initialization of the views / view models until the WCF call has returned? How would you go about solving this problem as elegantly as possible?
Generally, you use BusyIndicator from Silverlight Toolkit for scenarios like this one.
Instead of disabling the UI, it shows them a progress instead.
What you do is provide a IsBusy property on ViewModel. While loading data, set it to True and False rest of the time. Wrap your UI with a BusyIndicator control and bind that property's value with BusyIndicator's IsBusy property.
With this in place, your UI will acknowledge whenever it's busy.

WPF PRISM event subcriptions not dying

I have a PRISM RegionManager with a couple of region - a Ribbon region on the top, and a main content region for my view underneath it - fairly basic.
The app starts with a "home" view in the main content area. When I click a button on the Ribbon, I inject a second view into the content area and navigate to it in the region manager. When I click a button on this view, it should be removed and the original view should be shown.
I'm currently doing this using the RegionManager.Add() method to manually add the second view. When I want to remove it, I publish an event which is consumed by a manager class that gets the current active remove, calls Remove() on the Region Manager for it, and then navigates back to the original view.
This all works great, except that when the second view is left alive after I call Remove(), and keeps a handle onto any subscriptions that it made during its lifetime! I've tried calling Subscribe explicitly with false for weak event references, but this is the default anyway, and it didn't help. I've tried both types of creating the view (discovery and injection) and removing the view via Remove and Deactivate. None of them helped. This is a real problem as when I want to create the same view in the future (a new instance of that view), I'm left with several instances of them, all subscribing to the same events, even though some of those instances were removed ages ago from the Region Manager.
Do I need to manually unsubscribe from every event that I subscribe to in my views (highly undesirable)? Or is there some way that I can dispose of the control / mark it as deactivated so that its subscriptions get removed?
I get the feeling that I'm doing something silly here but it's got me completely stumped.
Thanks
This is a known issue. There is a bug in the eventAggregator code. Take a look at the following blog and the suggested hack to overcome it
http://greenicicleblog.com/2010/04/28/prism-event-aggregator-more-leaky-than-it-seems/
Hope this helps

Resources