예제 #1
0
        static public IEnumerable <Motion> AsSequenceMotion(
            this MotionParam Motion,
            IMemoryMeasurement MemoryMeasurement)
        {
            if (null == Motion)
            {
                yield break;
            }

            if (Motion?.WindowToForeground ?? false)
            {
                yield return(new Motion(null, WindowToForeground: true));
            }

            var SetElementExcludedFromOcclusion = MemoryMeasurement?.EnumerateSetElementExcludedFromOcclusion()?.ToArray();

            var Random = new Random((int)Bib3.Glob.StopwatchZaitMiliSictInt());

            var MouseListWaypoint = Motion?.MouseListWaypoint;

            for (int WaypointIndex = 0; WaypointIndex < (MouseListWaypoint?.Length ?? 0); WaypointIndex++)
            {
                var MouseWaypoint = MouseListWaypoint[WaypointIndex];

                var WaypointUIElement = MouseWaypoint?.UIElement;

                WaypointUIElement = (WaypointUIElement as Accumulation.IRepresentingMemoryObject)?.RepresentedMemoryObject as UIElement ?? WaypointUIElement;

                var WaypointRegionReplacement = MouseWaypoint.RegionReplacement;

                var WaypointUIElementCurrent =
                    WaypointUIElement.GetInstanceWithIdFromCLRGraph(MemoryMeasurement, Interface.FromSensorToConsumerMessage.SerialisPolicyCache);

                if (null == WaypointUIElementCurrent)
                {
                    throw new ApplicationException("mouse waypoint not anymore contained in UITree");
                }

                var WaypointUIElementRegion = WaypointUIElementCurrent.RegionInteraction?.Region;

                if (!WaypointUIElementRegion.HasValue)
                {
                    throw new ArgumentException("Waypoint UIElement has no Region to interact with");
                }

                if (WaypointRegionReplacement.HasValue)
                {
                    WaypointUIElementRegion = WaypointRegionReplacement.Value + WaypointUIElementRegion.Value.Center();
                }

                WaypointUIElementCurrent = WaypointUIElementCurrent.WithRegion(WaypointUIElementRegion.Value);

                var WaypointRegionPortionVisible =
                    WaypointUIElementCurrent.GetOccludedUIElementRemainingRegion(
                        MemoryMeasurement,
                        c => SetElementExcludedFromOcclusion?.Contains(c) ?? false)
                    //	remaining region is contracted to provide an safety margin.
                    ?.Select(PortionVisible => PortionVisible.WithSizeExpandedPivotAtCenter(-MotionMouseWaypointSafetyMarginMin * 2))
                    ?.Where(PortionVisible => !PortionVisible.IsEmpty())
                    ?.ToArray();

                var WaypointRegionPortionVisibleLargestPatch =
                    WaypointRegionPortionVisible
                    ?.OrderByDescending(Patch => Math.Min(Patch.Side0Length(), Patch.Side1Length()))
                    ?.FirstOrDefault();

                if (!(0 < WaypointRegionPortionVisibleLargestPatch?.Side0Length() &&
                      0 < WaypointRegionPortionVisibleLargestPatch?.Side1Length()))
                {
                    throw new ApplicationException("mouse waypoint region remaining after occlusion is too small");
                }

                var Point =
                    WaypointRegionPortionVisibleLargestPatch.Value
                    .WithSizeExpandedPivotAtCenter(-MotionMouseWaypointSafetyMarginAdditional * 2)
                    .RandomPointInRectangle(Random);

                yield return(new Motion(Point));

                if (0 == WaypointIndex)
                {
                    //	Mouse Buttons Down
                    yield return(new Motion(null, Motion?.MouseButton));
                }
            }

            //	Mouse Buttons Up
            yield return(new Motion(null, null, Motion?.MouseButton));

            var MotionKeyDown = Motion?.KeyDown;
            var MotionKeyUp   = Motion?.KeyUp;

            if (null != MotionKeyDown)
            {
                yield return(new Motion(null, KeyDown: MotionKeyDown));
            }

            if (null != MotionKeyUp)
            {
                yield return(new Motion(null, KeyUp: MotionKeyUp));
            }

            var MotionTextEntry = Motion?.TextEntry;

            if (0 < MotionTextEntry?.Length)
            {
                yield return(new Motion(null, TextEntry: MotionTextEntry));
            }
        }
