Mark and Remove As Favorite

Oct 16, 2012 at 1:09 AM

Hi

This feature updated the local storage.  I implemented the ability to persist the favorite to the back-end.  However I'm finding the mark and remove menu stays visible, even though the deleegate command is executing the update async.  Here is the code snippet of the command:

 this.RemoveFavoriteCommand = new DelegateCommand(() =>
  {
     this.Template.IsFavorite = false;
     this.Submit();
     this.RaisePropertyChanged(() => this.IsFavorite);
  }
);
 private void Submit() {
            surveyServiceClient.SetAsFavorite(this.IsFavorite, this.Title)
                .ObserveOnDispatcher()
                .Subscribe(
            taskCompletedSummary =>
            {
                string message = taskCompletedSummary.Context;

                if (string.IsNullOrEmpty(message)) {
                    message = TaskCompletedSummaryStrings.GetDescriptionForResult(taskCompletedSummary.Result);
                }

                if (taskCompletedSummary.Result != TaskSummaryResult.Success) {
                    this.submitErrorInteractionRequest.Raise(
                        new Microsoft.Practices.Prism.Interactivity.InteractionRequest.Notification
                        {
                            Title = "Survey Error",
                            Content = message
                        },
                        n =>
                        {
                        }
                    );
                }
            },
            exception =>
            {
            });
        }

I have obviously added a reference to SurveyServiceClient and added the SetAsFavorite method along with variable for submitErrorInteractionRequest.

So when Submit() is called, the code executes fine, except the context menu stays displayed until the command has finished.  Any ideas how to resolve this?

Thanks

Coordinator
Oct 17, 2012 at 5:42 PM

I'm guessing that the call to SurveyServiceClient.SetAsFavorite is not behaving like an async call. Perhaps due to ObserveOnDispatcher. Try removing the call to ObserveOnDispatcher and see if the context menu goes away immediately. This means, of course that you will need to call the dispatcher directly if you need to update the UI in the callback:

Deployment.Current.Dispatcher.BeginInvoke(() => {UpdateUI(); });

Oct 18, 2012 at 4:00 AM
I removed ObserveOnDispatcher but it didn't make any difference when executing on the device or emulator. Actually when the TailSpin app is running in the emulator, the menu delay is not noticible at all, even when hitting against the Windows Azure services. The issue is very noticible on the phyiscal device.
Given that the Submit() method is in the SurveyTemplateViewModel along with RaisePropertyChanged(()=>this.IsFavorite), I'm not quite clear where to put the UI update. The collection of favorite surveys is refreshed in the SurveyListViewModel (ListenSurveyChanges).
If this functionality was added to TailSpin, is having the Submit in the surveyTemplateViewModel the best place? Alternatively, I could move the Submit code block into the ListenSurveyChanges. I've tried both approaches and the delay in dismissing the context menu seems consistent in both scenarios.
How else might you achieve this?
Thanks