Пример #1
0
        public TouchAction(JsonTouchAction jsonTouchAction, Automator automator)
        {
            _jsonTouchAction = jsonTouchAction;
            _automator       = automator;

            if (this.Action == Wait)
            {
                this.MiliSeconds = jsonTouchAction.GetOptionAsInt("ms");
                return;
            }

            if (this.Action == Release)
            {
                return;
            }

            if (this.Action == Tap)
            {
                int count;
                this.Count = int.TryParse(jsonTouchAction.Options["count"], out count) ? count : 1;
            }

            if (this.Action == LongPress)
            {
                this.MiliSeconds = jsonTouchAction.Options.ContainsKey("duration")
                    ? jsonTouchAction.GetOptionAsInt("duration")
                    : 1000;
            }
        }
        public CommandResponse Do()
        {
            if (this.ExecutedCommand == null)
            {
                throw new NullReferenceException("ExecutedCommand property must be set before calling Do");
            }

            try
            {
                var session = this.ExecutedCommand.SessionId == null ? null : this.ExecutedCommand.SessionId.ToString();
                this.Automator = Automator.InstanceForSession(session);
                return CommandResponse.Create(HttpStatusCode.OK, this.DoImpl());
            }
            catch (AutomationException ex)
            {
                return CommandResponse.Create(HttpStatusCode.OK, this.JsonResponse(ex.Status, ex.Message));
            }
            catch (InnerDriverRequestException ex)
            {
                // Bad status returned by Inner Driver when trying to forward command
                return CommandResponse.Create(ex.StatusCode, ex.Message);
            }
            catch (NotImplementedException exception)
            {
                return CommandResponse.Create(
                    HttpStatusCode.NotImplemented, 
                    this.JsonResponse(ResponseStatus.UnknownCommand, exception.Message));
            }
            catch (Exception exception)
            {
                return CommandResponse.Create(
                    HttpStatusCode.OK, 
                    this.JsonResponse(ResponseStatus.UnknownError, "Unknown error: " + exception.Message));
            }
        }
Пример #3
0
        public CommandResponse Do()
        {
            if (this.ExecutedCommand == null)
            {
                throw new NullReferenceException("ExecutedCommand property must be set before calling Do");
            }

            try
            {
                var session = this.ExecutedCommand.SessionId;
                this.Automator = Automator.InstanceForSession(session);
                return(CommandResponse.Create(HttpStatusCode.OK, this.DoImpl()));
            }
            catch (AutomationException exception)
            {
                return(CommandResponse.Create(HttpStatusCode.OK, this.JsonResponse(exception.Status, exception)));
            }
            catch (NotImplementedException exception)
            {
                return(CommandResponse.Create(
                           HttpStatusCode.NotImplemented,
                           this.JsonResponse(ResponseStatus.UnknownCommand, exception)));
            }
            catch (Exception exception)
            {
                return(CommandResponse.Create(
                           HttpStatusCode.OK,
                           this.JsonResponse(ResponseStatus.UnknownError, exception)));
            }
        }
Пример #4
0
        public CommandResponse Do()
        {
            if (this.ExecutedCommand == null)
            {
                throw new NullReferenceException("ExecutedCommand property must be set before calling Do");
            }

            try
            {
                var session = this.ExecutedCommand.SessionId;
                this.Automator = Automator.InstanceForSession(session);
                return CommandResponse.Create(HttpStatusCode.OK, this.DoImpl());
            }
            catch (AutomationException ex)
            {
                return CommandResponse.Create(HttpStatusCode.OK, this.JsonResponse(ex.Status, ex.Message));
            }
            catch (NotImplementedException exception)
            {
                return CommandResponse.Create(
                    HttpStatusCode.NotImplemented, 
                    this.JsonResponse(ResponseStatus.UnknownCommand, exception.Message));
            }
            catch (Exception exception)
            {
                return CommandResponse.Create(
                    HttpStatusCode.OK, 
                    this.JsonResponse(ResponseStatus.UnknownError, "Unknown error: " + exception.Message));
            }
        }
