Exemplo n.º 1
0
        private void Deactivate(PulserTask t, Activity.State completionState, string completionReason)
        {
            string before = ToString();

            lock (_lock)
            {
                _active.Remove(t);
            }
            #region debug
            debugger.WriteLine(Common.Debugger.DebugLevel.DebugAxes,
                               "ActivePulsers: deleted {0}, \"{1}\" => \"{2}\"", t._axis.ToString(), before, ToString());
            #endregion
            if (_active.Count == 0)
            {
                Activity activity = activityMonitor.LookupInProgress(ActivityMonitor.ActivityType.Pulsing);
                if (activity != null)
                {
                    (activity as Activity.PulsingActivity).EndActivity(new Activity.PulsingActivity.EndParams()
                    {
                        endState  = completionState,
                        endReason = completionReason,
                        _end      = new Activity.TelescopeSlewActivity.Coords
                        {
                            ra  = WiseTele.Instance.RightAscension,
                            dec = WiseTele.Instance.Declination,
                        }
                    });
                }
            }
        }
Exemplo n.º 2
0
        private void Activate(PulserTask t)
        {
            string before = ToString();

            lock (_lock)
            {
                _active.Add(t);
            }
            #region debug
            debugger.WriteLine(Common.Debugger.DebugLevel.DebugAxes,
                               "ActivePulsers: added {0}, \"{1}\" => \"{2}\"", t._axis.ToString(), before, ToString());
            #endregion
        }
Exemplo n.º 3
0
        public void Start(GuideDirections direction, int duration)
        {
            PulserTask pulserTask;

            pulserTask = new PulserTask()
            {
                _axis     = guideDirection2Axis[direction],
                _duration = duration,
                _motor    = guideDirection2Motor[direction],
                task      = null,
            };
            pulseGuideCT = pulseGuideCTS.Token;

            Activate(pulserTask);
            pulserTask.task = Task.Run(() =>
            {
                try
                {
                    pulserTask.Run();
                }
                catch (Exception ex)
                {
                    #region debug
                    debugger.WriteLine(Common.Debugger.DebugLevel.DebugLogic,
                                       "Caught exception: {0}, aborting pulse guiding", ex.Message);
                    #endregion
                    Abort();
                    Deactivate(pulserTask, Activity.State.Aborted, string.Format("Caught exception: {0}, aborting pulse guiding", ex.Message));
                }
            }, pulseGuideCT).ContinueWith((t) =>
            {
                #region debug
                debugger.WriteLine(Common.Debugger.DebugLevel.DebugLogic,
                                   "pulser on {0} completed with status: {1}",
                                   pulserTask._axis.ToString(), t.Status.ToString());
                #endregion
                Deactivate(pulserTask, Activity.State.Succeeded, string.Format("pulser on {0} completed with status: {1}",
                                                                               pulserTask._axis.ToString(), t.Status.ToString()));
            }, TaskContinuationOptions.ExecuteSynchronously);
        }