예제 #1
0
        /// <summary>
        /// Handler for notifications by the localizer.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void localizer_LocalizerNotification(object sender, LocalizerNotificationEventArgs e)
        {
            // requires a lock since it's running on a different thread
            lock (_lockStatus)
            {
                // suspend prediction timer
                bool previousLocalizerStatus = _localizer.Enabled;
                _localizer.Enabled = false;

                switch (e.Code)
                {
                case LocalizerNotificationCode.Progress:
                    DoReportLocalizationProgress(e.ProgressValue);
                    break;

                case LocalizerNotificationCode.Prediction:

                    Debug.WriteLine("PREDICTION: " + e.PredictionValue.PredictedScenario.ToString() +
                                    " success: " + e.PredictionValue.Success.ToString());
                    // dispatch prediction
                    if (ServiceState == ServiceStateCode.Tracking)
                    {
                        _tracker.Update();
                    }
                    DispatchPrediction(e.PredictionValue);
                    break;
                }

                // restore localizer status
                _localizer.Enabled = previousLocalizerStatus;
            }
        }
예제 #2
0
파일: Localizer.cs 프로젝트: magseet/AttiLA
        /// <summary>
        /// Each time this handler is invoked, a new prediction is done.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void localizerTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            lock (_localizerLock)
            {
                // suspend
                _localizerTimer.Stop();

                if (LocalizerNotification != null)
                {
                    var prediction = this.Prediction();
                    if (prediction != null)
                    {
                        var args = new LocalizerNotificationEventArgs
                        {
                            Code            = LocalizerNotificationCode.Prediction,
                            PredictionValue = prediction
                        };
                        ThreadPool.QueueUserWorkItem(new WaitCallback(DoNotification), args);
                    }
                }

                // resume
                _localizerTimer.Start();
            }
        }
예제 #3
0
파일: Localizer.cs 프로젝트: magseet/AttiLA
        public Localizer()
        {
            _localizerTimer.Elapsed += localizerTimer_Elapsed;

            // task to notify localization progress
            _progressTask = System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                foreach (double progress in _progressCollection.GetConsumingEnumerable())
                {
                    if (LocalizerNotification != null)
                    {
                        var args = new LocalizerNotificationEventArgs
                        {
                            Code          = LocalizerNotificationCode.Progress,
                            ProgressValue = progress
                        };
                        LocalizerNotification(this, args);
                    }
                }
            });
        }