Пример #5
0
        public TouchAction(JsonTouchAction jsonTouchAction, Automator automator)
        {
            _jsonTouchAction = jsonTouchAction;
            _automator = automator;

            if (this.Action == Wait)
            {
                this.MiliSeconds = jsonTouchAction.GetOptionAsInt("ms");
                return;
            }

            if (this.Action == Release)
            {
                return;
            }

            if (this.Action == Tap)
            {
                int count;
                this.Count = int.TryParse(jsonTouchAction.Options["count"], out count) ? count : 1;
            }

            if (this.Action == LongPress)
            {
                this.MiliSeconds = jsonTouchAction.Options.ContainsKey("duration")
                    ? jsonTouchAction.GetOptionAsInt("duration")
                    : 1000;
            }
        }
Пример #6
0
    void LateUpdate()
    {
        if (Automator.Enabled())
        {
            if (!controller.Paralyzed)
            {
                string action = Automator.Step();
                controller.PerformAction(action);
            }
            return;
        }

        if (!created)
        {
            if (!client.Calling)
            {
                client.Create(GenerateMessage());
                created = true;
            }
        }
        else
        {
            if (client.HasAction)
            {
                lastAction = client.GetAction();
                controller.PerformAction(lastAction);
            }
            if (!client.Calling)
            {
                client.Step(GenerateMessage());
            }
        }
    }
        public static void CloseApp(Automator automator)
        {
            var remoteCommand = new Command(DriverCommand.CloseApp);

            automator.CommandForwarder.ForwardCommand(remoteCommand);
            Thread.Sleep(TimeSpan.FromMilliseconds(500));
        }
    //The prefab finds the purchasable linked to it and updates the buy button to reflect it
    private void OnEnable()
    {
        GS  = GameState.instance;
        UIM = UIManager.instance;

        switch (itemType)
        {
        case ItemTypes.AUTOMATOR:
            foreach (Automator a in UIM.automators)
            {
                if (automator == a.name)
                {
                    thisAutomator = a;
                }
            }
            break;

        case ItemTypes.ACCELERATOR:
            foreach (Accelerator a in UIM.accelerators)
            {
                if (accelerator == a.name)
                {
                    thisAccelerator = a;
                }
            }
            break;
        }

        UpdateBuyButton();
    }
        protected override string DoImpl()
        {
            var screen     = this.Automator.EmulatorController.PhoneScreenSize;
            var startPoint = new Point(screen.Width / 2, screen.Height / 2);
            var elementId  = Automator.GetValue <string>(this.ExecutedCommand.Parameters, "element");

            if (elementId != null)
            {
                startPoint = this.Automator.RequestElementLocation(elementId).GetValueOrDefault();
            }

            if (this.ExecutedCommand.Parameters.ContainsKey("speed"))
            {
                var xOffset = Convert.ToInt32(this.ExecutedCommand.Parameters["xoffset"], CultureInfo.InvariantCulture);
                var yOffset = Convert.ToInt32(this.ExecutedCommand.Parameters["yoffset"], CultureInfo.InvariantCulture);
                var speed   = Convert.ToDouble(this.ExecutedCommand.Parameters["speed"], CultureInfo.InvariantCulture);

                this.Automator.EmulatorController.PerformGesture(new FlickGesture(startPoint, xOffset, yOffset, speed));
            }
            else
            {
                var xSpeed = Convert.ToDouble(this.ExecutedCommand.Parameters["xspeed"], CultureInfo.InvariantCulture);
                var ySpeed = Convert.ToDouble(this.ExecutedCommand.Parameters["yspeed"], CultureInfo.InvariantCulture);
                this.Automator.EmulatorController.PerformGesture(new FlickGesture(startPoint, xSpeed, ySpeed));
            }

            return(this.JsonResponse());
        }
        public void GetInfoTest()
        {
            var automator = new Automator
            {
                AlternativePathToTeamViewer = @"C:\ProgramData\TeamViewerQuickSupport\TeamViewerQS.exe"
            };

            var info = automator.GetInfo();

            Console.Out.WriteLine(info);
            Assert.IsNotNull(info);
        }
