void PredictionCallCompleted(IAsyncResult ar) { var predictionCall = (Func <IEnumerable <ContextPreference> >)ar.AsyncState; var preferences = predictionCall.EndInvoke(ar); SendOrPostCallback setList = delegate { lstPreferences.Items.Clear(); if (preferences != null) { foreach (var preference in preferences.OrderByDescending(p => p.Value)) { var lvi = new ListViewItem(); var contextName = _contextService.GetById(preference.ContextId.ToString()).ContextName; lvi.Text = preference.ContextId.ToString(); lvi.SubItems.Add(contextName); lvi.SubItems.Add(preference.Value.ToString()); lstPreferences.Items.Add(lvi); } } }; _syncContext.Post(setList, null); }
public ActionResult Delete(int id) { var context = _contextService.GetById(id); var viewModel = new ContextViewModel() { Id = context.Id, Name = context.Name }; return(View(viewModel)); }
void _status_UserInteraction(object sender, EventArgs e) { var args = e as UserInteractionEventArgs; Debug.WriteLine("[BleDA] UserInteraction: " + args.Code.ToString()); switch (args.Code) { case UserInteractionCode.BetterContextFound: _status.NotifyIcon.ShowBalloonTip(Properties.Resources.PopupWarning, Properties.Resources.MsgBetterContext, BalloonIcon.Warning); ThreadPool.QueueUserWorkItem(new WaitCallback(AskForConfirmation)); break; case UserInteractionCode.CurrentContextFound: _status.NotifyIcon.ShowBalloonTip(Properties.Resources.PopupInfo, Properties.Resources.MsgAlignmentCompleted, BalloonIcon.Info); this.Dispatcher.BeginInvoke(new System.Action( () => { Switcher.Switch(new ViewContextPage()); })); break; case UserInteractionCode.NewContextSelected: _status.NotifyIcon.ShowBalloonTip(Properties.Resources.PopupInfo, Properties.Resources.MsgAlignmentStarted, BalloonIcon.Info); //_notifyIcon.HideBalloonTip(); this.Dispatcher.BeginInvoke(new System.Action( () => { Switcher.Switch(new AlignmentPage()); })); break; case UserInteractionCode.PreviousContextFound: var context = _contextService.GetById(args.PreviousContextFoundValue); _status.NotifyIcon.ShowBalloonTip(Properties.Resources.PopupInfo, Properties.Resources.MsgPreviousContext + context.ContextName, BalloonIcon.Info); //_notifyIcon.HideBalloonTip(); this.Dispatcher.BeginInvoke(new System.Action( () => { Switcher.Switch(new ViewContextPage()); })); break; case UserInteractionCode.TrackingSessionSucceded: _status.NotifyIcon.ShowBalloonTip(Properties.Resources.PopupInfo, Properties.Resources.MsgContexUpdated, BalloonIcon.Info); break; } }
/// <summary> /// Populate the context lists. /// </summary> /// <returns>False if update has been skipped due to the user selection</returns> private bool UpdateContextLists() { // get new results var recentContexts = _contextService.GetMostRecent((int)_settings.MostRecentLimit); var closerContexts = _serviceClient.GetCloserContexts(); List <ContextPreferenceItem> closerContextItems = new List <ContextPreferenceItem>(); foreach (var closerContext in closerContexts.OrderByDescending(c => c.Value)) { var context = _contextService.GetById(closerContext.ContextId); if (context == null) { continue; } var item = new ContextPreferenceItem { Name = context.ContextName, Value = closerContext.Value.ToString(), ContextId = closerContext.ContextId }; closerContextItems.Add(item); } try { // update could take time // check again for user selection bool closerSelected = listCloser.Dispatcher.Invoke( new Func <bool>( () => { return(listCloser.SelectedItem != null); }) ); bool recentSelected = listRecent.Dispatcher.Invoke( new Func <bool>( () => { return(listRecent.SelectedItem != null); }) ); if (!recentSelected && !closerSelected) { // update UI listRecent.Dispatcher.Invoke(new System.Action( () => { listRecent.ItemsSource = recentContexts; })); listCloser.Dispatcher.Invoke(new System.Action( () => { listCloser.ItemsSource = closerContextItems; })); // update performed return(true); } } catch { // tried to access UI after Dispose() return(false); } // update skipped return(false); }
/// <summary> /// Try to find a scenario for the target context. On failure, a new /// scenario is created if the creation is allowed, otherwise the /// predicted scenario is returned. /// </summary> /// <returns>A prediction, or null in case of error.</returns> public PredictionArgs Prediction() { Context context = null; PredictionArgs prediction = null; lock (_localizerLock) { if (ContextId != null) { try { context = _contextService.GetById(ContextId); if (context == null) { // notify error if (LocalizerErrorNotification != null) { var args = new LocalizerErrorNotificationEventArgs( LocalizerErrorNotificationCode.UnknownContext); ThreadPool.QueueUserWorkItem(new WaitCallback(DoNotification), args); } } } catch (Exception ex) { if (LocalizerErrorNotification != null) { // notify error var args = new LocalizerErrorNotificationEventArgs( LocalizerErrorNotificationCode.DatabaseError, ex); ThreadPool.QueueUserWorkItem(new WaitCallback(DoNotification), args); } } } if (context != null) { // context found in the database prediction = new PredictionArgs { Success = false }; IEnumerable <ContextPreference> pref = null; for (var attempts = this.Retries + 1; attempts > 0; attempts--) { prediction.PredictedScenario = GetScenarioForCurrentPosition(out pref); if (prediction.PredictedScenario == null) { // retry, eventually.. continue; } if (ContextId.Equals(prediction.PredictedScenario.ContextId.ToString())) { // correct prediction _scenarioService.IncreaseAccuracy(prediction.PredictedScenario); prediction.Success = true; break; } // wrong prediction _scenarioService.DecreaseAccuracy(prediction.PredictedScenario); } if (!prediction.Success && CreationAllowed) { // create a new scenario for the requested context prediction.PredictedScenario = new Scenario { ContextId = new ObjectId(ContextId), CreationTime = DateTime.Now }; try { _scenarioService.Create(prediction.PredictedScenario); } catch (Exception ex) { if (LocalizerErrorNotification != null) { // notify error var args = new LocalizerErrorNotificationEventArgs( LocalizerErrorNotificationCode.DatabaseError, ex); ThreadPool.QueueUserWorkItem(new WaitCallback(DoNotification), args); } prediction = null; } } } // end if(context != null) } // unlock return(prediction); }