예제 #2
0
        static public IEnumerable <Motion> AsSequenceMotion(
            this MotionParam motion,
            IMemoryMeasurement memoryMeasurement)
        {
            if (null == motion)
            {
                yield break;
            }

            if (motion?.WindowToForeground ?? false)
            {
                yield return(new Motion(null, windowToForeground: true));
            }

            var SetElementExcludedFromOcclusion = memoryMeasurement?.EnumerateSetElementExcludedFromOcclusion()?.ToArray();

            var Random = new Random((int)Bib3.Glob.StopwatchZaitMiliSictInt());

            var MouseListWaypoint = motion?.MouseListWaypoint;

            var mouseButtonDownMotion = new Motion(null, motion?.MouseButton);
            var mouseButtonUpMotion   = new Motion(null, null, motion?.MouseButton);

            for (int WaypointIndex = 0; WaypointIndex < (MouseListWaypoint?.Length ?? 0); WaypointIndex++)
            {
                var mouseWaypoint = MouseListWaypoint[WaypointIndex];

                var waypointUIElement = mouseWaypoint?.UIElement;

                waypointUIElement = (waypointUIElement as Accumulation.IRepresentingMemoryObject)?.RepresentedMemoryObject as UIElement ?? waypointUIElement;

                var waypointUIElementCurrent =
                    waypointUIElement.GetInstanceWithIdFromCLRGraph(memoryMeasurement, Interface.FromInterfaceResponse.SerialisPolicyCache);

                if (null == waypointUIElementCurrent)
                {
                    throw new ApplicationException("mouse waypoint not anymore contained in UITree");
                }

                var waypointRegion = waypointUIElementCurrent.RegionInteraction?.Region;

                var waypointRegionReplacement = mouseWaypoint.RegionReplacement;

                if (waypointRegionReplacement.HasValue)
                {
                    waypointRegion = waypointRegionReplacement.Value + waypointRegion.Value.Center();
                }

                waypointRegion = mouseWaypoint.RegionReplacementAbsolute ?? waypointRegion;

                if (!waypointRegion.HasValue)
                {
                    throw new ArgumentException("Did not find a region for the waypoint.");
                }

                waypointUIElementCurrent = waypointUIElementCurrent.WithRegion(waypointRegion.Value);

                var WaypointRegionPortionVisible =
                    waypointUIElementCurrent.GetOccludedUIElementRemainingRegion(
                        memoryMeasurement,
                        c => SetElementExcludedFromOcclusion?.Contains(c) ?? false)
                    //	remaining region is contracted to provide a safety margin.
                    ?.Select(portionVisible => portionVisible.WithSizeExpandedPivotAtCenter(-MotionMouseWaypointSafetyMarginMin * 2))
                    ?.Where(portionVisible => !portionVisible.IsEmpty())
                    ?.ToArray();

                var WaypointRegionPortionVisibleLargestPatch =
                    WaypointRegionPortionVisible
                    ?.OrderByDescending(patch => Math.Min(patch.Side0Length(), patch.Side1Length()))
                    ?.FirstOrDefault();

                if (!(0 < WaypointRegionPortionVisibleLargestPatch?.Side0Length() &&
                      0 < WaypointRegionPortionVisibleLargestPatch?.Side1Length()))
                {
                    throw new ApplicationException("mouse waypoint region remaining after occlusion is too small");
                }

                var Point =
                    WaypointRegionPortionVisibleLargestPatch.Value
                    .WithSizeExpandedPivotAtCenter(-MotionMouseWaypointSafetyMarginAdditional * 2)
                    .RandomPointInRectangle(Random);

                yield return(new Motion(Point));

                if (0 == WaypointIndex)
                {
                    yield return(mouseButtonDownMotion);

                    for (int repetitionIndex = 0; repetitionIndex < motion?.MouseButtonRepetitionCount; repetitionIndex++)
                    {
                        yield return(mouseButtonUpMotion);

                        yield return(mouseButtonDownMotion);
                    }
                }
            }

            yield return(mouseButtonUpMotion);

            var MotionKeyDown = motion?.KeyDown;
            var MotionKeyUp   = motion?.KeyUp;

            if (null != MotionKeyDown)
            {
                yield return(new Motion(null, keyDown: MotionKeyDown));
            }

            if (null != MotionKeyUp)
            {
                yield return(new Motion(null, keyUp: MotionKeyUp));
            }

            var MotionTextEntry = motion?.TextEntry;

            if (0 < MotionTextEntry?.Length)
            {
                yield return(new Motion(null, textEntry: MotionTextEntry));
            }
        }
예제 #3
0
		public MotionResult MotionExecute(MotionParam motionParam) => MotionExecuteFunc?.Invoke(motionParam);