Пример #11
0
        public void AutomatorCollection_OneAutomator_SameTotals()
        {
            var testAutomator = new Automator(100L, 1000L, 1.3M, 3.5M, 1L);

            _ac.Add(testAutomator);

            testAutomator.IncrementAutomator();
            _ac.Update();

            Assert.AreEqual(1L, testAutomator.UnitsPerTick);
            Assert.AreEqual(1L, _ac.TotalUnitsPerTick);
            Assert.AreEqual(testAutomator.UnitsPerTick, _ac.TotalUnitsPerTick);
        }
Пример #12
0
        internal static bool ClickElement(Automator automator, string elementId)
        {
            var location = automator.RequestElementLocation(elementId);

            if (!location.HasValue)
            {
                // TODO return bad parameters?
                return(false);
            }

            automator.EmulatorController.LeftButtonClick(location.Value);

            return(true);
        }
        internal static bool ClickElement(Automator automator, string elementId)
        {
            var location = automator.RequestElementLocation(elementId);

            if (!location.HasValue)
            {
                // TODO return bad parameters?
                return false;
            }

            automator.EmulatorController.LeftButtonClick(location.Value);

            return true;
        }
Пример #14
0
        protected override string DoImpl()
        {
            var elementId = Automator.GetValue <string>(this.ExecutedCommand.Parameters, "element");

            if (elementId == null)
            {
                return(this.JsonResponse());
            }

            var tapPoint = this.Automator.RequestElementLocation(elementId).GetValueOrDefault();

            this.Automator.EmulatorController.PerformGesture(new TapGesture(tapPoint));

            return(this.JsonResponse());
        }
Пример #15
0
        public void AutomatorCollection_TwoAutomators_SameTotals()
        {
            var testAutomator  = new Automator(100L, 1000L, 1.3M, 3.5M, 1L);
            var testAutomator2 = new Automator(100L, 1000L, 1.3M, 3.5M, 2L);

            _ac.Add(testAutomator);
            _ac.Add(testAutomator2);

            testAutomator.IncrementAutomator();
            testAutomator2.IncrementAutomator();

            _ac.Update();

            Assert.AreEqual(3L, _ac.TotalUnitsPerTick);
        }
Пример #16
0
    void Update()
    {
        rewardText.text = "Reward: " + Reward.Get();

        if (task.Success())
        {
            task.Reset();

            if (task.Done(Trials.GetSuccess(), Trials.GetFailure()))
            {
                task.Finish();

                PlayerPrefs.SetInt("Success Count", 0);
                PlayerPrefs.SetInt("Failure Count", 0);
                EditorSceneManager.LoadScene(Scenes.Next());
                return;
            }

            Trials.AddSuccess();

            PlayerPrefs.SetInt("Success Count", Trials.GetSuccess());
            PlayerPrefs.SetInt("Failure Count", Trials.GetFailure());
            EditorSceneManager.LoadScene(EditorSceneManager.GetActiveScene().name);
            return;
        }

        if (task.Failure())
        {
            if (Automator.Enabled())
            {
                Debug.LogError("You have enabled autorun but task has failed: check your automation sequence for task '" + PlayerPrefs.GetString("Task Name") + "'");
            }

            task.Reset();

            Trials.AddFailure();

            PlayerPrefs.SetInt("Success Count", Trials.GetSuccess());
            PlayerPrefs.SetInt("Failure Count", Trials.GetFailure());
            EditorSceneManager.LoadScene(EditorSceneManager.GetActiveScene().name);
            return;
        }

        elapsed += 1;

        PlayerPrefs.SetInt("Elapsed Time", elapsed);
    }
Пример #17
0
        protected override string DoImpl()
        {
            var path = Automator.GetValue <string>(this.ExecutedCommand.Parameters, "path");
            var data = Automator.GetValue <string>(this.ExecutedCommand.Parameters, "data");

            var localPath = Path.GetTempFileName();

            try
            {
                File.WriteAllBytes(localPath, Convert.FromBase64String(data));
                this.Automator.Deployer.SendFile("Local", localPath, path);
            }
            finally
            {
                File.Delete(localPath);
            }

            return(this.JsonResponse());
        }
