コード例 #1
0
        public override void Start()
        {
            if (!ActivationContext.IsOpen)
            {
                return;
            }

            ShowTask();

            // Store these - the task can be updated
            m_taskLocations = Task.Locations;

            if (Task.Locations != null &&
                Task.Locations.Length > 0)
            {
                if (ShouldHoldLocations)
                {
                    foreach (var l in Task.Locations)
                    {
                        RecentlyUsedLocationService.Instance.HoldLocation(l);
                    }
                }

                if (Task.ActionRange != null)
                {
                    m_fence = LocationFence.Watch(
                        Task.Locations,
                        Task.ActionRange.Min.GetValueOrDefault(),
                        Task.ActionRange.Max.GetValueOrDefault(double.MaxValue),
                        (inRangeLocations) =>
                    {
                        // In range
                        ActivationContext.FireEvent(TaskAction.InRange);
                        ActivationContext.SetState("in_range");

                        if (Task.Action == TaskAction.InRange)
                        {
                            // That's it! Task is comlete.
                            Complete(inRangeLocations.FirstOrDefault());
                        }
                    },
                        () =>
                    {
                        // Out of range
                        ActivationContext.ClearState("in_range");
                    });
                }
            }

            base.Start();
        }
コード例 #2
0
        public LocationFence CreateFence(
            Location location,
            double minRange,
            double maxRange,
            Action <IEnumerable <Location> > inRange,
            Action outOfRange)
        {
            var fence = LocationFence.Watch(
                location,
                minRange,
                maxRange,
                inRange,
                outOfRange);

            lock (m_fences)
            {
                m_fences.Add(fence);
            }

            return(fence);
        }