コード例 #1
0
        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader" /> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>
        /// The object value.
        /// </returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            ActionBase action = null;
            var condition = Condition.Equals;
            var actionName = string.Empty;
            var path = string.Empty;
            var value = string.Empty;
            var text = string.Empty;
            var expectedValue = string.Empty;
            var expectedText = string.Empty;
            var seconds = 0;

            while (reader.Read() && reader.TokenType != JsonToken.EndObject)
            {
                if (reader.TokenType == JsonToken.PropertyName)
                {
                    switch (reader.Value as string)
                    {
                        case "action":
                            actionName = reader.ReadAsString();
                            break;

                        case "path":
                            path = reader.ReadAsString();
                            break;

                        case "value":
                            value = reader.ReadAsString();
                            break;

                        case "text":
                            text = reader.ReadAsString();
                            break;

                        case "expectedValue":
                            expectedValue = reader.ReadAsString();
                            break;

                        case "expectedText":
                            expectedText = reader.ReadAsString();
                            break;

                        case "condition":
                            condition = (Condition)Enum.Parse(typeof (Condition), reader.ReadAsString(), true);
                            break;

                        case "seconds":
                            seconds = reader.ReadAsInt32() ?? 10;
                            break;
                    }
                }
            }

            switch (actionName)
            {
                case "click":
                    action = new ClickAction { Condition = condition, Path = path, Text = text, Value = value };
                    break;

                case "enterKey":
                    action = new EnterKeyAction { Condition = condition, Path = path, Text = text, Value = value };
                    break;

                case "navigateTo":
                    action = new NavigateToAction { Path = path };
                    break;

                case "selectItem":
                    action = new SelectItemAction { Condition = condition, Path = path, Text = text, Value = value };
                    break;

                case "setText":
                    action = new SetTextAction { Path = path, Value = value };
                    break;

                case "test":
                    action = new TestAction { Condition = condition, Path = path, ExpectedText = expectedText, ExpectedValue = expectedValue };
                    break;

                case "wait":
                    action = new WaitAction { Seconds = seconds };
                    break;
            }

            return action;
        }
コード例 #2
0
        /// <summary>
        /// Perform the actions that are stored in the action stack.
        /// </summary>
        public void PerformActions(Object myObject, EventArgs myEventArgs)
        {
            //
            // Go through all actions in the queue.
            //

            bool threadStateChangeActionPerformed = false;

            while (this.actionQueue.Count > 0)
            {
                Object action = this.actionQueue.Dequeue();

                if (action is AttachAction)
                {
                    AttachAction attachAction = action as AttachAction;

                    this.threadsInThreadState[(int)attachAction.threadState].Add(attachAction.thread);
                }
                else if (action is ThreadStateChangeAction)
                {
                    threadStateChangeActionPerformed = true;

                    ThreadStateChangeAction threadStateChangeAction = action as ThreadStateChangeAction;

                    this.threadsInThreadState[(int)threadStateChangeAction.oldThreadState].Remove(threadStateChangeAction.thread);
                    this.threadsInThreadState[(int)threadStateChangeAction.newThreadState].Add(threadStateChangeAction.thread);
                }
                else if (action is SetTextAction)
                {
                    SetTextAction setTextAction = action as SetTextAction;

                    this.text = setTextAction.Text;
                }
                else
                {
                    // Do nothing.
                }
            }


            //
            // Update the caption of this Form.
            //
            if ((this.text == null) || (this.text.Length == 0))
            {
                int attachedThreadsCount =
                    this.threadsInThreadState[(int)ThreadState.UnStarted].Count +
                    this.threadsInThreadState[(int)ThreadState.Running].Count +
                    this.threadsInThreadState[(int)ThreadState.Stopping].Count +
                    this.threadsInThreadState[(int)ThreadState.Stopped].Count;

                Text =
                    attachedThreadsCount.ToString() + " attached thread(s) (" +
                    threadsInThreadState[(int)ThreadState.UnStarted].Count.ToString() + " unstarted, " +
                    threadsInThreadState[(int)ThreadState.Running].Count.ToString() + " running, " +
                    threadsInThreadState[(int)ThreadState.Stopping].Count.ToString() + " stopping/waiting for child(s), " +
                    threadsInThreadState[(int)ThreadState.Stopped].Count.ToString() + " stopped)";
            }
            else
            {
                Text = this.text;
            }


            //
            // Check if this Form must be closed or the text on the button must change.
            //

            if (threadStateChangeActionPerformed)
            {
                int numberOfRunningAndStoppingThreads =
                    threadsInThreadState[(int)ThreadState.Running].Count +
                    threadsInThreadState[(int)ThreadState.Stopping].Count;

                if (numberOfRunningAndStoppingThreads == 0)
                {
                    if (this.hliForm.AutoExit)
                    {
                        Close();
                    }
                    else
                    {
                        this.buttonStop.Text = TEXT_EXIT;
                    }
                }
            }
        }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: brentj73/Tellurium
        /// <summary>
        /// Changes the type of the action.
        /// </summary>
        private void ChangeActionType()
        {
            var selectedAction = PackageTreeView.SelectedItem as ActionBase;
            if (!_isChangingAction && selectedAction != null && ActionComboBox.SelectedItem != null)
            {
                var helper = new PackageHelper(_package);
                var action = ActionComboBox.SelectedItem as ComboBoxItem;

                if (action != null)
                {
                    switch (action.Tag.ToString())
                    {
                        case "Click":
                            if (selectedAction.GetType() != typeof(ClickAction))
                            {
                                var replacementAction = new ClickAction();
                                helper.ReplaceAction(selectedAction, replacementAction);
                                RefreshTreeView(replacementAction);
                            }
                            break;

                        case "EnterKey":
                            if (selectedAction.GetType() != typeof(EnterKeyAction))
                            {
                                var replacementAction = new EnterKeyAction();
                                helper.ReplaceAction(selectedAction, replacementAction);
                                RefreshTreeView(replacementAction);
                            }
                            break;

                        case "NavigateTo":
                            if (selectedAction.GetType() != typeof(NavigateToAction))
                            {
                                var replacementAction = new NavigateToAction();
                                helper.ReplaceAction(selectedAction, replacementAction);
                                RefreshTreeView(replacementAction);
                            }
                            break;

                        case "SelectItem":
                            if (selectedAction.GetType() != typeof(SelectItemAction))
                            {
                                var replacementAction = new SelectItemAction();
                                helper.ReplaceAction(selectedAction, replacementAction);
                                RefreshTreeView(replacementAction);
                            }
                            break;

                        case "SetText":
                            if (selectedAction.GetType() != typeof(SetTextAction))
                            {
                                var replacementAction = new SetTextAction();
                                helper.ReplaceAction(selectedAction, replacementAction);
                                RefreshTreeView(replacementAction);
                            }
                            break;

                        case "Test":
                            if (selectedAction.GetType() != typeof(TestAction))
                            {
                                var replacementAction = new TestAction();
                                helper.ReplaceAction(selectedAction, replacementAction);
                                RefreshTreeView(replacementAction);
                            }
                            break;

                        case "Wait":
                            if (selectedAction.GetType() != typeof(WaitAction))
                            {
                                var replacementAction = new WaitAction();
                                helper.ReplaceAction(selectedAction, replacementAction);
                                RefreshTreeView(replacementAction);
                            }
                            break;
                    }
                }
            }
        }