Пример #1
0
        /// <summary>
        /// Take provided command string and delegate it to the requested command console logic.
        /// </summary>
        public static void SendCommand(string fullRawCommand)
        {
            if (extend)
            {
                //TODO: Add your custome code to send this command directly/programmatically to your command console's processor logic.
            }
            else
            {
                ConsoleCommands.SendCommand(fullRawCommand);
            }

            extend = false;             //Return to false.
        }
Пример #2
0
        public override void Render()
        {
            console = new GUIStyle(GUI.skin.box);
            console.normal.background = Swat.MakeTextureFromColor((Color) new Color32(100, 100, 100, 255));
            console.wordWrap          = true;
            console.normal.textColor  = Color.white;
            console.padding           = new RectOffset(10, 20, 0, 0);
            console.fontSize          = 15;
            console.alignment         = TextAnchor.MiddleLeft;

            description                  = new GUIStyle(GUI.skin.label);
            description.wordWrap         = true;
            description.margin           = new RectOffset(10, 10, 0, 0);
            description.padding          = new RectOffset(0, 0, 5, 5);
            description.normal.textColor = Swat.WindowDefaultTextColor;
            description.fontSize         = 12;

            args                  = new GUIStyle(GUI.skin.label);
            args.wordWrap         = true;
            args.margin           = new RectOffset(10, 10, 0, 0);
            args.normal.textColor = Swat.WindowDefaultTextColor;
            args.fontSize         = 11;

            editorName                  = new GUIStyle(GUI.skin.label);
            editorName.fontSize         = 16;
            editorName.fixedHeight      = 20;
            editorName.fontStyle        = FontStyle.Bold;
            editorName.padding          = new RectOffset(8, 0, 0, 0);
            editorName.normal.textColor = Swat.WindowDefaultTextColor;

            load = new GUIStyle(GUI.skin.box);
            load.normal.background = Swat.MakeTextureFromColor((Color) new Color32(75, 75, 75, 255));
            load.normal.textColor  = Color.white;
            load.fontSize          = 18;
            load.alignment         = TextAnchor.MiddleCenter;

            open                   = new GUIStyle(GUI.skin.button);
            open.fontSize          = 14;
            open.fixedHeight       = 28;
            open.fixedWidth        = 100;
            open.margin            = new RectOffset(10, 10, 0, 0);
            open.normal.textColor  = Swat.WindowDefaultTextColor;
            open.normal.background = open.active.background = open.focused.background = Swat.ToggleButtonBackgroundSelectedTexture;

            variables                  = new GUIStyle(GUI.skin.textField);
            variables.fontSize         = 12;
            variables.margin           = new RectOffset(10, 10, 0, 0);
            variables.normal.textColor = Swat.WindowDefaultTextColor;

            _scroll = GUILayout.BeginScrollView(_scroll);

            GUILayout.Space(!Application.isPlaying ? 15 : 45);
            EditorGUILayout.LabelField("Filter (Search for command name or description/purpose matching)", description);
            search = EditorGUILayout.TextField(search, variables, new GUILayoutOption[] { GUILayout.MaxWidth(400) });
            GUILayout.Space(25);

            int inputFieldId = 0;

            for (int x = 0; x < Commands.Count; x++)
            {
                Command command       = Commands[x];
                string  longestAlias  = string.Empty;
                bool    filterActive  = !string.IsNullOrEmpty(search.Trim());
                bool    filterMatched = false;
                for (int l = 0; l < command.Aliases.Count; l++)
                {
                    if (filterActive && (command.Aliases[l].ToLower().Contains(search) || command.Purpose.ToLower().Contains(search)))
                    {
                        filterMatched = true;
                    }
                    longestAlias = command.Aliases[l].Length > longestAlias.Length ? command.Aliases[l] : longestAlias;
                }

                if (filterActive && !filterMatched)
                {
                    continue;                     //Don't render this information; no match found.
                }

                EditorGUILayout.LabelField(longestAlias, editorName);
                GUILayout.Space(4);
                EditorGUILayout.LabelField(command.Purpose, description);
                GUILayout.Space(6);

                if (command.Args.Count > 0)
                {
                    for (int a = 0; a < command.Args.Count; a++)
                    {
                        EditorGUILayout.LabelField(string.Format("(Arg {0}) <{1}> {2}", a, command.Args[a].Key, command.Args[a].Value), description);
                        GUILayout.Space(2);
                    }

                    GUILayout.Space(4);
                    if (VariableInputFields.Count == inputFieldId)
                    {
                        VariableInputFields.Add(string.Empty);
                    }
                    VariableInputFields[inputFieldId] = EditorGUILayout.TextField(VariableInputFields[inputFieldId], variables, new GUILayoutOption[] { GUILayout.MaxWidth(400) });
                    GUILayout.Space(8);
                    inputFieldId++;
                }
                if (GUILayout.Button("Launch", open))
                {
                    if (!EditorApplication.isPlaying)
                    {
                        SimpleAlert.Pop("Console commands can only be executed when Play Mode is active.", null);
                    }
                    else
                    {
                        ConsoleCommands.SendCommand(string.Format("{0} {1}", longestAlias, VariableInputFields[inputFieldId - 1]));                         //Minus one because we are handling and incrementing this input before this onClick is implemented.
                        showCommandLog = true;
                    }
                }
                GUILayout.Space(20);
            }
            GUILayout.Space(40);
            GUILayout.EndScrollView();

            string arrow = showCommandLog ? "▲" : "▼";

            if (Application.isPlaying)
            {
                load.padding  = showCommandLog ? new RectOffset(0, 0, -8, 0) : new RectOffset(0, 0, 0, 0);
                load.fontSize = 15;
                if (GUI.Button(new Rect(0, 24, Nexus.Self.position.width, 30), string.Format("{0}    Show Command Log    {0}", arrow), load))
                {
                    showCommandLog = !showCommandLog;
                }
                if (showCommandLog)
                {
                    //_scrollConsole = GUI.BeginScrollView(new Rect(0, 30, Nexus.Self.position.width, 400), _scrollConsole, new Rect(0, 30, Nexus.Self.position.width, 400));
                    GUI.TextArea(new Rect(0, 50, Nexus.Self.position.width, 400), ConsoleCommands.ConsoleLog.text, console);
                    //GUILayout.EndScrollView();
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Handles incoming pubsub messages. Expects JSON format.
        /// </summary>
        public IEnumerator HandleMessage(string result)
        {
            //Ignore duplicate or empty messages. Ignore messages not meant for this client.
            if (lastMessageReceived == result || string.IsNullOrEmpty(result.Trim()))
            {
                yield break;
            }

            lastMessageReceived = result;

            List <KeyValuePair <string, string> > parameters = DeserializeJsonString(result);

            if (!LocalRunLaunch)
            {
                //If no context or identity is provided, then this is not a valid command. If the DeviceUdid is not valid, then ignore the command.
                if (!parameters.FindAll(x => x.Key.ToLower() == "grid_source").Any() || !parameters.FindAll(x => x.Key.ToLower() == "grid_identity").Any())
                {
                    yield break;
                }

                string source   = parameters.Find(x => x.Key == "grid_source").Value;
                string identity = parameters.Find(x => x.Key == "grid_identity").Value;
                string buddy    = parameters.Find(x => x.Key == "grid_identity_buddy").Value;

                //If message simply contains no reference to this GridIdentity OR the identity is self, then it is chatter and can be ignored.
                bool isChatter = !result.Contains(GridIdentity);
                bool isInvalid = string.IsNullOrEmpty(TestRunId) ? !parameters.FindAll(x => x.Key == "set_test_run_id").Any() : parameters.FindAll(x => x.Key == "test_run_id").Any() && TestRunId != parameters.Find(x => x.Key == "test_run_id").Value;
                bool isEcho    = identity == GridIdentity && source == "client";

                //If message is from a client source where the identity is not that of this client, but contains this client's identity, then this it is a BuddySystem message.
                bool isBuddyMessage = source != "server" && parameters.FindAll(x => x.Key.StartsWith("buddy_")).Any() && buddy == GridIdentity && identity == BuddyHandler.BuddyName;

                //If this message is meant for a different client, or is an echo from the current client, simply ignore the message.
                if (!isBuddyMessage && (isChatter || isEcho || isInvalid))
                {
                    yield break;
                }
            }
            else if (!LocalRunLaunch && parameters.FindAll(x => x.Key.ToLower() == "grid_identity").Any() ? parameters.Find(x => x.Key == "grid_identity").Value != GridIdentity : false)
            {
                yield break;
            }

            LastMessage = DateTime.Now;

            if (parameters.Count > 0)
            {
                //Process each command.
                for (int c = 0; c < parameters.Count; c++)
                {
                    string command             = parameters[c].Key.ToLower();
                    string message             = parameters[c].Value.TrimEnd(',');
                    bool   isRecognizedCommand = true;

                    switch (command.ToLower())
                    {
                    case "no_interval_screenshots":
                        AutomationMaster.NoIntervalScreenshots = true;
                        break;

                    case "ignore_memory_tracking":
                        AutomationMaster.IgnoreMemoryTracking = true;
                        break;

                    case "health_check":
                        SendCommunication(string.Format("heartbeat_{0}", (++AutomationMaster.HeartBeatIndex).ToString(), "0"));
                        break;

                    case "buddy_ignore_all":
                        AutomationMaster.IgnoreAllBuddyTests      = true;
                        AutomationMaster.LockIgnoreBuddyTestsFlag = true;                                 //Prevents Test editor window from implicitly updating the Ignore flag.
                        break;

                    case "buddy_ready_for_tests":
                        //TODO: Refactor and re-add GRIDLOCK logic. Without it, BuddySystem will not informatively report that both buddies are reporting as the same role.
                        //if((BuddyHandler.IsPrimary && message == "primary") || (!BuddyHandler.IsPrimary && message == "secondary")) {

                        //Gridlock. One client must be the primary, and one must be the secondary.
                        //SendCommunication("buddy_gridlock_detected", "0");
                        //BuddyHandler.RoleGridLock = true;

                        //} else {

                        SendCommunication("buddy_ready_for_tests_acknowledged", BuddyHandler.IsPrimary ? "primary" : "secondary");
                        BuddyHandler.IsBuddyReadyForBuddyTests = true;

                        //}
                        break;

                    case "buddy_ready_for_tests_acknowledged":
                        BuddyHandler.HasBuddyAcknowledgedOurReadiness = true;
                        break;

                    case "buddy_switching_roles":
                        BuddyHandler.BuddyHasSuccessfullySwitchRoles = true;
                        break;

                    case "buddy_requesting_required_details":
                        //Send/Resend details required by Primary Buddy.
                        BuddyHandler.SendBasicBuddyDetails();
                        break;

                    case "buddy_starting_reaction":
                        BuddyHandler.SecondaryReactionsStarted = true;
                        break;

                    case "buddy_tearing_down":
                        BuddyHandler.BuddyTearingDown = true;
                        break;

                    case "buddy_data_update":
                        BuddyHandler.SetCurrentBuddyRequiredDetails(message);
                        break;

                    case "buddy_primary_test_complete":
                        BuddyHandler.CurrentPrimaryTest    = message;
                        BuddyHandler.ReadyForReactionTests = true;
                        BuddyHandler.SendBuddyCommunication("buddy_xyz", string.Format("Buddy Primary Test Completion ({0}) Acknowledged ({1}) %%%%", BuddyHandler.CurrentPrimaryTest, BuddyHandler.ReadyForReactionTests));
                        break;

                    case "buddy_primary_pretest_commands":
                        AutomationMaster.BuddyHandler.PreTestCommandReceived(message);
                        break;

                    case "buddy_secondary_pretest_commands_complete":
                        BuddyHandler.BuddyProcessingCommands = false;
                        break;

                    case "buddy_secondary_pretest_commands_failure":
                        BuddyHandler.BuddyCommandExecutionFailure = true;
                        BuddyHandler.BuddyProcessingCommands      = false;
                        BuddyHandler.BuddyCommandFailure          = message;
                        break;

                    case "buddy_secondary_tests_complete":
                        BuddyHandler.WaitingForBuddyToCompleteReactionTests = false;
                        break;

                    case "buddy_primary_test_failed":
                        BuddyHandler.PrimaryFailed = true;
                        break;

                    case "buddy_primary_complete_action_tests":
                        BuddyHandler.IsPrimaryFinishedWithActionTests = true;
                        break;

                    case "loop_tests":
                        //This command should be sent before or at the same time as the run command. Sending it after may result in failing to have the desired effect.
                        List <KeyValuePair <string, int> > loopTests = new List <KeyValuePair <string, int> >();
                        List <string> RawRequests = message.Split(AutomationMaster.DELIMITER).ToList();
                        for (int x = 0; x < RawRequests.Count; x++)
                        {
                            string testName = RawRequests[x].Split('@').First();
                            string count    = RawRequests[x].Split('@').Last();
                            if (RawRequests[x].Split('@').ToList().Count != 2 || count.ToInt() == 0)
                            {
                                AutoConsole.PostMessage("Provided loop_tests command is invalid. The value must be a string and then integer, separated by an @ symbol.");
                                continue;
                            }
                            loopTests.Add(new KeyValuePair <string, int>(testName, count.ToInt()));
                        }
                        AutomationMaster.LoopTests = loopTests;
                        break;

                    case "request_response":
                        switch (message)
                        {
                        case "screenshot":
                            AutomationMaster.AwaitingScreenshot = false;
                            break;

                        default:
                            break;
                        }
                        break;

                    case "request_buddy":
                        //AutomationMaster.BuddyRequest(message, "newbuddy");
                        break;

                    case "set_test_run_id":
                        TestRunId = message;
                        break;

                    case "manual_set_buddy_primary":
                        BuddyHandler.BuddyName = message;
                        BuddyHandler.IsPrimary = true;
                        BuddyHandler.SendBasicBuddyDetails();
                        BuddyIdentity = message;
                        break;

                    case "manual_set_buddy_secondary":
                        BuddyHandler.BuddyName = message;
                        BuddyHandler.IsPrimary = false;
                        BuddyHandler.SendBasicBuddyDetails();
                        BuddyIdentity = message;
                        break;

                    case "no_test_rails_reporting":
                        AutomationReport.IgnoreTestRailsReporting = true;
                        break;

                    case "server_heartbeat":
                        AutomationMaster.ServerHeartbeatReceived();
                        break;

                    case "console_command":
                        List <string> commands = message.Trim().Split('|').ToList();
                        for (int co = 0; co < commands.Count; co++)
                        {
                            string com = string.Format("{0} {1}", commands[co].Split('$').First(), commands[co].Split('$').Last());
                            ConsoleCommands.SendCommand(com);
                            AutoConsole.PostMessage(string.Format("Ran Command: {0}", com), MessageLevel.Abridged);
                        }
                        break;

                    case "server_broker_response":
                        Q.request.CommandResponseReceived(message);
                        break;

                    case "automation_command":
                        if (AutomationMaster.Busy)
                        {
                            SendCommunication("Notification", "Busy completing previous test run.");
                            break;
                        }
                        SendCommunication("Notification", "Beginning pre-run checks.");

                        if (parameters.Find(x => x.Key == "grid_source").Value == "server")
                        {
                            AutomationMaster.IsServerListening = true;
                        }

                        yield return(StartCoroutine(Q.driver.WaitRealTime(1)));

                        AutomationMaster.Busy = true;
                        AutomationMaster.LockIgnoreBuddyTestsFlag = true;

                        //Split string and discard only command prefix. Also allows for spaces in test Category names.
                        message = message.TrimStart().TrimEnd().Replace(", ", ",").Split(new char[] { ' ' }, 2)[1].Trim().ToLower();
                        if (message == "all")
                        {
                            AutomationMaster.LaunchType = LaunchType.All;
                        }
                        else if (message.StartsWith("*") && message.Contains(","))
                        {
                            message = message.Replace("*", string.Empty);
                            AutomationMaster.LaunchType = LaunchType.MultipleMethodNames;
                        }
                        else if (message.StartsWith("*"))
                        {
                            message = message.Replace("*", string.Empty);
                            AutomationMaster.LaunchType = LaunchType.MethodName;
                        }
                        else if (message.StartsWith("&&"))
                        {
                            message = message.Replace("&&", string.Empty);
                            AutomationMaster.LaunchType = LaunchType.Mix;
                        }
                        else if (message.Contains(","))
                        {
                            AutomationMaster.LaunchType = LaunchType.MultipleCategoryNames;
                        }
                        else
                        {
                            AutomationMaster.LaunchType = LaunchType.CategoryName;
                        }

                        //Wait until loading of game is complete to attempt a launch of the automation suite
                        yield return(StartCoroutine(Q.game.WaitForGameLoadingComplete()));

                        StartCoroutine(AutomationMaster.StaticSelfComponent.BeginTestLaunch(message));

                        break;

                    case "buddy_secondary_test_complete":
                    case "buddy_requesting_value_ready":
                    case "buddy_setting_ready_to":
                        //Commands that do not require any action, but should be considered valid for logging purposes (isRecognizedCommand).
                        break;

                    default:
                        isRecognizedCommand = false;
                        break;
                    }

                    Arbiter.LocalRunLaunch = false;
                    if (isRecognizedCommand && !string.IsNullOrEmpty(message))
                    {
                        AutoConsole.PostMessage(string.Format("SENDER [{0}] - COMMAND [{1}] - MESSAGE [{2}]", parameters.Find(x => x.Key == "grid_identity").Value, command, message), ConsoleMessageType.Pubsub);
                    }
                }
            }
        }