-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathTouchFlickExecutor.cs
More file actions
74 lines (59 loc) · 2.52 KB
/
Copy pathTouchFlickExecutor.cs
File metadata and controls
74 lines (59 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
namespace Winium.Desktop.Driver.CommandExecutors
{
#region using
using System;
using System.Threading;
using System.Windows;
using Winium.Cruciatus;
using Winium.Cruciatus.Core;
using Winium.Desktop.Driver.Extensions;
using Winium.StoreApps.Common;
#endregion
internal class TouchFlickExecutor : CommandExecutorBase
{
#region Methods
protected override string DoImpl()
{
if (this.ExecutedCommand.Parameters.ContainsKey("element"))
{
return FlickElement();
}
return Flick();
}
string Flick()
{
if (!(this.ExecutedCommand.Parameters.ContainsKey("xspeed")
&& this.ExecutedCommand.Parameters.ContainsKey("yspeed")))
{
// TODO: in the future '400 : invalid argument' will be used
return this.JsonResponse(ResponseStatus.UnknownError, "WRONG PARAMETERS");
}
var xSpeed = this.ExecutedCommand.GetParameterAsInt("xspeed");
var ySpeed = this.ExecutedCommand.GetParameterAsInt("yspeed");
return TouchSimulator.Flick(xSpeed, ySpeed)
? this.JsonResponse()
: this.JsonResponse(ResponseStatus.UnknownError, "Touch input failed");
}
string FlickElement()
{
if (
!(this.ExecutedCommand.Parameters.ContainsKey("element")
&& this.ExecutedCommand.Parameters.ContainsKey("xoffset")
&& this.ExecutedCommand.Parameters.ContainsKey("yoffset")
&& this.ExecutedCommand.Parameters.ContainsKey("speed")))
{
// TODO: in the future '400 : invalid argument' will be used
return this.JsonResponse(ResponseStatus.UnknownError, "WRONG PARAMETERS");
}
var registeredKey = this.ExecutedCommand.Parameters["element"].ToString();
var element = this.Automator.ElementsRegistry.GetRegisteredElement(registeredKey);
var xOffset = this.ExecutedCommand.GetParameterAsInt("xoffset");
var yOffset = this.ExecutedCommand.GetParameterAsInt("yoffset");
var pixelsPerSecond = this.ExecutedCommand.GetParameterAsInt("speed");
return TouchSimulator.FlickElement(element, xOffset, yOffset, pixelsPerSecond)
? this.JsonResponse()
: this.JsonResponse(ResponseStatus.UnknownError, "Touch input failed");
}
#endregion
}
}