Пример #18
0
        protected override string DoImpl()
        {
            var path = Automator.GetValue <string>(this.ExecutedCommand.Parameters, "path");

            var localPath = Path.GetTempFileName();

            try
            {
                this.Automator.Deployer.ReceiveFile("Local", path, localPath);

                var bytes = File.ReadAllBytes(localPath);
                var data  = Convert.ToBase64String(bytes);
                return(this.JsonResponse(ResponseStatus.Success, data));
            }
            finally
            {
                File.Delete(localPath);
            }
        }
Пример #19
0
        protected override string DoImpl()
        {
            var screen     = this.Automator.EmulatorController.PhoneScreenSize;
            var startPoint = new Point(screen.Width / 2, screen.Height / 2);

            var elementId = Automator.GetValue <string>(this.ExecutedCommand.Parameters, "element");

            if (elementId != null)
            {
                startPoint = this.Automator.RequestElementLocation(elementId).GetValueOrDefault();
            }

            // TODO: Add handling of missing parameters. Server should respond with a 400 Bad Request if parameters are missing
            var xOffset = Convert.ToInt32(this.ExecutedCommand.Parameters["xoffset"], CultureInfo.InvariantCulture);
            var yOffset = Convert.ToInt32(this.ExecutedCommand.Parameters["yoffset"], CultureInfo.InvariantCulture);

            this.Automator.EmulatorController.PerformGesture(new ScrollGesture(startPoint, xOffset, yOffset));

            return(this.JsonResponse());
        }
        protected override string DoImpl()
        {
            var   elementId = Automator.GetValue <string>(this.ExecutedCommand.Parameters, "element");
            Point coordinates;

            if (elementId != null)
            {
                coordinates = this.Automator.RequestElementLocation(elementId).GetValueOrDefault();
            }
            else
            {
                var xOffset = Convert.ToInt32(this.ExecutedCommand.Parameters["xoffset"], CultureInfo.InvariantCulture);
                var yOffset = Convert.ToInt32(this.ExecutedCommand.Parameters["yoffset"], CultureInfo.InvariantCulture);
                coordinates = new Point(xOffset, yOffset);
            }

            this.Automator.EmulatorController.MoveCursorTo(coordinates);

            return(this.JsonResponse());
        }
Пример #21
0
    void Start()
    {
        task = GetComponent <Task>();

        if (Automator.Enabled())
        {
            Automator.Setup(task.AutomationSequence());
        }

        Reward.Set(0.0F);

        if (!PlayerPrefs.HasKey("Task Name"))
        {
            PlayerPrefs.SetString("Task Name", task.Name());
            Trials.Reset();
        }

        if (PlayerPrefs.GetString("Task Name") != task.Name())
        {
            PlayerPrefs.SetString("Task Name", task.Name());
            Trials.Reset();
        }

        PlayerPrefs.SetInt("Elapsed Time", elapsed);

        int successCount = Trials.GetSuccess();
        int failureCount = Trials.GetFailure();

        task.Initialize(successCount, failureCount);

        if (Automator.Enabled())
        {
            Automator.Setup(task.AutomationSequence());
        }

        taskText.text    = PlayerPrefs.GetString("Task Name");
        successText.text = "Success: " + successCount;
        failureText.text = "Failure: " + failureCount;
        rewardText.text  = "Reward: 0";
    }
Пример #22
0
 public static void LaunchApp(Automator automator)
 {
     automator.Deployer.Launch();
     automator.ConnectToApp();
 }
Пример #23
0
 public void SetAutomator(UIElement visualRoot) {
     automator = new Automator(visualRoot);
 }
 public static void LaunchApp(Automator automator)
 {
     automator.Deployer.Launch();
 }
Пример #25
0
 public void Cleanup()
 {
     testAutomator = null;
 }
Пример #26
0
 private void button1_Click(object sender, RoutedEventArgs e)
 {
     Automator.Post(this);
 }
 public static void CloseApp(Automator automator)
 {
     var remoteCommand = new Command(DriverCommand.CloseApp);
     automator.CommandForwarder.ForwardCommand(remoteCommand);
     Thread.Sleep(TimeSpan.FromMilliseconds(500));
 }
Пример #28
0
 public void Setup()
 {
     testAutomator = new Automator(100L, 1000L, 1.3M, 3.5M, 1L);
 }